Class: HeadMusic::Notation::InstrumentNotation

Inherits:
Object
  • Object
show all
Includes:
ValueEquality
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

Instance Method Summary collapse

Constructor Details

#initialize(instrument:, data:) ⇒ InstrumentNotation

Returns a new instance of InstrumentNotation.



17
18
19
20
21
22
# File 'lib/head_music/notation/instrument_notation.rb', line 17

def initialize(instrument:, data:)
  @instrument = instrument
  @staves = build_staves(data["staves"])
  @alternatives = build_staves(data["alternatives"])
  freeze
end

Instance Attribute Details

#alternativesObject (readonly)

Returns the value of attribute alternatives.



12
13
14
# File 'lib/head_music/notation/instrument_notation.rb', line 12

def alternatives
  @alternatives
end

#instrumentObject (readonly)

Returns the value of attribute instrument.



12
13
14
# File 'lib/head_music/notation/instrument_notation.rb', line 12

def instrument
  @instrument
end

#stavesObject (readonly)

Returns the value of attribute staves.



12
13
14
# File 'lib/head_music/notation/instrument_notation.rb', line 12

def staves
  @staves
end

Instance Method Details

#==(other) ⇒ Object Originally defined in module ValueEquality

#build_staves(list) ⇒ Object (private)



52
53
54
# File 'lib/head_music/notation/instrument_notation.rb', line 52

def build_staves(list)
  (list || []).map { |attributes| HeadMusic::Instruments::Staff.new(nil, attributes) }
end

#clefsObject



24
25
26
# File 'lib/head_music/notation/instrument_notation.rb', line 24

def clefs
  staves.map(&:clef)
end

#hashObject



40
41
42
# File 'lib/head_music/notation/instrument_notation.rb', line 40

def hash
  [instrument.name_key, staves_attributes].hash
end

#multiple_staves?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/head_music/notation/instrument_notation.rb', line 36

def multiple_staves?
  staves.length > 1
end

#single_staff?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/head_music/notation/instrument_notation.rb', line 32

def single_staff?
  staves.length == 1
end

#sounding_transpositionObject



28
29
30
# File 'lib/head_music/notation/instrument_notation.rb', line 28

def sounding_transposition
  staves.first&.sounding_transposition || 0
end

#staves_attributesObject (protected)



46
47
48
# File 'lib/head_music/notation/instrument_notation.rb', line 46

def staves_attributes
  staves.map(&:attributes)
end