Class: Stretto::MusicElements::Chord
- Inherits:
-
MusicElement
- Object
- MusicElement
- Stretto::MusicElements::Chord
- Extended by:
- Forwardable
- Includes:
- AttackDecay, Duration
- Defined in:
- lib/stretto/music_elements/chord.rb,
lib/stretto/music_elements/modifiers/chord_intervals.rb
Overview
A chord indicates a group of notes that can be played together.
The most common chord is a named chord. This is indicated by a note string (see Note) and the name of the chord. For example, chord C major is represented by Cmaj
, and it will consist on the notes C, E and G (for definition, according to the musical theory).
The chord can also indicate a duration (see Duration) and attack and decay (see AttackDecay), which have to be inserted after the named chord. For example, the chord C#5maj7wa80d100 has a base note of C#5, is the major 7th chord (maj7
) with a whole duration (w
), and has attack 80 and decay 100 (a80d100
). The default octave for chords is 3
For a list of supported chords see the JFugue reference guide, or the source code for CHORD_INTERVALS
A chord can be inverted; that is, some of its notes is raised or lowered an octave, also called as the voicing of a chord. Chord inversions can be specified by two ways. The first one is to indicate with the symbol ^ the number of notes that will be raised a whole octave (for example, the chord C5maj
will have notes C5, E5 and G5, its inversion C5maj^
will have E5, G5 and E6, and C5maj^^ notes G5, C6 and E6). The other way is to indicate explicitely the pivot note to invert from (the note C5maj^E5 is equivalent to the first inversion). It will raise an error if a chord is tried to be inverted by a note that is not part of the chord.
This class can also hold non-regular chords, called harmonic chords. See HarmonicChord
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_OCTAVE =
3
- CHORD_INTERVALS =
The literal names of chord intervals. Values represent the semitones from the base note of the notes that form the chord.
{ 'maj' => [4, 7], 'min' => [3, 7], 'aug' => [4, 8], 'dim' => [3, 6], 'dom7' => [4, 7, 10], 'maj7' => [4, 7, 11], 'min7' => [3, 7, 10], 'sus4' => [5, 7], 'sus2' => [2, 7], 'maj6' => [4, 7, 9], 'min6' => [3, 7, 9], 'dom9' => [4, 7, 10, 14], 'maj9' => [4, 7, 11, 14], 'min9' => [3, 7, 10, 14], 'dim7' => [3, 6, 9], 'add9' => [4, 7, 14], 'min11' => [7, 10, 14, 15, 17], 'dom11' => [7, 10, 14, 17], 'dom13' => [7, 10, 14, 16, 21], 'min13' => [7, 10, 14, 15, 21], 'maj13' => [7, 11, 14, 16, 21], 'dom7<5' => [4, 6, 10], 'dom7>5' => [4, 8, 10], 'maj7<5' => [4, 6, 11], 'maj7>5' => [4, 8, 11], 'minmaj7' => [3, 7, 11], 'dom7<5<9' => [4, 6, 10, 13], 'dom7<5>9' => [4, 6, 10, 15], 'dom7>5<9' => [4, 8, 10, 13], 'dom7>5>9' => [4, 8, 10, 15] }
Constants included from AttackDecay
AttackDecay::DEFAULT_ATTACK, AttackDecay::DEFAULT_DECAY
Constants included from Duration
Duration::DEFAULT_DURATION, Duration::DEFAULT_TUPLET_DENOMINATOR, Duration::DEFAULT_TUPLET_NUMERATOR, Duration::DURATIONS
Instance Attribute Summary collapse
-
#instrument ⇒ Object
Returns the value of attribute instrument.
-
#key_signature ⇒ Object
Returns the value of attribute key_signature.
-
#named_chord ⇒ Object
readonly
Returns the value of attribute named_chord.
-
#original_named_chord ⇒ Object
readonly
Returns the value of attribute original_named_chord.
Attributes included from AttackDecay
#original_attack, #original_decay
Attributes included from Duration
#end_tie, #original_duration, #start_tie
Attributes inherited from MusicElement
Attributes included from Node
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
True if all the notes of the chord are equal.
-
#base_note ⇒ Object
Returns the base note of the chord, that is, the note the chord was specified with.
-
#initialize(string_or_options, pattern = nil) ⇒ Chord
constructor
A new instance of Chord.
-
#inversions ⇒ Number
The number of inversions of the chord.
-
#notes ⇒ Array(MusicElements::Note)
The array of notes generated by this chord.
-
#pivot_note ⇒ MusicElements::Note
The pivot note in which do the inversion, if specified.
Methods included from AttackDecay
#attack, #attack=, #build_attack_and_decay, #decay, #decay=
Methods included from Duration
#build_duration_from_token, #duration, #end_of_tie?, parse_duration, #start_of_tie?, #tied_duration, #tied_elements
Methods inherited from MusicElement
#build_music_string, #duration, #end_of_tie?, #start_of_tie?, #to_s
Constructor Details
#initialize(string_or_options, pattern = nil) ⇒ Chord
Returns a new instance of Chord.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/stretto/music_elements/chord.rb', line 54 def initialize(, pattern = nil) token = case when String then Stretto::Parser.parse_chord!() else end super(token[:text_value], pattern) unless @notes = token[:notes] build_duration_from_token(token[:duration]) @original_base_note = token[:base_note] @original_named_chord = token[:named_chord] @named_chord = @original_named_chord.downcase @original_inversions = token[:inversions] @base_note = base_note build_attack_and_decay(token[:attack], token[:decay]) end end |
Instance Attribute Details
#instrument ⇒ Object
Returns the value of attribute instrument.
44 45 46 |
# File 'lib/stretto/music_elements/chord.rb', line 44 def instrument @instrument end |
#key_signature ⇒ Object
Returns the value of attribute key_signature.
43 44 45 |
# File 'lib/stretto/music_elements/chord.rb', line 43 def key_signature @key_signature end |
#named_chord ⇒ Object (readonly)
Returns the value of attribute named_chord.
42 43 44 |
# File 'lib/stretto/music_elements/chord.rb', line 42 def named_chord @named_chord end |
#original_named_chord ⇒ Object (readonly)
Returns the value of attribute original_named_chord.
42 43 44 |
# File 'lib/stretto/music_elements/chord.rb', line 42 def original_named_chord @original_named_chord end |
Instance Method Details
#==(other) ⇒ Boolean
Returns True if all the notes of the chord are equal.
91 92 93 |
# File 'lib/stretto/music_elements/chord.rb', line 91 def ==(other) notes && notes == other.notes end |
#base_note ⇒ Object
Returns the base note of the chord, that is, the note the chord was specified with.
Note that this is not necessarily equal to the first note in the chord. If it has inversions, the base note will be kept as the original note, but the notes
construct will be effectively transposed.
85 86 87 |
# File 'lib/stretto/music_elements/chord.rb', line 85 def base_note @base_note || build_base_note(@original_base_note) end |
#inversions ⇒ Number
Returns The number of inversions of the chord.
98 99 100 101 |
# File 'lib/stretto/music_elements/chord.rb', line 98 def inversions build_inversions unless @inversions @inversions end |
#notes ⇒ Array(MusicElements::Note)
Returns The array of notes generated by this chord.
72 73 74 75 76 77 78 |
# File 'lib/stretto/music_elements/chord.rb', line 72 def notes unless @notes build_chord_notes(@named_chord) build_inversions end @notes end |
#pivot_note ⇒ MusicElements::Note
Returns The pivot note in which do the inversion, if specified.
106 107 108 109 |
# File 'lib/stretto/music_elements/chord.rb', line 106 def pivot_note build_inversions unless @pivot_note @pivot_note end |