-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNK2Button.sc
executable file
·115 lines (93 loc) · 1.43 KB
/
NK2Button.sc
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
NK2Button {
classvar
<type_none = 0,
<type_trigger = 1,
<type_switch = 2;
var
<note,
<led,
<>type = 1,
value = false,
<change_switch = true,
press_fn, release_fn, change_fn;
*new {
|
note,
writer = nil,
type
|
^super.new.initButton(note, writer, type);
}
initButton { | arg_note, arg_writer, arg_type |
note = arg_note;
led = NK2Led(arg_note, arg_writer, false);
type = arg_type ?? { type };
}
val {
^value
}
val_{ | val |
switch( type,
type_trigger, {
this.doChange;
},
type_switch, {
if( change_switch, {
this.doChange;
});
change_switch = change_switch.not;
},
type_none, {
value = value.not;
this.change(value);
if(value,
{ this.press },
{ this.release }
);
}
);
^value
}
setVal_{ |val|
value = val;
if( value, { led.on }, { led.off });
this.change(value);
if(value,
{ this.press },
{ this.release }
);
^value;
}
valNotTrig_{ |val|
value = val;
if( value, { led.on }, { led.off });
^value;
}
doChange {
value = value.not;
if( value, { led.on }, { led.off });
this.change(value);
if(value,
{ this.press },
{ this.release }
);
}
change {
^change_fn.value(this, value);
}
change_{ | fn |
^change_fn = fn;
}
press {
^press_fn.value(this, value);
}
press_{ | fn |
^press_fn = fn;
}
release {
^release_fn.value(this, value);
}
release_{ | fn |
^release_fn = fn;
}
}