Obviously I don’t grok yet
I think my problem is in my play routine which uses the control bus to trigger the sound. If anybody has any epiphanies to share or videos that spark them, let me know.
Below is the synthdef that listens on the control bus and outputs the trigger based on the incoming value. I used SendTrig to see that the signal being sent to Our.ar(ctlBus, outSignal) is zero. But still the buffer was played because I hear it. So next I’m going to experiment with the CtrlBus signal. Maybe I need a UGen or something there?
var digitalPins = [ 0, 1, 2, 3, 4, 5, 6, 7];
var triggerCount = 1;
SynthDef(\trigDetector, {
arg ctlBus, deviceId;
var all = Array.fill(digitalPins.size, { |i|
DigitalIn.ar(digitalPins[i]);
});
// Convert all the bit array to a binary value
var allId = all.reverse.reduce({ arg total, bit; total * 2 + bit }, 0);
// Make sure they are set by delaying a little bit
var delay_allId = TDelay.ar(in: allId, dur: 0.003);
// Create bitmasks.
// velMask is how many bit used for velocity
// devMask used for devices, of which there are only 2
var velMask = pow(2, digitalPins.size - triggerCount) -1;
var devMask = pow(2, triggerCount) - 1;
// Use the masks to get the velocity and device that was activated
var velocity = allId.bitAnd(velMask);
var device = (allId >> (digitalPins.size - triggerCount)).bitAnd(devMask);
//var device = (allId >> (digitalPins.size - triggerCount));
// scale button between 0 and 1 based on velMask
var button = velocity / velMask;
var signal = Trig.ar( delay_allId * button, 0.4);
var outSignal = Select.ar(abs(device - deviceId) < 0.1, [signal, K2A.ar(0)]);
Out.ar(ctlBus, outSignal);
Out.kr(ctlBus, outSignal);
SendTrig.ar(HPZ1.ar(delay_allId), 20, device);
SendTrig.ar(HPZ1.ar(delay_allId), 21, deviceId);
SendTrig.ar(HPZ1.ar(delay_allId), 22, outSignal);
}).send(s);
SynthDef("sh",{
arg buf = 0, rate = 1.0, loop = 0, scale = 1.0, vol = 1.0, t_reset=0, wetBus = 0, deviceId = 0, trigBus;
var snd;
var button = In.ar(trigBus);
var latch = SetResetFF.ar(button, t_reset) ;
var volmultraw = ((1.0 - scale) + (button*scale));
var volmult = LastValue.ar((((1.0 - scale) + (button*scale))) * Schmidt.ar(button, 0.1, 0.1) ) ;
//button.belaScope(1);
n = LastValue.ar((((1.0 - scale) + ((button/3.2)*scale))) * Schmidt.ar(button, 0.1, 0.1) ) ;
snd=PlayBuf.ar(2, buf, BufRateScale.kr(buf) * rate, trigger: button, loop: loop * latch, startPos: 0, doneAction: 0) * volmultraw * vol;
// If we don't use LastValue, then the value is zero the next time and the sound is abruptly ended
Out.ar(wetBus, snd);
// Trigger debug msg
// SendTrig.ar(button, 5, BufSamples.kr(buf));
//SendTrig.ar(button, 5, button);
//SendTrig.ar(HPZ1.ar(button), 5, volmultraw);
}).send(s);
...
b = Bus.audio(s, 1);
//Synth.new("scope2", [\ctlBus, b]);
k = Buffer.read(s, "/root/src/HarmProject/data/samples/Kick2.wav");
Synth.new("sh", [trigBus: b, buf: k]);
Synth.new("trigDetector", [\deviceId, 1.0, \ctlBus, b]);
//SynthDef("scope2", { In.ar(b).belaScope(2); }).play;
//SynthDef("scope2", { SinOsc.ar(550.2, 0, 1).belaScope(2); }).play;
o = OSCFunc({ arg msg, time; [time, msg].postln; },'/tr');