pub fn for_percussion_key(key: u8) -> Result<Instrument>Expand description
The instrument a key of the General MIDI percussion map plays, played
the way that key says: music21’s
midi.percussion.PercussionMapper.midiPitchToInstrument.
A key is 0 to 127 and the map runs from 27 to 87. Where the instrument
is played more than one way the modifier is the one that key plays, so
key 36 is a bass drum played "midi-1" and key 35 the same drum played
"acoustic". Nine of the map’s sounds are not instruments at all –
a hand clap, a metronome click, a scratch – and each of those is a
bare unpitched percussion instrument under the sound’s own name
(music21’s namedSoundMapping). A key the map says nothing of is an
error, as it raises there; for_percussion_key_or_unmapped is
music21’s raiseIfUnmapped=False.
The key is the drum, not the class’s own. music21 writes the key onto the instrument after the modifier, so a key that is the muted one of a pair stays muted where its class starts on the open one: key 62 is a conga drum with the high drum’s modifier struck muted, where 63 is the same modifier struck open.
use music21::instrument::for_percussion_key;
let drum = for_percussion_key(36)?;
assert_eq!(drum.kind(), "BassDrum");
assert_eq!(drum.modifier(), Some("midi-1"));
assert_eq!(drum.percussion_pitch(), Some(36));
let muted = for_percussion_key(62)?;
assert_eq!((muted.modifier(), muted.muted()), (Some("high"), Some(true)));
let clap = for_percussion_key(39)?;
assert_eq!(clap.name(), Some("Hand Clap"));
assert!(for_percussion_key(22).is_err());§Errors
A key the map names neither an instrument nor a sound for.