| 1 | <!doctype html> |
| 2 | <html lang="en-us"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 6 | <title>ChucK + JS => ChucKScript</title> |
| 7 | <link rel="stylesheet" href="../../css/editor.css"> |
| 8 | </head> |
| 9 | <body onresize="chuckEditor.resize();"> |
| 10 | <div> |
| 11 | <div id="program">// Globals 8: secret replacement dac 2 |
| 12 | // This dac is secretly an LPF, and we're fetching its samples |
| 13 | // directly and the main chuck is not actually producing any sound |
| 14 | SawOsc s => dac; |
| 15 | while( true ) |
| 16 | { |
| 17 | Math.random2f( 30, 1000 ) => s.freq; |
| 18 | 130::ms => now; |
| 19 | } |
| 20 | </div> |
| 21 | </div> |
| 22 | <div class="buttons"> |
| 23 | <button class="chuckButton" id="startChuck" disabled="disabled">Start ChucK</button> |
| 24 | <button class="chuckButton" id="compileButton" disabled="disabled">Compile and Run</button> |
| 25 | <button class="chuckButton" id="replaceButton" disabled="disabled">Replace</button> |
| 26 | <button class="chuckButton" id="removeButton" disabled="disabled">Remove</button> |
| 27 | <button class="chuckButton" id="clearButton" disabled="disabled">Clear VM and Globals</button> |
| 28 | <button class="chuckButton" id="micButton" disabled="disabled">Enable Microphone</button> |
| 29 | <button class="chuckButton" id="fileFormButton">Show File Uploader</button> |
| 30 | </div> |
| 31 | <div id="fileForm" class="hidden"> |
| 32 | <p>File name to use in ChucK: <input type="text" id="uploadFilename"></p> |
| 33 | <p>Local file to upload: <input type="file" id="uploadFile" name="uploadFile"></p> |
| 34 | <p><button class="chuckButton" id="fileButton" disabled="disabled">Upload File to Virtual File System</button></p> |
| 35 | </div> |
| 36 | <div> |
| 37 | <textarea id="output"></textarea> |
| 38 | <div id="shreds"> |
| 39 | <table id="shredstable"> |
| 40 | <col width="60px"> |
| 41 | <col width="1*"> |
| 42 | <col width="50px"> |
| 43 | <col width="60px"> |
| 44 | <tr><th>shred</th><th>code</th><th>time</th><th>remove</th> |
| 45 | </table> |
| 46 | </div> |
| 47 | <div class="clearfix"></div> |
| 48 | </div> |
| 49 | <script type="text/javascript" src="../../js/ace-min-noconflict/ace.js" charset="utf-8"></script> |
| 50 | <script type="text/javascript" src="../../js/editor.js"></script> |
| 51 | <script type="text/javascript" src="../../js/defer.js"></script> |
| 52 | <script> |
| 53 | // override |
| 54 | var whereIsChuck = "../../js"; |
| 55 | </script> |
| 56 | <script type="text/javascript" src="../../js/webchuck_host.js"></script> |
| 57 | <script type="text/javascript" src="../../js/host.js"></script> |
| 58 | <script> |
| 59 | theChuckReady.then( async function() |
| 60 | { |
| 61 | // remove compile handlers |
| 62 | compileButton.removeEventListener( "click", chuckCompileButton ); |
| 63 | replaceButton.removeEventListener( "click", chuckReplaceButton ); |
| 64 | compileButton.disabled = replaceButton.disabled = true; |
| 65 | |
| 66 | // create the secret dac. |
| 67 | // IMPORTANT: set buffered to true so we can fetch its samples. |
| 68 | await theChuck.runCode( "global LPF secretDac => blackhole; true => secretDac.buffered; secretDac.freq( 700 );" ); |
| 69 | |
| 70 | // create a subinstance based on the secret dac |
| 71 | var theSubChuckReady = defer(); |
| 72 | var theSubChuck = createASubChuck( theChuck, "secretDac", theSubChuckReady ); |
| 73 | theSubChuck.connect( audioContext.destination ); |
| 74 | await theSubChuckReady; |
| 75 | |
| 76 | // reenable buttons, but with theSubChuck instead of theChuck |
| 77 | compileButton.addEventListener( "click", function() { |
| 78 | theSubChuck.runCode( chuckEditor.getValue() ); |
| 79 | }); |
| 80 | |
| 81 | replaceButton.addEventListener( "click", function() { |
| 82 | theSubChuck.replaceCode( chuckEditor.getValue() ); |
| 83 | }); |
| 84 | compileButton.disabled = replaceButton.disabled = false; |
| 85 | |
| 86 | }); |
| 87 | </script> |
| 88 | </body> |
| 89 | </html> |
| 90 | |
| 91 |