Class: HeadMusic::Notation::InstrumentNotation
- Inherits:
-
Object
- Object
- HeadMusic::Notation::InstrumentNotation
- Defined in:
- lib/head_music/notation/instrument_notation.rb
Overview
The resolved notation for one instrument within a NotationStyle: its staves (each with a clef and sounding transposition) plus any recorded alternatives.
This is a derived value object produced by NotationStyle#notation_for, not a catalog entry with its own factory. Alternatives are recorded data only — no selection behavior is implemented here (deferred to the Content layer).
Instance Attribute Summary collapse
-
#alternatives ⇒ Object
readonly
Returns the value of attribute alternatives.
-
#instrument ⇒ Object
readonly
Returns the value of attribute instrument.
-
#staves ⇒ Object
readonly
Returns the value of attribute staves.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
-
#build_staves(list) ⇒ Object
private
-
#clefs ⇒ Object
-
#hash ⇒ Object
-
#initialize(instrument:, data:) ⇒ InstrumentNotation
constructor
A new instance of InstrumentNotation.
-
#multiple_staves? ⇒ Boolean
-
#single_staff? ⇒ Boolean
-
#sounding_transposition ⇒ Object
-
#staves_attributes ⇒ Object
protected
Constructor Details
#initialize(instrument:, data:) ⇒ InstrumentNotation
Returns a new instance of InstrumentNotation.
12 13 14 15 16 17 |
# File 'lib/head_music/notation/instrument_notation.rb', line 12 def initialize(instrument:, data:) @instrument = instrument @staves = build_staves(data["staves"]) @alternatives = build_staves(data["alternatives"]) freeze end |
Instance Attribute Details
#alternatives ⇒ Object (readonly)
Returns the value of attribute alternatives.
10 11 12 |
# File 'lib/head_music/notation/instrument_notation.rb', line 10 def alternatives @alternatives end |
#instrument ⇒ Object (readonly)
Returns the value of attribute instrument.
10 11 12 |
# File 'lib/head_music/notation/instrument_notation.rb', line 10 def instrument @instrument end |
#staves ⇒ Object (readonly)
Returns the value of attribute staves.
10 11 12 |
# File 'lib/head_music/notation/instrument_notation.rb', line 10 def staves @staves end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
35 36 37 38 39 |
# File 'lib/head_music/notation/instrument_notation.rb', line 35 def ==(other) return false unless other.is_a?(self.class) instrument == other.instrument && staves_attributes == other.staves_attributes end |
#build_staves(list) ⇒ Object (private)
54 55 56 |
# File 'lib/head_music/notation/instrument_notation.rb', line 54 def build_staves(list) (list || []).map { |attributes| HeadMusic::Instruments::Staff.new(nil, attributes) } end |
#clefs ⇒ Object
19 20 21 |
# File 'lib/head_music/notation/instrument_notation.rb', line 19 def clefs staves.map(&:clef) end |
#hash ⇒ Object
42 43 44 |
# File 'lib/head_music/notation/instrument_notation.rb', line 42 def hash [instrument.name_key, staves_attributes].hash end |
#multiple_staves? ⇒ Boolean
31 32 33 |
# File 'lib/head_music/notation/instrument_notation.rb', line 31 def multiple_staves? staves.length > 1 end |
#single_staff? ⇒ Boolean
27 28 29 |
# File 'lib/head_music/notation/instrument_notation.rb', line 27 def single_staff? staves.length == 1 end |
#sounding_transposition ⇒ Object
23 24 25 |
# File 'lib/head_music/notation/instrument_notation.rb', line 23 def sounding_transposition staves.first&.sounding_transposition || 0 end |
#staves_attributes ⇒ Object (protected)
48 49 50 |
# File 'lib/head_music/notation/instrument_notation.rb', line 48 def staves_attributes staves.map(&:attributes) end |