electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks GalleryGallery 
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
midi sporking?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
openloop



Joined: Sep 20, 2007
Posts: 2
Location: colorado

PostPosted: Thu Sep 20, 2007 12:06 am    Post subject: midi sporking? Reply with quote  Mark this post and the followings unread

so i've got the example mandolin up and running from the STK with midi.

i have a small problem though that i can't seem to wrap my head around.

with i < 40 set below (by default) i can play 40 notes before playback stops

Quote:

// spork handlers, one for each voice
for( 0 => int i; i < 40; i++ ) spork ~ handler();


i tried changing the loop with i < 1 and got exactly 1 note of playback

is sporking the right thing to do here? how would i go about getting the playback to reuse the handlers?

here is the complete code. thanks in advance.

Quote:
//------------------------------------------------
// name: polyfony.ck
// desc: polyfonic mandolin model
//
// by: Ananya Misra and Ge Wang
// send all complaints to prc@cs.princeton.edu
//--------------------------------------------

// device to open (see: chuck --probe)
3 => int device;
// get from command line
if( me.args() ) me.arg(0) => Std.atoi => device;

MidiIn min;
MidiMsg msg;

// try to open MIDI port (see chuck --probe for available devices)
if( !min.open( device ) ) me.exit();

// print out device that was opened
<<< "MIDI device:", min.num(), " -> ", min.name() >>>;


// make our own event
class NoteEvent extends Event
{
int note;
int velocity;
}

// the event
NoteEvent on;
// array of ugen's handling each note
Event @ us[128];

// the base patch
Gain g => JCRev r => dac;
.1 => g.gain;
.2 => r.mix;

// handler for a single voice
fun void handler()
{
// don't connect to dac until we need it
Mandolin m;
Event off;
int note;

while( true )
{
on => now;
on.note => note;
// dynamically repatch
m => g;
Std.mtof( note ) => m.freq;
Std.rand2f( .6, .8 ) => m.pluckPos;
on.velocity / 128.0 => m.pluck;
off @=> us[note];

off => now;
null @=> us[note];
m =< g;
}
}

// spork handlers, one for each voice
for( 0 => int i; i < 1; i++ ) spork ~ handler();

// infinite time-loop
while( true )
{
// wait on midi event
min => now;

// get the midimsg
while( min.recv( msg ) )
{
// catch only noteon
if( msg.data1 != 144 )
continue;

// check velocity
if( msg.data3 > 0 )
{
// store midi note number
msg.data2 => on.note;
// store velocity
msg.data3 => on.velocity;
// signal the event
on.signal();
// yield without advancing time to allow shred to run
me.yield();
}
else
{
if( us[msg.data2] != null ) us[msg.data2].signal();
}
}
}
Back to top
View user's profile Send private message
drooler



Joined: Aug 23, 2007
Posts: 3
Location: california

PostPosted: Mon Sep 24, 2007 7:40 pm    Post subject: easier way... Reply with quote  Mark this post and the followings unread

http://wiki.cs.princeton.edu/forums.html/EasyMIDI.ck
Back to top
View user's profile Send private message
openloop



Joined: Sep 20, 2007
Posts: 2
Location: colorado

PostPosted: Mon Sep 24, 2007 10:23 pm    Post subject: Re: easier way... Reply with quote  Mark this post and the followings unread

drooler wrote:
http://wiki.cs.princeton.edu/forums.html/EasyMIDI.ck


Hey thanks, that's really what I was looking for.

I found by taking out this part of the first loop I could work around it:
Quote:

off @=> us[note];

off => now;
null @=> us[note];
m =< g;
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 [3 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
Buy N Save

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003, 2004, 2005, 2006 and 2007 by electro-music.com