-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.scd
74 lines (60 loc) · 1.95 KB
/
example.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
This example is tuned very specifically to the serial device described in:
https://github.com/FunctionalJerk/SuperCollider-SerialCtl
(
// execute once:
//
// for me, serial-devices always appeared as "/dev/ttyACM0" or "/dev/ttyACM1".
// In either case, they always were at index 0 of SerialPort.devices.
// if this doesn't work for you, go:
// SerialPort.listDevices
// and copy and paste the string pointing to your device in SerialPort's port argument below
var port = SerialPort.devices[0];
~switches = Bus.control(s,4);
~pots = Bus.control(s,4);
p = SerialPort(
port: port,
baudrate: 115200, //check that baudrate is the same as in the sketch
exclusive: true,
xonxoff: true,
);
p.doneAction = { ("serial port \"" ++ port ++ "\" disconnected").postln; };
)
(
r = Routine.run({
// Define the least significant & most significant byte
var lsb = 0;
var msb = 0;
var index = 0;
var item = 0;
loop {
msb = p.read; lsb = p.read;
if((msb == 255) && (lsb == 255)) { index = 0 } {
// In order to understand, see:
// https://github.com/FunctionalJerk/SuperCollider-SerialCtl/blob/main/src/main.cpp#L62
if(index == 0) {
item = lsb.asBinaryDigits.reverse[..3]; // only the last four bits are used here
~switches.setnSynchronous(item);
} {
item = (msb << 8) | lsb;
~pots.setAt(index - 1, item);
};
index = index + 1 % 5;
};
}
});
//// Uncomment to monitor the control-busses:
// fork { loop { ~pots.getnSynchronous.postln; 0.5.wait } };
//// If you want to stop the Routine with CmdPeriod, uncomment:
// CmdPeriod.doOnce{ r.stop; };
)
(
// This is just a very basic example on how to use the serial input:
// It uses the first two of the four pots to control the frequency,
// and the other two to control the width of a VarSaw Ugen.
// They can be silenced by the first two switches.
SynthDef(\test, {|out|
Out.ar(out,
VarSaw.ar(~pots.kr(2).linexp(1,16383,100,800),0,~pots.kr(2,2) / 16383,0.3 * ~switches.kr(2))
)
}).play(s)
)