Permalink
Browse files

get rid of the song, make the volume change according to the brush size

  • Loading branch information...
1 parent 0ca2dca commit 6628bec37f2b7e7099a7403d3181cb10041ecdc2 @eminaz eminaz committed Nov 10, 2013
Showing with 13 additions and 8 deletions.
  1. +9 −4 public/js/midi_test.js
  2. +4 −4 public/js/style.js
@@ -2,6 +2,7 @@
window.onload = init;
function init(){
+ audio_volume = 127;
MIDI.loadPlugin({
soundfontUrl: "./midi/soundfont/",
instruments: [ "acoustic_grand_piano", "synth_drum" ],
@@ -20,8 +21,6 @@
ctx = canvas.getContext('2d');
- console.log(ctx.strokeStyle);
-
window.onmousemove = handleMouseMove;
function handleMouseMove(event) {
event = event || window.event; // IE-ism
@@ -39,6 +38,8 @@
note = normalize(note);
+ check_volume();
+
console.log(note);
var random_num = Math.random();
if(random_num>0.9)
@@ -70,17 +71,21 @@
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.setVolume(0, audio_volume);
MIDI.noteOn(0, note, velocity, delay);
//MIDI.noteOff(0, note, delay + 0.75);
};
+ function check_volume(){
+ audio_volume = Math.round(200 * parseInt(document.getElementById('choose_range').value) / 15);
+ }
+
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);
+ MIDI.setVolume(0, audio_volume);
for(var i=0;i<arr.length;i++){
MIDI.noteOn(0, arr[i], velocity, delay);
}
View
@@ -42,7 +42,7 @@ $(function(){
});
//Audio
- var audio = new Audio('musics/01.mp3');
+ //var audio = new Audio('musics/01.mp3');
//canvas
var canvas = document.getElementById('myCanvas');
@@ -64,7 +64,7 @@ $(function(){
ctx.strokeStyle = $(this).attr("class");
//change music
- audio = new Audio('musics/01.mp3');
+ //audio = new Audio('musics/01.mp3');
});
@@ -184,7 +184,7 @@ var saved_dataURL;
var prev_state = ctx.getImageData(0,0,canvas.width,canvas.height);
history.pushState(prev_state, null);
// console.log(prev_state);
- audio.pause();
+ //audio.pause();
}
function drawing(e){
@@ -213,7 +213,7 @@ var saved_dataURL;
e.pageX - canvas.offsetLeft,
e.pageY - canvas.offsetTop
);
- audio.play();
+ //audio.play();
}

0 comments on commit 6628bec

Please sign in to comment.