Class: HeadMusic::Instruments::StaffProfile
- Inherits:
-
Object
- Object
- HeadMusic::Instruments::StaffProfile
- Defined in:
- lib/head_music/instruments/staff_profile.rb
Overview
The properties an instrument derives from its default notation staves: how many staves it uses, their clefs, whether it transposes, and whether it is pitched. These are a projection of the notation layer (a StaffScheme built from the default NotationStyle), separated from the instrument’s identity so Instrument can delegate to one place rather than carry the staff logic itself.
Instance Attribute Summary collapse
-
#instrument ⇒ Object
readonly
Returns the value of attribute instrument.
Instance Method Summary collapse
-
#default_clefs ⇒ Object
-
#default_notation_staves_data ⇒ Object
private
The raw staff-attribute list for this instrument’s default notation, resolved from the default NotationStyle.
-
#default_staff_scheme ⇒ Object
-
#default_staves ⇒ Object
-
#initialize(instrument) ⇒ StaffProfile
constructor
A new instance of StaffProfile.
-
#multiple_staves? ⇒ Boolean
-
#pitched? ⇒ Boolean
-
#single_staff? ⇒ Boolean
-
#sounding_transposition ⇒ Object
-
#staff_schemes ⇒ Object
-
#transposing? ⇒ Boolean
-
#transposing_at_the_octave? ⇒ Boolean
Constructor Details
#initialize(instrument) ⇒ StaffProfile
Returns a new instance of StaffProfile.
12 13 14 |
# File 'lib/head_music/instruments/staff_profile.rb', line 12 def initialize(instrument) @instrument = instrument end |
Instance Attribute Details
#instrument ⇒ Object (readonly)
Returns the value of attribute instrument.
10 11 12 |
# File 'lib/head_music/instruments/staff_profile.rb', line 10 def instrument @instrument end |
Instance Method Details
#default_clefs ⇒ Object
32 33 34 |
# File 'lib/head_music/instruments/staff_profile.rb', line 32 def default_clefs default_staves&.map(&:clef) || [] end |
#default_notation_staves_data ⇒ Object (private)
The raw staff-attribute list for this instrument’s default notation, resolved from the default NotationStyle. Referenced only inside a method body, because the Notation module loads after Instruments.
67 68 69 70 |
# File 'lib/head_music/instruments/staff_profile.rb', line 67 def default_notation_staves_data notation = HeadMusic::Notation::NotationStyle.default.notation_for(instrument) (notation&.staves || []).map(&:attributes) end |
#default_staff_scheme ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/head_music/instruments/staff_profile.rb', line 20 def default_staff_scheme @default_staff_scheme ||= HeadMusic::Instruments::StaffScheme.new( key: "default", instrument: instrument, list: default_notation_staves_data ) end |
#default_staves ⇒ Object
28 29 30 |
# File 'lib/head_music/instruments/staff_profile.rb', line 28 def default_staves default_staff_scheme.staves end |
#multiple_staves? ⇒ Boolean
52 53 54 |
# File 'lib/head_music/instruments/staff_profile.rb', line 52 def multiple_staves? default_staves.length > 1 end |
#pitched? ⇒ Boolean
56 57 58 59 60 |
# File 'lib/head_music/instruments/staff_profile.rb', line 56 def pitched? return false if default_clefs.compact.uniq == [HeadMusic::Rudiment::Clef.get("neutral_clef")] default_clefs.any? end |
#single_staff? ⇒ Boolean
48 49 50 |
# File 'lib/head_music/instruments/staff_profile.rb', line 48 def single_staff? default_staves.length == 1 end |
#sounding_transposition ⇒ Object
36 37 38 |
# File 'lib/head_music/instruments/staff_profile.rb', line 36 def sounding_transposition default_staves&.first&.sounding_transposition || 0 end |
#staff_schemes ⇒ Object
16 17 18 |
# File 'lib/head_music/instruments/staff_profile.rb', line 16 def staff_schemes [default_staff_scheme] end |
#transposing? ⇒ Boolean
40 41 42 |
# File 'lib/head_music/instruments/staff_profile.rb', line 40 def transposing? sounding_transposition != 0 end |
#transposing_at_the_octave? ⇒ Boolean
44 45 46 |
# File 'lib/head_music/instruments/staff_profile.rb', line 44 def transposing_at_the_octave? transposing? && sounding_transposition % 12 == 0 end |