-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPlayerButtons.sc
More file actions
132 lines (111 loc) · 3.36 KB
/
GPlayerButtons.sc
File metadata and controls
132 lines (111 loc) · 3.36 KB
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
GPlayerButtons : CompositeView {
var <btn_play, <btn_stop, btn_pause;
var b_rect, player_state = 0;
var btn_play_action, btn_stop_action, btn_pause_action;
const stop = 0, play = 1, pause = 2;
var osc_client, osc_path, osc_port;
*new {
arg parent, bounds = Rect(0, 0, 400, 30), oscPath = "/gplayer", oscPort = 10000;
^super.new(parent, bounds).init(oscPath, oscPort);
}
init { |oscPath, oscPort|
osc_path = oscPath;
osc_port = oscPort;
postf("PlayerButton listening OSC messages \"%\" on port: % \n", osc_path, osc_port);
b_rect = super.bounds;
osc_client = OSCFunc(this.handleOsc, osc_path, nil, osc_port);
this.onClose = {
this.setStopped;
osc_client.free;
}
}
handleOsc { |msg|
{
switch(msg,
\stop, {this.setStopped},
\play, {this.setPlaying},
\pause, {this.setPaused}
);
}.defer;
}
enablePlay { |value|
if(btn_play.notNil) {
if(value,
{ btn_play.states_([["Play ▶", Color.black, Color.white]])},
{ btn_play.states_([["Play ▶", Color.black, Color.gray]])}
);
}
}
enableStop { |value|
if(btn_stop.notNil) {
if(value,
{ btn_stop.states_([["Stop", Color.black, Color.white]])},
{ btn_stop.states_([["Stop", Color.black, Color.gray]])}
);
}
}
enablePause { |value|
if(btn_pause.notNil) {
if(value,
{ btn_pause.states_([["Pause ❚❚", Color.black, Color.white]])},
{ btn_pause.states_([["Pause ❚❚", Color.black, Color.gray]]) }
);
}
}
setInitState {
this.enablePlay(true);
this.enableStop(false);
this.enablePause(false);
}
setPlaying {
this.enablePlay(false);
this.enableStop(true);
this.enablePause(true);
if(player_state != play) {
btn_play_action.value;
player_state = play;
}
}
setStopped {
this.enablePlay(true);
this.enableStop(false);
this.enablePause(false);
if(player_state != stop) {
btn_stop_action.value;
player_state = stop;
}
}
setPaused {
switch (player_state,
play, {
this.enablePlay(false);
this.enableStop(true);
this.enablePause(false);
btn_pause_action.value(true);
player_state = pause;
},
pause, {
this.enablePlay(false);
this.enableStop(true);
this.enablePause(true);
btn_pause_action.value(false);
player_state = play;
}
);
}
playButton {
arg action;
btn_play_action = action;
btn_play = Button.new(this, Rect(0, 0, 80, 20)).action_({this.setPlaying});
}
stopButton {
arg action;
btn_stop_action = action;
btn_stop = Button.new(this, Rect(100, 0, 80, 20)).action_({this.setStopped});
}
pauseButton {
arg action;
btn_pause_action = action;
btn_pause = Button.new(this, Rect(200, 0, 80, 20)).action_({this.setPaused});
}
}