Table Of Contents

Previous topic

music21.key

Next topic

music21.interval

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

Inherits from: Music21Object, JSONSerializer

class music21.instrument.Instrument

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

Instrument attributes

classSortOrder

Property which returns an number (int or otherwise) depending on the class of the Music21Object that represents a priority for an object based on its class alone – used as a tie for stream sorting in case two objects have the same offset and priority. Lower numbers are sorted to the left of higher numbers. For instance, Clef, KeySignature, TimeSignature all come (in that order) before Note. All undefined classes have classSortOrder of 20 – same as note.Note

>>> from music21 import *
>>> tc = clef.TrebleClef()
>>> tc.classSortOrder
0
>>> ks = key.KeySignature(3)
>>> ks.classSortOrder
1
New classes can define their own default classSortOrder
>>> class ExampleClass(base.Music21Object):
...     classSortOrderDefault = 5
...
>>> ec1 = ExampleClass()
>>> ec1.classSortOrder
5

Attributes without Documentation: instrumentId, instrumentName, partAbbreviation, partName, midiChannel, midiProgram, instrumentAbbreviation, transposition, partId

Attributes inherited from Music21Object: id, groups

Instrument properties

mx
>>> from music21 import *
>>> i = instrument.Celesta()
>>> mxScorePart = i.mx
>>> len(mxScorePart.scoreInstrumentList)
1
>>> mxScorePart.scoreInstrumentList[0].instrumentName
'Celesta'
>>> mxScorePart.midiInstrumentList[0].midiProgram
9

Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, duration, measureNumberLocal, offset, priority

Properties inherited from JSONSerializer: json

Instrument methods

autoAssignMidiChannel(usedChannels=[])

Assign an unused midi channel given a list of used ones. 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.

>>> from music21 import instrument
>>> used = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11]
>>> i = instrument.Violin()
>>> i.autoAssignMidiChannel(used)
12
>>> i.midiChannel
12
bestName()
Find a viable name, looking first at instrument, then part, then abbreviations.
instrumentIdRandomize()
Force a unique id by using an MD5
partIdRandomize()
Force a unique id by using an MD5

Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndParent(), freezeIds(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

BassClarinet

Inherits from: Clarinet, WoodwindInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.BassClarinet
>>> from music21 import *
>>> bcl = instrument.BassClarinet()
>>> bcl.instrumentName
'Bass clarinet'
>>> bcl.midiProgram
71
>>> 'WoodwindInstrument' in bcl.classes
True

Bassoon

Inherits from: WoodwindInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Bassoon

Celesta

Inherits from: KeyboardInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Celesta

Clarinet

Inherits from: WoodwindInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Clarinet

Clavichord

Inherits from: KeyboardInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Clavichord

Contrabass

Inherits from: StringInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Contrabass

Contrabass attributes

lowestNote
An object for storing pitch values. All values are represented internally as a scale step (self.step), and octave and an accidental object. In addition, pitches know their pitchSpace representation (self._ps); altering any of the first three changes the pitchSpace representation. Similarly, altering the pitchSpace representation alters the first three.

Attributes inherited from Instrument: classSortOrder, instrumentId, instrumentName, partAbbreviation, partName, midiChannel, midiProgram, instrumentAbbreviation, transposition, partId

Attributes inherited from Music21Object: id, groups

Contrabass properties

Properties inherited from StringInstrument: stringPitches

Properties inherited from Instrument: mx

Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, duration, measureNumberLocal, offset, priority

Properties inherited from JSONSerializer: json

Contrabass methods

Methods inherited from Instrument: autoAssignMidiChannel(), bestName(), instrumentIdRandomize(), partIdRandomize()

Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndParent(), freezeIds(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

ElectricBass

Inherits from: Guitar, StringInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.ElectricBass

ElectricGuitar

Inherits from: Guitar, StringInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.ElectricGuitar

Flute

Inherits from: WoodwindInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Flute

Glockenspiel

Inherits from: PitchedPercussion, Instrument, Music21Object, JSONSerializer

class music21.instrument.Glockenspiel

Guitar

Inherits from: StringInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Guitar

Harp

Inherits from: StringInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Harp

Harpsichord

Inherits from: KeyboardInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Harpsichord

KeyboardInstrument

Inherits from: Instrument, Music21Object, JSONSerializer

class music21.instrument.KeyboardInstrument

Oboe

Inherits from: WoodwindInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Oboe

Piano

Inherits from: KeyboardInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Piano

Piccolo

Inherits from: Flute, WoodwindInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Piccolo

PitchedPercussion

Inherits from: Instrument, Music21Object, JSONSerializer

class music21.instrument.PitchedPercussion

StringInstrument

Inherits from: Instrument, Music21Object, JSONSerializer

class music21.instrument.StringInstrument

StringInstrument attributes

Attributes inherited from Instrument: classSortOrder, instrumentId, instrumentName, partAbbreviation, partName, midiChannel, midiProgram, instrumentAbbreviation, transposition, partId

Attributes inherited from Music21Object: id, groups

StringInstrument properties

stringPitches

stringPitches is a property that stores a list of Pitches (or pitch names, such as “C4”) that represent the pitch of the open strings from lowest to highest[#reentrant]_

>>> vln1 = Violin()
>>> vln1.stringPitches
[G3, D4, A4, E5]
instrument.stringPitches are full pitch objects, not just names
>>> [x.octave for x in vln1.stringPitches]
[3, 4, 4, 5]
scordatura for Scelsi's *Anahit*. N.B. string to pitch conversion
>>> vln1.stringPitches = ["G3","G4","B4","D4"]
>>> vln1.stringPitches
[G3, G4, B4, D4]
..[#reentrant] In some tuning methods such as reentrant tuning on the ukulele,
lute, or five-string banjo the order might not strictly be from lowest to
highest.  The same would hold true for certain violin scordatura pieces, such
as some of Biber's *Mystery Sonatas*

Properties inherited from Instrument: mx

Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, duration, measureNumberLocal, offset, priority

Properties inherited from JSONSerializer: json

StringInstrument methods

Methods inherited from Instrument: autoAssignMidiChannel(), bestName(), instrumentIdRandomize(), partIdRandomize()

Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndParent(), freezeIds(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

Viola

Inherits from: StringInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Viola

Viola attributes

lowestNote
An object for storing pitch values. All values are represented internally as a scale step (self.step), and octave and an accidental object. In addition, pitches know their pitchSpace representation (self._ps); altering any of the first three changes the pitchSpace representation. Similarly, altering the pitchSpace representation alters the first three.

Attributes inherited from Instrument: classSortOrder, instrumentId, instrumentName, partAbbreviation, partName, midiChannel, midiProgram, instrumentAbbreviation, transposition, partId

Attributes inherited from Music21Object: id, groups

Viola properties

Properties inherited from StringInstrument: stringPitches

Properties inherited from Instrument: mx

Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, duration, measureNumberLocal, offset, priority

Properties inherited from JSONSerializer: json

Viola methods

Methods inherited from Instrument: autoAssignMidiChannel(), bestName(), instrumentIdRandomize(), partIdRandomize()

Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndParent(), freezeIds(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

Violin

Inherits from: StringInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Violin

Violin attributes

lowestNote
An object for storing pitch values. All values are represented internally as a scale step (self.step), and octave and an accidental object. In addition, pitches know their pitchSpace representation (self._ps); altering any of the first three changes the pitchSpace representation. Similarly, altering the pitchSpace representation alters the first three.

Attributes inherited from Instrument: classSortOrder, instrumentId, instrumentName, partAbbreviation, partName, midiChannel, midiProgram, instrumentAbbreviation, transposition, partId

Attributes inherited from Music21Object: id, groups

Violin properties

Properties inherited from StringInstrument: stringPitches

Properties inherited from Instrument: mx

Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, duration, measureNumberLocal, offset, priority

Properties inherited from JSONSerializer: json

Violin methods

Methods inherited from Instrument: autoAssignMidiChannel(), bestName(), instrumentIdRandomize(), partIdRandomize()

Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndParent(), freezeIds(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

Violoncello

Inherits from: StringInstrument, Instrument, Music21Object, JSONSerializer

class music21.instrument.Violoncello

Violoncello attributes

lowestNote
An object for storing pitch values. All values are represented internally as a scale step (self.step), and octave and an accidental object. In addition, pitches know their pitchSpace representation (self._ps); altering any of the first three changes the pitchSpace representation. Similarly, altering the pitchSpace representation alters the first three.

Attributes inherited from Instrument: classSortOrder, instrumentId, instrumentName, partAbbreviation, partName, midiChannel, midiProgram, instrumentAbbreviation, transposition, partId

Attributes inherited from Music21Object: id, groups

Violoncello properties

Properties inherited from StringInstrument: stringPitches

Properties inherited from Instrument: mx

Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, duration, measureNumberLocal, offset, priority

Properties inherited from JSONSerializer: json

Violoncello methods

Methods inherited from Instrument: autoAssignMidiChannel(), bestName(), instrumentIdRandomize(), partIdRandomize()

Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndParent(), freezeIds(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

WoodwindInstrument

Inherits from: Instrument, Music21Object, JSONSerializer

class music21.instrument.WoodwindInstrument

Xylophone

Inherits from: PitchedPercussion, Instrument, Music21Object, JSONSerializer

class music21.instrument.Xylophone