Class: HeadMusic::Instruments::Instrument
- Inherits:
-
Object
- Object
- HeadMusic::Instruments::Instrument
show all
- Includes:
- Named
- Defined in:
- lib/head_music/instruments/instrument.rb
Overview
A musical instrument. An instrument object can be assigned to a staff object. Attributes:
name_key: the name of the instrument
alias_name_keys: an array of alternative names for the instrument
orchestra_section_key: the section of the orchestra (e.g. "strings")
family_key: the key for the family of the instrument (e.g. "saxophone")
classification_keys: an array of classification_keys
default_clefs: the default clef or system of clefs for the instrument
- [treble] for instruments that use the treble clef
- [treble, bass] for instruments that use the grand staff
variants:
a hash of default and alternative pitch designations
Associations:
family: the family of the instrument (e.g. "saxophone")
orchestra_section: the section of the orchestra (e.g. "strings")
Constant Summary
collapse
- INSTRUMENTS =
YAML.load_file(File.expand_path("instruments.yml", __dir__)).freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Named
#ensure_localized_name, included, #localized_name, #localized_names, #name, #name=
Instance Attribute Details
#alias_name_keys ⇒ Object
Returns the value of attribute alias_name_keys.
35
36
37
|
# File 'lib/head_music/instruments/instrument.rb', line 35
def alias_name_keys
@alias_name_keys
end
|
#classification_keys ⇒ Object
Returns the value of attribute classification_keys.
35
36
37
|
# File 'lib/head_music/instruments/instrument.rb', line 35
def classification_keys
@classification_keys
end
|
#family_key ⇒ Object
Returns the value of attribute family_key.
35
36
37
|
# File 'lib/head_music/instruments/instrument.rb', line 35
def family_key
@family_key
end
|
#name_key ⇒ Object
Returns the value of attribute name_key.
35
36
37
|
# File 'lib/head_music/instruments/instrument.rb', line 35
def name_key
@name_key
end
|
#orchestra_section_key ⇒ Object
Returns the value of attribute orchestra_section_key.
35
36
37
|
# File 'lib/head_music/instruments/instrument.rb', line 35
def orchestra_section_key
@orchestra_section_key
end
|
#variants ⇒ Object
Returns the value of attribute variants.
35
36
37
|
# File 'lib/head_music/instruments/instrument.rb', line 35
def variants
@variants
end
|
Class Method Details
.get(name) ⇒ Object
25
26
27
|
# File 'lib/head_music/instruments/instrument.rb', line 25
def self.get(name)
get_by_name(name)
end
|
Instance Method Details
#==(other) ⇒ Object
41
42
43
|
# File 'lib/head_music/instruments/instrument.rb', line 41
def ==(other)
to_s == other.to_s
end
|
#default_clefs ⇒ Object
93
94
95
|
# File 'lib/head_music/instruments/instrument.rb', line 93
def default_clefs
default_staves&.map(&:clef) || []
end
|
#default_sounding_transposition ⇒ Object
97
98
99
|
# File 'lib/head_music/instruments/instrument.rb', line 97
def default_sounding_transposition
default_staves&.first&.sounding_transposition || 0
end
|
#default_staff_scheme ⇒ Object
85
86
87
|
# File 'lib/head_music/instruments/instrument.rb', line 85
def default_staff_scheme
default_variant&.default_staff_scheme
end
|
#default_staves ⇒ Object
89
90
91
|
# File 'lib/head_music/instruments/instrument.rb', line 89
def default_staves
default_staff_scheme&.staves || []
end
|
#default_variant ⇒ Object
81
82
83
|
# File 'lib/head_music/instruments/instrument.rb', line 81
def default_variant
variants.find(&:default?) || variants.first
end
|
#multiple_staves? ⇒ Boolean
71
72
73
|
# File 'lib/head_music/instruments/instrument.rb', line 71
def multiple_staves?
default_staves.length > 1
end
|
#pitched? ⇒ Boolean
75
76
77
78
79
|
# File 'lib/head_music/instruments/instrument.rb', line 75
def pitched?
return false if default_clefs.compact.uniq == [HeadMusic::Rudiment::Clef.get("neutral_clef")]
default_clefs.any?
end
|
#single_staff? ⇒ Boolean
67
68
69
|
# File 'lib/head_music/instruments/instrument.rb', line 67
def single_staff?
default_staves.length == 1
end
|
#translation(locale = :en) ⇒ Object
45
46
47
48
49
|
# File 'lib/head_music/instruments/instrument.rb', line 45
def translation(locale = :en)
return name unless name_key
I18n.translate(name_key, scope: %i[head_music instruments], locale: locale, default: name)
end
|
#transposing? ⇒ Boolean
Returns true if the instrument sounds at a different pitch than written.
58
59
60
|
# File 'lib/head_music/instruments/instrument.rb', line 58
def transposing?
default_sounding_transposition != 0
end
|
#transposing_at_the_octave? ⇒ Boolean
Returns true if the instrument sounds at a different register than written.
63
64
65
|
# File 'lib/head_music/instruments/instrument.rb', line 63
def transposing_at_the_octave?
transposing? && default_sounding_transposition % 12 == 0
end
|