Csound Csound-dev Csound-tekno Search About

[Csnd] triggering instruments from OSC

Date2009-06-16 23:37
FromAtte Andre Jensen
Subject[Csnd] triggering instruments from OSC
Hi

I'm just getting started with OSC, so forgive me if I ask something obvious.

I'm trying to trigger csound instruments from another application via 
OSC. I'd like to have the osc -> instrument triggering only going on at 
one place to make things cleaner. At the moment I have something like 
(which seems to work just great):

--- begin csound code ---
     instr osc_listen_0
kp3      init 0
Sinstr       =     ""
     nxtmsg:
kk  OSClisten gihandle, "/csound/instr", "sf", Sinstr, kp3
if (kk == 0) goto ex
     event "i", Sinstr, 0, kp3
     kgoto nxtmsg
ex:
     endin

     instr osc_listen_1
kp3       init 0
kp4       init 0
Sinstr       =     ""
     nxtmsg:
kk  OSClisten gihandle, "/csound/instr", "sff", Sinstr, kp3, kp4
if (kk == 0) goto ex
     event "i", Sinstr, 0, kp3, kp4
     kgoto nxtmsg
ex:
     endin
--- end csound code ---

So basically I have one instrument that listens for OSC events that 
contains only p3, one that has p3 and p4, and would also have others to 
handle any number of p-fields. I don't expect to be needing much more 
than a handful of these instruments (up to, say, p6), but still:

Question #1:
Is there a better way, for instance with everything done in one instrument?

Question #2:
Actually I would rather not have to worry about the p3, but instead have 
things working more in a MIDI fashion, with matching noteon/noteoff. Or 
even better; be able to use both p3 for duration and noteon/noteoff with 
the same instruments (and even be able to trigger them via MIDI from a 
keyboard). Is this possible and if so where do I have to look for 
examples and/or opcodes that does this?

Also any general thoughts or experiences with this kind of approach are 
most welcome!

-- 
Atte

http://atte.dk   http://modlys.dk   http://virb.com/atte