Class: HeadMusic::GrandStaff

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/grand_staff.rb

Overview

A grand staff is a group of staves for a single instrument, such as a piano.

Constant Summary collapse

GRAND_STAVES =
{
  piano: {
    instrument: :piano,
    staves: [
      {clef: :treble_clef, for: :right_hand},
      {clef: :bass_clef, for: :left_hand}
    ]
  },
  organ: {
    instrument: :organ,
    staves: [
      {clef: :treble_clef, for: :right_hand},
      {clef: :bass_clef, for: :left_hand},
      {clef: :bass_clef, for: :pedals}
    ]
  }
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ GrandStaff

Returns a new instance of GrandStaff.



33
34
35
36
# File 'lib/head_music/grand_staff.rb', line 33

def initialize(name)
  @identifier = HeadMusic::Utilities::HashKey.for(name)
  @data = GRAND_STAVES[identifier]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#identifierObject (readonly)

Returns the value of attribute identifier.



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

def identifier
  @identifier
end

Class Method Details

.get(name) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/head_music/grand_staff.rb', line 23

def self.get(name)
  @grand_staves ||= {}
  hash_key = HeadMusic::Utilities::HashKey.for(name)
  return nil unless GRAND_STAVES.key?(hash_key)

  @grand_staves[hash_key] ||= new(hash_key)
end

Instance Method Details

#brace_staves_index_firstObject



49
50
51
# File 'lib/head_music/grand_staff.rb', line 49

def brace_staves_index_first
  0
end

#brace_staves_index_lastObject



53
54
55
# File 'lib/head_music/grand_staff.rb', line 53

def brace_staves_index_last
  1
end

#instrumentObject



38
39
40
# File 'lib/head_music/grand_staff.rb', line 38

def instrument
  @instrument ||= HeadMusic::Instrument.get(data[:instrument])
end

#stavesObject



42
43
44
45
46
47
# File 'lib/head_music/grand_staff.rb', line 42

def staves
  @staves ||=
    data[:staves].map do |staff|
      HeadMusic::Staff.new(staff[:clef], instrument: instrument)
    end
end