Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
122 changed files
with
13,379 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
window.onload = init; | ||
|
||
function init(){ | ||
MIDI.loadPlugin({ | ||
soundfontUrl: "./midi/soundfont/", | ||
instruments: [ "acoustic_grand_piano", "synth_drum" ], | ||
callback: function() { | ||
MIDI.programChange(0, 0); | ||
MIDI.programChange(1, 118); | ||
run(); | ||
} | ||
}); | ||
} | ||
|
||
function run() { | ||
|
||
canvas = document.getElementById('myCanvas'); | ||
canvas_rect = canvas.getBoundingClientRect(); | ||
|
||
ctx = canvas.getContext('2d'); | ||
|
||
console.log(ctx.strokeStyle); | ||
|
||
window.onmousemove = handleMouseMove; | ||
function handleMouseMove(event) { | ||
event = event || window.event; // IE-ism | ||
var num = 40; | ||
|
||
if(event.clientX>canvas_rect.left && event.clientX<canvas_rect.right && event.clientY>canvas_rect.top && event.clientY<canvas_rect.bottom){ | ||
console.log('x: ' + (num+event.clientX/20)); | ||
console.log('y: ' + (num+event.clientY/20)); | ||
|
||
var x = num+Math.floor(event.clientX/20); | ||
var y = num+Math.floor(event.clientY/20); | ||
//note = Math.floor(x*Math.random()+y*Math.random()); | ||
var note = Math.floor(x/y*50); | ||
//var note = Math.floor(x*y/50); | ||
|
||
note = normalize(note); | ||
|
||
console.log(note); | ||
var random_num = Math.random(); | ||
if(random_num>0.9) | ||
play(note) | ||
} | ||
} | ||
}; | ||
|
||
function normalize(note){ | ||
var color = ctx.strokeStyle.toString().substr(1); | ||
//alert(color); | ||
var factor = 1; | ||
if(color == 'ff0000') | ||
factor = 1/6; | ||
if(color == 'ffc0cb') | ||
factor = 2/6 | ||
if(color == 'ffa500') | ||
factor = 3/6 | ||
if(color == '0000ff') | ||
factor = 4/6 | ||
if(color == '008000') | ||
factor = 5/6 | ||
|
||
return Math.round(note * factor+40); | ||
} | ||
|
||
|
||
function play(note) { | ||
var delay = 0; // play one note every quarter second | ||
var velocity = 127; // how hard the note hits | ||
// play the note | ||
MIDI.setVolume(0, 127); | ||
MIDI.noteOn(0, note, velocity, delay); | ||
//MIDI.noteOff(0, note, delay + 0.75); | ||
}; | ||
|
||
|
||
function play_series(arr) { | ||
var delay = 0; // play one note every quarter second | ||
var velocity = 127; // how hard the note hits | ||
// play the note | ||
MIDI.setVolume(0, 127); | ||
for(var i=0;i<arr.length;i++){ | ||
MIDI.noteOn(0, arr[i], velocity, delay); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// http://ntt.cc/2008/01/19/base64-encoder-decoder-with-javascript.html | ||
|
||
// window.atob and window.btoa | ||
|
||
(function (window) { | ||
|
||
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | ||
|
||
window.btoa || (window.btoa = function encode64(input) { | ||
input = escape(input); | ||
var output = ""; | ||
var chr1, chr2, chr3 = ""; | ||
var enc1, enc2, enc3, enc4 = ""; | ||
var i = 0; | ||
do { | ||
chr1 = input.charCodeAt(i++); | ||
chr2 = input.charCodeAt(i++); | ||
chr3 = input.charCodeAt(i++); | ||
enc1 = chr1 >> 2; | ||
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); | ||
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); | ||
enc4 = chr3 & 63; | ||
if (isNaN(chr2)) { | ||
enc3 = enc4 = 64; | ||
} else if (isNaN(chr3)) { | ||
enc4 = 64; | ||
} | ||
output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); | ||
chr1 = chr2 = chr3 = ""; | ||
enc1 = enc2 = enc3 = enc4 = ""; | ||
} while (i < input.length); | ||
return output; | ||
}); | ||
|
||
window.atob || (window.atob = function(input) { | ||
var output = ""; | ||
var chr1, chr2, chr3 = ""; | ||
var enc1, enc2, enc3, enc4 = ""; | ||
var i = 0; | ||
// remove all characters that are not A-Z, a-z, 0-9, +, /, or = | ||
var base64test = /[^A-Za-z0-9\+\/\=]/g; | ||
if (base64test.exec(input)) { | ||
alert("There were invalid base64 characters in the input text.\n" + "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" + "Expect errors in decoding."); | ||
} | ||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); | ||
do { | ||
enc1 = keyStr.indexOf(input.charAt(i++)); | ||
enc2 = keyStr.indexOf(input.charAt(i++)); | ||
enc3 = keyStr.indexOf(input.charAt(i++)); | ||
enc4 = keyStr.indexOf(input.charAt(i++)); | ||
chr1 = (enc1 << 2) | (enc2 >> 4); | ||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); | ||
chr3 = ((enc3 & 3) << 6) | enc4; | ||
output = output + String.fromCharCode(chr1); | ||
if (enc3 != 64) { | ||
output = output + String.fromCharCode(chr2); | ||
} | ||
if (enc4 != 64) { | ||
output = output + String.fromCharCode(chr3); | ||
} | ||
chr1 = chr2 = chr3 = ""; | ||
enc1 = enc2 = enc3 = enc4 = ""; | ||
} while (i < input.length); | ||
return unescape(output); | ||
}); | ||
|
||
}(this)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Software License Agreement (BSD License) | ||
|
||
Copyright (c) 2007, Scott Schiller (schillmania.com) | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, this | ||
list of conditions and the following disclaimer in the documentation and/or | ||
other materials provided with the distribution. | ||
|
||
* Neither the name of schillmania.com nor the names of its contributors may be | ||
used to endorse or promote products derived from this software without | ||
specific prior written permission from schillmania.com. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Oops, something went wrong.