Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions js/midi/gm.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@
channel.solo = truthy;
}
};

/* get/setChannelVolume
--------------------------------------------------- */
root.getChannelVolume = function(channelId) {
var channel = root.channels[channelId];
return channel && channel.volume;
};

root.setChannelVolume = function(channelId, truthy) {
var channel = root.channels[channelId];
if (delay) {
return setTimeout(function() {
channel.volume = truthy;
}, delay);
} else {
channel.volume = truthy;
}
};

/* channels
--------------------------------------------------- */
Expand All @@ -132,6 +150,7 @@
channels[i] = { // default values
instrument: i,
pitchBend: 0,
volume: 127,
mute: false,
mono: false,
omni: false,
Expand Down
17 changes: 12 additions & 5 deletions js/midi/plugin.audiotag.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
window.Audio && (function() {
var midi = root.AudioTag = { api: 'audiotag' };
var noteToKey = {};
var volume = 127; // floating point
var buffer_nid = -1; // current channel
var audioBuffers = []; // the audio channels
var notesOn = []; // instrumentId + noteId that is currently playing in each 'channel', for routing noteOff/chordOff calls
Expand All @@ -37,7 +36,7 @@
return;
}
audio.src = root.Soundfont[instrumentId][note.id];
audio.volume = volume / 127;
audio.volume = root.channels[channel].volume / 127;
audio.play();
buffer_nid = nid;
}
Expand All @@ -64,9 +63,17 @@

midi.audioBuffers = audioBuffers;
midi.send = function(data, delay) { };
midi.setController = function(channel, type, value, delay) { };
midi.setVolume = function(channel, n) {
volume = n; //- should be channel specific volume
midi.setController = function(channel, type, value, delay) {
if(type == 7) root.setVolume(channel, value, delay);
};
midi.setVolume = function(channel, n, delay) {
if (delay) {
return setTimeout(function() {
root.channels[channel].volume = n;
}, delay * 1000);
} else {
root.channels[channel].volume = n;
}
};

midi.programChange = function(channel, program) {
Expand Down
24 changes: 14 additions & 10 deletions js/midi/plugin.webaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@
var ctx; // audio context
var sources = {};
var effects = {};
var masterVolume = 127;
var audioBuffers = {};
///
midi.audioBuffers = audioBuffers;
midi.send = function(data, delay) { };
midi.setController = function(channelId, type, value, delay) { };
midi.setController = function(channelId, type, value, delay) {
if(type == 7) root.setVolume(channelId, value, delay);
};

midi.setVolume = function(channelId, volume, delay) {
if (delay) {
setTimeout(function() {
masterVolume = volume;
}, delay * 1000);
} else {
masterVolume = volume;
}
// if (delay) {
// setTimeout(function() {
// var channel = root.channels[channelId];
// channel.volume = volume;
// }, delay * 1000);
// } else {
var channel = root.channels[channelId];
channel.volume = volume;
// }
};

midi.programChange = function(channelId, program, delay) {
Expand Down Expand Up @@ -92,7 +95,8 @@
}

/// add gain + pitchShift
var gain = (velocity / 127) * (masterVolume / 127) * 2 - 1;
var channel = root.channels[channelId];
var gain = ((velocity / 127) * (channel.volume / 127) * 2) - 1;
source.connect(ctx.destination);
source.playbackRate.value = 1; // pitch shift
source.gainNode = ctx.createGain(); // gain
Expand Down