music21.instrument

This module represents instruments through objects that contain general information such as Metadata for instrument names, classifications, transpositions and default MIDI program numbers. It also contains information specific to each instrument or instrument family, such as string pitches, etc. Information about instrumental ensembles is also included here though it may later be separated out into its own ensemble.py module.

Instrument

class music21.instrument.Instrument(instrumentName=None)

Base class for all musical instruments. Designed for subclassing, though usually a more specific instrument class (such as StringInstrument) would be better to subclass.

Some defined attributes for instruments include:

  • partId

  • partName

  • partAbbreviation

  • instrumentId

  • instrumentName

  • instrumentAbbreviation

  • midiProgram

  • midiChannel

  • lowestNote (a note object or a string)

  • highestNote (a note object or a string)

  • transposition (an interval object)

  • inGMPercMap (bool – if it uses the GM percussion map)

  • soundfontFn (filepath to a sound font, optional)

Instrument bases

Instrument read-only properties

Read-only properties inherited from Music21Object:

Instrument read/write properties

Read/write properties inherited from Music21Object:

Instrument methods

Instrument.autoAssignMidiChannel(usedChannels=[])

Assign an unused midi channel given a list of used channels.

assigns the number to self.midiChannel and returns it as an int.

Note that midi channel 10 is special, and thus is skipped.

Currently only 16 channels are used.

Note that the reused “usedChannels=[]” in the signature is NOT a mistake, but necessary for the case where there needs to be a global list.

>>> used = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11]
>>> i = instrument.Violin()
>>> i.autoAssignMidiChannel(used)
12
>>> i.midiChannel
12
Instrument.bestName()

Find a viable name, looking first at instrument, then part, then abbreviations.

Instrument.instrumentIdRandomize()

Force a unique id by using an MD5

Instrument.partIdRandomize()

Force a unique id by using an MD5

Methods inherited from Music21Object:

Instrument instance variables

Instance variables inherited from Music21Object:

Contrabass

class music21.instrument.Contrabass

For the Contrabass (or double bass), the stringPitches attribute refers to the sounding pitches of each string; whereas the lowestNote attribute refers to the lowest written note

Contrabass bases

Contrabass read-only properties

Read-only properties inherited from Music21Object:

Contrabass read/write properties

Read/write properties inherited from StringInstrument:

Read/write properties inherited from Music21Object:

Contrabass methods

Methods inherited from Instrument:

Methods inherited from Music21Object:

Contrabass instance variables

Instance variables inherited from Music21Object:

Piccolo

class music21.instrument.Piccolo

Piccolo bases

Piccolo read-only properties

Read-only properties inherited from Music21Object:

Piccolo read/write properties

Read/write properties inherited from Music21Object:

Piccolo methods

Methods inherited from Instrument: