Class: Stretto::MusicElements::Harmony

Inherits:
MusicElement show all
Defined in:
lib/stretto/music_elements/harmony.rb

Overview

Represents a group of notes, chords and rests of different lengths that should play together.

It is similar to a HarmonicChord (see HarmonicChord with the difference that it can also include rests and melodies (see Melody)

Instance Attribute Summary collapse

Attributes inherited from MusicElement

#original_string, #pattern

Attributes included from Node

#next, #prev

Instance Method Summary collapse

Methods inherited from MusicElement

#build_music_string, #end_of_tie?, #start_of_tie?, #substitute_variables!, #to_s

Constructor Details

#initialize(string_or_options, pattern = nil) ⇒ Harmony

Returns a new instance of Harmony.



15
16
17
18
19
20
21
22
# File 'lib/stretto/music_elements/harmony.rb', line 15

def initialize(string_or_options, pattern = nil)
  token = case string_or_options
    when String then Stretto::Parser.parse_harmony!(string_or_options)
    else string_or_options
  end
  super(token[:text_value], pattern)
  @elements = token[:music_elements]
end

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



13
14
15
# File 'lib/stretto/music_elements/harmony.rb', line 13

def elements
  @elements
end

Instance Method Details

#durationObject



25
26
27
# File 'lib/stretto/music_elements/harmony.rb', line 25

def duration
  @elements.map(&:duration).max
end

#pattern=(pattern) ⇒ Object



30
31
32
# File 'lib/stretto/music_elements/harmony.rb', line 30

def pattern=(pattern)
  @elements.each { |element| element.pattern = pattern }
end