-
Notifications
You must be signed in to change notification settings - Fork 0
/
operator.js
91 lines (82 loc) · 2 KB
/
operator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// operator.js
// A single oscillator
//
// MUMT307 project - Alastair Porter
Operator = function(element, options) {
var defaults = {
active: true,
hidden: false,
id: 0,
freqRatio: 1,
};
var el;
var settings = $.extend({}, defaults, options);
// Show and hide the operator box on the screen
function _hide() {
settings.hidden = true;
el.hide();
}
function _show() {
settings.hidden = false;
el.show();
}
// Turn this operator on/off
function _setPower(value) {
if (value) {
settings.active = true;
el.css({"background": ""});
$('#o'+settings.id+'power').text("Turn off");
} else {
settings.active = false;
el.css({"background": "gray"});
$('#o'+settings.id+'power').text("Turn on");
}
}
function _updateRatio(value) {
settings.freqRatio = value;
}
function _setup() {
el = $('#operator'+settings.id);
_fillForm();
_show();
}
function _fillForm() {
$('#freqratio'+settings.id).val(settings.freqRatio);
_setPower(settings.active);
}
// Public methods
return {
setup: function() {
_setup();
},
swap: function() {
if (settings.hidden) {
_show();
} else {
_hide();
}
},
hide: function() {
_hide();
},
show: function() {
_show();
},
togglePower: function() {
_setPower(!settings.active);
},
updateRatio: function(value) {
_updateRatio(value);
},
load: function(newsettings) {
settings = newsettings;
_setup();
},
getSettings: function() {
return settings;
},
fillForm: function() {
_fillForm();
}
};
};