<html>
<head>
    <title>Minimal Example using Csound for WebAssembly</title>
    <script src="csound.js"></script>
 </head>
<body>
    <script>
    var handleMessage = function(message) {
        var messages_textarea = document.getElementById("console");
        var existing = messages_textarea.value;
        messages_textarea.value = existing + '\n' + message;
        messages_textarea.scrollTop = messages_textarea.scrollHeight;        
    }
    var moduleDidLoad = function() {
        document.getElementById('console').value += 'moduleDidLoad was called; Csound functions may now be called.';
        console.warn = handleMessage;
    }
    var onPlayClick = function() {
        var csd = document.getElementById('csd').value;
        csound.compileCsdText(csd);
        csound.start();
        csound.perform();
    }
    var onPlayStop = function() {
        csound.stop();
    }
  </script>
<h1>xadsr</h1>
<p>
This example will play if your Web browser is a desktop version of Google Chrome with WebAssembly enabled. You can edit and replay the code. At this time, most but not all examples will run in WebAssembly.
</p>
<p>
<input type="button" value="Play" onclick="onPlayClick()"/>
<input type="button" value="Stop" onclick="onPlayStop()"/>
<p>
<textarea id="csd" style="width: 100%; height: 50%;font-size:12px;"><CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o xadsr.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2 ; Changed for WebAssembly output from: = 2
0dbfs = 1

instr 1

iatt  = p5
idec  = p6  
islev = p7
irel  = p8

kenv	xadsr iatt, idec, islev, irel
kcps =  cpspch(p4) 	  ;frequency

asig	vco2  kenv * 0.8, kcps
	outs  asig, asig

endin

</CsInstruments>
<CsScore>

i 1  0  1  7.00  .0001  1  .01  .001 ; short attack
i 1  2  1  7.02  1  .5  .01  .001    ; long attack
i 1  4  2  6.09  .0001  1 .1  .7     ; long release

e
</CsScore>
</CsoundSynthesizer>
</textarea>
<h3>Csound Messages</h3>
<textarea id="console" readonly style="width: 100%; height: 25%;font-size:12px;">
</textarea>
</body>
</html>