Class: MusicSetTheory::NoteSeq
- Inherits:
-
Object
- Object
- MusicSetTheory::NoteSeq
- Includes:
- MusUtility, Temperament
- Defined in:
- lib/music_set_theory/scales.rb,
lib/music_set_theory/scales.rb,
lib/music_set_theory/scales.rb
Direct Known Subclasses
Constant Summary
Constants included from MusUtility
Constants included from Temperament
Temperament::CHROM_NAT_NOTES, Temperament::CHROM_NAT_NOTE_POS, Temperament::CHROM_SIZE, Temperament::MNU_FLAT, Temperament::MNU_NATURAL, Temperament::MNU_SHARP, Temperament::M_FLAT, Temperament::M_NATURAL, Temperament::M_SHARP, Temperament::NSEQ_CHORD, Temperament::NSEQ_SCALE, Temperament::NSEQ_TYPE_HASH, Temperament::RE_NOTEPARSE, Temperament::RE_SHARP, Temperament::WestTemp, Temperament::WestTment
Instance Attribute Summary collapse
-
#nseq_abbrev ⇒ Object
Returns the value of attribute nseq_abbrev.
-
#nseq_name ⇒ Object
Initialiser.
-
#nseq_nat_posns ⇒ Object
Returns the value of attribute nseq_nat_posns.
-
#nseq_other_abbrevs ⇒ Object
Returns the value of attribute nseq_other_abbrevs.
-
#nseq_posn ⇒ Object
Initialiser.
-
#nseq_synonyms ⇒ Object
Returns the value of attribute nseq_synonyms.
-
#nseq_temp ⇒ Object
Initialiser.
-
#nseq_type ⇒ Object
Initialiser.
Instance Method Summary collapse
-
#get_notes_for_key(key, rotate_by = 0, slice = nil) ⇒ Object
Get the notes for the note_seq starting from a given key.
-
#get_posn_for_offset(rotate_by = 0, slice = nil, raz: false) ⇒ Object
For this noteseq, output its positions relative to its first note, then rotates the sequence (by rotate_by), then slices it (using slice, if not none).
-
#initialize(nseq_name, nseq_type, nseq_temp, nseq_posn, nseq_nat_posns, nseq_abbrev: "", nseq_synonyms: [], nseq_other_abbrevs: []) ⇒ NoteSeq
constructor
A new instance of NoteSeq.
-
#register_with_temp(nseq_temp = self.nseq_temp) ⇒ Object
Registers this note sequence with the underlying temperament, so that it can be looked up by name, by abbreviation or by sequence.
Methods included from MusUtility
#deep_freeze, #deep_melt, #enl_seq, #multislice, #norm_seq, #repseq, #rotate, #rotate_and_zero, #scalar_addition, #seqtostr
Methods included from Temperament
#WestTempNew, WestTempNew, #un_unicode_accdtls
Constructor Details
#initialize(nseq_name, nseq_type, nseq_temp, nseq_posn, nseq_nat_posns, nseq_abbrev: "", nseq_synonyms: [], nseq_other_abbrevs: []) ⇒ NoteSeq
Returns a new instance of NoteSeq.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/music_set_theory/scales.rb', line 130 def initialize( nseq_name, nseq_type, nseq_temp, nseq_posn, nseq_nat_posns, # nseq_abbrev = "", nseq_synonyms = [], # nseq_other_abbrevs = [] ) nseq_abbrev: "", nseq_synonyms: [], nseq_other_abbrevs: [] ) self.nseq_name = nseq_name self.nseq_type = nseq_type self.nseq_temp = nseq_temp # self.nseq_temp = deep_melt(nseq_temp.deep_dup) self.nseq_posn = nseq_posn self.nseq_nat_posns = nseq_nat_posns self.nseq_abbrev = nseq_abbrev self.nseq_synonyms = nseq_synonyms self.nseq_other_abbrevs = nseq_other_abbrevs # self.register_with_temp(self.nseq_temp) end |
Instance Attribute Details
#nseq_abbrev ⇒ Object
Returns the value of attribute nseq_abbrev.
128 129 130 |
# File 'lib/music_set_theory/scales.rb', line 128 def nseq_abbrev @nseq_abbrev end |
#nseq_name ⇒ Object
Initialiser. It contains the following arguments.
Args
- nseq_name
the full name of the note sequence.
- nseq_type
the type of note sequence (e.g., NSEQ_SCALE or NSEQ_CHORD).
- nseq_temp
the musical temperament from which the sequence of notes is taken. This should be an instance of the class temperament.
- nseq_posn
a sequence of integers representing positions of the notes in the sequence relative to its first note. (For best results, the first item should be 0 to represent the first note.)
- nseq_nat_posns
a sequence of integers (which should be the same size as nseq_posn). For each item in nseq_posn, the corresponding item in nseq_nat_posns represent the difference in its calculated natural note from the base key's natural note. For example, this parameter is [0, 2, 4] for a major chord; the second note is always two letters higher than the first note, and the third note is two letters higher again. (! this is in degrees.)
- nseq_abbrv
the primary abbreviation for the note sequence (if any).
- nseq_synonyms
a list of possible synonyms, or extra names, for the note sequence. For example, the "Ionian" mode is another name for the major scale as far as this class is concerned.
- nseq_other_abbrevs
a list of possible alternate abbreviations for the note sequence. For example, both "min7" and "m7" are abbreviations for the minor seventh chord.
Examples of defining scales:
- Major scale
NoteSeq.new("Major", NSEQ_SCALE, WestTemp, [0, 2, 4, 5, 7, 9, 11], range(7), nseq_synonyms: ["Ionian"])
- Harmonic Minor scale
NoteSeq.new("Harmonic Minor", NSEQ_SCALE, WestTemp, [0, 2, 3, 5, 7, 8, 11], 0...7);
Examples of defining chords: Major chord: noteseq("Major", NSEQ_CHORD, WestTemp, [0, 4, 7], [0, 2, 4], "maj"); Minor chord: noteseq("Minor", NSEQ_CHORD, WestTemp, [0, 3, 7], [0, 2, 4], "min", nseq_other_abbrevs = ["m"]); Min 7 chord: noteseq("Minor Seventh", NSEQ_CHORD, WestTemp, [0, 3, 7, 11], [0, 2, 4, 6], "min7", nseq_other_abbrevs = ["m7"]);
Note: it is easier to define scales using the noteseq_scale class (this file) and chord using the noteseq_chord class (in chords.py)
Warning
- ! This method updates
nseq_temp.
127 128 129 |
# File 'lib/music_set_theory/scales.rb', line 127 def nseq_name @nseq_name end |
#nseq_nat_posns ⇒ Object
Returns the value of attribute nseq_nat_posns.
128 129 130 |
# File 'lib/music_set_theory/scales.rb', line 128 def nseq_nat_posns @nseq_nat_posns end |
#nseq_other_abbrevs ⇒ Object
Returns the value of attribute nseq_other_abbrevs.
128 129 130 |
# File 'lib/music_set_theory/scales.rb', line 128 def nseq_other_abbrevs @nseq_other_abbrevs end |
#nseq_posn ⇒ Object
Initialiser. It contains the following arguments.
Args
- nseq_name
the full name of the note sequence.
- nseq_type
the type of note sequence (e.g., NSEQ_SCALE or NSEQ_CHORD).
- nseq_temp
the musical temperament from which the sequence of notes is taken. This should be an instance of the class temperament.
- nseq_posn
a sequence of integers representing positions of the notes in the sequence relative to its first note. (For best results, the first item should be 0 to represent the first note.)
- nseq_nat_posns
a sequence of integers (which should be the same size as nseq_posn). For each item in nseq_posn, the corresponding item in nseq_nat_posns represent the difference in its calculated natural note from the base key's natural note. For example, this parameter is [0, 2, 4] for a major chord; the second note is always two letters higher than the first note, and the third note is two letters higher again. (! this is in degrees.)
- nseq_abbrv
the primary abbreviation for the note sequence (if any).
- nseq_synonyms
a list of possible synonyms, or extra names, for the note sequence. For example, the "Ionian" mode is another name for the major scale as far as this class is concerned.
- nseq_other_abbrevs
a list of possible alternate abbreviations for the note sequence. For example, both "min7" and "m7" are abbreviations for the minor seventh chord.
Examples of defining scales:
- Major scale
NoteSeq.new("Major", NSEQ_SCALE, WestTemp, [0, 2, 4, 5, 7, 9, 11], range(7), nseq_synonyms: ["Ionian"])
- Harmonic Minor scale
NoteSeq.new("Harmonic Minor", NSEQ_SCALE, WestTemp, [0, 2, 3, 5, 7, 8, 11], 0...7);
Examples of defining chords: Major chord: noteseq("Major", NSEQ_CHORD, WestTemp, [0, 4, 7], [0, 2, 4], "maj"); Minor chord: noteseq("Minor", NSEQ_CHORD, WestTemp, [0, 3, 7], [0, 2, 4], "min", nseq_other_abbrevs = ["m"]); Min 7 chord: noteseq("Minor Seventh", NSEQ_CHORD, WestTemp, [0, 3, 7, 11], [0, 2, 4, 6], "min7", nseq_other_abbrevs = ["m7"]);
Note: it is easier to define scales using the noteseq_scale class (this file) and chord using the noteseq_chord class (in chords.py)
Warning
- ! This method updates
nseq_temp.
127 128 129 |
# File 'lib/music_set_theory/scales.rb', line 127 def nseq_posn @nseq_posn end |
#nseq_synonyms ⇒ Object
Returns the value of attribute nseq_synonyms.
128 129 130 |
# File 'lib/music_set_theory/scales.rb', line 128 def nseq_synonyms @nseq_synonyms end |
#nseq_temp ⇒ Object
Initialiser. It contains the following arguments.
Args
- nseq_name
the full name of the note sequence.
- nseq_type
the type of note sequence (e.g., NSEQ_SCALE or NSEQ_CHORD).
- nseq_temp
the musical temperament from which the sequence of notes is taken. This should be an instance of the class temperament.
- nseq_posn
a sequence of integers representing positions of the notes in the sequence relative to its first note. (For best results, the first item should be 0 to represent the first note.)
- nseq_nat_posns
a sequence of integers (which should be the same size as nseq_posn). For each item in nseq_posn, the corresponding item in nseq_nat_posns represent the difference in its calculated natural note from the base key's natural note. For example, this parameter is [0, 2, 4] for a major chord; the second note is always two letters higher than the first note, and the third note is two letters higher again. (! this is in degrees.)
- nseq_abbrv
the primary abbreviation for the note sequence (if any).
- nseq_synonyms
a list of possible synonyms, or extra names, for the note sequence. For example, the "Ionian" mode is another name for the major scale as far as this class is concerned.
- nseq_other_abbrevs
a list of possible alternate abbreviations for the note sequence. For example, both "min7" and "m7" are abbreviations for the minor seventh chord.
Examples of defining scales:
- Major scale
NoteSeq.new("Major", NSEQ_SCALE, WestTemp, [0, 2, 4, 5, 7, 9, 11], range(7), nseq_synonyms: ["Ionian"])
- Harmonic Minor scale
NoteSeq.new("Harmonic Minor", NSEQ_SCALE, WestTemp, [0, 2, 3, 5, 7, 8, 11], 0...7);
Examples of defining chords: Major chord: noteseq("Major", NSEQ_CHORD, WestTemp, [0, 4, 7], [0, 2, 4], "maj"); Minor chord: noteseq("Minor", NSEQ_CHORD, WestTemp, [0, 3, 7], [0, 2, 4], "min", nseq_other_abbrevs = ["m"]); Min 7 chord: noteseq("Minor Seventh", NSEQ_CHORD, WestTemp, [0, 3, 7, 11], [0, 2, 4, 6], "min7", nseq_other_abbrevs = ["m7"]);
Note: it is easier to define scales using the noteseq_scale class (this file) and chord using the noteseq_chord class (in chords.py)
Warning
- ! This method updates
nseq_temp.
127 128 129 |
# File 'lib/music_set_theory/scales.rb', line 127 def nseq_temp @nseq_temp end |
#nseq_type ⇒ Object
Initialiser. It contains the following arguments.
Args
- nseq_name
the full name of the note sequence.
- nseq_type
the type of note sequence (e.g., NSEQ_SCALE or NSEQ_CHORD).
- nseq_temp
the musical temperament from which the sequence of notes is taken. This should be an instance of the class temperament.
- nseq_posn
a sequence of integers representing positions of the notes in the sequence relative to its first note. (For best results, the first item should be 0 to represent the first note.)
- nseq_nat_posns
a sequence of integers (which should be the same size as nseq_posn). For each item in nseq_posn, the corresponding item in nseq_nat_posns represent the difference in its calculated natural note from the base key's natural note. For example, this parameter is [0, 2, 4] for a major chord; the second note is always two letters higher than the first note, and the third note is two letters higher again. (! this is in degrees.)
- nseq_abbrv
the primary abbreviation for the note sequence (if any).
- nseq_synonyms
a list of possible synonyms, or extra names, for the note sequence. For example, the "Ionian" mode is another name for the major scale as far as this class is concerned.
- nseq_other_abbrevs
a list of possible alternate abbreviations for the note sequence. For example, both "min7" and "m7" are abbreviations for the minor seventh chord.
Examples of defining scales:
- Major scale
NoteSeq.new("Major", NSEQ_SCALE, WestTemp, [0, 2, 4, 5, 7, 9, 11], range(7), nseq_synonyms: ["Ionian"])
- Harmonic Minor scale
NoteSeq.new("Harmonic Minor", NSEQ_SCALE, WestTemp, [0, 2, 3, 5, 7, 8, 11], 0...7);
Examples of defining chords: Major chord: noteseq("Major", NSEQ_CHORD, WestTemp, [0, 4, 7], [0, 2, 4], "maj"); Minor chord: noteseq("Minor", NSEQ_CHORD, WestTemp, [0, 3, 7], [0, 2, 4], "min", nseq_other_abbrevs = ["m"]); Min 7 chord: noteseq("Minor Seventh", NSEQ_CHORD, WestTemp, [0, 3, 7, 11], [0, 2, 4, 6], "min7", nseq_other_abbrevs = ["m7"]);
Note: it is easier to define scales using the noteseq_scale class (this file) and chord using the noteseq_chord class (in chords.py)
Warning
- ! This method updates
nseq_temp.
127 128 129 |
# File 'lib/music_set_theory/scales.rb', line 127 def nseq_type @nseq_type end |
Instance Method Details
#get_notes_for_key(key, rotate_by = 0, slice = nil) ⇒ Object
Get the notes for the note_seq starting from a given key. Then rotates the sequence (by rotate_by). Then slices it (using the argument in the slice parameter).
234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/music_set_theory/scales.rb', line 234 def get_notes_for_key( key, rotate_by=0, slice=nil ) ret = nil default_seq = self.nseq_temp.get_note_sequence( key, self.nseq_posn, self.nseq_nat_posns); #C modulus = self.nseq_temp.no_nat_keys if slice ret = multislice( default_seq, slice, offset: rotate_by, mod: modulus); else ret = rotate(default_seq, rotate_by); end ret end |
#get_posn_for_offset(rotate_by = 0, slice = nil, raz: false) ⇒ Object
For this noteseq, output its positions relative to its first note, then rotates the sequence (by rotate_by), then slices it (using slice, if not none). If and only if raz is True, the result is rotated-and-zeroed.
See Also
- chord_generator.rb:
populate_scale_chords()
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/music_set_theory/scales.rb', line 256 def get_posn_for_offset( rotate_by=0, slice=nil, raz: false ) if slice modulus = self.nseq_temp.no_nat_keys multisliced = multislice( self.nseq_posn, slice, offset: rotate_by, mod: modulus) if raz return rotate_and_zero(multisliced, 0, self.nseq_temp.no_keys); else return multisliced; end else if raz return rotate_and_zero( self.nseq_posn, rotate_by, self.nseq_temp.no_keys) else return rotate(self.nseq_posn, rotate_by) end end end |
#register_with_temp(nseq_temp = self.nseq_temp) ⇒ Object
Registers this note sequence with the underlying temperament, so that it can be looked up by name, by abbreviation or by sequence.
Warning
- This methods updates
self.nseq_temp
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/music_set_theory/scales.rb', line 202 def register_with_temp( nseq_temp = self.nseq_temp ) if self.nseq_synonyms #if self.nseq_name not in self.nseq_synonyms if !(self.nseq_synonyms.include? self.nseq_name) our_names = [self.nseq_name] + self.nseq_synonyms; else our_names = self.nseq_synonyms; end else our_names = [self.nseq_name]; end if self.nseq_other_abbrevs #if self.nseq_abbrev not in self.nseq_other_abbrevs if !(self.nseq_other_abbrevs.include? self.nseq_abbrev) our_abbrevs = [self.nseq_abbrev] + self.nseq_other_abbrevs else our_abbrevs = self.nseq_other_abbrevs end else our_abbrevs = [self.nseq_abbrev] end # nseq_temp.seq_maps.add_elem( self, self.nseq_type, our_names, our_abbrevs, self.nseq_posn) end |