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

241 lines
8.3 KiB
JavaScript

(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 configureTracksHelper = null;
var voiceChatHelper = null;
var profiles = null;
var currentProfile = null;
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') {
$instructions.html('Choose your audio device. Drag and drop to assign input ports to tracks, and specify the instrument for each track. Drag and drop to assign a pair of output ports for session stereo audio monitoring.')
return;
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() {
//return voiceChatHelper.trySave(); // not necessary since we use saveImmediate now
return true;
}
function showMusicAudioPanel() {
setInstructions('audio');
activateTab('audio');
}
function validateAudioSettings() {
return configureTracksHelper.trySave();
}
function showVoiceChatPanel() {
setInstructions('voice');
activateTab('voice');
}
function events() {
$musicAudioTabSelector.click(function () {
// validate voice chat settings
if (validateVoiceChatSettings()) {
configureTracksHelper.reset();
voiceChatHelper.reset();
showMusicAudioPanel();
}
});
$voiceChatTabSelector.click(function () {
// validate audio settings
if (validateAudioSettings()) {
configureTracksHelper.reset();
voiceChatHelper.reset();
showVoiceChatPanel();
}
});
$btnCancel.click(function() {
if(voiceChatHelper.cancel()) {
app.layout.closeDialog('configure-tracks')
}
return false;
});
//$btnAddNewGear.click(function() {
// return false;
//});
$btnUpdateTrackSettings.click(function() {
if(configureTracksHelper.trySave() && voiceChatHelper.trySave()) {
app.layout.closeDialog('configure-tracks');
}
return false;
});
$certifiedAudioProfile.change(deviceChanged);
}
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);
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);
context.JK.alertSupportedNeeded("Unable to activate audio configuration for profile named: " + profile);
renderCertifiedGearDropdown(); // force the dropdown to be reflective of the actually active profile
}
else {
configureTracksHelper.reset();
}
}
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.");
}
configureTracksHelper.reset();
voiceChatHelper.reset();
voiceChatHelper.beforeShow();
}
function afterShow() {
sessionUtils.SessionPageEnter();
}
function afterHide() {
voiceChatHelper.beforeHide();
sessionUtils.SessionPageLeave();
}
function initialize() {
var dialogBindings = {
'beforeShow' : beforeShow,
'afterShow' : afterShow,
'afterHide': afterHide
};
app.bindDialog('configure-tracks', dialogBindings);
$dialog = $('#configure-tracks-dialog');
$instructions = $dialog.find('.instructions span');
$musicAudioTab = $dialog.find('div[tab-id="music-audio"]');
$musicAudioTabSelector = $dialog.find('.tab-configure-audio');
$voiceChatTab = $dialog.find('div[tab-id="voice-chat"]');
$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');
configureTracksHelper = new context.JK.ConfigureTracksHelper(app);
configureTracksHelper.initialize($dialog);
voiceChatHelper = new context.JK.VoiceChatHelper(app);
voiceChatHelper.initialize($dialog, 'configure_track_dialog', true, {vuType: "vertical", lightCount: 10, lightWidth: 3, lightHeight: 17}, 191);
events();
}
this.initialize = initialize;
return this;
};
})(window, jQuery);