Class: MiltonsMachine::Core::ForteSet
- Inherits:
-
Array
- Object
- Array
- MiltonsMachine::Core::ForteSet
- Defined in:
- lib/miltons_machine/core/forte_set.rb
Overview
Class: Forte Set
An extention to the basic Array class of Ruby to allow for modulus 12 operations and transformations related to musical set theoretics.
TODO Add method to allow for subset search with an array of forte sets
Class Method Summary (collapse)
-
+ (Integer) invert_pc(pitch_class)
Given a musical pitch, return the inversion of the pitch.
-
+ (Integer) pc_from_alpha(pitch_class)
Convert String representation of a pitch to an Integer representation.
-
+ (String) pc_to_alpha(pitch_class)
Convert Integer representation of a pitch to a String representation.
-
+ (String) pc_to_chromatic(pitch_class)
Convert Integer representation of a pitch to a String representation from the chromatic scale.
-
+ (Array) search_for_subsets(source_set, search_sets)
Given a set and an array of subsets to search for, this method will return true or false on each one found.
-
+ (Integer) transpose_pc(pitch_class, number_to_transpose = 0)
Given a musical pitch, and how many 1/2 steps you want to transpose it, returns a new pitch at the new transposition.
Instance Method Summary (collapse)
-
- (ForteSet) compare_compact_sets(compare_set)
Compare two sets and return the most compact version.
-
- (ForteSet) complement_mod12
Return the complement of this set.
-
- (ForteSet) complement_mod12!
Replace with the complement of this set.
-
- (ForteSet) convert_set_from_alpha
Converts the set from alpha representation to pc numbers and return a copy.
-
- (ForteSet) convert_set_from_alpha!
Converts the set in place from alpha representation to pc numbers and return a reference.
-
- (ForteSet) convert_set_to_alpha
Converts the set from numeric representation to alphanumeric and return a copy.
-
- (ForteSet) convert_set_to_alpha!
Converts the set in place from numeric representation to alphanumeric and return a reference.
-
- (ForteSet) convert_set_to_chromatic
Converts the set in place from numeric representation to a representation from the chromatic scale.
-
- (ForteSet) invert_mod12
Return the inversion of this set.
-
- (ForteSet) invert_mod12!
Invert the set in place and return a reference.
-
- (ForteSet) normalize_mod12
Returns the most compact order of a set.
-
- (ForteSet) normalize_mod12!
Normalizes the set in place and returns a reference to the set.
-
- (ForteSet) prime_mod12
Return the prime version of the set.
-
- (ForteSet) prime_mod12!
Set the prime version of the set in place and return a reference.
-
- (ForteSet) reduce_mod12
Normalize and zero down the set, returning a copy.
-
- (ForteSet) reduce_mod12!
Normalize and zero down the set in place, returning a reference to the set.
-
- (ForteSet) transpose_mod12(number_to_transpose = 0)
Returns a copy of the set at a new transposition.
-
- (ForteSet) transpose_mod12!(number_to_transpose = 0)
Transposes the set in place and returns a reference to the set at the new transposition.
-
- (ForteSet) zero_mod12
Return a copy of the set with all elements transposed so that the first element is set to zero.
-
- (ForteSet) zero_mod12!
Zero the set in place, so that all element transposed so that the first element is set to zero.
Class Method Details
+ (Integer) invert_pc(pitch_class)
Given a musical pitch, return the inversion of the pitch
300 301 302 |
# File 'lib/miltons_machine/core/forte_set.rb', line 300 def self.invert_pc( pitch_class ) (12 - pitch_class) % 12 end |
+ (Integer) pc_from_alpha(pitch_class)
Convert String representation of a pitch to an Integer representation
310 311 312 313 314 315 316 317 |
# File 'lib/miltons_machine/core/forte_set.rb', line 310 def self.pc_from_alpha( pitch_class ) case pitch_class.to_s when 'A', 'a' then 10 when 'B', 'b' then 11 when 'C', 'c' then 12 else pitch_class.to_i end end |
+ (String) pc_to_alpha(pitch_class)
Convert Integer representation of a pitch to a String representation
325 326 327 328 329 330 331 332 |
# File 'lib/miltons_machine/core/forte_set.rb', line 325 def self.pc_to_alpha( pitch_class ) case pitch_class.to_i when 10 then 'A' when 11 then 'B' when 12 then 'C' else pitch_class.to_s end end |
+ (String) pc_to_chromatic(pitch_class)
Convert Integer representation of a pitch to a String representation from the chromatic scale
for example: 3 would return "D#/Eb"
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/miltons_machine/core/forte_set.rb', line 263 def self.pc_to_chromatic( pitch_class ) case pitch_class when 0 then 'C' when 1 then 'C#/Db' when 2 then 'D' when 3 then 'D#/Eb' when 4 then 'E' when 5 then 'F' when 6 then 'F#/Gb' when 7 then 'G' when 8 then 'G#/Ab' when 9 then 'A' when 10 then 'A#/Bb' when 11 then 'B' else 'unknown' end end |
+ (Array) search_for_subsets(source_set, search_sets)
Given a set and an array of subsets to search for, this method will return true or false on each one found
244 245 246 247 248 249 250 251 252 253 |
# File 'lib/miltons_machine/core/forte_set.rb', line 244 def self.search_for_subsets(source_set, search_sets) sonority = Set.new(source_set) set_to_search = Set.new results = [] search_sets.each do |search_set| set_to_search.replace(search_set) set_to_search.subset?(sonority) ? results << true : results << false end [search_sets.clone, results] end |
+ (Integer) transpose_pc(pitch_class, number_to_transpose = 0)
Given a musical pitch, and how many 1/2 steps you want to transpose it, returns a new pitch at the new transposition
290 291 292 |
# File 'lib/miltons_machine/core/forte_set.rb', line 290 def self.transpose_pc( pitch_class, number_to_transpose = 0 ) (pitch_class + number_to_transpose) % 12 end |
Instance Method Details
- (ForteSet) compare_compact_sets(compare_set)
Compare two sets and return the most compact version
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/miltons_machine/core/forte_set.rb', line 169 def compare_compact_sets( compare_set ) winner = clone # Assume the set is the winner going in. working_set = compare_set.clone winner.reverse! working_set.reverse! # Work backwards checking largest interval edge working_set.each_index do |working_last_index| compare_interval1 = (winner[working_last_index] - winner.at(-1)) % 12 compare_interval2 = (working_set[working_last_index] - working_set.at(-1)) % 12 if compare_interval2 == compare_interval1 next # equal, so loop back for next outer interval elsif compare_interval2 < compare_interval1 # new winner else assume #1 is good enough. winner = working_set.clone end break end winner.reverse! end |
- (ForteSet) complement_mod12
Return the complement of this set
66 67 68 |
# File 'lib/miltons_machine/core/forte_set.rb', line 66 def complement_mod12 ForteSet.new(12) { |i| i } - self end |
- (ForteSet) complement_mod12!
Replace with the complement of this set
75 76 77 |
# File 'lib/miltons_machine/core/forte_set.rb', line 75 def complement_mod12! replace( complement_mod12 ) end |
- (ForteSet) convert_set_from_alpha
Converts the set from alpha representation to pc numbers and return a copy
195 196 197 198 |
# File 'lib/miltons_machine/core/forte_set.rb', line 195 def convert_set_from_alpha return_set = clone return_set.collect! { |pc| pc = MiltonsMachine::Core::ForteSet.pc_from_alpha(pc) } end |
- (ForteSet) convert_set_from_alpha!
Converts the set in place from alpha representation to pc numbers and return a reference
205 206 207 |
# File 'lib/miltons_machine/core/forte_set.rb', line 205 def convert_set_from_alpha! replace( convert_set_from_alpha ) end |
- (ForteSet) convert_set_to_alpha
Converts the set from numeric representation to alphanumeric and return a copy
214 215 216 217 |
# File 'lib/miltons_machine/core/forte_set.rb', line 214 def convert_set_to_alpha return_set = clone return_set.collect! { |pc| pc = MiltonsMachine::Core::ForteSet.pc_to_alpha(pc) } end |
- (ForteSet) convert_set_to_alpha!
Converts the set in place from numeric representation to alphanumeric and return a reference
224 225 226 |
# File 'lib/miltons_machine/core/forte_set.rb', line 224 def convert_set_to_alpha! replace( convert_set_to_alpha ) end |
- (ForteSet) convert_set_to_chromatic
Converts the set in place from numeric representation to a representation from the chromatic scale
233 234 235 236 |
# File 'lib/miltons_machine/core/forte_set.rb', line 233 def convert_set_to_chromatic return_set = clone return_set.collect! { |pc| pc = MiltonsMachine::Core::ForteSet.pc_to_chromatic(pc) } end |
- (ForteSet) invert_mod12
Return the inversion of this set
47 48 49 50 |
# File 'lib/miltons_machine/core/forte_set.rb', line 47 def invert_mod12 return_set = clone return_set.collect! { |pc| pc = MiltonsMachine::Core::ForteSet.invert_pc(pc) } end |
- (ForteSet) invert_mod12!
Invert the set in place and return a reference
57 58 59 |
# File 'lib/miltons_machine/core/forte_set.rb', line 57 def invert_mod12! replace( invert_mod12 ) end |
- (ForteSet) normalize_mod12
Returns the most compact order of a set
105 106 107 108 109 110 111 112 113 |
# File 'lib/miltons_machine/core/forte_set.rb', line 105 def normalize_mod12 winner = clone winner.sort! working_set = winner.clone # Pick the best winner out of the lot of permutations 0.upto(length - 2) { winner = winner.compare_compact_sets( working_set.rotate!(1) ) } winner end |
- (ForteSet) normalize_mod12!
Normalizes the set in place and returns a reference to the set
120 121 122 |
# File 'lib/miltons_machine/core/forte_set.rb', line 120 def normalize_mod12! replace( normalize_mod12 ) end |
- (ForteSet) prime_mod12
Return the prime version of the set
148 149 150 151 152 |
# File 'lib/miltons_machine/core/forte_set.rb', line 148 def prime_mod12 prime_form = normalize_mod12.zero_mod12 inverted_form = invert_mod12.normalize_mod12.zero_mod12 prime_form.compare_compact_sets(inverted_form) end |
- (ForteSet) prime_mod12!
Set the prime version of the set in place and return a reference
159 160 161 |
# File 'lib/miltons_machine/core/forte_set.rb', line 159 def prime_mod12! replace( prime_mod12 ) end |
- (ForteSet) reduce_mod12
Normalize and zero down the set, returning a copy
129 130 131 132 |
# File 'lib/miltons_machine/core/forte_set.rb', line 129 def reduce_mod12 return_set = normalize_mod12 return_set.zero_mod12! end |
- (ForteSet) reduce_mod12!
Normalize and zero down the set in place, returning a reference to the set
139 140 141 |
# File 'lib/miltons_machine/core/forte_set.rb', line 139 def reduce_mod12! replace( reduce_mod12 ) end |
- (ForteSet) transpose_mod12(number_to_transpose = 0)
Returns a copy of the set at a new transposition
27 28 29 30 |
# File 'lib/miltons_machine/core/forte_set.rb', line 27 def transpose_mod12( number_to_transpose = 0 ) return_set = clone return_set.collect! { |pc| pc = MiltonsMachine::Core::ForteSet.transpose_pc(pc, number_to_transpose) } end |
- (ForteSet) transpose_mod12!(number_to_transpose = 0)
Transposes the set in place and returns a reference to the set at the new transposition
38 39 40 |
# File 'lib/miltons_machine/core/forte_set.rb', line 38 def transpose_mod12!( number_to_transpose = 0 ) replace( transpose_mod12(number_to_transpose) ) end |
- (ForteSet) zero_mod12
Return a copy of the set with all elements transposed so that the first element is set to zero.
84 85 86 87 88 |
# File 'lib/miltons_machine/core/forte_set.rb', line 84 def zero_mod12 number_to_transpose = 0 self[0] == 0 ? number_to_transpose = 0 : number_to_transpose = 12 - self[0] transpose_mod12(number_to_transpose) end |
- (ForteSet) zero_mod12!
Zero the set in place, so that all element transposed so that the first element is set to zero. Return a reference to the result.
96 97 98 |
# File 'lib/miltons_machine/core/forte_set.rb', line 96 def zero_mod12! replace( zero_mod12 ) end |