mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 21:58:37 +00:00
baasic csound output
This commit is contained in:
parent
43aa2247f1
commit
eab86840d3
1744
package-lock.json
generated
1744
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
32
packages/csound/csound.mjs
Normal file
32
packages/csound/csound.mjs
Normal file
@ -0,0 +1,32 @@
|
||||
import { Pattern } from '@strudel.cycles/core';
|
||||
import { Csound } from '@csound/browser'; // TODO: use dynamic import for code splitting..
|
||||
import csd from './sounds.csd?raw';
|
||||
import { getAudioContext } from '@strudel.cycles/webaudio';
|
||||
|
||||
let csoundLoader;
|
||||
|
||||
Pattern.prototype.csound = async function () {
|
||||
if (!csoundLoader) {
|
||||
csoundLoader = (async () => {
|
||||
const csound = await Csound({ audioContext: getAudioContext() });
|
||||
await csound.setOption('-m0');
|
||||
await csound.compileCsdText(csd);
|
||||
await csound.setControlChannel('main.note.amp', -12);
|
||||
await csound.start();
|
||||
return csound;
|
||||
})();
|
||||
}
|
||||
const csound = await csoundLoader;
|
||||
return this.onTrigger((time, hap, currentTime) => {
|
||||
const { gain = 0.8 } = hap.value;
|
||||
const deadline = time - currentTime;
|
||||
const midi = toMidi(getPlayableNoteValue(hap));
|
||||
// TODO: find out how to send a precise ctx based time
|
||||
const ctime = `next_time(.000001)+${deadline.toFixed(6)}`;
|
||||
// const ctime = `${deadline.toFixed(6)}`;
|
||||
const cmidi = `cpsmidinn(${midi})`;
|
||||
const cgain = gain ? `ampdbfs(-32 + 32*${gain})` : `0`;
|
||||
const code = `schedule(1, ${ctime}, .125, ${cmidi}, ${cgain})`;
|
||||
csound.evalCode(code);
|
||||
});
|
||||
};
|
||||
@ -2,7 +2,7 @@
|
||||
"name": "@strudel.cycles/csound",
|
||||
"version": "0.3.0",
|
||||
"description": "csound bindings for strudel",
|
||||
"main": "index.mjs",
|
||||
"main": "csound.mjs",
|
||||
"scripts": {
|
||||
"test": "echo \"No tests present.\" && exit 0"
|
||||
},
|
||||
|
||||
@ -42,6 +42,7 @@ const modules = [
|
||||
import('@strudel.cycles/osc'),
|
||||
import('@strudel.cycles/serial'),
|
||||
import('@strudel.cycles/soundfonts'),
|
||||
import('@strudel.cycles/csound'),
|
||||
];
|
||||
|
||||
evalScope(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user