Skip to content

Commit 49361da

Browse files
committed
Added new "scalenator" method and some helpers for forte & ais sets
New "scalenator" method can be used to create new scales from anything from it's binary form that is turned to interval array. See wiki info for scaled for more info. Forte & AIS sets yet to be documented.
1 parent 1669416 commit 49361da

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

lib/generators.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,27 @@ def bools_to_durations(arr, default_dur=1.0, rhythm_map=nil)
152152
end
153153
end
154154

155-
def parse_binary(val, default_dur=1.0, rhythm_map=nil)
155+
def parse_binary_as_rhythm(val, default_dur=1.0, rhythm_map=nil)
156+
bools_to_durations(parse_binary(val), default_dur, rhythm_map)
157+
end
158+
159+
def parse_binary(val)
156160
if val.is_a?(Integer)
157-
bools_to_durations(val.to_s(2).split("").map{|b| b=="1" ? true : false }.flatten, default_dur, rhythm_map)
161+
val.to_s(2).split("").map{|b| b=="1" ? true : false }.flatten
158162
elsif val.is_a?(String)
159-
bools_to_durations(val.bytes.map {|v| v.to_s(2).split("").map{|b| b=="1" ? true : false } }.flatten, default_dur, rhythm_map)
163+
val.bytes.map {|v| v.to_s(2).split("").map{|b| b=="1" ? true : false } }.flatten
160164
elsif val.is_a?(Array) or val.is_a?(SonicPi::Core::RingVector)
161-
bools_to_durations(val,default_dur,rhythm_map)
165+
val
162166
else
163-
raise "Not that shit!"
167+
raise "Could not parse binary!"
164168
end
165169
end
166170

171+
# Creates "scales" out of things
172+
def scalenator(val)
173+
bools_to_intervals(parse_binary(val))
174+
end
175+
167176
# Tonnetz moves
168177
def get_move(move,triad)
169178
moves = {

lib/pc_sets.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
# From http //www.stephenandrewtaylor.net/setfinder/index.html
1+
module Ziffers
2+
3+
def forte(n)
4+
if n.is_a?(String)
5+
r = FORTE.key(n)
6+
elsif n.is_a?(Integer)
7+
r = FORTE.keys[n]
8+
elsif n.is_a?(Array)
9+
r = n.sort
10+
r = FORTE[r]
11+
r = "No forte name for: "+n.to_s if !r
12+
end
13+
r ? r : []
14+
end
215

16+
# From http //www.stephenandrewtaylor.net/setfinder/index.html
317
FORTE = {
418
[0, 1, 2] => "3-1",
519
[0, 1, 3] => "3-2",
@@ -211,6 +225,19 @@
211225
[0, 1, 2, 4, 5, 6, 8, 9, 10] => "9-12"
212226
}
213227

228+
def ais(n)
229+
if n.is_a?(String)
230+
r = AIS.key(n)
231+
elsif n.is_a?(Integer)
232+
r = AIS.keys[n]
233+
elsif n.is_a?(Array)
234+
r = n.sort
235+
r = AIS[r]
236+
r = "Not an AIS name for: "+n.to_s if !r
237+
end
238+
r ? r : []
239+
end
240+
214241
# From https //github.com/marcobn/TheHichhikersGuideToAIS
215242
AIS = {
216243
[0, 1, 3, 7, 2, 5, 11, 10, 8, 4, 9, 6] => "12-0P",
@@ -1132,3 +1159,5 @@
11321159
[0, 4, 3, 1, 9, 11, 8, 2, 7, 10, 5, 6] => "12-916",
11331160
[0, 4, 3, 1, 9, 2, 8, 5, 7, 10, 11, 6] => "12-917L"
11341161
}
1162+
1163+
end

lib/ziffarray.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,12 @@ def modify_rhythm(val, loop_n=0, rhythm_map=nil)
571571
new_arr = self.deep_clone
572572
val = val.() if val.is_a? Proc
573573
if val.is_a?(Array) and (!val.union([true,false]).difference([true,false]).any? or !val.union([1,0]).difference([1,0]).any?)
574-
pattern = parse_binary(val, 1.0, rhythm_map) # If boolean or bool as int array
574+
pattern = parse_binary_as_rhythm(val, 1.0, rhythm_map) # If boolean or bool as int array
575575
elsif val.is_a?(Array)
576576
pattern = val.map {|v| v.is_a?(Float) ? v : int_to_length(v)}
577577
elsif val.is_a?(SonicPi::Core::RingVector)
578578
if !val.to_a.union([true,false]).difference([true,false]).any? or !val.to_a.union([1,0]).difference([1,0]).any?
579-
pattern = parse_binary(val, 1.0, rhythm_map) # If boolean ring
579+
pattern = parse_binary_as_rhythm(val, 1.0, rhythm_map) # If boolean ring
580580
else
581581
pattern = val.map {|v| v.is_a?(Float) ? v : int_to_length(v)}
582582
end
@@ -589,7 +589,7 @@ def modify_rhythm(val, loop_n=0, rhythm_map=nil)
589589
pattern = map_pcs_to_durations(numbers)
590590
elsif val[:binary]
591591
val[:binary] = val[:binary].() if val[:binary].is_a? Proc
592-
pattern = parse_binary(val[:binary], (val[:ratio] ? val[:ratio] : 1.0), rhythm_map)
592+
pattern = parse_binary_as_rhythm(val[:binary], (val[:ratio] ? val[:ratio] : 1.0), rhythm_map)
593593
elsif val[:minor] and val[:major]
594594
pattern = schillinger(val, rhythm_map)
595595
elsif val[:pattern]

0 commit comments

Comments
 (0)