-
Notifications
You must be signed in to change notification settings - Fork 5
/
CuePlayer.sc
executable file
·176 lines (146 loc) · 4.61 KB
/
CuePlayer.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
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
CuePlayer : Cues {
classvar <globalClock;
var <>clock, <guiInstance;
var <timelineRegister, oscTriggerFunc;
var midiFuncRegister;
*new {
^super.new.init;
}
*initClass {
globalClock = TempoClock(120/60, queueSize: 2048 * 2).permanent_(true);
}
init {
super.init;
clock = TempoClock(120/60, queueSize: 2048 * 2).permanent_(true);
timelineRegister = IdentityDictionary.new;
midiFuncRegister = Array.new;
}
add { arg function, timeline, timelineOptions = ();
timeline = timeline.asTimeline(clock, timelineOptions);
this.addTimelineToRegister(cueList.size+1, timeline);
^super.add(function, {timeline.play;});
}
put { arg cueNumber, function, timeline, timelineOptions = ();
timeline = timeline.asTimeline(clock, timelineOptions);
this.addTimelineToRegister(cueNumber, timeline);
^super.put(cueNumber, function, {timeline.play;});
}
stop {
clock.clear;
}
gui {arg monitorInChannels = 2, monitorOutChannels = 8, options;
if (guiInstance.isNil or: {guiInstance.active.not},
{
guiInstance = CuePlayerGUI(this, monitorInChannels, monitorOutChannels, options);
this.addDependant(guiInstance);
}, {"The GUI for this CuePlayer is already active".warn;})
}
tempo_ { arg bpm = 120;
("CuePlayer tempo set to " ++ bpm ++ " bpm").postln;
clock.tempo = bpm/60;
this.changed(\tempo);
^bpm;
}
tempo {
^clock.tempo*60
}
plot { arg cueNumber = current; var timeline;
timeline = timelineRegister[cueNumber.asSymbol];
if(timeline.notNil) {timeline.plot};
}
disableLiveReload {
timelineRegister.do{arg i; i.options.liveReload = false};
this.liveReload = false;
"Live reload disabled".postln;
}
enableLiveReload {
timelineRegister.do{arg i; i.options.liveReload = true};
this.liveReload = true;
"Live reload enabled".postln;
}
/* External Control */
midiTrigger { arg note = 60, channel = 15; var msg;
"\n==============".postln;
msg = "\nThe method midiTrigger has been deprecated";
msg = msg ++ "\nand will be removed. Please use\nmidiTriggerNoteOn instead.";
msg.warn;
"==============\n".postln;
this.midiTriggerNoteOn(note, channel);
}
midiTriggerNoteOn { arg note = 60, channel = 15; var func;
func = { arg vel, noteNum, chan;
chan = chan + 1;
if (note == noteNum && chan == channel, {
/* [chan, noteNum, vel].debug("midiTriggerNoteOn"); */
{this.next}.defer;
});
};
this.addMIDIFunc(MIDIFunc.noteOn(func).fix);
}
midiTriggerVelocity { arg note = 60, channel = 16, offset = 0; var func;
func = { arg vel, noteNum, chan;
chan = chan + 1;
if (note == noteNum && chan == channel, {
/* [chan, noteNum, vel].debug("midiTriggerVelocity"); */
{this.trigger((vel)+offset)}.defer;
});
};
this.addMIDIFunc(MIDIFunc.noteOn(func).fix);
}
midiTriggerControl { arg value = 0, ccNum = 64, channel = 1 ; var func;
func = { arg val, controller, chan;
chan = chan + 1;
if (value == val && ccNum == controller && channel == chan, {
{this.next}.defer;
});
};
this.addMIDIFunc(MIDIFunc.cc(func).fix);
}
addMIDIFunc { arg midiFunc;
midiFuncRegister = midiFuncRegister.add(midiFunc);
}
clearMIDI {
midiFuncRegister.do{ arg midiFunc; midiFunc.free};
}
oscTrigger { arg path = '/cueTrigger';
oscTriggerFunc = OSCFunc(
{ arg msg;
if (msg[1] == -1,
{ {this.next}.defer },
{ {this.trigger(msg[1])}.defer }
);
}, path
);
oscTriggerFunc.permanent = true;
this.oscTriggerInform(path);
^oscTriggerFunc;
}
freeOscTrigger {
oscTriggerFunc.free;
"The OSC trigger has been removed".postln;
}
sendOSC { arg ip = "127.0.0.1", port = 8000, msg = ["/play", 1]; var address;
address = NetAddr(ip, port);
this.sched(clock.timeToNextBeat,{address.sendMsg(msg[0], msg[1])});
}
useGlobalClock {
clock = globalClock;
"This instance of CuePlayer is now using the global clock.".postln;
}
/* Private */
sched { arg time, function;
Routine {
time.wait;
Server.default.makeBundle(Server.default.latency, function);
}.play(clock);
}
oscTriggerInform { arg path, message;
("CuePlayer OSC trigger:").postln;
(" with path " ++ path).postln;
(" message: -1 for next cue or any number for specific cues").postln;
}
addTimelineToRegister { arg cueNumber, timeline; var registerNumber;
registerNumber = if(cueNumber.isNil && timeline.notNil, {cueList.size.asSymbol}, {cueNumber.asSymbol});
timelineRegister.put(registerNumber, timeline);
}
}