Hey hello,
I am working on a wearable instrument using the bela mini together with the Trill Flex, Hex, Ring, Square, Bar and Craft. I am using SuperCollider with the TrillCentroids UGen to get data from the Trill sensors. Everything is working rather smoothly until I start touching the Trill Flex. It will sometimes work for a while untli l get this error:
Trill: error while reading from device Flex at address 0x48 (72): -1 of 20 bytes read (error: 121 Remote I/O error)
Trill: error while reading from device Square at address 0x28 (40): -1 of 32 bytes read (error: 121 Remote I/O error)
Trill: error while reading from device Bar at address 0x20 (32): -1 of 20 bytes read (error: 121 Remote I/O error)
Trill: error while reading from device Craft at address 0x30 (48): -1 of 60 bytes read (error: 121 Remote I/O error)
Trill: error while reading from device Hex at address 0x40 (64): -1 of 32 bytes read (error: 110 Connection timed out)
Trill: error while reading from device Ring at address 0x38 (56): -1 of 24 bytes read (error: 110 Connection timed out)
In this manner I am getting data from the Trill Flex (and it happens when nothing is done inside the OSCdef yet):
SynthDef(\trillflex, {|t_recalibrate=0.0|
var i2c_bus = 1;
var i2c_address = 0x48;
var noiseThreshold = 0.045; // float: 0-0.0625, with 0.0625 being the highest noise thresh
var prescalerOpt = 4; // int: 1-8 with 1 being the highest sensitivity
var touchsigs = DC.ar(0).dup(3); // use 3 touches
var centroids;
var rawvals;
var out, ping;
centroids = TrillCentroids.kr(i2c_bus, i2c_address, noiseThreshold, prescalerOpt, t_recalibrate);
SendReply.kr(Impulse.kr(10), "/flex", centroids);
}).store;`
`
~trill_flx = Synth(\trillflex);`
`
OSCdef(\trillflex, {|msg|
msg.postln;
}, '/flex');`
These are the other Trill synthdefs I am using:
`SynthDef(\trillcraft, {|t_recalibrate=0.0|
var i2c_bus = 1;
var i2c_address = 0x30;
var noiseThreshold = 0.045; // float: 0-0.0625, with 0.0625 being the highest noise thresh
var prescalerOpt = 3; // int: 1-8 with 1 being the highest sensitivity
var touchsigs = DC.ar(0).dup(3); // use 3 touches
var centroids;
var out, ping;
centroids = TrillRaw.kr(i2c_bus, i2c_address, noiseThreshold, prescalerOpt, t_recalibrate);
SendReply.kr(Impulse.kr(10), "/craft", centroids);
}).store;`
`SynthDef(\trillbar, {|t_recalibrate=0.0|
var i2c_bus = 1;
var i2c_address = 0x20;
var noiseThreshold = 0.045; // float: 0-0.0625, with 0.0625 being the highest noise thresh
var prescalerOpt = 3; // int: 1-8 with 1 being the highest sensitivity
var touchsigs = DC.ar(0).dup(3); // use 3 touches
var centroids;
var out, ping;
centroids = TrillCentroids.kr(i2c_bus, i2c_address, noiseThreshold, prescalerOpt, t_recalibrate);
SendReply.kr(Impulse.kr(10), "/bar", centroids);
}).store;`
`SynthDef(\trillsquare, {|t_recalibrate=0.0|
var i2c_bus = 1;
var i2c_address = 0x28;
var noiseThreshold = 0.045; // float: 0-0.0625, with 0.0625 being the highest noise thresh
var prescalerOpt = 1; // int: 1-8 with 1 being the highest sensitivity
var touchsigs = DC.ar(0).dup(3); // use 3 touches
var centroids;
var out, ping;
centroids = TrillCentroids.kr(i2c_bus, i2c_address, noiseThreshold, prescalerOpt, t_recalibrate);
SendReply.kr(Impulse.kr(10), "/square", centroids);
}).store;`
`SynthDef(\trillring, {|t_recalibrate=0.0|
var i2c_bus = 1;
var i2c_address = 0x38;
var noiseThreshold = 0.045; // float: 0-0.0625, with 0.0625 being the highest noise thresh
var prescalerOpt = 1; // int: 1-8 with 1 being the highest sensitivity
var touchsigs = DC.ar(0).dup(3); // use 3 touches
var centroids;
var out, ping;
centroids = TrillCentroids.kr(i2c_bus, i2c_address, noiseThreshold, prescalerOpt, t_recalibrate);
SendReply.kr(Impulse.kr(10), "/ring", centroids);
}).store;`
`SynthDef(\trillhex, {|t_recalibrate=0.0|
var i2c_bus = 1;
var i2c_address = 0x40;
var noiseThreshold = 0.045; // float: 0-0.0625, with 0.0625 being the highest noise thresh
var prescalerOpt = 1; // int: 1-8 with 1 being the highest sensitivity
var touchsigs = DC.ar(0).dup(3); // use 3 touches
var centroids;
var out, ping;
centroids = TrillCentroids.kr(i2c_bus, i2c_address, noiseThreshold, prescalerOpt, t_recalibrate);
SendReply.kr(Impulse.kr(10), "/hex", centroids);
}).store;`
And I use them like this (within a livecoding setup):
`~trill_craft = Synth(\trillcraft);
~trill_bar = Synth(\trillbar);
~trill_square = Synth(\trillsquare);
~trill_ring = Synth(\trillring);
~trill_hex = Synth(\trillhex);
~trill_flx = Synth(\trillflex);`
`~craft_buffer_left = Buffer.alloc(s, 22050, 1);
~craft_fftbuf_left = Buffer.alloc(s, 512);`
` Synth(\recorder, [\in, 0, \thresh, 0.35, \fftbuf, ~craft_fftbuf_left, \recbuf, ~craft_buffer_left]); `
`~synthGroup = Group.new;
~grainbufGroup = Group.new(~synthGroup);
~effectGroup = Group.after(~synthGroup);
~nyquist = s.sampleRate * 0.5;`
`~combBuses = Array.fill(2, { Bus.audio(s, 1); });`
`~clocks = Array.fill(4, { TempoClock.new(1); });`
`~clockSpec = [0.125, 3.0, \exp].asSpec;
~lengthSpec = [0.999,0.01,\exp].asSpec;
~endSpec = [0.999,0.0001,\exp].asSpec;
~ampSpec = [0.15,6.0,-15].asSpec;
~octaveSpec = [0.0625,3.0,\exp, 0.0625,1].asSpec;
~relSpec = [0.1,0.5,\linear].asSpec;
~freqSpec = [10.0,300.0,\linear].asSpec;`
`~ampBuses = Array.fill(8, { Bus.control(s, 1).set(1.0); });
~ampBus = Array.fill(2, { Bus.control(s,1).set(0.001); });`
`~octaveBus = Bus.control(s, 1).set(1);`
`~durBus = Bus.control(s, 1).set(0.25);
~trateBus = Bus.control(s, 1).set(80);`
`~sine = Env.sine.discretize(1024).putLast(0);
~sineEnv = Buffer.sendCollection(s, ~sine, 1);`
`~samNum1 = 0;
~samNum2 = 0; `
`~button_gates = [0, 0];
~rec_gate = 0;
~comb_gate = 0;`
`~button_gates = Array.fill(16 , { 0 } );
~posBus = Array.fill(16, {|i| Bus.control(s, 1).set(i*0.125); });
~rateBus = Array.fill(16, {|i| Bus.control(s, 1).set(1); });`
`~comb_synths = Array.fill(2, {|i| Synth(\combc, [\in, ~combBuses[i], \mix, 0.0 ], ~effectGroup);
}); `
`OSCdef(\craft, {|msg| var val0,val2,val4,val6,val8,val10, val12,val14,val15,val17,val19, val21,val23,val25,val27,val29;
val0 = msg[0+3];
val2 = msg[2+3];
val4 = msg[4+3];
val6 = msg[6+3];
val8 = msg[8+3];
val10 = msg[10+3];
val12 = msg[12+3];
val14 = msg[14+3];
val15 = msg[15+3];
val17 = msg[17+3];
val19 = msg[19+3];
val21 = msg[21+3];
val23 = msg[23+3];
val25 = msg[25+3];
val27 = msg[27+3];
val29 = msg[29+3];
if ( val0 != 0, {
val0 = (val0 - 0.025)/0.075;
if ( ~button_gates[0] == 0, {
~button_gates.put(0, 1); "button 0 pressed".postln;
~grain0 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[0].index,
\release, ~relSpec.map(val0),
\rateBus, ~rateBus[0].index,
\amp, 1,
\out, ~combBuses[0] ], ~synthGroup);
});
}, {
if ( ~button_gates[0] == 1, {
~grain0.set(\gate, 0);
~button_gates.put(0, 0); "button unpressed".postln;
});
});
if ( val2 != 0, {
val2 = (val2 - 0.025)/0.075;
if ( ~button_gates[1] == 0, {
~button_gates.put(1, 1); "button 2 pressed".postln;
~grain1 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[1].index,
\release, ~relSpec.map(val2),
\rateBus, ~rateBus[1].index,
\amp, 1,
\out, ~combBuses[0] ], ~synthGroup);
});
}, {
if ( ~button_gates[1] == 1, {
~grain1.set(\gate, 0);
~button_gates.put(1, 0); "button 2 unpressed".postln;
});
});
if ( val4 != 0, {
val4 = (val4 - 0.025)/0.075;
if ( ~button_gates[2] == 0, {
~button_gates.put(2, 1); "button 4 pressed".postln;
~grain2 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[2].index,
\release, ~relSpec.map(val4),
\rateBus, ~rateBus[2].index,
\amp, 1,
\out, ~combBuses[0] ], ~synthGroup);
});
}, {
if ( ~button_gates[2] == 1, {
~grain2.set(\gate, 0);
~button_gates.put(2, 0); "button 4 unpressed".postln;
});
});
if ( val6 != 0, {
val6 = (val6 - 0.025)/0.075;
if ( ~button_gates[3] == 0, {
~button_gates.put(3, 1); "button 6 pressed".postln;
~grain3 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[3].index,
\release, ~relSpec.map(val6),
\rateBus, ~rateBus[3].index,
\amp, 1,
\out, ~combBuses[0] ], ~synthGroup);
});
}, {
if ( ~button_gates[3] == 1, {
~grain3.set(\gate, 0);
~button_gates.put(3, 0); "button 6 unpressed".postln;
});
});
if ( val8 != 0, {
val8 = (val8 - 0.025)/0.075;
if ( ~button_gates[4] == 0, {
~button_gates.put(4, 1); "button 8 pressed".postln;
~grain4 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[4].index,
\release, ~relSpec.map(val8),
\rateBus, ~rateBus[4].index,
\amp, 1,
\out, ~combBuses[0] ], ~synthGroup);
});
}, {
if ( ~button_gates[4] == 1, {
~grain4.set(\gate, 0);
~button_gates.put(4, 0); "button 8 unpressed".postln;
});
});
if ( val10 != 0, {
val10 = (val10 - 0.025)/0.075;
if ( ~button_gates[5] == 0, {
~button_gates.put(5, 1); "button 10 pressed".postln;
~grain5 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[5].index,
\release, ~relSpec.map(val10),
\rateBus, ~rateBus[5].index,
\amp, 1,
\out, ~combBuses[0] ], ~synthGroup);
});
}, {
if ( ~button_gates[5] == 1, {
~grain5.set(\gate, 0);
~button_gates.put(5, 0); "button 10 unpressed".postln;
});
});
if ( val12 != 0, {
val12 = (val12 - 0.025)/0.075;
if ( ~button_gates[6] == 0, {
~button_gates.put(6, 1); "button 12 pressed".postln;
~grain6 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[6].index,
\release, ~relSpec.map(val12),
\rateBus, ~rateBus[6].index,
\amp, 1,
\out, ~combBuses[0] ], ~synthGroup);
});
}, {
if ( ~button_gates[6] == 1, {
~grain6.set(\gate, 0);
~button_gates.put(6, 0); "button 12 unpressed".postln;
});
});
if ( val14 != 0, {
val14 = (val14 - 0.025)/0.075;
if ( ~button_gates[7] == 0, {
~button_gates.put(7, 1); "button 14 pressed".postln;
~grain7 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[7].index,
\release, ~relSpec.map(val14),
\rateBus, ~rateBus[7].index,
\amp, 1,
\out, ~combBuses[0] ], ~synthGroup);
});
}, {
if ( ~button_gates[7] == 1, {
~grain7.set(\gate, 0);
~button_gates.put(7, 0); "button 14 unpressed".postln;
});
});
if ( val15 != 0, {
val15 = (val15 - 0.025)/0.075;
if ( ~button_gates[8] == 0, {
~button_gates.put(8, 1); "button 0 pressed".postln;
~grain8 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[8].index,
\release, ~relSpec.map(val15),
\rateBus, ~rateBus[8].index,
\amp, 1,
\out, ~combBuses[1] ], ~synthGroup);
});
}, {
if ( ~button_gates[8] == 1, {
~grain8.set(\gate, 0);
~button_gates.put(8, 0); "button unpressed".postln;
});
});
if ( val17 != 0, {
val17 = (val17 - 0.025)/0.075;
if ( ~button_gates[9] == 0, {
~button_gates.put(9, 1); "button 2 pressed".postln;
~grain9 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[9].index,
\release, ~relSpec.map(val17),
\rateBus, ~rateBus[9].index,
\amp, 1,
\out, ~combBuses[1] ], ~synthGroup);
});
}, {
if ( ~button_gates[9] == 1, {
~grain9.set(\gate, 0);
~button_gates.put(9, 0); "button 2 unpressed".postln;
});
});
if ( val19 != 0, {
val19 = (val19 - 0.025)/0.075;
if ( ~button_gates[10] == 0, {
~button_gates.put(10, 1); "button 4 pressed".postln;
~grain10 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[10].index,
\release, ~relSpec.map(val19),
\rateBus, ~rateBus[10].index,
\amp, 1,
\out, ~combBuses[1] ], ~synthGroup);
});
}, {
if ( ~button_gates[10] == 1, {
~grain10.set(\gate, 0);
~button_gates.put(10, 0); "button 4 unpressed".postln;
});
});
if ( val21 != 0, {
val21 = (val21 - 0.025)/0.075;
if ( ~button_gates[11] == 0, {
~button_gates.put(11, 1); "button 6 pressed".postln;
~grain11 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[11].index,
\release, ~relSpec.map(val21),
\rateBus, ~rateBus[11].index,
\amp, 1,
\out, ~combBuses[1] ], ~synthGroup);
});
}, {
if ( ~button_gates[11] == 1, {
~grain11.set(\gate, 0);
~button_gates.put(11, 0); "button 6 unpressed".postln;
});
});
if ( val23 != 0, {
val23 = (val23 - 0.025)/0.075;
if ( ~button_gates[12] == 0, {
~button_gates.put(12, 1); "button 8 pressed".postln;
~grain12 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[12].index,
\release, ~relSpec.map(val23),
\rateBus, ~rateBus[12].index,
\amp, 1,
\out, ~combBuses[1] ], ~synthGroup);
});
}, {
if ( ~button_gates[12] == 1, {
~grain12.set(\gate, 0);
~button_gates.put(12, 0); "button 8 unpressed".postln;
});
});
if ( val25 != 0, {
val25 = (val25 - 0.025)/0.075;
if ( ~button_gates[13] == 0, {
~button_gates.put(13, 1); "button 10 pressed".postln;
~grain13 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[13].index,
\release, ~relSpec.map(val25),
\rateBus, ~rateBus[13].index,
\amp, 1,
\out, ~combBuses[1] ], ~synthGroup);
});
}, {
if ( ~button_gates[13] == 1, {
~grain13.set(\gate, 0);
~button_gates.put(13, 0); "button 10 unpressed".postln;
});
});
if ( val27 != 0, {
val27 = (val27 - 0.025)/0.075;
if ( ~button_gates[14] == 0, {
~button_gates.put(14, 1); "button 12 pressed".postln;
~grain14 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[14].index,
\release, ~relSpec.map(val27),
\rateBus, ~rateBus[14].index,
\amp, 1,
\out, ~combBuses[1] ], ~synthGroup);
});
}, {
if ( ~button_gates[14] == 1, {
~grain14.set(\gate, 0);
~button_gates.put(14, 0); "button 12 unpressed".postln;
});
});
if ( val29 != 0, {
val29 = (val29 - 0.025)/0.075;
if ( ~button_gates[15] == 0, {
~button_gates.put(15, 1); "button 14 pressed".postln;
~grain15 = Synth(\grainSampler,[\bufnum, ~craft_buffer_left,
\envbuf, ~sineEnv,
\posBus, ~posBus[15].index,
\release, ~relSpec.map(val29),
\rateBus, ~rateBus[15].index,
\amp, 1,
\out, ~combBuses[1] ], ~synthGroup);
});
}, {
if ( ~button_gates[15] == 1, {
~grain15.set(\gate, 0);
~button_gates.put(15, 0); "button 14 unpressed".postln;
});
});
}, "/craft");`
`~tone_col_sel_spec = [0, 4, \linear, 1].asSpec;`
`~tune_specs = [ [287, 0, -4, 1].asSpec, [154, 0, -4, 1].asSpec,[105, 0, -4, 1].asSpec, [77, 0, -4, 1].asSpec, [63, 0, -4, 1].asSpec; ];`
`~tuner = ~tune_specs[0];
~tone_col_sel = 0;`
`OSCdef(\trillsquare, {|msg|
var x_val = msg[4];
var x_val2 = msg[6];
if ( x_val != 0, {
8.do{|i| ~rateBus[i].set(~tone_collection.wrapAt(~tuner.map(x_val)+i));
}; });
if ( msg[3] > 1, {
~tone_col_sel = ~tone_col_sel_spec.map(x_val2).postln;
~tone_collection = ~scale_array[~tone_col_sel];
~tuner = ~tune_specs[~tone_col_sel];
});
}, '/square');`
`OSCdef(\trillbar, {|msg|
var x_val = msg[4];
var x_val2 = msg[6];
//msg.postln;
//x_val.postln;
if ( x_val != 0, {
8.do{|i| ~rateBus[i+8].set(~tone_collection.wrapAt(~tuner.map(x_val)+i));
}; });
}, '/bar');`
`~delmodSpec = [0.001,150.0, \exp, 0.001].asSpec;`
`OSCdef(\trillring, {|msg|
var x_val = msg[4];
if ( x_val != 0, {
~comb_synths[0].set(\mix, x_val); });
if ( msg[3] > 1, {
~comb_synths[0].set(\delmod, ~delmodSpec.map(x_val));
});
}, '/ring');`
`OSCdef(\trillhex, {|msg|
var x_val = msg[4];
if ( x_val != 0, {
~comb_synths[1].set(\mix, x_val); });
if ( msg[3] > 1, {
~comb_synths[1].set(\delmod, ~delmodSpec.map(x_val));
});
}, '/hex');`
And this works all super smooth, as long as I don't start touching the Trill Flex. But I really want to add the Flex to the setup. Could you point me in the right direction for solving this issue?
Thanks in advance.
Kind regards,
Sjoerd