Class: HeadMusic::Notation::InstrumentNotation

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



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

#alternativesObject (readonly)

Returns the value of attribute alternatives.



10
11
12
# File 'lib/head_music/notation/instrument_notation.rb', line 10

def alternatives
  @alternatives
end

#instrumentObject (readonly)

Returns the value of attribute instrument.



10
11
12
# File 'lib/head_music/notation/instrument_notation.rb', line 10

def instrument
  @instrument
end

#stavesObject (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

#clefsObject



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

def clefs
  staves.map(&:clef)
end

#hashObject



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

Returns:

  • (Boolean)


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

def multiple_staves?
  staves.length > 1
end

#single_staff?Boolean

Returns:

  • (Boolean)


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

def single_staff?
  staves.length == 1
end

#sounding_transpositionObject



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

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

#staves_attributesObject (protected)



48
49
50
# File 'lib/head_music/notation/instrument_notation.rb', line 48

def staves_attributes
  staves.map(&:attributes)
end