forked from switchangel/strudel-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallscripts(deprecated).js
More file actions
190 lines (156 loc) · 5.2 KB
/
allscripts(deprecated).js
File metadata and controls
190 lines (156 loc) · 5.2 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
register('o', (orbit, pat) => pat.orbit(orbit))
samples('http://localhost:5432')
setCpm(140 / 4)
setGainCurve(x => Math.pow(x, 2))
// setGainCurve(x => x**2)
function blockArrange(patArr, modifiers = []) {
return stack(
...patArr.map(([pat, maskPat]) => {
pat = [pat].flat()
return maskPat.fmap(m => {
return stack(...pat.map(p => {
if (m == 0) {
return
}
const ms = m.toString()
let newPat = p
if (ms.includes('R')) {
newPat = newPat.restart(1)
}
if (ms.includes('B')) {
newPat = newPat.rev().speed(-1)
}
modifiers.forEach(([mod, callback]) => {
if (mod(ms)) {
newPat = callback(newPat)
}
})
return newPat
}).filter(Boolean))
}).innerJoin()
}).flat()
)
}
// example:
// $: blockArrange(
// [
// [[bd], "<F F F F F F F F F 0>"],
// [[bass], "<0 0 F F F S F F F B>"],
// [[hat], "<0 F F F F F F F F F>"],
// ],
// //ADD CUSTOM BINDINGS
// [[(m) => m.includes('S') , (x) => x.stretch(1)]]
// )._scope()
// fill in gaps between events
register('fill', function (pat) {
return new Pattern(function (state) {
const lookbothways = 1;
// Expand the query window
const haps = pat.query(state.withSpan(span => new TimeSpan(span.begin.sub(lookbothways), span.end.add(lookbothways))));
const onsets = haps.map(hap => hap.whole.begin)
// sort fractions
.sort((a, b) => a.compare(b))
// make unique
.filter((x, i, arr) => i == (arr.length - 1) || x.ne(arr[i + 1]));
const newHaps = [];
for (const hap of haps) {
// Ingore if the part starts after the original query
if (hap.part.begin.gte(state.span.end)) {
continue;
}
// Find the next onset, to use as an offset
const next = onsets.find(onset => onset.gte(hap.whole.end));
// Ignore if the part ended before the original query, and hasn't expanded inside
if (next.lte(state.span.begin)) {
continue;
}
const whole = new TimeSpan(hap.whole.begin, next);
// Constrain part to original query
const part = new TimeSpan(hap.part.begin.max(state.span.begin), next.min(state.span.end));
newHaps.push(new Hap(whole, part, hap.value, hap.context, hap.stateful));
}
return newHaps;
});
});
register('trancegate', (density, seed, length, x) => {
return x.struct(rand.mul(density).round().seg(16).rib(seed, length)).fill().clip(.7)
})
// quantize notes to given values: pat.grab("e:f#:c")
register('grab', function (scale, pat) {
// Supports ':' list syntax in mininotation
scale = (Array.isArray(scale) ? scale.flat() : [scale]).flatMap((val) =>
typeof val === 'number' ? val : noteToMidi(val) - 48
);
return pat.withHap((hap) => {
const isObject = typeof hap.value === 'object';
let note = isObject ? hap.value.n : hap.value;
if (typeof note === 'number') {
note = note;
}
if (typeof note === 'string') {
note = noteToMidi(note);
}
if (isObject) {
delete hap.value.n; // remove n so it won't cause trouble
}
const octave = (note / 12) >> 0;
const transpose = octave * 12;
const goal = note - transpose;
note =
scale.reduce((prev, curr) => {
return Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev;
}) + transpose;
return hap.withValue(() => (isObject ? { ...hap.value, note } : note));
});
});
setDefault('gain', 1)
// multi orbit pan for quad setups etc.
// ex: s("bd!4").mpan("3:4", slider(0.761))
register('mpan', (orbits, amount, pat) => {
const index = Math.round(amount * (orbits.length - 1))
const orbit = orbits[index]
const pamt = (amount * orbits.length) % 1
return pat.orbit(orbit).pan(pamt)
})
// lpf between 0 and 1
register('rlpf', (x, pat) => { return pat.lpf(pure(x).mul(12).pow(4)) })
//hpf between 0 and 1
register('rhpf', (x, pat) => { return pat.hpf(pure(x).mul(12).pow(4)) })
//@title velocity structure @by Switch Angel
register('vstruct', (ipat,pat) => {
return ipat.outerBind(vel => {
return pat.keepif.out(Math.ceil(vel)).velocity(vel)
})
},false)
// sets my vocoder CC key to the specified value, probably only useful for me
register('voc', (key, x) => {
let value;
switch (key) {
case 'f#': value = 0; break;
case 'g': value = 0.1; break;
case 'g#': value = 0.2; break;
case 'a': value = 0.3; break;
case 'a#': value = 0.4; break;
case 'b': value = 0.45; break;
case 'c': value = 0.5; break;
case 'c#': value = 0.6; break;
case 'd': value = 0.7; break;
case 'd#': value = 0.8; break;
case 'e': value = 0.9; break;
case 'f': value = 1; break;
default: value = 0.5; // fallback value if key is not recognized
}
return x.ccn(74).ccv(value).midi('tout');
});
// tb303 style filter envelope control between 0 & 1 values for useful range
register('acidenv', (x, pat) => pat.rlpf(.25).lpenv(x * 9).lps(.2).lpd(.15))
/** SOUNDS */
register('acid', (pat) => {
return pat.s('supersaw')
.detune(.5)
.unison(1)
.lpf(100)
.lpsustain(0.2).lpd(.2).lpenv(2)
.lpq(12)
})
$: s("white").clip(0).gain(0)