update demos to for latest libraries

This commit is contained in:
Michael Deal 2012-11-21 01:29:46 -08:00
parent a50ca64600
commit 26f6e8a031
3 changed files with 52 additions and 46 deletions

View file

@ -5,6 +5,7 @@
<script src="./js/MIDI/loadPlugin.js" type="text/javascript"></script> <script src="./js/MIDI/loadPlugin.js" type="text/javascript"></script>
<script src="./js/MIDI/Plugin.js" type="text/javascript"></script> <script src="./js/MIDI/Plugin.js" type="text/javascript"></script>
<script src="./js/MIDI/Player.js" type="text/javascript"></script> <script src="./js/MIDI/Player.js" type="text/javascript"></script>
<script src="./js/Widgets/Loader.js" type="text/javascript"></script>
<script src="./js/Window/DOMLoader.XMLHttp.js" type="text/javascript"></script> <script src="./js/Window/DOMLoader.XMLHttp.js" type="text/javascript"></script>
<script src="./js/Window/DOMLoader.script.js" type="text/javascript"></script> <script src="./js/Window/DOMLoader.script.js" type="text/javascript"></script>
<!-- base64 packages --> <!-- base64 packages -->
@ -14,10 +15,15 @@
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
var loader;
window.onload = function () { window.onload = function () {
loader = new widgets.Loader;
MIDI.loadPlugin({ MIDI.loadPlugin({
instruments: [ "acoustic_grand_piano", "acoustic_guitar_nylon" ], // or multiple instruments instruments: [ "acoustic_grand_piano", "acoustic_guitar_nylon" ], // or multiple instruments
callback: function() { callback: function() {
loader.stop();
MIDI.programChange(0, 0);
MIDI.programChange(1, 24);
for (var n = 0; n < 100; n ++) { for (var n = 0; n < 100; n ++) {
var delay = n / 4; // play one note every quarter second var delay = n / 4; // play one note every quarter second
var note = MIDI.pianoKeyOffset + n; // the MIDI note var note = MIDI.pianoKeyOffset + n; // the MIDI note
@ -25,7 +31,7 @@ window.onload = function () {
// play the note // play the note
MIDI.noteOn(0, note, velocity, delay); MIDI.noteOn(0, note, velocity, delay);
// play the some note 3-steps up // play the some note 3-steps up
MIDI.noteOn(0, note + 3, velocity, delay); MIDI.noteOn(1, note + 3, velocity, delay);
} }
} }
}); });

View file

@ -205,35 +205,32 @@ Event.add(window, "load", function(event) {
colors.appendChild(d); colors.appendChild(d);
} }
// //
MIDI.loadPlugin({ MIDI.loadPlugin(function () {
instrument: 1, // this is the language we are running in
callback: function () { var title = document.getElementById("title");
// this is the language we are running in title.innerHTML = "Sound being generated with " + MIDI.lang + ".";
var title = document.getElementById("title"); // this sets up the MIDI.Player and gets things going...
title.innerHTML = "Sound being generated with " + MIDI.lang + "."; player = MIDI.Player;
// this sets up the MIDI.Player and gets things going... player.timeWarp = 1; // speed the song is played back
player = MIDI.Player; player.loadFile(song[songid++%3], player.start);
player.timeWarp = 1; // speed the song is played back // control the piano keys colors
player.loadFile(song[songid++%3], player.start); var colorMap = MusicTheory.Synesthesia.map();
// control the piano keys colors player.addListener(function(data) {
var colorMap = MusicTheory.Synesthesia.map(); var pianoKey = data.note - MIDI.pianoKeyOffset;
player.addListener(function(data) { var d = colorElements[pianoKey];
var pianoKey = data.note - MIDI.pianoKeyOffset; if (data.message === 144) {
var d = colorElements[pianoKey]; d.style.background = colorMap[data.note-27].hex;
if (data.message === 144) { d.style.color = "#fff";
d.style.background = colorMap[data.note-27].hex; } else {
d.style.color = "#fff"; d.style.background = "";
} else { d.style.color = "";
d.style.background = ""; }
d.style.color = ""; });
} //
}); ColorSphereBackground();
// MIDIPlayerPercentage(player);
ColorSphereBackground(); //
MIDIPlayerPercentage(player); loader.stop();
//
loader.stop();
}
}); });
}); });

View file

@ -66,7 +66,7 @@ RefreshFrame = function () {
var len = circleRadius * (1 + 1.0 / nbrPoints - r); var len = circleRadius * (1 + 1.0 / nbrPoints - r);
if (Math.floor(a / PI2) !== Math.floor(tines[i] / PI2)) { if (Math.floor(a / PI2) !== Math.floor(tines[i] / PI2)) {
MIDI.noteOn(0, i + 21, 100, 0); MIDI.noteOn(0, i + 21, 100, 0);
MIDI.noteOn(0, i + 21 + 36, 100, 0); MIDI.noteOn(24, i + 21 + 36, 100, 0);
lastSound[i] = ms; lastSound[i] = ms;
} }
var x = (cx + Math.cos(a) * len); var x = (cx + Math.cos(a) * len);
@ -85,21 +85,24 @@ RefreshFrame = function () {
}; };
window.onload = function () { window.onload = function () {
MIDI.loadPlugin(function() { MIDI.loadPlugin({
loader.stop(); instruments: [ "acoustic_grand_piano", "acoustic_guitar_nylon" ], // or multiple instruments
var canvas = document.getElementById('mycanvas'); callback: function() {
canvas.style.width = gw + "px"; loader.stop();
canvas.style.width = gw + "px"; var canvas = document.getElementById('mycanvas');
canvas.width = gw; canvas.style.width = gw + "px";
canvas.height = gh; canvas.style.width = gw + "px";
dc = canvas.getContext('2d'); canvas.width = gw;
for (var i = 0; i < nbrPoints; ++i) { canvas.height = gh;
if (i % 7 === 0) MIDI.noteOn(0, i + 21, 100, 0); dc = canvas.getContext('2d');
lastSound[i] = 0; for (var i = 0; i < nbrPoints; ++i) {
tines[i] = 0; if (i % 7 === 0) MIDI.noteOn(0, i + 21, 100, 0);
lastSound[i] = 0;
tines[i] = 0;
}
startTime = (new Date()).getTime();
setInterval(RefreshFrame, 1000 / 30);
} }
startTime = (new Date()).getTime();
setInterval(RefreshFrame, 1000 / 30);
}); });
}; };