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:
- if instrument is monophonic or polyphonic,
- how many simultaneous notes are playable,
- it's common ambitus,
- glissando type: continuous, white keys, semi-tones...
- if pitch and velocity can change after note's attack
- its classifications in orchestra and in general MIDI
- ...
Section
Section | Summary |
---|---|
InstrumentsClassifications | Musical instrument classifications |
Summary
Field | Type | Summary |
---|---|---|
AlternativeNames | table | Alternative names |
Era | table | For historical instrument, their era (Renaissance, Baroque, chinese dinasty). |
Family | int | Family of instrument: one of FAMILY_* constants. |
GeographicOrigin | table | For "ethnic" instrument, their geographical origin |
ID | int | Identifier of the instrument, one of INSTR_* constants. |
IsVolumeDecays | boolean | Does volume decays? |
MaxSimultaneousNotes | int | Maximum number of simultaneously played notes: 1=monophonic, 2==polyphonic. |
MidiSection | int | MIDI section: one of the MIDI_SECTION_* constants. |
Name | string | Instrument name |
Necks | Collection | Necks definitions: number of courses, number of strings per course, tunings... |
OrchestraSection | int | Section of the orchestra: one of the ORCH_SECTION_* constants |
ShortNames | table | Short staff names |
Sounds | Collection | Instrument's sounds, a table of Sound. |
StaffSpan | int | Number of staves the instrument use, (flûte:1, piano:2, organ:3). |
Variants | table | Variants of this instrument, that may have different play/written range. |
Return type | Function and summary |
---|---|
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. |
Neck | getNeck() Returns the neck from its name. |
Collection | getNecksNames() Return all necks names |
string, string, string, string, string, string | getPlayRange(string rangeName) Return two play ranges of extrem and easy-to-play low and high note for the range name or sound ID. |
Collection | getRangesNames() Return distinct names for ranges: "" (default), "Amateur", "Pro", variant name, neck and tuning name in a iterable Collection. |
Sound | getSound(int soundID) Get the sound from its ID. |
string, string | getSoundPlayRange(int soundId) Returns the sound-specific play range, if known. |
table | getVariant(string variantName) Return the asked variant. |
table, string, string, table, string, string | getWrittenRange(string rangeName) Get written range, clef(s) and low/high notes. |
boolean | hasSounds() Does this instrument has sound(s)? |
boolean | hasVariants() Does this instrument has variant(s)? |
boolean | isEra(string era) Is this instrument created or massively played in era (period)? |
boolean | isGeo(string country) Is this instrument coming from country? |
boolean | isMonophonic() Is instrument monophonic? |
boolean | isPolyphonic() 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.
Parameter | Type | Default | Description |
---|---|---|---|
variantName | string | Or table of strings | |
clefs | string | "G" | "G", "G8va", "F,G" |
transpo | Interval | nil | Transposition interval |
staffSpan | int | 1 | 2 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(...)
Parameter | Type | Default | Description |
---|---|---|---|
soundID | int | soundID |
- Return
- Sound: nil if not found
- See
- GetInstrumentBySoundID
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.
Parameter | Type | Default | Description |
---|---|---|---|
rangeName | string | "" | 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.
Parameter | Type | Default | Description |
---|---|---|---|
soundId | int | 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.
Parameter | Type | Default | Description |
---|---|---|---|
rangeName | string | "" | "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.
Parameter | Type | Default | Description |
---|---|---|---|
variantName | string | variantName |
- Return
- table: or
nil
if variant doesn't exist
MusicalInstrument:isEra(string era)
Is this instrument created or massively played in era (period)?
Parameter | Type | Default | Description |
---|---|---|---|
era | string | era |
- Return
- boolean:
nil
for false.
MusicalInstrument:isGeo(string country)
Is this instrument coming from country?
Mostly apply to ethnic instruments
Parameter | Type | Default | Description |
---|---|---|---|
country | string | country |
- Return
- boolean:
nil
for false.