Class MusicalInstrument

MusicalInstrument is an object that regroup several sounds sharing same characteristics, playing techniques, sound capabilities.

i.e. Piano is an instrument, Grand Piano, Upright piano, Honky-tonk are different sounds of piano. This class allow to know:

Section

SectionSummary
InstrumentsClassificationsMusical instrument classifications

Summary

FieldTypeSummary
AlternativeNamestableAlternative names
EratableFor historical instrument, their era (Renaissance, Baroque, chinese dinasty).
FamilyintFamily of instrument: one of FAMILY_* constants.
GeographicOrigintableFor "ethnic" instrument, their geographical origin
IDintIdentifier of the instrument, one of INSTR_* constants.
IsVolumeDecaysbooleanDoes volume decays?
MaxSimultaneousNotesintMaximum number of simultaneously played notes: 1=monophonic, 2==polyphonic.
MidiSectionintMIDI section: one of the MIDI_SECTION_* constants.
NamestringInstrument name
NecksCollectionNecks definitions: number of courses, number of strings per course, tunings...
OrchestraSectionintSection of the orchestra: one of the ORCH_SECTION_* constants
ShortNamestableShort staff names
SoundsCollectionInstrument's sounds, a table of Sound.
StaffSpanintNumber of staves the instrument use, (flûte:1, piano:2, organ:3).
VariantstableVariants of this instrument, that may have different play/written range.
Return typeFunction and summary
MusicalInstrumentaddVariant(string variantName, string clefs, Interval transpo, int staffSpan)
Add a variant to the instrument, "Bb", "C", "A" and "G" are variant for Clarinet, as well as "3 octaves" and "5 octaves" are variants for Celesta.
NeckgetNeck()
Returns the neck from its name.
CollectiongetNecksNames()
Return all necks names
string, string, string, string, string, stringgetPlayRange(string rangeName)
Return two play ranges of extrem and easy-to-play low and high note for the range name or sound ID.
CollectiongetRangesNames()
Return distinct names for ranges: "" (default), "Amateur", "Pro", variant name, neck and tuning name in a iterable Collection.
SoundgetSound(int soundID)
Get the sound from its ID.
string, stringgetSoundPlayRange(int soundId)
Returns the sound-specific play range, if known.
tablegetVariant(string variantName)
Return the asked variant.
table, string, string, table, string, stringgetWrittenRange(string rangeName)
Get written range, clef(s) and low/high notes.
booleanhasSounds()
Does this instrument has sound(s)?
booleanhasVariants()
Does this instrument has variant(s)?
booleanisEra(string era)
Is this instrument created or massively played in era (period)?
booleanisGeo(string country)
Is this instrument coming from country?
booleanisMonophonic()
Is instrument monophonic?
booleanisPolyphonic()
Is instrument polyphonic?

Fields

int MusicalInstrument:ID

Identifier of the instrument, one of INSTR_* constants.

string MusicalInstrument:Name

Instrument name

int MusicalInstrument:OrchestraSection

Section of the orchestra: one of the ORCH_SECTION_* constants

int MusicalInstrument:MidiSection

MIDI section: one of the MIDI_SECTION_* constants.

int MusicalInstrument:Family

Family of instrument: one of FAMILY_* constants.

table MusicalInstrument:GeographicOrigin

For "ethnic" instrument, their geographical origin

table MusicalInstrument:Era

For historical instrument, their era (Renaissance, Baroque, chinese dinasty).

Collection MusicalInstrument:Sounds

Instrument's sounds, a table of Sound.

boolean MusicalInstrument:IsVolumeDecays

Does volume decays?

table MusicalInstrument:Variants

Variants of this instrument, that may have different play/written range.

e.g. 4- or 5-octaves celesta, Bb- or C- or A- soprano clarinet.
Note: in oriented-object, the good practice would have been a MusicalInstrumentVariant object but we are also concerned by memory and serialization optimizations.

int MusicalInstrument:StaffSpan

Number of staves the instrument use, (flûte:1, piano:2, organ:3).

int MusicalInstrument:MaxSimultaneousNotes

Maximum number of simultaneously played notes: 1=monophonic, 2==polyphonic.

Pianos may have 51 (white keys in a HUGE cluster), Marimba/Vibraphone may have 4 (2 sticks in each hand), clarinet is monophonic (MaxSimultaneousNotes=1).

Collection MusicalInstrument:Necks

Necks definitions: number of courses, number of strings per course, tunings...

table MusicalInstrument:AlternativeNames

Alternative names

table MusicalInstrument:ShortNames

Short staff names

Methods

MusicalInstrument:addVariant(string variantName, string clefs, Interval transpo, int staffSpan)

Add a variant to the instrument, "Bb", "C", "A" and "G" are variant for Clarinet, as well as "3 octaves" and "5 octaves" are variants for Celesta.

ParameterTypeDefaultDescription
variantNamestring Or table of strings
clefsstring"G""G", "G8va", "F,G"
transpoIntervalnilTransposition interval
staffSpanint12 for two-staves instrument (piano, harp), or 3 for organ.
Return
MusicalInstrument: self for concatenation i:addVariant("Bb", ...):play("...", "Bb/Amateur"):play(...)

MusicalInstrument:getSound(int soundID)

Get the sound from its ID.

If MusicalInstrument is known, this is really faster than GetInstrumentBySoundID(...)

ParameterTypeDefaultDescription
soundIDint soundID
Return
Sound: nil if not found
See
GetInstrumentBySoundID

MusicalInstrument:getNecksNames()

Return all necks names

Return
Collection: Collection

MusicalInstrument:getNeck()

Returns the neck from its name.

If name is in neck name - tuning name format, then neck is tuned to the tuning, else to its default.

Return
Neck: nil if not found

MusicalInstrument:getRangesNames()

Return distinct names for ranges: "" (default), "Amateur", "Pro", variant name, neck and tuning name in a iterable Collection.

Return
Collection: May be empty if no play/write ranges defined

MusicalInstrument:getPlayRange(string rangeName)

Return two play ranges of extrem and easy-to-play low and high note for the range name or sound ID.

Piano doesn't require special skills to play notes between A0 and C8, while practice or professional skills are required to play very high woodwinds notes and brass pedal notes.
Some instruments may exist in different sizes, the bigger the more expensive and less portative.
And some instrument exist in various tuning like C- and Bb-clarinet, as well as Nashville or Irish DADGAD guitar strings tunings.

ParameterTypeDefaultDescription
rangeNamestring""Range name ("", "Bb", "4 octaves"). By default, the first defined and the largest range are returned. If precise, or no multiple ranges, extreme and easy ranges can be the same.
Returns
string: Extreme low note, notes below this one are not playable.
string: Easy low note, notes below this one are difficult to play (require skills), or missing for some low-price or portative instruments. Notes above this one are easy to play.
string: Easy high note, notes below this one are easy to play. Notes above this one are difficult to play (require skills), or missing for some low-price or portative instruments.
string: Extrem high Note, notes above this one are not playable.
string: Easy range name, most probably "Amateur" or ""
string: Extrem range name, most probably "Professional" or ""

MusicalInstrument:getSoundPlayRange(int soundId)

Returns the sound-specific play range, if known.

ParameterTypeDefaultDescription
soundIdint soundId
Returns
string: lowest note name, or nil
string: highest note name, or nil

MusicalInstrument:getWrittenRange(string rangeName)

Get written range, clef(s) and low/high notes.

ParameterTypeDefaultDescription
rangeNamestring"""Variant name", "Neck name/Tuning"
Returns
table: Lowest clef, table containing clef name, octave shift (+/- 8 or 15), line shift (+/- 5)
string: Lowest easy note name
string: Lowest extreme note name
table: Highest clef, nil means it's the same as lowest clef
string: Highest easy note name
string: Highest extreme note name

MusicalInstrument:hasSounds()

Does this instrument has sound(s)?

Return
boolean: true if so, nil (for false) if not.

MusicalInstrument:hasVariants()

Does this instrument has variant(s)?

Bb- or A- or G-Clarinet, 3- or 4- or 5-octave Celesta...

Return
boolean: true if so, nil (for false) if not.

MusicalInstrument:getVariant(string variantName)

Return the asked variant.

ParameterTypeDefaultDescription
variantNamestring variantName
Return
table: or nil if variant doesn't exist

MusicalInstrument:isEra(string era)

Is this instrument created or massively played in era (period)?

ParameterTypeDefaultDescription
erastring era
Return
boolean: nil for false.

MusicalInstrument:isGeo(string country)

Is this instrument coming from country?

Mostly apply to ethnic instruments

ParameterTypeDefaultDescription
countrystring country
Return
boolean: nil for false.

MusicalInstrument:isPolyphonic()

Is instrument polyphonic?

Return
boolean: boolean

MusicalInstrument:isMonophonic()

Is instrument monophonic?

Return
boolean: boolean