Commit 84abebe4 authored by user's avatar user
Browse files

clean up dialog_prefs, remove unused functions

parent fd65ff25
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="dialog_iemgui.css">
<link id="page_style" rel="stylesheet" type="text/css" href="css/default.css">
</head>
<body>
<div class="container noselect">
......@@ -246,26 +246,28 @@
</div>
<script>
'use strict';
var nw = require('nw.gui');
var pdgui = require('./pdgui.js');
'use strict';
var nw = require('nw.gui');
var pdgui = require('./pdgui.js');
// For translations
var l = pdgui.get_local_string;
// For translations
var l = pdgui.get_local_string;
console.log("my working dire is " + pdgui.get_pwd());
// Gui presets
pdgui.skin.apply(this);
console.log("my working dire is " + pdgui.get_pwd());
var pd_object_callback;
var pd_object_callback;
var pd_audio_attrs;
var pd_midi_attrs;
var pd_audio_attrs;
var pd_midi_attrs;
function ok() {
function ok() {
apply();
cancel();
}
}
function display_pref(type) {
function display_pref(type) {
pdgui.gui_post("here i am with " + type);
var all, i, this_elem;
all = document.getElementsByTagName('fieldset');
......@@ -274,65 +276,14 @@
all[i].style.setProperty('display', 'none');
}
this_elem.style.setProperty('display', 'inline');
}
}
function gui_preset_change(elem) {
function gui_preset_change(elem) {
pdgui.skin.set(elem.value);
}
function flag_change(elem) {
var attr, arrays_select, name, value, flag;
arrays_select = document.getElementById('arrays_select');
attr = pd_garray_attrs[arrays_select.value];
name = elem.name;
// pdgui.gui_post("name is " + name);
// get value from radio group, checked from checkboxes
if (name === 'array_style') {
value = document.querySelector('input[name="array_style"]:checked').value;
pdgui.gui_post("array style found: " + value);
} else {
// '+' for casting boolean to number
value = +elem.checked;
}
// pdgui.gui_post("value is " + value);
flag = attr[attr.indexOf('array_flags') + 1];
pdgui.gui_post("flag before is " + flag);
switch (name) {
case "array_save":
flag &= ~1; // clear the save bit
flag |= value; // set it
break;
case "array_style":
flag &= ~(1 << 2); // clear style bit 2...
flag &= ~(1 << 1); // ... and 1 ...
flag += (2 * value); // set them
break;
case "array_jump":
flag &= ~(1 << 3);
flag += (16 * value);
break;
}
attr[attr.indexOf('array_flags') + 1] = flag;
pdgui.gui_post("array is " + attr);
}
function flag2_change(elem) {
var attr, arrays_select, name, value, flag;
arrays_select = document.getElementById('arrays_select');
attr = pd_garray_attrs[arrays_select.value];
name = elem.name;
// pdgui.gui_post("name is " + name);
// get value from radio group, checked from checkboxes
// '+' for casting boolean to number
value = +elem.checked;
// pdgui.gui_post("value is " + value);
attr[attr.indexOf(name) + 1] = value;
pdgui.gui_post("array is " + attr);
}
}
// callbacks for devices and/or their number of channels
function dev_change(elem) {
// callbacks for devices and/or their number of channels
function dev_change(elem) {
var attrs, id, direction, index;
// the same logic works for both channels and
// devices-- we use the variable 'type' to
......@@ -349,47 +300,47 @@
attrs[index] = elem.value;
pdgui.gui_post("id is " + elem.id);
pdgui.gui_post("new chan attrs is " + attrs);
}
}
function attr_change(elem) {
function attr_change(elem) {
var attr, id;
attr = pd_audio_attrs;
id = elem.id;
attr[attr.indexOf(id) + 1] = elem.value;
pdgui.gui_post("id is " + elem.id);
pdgui.gui_post("value is " + elem.value);
}
}
function get_input(name) {
function get_input(name) {
var val = document.getElementsByName(name)[0].value;
return val === 0 ? '0' : val;
}
}
// get a value from the garray attr array
function get_array_value(name, attrs) {
// get a value from the garray attr array
function get_array_value(name, attrs) {
return attrs[attrs.indexOf(name) + 1];
}
}
// If dev is -1, just change it to 0. Not sure if the Pd audio
// backend requires this, but it's how it works currently.
function kludge_dev(type, attrs, index) {
// If dev is -1, just change it to 0. Not sure if the Pd audio
// backend requires this, but it's how it works currently.
function kludge_dev(type, attrs, index) {
var dev = get_attr('pd-' + type + 'devs', attrs)[index];
if (dev < 0) { dev = 0; }
return dev;
}
}
// If the device is -1 ('None'), make the number of channels negative.
// This is the way Pd's audio back end turns off the device. (It works
// this way so you can remember your number of channels even if
// you turn off the device.)
function kludge_chans(type, attrs, index) {
// If the device is -1 ('None'), make the number of channels negative.
// This is the way Pd's audio back end turns off the device. (It works
// this way so you can remember your number of channels even if
// you turn off the device.)
function kludge_chans(type, attrs, index) {
var dev = get_attr('pd-' + type + 'devs', attrs)[index],
chans = get_attr('pd-' + type + 'chans', attrs)[index];
if (dev < 0 && chans >= 0) { chans *= -1; }
return chans;
}
}
function apply() {
function apply() {
var attrs = pd_audio_attrs;
pdgui.gui_post("we're applying shits!");
......@@ -433,16 +384,16 @@
0, // midi_alsain
0 // midi_alsaout
].join(' '));
}
}
function cancel() {
function cancel() {
var i, attrs, gfxstub;
pdgui.gui_post("closing the window at this point");
window.close(true);
// pdgui.pdsend(pd_object_callback + " cancel");
}
//pdgui.pdsend(pd_object_callback + " cancel");
}
function change_api(elem) {
function change_api(elem) {
var id = elem.getAttribute('id'),
value = elem.getAttribute('value');
if (id === 'audio_api') {
......@@ -450,13 +401,13 @@
} else {
pdgui.pdsend("pd midi-setapi " + value);
}
}
}
function get_attr(name, attrs) {
function get_attr(name, attrs) {
return attrs[attrs.indexOf(name) + 1];
}
}
function populate_apis(elem, apis, current_api) {
function populate_apis(elem, apis, current_api) {
pdgui.gui_post("curent api is " + current_api);
var i, opt, api_select = elem;
pdgui.gui_post('apis are ' + apis);
......@@ -467,7 +418,7 @@
api_select.appendChild(opt);
}
api_select.value = current_api;
}
}
function populate_devs(type, attrs) {
var devs = get_attr(type === 'in' ? 'sys-indevs' : 'sys-outdevs', attrs);
......@@ -525,7 +476,7 @@ function populate_midi_devs(type, attrs) {
}
}
function audio_prefs_callback(attrs) {
function audio_prefs_callback(attrs) {
pd_audio_attrs = attrs;
var api_select = document.getElementById('audio_api');
var callback, i, j, elem, devs, opt;
......@@ -564,16 +515,16 @@ function populate_midi_devs(type, attrs) {
// have the side-effect of setting the dev to 'None')
set_chans('in', get_attr('pd-inchans', attrs));
set_chans('out', get_attr('pd-outchans', attrs));
}
}
function set_devs(type, devs) {
function set_devs(type, devs) {
var i;
for (i = 0; i < devs.length; i++) {
document.getElementById(type + (i+1)).value = devs[i];
}
}
}
function set_chans(type, chans_array) {
function set_chans(type, chans_array) {
var i;
for (i = 0; i < chans_array.length; i++) {
document.getElementById(type + 'chans' + (i+1)).value = chans_array[i];
......@@ -582,9 +533,9 @@ function populate_midi_devs(type, attrs) {
document.getElementById(type + (i+1)).value = -1;
}
}
}
}
function midi_prefs_callback(attrs) {
function midi_prefs_callback(attrs) {
pd_midi_attrs = attrs;
var api_select = document.getElementById('midi_api');
pdgui.gui_post("midi attrs are " + attrs);
......@@ -599,13 +550,13 @@ function populate_midi_devs(type, attrs) {
}
}
}
// This gets called from the nw_create_window function in index.html
// It provides us with our window id from the C side. Once we have it
// we can create the menu and register event callbacks
function register_canvas_id(gfxstub, attr_arrays) {
// This gets called from the nw_create_window function in index.html
// It provides us with our window id from the C side. Once we have it
// we can create the menu and register event callbacks
function register_canvas_id(gfxstub, attr_arrays) {
pd_object_callback = gfxstub;
add_events(gfxstub);
translate_form();
......@@ -622,7 +573,7 @@ function populate_midi_devs(type, attrs) {
pdgui.pdsend("pd audio-properties"); // request audio pref attrs
pdgui.pdsend("pd midi-properties"); // request midi pref attrs
document.getElementsByClassName('container')[0].style.setProperty('display', 'inline');
}
}
function tr_text(id) {
var elem = document.getElementById('iem.prop.' + id);
......@@ -644,23 +595,8 @@ function translate_form() {
}
function populate_form(attr_array) {
// First, let's put the translated text for the form labels:
// tr_text('heading.size');
// tr_text('heading.messages');
// tr_text('heading.label');
// tr_text('heading.colors');
// tr_prop('width');
// tr_tooltip('width');
// var headings = ["size", "messages", "label", "colors"];
// for (var i = 0; i < headings.length; i++) {
// var str = "iem.prop.heading." + headings[i];
// var heading = document.getElementById(str);
// heading.textContent = l(str);
// }
for(var i = 0; i < attr_array.length; i+=2) {
// Unhide the span with the class with the same name as the id
var prop_group = document.getElementsByClassName(attr_array[i])[0];
......@@ -671,23 +607,9 @@ function populate_form(attr_array) {
pdgui.gui_post("Error: couldn't find iemgui prop group for " + attr_array[i]);
}
if (attr_array[i] === 'display-flags') {
// protip: '!!' forces Boolean, '+' forces Number type
var flag = +attr_array[i+1];
document.getElementsByName('gop')[0].checked = !!flag;
document.getElementsByName('hide-name')[0].checked = !!(flag & 2);
// Set the gop-related parts of the form to be enabled/disabled based on state
set_gop(!!flag);
}
var elem = document.getElementsByName(attr_array[i]);
if (elem.length > 0) {
if(attr_array[i].slice(-5) === 'color') {
var hex_string = Number(attr_array[i+1]).toString(16);
var color_string = "#" + (hex_string === '0' ? '000000' : hex_string);
pdgui.gui_post("color is " + color_string);
elem[0].value = color_string;
} else if (elem[0].type === 'checkbox') {
if (elem[0].type === 'checkbox') {
// The attr here is a string, so we need to
// force it to number, hence the "+" below
gui_post("found a CHECKED ITEM!!!");
......@@ -705,8 +627,6 @@ function add_events(name) {
// closing the Window
nw.Window.get().on("close", function() {
// this needs to do whatever the "cancel" button does
// pdgui.pdsend(name + " menuclose 0");
// cancel();
pdgui.remove_dialogwin(pd_object_callback);
this.close(true);
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment