Author |
Message |
momo_the_monster
Joined: Apr 06, 2007 Posts: 5 Location: Los Angeles
|
Posted: Thu Apr 12, 2007 11:09 pm Post subject:
MIDI and Timing issues |
|
|
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
|
|
|
moudi
Joined: Oct 07, 2006 Posts: 63 Location: Bern Switzerland
|
Posted: Fri Apr 13, 2007 2:04 am Post subject:
|
|
|
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
jassas
/moudi |
|
Back to top
|
|
|
spencer
Joined: Aug 16, 2006 Posts: 53 Location: northern california
|
Posted: Mon Apr 16, 2007 1:46 pm Post subject:
|
|
|
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
|
|
|
momo_the_monster
Joined: Apr 06, 2007 Posts: 5 Location: Los Angeles
|
Posted: Mon Apr 16, 2007 10:37 pm Post subject:
|
|
|
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
|
|
|
renderful
Joined: Apr 18, 2007 Posts: 29 Location: Boulder, Co
|
Posted: Wed Apr 18, 2007 2:12 pm Post subject:
|
|
|
This helped me greatly!
Thanks Spencer. |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Apr 18, 2007 3:10 pm Post subject:
|
|
|
Welcome on board, Renderful! _________________ Kassen |
|
Back to top
|
|
|
renderful
Joined: Apr 18, 2007 Posts: 29 Location: Boulder, Co
|
Posted: Wed Apr 18, 2007 4:01 pm Post subject:
|
|
|
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
|
|
|
|