b.d
1
Hi there -
I have a stream of values coming in from OSC…let’s represent it with a simple
~streamOfValues = 3.rand;
Is there anything on the client-side that can detect if this has made a 0-to-1 transition?
I was thinking along the lines of ~streamOfValues.changed
, but this doesn’t work as expected.
prko
2
Hello!
Would you mind reviewing this structure and sharing your feedback?
(
var streamOfValues = { 3.rand.debug };
var netAddr = NetAddr("127.0.0.1", 57120);
var receivedCurrent = nil;
var receivedPrevious = nil;
OSCdef(\test, { |msg, time, addr, recvPort|
var test = {
"<- (previous:" + receivedPrevious + "; current:" + receivedCurrent ++ ")"
};
receivedPrevious = receivedCurrent;
receivedCurrent = msg[1];
case
{ receivedPrevious == 1 and: receivedCurrent == 0} {
var midinote = 69;
(\midinote: midinote).play;
"1-to-0-change. is playing midinote" + midinote + test.()
}
{ receivedPrevious == 0 and: receivedCurrent == 1} {
var midinote = 93;
(\midinote: midinote).play;
"0-to-1-change. is playing midinote" + midinote + test.()
}
{ receivedPrevious.isNil } {
"nothing to be compared" + test.()
}
{
test.()
}
.postln
}, '/osc1', netAddr
);
fork {
20.do {
netAddr.sendMsg("/osc1", streamOfValues.());
0.1.wait
}
}
)
1 Like
b.d
3
Thanks - this inspired me to make a slightly smaller version for my specific uses…
~streamOfValues = {2.rand};
~previousValue = 0;
~change = {|value|
if ((~previousValue == 0) && (value==1))
{"ok".postln;};
~previousValue = value;
};
~change.(~streamOfValues.());
1 Like