-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.rb
More file actions
89 lines (86 loc) · 2.24 KB
/
utils.rb
File metadata and controls
89 lines (86 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
define :change_tempo do |new_tempo, step = 1|
tempo = if current_bpm == new_tempo
current_bpm
elsif current_bpm < new_tempo
current_bpm + step
else
current_bpm - step
end
set_link_bpm! tempo
end
define :psample do |options, **kwargs|
# wrapper for sample method
# also accepts hashes with name and option values
defaults = {
name: nil,
rate: nil,
beat_stretch: nil,
pitch_stretch: nil,
attack: nil,
sustain: nil,
release: nil,
start: nil,
finish: nil,
pan: nil,
amp: nil,
onset: nil,
num_slices: nil,
slice: nil,
rpitch: nil,
pitch: nil,
window_size: nil,
pitch_dis: nil,
time_dis: nil,
norm: nil
}
if options.is_a?(Hash)
opts = defaults.merge(options).merge(kwargs)
(sample opts[:name],
rate: opts[:rate],
beat_stretch: opts[:beat_stretch],
pitch_stretch: opts[:pitch_stretch],
attack: opts[:attack],
sustain: opts[:sustain],
release: opts[:release],
start: opts[:start],
finish: opts[:finish],
pan: opts[:pan],
amp: opts[:amp],
onset: opts[:onset],
num_slices: opts[:num_slices],
slice: opts[:slice],
rpitch: opts[:rpitch],
pitch: opts[:pitch],
window_size: opts[:window_size],
pitch_dis: opts[:pitch_dis],
time_dis: opts[:time_dis],
norm: opts[:norm]
)
else
sample options, **kwargs
end
end
define :stutter_sample do |sample_name, n_repeats, sleep_time|
new_sleep = sleep_time / n_repeats
n_repeats.times do
psample sample_name, sustain: 0, release: new_sleep
sleep new_sleep
end
end
define :play_samples_pattern do |pattern, sounds, sleep_time = 0.25|
# pattern -- string like this "iik-----"
# sounds -- hash of sounds defined for the pattern
# in hash :key=>sample or :key=>[sample, n_repeats]
pattern.split('').each do |c|
if c != '-'
if sounds[c].is_a?(Array)
stutter_sample sounds[c][0], sounds[c][1], sleep_time
else
psample sounds[c]
sleep sleep_time
end
else
sleep sleep_time
end
end
end