Debian Codegraph @

wasm/browser/tests/midi-test.html

raw
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>debug @csound/browser</title>
5 </head>
6 <body>
7 <script type="module">
8 const url = "/libcsound.dev.mjs";
9
10 const testMidi = `
11 <CsoundSynthesizer>
12 <CsOptions>
13 -odac -Ma
14 </CsOptions>
15 <CsInstruments>
16 sr = 44100
17 ksmps = 32
18 nchnls = 1
19 0dbfs = 1
20
21 giSine ftgen 0,0,2^10,10,1 ; a sine wave
22
23 instr 1
24 ; -- pitch bend --
25 kPchBnd pchbend 0,4 ;read in pitch bend (range -2 to 2)
26 kTrig1 changed kPchBnd ;if 'kPchBnd' changes generate a trigger
27 if kTrig1=1 then
28 printks "Pitch Bend:%f%n",0,kPchBnd ;print kPchBnd to console when it changes
29 endif
30
31 ; -- aftertouch --
32 kAfttch aftouch 0,0.9 ;read in aftertouch (range 0 to 0.9)
33 kTrig2 changed kAfttch ;if 'kAfttch' changes generate a trigger
34 if kTrig2=1 then
35 printks "Aftertouch:%d%n",0,kAfttch ;print kAfttch to console when it changes
36 endif
37
38 ; -- create a sound --
39 iNum notnum ;read in MIDI note number
40 ; MIDI note number + pitch bend are converted to cycles per seconds
41 aSig poscil 0.1,cpsmidinn(iNum+kPchBnd),giSine
42
43 aSig *= expsegr(0.001, .02, 1, .5, 0.001)
44 out aSig ;audio to output
45 endin
46
47 </CsInstruments>
48 <CsScore>
49 </CsScore>
50 <CsoundSynthesizer>
51 ;example by Iain McCurdy
52 `;
53
54 const runIt = async () => {
55 const { Csound } = await import(url);
56 const csoundObj = await Csound({
57 useWorker: false,
58 useSPN: true,
59 useSAB: false
60 });
61
62 const compileReturn = await csoundObj.compileCsdText(testMidi);
63 const startReturn = await csoundObj.start();
64
65 };
66
67 const triggerEvent = "ontouchstart" in document.documentElement ? "touchend" : "click";
68 document.querySelector("#all_tests").addEventListener(triggerEvent, async function () {
69 await runIt();
70 });
71 </script>
72 <button id="all_tests">Run All Tests</button>
73 </body>
74 </html>