-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathControl Panel Example.scd
More file actions
138 lines (124 loc) · 7.27 KB
/
Control Panel Example.scd
File metadata and controls
138 lines (124 loc) · 7.27 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
133
134
135
136
137
138
// ControlPanel example: register each control type, listen for changes,
// and update values from sclang via a Routine.
( // TEST
var muteState = false;
// ─────────────────────────────────────────────────────────────────────
// 1. NUMERIC CONTROL (animated) — sweeps automatically via Routine
// ─────────────────────────────────────────────────────────────────────
ControlPanelNotification.registerNumericControl(
path: ["demo", "lfo"],
position: 0,
displayName: "LFO",
displayValue: "0.0",
normalizedValue: 0
);
// ─────────────────────────────────────────────────────────────────────
// 2. NUMERIC CONTROL (user-controlled) — drag to change
// ─────────────────────────────────────────────────────────────────────
ControlPanelNotification.registerNumericControl(
path: ["demo", "gain"],
position: 1,
displayName: "Gain",
displayValue: "0.5",
normalizedValue: 0.5
);
// ─────────────────────────────────────────────────────────────────────
// 3. ACTION CONTROL — a button (non-toggleable)
// ─────────────────────────────────────────────────────────────────────
ControlPanelNotification.registerActionControl(
path: ["demo", "randomize"],
position: 2,
displayName: "Randomize",
displayValue: "Click me",
normalizedValue: 0,
enabled: true,
toggleable: false
);
// ─────────────────────────────────────────────────────────────────────
// 4. ACTION CONTROL (toggleable) — an on/off toggle button
// ─────────────────────────────────────────────────────────────────────
ControlPanelNotification.registerActionControl(
path: ["demo", "mute"],
position: 3,
displayName: "Mute",
displayValue: "OFF",
normalizedValue: 0,
enabled: true,
toggleable: true
);
// ─────────────────────────────────────────────────────────────────────
// 5. TEXT CONTROL — displays rich markdown content
// ─────────────────────────────────────────────────────────────────────
ControlPanelNotification.registerTextControl(
path: ["demo", "info"],
position: 4,
displayName: "Status",
displayValue: "# System Status\n\nAll systems **operational**.\n\n---\n\n## Details\n\n- CPU: `12%`\n- Memory: `384 MB`\n- Synths: `0`\n\n> Ready for input.",
displayPropertyName: true
);
// ─────────────────────────────────────────────────────────────────────
// 6. POPUP CONTROL — dropdown selection
// ─────────────────────────────────────────────────────────────────────
ControlPanelNotification.registerPopupControl(
path: ["demo", "scale"],
position: 5,
displayName: "Scale",
items: ["Chromatic", "Major", "Minor", "Dorian", "Hexatonic"],
normalizedValue: 0
);
// ─────────────────────────────────────────────────────────────────────
// LISTEN FOR CHANGES — respond to user interaction and echo back
// ─────────────────────────────────────────────────────────────────────
~cpDependant = { |obj, what, value|
"──── ControlPanel changed: % = %".format(what, value).postln;
// IMPORTANT:
// Control panel controls are "dumb" - they send changes, but they rely on SuperCollider
// to be updated. So, without sending the updated values back, controls on the VSCode side
// will never change.
switch(what,
'demo_gain', {
// Echo the new gain value back to the panel
ControlPanelNotification.updateValue(
["demo", "gain"],
value.round(0.01).asString,
value
);
},
'demo_mute', {
// Toggle local state and confirm back to the panel
muteState = muteState.not;
ControlPanelNotification.updateValue(
["demo", "mute"],
if(muteState, "ON", "OFF"),
muteState.asInteger.asFloat
);
}
);
};
ControlPanelChangeProvider.addDependant(~cpDependant);
// ─────────────────────────────────────────────────────────────────────
// ANIMATE LFO — sweep the first slider automatically
// ─────────────────────────────────────────────────────────────────────
~cpRoutine = Routine({
var phase;
inf.do { |i|
phase = (i * 0.07 % 1.0).round(0.01);
ControlPanelNotification.updateValue(
["demo", "lfo"],
phase.asString,
phase
);
0.5.wait;
};
}).play(AppClock);
)
// ─────────────────────────────────────────────────────────────────────
// CLEANUP
// ─────────────────────────────────────────────────────────────────────
(
~cpRoutine.stop;
ControlPanelChangeProvider.removeDependant(~cpDependant);
["lfo", "gain", "randomize", "mute", "info", "scale"].do { |name|
ControlPanelNotification.unregisterControl(["demo", name]);
};
)