mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 19:48:31 +00:00
now passing controls as string keymap
This commit is contained in:
parent
e4ee4211c8
commit
e8fb7ee683
@ -16,10 +16,16 @@ Pattern.prototype._csound = function (instrument) {
|
|||||||
logger('[csound] not loaded yet', 'warning');
|
logger('[csound] not loaded yet', 'warning');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (typeof hap.value !== 'object') {
|
||||||
|
throw new Error('csound only support objects as hap values');
|
||||||
|
}
|
||||||
let { gain = 0.8 } = hap.value;
|
let { gain = 0.8 } = hap.value;
|
||||||
gain *= 0.2;
|
gain *= 0.2;
|
||||||
|
|
||||||
const freq = getFrequency(hap);
|
const freq = Math.round(getFrequency(hap));
|
||||||
|
const controls = Object.entries({ ...hap.value, freq })
|
||||||
|
.flat()
|
||||||
|
.join('/');
|
||||||
// TODO: find out how to send a precise ctx based time
|
// TODO: find out how to send a precise ctx based time
|
||||||
// http://www.csounds.com/manual/html/i.html
|
// http://www.csounds.com/manual/html/i.html
|
||||||
const params = [
|
const params = [
|
||||||
@ -29,6 +35,7 @@ Pattern.prototype._csound = function (instrument) {
|
|||||||
// instrument specific params:
|
// instrument specific params:
|
||||||
freq, //.toFixed(precision), // p4: frequency
|
freq, //.toFixed(precision), // p4: frequency
|
||||||
gain, // p5: gain
|
gain, // p5: gain
|
||||||
|
`"${controls}"`, // p6 controls as string (like superdirt osc message)
|
||||||
];
|
];
|
||||||
const msg = `i ${params.join(' ')}`;
|
const msg = `i ${params.join(' ')}`;
|
||||||
_csound.inputMessage(msg);
|
_csound.inputMessage(msg);
|
||||||
@ -38,9 +45,12 @@ Pattern.prototype._csound = function (instrument) {
|
|||||||
// initializes csound + can be used to reevaluate given instrument code
|
// initializes csound + can be used to reevaluate given instrument code
|
||||||
export async function csound(code = '') {
|
export async function csound(code = '') {
|
||||||
await init();
|
await init();
|
||||||
code && (await _csound?.evalCode(`${code}`));
|
if (code) {
|
||||||
// ^ ^
|
code = `${code}`;
|
||||||
// wrapping in backticks makes sure it works when calling as templated function
|
// ^ ^
|
||||||
|
// wrapping in backticks makes sure it works when calling as templated function
|
||||||
|
await _csound?.evalCode(code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Pattern.prototype.define('csound', (a, pat) => pat.csound(a), { composable: false, patternified: true });
|
Pattern.prototype.define('csound', (a, pat) => pat.csound(a), { composable: false, patternified: true });
|
||||||
@ -78,7 +88,7 @@ async function load() {
|
|||||||
}
|
}
|
||||||
_csound.removeAllListeners('message');
|
_csound.removeAllListeners('message');
|
||||||
['message'].forEach((k) => _csound.on(k, (...args) => eventLogger(k, args)));
|
['message'].forEach((k) => _csound.on(k, (...args) => eventLogger(k, args)));
|
||||||
await _csound.setOption('-m0'); // see -m flag https://csound.com/docs/manual/CommandFlags.html
|
await _csound.setOption('-m0d'); // see -m flag https://csound.com/docs/manual/CommandFlags.html
|
||||||
await _csound.setOption('--sample-accurate');
|
await _csound.setOption('--sample-accurate');
|
||||||
await _csound.compileCsdText(csd);
|
await _csound.compileCsdText(csd);
|
||||||
await _csound.compileOrc(livecodeOrc);
|
await _csound.compileOrc(livecodeOrc);
|
||||||
|
|||||||
@ -1,3 +1,15 @@
|
|||||||
|
; returns value of given key in given "string map"
|
||||||
|
; keymap("freq", "note/c3/freq/220/gain/0.5")
|
||||||
|
; yields "220"
|
||||||
|
opcode keymap, S, SS
|
||||||
|
Skey, Smap xin
|
||||||
|
idelimiter = strindex(Smap, strcat(Skey, "/"))
|
||||||
|
ifrom = idelimiter + strlen(Skey) + 1
|
||||||
|
Svalue = strsub(Smap, ifrom, strlen(Smap))
|
||||||
|
Svalue = strsub(Svalue, 0, strindex(Svalue, "/"))
|
||||||
|
xout Svalue
|
||||||
|
endop
|
||||||
|
|
||||||
; TODO add incredibly dope synths
|
; TODO add incredibly dope synths
|
||||||
instr organ
|
instr organ
|
||||||
iduration = p3
|
iduration = p3
|
||||||
@ -58,4 +70,27 @@ instr pad
|
|||||||
asig = zdf_2pole(asig, 1000, 2)
|
asig = zdf_2pole(asig, 1000, 2)
|
||||||
|
|
||||||
out(asig, asig)
|
out(asig, asig)
|
||||||
|
endin
|
||||||
|
|
||||||
|
|
||||||
|
gisine ftgen 0, 0, 4096, 10, 1
|
||||||
|
|
||||||
|
instr bow
|
||||||
|
kpres = 2
|
||||||
|
krat = 0.16
|
||||||
|
kvibf = 6.12723
|
||||||
|
|
||||||
|
kvib linseg 0, 0.5, 0, 1, 1, p3-0.5, 1
|
||||||
|
kvamp = kvib * 0.01
|
||||||
|
asig wgbow .7, p4, kpres, krat, kvibf, kvamp, gisine
|
||||||
|
asig = asig*p5
|
||||||
|
outs asig, asig
|
||||||
|
endin
|
||||||
|
|
||||||
|
|
||||||
|
instr Meta
|
||||||
|
Smap = strget(p6)
|
||||||
|
Sinstrument = keymap("s", Smap)
|
||||||
|
schedule(Sinstrument, 0, p3, p4, p5)
|
||||||
|
; TODO find a way to pipe Sinstrument through effects
|
||||||
endin
|
endin
|
||||||
@ -1023,3 +1023,19 @@ endin\`
|
|||||||
.note()
|
.note()
|
||||||
//.pianoroll()
|
//.pianoroll()
|
||||||
.csound("<CoolSynth Organ1>/4")`;
|
.csound("<CoolSynth Organ1>/4")`;
|
||||||
|
|
||||||
|
export const loungeSponge = `await csound()
|
||||||
|
|
||||||
|
stack(
|
||||||
|
note("<C^7 A7 Dm7 Fm7>/2".voicings())
|
||||||
|
.cutoff(sine.range(500,2000).round().slow(16))
|
||||||
|
.euclidLegato(3,8).csound('FM1')
|
||||||
|
,
|
||||||
|
note("<C2 A1 D2 F2>/2").ply(8).csound('Bass').gain("1 4 1 4")
|
||||||
|
,
|
||||||
|
note("0 7 [4 3] 2".fast(2/3).off(".25 .125",add("<2 4 -3 -1>"))
|
||||||
|
.slow(2).scale('A4 minor'))
|
||||||
|
.legato(.25).csound('SynHarp')
|
||||||
|
,
|
||||||
|
s("bd*2,[~ hh]*2,~ cp").bank('RolandTR909')
|
||||||
|
)`;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user