pub struct Instrument { /* private fields */ }Expand description
An instrument of one of music21’s kinds: music21’s Instrument.
use music21_rs::instrument::{Instrument, SearchLanguage};
let clarinet = Instrument::from_name("Clarinet in A", SearchLanguage::All)?;
assert_eq!(clarinet.kind(), "Clarinet");
assert!(clarinet.is_a("WoodwindInstrument"));
assert_eq!(clarinet.transposition().unwrap().directed_name(), "m-3");Implementations§
Source§impl Instrument
impl Instrument
Sourcepub fn of_kind(class: &str) -> Result<Self>
pub fn of_kind(class: &str) -> Result<Self>
An instrument of the kind music21 names by that class, as a new one of
that class starts out: "Piano", "BassClarinet", "Triangle".
Sourcepub fn part_id(&self) -> Option<&str>
pub fn part_id(&self) -> Option<&str>
The id of the part this instrument plays, as a score writes it:
music21’s partId, P1 in a score read from MusicXML.
Sourcepub fn set_part_id(&mut self, id: Option<String>)
pub fn set_part_id(&mut self, id: Option<String>)
Sets the id of the part this instrument plays.
Sourcepub fn instrument_id(&self) -> Option<&str>
pub fn instrument_id(&self) -> Option<&str>
The instrument’s own id within its part, P1-I1: music21’s
instrumentId.
Sourcepub fn set_instrument_id(&mut self, id: Option<String>)
pub fn set_instrument_id(&mut self, id: Option<String>)
Sets the instrument’s own id.
Sourcepub fn kinds() -> impl Iterator<Item = &'static str>
pub fn kinds() -> impl Iterator<Item = &'static str>
Every kind of instrument music21 has a class for, families first.
Sourcepub fn from_midi_program(program: u8) -> Result<Self>
pub fn from_midi_program(program: u8) -> Result<Self>
The instrument music21 makes of a General MIDI program, 0 to 127,
with its program set to that number: music21’s
instrumentFromMidiProgram.
Sourcepub fn from_name(text: &str, language: SearchLanguage) -> Result<Self>
pub fn from_name(text: &str, language: SearchLanguage) -> Result<Self>
The instrument a score’s name for one means, read the way music21’s
fromString reads it.
The name is taken apart into every run of its words, and the longest
run naming an instrument wins, a later one breaking a tie unless the
one found is already of its kind – so "Bb Piccolo Trumpet" is a
trumpet, not a piccolo. The instrument is named with the text as
given. For an instrument that comes in several keys, a run
naming a pitch sets its transposition: "Horn in F", "Klarinette in B.".
Sourcepub fn class_name(&self) -> Option<&'static str>
pub fn class_name(&self) -> Option<&'static str>
music21’s own name for this kind of instrument, where it is one
music21 has a class for: the name as the table spells it, which is
what is_a and the class lineage answer with.
Sourcepub fn families(&self) -> &'static [&'static str]
pub fn families(&self) -> &'static [&'static str]
The families this kind belongs to, nearest first and ending with
Instrument: a clarinet is a WoodwindInstrument.
Sourcepub fn is_a(&self, class: &str) -> bool
pub fn is_a(&self, class: &str) -> bool
Whether this is an instrument of that kind or of a kind in that
family, as music21’s isinstance answers.
Sourcepub fn abbreviation(&self) -> Option<&str>
pub fn abbreviation(&self) -> Option<&str>
The instrument’s abbreviation: music21’s instrumentAbbreviation.
Sourcepub fn set_abbreviation(&mut self, abbreviation: Option<String>)
pub fn set_abbreviation(&mut self, abbreviation: Option<String>)
Sets the abbreviation, or takes it away.
Sourcepub fn part_name(&self) -> Option<&str>
pub fn part_name(&self) -> Option<&str>
What the part this instrument plays is called, where that is not
the instrument’s name: music21’s partName.
Sourcepub fn set_part_name(&mut self, name: Option<String>)
pub fn set_part_name(&mut self, name: Option<String>)
Sets what the part is called.
Sourcepub fn part_abbreviation(&self) -> Option<&str>
pub fn part_abbreviation(&self) -> Option<&str>
The part’s abbreviation: music21’s partAbbreviation.
Sourcepub fn set_part_abbreviation(&mut self, abbreviation: Option<String>)
pub fn set_part_abbreviation(&mut self, abbreviation: Option<String>)
Sets the part’s abbreviation.
Sourcepub fn best_name(&self) -> Option<&str>
pub fn best_name(&self) -> Option<&str>
The best name there is for this instrument: the part’s name, the
part’s abbreviation, the instrument’s name or its abbreviation, the
first of those given. music21’s bestName.
Sourcepub fn sound(&self) -> Option<&str>
pub fn sound(&self) -> Option<&str>
The sound’s MusicXML id, "wind.reed.clarinet.bflat" and the like:
music21’s instrumentSound.
Sourcepub fn midi_program(&self) -> Option<u8>
pub fn midi_program(&self) -> Option<u8>
The General MIDI program, counted from nought: music21’s midiProgram.
Sourcepub fn set_midi_program(&mut self, program: Option<u8>)
pub fn set_midi_program(&mut self, program: Option<u8>)
Sets the General MIDI program.
Sourcepub fn midi_channel(&self) -> Option<u8>
pub fn midi_channel(&self) -> Option<u8>
The MIDI channel, counted from nought, 9 being the drums: music21’s
midiChannel.
Sourcepub fn set_midi_channel(&mut self, channel: Option<u8>)
pub fn set_midi_channel(&mut self, channel: Option<u8>)
Sets the MIDI channel.
Sourcepub fn lowest(&self) -> Option<&Pitch>
pub fn lowest(&self) -> Option<&Pitch>
The lowest note the instrument plays, as it sounds: music21’s
lowestNote.
Sourcepub fn set_lowest(&mut self, pitch: Option<Pitch>)
pub fn set_lowest(&mut self, pitch: Option<Pitch>)
Sets the lowest note.
Sourcepub fn highest(&self) -> Option<&Pitch>
pub fn highest(&self) -> Option<&Pitch>
The highest note the instrument plays: music21’s highestNote.
Sourcepub fn set_highest(&mut self, pitch: Option<Pitch>)
pub fn set_highest(&mut self, pitch: Option<Pitch>)
Sets the highest note.
Sourcepub fn transposition(&self) -> Option<&Interval>
pub fn transposition(&self) -> Option<&Interval>
The interval from what is written for the instrument to what sounds:
a B-flat clarinet sounds a major second below, M-2. music21’s
transposition.
Sourcepub fn set_transposition(&mut self, interval: Option<Interval>)
pub fn set_transposition(&mut self, interval: Option<Interval>)
Sets the transposition, or takes it away.
Sourcepub fn sounding(&self, written: &Pitch) -> Result<Pitch>
pub fn sounding(&self, written: &Pitch) -> Result<Pitch>
What sounds when written is played: the pitch moved by the
transposition, or itself for an instrument that does not transpose.
Sourcepub fn written(&self, sounding: &Pitch) -> Result<Pitch>
pub fn written(&self, sounding: &Pitch) -> Result<Pitch>
What is written for sounding to be heard.
Sourcepub fn in_percussion_map(&self) -> bool
pub fn in_percussion_map(&self) -> bool
Whether the instrument is one of General MIDI’s percussion map:
music21’s inGMPercMap.
Sourcepub fn percussion_pitch(&self) -> Option<u8>
pub fn percussion_pitch(&self) -> Option<u8>
The General MIDI drum the instrument plays, for unpitched percussion:
music21’s percMapPitch.
Sourcepub fn set_percussion_pitch(&mut self, pitch: Option<u8>)
pub fn set_percussion_pitch(&mut self, pitch: Option<u8>)
Sets the General MIDI drum the instrument plays.
Sourcepub fn set_in_percussion_map(&mut self, in_map: bool)
pub fn set_in_percussion_map(&mut self, in_map: bool)
Says whether the instrument is in the General MIDI percussion map.
Sourcepub fn string_pitches(&self) -> Option<&[Pitch]>
pub fn string_pitches(&self) -> Option<&[Pitch]>
The open strings, lowest first unless the tuning is reentrant, for a
string instrument music21 tunes: music21’s stringPitches.
use music21_rs::Instrument;
let violin = Instrument::of_kind("Violin")?;
let open: Vec<String> = violin
.string_pitches()
.unwrap()
.iter()
.map(|pitch| pitch.name_with_octave())
.collect();
assert_eq!(open, ["G3", "D4", "A4", "E5"]);Sourcepub fn set_string_pitches(&mut self, pitches: Vec<Pitch>)
pub fn set_string_pitches(&mut self, pitches: Vec<Pitch>)
Retunes the open strings, a scordatura.
Sourcepub fn modifier(&self) -> Option<&str>
pub fn modifier(&self) -> Option<&str>
How an unpitched percussion instrument is played, such as "low" for
a bongo or "rimshot" for a snare: music21’s modifier.
Sourcepub fn set_modifier(&mut self, modifier: &str)
pub fn set_modifier(&mut self, modifier: &str)
Sets how the instrument is played. A modifier its drum map knows
changes the drum it plays, and is written back as that drum’s own name
for it, so a woodblock set to "LO" plays the low block and says
"low".
use music21_rs::Instrument;
let mut woodblock = Instrument::of_kind("Woodblock")?;
woodblock.set_modifier("LO");
assert_eq!(woodblock.modifier(), Some("low"));
assert_eq!(woodblock.percussion_pitch(), Some(77));Sourcepub fn auto_assign_midi_channel(
&mut self,
used: &[u8],
max_channels: u8,
) -> Result<u8>
pub fn auto_assign_midi_channel( &mut self, used: &[u8], max_channels: u8, ) -> Result<u8>
Takes a MIDI channel no instrument in used has, and returns it:
music21’s autoAssignMidiChannel.
Unpitched percussion goes to channel 9 when that is free; otherwise
the lowest free channel below max_channels that is not a drum
channel is taken. It is an error when every channel is in use; where
none is free the answer is 0 and no channel is set, as music21 answers.
Sourcepub fn all_names(
&self,
language: SearchLanguage,
) -> Vec<(SearchLanguage, Vec<&'static str>)>
pub fn all_names( &self, language: SearchLanguage, ) -> Vec<(SearchLanguage, Vec<&'static str>)>
Every name a score may call this kind of instrument in one language,
or in each of them: music21’s getAllNamesForInstrument.
The names are those of the nearest kind in the instrument’s family that the tables name at all – its own, or for a guitar, which they do not name, a string instrument’s – whatever the instrument itself is called.
Trait Implementations§
Source§impl Clone for Instrument
impl Clone for Instrument
Source§impl Debug for Instrument
impl Debug for Instrument
Source§impl Default for Instrument
impl Default for Instrument
Source§impl<'de> Deserialize<'de> for Instrument
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Instrument
serde only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Instrument
impl Display for Instrument
Source§impl From<Instrument> for StreamElement
impl From<Instrument> for StreamElement
Source§fn from(value: Instrument) -> Self
fn from(value: Instrument) -> Self
Source§impl PartialEq for Instrument
impl PartialEq for Instrument
Source§impl Serialize for Instrument
Available on crate feature serde only.
impl Serialize for Instrument
serde only.impl StructuralPartialEq for Instrument
Auto Trait Implementations§
impl Freeze for Instrument
impl RefUnwindSafe for Instrument
impl Send for Instrument
impl Sync for Instrument
impl Unpin for Instrument
impl UnsafeUnpin for Instrument
impl UnwindSafe for Instrument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more