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 ;
2014-06-09 03:26:50 +00:00
var gearUtils = context . JK . GearUtils ;
2014-08-29 02:11:25 +00:00
var sessionUtils = context . JK . SessionUtils ;
2014-06-09 03:26:50 +00:00
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 ;
2016-07-17 15:16:27 +00:00
var $btnCloseJamBlasterConfig = null ;
2014-06-09 03:26:50 +00:00
var configureTracksHelper = null ;
var voiceChatHelper = null ;
var profiles = null ;
var currentProfile = null ;
2015-12-21 22:42:18 +00:00
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." )
2014-06-09 03:26:50 +00:00
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 ( ) {
2014-06-04 19:47:05 +00:00
setInstructions ( 'voice' ) ;
activateTab ( 'voice' ) ;
2014-06-03 22:45:48 +00:00
}
function events ( ) {
$musicAudioTabSelector . click ( function ( ) {
// validate voice chat settings
2014-06-09 03:26:50 +00:00
if ( validateVoiceChatSettings ( ) ) {
2015-12-04 21:29:59 +00:00
window . ConfigureTracksActions . reset ( false ) ;
2014-06-09 03:26:50 +00:00
voiceChatHelper . reset ( ) ;
showMusicAudioPanel ( ) ;
2014-06-03 22:45:48 +00:00
}
} ) ;
$voiceChatTabSelector . click ( function ( ) {
// validate audio settings
2014-06-09 03:26:50 +00:00
if ( validateAudioSettings ( ) ) {
2015-07-15 15:04:45 +00:00
logger . debug ( "initializing voice chat helper" )
2015-12-04 21:29:59 +00:00
window . ConfigureTracksActions . reset ( false ) ;
2014-06-09 03:26:50 +00:00
voiceChatHelper . reset ( ) ;
showVoiceChatPanel ( ) ;
2014-06-03 22:45:48 +00:00
}
2015-07-15 15:04:45 +00:00
else {
logger . debug ( "invalid audio settings; ignoring" )
}
2014-06-03 22:45:48 +00:00
} ) ;
2014-06-09 03:26:50 +00:00
$btnCancel . click ( function ( ) {
2014-09-22 19:20:58 +00:00
app . layout . cancelDialog ( 'configure-tracks' ) ;
2014-06-09 03:26:50 +00:00
return false ;
} ) ;
2016-06-24 14:15:04 +00:00
$btnAddNewGear . click ( function ( ) {
2014-06-09 03:26:50 +00:00
2016-06-24 14:15:04 +00:00
app . layout . showDialog ( "add-new-audio-gear" )
return false ;
} ) ;
2014-06-09 03:26:50 +00:00
$btnUpdateTrackSettings . click ( function ( ) {
2015-11-09 21:33:04 +00:00
if ( voiceChatHelper . trySave ( ) ) {
2014-06-09 03:26:50 +00:00
app . layout . closeDialog ( 'configure-tracks' ) ;
}
return false ;
} ) ;
$certifiedAudioProfile . change ( deviceChanged ) ;
2014-06-03 22:45:48 +00:00
}
2014-06-09 03:26:50 +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);
2014-06-09 03:26:50 +00:00
}
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 ) {
2014-08-31 21:13:53 +00:00
logger . error ( "unable to activate audio configuration: " + profile + ", " + JSON . stringify ( result ) ) ;
2014-06-09 03:26:50 +00:00
context . JK . alertSupportedNeeded ( "Unable to activate audio configuration for profile named: " + profile ) ;
renderCertifiedGearDropdown ( ) ; // force the dropdown to be reflective of the actually active profile
2014-08-31 21:13:53 +00:00
return ;
2014-06-09 03:26:50 +00:00
}
2014-08-31 21:13:53 +00:00
// 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 ;
2014-06-09 03:26:50 +00:00
}
2014-08-31 21:13:53 +00:00
currentProfile = profile ;
2015-12-04 21:29:59 +00:00
window . ConfigureTracksActions . reset ( false ) ;
2014-06-09 03:26:50 +00:00
}
2015-05-05 01:56:05 +00:00
2014-06-04 19:47:05 +00:00
function beforeShow ( ) {
2014-08-29 02:11:25 +00:00
2014-06-09 03:26:50 +00:00
profiles = gearUtils . getProfiles ( ) ;
renderCertifiedGearDropdown ( ) ;
2014-06-04 19:47:05 +00:00
showMusicAudioPanel ( ) ;
2014-06-09 03:26:50 +00:00
2014-08-29 02:11:25 +00:00
currentProfile = context . jamClient . LastUsedProfileName ( ) ;
2014-06-09 03:26:50 +00:00
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." ) ;
}
2015-05-05 01:56:05 +00:00
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 ) ;
2015-12-21 22:42:18 +00:00
if ( ! window . SessionStore . inSession ( ) ) {
delayEnableVst ( )
}
else {
logger . debug ( "in a session, so no delayEnableVst()" ) ;
}
2014-06-09 03:26:50 +00:00
voiceChatHelper . reset ( ) ;
2014-06-12 18:36:51 +00:00
voiceChatHelper . beforeShow ( ) ;
2014-06-04 19:47:05 +00:00
}
2015-12-21 22:42:18 +00:00
function delayEnableVst ( ) {
if ( enableVstTimeout ) {
clearTimeout ( enableVstTimeout )
}
2015-12-23 18:35:57 +00:00
var isVstLoaded = context . jamClient . IsVstLoaded ( )
var hasVstAssignment = context . jamClient . hasVstAssignment ( )
if ( hasVstAssignment && ! isVstLoaded ) {
enableVstTimeout = setTimeout ( function ( ) { enableVst ( ) } , 1000 )
}
2015-12-21 22:42:18 +00:00
}
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" )
}
}
2014-08-29 02:11:25 +00:00
function afterShow ( ) {
2016-07-17 15:16:27 +00:00
if ( ! window . JamBlasterStore . pairedJamBlaster ) {
sessionUtils . SessionPageEnter ( ) ;
}
2015-10-30 14:59:50 +00:00
2017-10-19 12:30:09 +00:00
if ( currentProfile == 'JB Remote' || currentProfile == 'JamBlaster' ) {
window . JamBlasterActions . resyncBonjour ( )
}
2016-06-24 14:15:04 +00:00
2015-11-01 12:39:51 +00:00
//context.ConfigureTracksActions.vstScan();
2015-10-30 14:59:50 +00:00
2014-08-29 02:11:25 +00:00
}
2014-09-22 19:20:58 +00:00
function onCancel ( ) {
return voiceChatHelper . cancel ( ) ;
}
2014-06-04 19:47:05 +00:00
function afterHide ( ) {
2014-06-12 18:36:51 +00:00
voiceChatHelper . beforeHide ( ) ;
2016-07-17 15:16:27 +00:00
if ( ! window . JamBlasterStore . pairedJamBlaster ) {
sessionUtils . SessionPageLeave ( ) ;
}
2014-06-04 19:47:05 +00:00
}
2014-06-03 22:45:48 +00:00
function initialize ( ) {
2014-06-04 19:47:05 +00:00
var dialogBindings = {
'beforeShow' : beforeShow ,
2014-08-29 02:11:25 +00:00
'afterShow' : afterShow ,
2014-09-22 19:20:58 +00:00
'afterHide' : afterHide ,
'onCancel' : onCancel
2014-06-04 19:47:05 +00:00
} ;
app . bindDialog ( 'configure-tracks' , dialogBindings ) ;
2014-06-03 22:45:48 +00:00
$dialog = $ ( '#configure-tracks-dialog' ) ;
$instructions = $dialog . find ( '.instructions span' ) ;
2016-06-24 14:15:04 +00:00
$musicAudioTab = $dialog . find ( 'div[data-tab-id="music-audio"]' ) ;
2014-06-03 22:45:48 +00:00
$musicAudioTabSelector = $dialog . find ( '.tab-configure-audio' ) ;
2016-06-24 14:15:04 +00:00
$voiceChatTab = $dialog . find ( 'div[data-tab-id="voice-chat"]' ) ;
2014-06-03 22:45:48 +00:00
$voiceChatTabSelector = $dialog . find ( '.tab-configure-voice' ) ;
2014-06-09 03:26:50 +00:00
$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-09 03:26:50 +00:00
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-09 03:26:50 +00:00
2014-06-03 22:45:48 +00:00
events ( ) ;
}
this . initialize = initialize ;
return this ;
} ;
} ) ( window , jQuery ) ;