117 lines
4.4 KiB
JavaScript
117 lines
4.4 KiB
JavaScript
/**
|
|
* FtueAudioSelectionScreen
|
|
* Javascript that goes with the screen where initial
|
|
* selection of the audio devices takes place.
|
|
* Corresponds to /#ftue2
|
|
*/
|
|
(function(context,$) {
|
|
|
|
"use strict";
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.FtueAudioSelectionScreen = function(app) {
|
|
var logger = context.JK.logger;
|
|
var jamClient = context.jamClient;
|
|
|
|
function beforeShow(data) {
|
|
loadDevices();
|
|
}
|
|
|
|
function afterShow(data) {
|
|
}
|
|
|
|
function loadDevices() {
|
|
$('#choose-input-audio-device select').empty();
|
|
$('#choose-output-audio-device select').empty();
|
|
$('#choose-input-voice-device select').empty();
|
|
var optionTemplate = $('#template_audio_device_item').html();
|
|
var devices = context.jamClient.GetASIODevices();
|
|
var inputOptions = [];
|
|
var outputOptions = [];
|
|
// We're going to build a list of individual choices...
|
|
// Each 'value' will be device id.interface id.pin id (dot separated).
|
|
// example: 1.1.1
|
|
// Label will be a string with device name, interface name, pin name.
|
|
var d, i, p;
|
|
var deviceName, deviceId;
|
|
var interfaceName, interfaceId;
|
|
var pinName, pinId, isInput;
|
|
var value, label, option;
|
|
for (d=0; d<devices.length; d++) {
|
|
deviceName = devices[d].device_name;
|
|
deviceId = devices[d].device_id;
|
|
for (i=0; i<devices[d].interfaces.length; i++) {
|
|
interfaceName = devices[d].interfaces[i].interface_name;
|
|
interfaceId = devices[d].interfaces[i].interface_id;
|
|
for (p=0; p<devices[d].interfaces[i].pins.length; p++) {
|
|
pinName = devices[d].interfaces[i].pins[p].pin_name;
|
|
pinId = devices[d].interfaces[i].pins[p].pin_id;
|
|
value = deviceId + "." + interfaceId + "." + pinId;
|
|
label = deviceName + ":" + interfaceName + ":" + pinName;
|
|
option = context.JK.fillTemplate(optionTemplate, { value: value, label: label});
|
|
isInput = devices[d].interfaces[i].pins[p].is_input;
|
|
if (isInput) {
|
|
inputOptions.push(option);
|
|
} else {
|
|
outputOptions.push(option);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$('#choose-input-audio-device select').html(inputOptions.join(''));
|
|
$('#choose-output-audio-device select').html(outputOptions.join(''));
|
|
$('#choose-input-voice-device select').html(inputOptions.join(''));
|
|
}
|
|
|
|
/**
|
|
* Use the currently selecting input and output device to call SetASIOEnabled
|
|
* on the bridge.
|
|
*/
|
|
function enableAudioDevices() {
|
|
var input = $('#choose-input-audio-device select').val().split('.');
|
|
var output = $('#choose-output-audio-device select').val().split('.');
|
|
context.jamClient.SetASIOEnabled(
|
|
parseInt(input[0], 10),
|
|
parseInt(input[1], 10),
|
|
parseInt(input[2], 10),
|
|
parseInt(output[0], 10),
|
|
parseInt(output[1], 10),
|
|
parseInt(output[2], 10));
|
|
}
|
|
|
|
function testLatency() {
|
|
$('#latency-testing p').html("Testing latency...");
|
|
context.jamClient.TestASIOLatency("JK.latencyTestingComplete");
|
|
}
|
|
|
|
function latencyTestingComplete() {
|
|
logger.debug("latencyTestingComplete. Arguments:");
|
|
logger.debug(arguments);
|
|
$('#latency-testing p').html("Done.");
|
|
}
|
|
|
|
|
|
function events() {
|
|
$('#enableDevices').click(function() {
|
|
enableAudioDevices();
|
|
testLatency();
|
|
});
|
|
|
|
}
|
|
|
|
function initialize() {
|
|
events();
|
|
var screenBindings = { 'beforeShow': beforeShow, 'afterShow': afterShow };
|
|
app.bindScreen('ftue2', screenBindings);
|
|
}
|
|
|
|
// Expose publics
|
|
this.initialize = initialize;
|
|
|
|
// Expose callbacks for the bridge on the global namespace
|
|
context.JK.latencyTestingComplete = latencyTestingComplete;
|
|
|
|
return this;
|
|
};
|
|
|
|
})(window,jQuery); |