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
|
<!DOCTYPE html>
<html>
<head>
<title>debug @csound/browser</title>
</head>
<body>
<script type="module">
const url = "/libcsound.dev.mjs";
const testMidi = `
<CsoundSynthesizer>
<CsOptions>
-odac -Ma
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1
giSine ftgen 0,0,2^10,10,1 ; a sine wave
instr 1
; -- pitch bend --
kPchBnd pchbend 0,4 ;read in pitch bend (range -2 to 2)
kTrig1 changed kPchBnd ;if 'kPchBnd' changes generate a trigger
if kTrig1=1 then
printks "Pitch Bend:%f%n",0,kPchBnd ;print kPchBnd to console when it changes
endif
; -- aftertouch --
kAfttch aftouch 0,0.9 ;read in aftertouch (range 0 to 0.9)
kTrig2 changed kAfttch ;if 'kAfttch' changes generate a trigger
if kTrig2=1 then
printks "Aftertouch:%d%n",0,kAfttch ;print kAfttch to console when it changes
endif
; -- create a sound --
iNum notnum ;read in MIDI note number
; MIDI note number + pitch bend are converted to cycles per seconds
aSig poscil 0.1,cpsmidinn(iNum+kPchBnd),giSine
aSig *= expsegr(0.001, .02, 1, .5, 0.001)
out aSig ;audio to output
endin
</CsInstruments>
<CsScore>
</CsScore>
<CsoundSynthesizer>
;example by Iain McCurdy
`;
const runIt = async () => {
const { Csound } = await import(url);
const csoundObj = await Csound({
useWorker: false,
useSPN: true,
useSAB: false
});
const compileReturn = await csoundObj.compileCsdText(testMidi);
const startReturn = await csoundObj.start();
};
const triggerEvent = "ontouchstart" in document.documentElement ? "touchend" : "click";
document.querySelector("#all_tests").addEventListener(triggerEvent, async function () {
await runIt();
});
</script>
<button id="all_tests">Run All Tests</button>
</body>
</html>
|