
    rhN#                        S SK Jr  S SKrS SKJr  S SKJr  S SKJr   " S S\R                  5      r " S S	5      r	 " S
 S\R                  5      r\	/r\S:X  a  S SKr\R                  " \5        gg)    )annotationsN)pitch)exceptions21)
instrumentc                      \ rS rSrSrg)MIDIPercussionException    N)__name__
__module____qualname____firstlineno____static_attributes__r
       Q/home/james-whalen/.local/lib/python3.13/site-packages/music21/midi/percussion.pyr   r      s    r   r   c                     \ rS rSrSr\r0 S\R                  _S\R                  _S\R                  _S\R                  _S\R                  _S\R                  _S	\R                  _S
\R                  _S\R                  _S\R                  _S\R                  _S\R                  _S\R                  _S\R                  _S\R                  _S\R                  _S\R                  _0 S\R                  _S\R                  _S\R                  _S\R                  _S\R                   _S\R                   _S\R                   _S\R"                  _S\R"                  _S\R$                  _S\R$                  _S\R&                  _S \R(                  _S!\R(                  _S"\R*                  _S#\R*                  _S$\R,                  _ES%\R,                  0ErS& rS' r\\/rS(rg))*PercussionMapper   a*  
PercussionMapper provides tools to convert between 0-indexed MIDI pitches
and music21 instruments, based on the official General MIDI Level 1 Percussion Key Map.
This mapping is conventionally applied to MIDI channel 10;
see https://midi.org/general-midi-level-1 for more info.

Give me the instrument that corresponds to MIDI note 58!

>>> pm = midi.percussion.PercussionMapper()
>>> pm.reverseInstrumentMapping[58]
<class 'music21.instrument.Vibraslap'>

That's right, vibraslap.

But you're better off using the midiPitchToInstrument() method below!
#   $   %   &   (   )   *   +   ,   -   .   /   0   1   2   6   8   9   :   <   =   >   ?   @   A   B   C   D   F   G   H   L   M   P   Q   c                >   [        U[        5      (       a  UnOUR                  nX R                  ;  a  [	        U< S35      eU R                  U   nU" 5       nUR
                  SL a5  [        US5      (       a$  X$R                  ;   a  UR                  U   nXTl        U$ )a  
Takes a pitch.Pitch object or int ranging from 0-127 and returns
the corresponding instrument in the GM Percussion Map.

>>> pm = midi.percussion.PercussionMapper()
>>> cowPitch = pitch.Pitch(56)
>>> cowbell = pm.midiPitchToInstrument(cowPitch)
>>> cowbell
<music21.instrument.Cowbell 'Cowbell'>

Or it can just take an integer (representing MIDI note) for the pitch instead:

>>> moreCowbell = pm.midiPitchToInstrument(56)
>>> moreCowbell
<music21.instrument.Cowbell 'Cowbell'>

The standard GM Percussion list goes from 35 to 81;
pitches outside this range raise an exception.

>>> bassDrum1Pitch = pitch.Pitch('B-1')
>>> pm.midiPitchToInstrument(bassDrum1Pitch)
Traceback (most recent call last):
music21.midi.percussion.MIDIPercussionException: 34 does not map to a valid instrument!

Also, certain GM instruments do not have corresponding music21 instruments,
so at present they also raise an exception.

>>> cabasaPitch = 69
>>> pm.midiPitchToInstrument(cabasaPitch)
Traceback (most recent call last):
music21.midi.percussion.MIDIPercussionException: 69 does not map to a valid instrument!


Some music21 Instruments have more than one MidiPitch.  In this case you'll
get the same Instrument object but with a different modifier

>>> acousticBassDrumPitch = pitch.Pitch(35)
>>> acousticBDInstrument = pm.midiPitchToInstrument(acousticBassDrumPitch)
>>> acousticBDInstrument
<music21.instrument.BassDrum 'Bass Drum'>
>>> acousticBDInstrument.modifier
'acoustic'

>>> oneBassDrumPitch = pitch.Pitch(36)
>>> oneBDInstrument = pm.midiPitchToInstrument(oneBassDrumPitch)
>>> oneBDInstrument
<music21.instrument.BassDrum 'Bass Drum'>
>>> oneBDInstrument.modifier
'1'

z$ does not map to a valid instrument!T_percMapPitchToModifier)	
isinstanceintmidireverseInstrumentMappingr   inGMPercMaphasattrr9   modifier)self	midiPitch
midiNumbermidiInstrumentmidiInstrumentObjectr@   s         r   midiPitchToInstrument&PercussionMapper.midiPitchToInstrumentb   s    j i%%"J"J:::)ZN:^*_``66zB-/ ,,402KLLIII/GG
S08-##r   c                    [        US5      (       a  UR                  SL a  [        U< S35      eUR                  n[        R
                  " 5       nX#l        U$ )a  
Takes an instrument.Instrument object and returns a pitch object
with the corresponding 1-indexed MIDI note, according to the GM Percussion Map.


>>> pm = midi.percussion.PercussionMapper()
>>> myCow = instrument.Cowbell()
>>> cowPitch = pm.midiInstrumentToPitch(myCow)
>>> cowPitch.midi
56

Note that cowPitch is an actual pitch.Pitch object
even though it's meaningless!

>>> cowPitch
<music21.pitch.Pitch G#3>

If the instrument does not have an equivalent in the GM Percussion Map,
return an Exception:

>>> myBagpipes = instrument.Bagpipes()
>>> pipePitch = pm.midiInstrumentToPitch(myBagpipes)
Traceback (most recent call last):
music21.midi.percussion.MIDIPercussionException: <music21.instrument.Bagpipes 'Bagpipes'>
    is not in the GM Percussion Map!
r>   Fz! is not in the GM Percussion Map!)r?   r>   r   percMapPitchr   Pitchr<   )rA   rD   rB   pitchObjects       r   midiInstrumentToPitch&PercussionMapper.midiInstrumentToPitch   sU    6 ~}559S9SW\9\)^,>>_*`aa"//	kkm$r   r
   N)r   r   r   r   __doc__r   iBassDrum	SnareDrumTomTomHiHatCymbalCrashCymbals
TambourineCowbell	Vibraslap
BongoDrums	CongaDrumTimbalesAgogoMaracasWhistle	WoodblockTriangler=   rF   rL   
_DOC_ORDERr   r
   r   r   r   r      sl   " 	A/ "AJJ / " "AJJ/ " "AKK/ " !#AKK/ "
 !#AKK/ " !#AHH/ " !#AMM/ " !#AHH/ " !#AMM/ " !#AHH/ " !#AMM/ " !#AHH/ " !#AHH/ " !#ANN/ " !#AHH/ "& !#ALL'/ "* !#AII+/ ", !#ANN-/ ". !#AKK// "2 !#ALL3/ "4 !#ALL5/ "6 !#AKK7/ "8 !#AKK9/ ": !#AKK;/ "< !#AJJ=/ "> !#AJJ?/ "@ !#AGGA/ "B !#AGGC/ "F !#AIIG/ "H !#AIII/ "J !#AIIK/ "R !#AKKS/ "T !#AKKU/ "Z !#AJJ[/ "\ !#AJJ]/ "lD$L D ()>?Jr   r   c                      \ rS rSrS rSrg)Test   c                2    SSK Jn  U" U [        5       5        g )Nr   )testCopyAll)music21.test.commonTestre   globals)rA   re   s     r   testCopyAndDeepcopyTest.testCopyAndDeepcopy   s    7D')$r   r
   N)r   r   r   r   rh   r   r
   r   r   rb   rb      s    %r   rb   __main__)
__future__r   unittestmusic21r   r   r   Music21Exceptionr   r   TestCaserb   r`   r   mainTestr
   r   r   <module>rq      ss    #     	l;; 	q@ q@h%8 % 
 zT r   