2012-12-01 23:50:28 +00:00
( function ( context , $ ) {
2012-12-07 00:31:46 +00:00
"use strict" ;
2012-12-01 23:50:28 +00:00
context . JK = context . JK || { } ;
context . JK . FakeJamClient = function ( app ) {
var logger = context . JK . logger ;
logger . info ( "*** Fake JamClient instance initialized. ***" ) ;
2013-01-05 21:30:24 +00:00
var ftue = false ;
2013-01-30 16:50:43 +00:00
var eventCallbackName = '' ;
var eventCallbackRate = 1000 ;
var vuValue = - 70 ;
var vuChange = 10 ;
var callbackTimer = null ;
2013-01-05 21:30:24 +00:00
function dbg ( msg ) { logger . debug ( 'FakeJamClient: ' + msg ) ; }
// Bummer that javascript doesn't have much in the way of reflection.
// arguments.callee.name would probably do what we want, but it's deprecated
// and not allowed when using "strict"
// (Wishing I could write a single function which debug logs the name of the
// current function and a JSON stringify of the arguments).
function GetFTUE ( ) { return ftue ; }
function SetFTUE ( b ) { ftue = b ; }
function GetOS ( ) { return 100000000 ; }
function LatencyUpdated ( map ) { dbg ( 'LatencyUpdated:' + JSON . stringify ( map ) ) ; }
function LeaveSession ( map ) { dbg ( 'LeaveSession:' + JSON . stringify ( map ) ) ; }
function P2PMessageReceived ( s1 , s2 ) { dbg ( 'P2PMessageReceived:' + s1 + ',' + s2 ) ; }
function JoinSession ( sessionId ) { dbg ( 'JoinSession:' + sessionId ) ; }
function ParticipantLeft ( session , participant ) {
dbg ( 'ParticipantLeft:' + JSON . stringify ( session ) + ',' +
JSON . stringify ( participant ) ) ;
}
function ParticipantJoined ( session , participant ) {
dbg ( 'ParticipantJoined:' + JSON . stringify ( session ) + ',' +
JSON . stringify ( participant ) ) ;
}
function RecordTestBegin ( ) { dbg ( 'RecordTestBegin' ) ; }
function RecordTestEnd ( ) { dbg ( 'RecordTestBegin' ) ; }
function RecordTestPlayback ( ) { dbg ( 'RecordTestBegin' ) ; }
function SendP2PMessage ( s1 , s2 ) { dbg ( 'SendP2PMessage:' + s1 + ',' + s2 ) ; }
function SetASIOEnabled ( i1 , i2 , i3 , i4 , i5 , i6 ) {
dbg ( 'SetASIOEnabled(' + i1 + ',' + i2 + ',' + i3 + ',' + i4 + ',' + i5 + ',' + i6 + ')' ) ;
}
function SignalLatencyUpdated ( client ) {
dbg ( 'SignalLatencyUpdated:' + JSON . stringify ( client ) ) ;
}
function SignalSendP2PMessage ( s1 , ba ) {
dbg ( 'SignalSendP2PMessage:' + JSON . stringify ( arguments ) ) ;
}
function StartPlayTest ( s ) { dbg ( 'StartPlayTest' + JSON . stringify ( arguments ) ) ; }
function StartRecordTest ( s ) { dbg ( 'StartRecordTest' + JSON . stringify ( arguments ) ) ; }
function StartRecording ( map ) { dbg ( 'StartRecording' + JSON . stringify ( arguments ) ) ; }
function StopPlayTest ( ) { dbg ( 'StopPlayTest' ) ; }
function StopRecording ( map ) { dbg ( 'StopRecording' + JSON . stringify ( arguments ) ) ; }
function TestASIOLatency ( s ) { dbg ( 'TestASIOLatency' + JSON . stringify ( arguments ) ) ; }
2013-01-06 20:34:48 +00:00
function TestLatency ( clientID , callbackFunctionName ) {
logger . debug ( "Fake JamClient: TestLatency called with client, " + clientID + " and callback function name: " + callbackFunctionName ) ;
2012-12-01 23:50:28 +00:00
var response = {
2012-12-13 04:53:15 +00:00
clientID : clientID ,
2012-12-01 23:50:28 +00:00
latency : 50
} ;
2012-12-08 20:14:00 +00:00
var js = callbackFunctionName + "(" + JSON . stringify ( response ) + ");" ;
2012-12-08 17:12:00 +00:00
eval ( js ) ;
2012-12-01 23:50:28 +00:00
}
2013-01-05 21:30:24 +00:00
function GetASIODevices ( ) {
var response = [ { "device_id" : 0 , "device_name" : "Realtek High Definition Audio" , "interfaces" : [ { "interface_id" : 0 , "interface_name" : "Realtek HDA SPDIF Out" , "pins" : [ { "is_input" : false , "pin_id" : 0 , "pin_name" : "PC Speaker" } ] } , { "interface_id" : 1 , "interface_name" : "Realtek HD Audio rear output" , "pins" : [ { "is_input" : false , "pin_id" : 0 , "pin_name" : "PC Speaker" } ] } , { "interface_id" : 2 , "interface_name" : "Realtek HD Audio Mic input" , "pins" : [ { "is_input" : true , "pin_id" : 0 , "pin_name" : "Recording Control" } ] } , { "interface_id" : 3 , "interface_name" : "Realtek HD Audio Line input" , "pins" : [ { "is_input" : true , "pin_id" : 0 , "pin_name" : "Recording Control" } ] } , { "interface_id" : 4 , "interface_name" : "Realtek HD Digital input" , "pins" : [ { "is_input" : true , "pin_id" : 0 , "pin_name" : "Capture" } ] } , { "interface_id" : 5 , "interface_name" : "Realtek HD Audio Stereo input" , "pins" : [ { "is_input" : true , "pin_id" : 0 , "pin_name" : "Recording Control" } ] } ] , "wavert_supported" : false } , { "device_id" : 1 , "device_name" : "M-Audio FW Audiophile" , "interfaces" : [ { "interface_id" : 0 , "interface_name" : "FW AP Multi" , "pins" : [ { "is_input" : false , "pin_id" : 0 , "pin_name" : "Output" } , { "is_input" : true , "pin_id" : 1 , "pin_name" : "Input" } ] } , { "interface_id" : 1 , "interface_name" : "FW AP 1/2" , "pins" : [ { "is_input" : false , "pin_id" : 0 , "pin_name" : "Output" } , { "is_input" : true , "pin_id" : 1 , "pin_name" : "Input" } ] } , { "interface_id" : 2 , "interface_name" : "FW AP SPDIF" , "pins" : [ { "is_input" : false , "pin_id" : 0 , "pin_name" : "Output" } , { "is_input" : true , "pin_id" : 1 , "pin_name" : "Input" } ] } , { "interface_id" : 3 , "interface_name" : "FW AP 3/4" , "pins" : [ { "is_input" : false , "pin_id" : 0 , "pin_name" : "Output" } ] } ] , "wavert_supported" : false } , { "device_id" : 2 , "device_name" : "Virtual Audio Cable" , "interfaces" : [ { "interface_id" : 0 , "interface_name" : "Virtual Cable 2" , "pins" : [ { "is_input" : true , "pin_id" : 0 , "pin_name" : "Capture" } , { "is_input" : false , "pin_id" : 1 , "pin_name" : "Output" } ] } , { "interface_id" : 1 , "interface_name" : "Virtual Cable 1" , "pins" : [ { "is_input" : true , "pin_id" : 0 , "pin_name" : "Capture" } , { "is_input" : false , "pin_id" : 1 , "pin_name" : "Output" } ] } ] , "wavert_supported" : false } , { "device_id" : 3 , "device_name" : "WebCamDV WDM Audio Capture" , "interfaces" : [ { "interface_id" : 0 , "interface_name" : "WebCamDV Audio" , "pins" : [ { "is_input" : true , "pin_id" : 0 , "pin_name" : "Recording Control" } , { "is_input" : false , "pin_id" : 1 , "pin_name" : "Volume Control" } ] } ] , "wavert_supported" : false } ] ;
2012-12-16 19:28:10 +00:00
2013-01-05 21:30:24 +00:00
return response ;
2012-12-16 19:28:10 +00:00
}
2013-01-30 16:50:43 +00:00
// Session Functions
function SessionAddTrack ( ) { }
function SessionGetControlState ( mixerIds ) {
var response = [ ] ;
for ( var i = 0 ; i < mixerIds . length ; i ++ ) {
2013-01-31 16:32:32 +00:00
response . push ( {
client _id : "" ,
2013-02-02 23:48:31 +00:00
group _id : 2 ,
2013-01-30 16:50:43 +00:00
id : mixerIds [ i ] ,
master : true ,
monitor : true ,
mute : false ,
name : "FW AP Multi" ,
range _high : 20 ,
range _low : - 80 ,
record : true ,
stereo : true ,
volume _left : 20 ,
volume _right : 20
} ) ;
}
return response ;
}
function SessionGetIDs ( ) {
return [ "FW AP Multi_0_10000" , "FW AP Multi_2_10200" ] ;
}
function SessionRegisterCallback ( callbackName ) {
eventCallbackName = callbackName ;
if ( callbackTimer ) { context . clearInterval ( callbackTimer ) ; }
if ( eventCallbackName ) {
callbackTimer = context . setInterval ( doCallbacks , eventCallbackRate ) ;
}
}
function SessionSetControlState ( stringValue ) { }
function SessionSetRecordingFilename ( filename ) { }
function SessionSetRecordingFolder ( folderName ) { }
function SessionStartPlay ( ) { }
function SessionStartRecording ( ) { }
function SessionStopPlay ( ) { }
function SessionStopRecording ( ) { }
function doCallbacks ( ) {
var names = [ "left_vu" , "right_vu" ] ;
var ids = [ "FW AP Multi_2_10200" , "FW AP Multi_0_10000" ] ;
2013-01-31 16:32:32 +00:00
var args = [ ] ;
for ( var i = 0 ; i < ids . length ; i ++ ) {
for ( var j = 0 ; j < names . length ; j ++ ) {
args . push ( '"' + names [ j ] + '"' ) ;
args . push ( '"' + ids [ i ] + '"' ) ;
args . push ( vuValue ) ;
}
2013-01-30 16:50:43 +00:00
}
2013-01-31 16:32:32 +00:00
var js = eventCallbackName + '(' + args . join ( ',' ) + ')' ;
eval ( js ) ;
2013-01-30 16:50:43 +00:00
vuValue += vuChange ;
if ( vuValue > 10 || vuValue < - 70 ) { vuChange = vuChange * - 1 ; }
}
function SetVURefreshRate ( rateMS ) {
eventCallbackRate = rateMS ;
if ( callbackTimer ) { context . clearInterval ( callbackTimer ) ; }
if ( eventCallbackName ) {
callbackTimer = context . setInterval ( doCallbacks , eventCallbackRate ) ;
}
}
2012-12-01 23:50:28 +00:00
// Javascript Bridge seems to camel-case
2013-01-05 21:30:24 +00:00
// Set the instance functions:
2012-12-16 19:28:10 +00:00
this . GetASIODevices = GetASIODevices ;
2013-01-05 21:30:24 +00:00
this . GetFTUE = GetFTUE ;
this . GetOS = GetOS ;
this . JoinSession = JoinSession ;
this . LatencyUpdated = LatencyUpdated ;
this . LeaveSession = LeaveSession ;
this . P2PMessageReceived = P2PMessageReceived ;
this . ParticipantJoined = ParticipantJoined ;
this . ParticipantLeft = ParticipantLeft ;
this . RecordTestBegin = RecordTestBegin ;
this . RecordTestEnd = RecordTestEnd ;
this . RecordTestPlayback = RecordTestPlayback ;
this . SendP2PMessage = SendP2PMessage ;
this . SetASIOEnabled = SetASIOEnabled ;
this . SetFTUE = SetFTUE ;
this . SignalLatencyUpdated = SignalLatencyUpdated ;
this . SignalSendP2PMessage = SignalSendP2PMessage ;
this . StartPlayTest = StartPlayTest ;
this . StartRecordTest = StartRecordTest ;
this . StartRecording = StartRecording ;
this . StopPlayTest = StopPlayTest ;
this . StopRecording = StopRecording ;
this . TestASIOLatency = TestASIOLatency ;
2013-01-06 20:34:48 +00:00
this . TestLatency = TestLatency ;
2013-01-05 21:30:24 +00:00
this . connected = true ;
2013-01-30 16:50:43 +00:00
// Session
this . SessionAddTrack = SessionAddTrack ;
this . SessionGetControlState = SessionGetControlState ;
this . SessionGetIDs = SessionGetIDs ;
this . SessionRegisterCallback = SessionRegisterCallback ;
this . SessionSetControlState = SessionSetControlState ;
this . SessionSetRecordingFilename = SessionSetRecordingFilename ;
this . SessionSetRecordingFolder = SessionSetRecordingFolder ;
this . SessionStartPlay = SessionStartPlay ;
this . SessionStartRecording = SessionStartRecording ;
this . SessionStopPlay = SessionStopPlay ;
this . SessionStopRecording = SessionStopRecording ;
this . SetVURefreshRate = SetVURefreshRate ;
2012-12-01 23:50:28 +00:00
} ;
} ) ( window , jQuery ) ;