-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive.scd
161 lines (115 loc) · 3.63 KB
/
interactive.scd
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
// the host of processing machine
n = NetAddr("192.168.1.101", 12000);
(
~grain_bus = Bus.audio(s);
// load all the buffers
~buffers = "~/Desktop/mixture/sounds/grains/*".asAbsolutePath.pathMatch.collect {|file| Buffer.read(s, file);};
// id -> nodeId in scsynth,
~userNodeDict = ();
)
(
SynthDef(\Grainbuf, { |out=0, buf, dens=0.5, pan=0.5, dur=0.5, rate=0.5, pos=0.5, amp=0.5|
var trig = Dust.kr(dens.linlin(0, 1, 5, 15));
var sound = GrainBuf.ar(
numChannels: 2,
trigger: trig,
dur: dur.linlin(0, 1, 0.02, 0.08),
sndbuf: buf,
rate: rate.linlin(0, 1, 0.5, 1.5),
pos: pos,
interp: 2,
pan: pan.linlin(0, 1, -1, 1),
envbufnum: -1
) * 1 * (amp.linlin(0, 1, 0.5, 1)) * 0.25;
Out.ar(out, sound);
}).add;
//limit the grains volume
Ndef(\limit, {
var bus = ~grain_bus;
var sound = Limiter.ar(In.ar(bus, 2), 1.0);
sound;
}).play(0, 2, addAction: \addToTail);
(
// new device connect
OSCdef(\new_audio, { |args|
var userID = args[1];
var nodeID = s.nextNodeID;
"new audio".postln;
if(~userNodeDict.at(userID) != nil, {
s.sendMsg(\n_free, ~userNodeDict.at(userID));
});
~userNodeDict.add(userID -> nodeID);
~userNodeDict.postln;
s.sendMsg(\s_new, \Grainbuf, nodeID, 0, 0, \buf, ~buffers.choose.bufnum, \out, ~grain_bus);
}, '/interactive/new_audio', nil, 9001);
OSCdef(\new_visual, { |args|
var userID = args[1];
"new visual".postln;
if(~userNodeDict.at(userID) != nil, {
s.sendMsg(\n_free, ~userNodeDict.at(userID));
});
n.sendMsg("/new");
}, '/interactive/new_visual', nil, 9001);
// update the parameter
OSCdef(\update_audio, { |args|
var userID = args[1];
var xval = args[2].abs.linlin(0, 8, 0.0, 1.0);
var yval = args[3].abs.linlin(0, 8, 0.0, 1.0);
var zval = args[4].abs.linlin(0, 8, 0.0, 1.0);
var alpha = args[5].linlin(0, 360, 0.0, 1.0);
var beta = args[6].linlin(-180, 180, 0.0, 1.0);
var gamma = args[7].linlin(-90, 90, 0.0, 1.0);
var nodeID = ~userNodeDict.at(userID);
var log = "update "++ userID ++ "node " ++ nodeID ++ "args " ++ args;
log.postln;
s.sendMsg(\n_set, nodeID,
\dens, yval,
\pan, alpha,
\dur, gamma,
\rate, zval,
\pos, beta,
\amp, xval
);
n.sendMsg("/update", xval, yval, zval, alpha, beta, gamma);
}, '/interactive/update_audio', nil, 9001);
OSCdef(\update_visual, { |args|
var userID = args[1];
var xval = args[2].abs.linlin(0, 8, 0.5, 1.0);
var yval = args[3].abs.linlin(0, 8, 0.0, 1.0);
var zval = args[4].abs.linlin(0, 8, 0.0, 1.0);
var alpha = args[5].linlin(0, 360, 0.0, 1.0);
var beta = args[6].linlin(-180, 180, 0.0, 1.0);
var gamma = args[7].linlin(-90, 90, 0.0, 1.0);
args.postln;
n.sendMsg("/update", xval, yval, zval, alpha, beta, gamma);
}, '/interactive/update_visual', nil, 9001);
OSCdef(\change, { |args|
var userID = args[1];
var nodeID = ~userNodeDict.at(userID);
// var log = "change buffer: "++ userID ++ " node " ++ nodeID ++ "args " ++ args;
// log.postln;
s.sendMsg(\n_set, nodeID,
\buf, ~buffers.choose.bufnum
);
}, '/interactive/change', nil, 9001);
OSCdef(\subscribed, { |args|
"subed".postln;
}, '/sys/subscribed', nil, 9001);
// NOTICE: /sys/close is my patch to rhizome, currently not in the npm version
OSCdef(\close, { |args|
var userID = args[1];
var nodeID = ~userNodeDict.at(userID);
~userNodeDict.removeAt(nodeID);
s.sendMsg(\n_free, nodeID);
}, '/sys/close', nil, 9001);
)
(
var addr = NetAddr.new("127.0.0.1", 9000);
OSCdef.all.do {|item|
addr.sendMsg('/sys/subscribe', 9001, item.path.asString);
};
// pause the processing sktech, display help text for audience
n.sendMsg("/pause");
)
// resume the sktech
n.sendMsg("/resume");