Re: Trouble with Music Player
Re: Trouble with Music Player
- Subject: Re: Trouble with Music Player
- From: William Stewart <email@hidden>
- Date: Thu, 11 Jun 2009 18:01:57 -0700
rather than usleep, its probably better to call CFRunLoopRunInMode
with a timeout of 2 seconds
But I don't think this is related to your bug - if you do a
CAShow(seq) what does that look like?
On Jun 11, 2009, at 5:10 PM, Carlos Eduardo Mello wrote:
Hi,
I need some help to figure out what is going on with my MIDI player.
The code below is used to play some midi notes which are generated
inside my application. So far, the application is only a C++ tool in
which I am building my data model. But I need to listen to midi data
as I go, so decided to build a little player.
I am using the Music Player API. It took me a while to figure it
out, starting with the PlaySequence sample project. Now it seems to
be playing ok, but with a very weird bug. The track contains two
consecutive triads with 1 beat of duration each. This is inside a
track in my sequence (seq). I checked many times and am sure that
the correct data is inside the track, but when it plays, the third
note of the first chord (and only this note) is offset by about an
eighth-note length.
I tried playing other data, like a melody, and it seems to be fine.
This problem apparently only happens when the track contains
simultaneous notes, like the chords I described above.
I copied the PlayLoop from the PlaySequence example and removed
everything related to AUGraph, which I didn't need (sending MIDI
data directly to a MIDI Endtpoint). Should I replace this loop with
something like a timer (NSTimer, CFTimer, ...?) , in order to allow
the player to work correctly. I mean, does usleep() actually yeld
the processor to other parts of the code? (the documentation I found
didn't make it clear...)
Can anybody see what is wrong with my code?
<code>
/ /... part of ::PlaySequence()
endPoint = MIDIGetDestination(destIndex);
if(endPoint)
{
sErr = MusicSequenceSetMIDIEndpoint( seq, endPoint );
if(sErr == noErr)
{
sErr = NewMusicPlayer( &player );
if(sErr == noErr)
{
sErr = MusicPlayerSetSequence( player, seq );
if(sErr == noErr)
{
sErr = MusicPlayerSetTime(player, 0);
if(sErr == noErr)
{
sErr = MusicPlayerPreroll(player); // overkill??
if(sErr == noErr)
{
sErr = MusicPlayerStart(player);
if(sErr == noErr)
{
PlayLoop( player, seqLen );
sErr = MusicPlayerStop(player);
if(sErr == noErr)
delete [] tracks;
}
// ...
void ::PlayLoop( MusicPlayer &player, MusicTimeStamp sequenceLength )
{
OSStatus err = noErr;
MusicTimeStamp time;
while(1)
{
usleep (2 * 1000);
err = MusicPlayerGetTime( player, &time );
if(err == noErr)
{
if (time >= sequenceLength)
break;
}
}
return;
}
</code>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden