| 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">// HID 1: keyboard organ |
| 12 | global Event buttonDown; |
| 13 | global Event buttonUp; |
| 14 | global int whichButton; |
| 15 | // patch |
| 16 | BeeThree organ => JCRev r => Echo e => Echo e2 => dac; |
| 17 | r => dac; |
| 18 | |
| 19 | // set delays |
| 20 | 240::ms => e.max => e.delay; |
| 21 | 480::ms => e2.max => e2.delay; |
| 22 | // set gains |
| 23 | .6 => e.gain; |
| 24 | .3 => e2.gain; |
| 25 | .05 => r.mix; |
| 26 | 0 => organ.gain; |
| 27 | |
| 28 | fun void RespondToButtonDown() |
| 29 | { |
| 30 | while( true ) |
| 31 | { |
| 32 | buttonDown => now; |
| 33 | chout <= IO.newline(); |
| 34 | <<< whichButton, "down" >>>; |
| 35 | Std.mtof( whichButton - 25 ) => float freq; |
| 36 | if( freq > 20000 ) continue; |
| 37 | |
| 38 | freq => organ.freq; |
| 39 | .5 => organ.gain; |
| 40 | 1 => organ.noteOn; |
| 41 | |
| 42 | 80::ms => now; |
| 43 | } |
| 44 | } |
| 45 | spork ~ RespondToButtonDown(); |
| 46 | |
| 47 | fun void RespondToButtonUp() |
| 48 | { |
| 49 | while( true ) |
| 50 | { |
| 51 | buttonUp => now; |
| 52 | <<< whichButton, "up" >>>; |
| 53 | 0 => organ.noteOff; |
| 54 | } |
| 55 | } |
| 56 | spork ~ RespondToButtonUp(); |
| 57 | |
| 58 | while( true ) |
| 59 | { |
| 60 | 1::second => now; |
| 61 | } |
| 62 | </div> |
| 63 | </div> |
| 64 | <div class="buttons"> |
| 65 | <button class="chuckButton" id="startChuck" disabled="disabled">Start ChucK</button> |
| 66 | <button class="chuckButton" id="compileButton" disabled="disabled">Compile and Run</button> |
| 67 | <button class="chuckButton" id="replaceButton" disabled="disabled">Replace</button> |
| 68 | <button class="chuckButton" id="removeButton" disabled="disabled">Remove</button> |
| 69 | <button class="chuckButton" id="clearButton" disabled="disabled">Clear VM and Globals</button> |
| 70 | <button class="chuckButton" id="micButton" disabled="disabled">Enable Microphone</button> |
| 71 | <button class="chuckButton" id="fileFormButton">Show File Uploader</button> |
| 72 | </div> |
| 73 | <div id="fileForm" class="hidden"> |
| 74 | <p>File name to use in ChucK: <input type="text" id="uploadFilename"></p> |
| 75 | <p>Local file to upload: <input type="file" id="uploadFile" name="uploadFile"></p> |
| 76 | <p><button class="chuckButton" id="fileButton" disabled="disabled">Upload File to Virtual File System</button></p> |
| 77 | </div> |
| 78 | <div> |
| 79 | <p>Type below in the output to play the keyboard organ!</p> |
| 80 | </div> |
| 81 | <div> |
| 82 | <textarea id="output"></textarea> |
| 83 | <div id="shreds"> |
| 84 | <table id="shredstable"> |
| 85 | <col width="60px"> |
| 86 | <col width="1*"> |
| 87 | <col width="50px"> |
| 88 | <col width="60px"> |
| 89 | <tr><th>shred</th><th>code</th><th>time</th><th>remove</th> |
| 90 | </table> |
| 91 | </div> |
| 92 | <div class="clearfix"></div> |
| 93 | </div> |
| 94 | <script type="text/javascript" src="../../js/ace-min-noconflict/ace.js" charset="utf-8"></script> |
| 95 | <script type="text/javascript" src="../../js/editor.js"></script> |
| 96 | <script type="text/javascript" src="../../js/defer.js"></script> |
| 97 | <script> |
| 98 | // override |
| 99 | var whereIsChuck = "../../js"; |
| 100 | </script> |
| 101 | <script type="text/javascript" src="../../js/webchuck_host.js"></script> |
| 102 | <script type="text/javascript" src="../../js/host.js"></script> |
| 103 | <script> |
| 104 | // make editor a bit smaller |
| 105 | chuckEditor.setOptions({ |
| 106 | maxLines: 20, |
| 107 | minLines: 20 |
| 108 | }); |
| 109 | |
| 110 | theChuckReady.then( function() |
| 111 | { |
| 112 | var output = document.getElementById( "output" ); |
| 113 | output.onkeydown = function( e ) |
| 114 | { |
| 115 | theChuck.setInt( "whichButton", e.key.charCodeAt(0) ); |
| 116 | theChuck.broadcastEvent( "buttonDown" ); |
| 117 | } |
| 118 | output.onkeyup = function( e ) |
| 119 | { |
| 120 | theChuck.setInt( "whichButton", e.key.charCodeAt(0) ); |
| 121 | theChuck.broadcastEvent( "buttonUp" ); |
| 122 | } |
| 123 | }); |
| 124 | </script> |
| 125 | </body> |
| 126 | </html> |
| 127 | |
| 128 |