Class: Stretto::Tokens::ChordToken

Inherits:
HashToken
  • Object
show all
Includes:
WithAttackDecayToken, WithDurationToken, WithNoteStringToken
Defined in:
lib/stretto/grammar/tokens/chord_token.rb

Overview

Parses a named chord

@example: “C5#maj”

Instance Method Summary collapse

Methods included from WithAttackDecayToken

#attack, #decay

Methods included from WithNoteStringToken

#accidental, #key, #octave, #pitch

Methods included from WithDurationToken

#duration

Methods inherited from HashToken

#[]

Instance Method Details

#base_noteObject

Returns a base note hash, which can be seen as a token returned by the parsed note



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/stretto/grammar/tokens/chord_token.rb', line 25

def base_note
  {
      :text_value => note_string.text_value,
      :key        => key,
      :pitch      => pitch,
      :accidental => accidental,
      :octave     => octave,
      :attack     => attack,
      :decay      => decay,
      :duration   => duration
  }
end

#inversionsObject

If inversions are present, return a hash containing the pivot note

(e.g. "^C") or the number of inversions (e.g. 5)


51
52
53
54
55
56
# File 'lib/stretto/grammar/tokens/chord_token.rb', line 51

def inversions
  if __chord_inversions and __chord_inversions.text_value.present?
    { :inversions => __chord_inversions.inversions,
      :pivot_note => __chord_inversions.pivot_note }
  end
end

#named_chordObject

Returns A string containing the named chord.

Examples:

“sus4”

Returns:

  • A string containing the named chord



45
46
47
# File 'lib/stretto/grammar/tokens/chord_token.rb', line 45

def named_chord
  __named_chord.text_value
end

#note_stringNoteStringToken

Returns:

  • (NoteStringToken)


39
40
41
# File 'lib/stretto/grammar/tokens/chord_token.rb', line 39

def note_string
  __note_string
end

#notesObject

Don’t precalculate values. Added for harmonic chords to be able to be constructed from a chord token.



61
62
63
# File 'lib/stretto/grammar/tokens/chord_token.rb', line 61

def notes
  nil
end

#to_stretto(pattern = nil) ⇒ MusicElements::Chord

Returns The constructed Chord element.

Returns:



19
20
21
# File 'lib/stretto/grammar/tokens/chord_token.rb', line 19

def to_stretto(pattern = nil)
  Stretto::MusicElements::Chord.new(self, pattern)
end