electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
poster
 Forum index » DIY Hardware and Software » ChucK programming language
Troubles with OSC
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
shmoyko



Joined: Dec 19, 2013
Posts: 5
Location: London

PostPosted: Thu Dec 26, 2013 7:52 am    Post subject: Troubles with OSC Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Sun Dec 29, 2013 2:12 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Sun Dec 29, 2013 2:15 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
heuermh



Joined: Dec 15, 2006
Posts: 19
Location: minneapolis

PostPosted: Tue Dec 31, 2013 4:32 pm    Post subject: Reply with quote  Mark this post and the followings unread

I have a TouchOSC example here, I think it just uses one of the default/example scenes

https://github.com/heuermh/lick/blob/master/examples/touchOscSimple.ck

Here's the "server" side ChucK class

https://github.com/heuermh/lick/blob/master/TouchOscServer.ck

You might want to double check the OSC address signatures to make sure they match the controls in your scene.
Back to top
View user's profile Send private message
shmoyko



Joined: Dec 19, 2013
Posts: 5
Location: London

PostPosted: Thu Jan 02, 2014 5:00 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use