755 lines
29 KiB
JavaScript
755 lines
29 KiB
JavaScript
(function(context,$) {
|
|
|
|
"use strict";
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.SessionScreen = function(app) {
|
|
var logger = context.JK.logger;
|
|
var sessionId;
|
|
var session = null;
|
|
var users = {}; // Light cache of user info for session users.
|
|
var tracks = {};
|
|
var mixers = [];
|
|
// Consolidate dragged controls and handles
|
|
var $draggingFaderHandle = null;
|
|
var $draggingFader = null;
|
|
var $draggingVolumeHandle = null;
|
|
var $draggingVolume = null;
|
|
var $draggingChatHandle = null;
|
|
var $draggingChat = null;
|
|
var currentMixerId = null;
|
|
var currentMixerRangeMin = null;
|
|
var currentMixerRangeMax = null;
|
|
|
|
var lookingForMixersCount = 0;
|
|
var lookingForMixersTimer = null;
|
|
var lookingForMixers = {};
|
|
|
|
var defaultParticipant = {
|
|
tracks: [{
|
|
instrument_id: "unknown"
|
|
}],
|
|
user: {
|
|
first_name: 'Unknown',
|
|
last_name: 'User',
|
|
photo_url: null
|
|
}
|
|
};
|
|
|
|
// Replicate the Channel Group enum from C++
|
|
var ChannelGroupIds = {
|
|
0: "MasterGroup",
|
|
1: "MonitorGroup",
|
|
2: "AudioInputMusicGroup",
|
|
3: "AudioInputChatGroup",
|
|
4: "MediaTrackGroup",
|
|
5: "StreamOutMusicGroup",
|
|
6: "StreamOutChatGroup",
|
|
7: "UserMusicInputGroup",
|
|
8: "UserChatInputGroup",
|
|
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?
|
|
|
|
// Results for a live session where David joined my session.
|
|
// P2P message from my client to Davids (JamServer.js:121)
|
|
// Events fired:
|
|
// add,User@208.191.152.98#,0 (session.js:233)
|
|
// add,User@208.191.152.98_*,0
|
|
// add,User@208.191.152.98#,0
|
|
// add,User@208.191.152.98_*,0
|
|
// jamkazam.js:50 -- various PEER_MESSAGE here and there
|
|
// jamkazam.js:50 - USER_JOINED_MUSIC_SESSION (session_id, user_id, username: "David Wilson")
|
|
// my session refreshed (refreshSession.js:39) with 2 participants
|
|
// more PEER_MESSAGE
|
|
// Mixers updated (session.js:97)
|
|
// 4 now (instead of 2). New ones:
|
|
// client_id: David's Client Id
|
|
// group_id: 7
|
|
// id: User@208.191.152.98#
|
|
// volume_left: 0
|
|
// volume_right: 0
|
|
//
|
|
// client_id: ""
|
|
// group_id: 9
|
|
// id: User@208.191.152.98_*
|
|
// volume_left: 12
|
|
// volume:right: 15
|
|
//
|
|
// more add,User@208.191.152.98#,0 events.
|
|
//
|
|
// Eventually, Socket to server closed. (JamServer.js:86)
|
|
|
|
function beforeShow(data) {
|
|
sessionId = data.id;
|
|
$('#session-mytracks-container').empty();
|
|
$('#session-livetracks-container').empty();
|
|
}
|
|
|
|
function afterShow(data) {
|
|
context.JK.joinMusicSession(sessionId, app);
|
|
// Subscribe for callbacks on audio events
|
|
context.jamClient.SessionRegisterCallback("JK.HandleBridgeCallback");
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "/api/sessions/" + sessionId,
|
|
success: updateSession,
|
|
error: fetchSessionError
|
|
});
|
|
}
|
|
|
|
function fetchSessionError() {
|
|
context.location = '#/home';
|
|
}
|
|
|
|
function beforeHide(data) {
|
|
// Move joinSession function to this file for ease of finding it?
|
|
context.JK.leaveMusicSession(sessionId);
|
|
// 'unregister' for callbacks
|
|
context.jamClient.SessionRegisterCallback("");
|
|
}
|
|
|
|
function updateSession(sessionData) {
|
|
session = sessionData;
|
|
updateParticipants(function() { renderSession(); });
|
|
}
|
|
|
|
/**
|
|
* Make sure that for each participant in the session, we have user info.
|
|
*/
|
|
function updateParticipants(onComplete) {
|
|
var callCount = 0;
|
|
$.each(session.participants, function(index, value) {
|
|
if (!(this.user.id in users)) {
|
|
callCount += 1;
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "/api/users/" + this.user.id
|
|
}).done(function(user) {
|
|
callCount -= 1;
|
|
users[user.id] = user;
|
|
});
|
|
}
|
|
});
|
|
if (!(onComplete)) {
|
|
return;
|
|
}
|
|
// TODO: generalize this pattern. Likely needed elsewhere.
|
|
function checker() {
|
|
if (callCount === 0) {
|
|
onComplete();
|
|
} else {
|
|
context.setTimeout(checker, 10);
|
|
}
|
|
}
|
|
checker();
|
|
}
|
|
|
|
function renderSession() {
|
|
$('#session-mytracks-container').empty();
|
|
$('#session-livetracks-container').empty();
|
|
_updateMixers();
|
|
_renderTracks();
|
|
_wireTopVolume();
|
|
_addVoiceChat();
|
|
}
|
|
|
|
// Get the latest list of underlying audio mixer channels
|
|
function _updateMixers() {
|
|
var mixerIds = context.jamClient.SessionGetIDs();
|
|
var holder = $.extend(true, {}, {mixers: context.jamClient.SessionGetControlState(mixerIds)});
|
|
mixers = holder.mixers;
|
|
}
|
|
|
|
function _participantForClientId(clientId) {
|
|
var foundParticipant = null;
|
|
$.each(session.participants, function(index, participant) {
|
|
if (participant.client_id === clientId) {
|
|
foundParticipant = participant;
|
|
return false;
|
|
}
|
|
});
|
|
return foundParticipant;
|
|
}
|
|
|
|
function _mixerForClientId(clientId, groupIds) {
|
|
var foundMixer = null;
|
|
$.each(mixers, function(index, mixer) {
|
|
if (mixer.client_id === clientId) {
|
|
for (var i=0; i<groupIds.length; i++) {
|
|
if (mixer.group_id === groupIds[i]) {
|
|
foundMixer = mixer;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
return foundMixer;
|
|
}
|
|
|
|
function _wireTopVolume() {
|
|
var $volumeSlider = $('#volume');
|
|
$.each(mixers, function(index, mixer) {
|
|
if (mixer.group_id === 0) { // master
|
|
$volumeSlider.attr('master-id', mixer.id);
|
|
var gainPercent = percentFromMixerValue(
|
|
mixer.range_low, mixer.range_high, mixer.volume_left);
|
|
$volumeSlider.find('.slider-volume').css('left', gainPercent + '%');
|
|
}
|
|
if (mixer.group_id === 1) { // monitor
|
|
$volumeSlider.attr('monitor-id', mixer.id);
|
|
}
|
|
});
|
|
}
|
|
|
|
function _addVoiceChat() {
|
|
// If, and only if, there is a mixer in group 3 (voice chat)
|
|
// Add the voice chat controls below my tracks, and hook up the mixer.
|
|
// Assumption is that there is only ever one, so we just take the first one.
|
|
$.each(mixers, function(index, mixer) {
|
|
if (mixer.group_id === 3) { // Local voice chat
|
|
var $voiceChat = $('#voice-chat');
|
|
$voiceChat.show();
|
|
$voiceChat.attr('mixer-id', mixer.id);
|
|
$('#voice-chat .voicechat-mute').attr('mixer-id', mixer.id);
|
|
|
|
var gainPercent = percentFromMixerValue(
|
|
mixer.range_low, mixer.range_high, mixer.volume_left);
|
|
$voiceChat.find('.voicechat-gain-slider').css({'left': gainPercent + '%'});
|
|
if (mixer.mute) {
|
|
var $mute = $voiceChat.find('.voicechat-mute');
|
|
_toggleVisualMuteControl($mute, true);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
var instrumentIcons = {
|
|
"keyboard": "content/icon_instrument_keyboard45.png",
|
|
"electric guitar": "content/icon_instrument_guitar45.png",
|
|
"bass guitar": "content/icon_instrument_guitar45.png",
|
|
"voice": "content/icon_instrument_vocal45.png"
|
|
};
|
|
|
|
function _instrumentIconFromId(id) {
|
|
if (id in instrumentIcons) {
|
|
return instrumentIcons[id];
|
|
}
|
|
// return default instrument for any unknowns
|
|
return "content/icon_instrument_default45.png";
|
|
}
|
|
|
|
function _renderTracks() {
|
|
// Participants are here now, but the mixers don't update right away.
|
|
// Draw tracks from participants, then setup timers to look for the
|
|
// mixers that go with those participants, if they're missing.
|
|
lookingForMixersCount = 0;
|
|
$.each(session.participants, function(index, participant) {
|
|
|
|
var name = participant.user.name;
|
|
if (!(name)) {
|
|
name = participant.user.first_name + ' ' + participant.user.last_name;
|
|
}
|
|
var instrumentIcon = _instrumentIconFromId(participant.tracks[0].instrument_id);
|
|
var photoUrl = participant.user.photo_url;
|
|
if (!(photoUrl)) {
|
|
photoUrl = "/assets/shared/avatar_default.jpg";
|
|
}
|
|
|
|
var myTrack = false;
|
|
|
|
// Default trackData to participant + no Mixer state.
|
|
var trackData = {
|
|
clientId: participant.client_id,
|
|
name: name,
|
|
instrumentIcon: instrumentIcon,
|
|
avatar: photoUrl,
|
|
latency: "good",
|
|
gainPercent: 0,
|
|
muteClass: 'muted',
|
|
mixerId: ""
|
|
};
|
|
|
|
var mixer = _mixerForClientId(participant.client_id, [2,7]);
|
|
if (mixer) {
|
|
myTrack = (mixer.group_id === 2);
|
|
var gainPercent = percentFromMixerValue(
|
|
mixer.range_low, mixer.range_high, mixer.volume_left);
|
|
var muteClass = "enabled";
|
|
if (mixer.mute) {
|
|
muteClass = "muted";
|
|
}
|
|
trackData.gainPercent = gainPercent;
|
|
trackData.muteClass = muteClass;
|
|
trackData.mixerId = mixer.id;
|
|
} else { // No mixer to match, yet
|
|
lookingForMixers[participant.client_id] = true;
|
|
if (!(lookingForMixersTimer)) {
|
|
lookingForMixersTimer = context.setInterval(lookForMixers, 300);
|
|
}
|
|
}
|
|
_addTrack(trackData);
|
|
// Show settings icons only for my tracks
|
|
if (myTrack) {
|
|
$('div[mixer-id="' + mixer.id + '"].track-icon-settings').show();
|
|
}
|
|
});
|
|
}
|
|
|
|
// Function called on an interval when participants change. Mixers seem to
|
|
// show up later, so we render the tracks from participants, but keep track
|
|
// of the ones there weren't any mixers for, and continually try to find them
|
|
// and get them connected to the mixers underneath.
|
|
function lookForMixers() {
|
|
lookingForMixersCount++;
|
|
_updateMixers();
|
|
var keysToDelete = [];
|
|
for (var key in lookingForMixers) {
|
|
var mixer = _mixerForClientId(key, [2,7]);
|
|
if (mixer) {
|
|
keysToDelete.push(key);
|
|
var gainPercent = percentFromMixerValue(
|
|
mixer.range_low, mixer.range_high, mixer.volume_left);
|
|
var $track = $('div.track[client-id="' + key + '"]');
|
|
// Set mixer-id attributes
|
|
$track.find('.vu').attr('mixer-id', mixer.id);
|
|
$track.find('.track-gain').attr('mixer-id', mixer.id);
|
|
$track.find('.track-icon-mute').attr('mixer-id', mixer.id);
|
|
$track.find('.track-icon-settings').attr('mixer-id', mixer.id);
|
|
|
|
// Set gain position
|
|
$track.find('.track-gain-slider').css('bottom', gainPercent + '%');
|
|
|
|
// Set mute state
|
|
_toggleVisualMuteControl($track.find('.track-icon-mute'), mixer.mute);
|
|
}
|
|
}
|
|
|
|
for (var i=0; i<keysToDelete.length; i++) {
|
|
delete lookingForMixers[keysToDelete[i]];
|
|
}
|
|
|
|
if (context.JK.dlen(lookingForMixers) === 0 ||
|
|
lookingForMixersCount > 10) {
|
|
lookingForMixersCount = 0;
|
|
lookingForMixers = {};
|
|
context.clearTimeout(lookingForMixersTimer);
|
|
lookingForMixersTimer = null;
|
|
}
|
|
}
|
|
|
|
|
|
// Given a mixerID and a value between 0.0-1.0,
|
|
// light up the proper VU lights.
|
|
function _updateVU(mixerId, value) {
|
|
// Minor tweak to support VU values -- the mixerId here will
|
|
// have a suffix added _vul or _vur to indicate the channel.
|
|
// There are 13 VU lights. Figure out how many to
|
|
// light based on the incoming value.
|
|
var i = 0;
|
|
var state = 'on';
|
|
var lights = Math.round(13 * value);
|
|
var selector = null;
|
|
var $light = null;
|
|
var colorClass = 'vu-green-';
|
|
// Remove all light classes from all lights
|
|
var allLightsSelector = '#tracks table[mixer-id="' + mixerId + '"] td.vulight';
|
|
$(allLightsSelector).removeClass('vu-green-off vu-green-on vu-red-off vu-red-on');
|
|
|
|
// Set the lights
|
|
for (i=0; i<13; i++) {
|
|
colorClass = 'vu-green-';
|
|
state = 'on';
|
|
if (i > 8) {
|
|
colorClass = 'vu-red-';
|
|
}
|
|
if (i >= lights) {
|
|
state = 'off';
|
|
}
|
|
selector = '#tracks table[mixer-id="' + mixerId + '"] td.vu' + i;
|
|
$light = $(selector);
|
|
$light.addClass(colorClass + state);
|
|
}
|
|
}
|
|
|
|
function _addTrack(trackData) {
|
|
var $destination = $('#session-mytracks-container');
|
|
if (trackData.clientId !== app.clientId) {
|
|
$destination = $('#session-livetracks-container');
|
|
}
|
|
trackData["left-vu"] = $('#template-vu').html();
|
|
trackData["right-vu"] = trackData["left-vu"];
|
|
var template = $('#template-session-track').html();
|
|
var newTrack = context.JK.fillTemplate(template, trackData);
|
|
$destination.append(newTrack);
|
|
tracks[trackData.clientId] = new context.JK.SessionTrack(trackData.clientId);
|
|
}
|
|
|
|
function _userJoinedSession(header, payload) {
|
|
// Just refetch the session and update.
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "/api/sessions/" + sessionId
|
|
}).done(function(response) {
|
|
updateSession(response);
|
|
});
|
|
}
|
|
|
|
function handleBridgeCallback() {
|
|
var eventName = null;
|
|
var mixerId = null;
|
|
var value = null;
|
|
var tuples = arguments.length / 3;
|
|
for (var i=0; i<tuples; i++) {
|
|
eventName = arguments[3*i];
|
|
mixerId = arguments[(3*i)+1];
|
|
value = arguments[(3*i)+2];
|
|
var vuVal = 0.0;
|
|
if (eventName === 'left_vu' || eventName === 'right_vu') {
|
|
// TODO - no guarantee range will be -80 to 20. Get from the
|
|
// GetControlState for this mixer which returns min/max
|
|
// value is a DB value from -80 to 20. Convert to float from 0.0-1.0
|
|
vuVal = (value + 80) / 100;
|
|
if (eventName === 'left_vu') {
|
|
mixerId = mixerId + "_vul";
|
|
} else {
|
|
mixerId = mixerId + "_vur";
|
|
}
|
|
_updateVU(mixerId, vuVal);
|
|
} else {
|
|
// Examples of other events
|
|
// Add media file track: "add", "The_Abyss_4T", 0
|
|
logger.debug('non-vu event: ' + eventName + ',' + mixerId + ',' + value);
|
|
}
|
|
}
|
|
}
|
|
|
|
function deleteSession(evt) {
|
|
var sessionId = $(evt.currentTarget).attr("action-id");
|
|
if (sessionId) {
|
|
$.ajax({
|
|
type: "DELETE",
|
|
url: "/api/sessions/" + sessionId
|
|
}).done(
|
|
function() { context.location="#/home"; }
|
|
);
|
|
}
|
|
}
|
|
|
|
function _toggleVisualMuteControl($control, muting) {
|
|
if (muting) {
|
|
$control.removeClass('enabled');
|
|
$control.addClass('muted');
|
|
} else {
|
|
$control.removeClass('muted');
|
|
$control.addClass('enabled');
|
|
}
|
|
}
|
|
|
|
function _toggleAudioMute(mixerId, muting) {
|
|
context.trackVolumeObject.mute = muting;
|
|
context.jamClient.SessionSetControlState(mixerId);
|
|
}
|
|
|
|
function toggleMute(evt) {
|
|
var $control = $(evt.currentTarget);
|
|
var mixerId = $control.attr('mixer-id');
|
|
currentMixerId = mixerId;
|
|
fillTrackVolumeObject(currentMixerId);
|
|
var muting = ($control.hasClass('enabled'));
|
|
_toggleVisualMuteControl($control, muting);
|
|
_toggleAudioMute(mixerId, muting);
|
|
}
|
|
|
|
function getVerticalFaderPercent(eventY, $fader) {
|
|
var faderPosition = $fader.offset();
|
|
var faderHeight = $fader.height();
|
|
var handleValue = faderHeight - (eventY - faderPosition.top);
|
|
var faderPct = Math.round(handleValue/faderHeight * 100);
|
|
if (faderPct < 0) {
|
|
faderPct = 0;
|
|
}
|
|
if (faderPct > 100) {
|
|
faderPct = 100;
|
|
}
|
|
return faderPct;
|
|
}
|
|
|
|
function getHorizontalFaderPercent(eventX, $fader) {
|
|
var faderPosition = $fader.offset();
|
|
var faderWidth = $fader.width();
|
|
var handleValue = (eventX - faderPosition.left);
|
|
var faderPct = Math.round(handleValue/faderWidth * 100);
|
|
if (faderPct < 0) {
|
|
faderPct = 0;
|
|
}
|
|
if (faderPct > 100) {
|
|
faderPct = 100;
|
|
}
|
|
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 mixer's min/max and current value, return it as
|
|
// a percent from 0-100. Return an integer.
|
|
function percentFromMixerValue(min, max, value) {
|
|
var range = Math.abs(max - min);
|
|
var magnitude = value - min;
|
|
var percent = Math.round(100*(magnitude/range));
|
|
return percent;
|
|
}
|
|
|
|
// Given a mixer's min/max and a percent value, return it as
|
|
// the mixer's value. Returns an integer.
|
|
function percentToMixerValue(min, max, percent) {
|
|
var range = Math.abs(max - min);
|
|
var multiplier = percent/100; // Change 85 into 0.85
|
|
var value = min + (multiplier * range);
|
|
// Protect against percents < 0 and > 100
|
|
if (value < min) {
|
|
value = min;
|
|
}
|
|
if (value > max) {
|
|
value = max;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
// Given a volume percent (0-100), set the underlying
|
|
// audio volume level of the passed mixerId to the correct
|
|
// value.
|
|
function setMixerVolume(mixerId, 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 sliderValue = percentToMixerValue(
|
|
currentMixerRangeMin, currentMixerRangeMax, volumePercent);
|
|
context.trackVolumeObject.volL = sliderValue;
|
|
context.trackVolumeObject.volR = sliderValue;
|
|
context.jamClient.SessionSetControlState(mixerId);
|
|
}
|
|
|
|
|
|
// Refactor. Only need one of these xxxDown methods.
|
|
function faderHandleDown(evt) {
|
|
evt.stopPropagation();
|
|
$draggingFaderHandle = $(evt.currentTarget);
|
|
$draggingFader = $draggingFaderHandle.closest('div[control="fader"]');
|
|
currentMixerId = $draggingFader.closest('[mixer-id]').attr('mixer-id');
|
|
fillTrackVolumeObject(currentMixerId);
|
|
return false;
|
|
}
|
|
|
|
function volumeHandleDown(evt) {
|
|
evt.stopPropagation();
|
|
$draggingVolumeHandle = $(evt.currentTarget);
|
|
$draggingVolume = $('#volume');
|
|
currentMixerId = $draggingVolume.attr('master-id');
|
|
fillTrackVolumeObject(currentMixerId);
|
|
return false;
|
|
}
|
|
|
|
function chatHandleDown(evt) {
|
|
evt.stopPropagation();
|
|
$draggingChatHandle = $(evt.currentTarget);
|
|
$draggingChat = $draggingChatHandle.closest('div[control="fader"]');
|
|
currentMixerId = $draggingChat.closest('[mixer-id]').attr('mixer-id');
|
|
fillTrackVolumeObject(currentMixerId);
|
|
return false;
|
|
}
|
|
|
|
|
|
// TODO - only need one of these next three
|
|
function tracksMouseUp(evt) {
|
|
evt.stopPropagation();
|
|
if ($draggingFaderHandle) {
|
|
$draggingFaderHandle = null;
|
|
$draggingFader = null;
|
|
currentMixerId = null;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function volumeMouseUp(evt) {
|
|
evt.stopPropagation();
|
|
if ($draggingVolumeHandle) {
|
|
$draggingVolumeHandle = null;
|
|
$draggingVolume = null;
|
|
currentMixerId = null;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function chatMouseUp(evt) {
|
|
evt.stopPropagation();
|
|
if ($draggingChatHandle) {
|
|
$draggingChatHandle = null;
|
|
$draggingChat = null;
|
|
currentMixerId = null;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// TODO - only need one of next three
|
|
function tracksMouseMove(evt) {
|
|
// bail out early if there's no in-process drag
|
|
if (!($draggingFaderHandle)) {
|
|
return false;
|
|
}
|
|
evt.stopPropagation();
|
|
var faderPct = getVerticalFaderPercent(evt.clientY, $draggingFader);
|
|
setMixerVolume(currentMixerId, faderPct);
|
|
if (faderPct > 90) { faderPct = 90; } // Visual limit
|
|
$draggingFaderHandle.css('bottom', faderPct + '%');
|
|
return false;
|
|
}
|
|
|
|
function volumeMouseMove(evt) {
|
|
// bail out early if there's no in-process drag
|
|
if (!($draggingVolumeHandle)) {
|
|
return false;
|
|
}
|
|
evt.stopPropagation();
|
|
var faderPct = getHorizontalFaderPercent(evt.clientX, $draggingVolume);
|
|
setMixerVolume(currentMixerId, faderPct);
|
|
// TODO - this could use attention:
|
|
var monitorId = $draggingVolume.attr('monitor-id');
|
|
setMixerVolume(monitorId, faderPct);
|
|
if (faderPct > 90) { faderPct = 90; } // Visual limit
|
|
$draggingVolumeHandle.css('left', faderPct + '%');
|
|
return false;
|
|
}
|
|
|
|
function chatMouseMove(evt) {
|
|
// bail out early if there's no in-process drag
|
|
if (!($draggingChatHandle)) {
|
|
return false;
|
|
}
|
|
evt.stopPropagation();
|
|
var faderPct = getHorizontalFaderPercent(evt.clientX, $draggingChat);
|
|
setMixerVolume(currentMixerId, faderPct);
|
|
if (faderPct > 90) { faderPct = 90; } // Visual limit
|
|
$draggingChatHandle.css('left', faderPct + '%');
|
|
return false;
|
|
}
|
|
|
|
// TODO - refactor - all these clicks are the same.
|
|
// Parameters and consolidate into one.
|
|
function faderClick(evt) {
|
|
evt.stopPropagation();
|
|
if ($draggingFaderHandle) {
|
|
return;
|
|
}
|
|
var $fader = $(evt.currentTarget);
|
|
var $handle = $fader.find('div[control="fader-handle"]');
|
|
var faderPct = getVerticalFaderPercent(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 + '%');
|
|
return false;
|
|
}
|
|
|
|
function voiceChatClick(evt) {
|
|
evt.stopPropagation();
|
|
if ($draggingChatHandle) {
|
|
return;
|
|
}
|
|
var $fader = $(evt.currentTarget);
|
|
var $handle = $fader.find('div[control="fader-handle"]');
|
|
var faderPct = getHorizontalFaderPercent(evt.clientX, $fader);
|
|
var mixerId = $fader.closest('[mixer-id]').attr('mixer-id');
|
|
fillTrackVolumeObject(mixerId);
|
|
setMixerVolume(mixerId, faderPct);
|
|
if (faderPct > 90) { faderPct = 90; } // Visual limit
|
|
$handle.css('left', faderPct + '%');
|
|
return false;
|
|
}
|
|
|
|
function volumeClick(evt) {
|
|
evt.stopPropagation();
|
|
if ($draggingVolumeHandle) {
|
|
return;
|
|
}
|
|
var $volume = $(evt.currentTarget);
|
|
var $handle = $volume.find('div.slider-volume');
|
|
var faderPct = getHorizontalFaderPercent(evt.clientX, $volume);
|
|
var masterId = $volume.attr('master-id');
|
|
var monitorId = $volume.attr('monitor-id');
|
|
fillTrackVolumeObject(masterId);
|
|
setMixerVolume(masterId, faderPct);
|
|
fillTrackVolumeObject(monitorId);
|
|
setMixerVolume(monitorId, faderPct);
|
|
if (faderPct > 90) { faderPct = 90; } // Visual limit
|
|
$handle.css('left', faderPct + '%');
|
|
return false;
|
|
}
|
|
|
|
function events() {
|
|
$('#session-contents').on("click", '[action="delete"]', deleteSession);
|
|
$('#tracks').on('click', 'div[control="mute"]', toggleMute);
|
|
$('#tracks').on('click', 'div[control="fader"]', faderClick);
|
|
$('#tracks').on('mousedown', 'div[control="fader-handle"]', faderHandleDown);
|
|
$('#tracks').on('mousemove', tracksMouseMove);
|
|
$('body').on('mouseup', tracksMouseUp);
|
|
|
|
$('#volume').on('click', volumeClick);
|
|
$('#volume').on('mousedown', '.slider-volume', volumeHandleDown);
|
|
$('body').on('mousemove', volumeMouseMove);
|
|
$('body').on('mouseup', volumeMouseUp);
|
|
|
|
// Go ahead and wire up voice-chat events, although it won't be visible
|
|
// (and can't fire events) unless the user has a voice chat mixer
|
|
$('#voice-chat').on('click', 'div[control="fader"]', voiceChatClick);
|
|
$('#voice-chat').on('mousedown', 'div[control="fader-handle"]', chatHandleDown);
|
|
$('#voice-chat').on('mousemove', chatMouseMove);
|
|
$('body').on('mouseup', chatMouseUp);
|
|
}
|
|
|
|
this.initialize = function() {
|
|
events();
|
|
var screenBindings = {
|
|
'beforeShow': beforeShow,
|
|
'afterShow': afterShow,
|
|
'beforeHide': beforeHide
|
|
};
|
|
app.bindScreen('session', screenBindings);
|
|
app.subscribe(context.JK.MessageType.USER_JOINED_MUSIC_SESSION, _userJoinedSession);
|
|
};
|
|
|
|
this.tracks = tracks;
|
|
|
|
context.JK.HandleBridgeCallback = handleBridgeCallback;
|
|
|
|
};
|
|
|
|
})(window,jQuery); |