electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
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 
 Forum index » DIY Hardware and Software » ChucK programming language
MIDI and Timing issues
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [7 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
momo_the_monster



Joined: Apr 06, 2007
Posts: 5
Location: Los Angeles

PostPosted: Thu Apr 12, 2007 11:09 pm    Post subject: MIDI and Timing issues Reply with quote  Mark this post and the followings unread

So I'm beginning work on my AV game - think of it like Parappa the Rapper with Audio/Visual clips.

The first thing I need to get working is that I need to detect whether the user inputs MIDI notes at the proper time (and allow a variable tolerance). So I figured I would start by toggling back and forth between binary states in a variable along with an audible sound, and seeing if I could detect whether or not an input was received during the '1' input, ignoring the opposite.

This is the code I've got so far:
Code:

MidiIn min;
MidiMsg msg;
MidiOut mout;
   if(!min.open(0)) me.exit();
int i;
// connect sine oscillator to D/A convertor (sound card)
      SinOsc s => dac;
while (true) {
300 => s.freq;
1 => i;
<<<i>>>;
if( min.recv( msg )&& msg.data3 != 0 && i==1 )
{ <<<msg>>>;}
1::second => now;
0 => s.freq;
0 => i;
<<<i>>>;
   1::second => now;
}

It doesn't really work right. If I push a MIDI note, it always gets sent, with a delay if it's pushed during the '0'. If I push it a couple of times, it gets queued up and comes through during the next few times. Any tips?

_________________
VJ Kung Fu :: Online Motion Magazine for DIY Video Artists

Last edited by momo_the_monster on Fri Apr 13, 2007 9:13 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
moudi



Joined: Oct 07, 2006
Posts: 63
Location: Bern Switzerland

PostPosted: Fri Apr 13, 2007 2:04 am    Post subject: Reply with quote  Mark this post and the followings unread

hi momo

there is a special code tag when you need to post code.
otherwise some special characters get lost.
look also at this thread: http://electro-music.com/forum/topic-14150.html

i think that this is the case with characters like them in your code: 
(even i have to admit, that i didn't tried to run it already).

besides of this, welcome to ChucK Cool

jassas
/moudi
Back to top
View user's profile Send private message Visit poster's website
spencer



Joined: Aug 16, 2006
Posts: 53
Location: northern california

PostPosted: Mon Apr 16, 2007 1:46 pm    Post subject: Reply with quote  Mark this post and the followings unread

Hi momo,
I think this doesn't work because MidiIn buffers MIDI messages. You probably need to read every MIDI message that is sent, and then decide if it happened at the right time. For this you'll need two shreds, one to keep track of the "right time" and one to handle MIDI input. Does the following code work a little better? (warning: I haven't tested it.)

Code:

MidiIn min;
MidiMsg msg;
MidiOut mout;

if(!min.open(0)) me.exit();
int i;
// connect sine oscillator to D/A convertor (sound card)
SinOsc s => dac;

fun void doMIDI()
{
    while (true)
    {
        min => now;
        while( min.recv( msg ) && msg.data3 != 0 )
        {
            if( i == 1 )
                <<<msg>>>;
        }
    }
}

spork ~ doMIDI();

while( true )
{
    300 => s.freq;
    1 => i;
    <<<i>>>;
    1::second => now;
   
    0 => s.freq;
    0 => i;
    <<<i>>>;
    1::second => now;
}



spencer
Back to top
View user's profile Send private message
momo_the_monster



Joined: Apr 06, 2007
Posts: 5
Location: Los Angeles

PostPosted: Mon Apr 16, 2007 10:37 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yes yes! The problem was exactly that - the MIDI messages were getting queued up, but I tried all sorts of looping and control structures to no avail. Your solution worked excellently - and I'm now on my way. Thanks!
_________________
VJ Kung Fu :: Online Motion Magazine for DIY Video Artists
Back to top
View user's profile Send private message Visit poster's website
renderful



Joined: Apr 18, 2007
Posts: 29
Location: Boulder, Co

PostPosted: Wed Apr 18, 2007 2:12 pm    Post subject: Reply with quote  Mark this post and the followings unread

This helped me greatly!

Thanks Spencer.
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Apr 18, 2007 3:10 pm    Post subject: Reply with quote  Mark this post and the followings unread

Welcome on board, Renderful!
_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
renderful



Joined: Apr 18, 2007
Posts: 29
Location: Boulder, Co

PostPosted: Wed Apr 18, 2007 4:01 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thanks Kassen. Currently playing with SMELT, noticed it in your Updates! thread. Great little toolset, already created an additive synth which uses touchpad coordinates to control frequency of each OSC.

Happy to be here. I've already learned so much!
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 [7 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
emSynth

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 through 2009 by electro-music.com - Conditions Of Use