-
Notifications
You must be signed in to change notification settings - Fork 7
/
Prototypes.js
4300 lines (3838 loc) · 122 KB
/
Prototypes.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 0613 amounra : http://www.aumhaa.com
const NOTE_TYPE = 'NOTE_TYPE';
const CC_TYPE = 'CC_TYPE';
const NONE_TYPE = 'NONE_TYPE';
const CHANNEL = 0;
const NONE = 'NONE';
var colors = {OFF : 0, WHITE : 1, CYAN : 5, MAGENTA : 9, RED : 17, BLUE : 33, YELLOW : 65, GREEN : 127};
NOTE_OBJECTS = new Array(128);
CC_OBJECTS = new Array(128);
//var noteInput = {'setNoteKeyMap':function(){}};
var noteInput = {'setKeyTranslationTable':function(){}};
var midiBuffer = {NONE_TYPE:{},CC_TYPE:{},NOTE_TYPE:{}};
var midiNoteBuffer = {};
var midiCCBuffer = {};
var recalculate_translation_map = true;
var Note_Translation_Table = [];
var Velocity_Translation_Table = [];
for (var i=0;i<128;i++) {Note_Translation_Table[i] = -1; Velocity_Translation_Table[i] = i;}
//this function initializes all the prototype core processes. It should be called during init().
function initialize_prototypes()
{
registerControlDicts();
tasks = new TaskServer(script, 100);
flash = new FlashTask();
tasks.addTask(flash.update, null, 1, true, 'Flash');
host.scheduleTask(flush, null, 100);
}
function FlashTask()
{
var self = this;
this.state = 0
this.buffer = [];
this.update = function()
{
self.state = Math.abs(self.state-1);
//post('flash state:', self.state);
if(self.state)
{
for(var i in self.buffer)
{
var button = self.buffer[i];
button.send(button._last_sent_value, true);
}
}
else
{
for(var i in self.buffer)
{
var button = self.buffer[i];
button.send(button._offValue, true);
}
}
}
this.remove = function(obj)
{
for(var i in self.buffer)
{
if(self.buffer[i]===obj)
{
self.buffer.splice(i, 1);
}
}
}
this.add = function(obj)
{
if(!(obj in self.buffer))
{
self.buffer.unshift(obj);
}
}
}
function extend(destination, source)
{
for (var k in source)
{
if (source.hasOwnProperty(k))
{
destination[k] = source[k];
}
}
return destination;
}
function override(object, methodName, callback)
{
object[methodName] = callback(object[methodName])
}
function after(extraBehavior)
{
return function(original)
{
return function()
{
var returnValue = original.apply(this, arguments)
extraBehavior.apply(this, arguments)
return returnValue
}
}
}
var toClass = {}.toString
//simple utility function to flatten incoming arguments to a function
function arrayfromargs(args)
{
return Array.prototype.slice.call(args, 0);
}
//use this for debug messages instead of println, it can be turned off with DEBUG flag.
function post()
{
if(DEBUG){println('> '+arrayfromargs(arguments).join(' '));}
}
//we need to use this when adding notifier targets or listeners so that the proper context is maintained.
//it isn't necessary for certain prototype targets, but won't hurt either. If something doesn't work, try this.
function wrap_callback(obj, func)
{
var callback = function(control)
{
func.apply(obj, [control]);
}
return callback;
}
//this is called at init to initialize all control definitions
function registerControlDicts()
{
NOTE_OBJECTS = new Array(128);
for (var i=0;i<128;i++){NOTE_OBJECTS[i] = new Control(i, 'None');}
CC_OBJECTS = new Array(128);
for (var i=0;i<128;i++){CC_OBJECTS[i] = new Control(i, 'None');}
}
//this is called whenever a control object is created, and basically maintains a list of all NOTE_TYPES and CC_TYPES that serve as lookup tables for MIDI input.
function register_control(control)
{
if (control._type == NOTE_TYPE)
{
NOTE_OBJECTS[control._id] = control;
}
else if(control._type == CC_TYPE)
{
CC_OBJECTS[control._id] = control;
}
}
function flush()
{
//tasks._run();
for(var type in midiBuffer)
{
var buf = midiBuffer[type];
for(var index in buf)
{
var Event = buf[index];
Event[0]._send(Event[1]);
}
}
midiBuffer = {NONE_TYPE:{},CC_TYPE:{},NOTE_TYPE:{}};
if(recalculate_translation_map)
{
//post('Note_Translation_Table:', Note_Translation_Table);
noteInput.setKeyTranslationTable(Note_Translation_Table);
noteInput.setVelocityTranslationTable(Velocity_Translation_Table);
recalculate_translation_map = false;
}
}
//this sends reset() to all controls that are defined with register_control()
function resetAll()
{
for (var index in CC_OBJECTS)
{
CC_OBJECTS[index].reset();
}
for (var index in NOTE_OBJECTS)
{
NOTE_OBJECTS[index].reset();
}
}
function displayMessage(message)
{
host.showPopupNotification(message);
}
var SETTING_TYPES = {'enum':{func:'getEnumSetting', observer:'addValueObserver', params:['_options', '_initialValue']},
'number':{func:'getNumberSetting', observer:'addRawValueObserver', params:['_minValue', '_maxValue', '_stepResolution', '_unit', '_initialValue']},
'signal':{func:'getSignalSetting', observer:'addSignalObserver', params:['_action']},
'string':{func:'getStringSetting', observer:'addValueObserver', params:['_numChars', '_initialText']}};
function Setting(name, type, args)
{
post('Setting:', name, type, args);
var self = this;
this._name = name;
this._category = undefined;
this._type = type;
this._parameter = undefined;
for (var i in args)
{
this['_'+i] = args[i];
}
this._Callback = function(val)
{
post('Value changed for', self._name, 'setting:', val);
//add check for _parameter, forward value if value is different than parameter._value is different.
}
if(this._type in SETTING_TYPES)
{
var defs = SETTING_TYPES[this._type];
var func_args = [], func = defs['func'], observer = defs['observer'], params = defs['params'];
func_args.push(this._name);
func_args.push(this._category);
for(var i=0;i<params.length;i++)
{
if(this.hasOwnProperty(params[i]))
{
func_args.push(this[params[i]]);
}
else
{
post('missing parameter for creation of setting :', params[i]);
func_args.push(undefined);
}
}
var theDocument = host.getDocumentState();
this._setting = theDocument[func].apply(theDocument, func_args);
post('type', this._type, 'observer', observer);
this._setting[observer](this._Callback);
}
}
function OSCDisplay(name)
{
var self = this;
this.controls = [];
this._enabled = false;
}
OSCDisplay.prototype.set_enabled = function(val)
{
for(var i in self.controls)
{
var control = self.controls[i];
control.add_listener(this.Callback);
}
}
/////////////////////////////////////////////////////////////////////////
//This is the root object to be used for all controls, or objects that
//will serve as notifiers to other objects. It maintains a list of listeners as well as a
//"target_stack" that can be used to push/pop targets to be notified when its value changes
//(only the first target in the stack is notified). Notifier is "subclassed" by many other prototypes.
function Notifier(name)
{
var self = this;
this._name = name;
this._value = -1;
this._listeners = [];
this._target_heap = [];
this._enabled = true;
this._display_value = false;
this._is_setting = false;
this.instance = function(){return self;}
}
Notifier.prototype.get_target = function(){return this._target_heap[0];}
Notifier.prototype.set_target = function(target)
{
if (target)
{
if (target in this._target_heap)
{
//post('target was present for' + this._name, 'placing at front');
this._target_heap.unshift(this._target_heap.splice(this._target_heap.indexOf(target), 1));
}
else
{
this._target_heap.unshift(target);
//post('target added to heap for ' + this._name);
}
}
else
{
this.remove_target();
}
}
Notifier.prototype.remove_target = function(target)
{
if (target)
{
for(var item in this._target_heap)
{
if(target === this._target_heap[item])
{
this._target_heap.splice(item, 1);
break;
}
}
}
else
{
this._target_heap.shift();
}
}
Notifier.prototype.clear_targets = function()
{
this._target_heap = [];
}
Notifier.prototype.add_listener = function(callback)
{
//if(!(callback in this._listeners))
//{
// this._listeners.unshift(callback);
//}
var add = true;
if (callback)
{
for(var item in this._listeners)
{
if(callback == this._listeners[item])
{
add = false;
break;
}
}
}
if(add)
{
this._listeners.unshift(callback);
}
}
Notifier.prototype.remove_listener = function(callback)
{
//if(callback in this._listeners){this._listeners.slice(this._listeners.indexOf(callback), 1);}
if (callback)
{
for(var item in this._listeners)
{
if(callback === this._listeners[item])
{
this._listeners.splice(callback, 1);
}
}
}
}
Notifier.prototype.notify = function(obj)
{
if(!obj)
{
var obj = this;
}
//post('notify', this._name, obj._name);
if(this._target_heap[0])
{
var cb = this._target_heap[0];
try
{
cb(obj);
}
catch(err)
{
post('target callback exception:', err);
post('-> for', this._name,' : ',cb);
}
}
for (var i in this._listeners)
{
var cb = this._listeners[i];
try
{
cb(obj);
}
catch(err)
{
post('listener callback exception:', err);
post('-> for', this._name,' : ',cb);
}
}
if(this._display_value>0)
{
displayMessage(this._name + ' : ' + this._value);
}
if(this._is_setting>0)
{
}
}
Notifier.prototype.set_enabled = function(val)
{
this._enabled = (val>0);
}
//////////////////////////////////////////////////////////////////////////
//A Notifier representing a physical control that can send and receive MIDI
function Control(identifier, name)
{
Notifier.call( this, name );
var self = this;
this._type = NONE_TYPE;
this._id = identifier;
this._channel = CHANNEL;
this._grid = {};
this._last_sent_value = 0;
this.receive = function(value)
{
if(self._enabled)
{
self._value = value;
self.notify();
}
}
this.receive_notifier = function(notification)
{
if(self._enabled){self.send(notification._value);}
}
this._x = function(grid){if(self._grid[grid._name]!=undefined){return(self._grid[grid._name].x)}}
this._y = function(grid){if(self._grid[grid._name]!=undefined){return(self._grid[grid._name].y)}}
}
Control.prototype = new Notifier();
Control.prototype.constructor = Control;
Control.prototype.identifier = function(){return this._id;}
Control.prototype._send = function(value){}//this should be overridden by subclass
Control.prototype.send = function(value)
{
midiBuffer[this._type][this._id] = [this, value];
this._last_sent_value = value;
}
Control.prototype.reset = function()
{
this.send(0);
}
function Button(identifier, name)
{
Control.call( this, identifier, name );
var this_button = this;
this._type = NOTE_TYPE;
this._onValue = 127;
this._offValue = 0;
this._translation = -1;
this._flash = false;
this._grid = [];
register_control(this);
}
Button.prototype = new Control();
Button.prototype.constructor = Button;
Button.prototype.pressed = function()
{
return this._value > 0;
}
Button.prototype.send = function(value, flash)
{
midiBuffer[this._type][this._id] = [this, value];
this.flash(flash);
this._last_sent_value = value;
}
Button.prototype._send = function(value)
{
sendNoteOn(this._channel, this._id, value);
}
Button.prototype.turn_on = function()
{
this.send(this._onValue);
}
Button.prototype.turn_off = function()
{
this.send(this._offValue);
}
Button.prototype.set_on_off_values = function(onValue, offValue)
{
this._onValue = onValue||127;
this._offValue = offValue||0;
}
Button.prototype.set_translation = function(newID)
{
//post(this._name, 'set translation', this._id, newID);
this._translation = newID;
Note_Translation_Table[this._id] = this._translation;
recalculate_translation_map = true;
}
Button.prototype.flash = function(val)
{
if(val!=this._flash)
{
this._flash = val;
if(!val)
{
flash.remove(this);
}
else
{
flash.add(this);
}
}
}
Button.prototype.get_coords= function(grid)
{
if(grid instanceof Grid && this._grid[grid._name])
{
return([this._grid[grid._name].x, this._grid[grid._name].y]);
}
}
function PadPressure(identifier, name)
{
Control.call( this, identifier, name);
this._type = CC_TYPE;
register_control(this);
}
PadPressure.prototype = new Control();
PadPressure.prototype.constructor = PadPressure;
PadPressure.prototype.pressed = function()
{
return this._value > 0;
}
function Slider(identifier, name)
{
Control.call( this, identifier, name );
this._type = CC_TYPE;
register_control(this);
}
Slider.prototype = new Control();
Slider.prototype.constructor = Slider;
Slider.prototype._send = function(value)
{
sendChannelController(this._channel, this._id, value);
}
function Encoder(identifier, name)
{
Control.call( this, identifier, name );
this._type = CC_TYPE;
register_control(this);
}
Encoder.prototype = new Control();
Encoder.prototype.constructor = Encoder;
Encoder.prototype._send = function(value)
{
sendChannelController(this._channel, this._id, value);
}
function TouchFader(identifier, name)
{
Slider.call( this, identifier, name );
this._color = 0;
}
TouchFader.prototype = new Slider();
TouchFader.prototype.constructor = TouchFader;
TouchFader.prototype.set_color = function(color){}//not implemented
TouchFader.prototype.set_mode = function(mode){}//not implemented
function DisplayElement(identifier, name)
{
Control.call( this, identifier, name );
this._type = CC_TYPE;
register_control(this);
}
DisplayElement.prototype = new Control();
DisplayElement.prototype.constructor = DisplayElement;
DisplayElement.prototype._send = function(value)
{
sendChannelController(this._channel, this._id, value);
}
function DisplaySection(name, width, base_id, map, def)
{
this._width = width;
var self = this;
this._value = '';
this._elements = [];
this._base_id = 0;
this._character_map = map||{};
this._default = this._character_map[def] || 0;
for(var i = 0;i < this._width; i++)
{
this._elements[i] = new DisplayElement(base_id + i, this._name + '_DisplayElement_' + i);
}
}
DisplaySection.prototype.set_character_map = function(map)
{
this._character_map = map;
}
DisplaySection.prototype._send = function(value)
{
value = value+'';
var dif = this._width - value.length;
if(dif>0)
{
dif--;
do{
value = ' '+value;
}while(dif--);
}
/*if(value.length<this._width)
{
value = ' ' + value;
}*/
if(value.length>this._width){value.length = this._width;}
this._value = value;
for(var i=0;i<this._width;i++)
{
var ch = this._character_map[this._value.charAt(i)] || this._default;
this._elements[i]._send(ch);
}
}
DisplaySection.prototype.set_default = function(def)
{
this._character_map[def] || 0;
}
/////////////////////////////////////////////////////////////////////////////
//A notifier that collects a grid of buttons
function Grid(width, height, name)
{
Notifier.call( this, name );
var self = this;
this.width = function(){return width;}
this.height = function(){return height;}
this.size = function(){return width * height;}
this._name = name;
var contents = [];
for(var i = 0; i < width; i++)
{
contents[i] = [];
for(var j = 0; j < height; j++)
{
contents[i][j] = undefined;
}
}
this._grid = contents;
this.receive = function(button){self.notify(button);}
}
Grid.prototype = new Notifier();
Grid.prototype.constructor = Grid;
Grid.prototype.controls = function()
{
var buttons = [];
for(var x in this._grid)
{
for(var y in this._grid[x])
{
//if(this._grid[x][y] instanceof Notifier)
//{
buttons.push(this._grid[x][y]);
//}
}
}
return buttons;
}
Grid.prototype.add_control = function(x, y, button)
{
if(x < this.width())
{
if(y < this.height())
{
if(button instanceof Notifier)
{
this._grid[x][y] = button;
button._grid[this._name] = {x:x, y:y, obj:this};
button.add_listener(this.receive);
}
}
}
}
Grid.prototype.send = function(x, y, value)
{
this._grid[x][y].send(value);
}
Grid.prototype.get_button = function(x, y)
{
var button = undefined;
if(this._grid[x])
{
if(this._grid[x][y])
{
button = this._grid[x][y];
}
}
return button;
}
Grid.prototype.reset = function()
{
var buttons = this.controls();
for (index in buttons)
{
if(buttons[index] instanceof Notifier)
{
buttons[index].reset();
}
}
}
Grid.prototype.clear_buttons = function()
{
var buttons = this.controls();
for (var i in buttons)
{
if(buttons[i] instanceof Notifier)
{
buttons[i].remove_listener(this.receive);
delete buttons[i]._grid[this._name];
}
}
var contents = [];
for(var i = 0; i < this.width(); i++)
{
contents[i] = [];
for(var j = 0; j < this.height(); j++)
{
contents[i][j] = undefined;
}
}
this._grid = contents;
}
Grid.prototype.sub_grid = function(subject, x_start, x_end, y_start, y_end)
{
for(var x=0;x<(x_end-x_start);x++)
{
for(var y=0;y<(y_end-y_start);y++)
{
var button = subject.get_button(x+x_start, y+y_start);
//post('adding button', button._name);
this.add_control(x, y, button);
}
}
return this;
}
Grid.prototype.clear_translations = function()
{
var buttons = this.controls();
for(var index in buttons)
{
if(buttons[index])
{
buttons[index].set_translation(-1);
}
}
}
/////////////////////////////////////////////////////////////////////////////
//Mode is a notifier that automatically updates buttons when its state changes
function Mode(number_of_modes, name)
{
Notifier.call( this, name);
var self = this;
this._value = 0;
this._mode_callbacks = new Array(number_of_modes);
this.mode_buttons = [];
this.mode_cycle_button = undefined;
this.mode_cycle_value = function(button)
{
if(button.pressed())
{
self.change_mode((self._value + 1) % self._mode_callbacks.length)
self.notify();
}
}
this.mode_value = function(button)
{
if(button.pressed())
{
self.change_mode(self.mode_buttons.indexOf(button));
self.notify();
}
}
this.toggle_value = function(button)
{
self.change_mode(button._value);
self.notify();
}
this.mode_toggle = new ToggledParameter(this._name + '_Mode_Toggle', {'onValue':colors.BLUE, 'offValue':colors.CYAN, 'value':0});
this.mode_toggle.add_listener(self.toggle_value);
}
Mode.prototype = new Notifier();
Mode.prototype.constructor = Mode;
Mode.prototype.change_mode = function(value, force)
{
if (value < (this._mode_callbacks.length))
{
if((this._value != value)||(force))
{
this._value = value;
this.update();
}
}
}
Mode.prototype.update = function()
{
var callback = this._mode_callbacks[this._value];
if(callback)
{
try
{
callback();
}
catch(err)
{
post('callback error:', err, 'for mode index', this._value,'for', this._name, 'mode component');
}
}
for(var i in this.mode_buttons)
{
if (i == this._value)
{
this.mode_buttons[i].turn_on();
}
else
{
this.mode_buttons[i].turn_off();
}
}
}
Mode.prototype.add_mode = function(mode, callback)
{
if (mode < this._mode_callbacks.length)
{
this._mode_callbacks[mode] = callback;
}
}
Mode.prototype.set_mode_buttons = function(buttons)
{
if (((buttons == undefined)||(buttons.length == this._mode_callbacks.length))&&(buttons != this.mode_buttons))
{
for (var i in this.mode_buttons)
{
this.mode_buttons[i].remove_target(this.mode_value);
}
if(!buttons)
{
buttons = [];
}
this.mode_buttons = [];
for (var i in buttons)
{
this.mode_buttons.push(buttons[i]);
buttons[i].set_target(this.mode_value);
}
//post('mode buttons length: ' + this._name + ' ' + this.mode_buttons.length)
}
}
Mode.prototype.set_mode_cycle_button = function(button)
{
if(this.mode_cycle_button)
{
this.mode_cycle_button.remove_target(this.mode_cycle_value);
}
this.mode_cycle_button = button;
if(button)
{
button.set_target(this.mode_cycle_value);
}
}
Mode.prototype.current_mode = function()
{
return(this._value)
}
/////////////////////////////////////////////////////////////////////////////
//Parameter is a notifier that automatically updates its listeners when its state changes
//It can either reflect an internal state or a JavaObject's value, and can be assigned a control
function Parameter(name, args)
{
Notifier.call( this, name );
var self = this;
this._name = name;
this._parameter = undefined;
this._num = 0;
this._value = 0;
this._onValue = 127;
this._offValue = 0;
this._text_length = 10;
this._unassigned = 'None';
for (var i in args)
{
this['_'+i] = args[i];
}
this.receive = function(value)
{
self._value = value;
self.update_control();
self.notify();
}
this.set_value = function(value)
{
self.receive(value);
}
this.update_control = function(){if(self._control){self._control.send(Math.floor(self._value));}}
this._Callback = function(obj){if(obj){self.receive(obj._value);}}
this.set_control = function(control)
{
if (control instanceof(Notifier) || !control)
{
if(self._control)
{
self._control.remove_target(self._Callback);
}
self._control = control;
if(self._control)
{
self._control.set_target(self._Callback);
//self.receive(self._value);
self.update_control();
}
}
}
if(this._javaObj)
{
if(this._action){this._Callback = function(obj){if(obj._value){self._javaObj[self._action]();}}}
if(this._monitor){this._javaObj[this._monitor](this.receive);}
if(this._monitor_text){this._javaObj[this._monitor_text](this._text_length, this._unassigned, this.receive);}
}