219 lines
8.4 KiB
JavaScript
219 lines
8.4 KiB
JavaScript
(function(context,$) {
|
|
|
|
"use strict";
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.AddTrackDialog = function(app, myTracks, sessionId, sessionModel) {
|
|
var logger = context.JK.logger;
|
|
|
|
var myTrackCount = myTracks.length;
|
|
|
|
var ASSIGNMENT = {
|
|
CHAT: -2,
|
|
OUTPUT: -1,
|
|
UNASSIGNED: 0,
|
|
TRACK1: 1,
|
|
TRACK2: 2
|
|
};
|
|
|
|
var VOICE_CHAT = {
|
|
CHAT: "0",
|
|
SESSION: "1",
|
|
MIC: "2"
|
|
};
|
|
|
|
var instrument_array = [];
|
|
|
|
var instrument_map = {
|
|
"Acoustic Guitar": { "client_id": 10, "server_id": "acoustic guitar" },
|
|
"Bass Guitar": { "client_id": 20, "server_id": "bass guitar" },
|
|
"Computer": { "client_id": 30, "server_id": "computer" },
|
|
"Drums": { "client_id": 40, "server_id": "drums" },
|
|
"Electric Guitar": { "client_id": 50, "server_id": "electric guitar" },
|
|
"Keyboard": { "client_id": 60, "server_id": "keyboard" },
|
|
"Voice": { "client_id": 70, "server_id": "voice" },
|
|
"Flute": { "client_id": 80, "server_id": "flute" },
|
|
"Clarinet": { "client_id": 90, "server_id": "clarinet" },
|
|
"Saxophone": { "client_id": 100, "server_id": "saxophone" },
|
|
"Trumpet": { "client_id": 110, "server_id": "trumpet" },
|
|
"Violin": { "client_id": 120, "server_id": "violin" },
|
|
"Trombone": { "client_id": 130, "server_id": "trombone" },
|
|
"Banjo": { "client_id": 140, "server_id": "banjo" },
|
|
"Harmonica": { "client_id": 150, "server_id": "harmonica" },
|
|
"Accordion": { "client_id": 160, "server_id": "accordion" },
|
|
"French Horn": { "client_id": 170, "server_id": "french horn" },
|
|
"Euphonium": { "client_id": 180, "server_id": "euphonium" },
|
|
"Tuba": { "client_id": 190, "server_id": "tuba" },
|
|
"Oboe": { "client_id": 200, "server_id": "oboe" },
|
|
"Ukulele": { "client_id": 210, "server_id": "ukulele" },
|
|
"Cello": { "client_id": 220, "server_id": "cello" },
|
|
"Viola": { "client_id": 230, "server_id": "viola" },
|
|
"Mandolin": { "client_id": 240, "server_id": "mandolin" },
|
|
"Other": { "client_id": 250, "server_id": "other" }
|
|
};
|
|
|
|
// dialog variables
|
|
var unusedAudioInputChannels = [];
|
|
var track2AudioInputChannels = [];
|
|
|
|
function events() {
|
|
|
|
// Track 2 Add
|
|
$('#img-add-track2-input-add').click(function() {
|
|
$('#add-track2-unused > option:selected').remove().appendTo('#add-track2-input');
|
|
});
|
|
|
|
// Track 2 Remove
|
|
$('#img-add-track2-input-remove').click(function() {
|
|
$('#add-track2-input > option:selected').remove().appendTo('#add-track2-unused');
|
|
});
|
|
|
|
$('#btn-cancel-new-audio').click(showOverlay);
|
|
$('#btn-error-ok').click(showOverlay);
|
|
$('#btn-add-track').click(saveSettings);
|
|
|
|
$('#btn-leave-session-test').click(function() {
|
|
$('div[layout-id="add-track"]').hide();
|
|
});
|
|
}
|
|
|
|
// TODO: figure out how to handle this in layout.js for layered popups
|
|
function showOverlay() {
|
|
$('.dialog-overlay').show();
|
|
}
|
|
|
|
function hideOverlay() {
|
|
$('.dialog-overlay').hide();
|
|
}
|
|
|
|
function showDialog() {
|
|
|
|
$('#add-track2-input').empty();
|
|
$('#add-track2-instrument').empty();
|
|
|
|
initDialogData();
|
|
|
|
// load Unused Inputs
|
|
context.JK.loadOptions($('#template-option').html(), $('#add-track2-unused'), unusedAudioInputChannels, "device_id", "name", -1);
|
|
|
|
// load Track 2 Input(s)
|
|
context.JK.loadOptions($('#template-option').html(), $('#add-track2-input'), track2AudioInputChannels, "device_id", "name", -1);
|
|
|
|
// load Track 2 Instrument
|
|
context.JK.loadOptions($('#template-option').html(), $('#add-track2-instrument'), instrument_array, "id", "description", -1);
|
|
}
|
|
|
|
function initDialogData() {
|
|
|
|
// clear out arrays
|
|
unusedAudioInputChannels = [];
|
|
track2AudioInputChannels = [];
|
|
|
|
// get data needed for listboxes
|
|
var channels = context.jamClient.TrackGetChannels();
|
|
|
|
$.each(channels, function(index, val) {
|
|
var assignment = context.jamClient.TrackGetAssignment(val.id, val.input);
|
|
logger.debug("channel id=" + val.id + ", channel input=" + val.input + ", channel assignment=" + assignment +
|
|
", channel name=" + val.name + ", channel type=" + val.device_type + ", chat=" + val.chat);
|
|
|
|
// INPUT
|
|
if (context.jamClient.TrackIsMusicDeviceType(val.device_type)) {
|
|
if (val.input) {
|
|
if (assignment === ASSIGNMENT.UNASSIGNED) {
|
|
if (!val.chat) {
|
|
unusedAudioInputChannels.push(val);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function saveSettings() {
|
|
if (!validateSettings()) {
|
|
return;
|
|
}
|
|
|
|
saveTrack();
|
|
|
|
$('div[layout-id="add-track"]').hide();
|
|
|
|
hideOverlay();
|
|
|
|
// refresh Session screen
|
|
sessionModel.refreshCurrentSession();
|
|
}
|
|
|
|
function saveTrack() {
|
|
// TRACK 2 INPUTS
|
|
$("#add-track2-input > option").each(function() {
|
|
logger.debug("Saving track 2 input = " + this.value);
|
|
context.jamClient.TrackSetAssignment(this.value, true, ASSIGNMENT.TRACK2);
|
|
});
|
|
|
|
// TRACK 2 INSTRUMENT
|
|
var instrumentVal = $('#add-track2-instrument').val();
|
|
var instrumentText = $('#add-track2-instrument > option:selected').text().toLowerCase();
|
|
|
|
logger.debug("Saving track 2 instrument = " + instrumentVal);
|
|
context.jamClient.TrackSetInstrument(ASSIGNMENT.TRACK2, instrumentVal);
|
|
|
|
// UPDATE SERVER
|
|
logger.debug("Adding track with instrument " + instrumentText);
|
|
var data = {};
|
|
// use the first track's connection_id (not sure why we need this on the track data model)
|
|
logger.debug("myTracks[0].connection_id=" + myTracks[0].connection_id);
|
|
data.connection_id = myTracks[0].connection_id;
|
|
data.instrument_id = instrumentText;
|
|
data.sound = "stereo";
|
|
sessionModel.addTrack(sessionId, data);
|
|
|
|
context.jamClient.TrackSaveAssignments();
|
|
}
|
|
|
|
function validateSettings() {
|
|
var isValid = true;
|
|
var noTrackErrMsg = 'You must assign at least one input port to each of your tracks. Please update your settings to correct this. If you want to delete a track, please return to the session screen and delete the track by clicking the "x" box in the upper right-hand corner of the track.';
|
|
var noInstrumentErrMsg = 'You must specify what instrument is being played for each track. Please update your settings to correct this.';
|
|
|
|
var errMsg;
|
|
|
|
// verify Input and Instrument exist
|
|
if ($('#add-track2-input > option').size() === 0 || $('#add-track2-input > option').size() > 2) {
|
|
errMsg = noTrackErrMsg;
|
|
isValid = false;
|
|
}
|
|
|
|
if (isValid && $('#add-track2-instrument > option:selected').length === 0) {
|
|
errMsg = noInstrumentErrMsg;
|
|
isValid = false;
|
|
}
|
|
|
|
if (!isValid) {
|
|
context.JK.showErrorDialog(app, errMsg);
|
|
}
|
|
return isValid;
|
|
}
|
|
|
|
// TODO: repeated in configureTrack.js
|
|
function _init() {
|
|
// load instrument array for populating listboxes, using client_id in instrument_map as ID
|
|
context.JK.getInstruments(app, function(instruments) {
|
|
$.each(instruments, function(index, val) {
|
|
instrument_array.push({"id": instrument_map[val.description].client_id, "description": val.description});
|
|
});
|
|
});
|
|
}
|
|
|
|
this.initialize = function() {
|
|
events();
|
|
_init();
|
|
};
|
|
|
|
this.showDialog = showDialog;
|
|
|
|
return this;
|
|
};
|
|
|
|
})(window,jQuery); |