-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOSCBus.sc
89 lines (74 loc) · 1.66 KB
/
OSCBus.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
OSCBus{
var <bus;
var <oscTag;
var <server;
var responder;
var <numChannels;
var <>scale=1;
*updateWarning{
"OSCBus: the order of arguments to create an OSCBus has changed to match the logic of OSCFunc. Please update your code!".warn;
}
*new{ |cmdName, nchan, addr, server|
OSCBus.updateWarning;
^super.new.init(cmdName, nchan, addr, server);
}
init{ |addr, cmdName, nchan, s|
server = s ? Server.default;
numChannels = nchan ? 1;
oscTag = cmdName;
responder = OSCFunc.new(
{ |msg|
bus.setn( msg.copyRange( 1, numChannels ) * scale );
},
cmdName, addr );
this.renew;
}
renew{
if ( bus.notNil, { this.free; });
bus = Bus.control( server, numChannels );
responder.add;
}
free{
bus.free;
responder.remove;
bus = nil;
}
printOn { arg stream;
stream << this.class.name << "(" <<*
[oscTag, numChannels, responder.srcID.asCompileString, server.asCompileString] <<")"
}
storeOn { arg stream;
stream << this.class.name << "(" <<*
[oscTag, numChannels, responder.srcID.asCompileString, server.asCompileString] <<")"
}
}
DataBus{
var <bus;
var <server;
var <func;
var <numChannels;
var updater;
var <dT = 0.05;
var <>scale=1;
*new{ |function, nchan, server|
^super.new.init(function, nchan, server);
}
init{ |function, nchan, s|
server = s ? Server.default;
numChannels = nchan ? 1;
func = function;
this.renew;
}
renew{
if ( bus.notNil, { this.free; });
bus = Bus.control( server, numChannels );
updater = SkipJack( { bus.setn( func.value * scale ) }, dT, autostart: true );
// updater.start;
}
dT_{ |dt| dT = dt; updater.dt = dT; }
free{
bus.free;
updater.stop;
bus = nil;
}
}