jam-cloud/web/app/assets/javascripts/dialog/configureTrackDialog.js

308 lines
11 KiB
JavaScript
Raw Permalink Normal View History

2014-06-03 22:45:48 +00:00
(function (context, $) {
"use strict";
context.JK = context.JK || {};
context.JK.ConfigureTracksDialog = function (app) {
var logger = context.JK.logger;
var ASSIGNMENT = context.JK.ASSIGNMENT;
var VOICE_CHAT = context.JK.VOICE_CHAT;
var gearUtils = context.JK.GearUtils;
var sessionUtils = context.JK.SessionUtils;
var $dialog = null;
var $instructions = null;
var $musicAudioTab = null;
var $musicAudioTabSelector = null;
var $voiceChatTab = null;
var $voiceChatTabSelector = null;
var $certifiedAudioProfile = null;
var $btnCancel = null;
var $btnAddNewGear = null;
var $btnUpdateTrackSettings = null;
var $btnCloseJamBlasterConfig = null;
var configureTracksHelper = null;
var voiceChatHelper = null;
var profiles = null;
var currentProfile = null;
var enableVstTimeout = null;
2014-06-03 22:45:48 +00:00
var configure_audio_instructions = {
"Win32": "Choose the audio device you would like to use for this session. If needed, use arrow buttons to assign audio inputs " +
"to your tracks, to indicate what instrument you are playing on each track, and to assign audio outputs for listening. " +
"If you want to use a new audio device you have not tested/certified for latency using JamKazam, click the Add New Audio " +
"Gear button to test that device.",
"MacOSX": "Choose the audio device you would like to use for this session. If needed, use arrow buttons to assign audio inputs " +
"to your tracks, to indicate what instrument you are playing on each track, and to assign audio outputs for listening. " +
"If you want to use a new audio device you have not tested/certified for latency using JamKazam, click the Add New Audio " +
"Gear button to test that device.",
"Unix": "Choose the audio device you would like to use for this session. If needed, use arrow buttons to assign audio inputs " +
"to your tracks, to indicate what instrument you are playing on each track, and to assign audio outputs for listening. " +
"If you want to use a new audio device you have not tested/certified for latency using JamKazam, click the Add New Audio " +
"Gear button to test that device."
};
var configure_voice_instructions = "If you are using a microphone to capture your instrumental or vocal audio, you can simply use that mic " +
"for both music and chat. Otherwise, choose a device to use for voice chat, and use arrow buttons to " +
"select an input on that device.";
function setInstructions(type) {
if (type === 'audio') {
2015-11-09 21:33:04 +00:00
$instructions.html("Click the 'ADD LIVE TRACK' button to add more tracks. You may set up a live track for each instrumental and/or vocal part to perform in sessions. You must also set up exactly two Session Audio Output ports to deliver the stereo audio in your sessions.")
return;
2014-06-03 22:45:48 +00:00
var os = context.jamClient.GetOSAsString();
$instructions.html(configure_audio_instructions[os]);
}
else if (type === 'voice') {
$instructions.html(configure_voice_instructions);
}
else {
throw "unknown type in setInstructions(" + type + ')';
}
}
function activateTab(type) {
if (type === 'voice') {
$musicAudioTab.hide();
$voiceChatTab.show();
$musicAudioTabSelector.removeClass('selected');
$voiceChatTabSelector.addClass('selected');
}
else {
$musicAudioTab.show();
$voiceChatTab.hide();
$musicAudioTabSelector.addClass('selected');
$voiceChatTabSelector.removeClass('selected');
}
}
function validateVoiceChatSettings() {
2014-06-13 17:51:03 +00:00
//return voiceChatHelper.trySave(); // not necessary since we use saveImmediate now
return true;
2014-06-03 22:45:48 +00:00
}
function showMusicAudioPanel() {
setInstructions('audio');
activateTab('audio');
}
function validateAudioSettings() {
2015-11-09 21:33:04 +00:00
return true;
2014-06-03 22:45:48 +00:00
}
function showVoiceChatPanel() {
setInstructions('voice');
activateTab('voice');
2014-06-03 22:45:48 +00:00
}
function events() {
$musicAudioTabSelector.click(function () {
// validate voice chat settings
if (validateVoiceChatSettings()) {
2015-12-04 21:29:59 +00:00
window.ConfigureTracksActions.reset(false);
voiceChatHelper.reset();
showMusicAudioPanel();
2014-06-03 22:45:48 +00:00
}
});
$voiceChatTabSelector.click(function () {
// validate audio settings
if (validateAudioSettings()) {
logger.debug("initializing voice chat helper")
2015-12-04 21:29:59 +00:00
window.ConfigureTracksActions.reset(false);
voiceChatHelper.reset();
showVoiceChatPanel();
2014-06-03 22:45:48 +00:00
}
else {
logger.debug("invalid audio settings; ignoring")
}
2014-06-03 22:45:48 +00:00
});
$btnCancel.click(function() {
2014-09-22 19:20:58 +00:00
app.layout.cancelDialog('configure-tracks');
return false;
});
$btnAddNewGear.click(function() {
app.layout.showDialog("add-new-audio-gear")
return false;
});
$btnUpdateTrackSettings.click(function() {
2015-11-09 21:33:04 +00:00
if(voiceChatHelper.trySave()) {
app.layout.closeDialog('configure-tracks');
}
return false;
});
$certifiedAudioProfile.change(deviceChanged);
2014-06-03 22:45:48 +00:00
}
function renderCertifiedGearDropdown() {
var optionsHtml = '';
context._.each(profiles, function (profile) {
if(profile.good) {
optionsHtml += '<option title="' + profile.id + '" value="' + profile.id + '"' + (profile.current ? 'selected="selected"' : '') + '>' + profile.id + '</option>';
}
});
$certifiedAudioProfile.html(optionsHtml);
2015-11-09 21:33:04 +00:00
//context.JK.dropdown($certifiedAudioProfile);
}
function deviceChanged() {
var profile = $certifiedAudioProfile.val();
if(currentProfile == profile) {
return; // just bail early, because the easydropdown fires change events even when you select the same value
}
logger.debug("activating audio profile: " + profile);
var result = context.jamClient.FTUELoadAudioConfiguration(profile);
if(!result) {
logger.error("unable to activate audio configuration: " + profile + ", " + JSON.stringify(result));
context.JK.alertSupportedNeeded("Unable to activate audio configuration for profile named: " + profile);
renderCertifiedGearDropdown(); // force the dropdown to be reflective of the actually active profile
return;
}
// FTUELoadAudioConfiguration eventually sets this, but apparently asynchronously
result = context.jamClient.SetLastUsedProfileName(profile);
if(!result) {
logger.error("unable to activate audio configuration after loading it: " + profile);
context.JK.alertSupportedNeeded("Unable to activate audio configuration for profile named: " + profile);
return;
}
currentProfile = profile;
2015-12-04 21:29:59 +00:00
window.ConfigureTracksActions.reset(false);
}
function beforeShow() {
profiles = gearUtils.getProfiles();
renderCertifiedGearDropdown();
showMusicAudioPanel();
currentProfile = context.jamClient.LastUsedProfileName();
if(currentProfile != $certifiedAudioProfile.val()) {
logger.error("the currently active profile (" + currentProfile + ") is not the same as the Certified Audio Gear dropdown (" + $certifiedAudioProfile.val() + ")");
context.JK.alertSupportedNeeded("Unable to determine the current profile.");
}
var result = context.jamClient.FTUELoadAudioConfiguration(currentProfile);
if(!result) {
logger.error("unable to activate audio configuration: " + currentProfile + ", " + JSON.stringify(result));
context.JK.alertSupportedNeeded("Unable to activate audio configuration for profile named: " + currentProfile);
return;
}
2015-12-04 21:29:59 +00:00
window.ConfigureTracksActions.reset(false);
if(!window.SessionStore.inSession()) {
delayEnableVst()
}
else {
logger.debug("in a session, so no delayEnableVst()");
}
voiceChatHelper.reset();
voiceChatHelper.beforeShow();
}
function delayEnableVst() {
if (enableVstTimeout) {
clearTimeout(enableVstTimeout)
}
var isVstLoaded = context.jamClient.IsVstLoaded()
var hasVstAssignment = context.jamClient.hasVstAssignment()
if (hasVstAssignment && !isVstLoaded) {
enableVstTimeout = setTimeout(function() { enableVst() }, 1000)
}
}
function enableVst () {
enableVstTimeout = null
if (app.layout.isDialogShowing('configure-tracks')) {
ConfigureTracksActions.enableVst()
}
else {
logger.debug("no longer in configure tracks dialog; not enabling VSTs at this time")
}
}
function afterShow() {
if (!window.JamBlasterStore.pairedJamBlaster) {
sessionUtils.SessionPageEnter();
}
2015-10-30 14:59:50 +00:00
if(currentProfile == 'JB Remote' || currentProfile == 'JamBlaster') {
window.JamBlasterActions.resyncBonjour()
}
2015-11-01 12:39:51 +00:00
//context.ConfigureTracksActions.vstScan();
2015-10-30 14:59:50 +00:00
}
2014-09-22 19:20:58 +00:00
function onCancel() {
return voiceChatHelper.cancel();
}
function afterHide() {
voiceChatHelper.beforeHide();
if(!window.JamBlasterStore.pairedJamBlaster) {
sessionUtils.SessionPageLeave();
}
}
2014-06-03 22:45:48 +00:00
function initialize() {
var dialogBindings = {
'beforeShow' : beforeShow,
'afterShow' : afterShow,
2014-09-22 19:20:58 +00:00
'afterHide': afterHide,
'onCancel' : onCancel
};
app.bindDialog('configure-tracks', dialogBindings);
2014-06-03 22:45:48 +00:00
$dialog = $('#configure-tracks-dialog');
$instructions = $dialog.find('.instructions span');
$musicAudioTab = $dialog.find('div[data-tab-id="music-audio"]');
2014-06-03 22:45:48 +00:00
$musicAudioTabSelector = $dialog.find('.tab-configure-audio');
$voiceChatTab = $dialog.find('div[data-tab-id="voice-chat"]');
2014-06-03 22:45:48 +00:00
$voiceChatTabSelector = $dialog.find('.tab-configure-voice');
$certifiedAudioProfile = $dialog.find('.certified-audio-profile');
$btnCancel = $dialog.find('.btn-cancel');
$btnAddNewGear = $dialog.find('.btn-add-new-audio-gear');
$btnUpdateTrackSettings = $dialog.find('.btn-update-settings');
2015-10-27 01:20:26 +00:00
//configureTracksHelper = new context.JK.ConfigureTracksHelper(app);
//configureTracksHelper.initialize($dialog);
2014-06-13 17:51:03 +00:00
voiceChatHelper = new context.JK.VoiceChatHelper(app);
voiceChatHelper.initialize($dialog, 'configure_track_dialog', true, {vuType: "vertical", lightCount: 10, lightWidth: 3, lightHeight: 17}, 191);
2014-06-03 22:45:48 +00:00
events();
}
this.initialize = initialize;
return this;
};
})(window, jQuery);