continue tutorial
This commit is contained in:
parent
ac2aa7f288
commit
e621020474
4 changed files with 100 additions and 2 deletions
7
packages/csound/example/README.md
Normal file
7
packages/csound/example/README.md
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
# README
|
||||||
|
|
||||||
|
this project is based on the webaudio csound tutorial:
|
||||||
|
|
||||||
|
<https://kunstmusik.github.io/icsc2022-csound-web/tutorial2-interacting-with-csound#evaluating-csound-sco>
|
||||||
|
|
||||||
|
(currently came till step 4)
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { Csound } from '@csound/browser';
|
import { Csound } from '@csound/browser';
|
||||||
import './style.css';
|
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 = `
|
document.querySelector('#app').innerHTML = `
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -17,11 +18,32 @@ const startCsound = async () => {
|
||||||
csound = await Csound();
|
csound = await Csound();
|
||||||
console.log(csound);
|
console.log(csound);
|
||||||
window.csound = csound;
|
window.csound = csound;
|
||||||
|
await csound.setOption('-m0');
|
||||||
await csound.compileCsdText(csd);
|
await csound.compileCsdText(csd);
|
||||||
|
await csound.setControlChannel('main.note.amp', -12);
|
||||||
await csound.start();
|
await csound.start();
|
||||||
|
|
||||||
document.querySelector('#startButton').remove();
|
document.querySelector('#startButton').remove();
|
||||||
|
createPerformanceUI(csound);
|
||||||
|
};
|
||||||
|
const createPerformanceUI = (csound) => {
|
||||||
|
document.querySelector('#app').innerHTML = `
|
||||||
|
<div>
|
||||||
|
<button id='flourish'>Flourish</button>
|
||||||
|
<input id='ampSlider' type='range' min='-60' max='-12' value='-12'/>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
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);
|
document.querySelector('#startButton').addEventListener('click', startCsound);
|
||||||
|
|
|
||||||
1
packages/csound/example/test.orc
Normal file
1
packages/csound/example/test.orc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
schedule("Flourish", 0, 0, 0)
|
||||||
68
packages/csound/example/tutorial2.csd
Normal file
68
packages/csound/example/tutorial2.csd
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
;; Author: Steven Yi
|
||||||
|
<CsoundSynthesizer>
|
||||||
|
<CsOptions>
|
||||||
|
-o dac --port=10000
|
||||||
|
</CsOptions>
|
||||||
|
<CsInstruments>
|
||||||
|
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)
|
||||||
|
|
||||||
|
</CsInstruments>
|
||||||
|
</CsoundSynthesizer>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue