Get gain control actually controlling audio. Refactor for cleaner code for mute.

This commit is contained in:
Jonathon Wilson 2013-02-03 15:47:17 -07:00
parent 0671587efa
commit 015921b08c
1 changed files with 45 additions and 22 deletions

View File

@ -13,6 +13,8 @@
var $draggingFaderHandle = null;
var $draggingFader = null;
var currentMixerId = null;
var currentMixerRangeMin = null;
var currentMixerRangeMax = null;
// Replicate the Channel Group enum from C++
var ChannelGroupIds = {
@ -28,6 +30,12 @@
9: "PeerAudioInputMusicGroup"
};
// Group 0 is the master mix. Mixer ID should go with the top horizontal volume slider, and possibly new VU meter.
// Group 1 is the monitor mix. Currently no UI component.
// Group 2 is my local music input. Any tracks here go into "My Tracks"
// Group 3 is my local voice chat.
// Group 4 is media files -- for sure for me locally, possibly from others?
function beforeShow(data) {
sessionId = data.id;
}
@ -97,8 +105,6 @@
function _updateMixers() {
var mixerIds = context.jamClient.SessionGetIDs();
mixers = context.jamClient.SessionGetControlState(mixerIds);
logger.debug("Mixers updated:");
logger.debug(mixers);
}
// Given a clientId, return a dictionary of mixer ids which
@ -217,7 +223,6 @@
eventName = arguments[3*i];
mixerId = arguments[(3*i)+1];
value = arguments[(3*i)+2];
//logger.debug(tuples + ',' + eventName + ',' + mixerId + ',' + value);
var vuVal = 0.0;
if (eventName === 'left_vu' || eventName === 'right_vu') {
// TODO - no guarantee range will be -80 to 20. Get from the
@ -261,26 +266,14 @@
}
function _toggleAudioMute(mixerId, muting) {
// 'fill' the trackVolume object volumes from what's in the
// corresponding mixer.
var mixer = null;
for (var i=0; i<mixers.length; i++) {
mixer = mixers[i];
if (mixer.id === mixerId) {
context.trackVolumeObject.volL = mixer.volume_left;
context.trackVolumeObject.volR = mixer.volume_right;
break;
}
}
context.trackVolumeObject.mute = muting;
logger.debug("Set Control State:");
logger.debug(context.trackVolumeObject);
context.jamClient.SessionSetControlState(mixerId);
}
function toggleMute(evt) {
var $control = $(evt.currentTarget);
var mixerId = $control.attr('mixer-id');
fillTrackVolumeObject(currentMixerId);
var muting = ($control.hasClass('enabled'));
_toggleVisualMuteControl($control, muting);
_toggleAudioMute(mixerId, muting);
@ -300,16 +293,44 @@
return faderPct;
}
function fillTrackVolumeObject(mixerId) {
var mixer = null;
for (var i=0; i<mixers.length; i++) {
mixer = mixers[i];
if (mixer.id === mixerId) {
context.trackVolumeObject.clientID = mixer.client_id;
context.trackVolumeObject.master = mixer.master;
context.trackVolumeObject.monitor = mixer.monitor;
context.trackVolumeObject.mute = mixer.mute;
context.trackVolumeObject.name = mixer.name;
context.trackVolumeObject.record = mixer.record;
context.trackVolumeObject.volL = mixer.volume_left;
context.trackVolumeObject.volR = mixer.volume_right;
// trackVolumeObject doesn't have a place for range min/max
currentMixerRangeMin = mixer.range_low;
currentMixerRangeMax = mixer.range_high;
break;
}
}
}
// Given a volumne percent (0-100), set the underlying
// audio volume level of the passed mixerId to the correct
// value.
function setMixerVolume(mixerId, volumePercent) {
// TODO - implement me. Update trackVolumeObject values, then
// call SessionSetControlState with the mixer id.
// Create a function: trackVolumeObjectFromMixerId, which fills out
// all of the properties of the trackVolumeObject given a mixerId.
// Call this on anything that sets the currentMixerId.
logger.debug("Set mixer, " + mixerId + " to " + volumePercent);
// The context.trackVolumeObject has been filled with the mixer values
// that go with mixerId, and the range of that mixer
// has been set in currentMixerRangeMin-Max.
// All that needs doing is to translate the incoming percent
// into the real value ont the sliders range. Set Left/Right
// volumes on trackVolumeObject, and call SetControlState to stick.
var sliderRange = currentMixerRangeMax - currentMixerRangeMin;
volumePercent = volumePercent/100;
var sliderValue = currentMixerRangeMin + (volumePercent * sliderRange);
context.trackVolumeObject.volL = sliderValue;
context.trackVolumeObject.volR = sliderValue;
context.jamClient.SessionSetControlState(mixerId);
}
function faderClick(evt) {
@ -321,6 +342,7 @@
var $handle = $fader.find('div[control="fader-handle"]');
var faderPct = getFaderPercent(evt.clientY, $fader);
var mixerId = $fader.closest('[mixer-id]').attr('mixer-id');
fillTrackVolumeObject(mixerId);
setMixerVolume(mixerId, faderPct);
if (faderPct > 90) { faderPct = 90; } // Visual limit
$handle.css('bottom', faderPct + '%');
@ -332,6 +354,7 @@
$draggingFaderHandle = $(evt.currentTarget);
$draggingFader = $draggingFaderHandle.closest('div[control="fader"]');
currentMixerId = $draggingFader.closest('[mixer-id]').attr('mixer-id');
fillTrackVolumeObject(currentMixerId);
return false;
}