diff --git a/packages/csound/example/README.md b/packages/csound/example/README.md new file mode 100644 index 00000000..9a52f5f7 --- /dev/null +++ b/packages/csound/example/README.md @@ -0,0 +1,7 @@ +# README + +this project is based on the webaudio csound tutorial: + + + +(currently came till step 4) diff --git a/packages/csound/example/main.js b/packages/csound/example/main.js index 1cc55000..e94d7882 100644 --- a/packages/csound/example/main.js +++ b/packages/csound/example/main.js @@ -1,6 +1,7 @@ import { Csound } from '@csound/browser'; import './style.css'; -import csd from './tutorial1.csd?raw'; +// import csd from './tutorial1.csd?raw'; +import csd from './tutorial2.csd?raw'; document.querySelector('#app').innerHTML = `
@@ -17,11 +18,32 @@ const startCsound = async () => { csound = await Csound(); console.log(csound); window.csound = csound; - + await csound.setOption('-m0'); await csound.compileCsdText(csd); + await csound.setControlChannel('main.note.amp', -12); await csound.start(); document.querySelector('#startButton').remove(); + createPerformanceUI(csound); +}; +const createPerformanceUI = (csound) => { + document.querySelector('#app').innerHTML = ` +
+ + +
+ `; + + document.querySelector('#flourish').addEventListener('click', async () => { + console.log('flourish..'); + // await csound.readScore(`i "Flourish" 0 0 0`); + await csound.evalCode(` + schedule("Flourish", next_time(.25), 0, 0) + `); + }); + document.querySelector('#ampSlider').addEventListener('input', async (evt) => { + await csound.setControlChannel('main.note.amp', evt.target.value); + }); }; document.querySelector('#startButton').addEventListener('click', startCsound); diff --git a/packages/csound/example/test.orc b/packages/csound/example/test.orc new file mode 100644 index 00000000..eb51791b --- /dev/null +++ b/packages/csound/example/test.orc @@ -0,0 +1 @@ +schedule("Flourish", 0, 0, 0) \ No newline at end of file diff --git a/packages/csound/example/tutorial2.csd b/packages/csound/example/tutorial2.csd new file mode 100644 index 00000000..bb853da3 --- /dev/null +++ b/packages/csound/example/tutorial2.csd @@ -0,0 +1,68 @@ +;; Author: Steven Yi + + +-o dac --port=10000 + + +sr=48000 +ksmps=64 +nchnls=2 +0dbfs=1 + +instr 1 + ioct = octcps(p4) + kpwm = oscili(.1, 5) + asig = vco2(p5, p4, 4, .5 + kpwm) + asig += vco2(p5, p4 * 2) + + idepth = 3 + acut = transegr:a(0, .002, 0, idepth, .5, -4.2, 0.001, .5, -4.2, 0) + asig = zdf_2pole(asig, cpsoct(ioct + acut), 0.5) + + asig *= linsegr:a(1, p3, 1, .5, 0) + + out(asig, asig) + +endin + +opcode next_time, i, i + inext xin + + itime = times:i() + iticks = round(itime / inext) + iticks += 1 + + iout = (iticks * inext) - itime + xout iout +endop + +instr Flourish + inotes[] fillarray 72, 74, 75, 77, 79 + inote = inotes[floor(rnd(5))] + + schedule(1, 0, .25, cpsmidinn(inote), ampdbfs(-12 + p4 * .5)) + + if(p4 > -60) then + schedule(p1, next_time(.125), 0, p4 - 1) + endif +endin + +instr Main + iamp = ampdbfs(chnget:i("main.note.amp")) + inotes[] fillarray 60, 67, 63, 65, 62 + ioct[] fillarray 0,1,0,0,1 + inote = inotes[p4 % 37 % 11 % 5] + 12 * ioct[p4 % 41 % 17 % 5] + schedule(1, 0, .25, cpsmidinn(inote), iamp) + + if(p4 % 64 % 37 % 17 % 11 == 0 && inote != 74 && inote != 62) then + schedule(1, 0, .5, cpsmidinn(inote + 7), iamp / 2) + endif + + schedule(p1, next_time(.25), .25, p4 + 1) +endin + + +schedule("Main", 0, 0, 0) + + + \ No newline at end of file