Author |
Message |
shmoyko
Joined: Dec 19, 2013 Posts: 5 Location: London
|
Posted: Thu Dec 26, 2013 7:52 am Post subject:
Troubles with OSC |
|
|
Hello,
I'm trying to build some sort of phrase sampler with ChucK and TouchOSC.
So far, all I have in TouchOSC is one push button that sends a float, either 0 or 1 - 1 on touch, 0 on release.
However, the detection of this message is sporadic. Most of the time my code only detects the release action, occasionally it detects the touch.
Here's my code (having troubles with formatting. Here's pastebin: http://pastebin.com/90qaFyw9). Can anyone see what I'm doing wrong? Thanks.
Code: |
public class Sampleholder extends Chubgraph
{
SndBuf buffy;
string path;
string sampleLocation;
buffy => outlet;
fun void setSamplePath(string givenPath)
{
givenPath => path;
}
fun void setSample(string filename)
{
path + "/" + filename => sampleLocation;
sampleLocation => buffy.read;
buffy.samples() => buffy.pos;
}
fun void setPositionToStart()
{
0 => buffy.pos;
}
fun void setPositionToEnd()
{
buffy.samples() => buffy.pos;
}
}
/**************************************************************************************/
/* GLOBAL VARIABLES */
/**************************************************************************************/
// OSC stuff
OscRecv recv;
8001 => recv.port;
recv.listen();
// define BPM
120.0 => float BPM;
4 => int signature;
60.0 / BPM => float crotchet; //float representing the number of seconds that a crotched lasts
crotchet::second => dur cr;
signature::cr => dur bar;
// master gain
Gain masterGain => dac;
// array of files to load
[
[me.dir(-5) + "/Samples/DISCRETEENERGYII[SAMPLE PACK]/SYNTHS", "152bpm_UO_BELLS_C.wav"]
] @=> string files[][];
/**************************************************************************************/
/* SHREDS */
/**************************************************************************************/
fun void touchSampleShred(int sampleIndex, Sampleholder sample)
{
recv.event("/chooper/touchsample/" + sampleIndex + ", f") @=> OscEvent touchEvent;
while (true)
{
touchEvent => now;
while (touchEvent.nextMsg()) {
touchEvent.getFloat() => float f;
<<< "touchEvent: ",f, "sample: ", sampleIndex >>>;
if (f > 0) {
sample.setPositionToStart();
} else {
sample.setPositionToEnd();
}
}
}
}
/**************************************************************************************/
/* MAIN PROGRAM */
/**************************************************************************************/
// create instances of Sampleholder
Sampleholder s[files.cap()];
// connect the instances to dac and initialize them
files.cap() => int loopEnd;
for (0 => int i; i <loopEnd> masterGain;
// load the files
files[i][0] => s[i].setSamplePath;
files[i][1] => s[i].setSample;
}
0.6 => masterGain.gain;
// spork 'em all
for (0 => int i; i <loopEnd> now;
}
| [url][/url] |
|
Back to top
|
|
|
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Sun Dec 29, 2013 2:12 pm Post subject:
|
|
|
Hi!
First a tip: turn off html and smilies when including code samples in your post. Especially the html parser tends to mangle chuck code like for loops like in the last bit of your code.
Second: have you tried communicating with something other than chuck, maybe trying out the puredata example here http://hexler.net/docs/touchosc-getting-started-osc , just to check that messages get through and that they look the way you expect them too? I'm wondering if perhaps more arguments than the single float number you've specified in e.g. "/chooper/touchsample/0, f" are sent from touchosc. Perhaps there's some kind of network issue - osc can lose messages when there is a bad connection. _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
|
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Sun Dec 29, 2013 2:15 pm Post subject:
|
|
|
Also, is your problem that you don't see the debug text in your while loop as often as you'd like to, or is it only a problem with the sound you expect to hear? _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
|
heuermh
Joined: Dec 15, 2006 Posts: 19 Location: minneapolis
|
|
Back to top
|
|
|
shmoyko
Joined: Dec 19, 2013 Posts: 5 Location: London
|
Posted: Thu Jan 02, 2014 5:00 am Post subject:
|
|
|
Thanks guys for your replies.
Antimon: I tried a similar setup with Pure Data and it all works perfectly fine. The problem is that I'm not seeing the debug message when I expect to see it. It kind of appears randomly - it should show every time I press my TouchOSC "button"
heuermh: thanks for the links to your code. I'll study it and maybe shed some light on my bug. Cheers. |
|
Back to top
|
|
|
|