File: SendReply.schelp

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (105 lines) | stat: -rw-r--r-- 2,353 bytes parent folder | download | duplicates (4)
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
class:: SendReply
summary:: Send an array of values from the server to all notified clients
categories:: UGens>Triggers
related:: Classes/SendTrig, Classes/OSCFunc

description::
A message is sent to all notified clients. See link::Classes/Server::.

list::
## strong::cmdName::
	list::
	## int - node ID
	## int - reply ID
	## ... floats - values.
	::
::

classmethods::
method:: ar, kr

argument:: trig
a non-positive to positive transition triggers a message.
argument:: cmdName
a string or symbol, as a message name.
argument:: values
array of ugens, or valid ugen inputs.
argument:: replyID
integer id (similar to link::Classes/SendTrig::).

examples::
code::
(
{
	SendReply.kr(Impulse.kr(3), '/the_answer', [40, 41, 42, 43] + MouseX.kr, 1905);
}.play(s);
)

o = OSCFunc({ |msg| msg.postln }, '/the_answer');


// multichannel expansion
(
{
	SendReply.kr(Impulse.kr(3),
		'/the_answer',
		values: [[40, 80], [41, 56], 42, [43, 100, 200]],
		replyID: [1905, 1906, 1907, 1908]
	);
}.play(s);
)

o.free;

// Sending audio parameters over a network via OSC
// Since SendReply can only respond to the host, this shows how
// to send data to a separate target through sclang.
(
SynthDef(\amplitudeAnalysis, {|in=0, rate=60|
	var input = SoundIn.ar(in);
	var amp = Amplitude.kr(input);
	var freq = Pitch.kr(input);
	var trig = Impulse.kr(rate);
	SendReply.kr(trig, '/analysis', [amp, freq[0], freq[1]]);
}).add;
)

// example target address - insert your target host & port here
~testNetAddr = NetAddr("127.0.0.1", 5000);
~mySynth = Synth(\amplitudeAnalysis);

(
OSCdef(\listener, {|msg|
	var data = msg[3..];
	data.postln;
	~testNetAddr.sendMsg("data", data);
}, '/analysis');
)

~mySynth.set(\rate, 10); // slow it down...
::

subsection::Identitying the time a message was sent

Sometimes, we need to know when a message was sent. Because code::SendReply:: can send only messages (which have no timestamp) and no bundles (which have), we can't use the code::time:: argument of the link::Classes/OSCdef::'s function. Instead, you can send a time stamp with the data, by using the link::Classes/Sweep:: UGen.

code::
(
{ SendReply.ar(Impulse.ar(4), "/reply", [Sweep.ar, SinOsc.ar(0.3)]); 0 }.play;
OSCdef(\x, { |msg|
	var time, value;
	time = msg[3];
	value = msg[4];
	"value % occurred at time %".format(value, time).postln;
}, "/reply");
)
::