Class: Stretto::Tokens::HarmonyWithMelodyToken

Inherits:
HashToken
  • Object
show all
Defined in:
lib/stretto/grammar/tokens/harmony_with_melody_token.rb

Overview

Token result from parsing a harmony

Examples:

“Cmajh+Dh_+Ew”

Instance Method Summary collapse

Methods inherited from HashToken

#[]

Instance Method Details

#music_elementsArray(MusicElements::MusicElement)

Returns AN array of the music elements that form the harmony.

Returns:



27
28
29
# File 'lib/stretto/grammar/tokens/harmony_with_melody_token.rb', line 27

def music_elements
  @music_elements ||= harmony_elements(@pattern)
end

#to_stretto(pattern = nil) ⇒ MusicElements::Harmony, MusicElements::Melody

Returns the constructed Harmony or Melody object. It is a Harmony when there is more than one element (e.g. “A+B_C”)

Returns:



16
17
18
19
20
21
22
23
24
# File 'lib/stretto/grammar/tokens/harmony_with_melody_token.rb', line 16

def to_stretto(pattern = nil)
  @pattern = pattern
  music_elements = harmony_elements(pattern)
  if music_elements.size == 1 and music_elements.first.kind_of?(Stretto::MusicElements::Melody)
    music_elements.first
  else
    Stretto::MusicElements::Harmony.new(self, pattern)
  end
end