-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConcertControl.sc
131 lines (109 loc) · 2.87 KB
/
ConcertControl.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
ConcertControl {
var <place, <date;
var parts, <oscPort;
var osc_out_addr;
var osc_in;
*new {
arg place, date, oscPort = NodeJS.outOscPort;
^super.new.init(place, date, oscPort);
}
init {
arg place_, date_, oscPort_;
place = place_;
date = date_;
oscPort = oscPort_;
parts = List.new;
osc_in = OSCFunc({
this.sendInfo;
}, "/concert/info/get", nil, oscPort_);
osc_out_addr = NetAddr("localhost", NodeJS.inOscPort);
this.sendInfo
}
sendInfo {
var date_fmt = date.format("%e %B %Y").asString;
var data = Dictionary.new;
data.put(\place, place);
data.put(\date, date_fmt);
osc_out_addr.sendMsg("/sc/concert/info", JSON.convert(data));
parts.do {
arg entry;
osc_out_addr.sendMsg("/sc/concert/add", JSON.convert(entry));
};
}
add {
arg composer, title, id, f_synth, oscFunc = nil;
var entry, osc_f;
var synth_n;
if(oscFunc.isNil, {
osc_f = OSCFunc({
arg msg;
msg.postln;
switch(msg[1],
\start, {
synth_n = f_synth.value;
synth_n.run(true)
},
\stop, {
synth_n.free;
},
\pause, {synth_n.run(false)},
{ format("[ConcertControl] unknown action: '%'").postln; }
);
}, "/concert/" ++ id, nil, oscPort);
}, {
osc_f = oscFunc;
} );
entry = Dictionary.new;
entry.put(\composer, composer);
entry.put(\title, title);
entry.put(\f_synth, f_synth);
entry.put(\synth, synth_n);
entry.put(\osc, osc_f);
entry.put(\id, id);
// remove old entries
parts = parts.reject({arg item; item[\id] == id;});
parts.add(entry);
}
play {
arg id;
var synth;
parts.do { |entry|
if(entry[\id] == id) {
entry[\synth] = entry[\f_synth].value;
};
}
}
pause {
arg id;
var synth;
parts.do { |entry|
if(entry[\id] == id) {
entry[\synth].run(false);
};
}
}
release {
arg id, tm = 1;
var synth;
parts.do { |entry|
if(entry[\id] == id) {
entry[\synth].set(\fadeTime, tm);
entry[\synth].release;
};
}
}
stop {
arg id;
var synth;
parts.do { |entry|
if(entry[\id] == id) {
entry[\synth].free;
};
}
}
list {
parts.do { |entry|
entry.postln;
}
}
}