• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Timing mechanism for MIDI ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Timing mechanism for MIDI ?


  • Subject: Re: Timing mechanism for MIDI ?
  • From: "Aengus Martin" <email@hidden>
  • Date: Tue, 9 Dec 2008 23:16:19 +1100

Hi Peter,

Does this mean that you're relying on the accuracy of [NSThread sleepUntilDate:]  ?

Can you say more about how you get CoreMIDI to schedule events at the correct times?

Thanks,

Aengus.



On Tue, Dec 9, 2008 at 8:15 AM, Peter Johnson <email@hidden> wrote:
Hi Aengus

In my AppKit sequencer application I use a thread for the timing. The sequencer runs on a separate thread which blocks on a semaphore, this is then signalled when the timer expires. The sequencer schedules MIDI events to occur at a specific clock value (in PPQN). The MIDI send code uses this value and converts it to system nanoseconds with AudioConvertNanosToHostTime() so that CoreMIDI schedules the event at the correct time. I've found this approach to give good timing.

Below is my timer thread code.

cheers
peter

In your class add:


BOOLtimerRunning;

The implementation:

- (void)StartTimer
{
if(timerRunning== NO)
{
timerRunning= YES;
[NSThreaddetachNewThreadSelector:@selector(timerThreadMethod:) toTarget:selfwithObject:nil];
}
}

- (void)StopTimer
{
timerRunning= NO;
}

- (void)timerThreadMethod:(id)anObject
{
NSAutoreleasePool* pool = [[NSAutoreleasePoolalloc] init];

[NSThreadsetThreadPriority:1.0];

if (sequencer)
{
sequencer->get_scheduler()->set_clock(0);
}

NSTimeInterval interval = 0.001;// 1ms

while(timerRunning)
{
interval = (60.0f / >get_tempo() / Clock::PPQN);
NSDate* sleepDate = [[NSDatealloc] initWithTimeIntervalSinceNow:interval];
[NSThread sleepUntilDate:sleepDate];
[sleepDate release];

{
// Internal clock
if (sequencer && sequencer->get_scheduler()->get_sync_in() == MIDI_time_code::OFF)
{
[selfPollSequencerSignal];
sequencer->get_scheduler()->set_clock(sequencer->get_scheduler()->get_clock() + 1);
}
}
}

[pool release];
}




--
____________________
www.am-process.org
 _______________________________________________
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

  • Follow-Ups:
    • Re: Timing mechanism for MIDI ?
      • From: Brian Willoughby <email@hidden>
References: 
 >Re: Timing mechanism for MIDI ? (From: Peter Johnson <email@hidden>)

  • Prev by Date: Re: Timing mechanism for MIDI ?
  • Next by Date: Re: Timing mechanism for MIDI ?
  • Previous by thread: Re: Timing mechanism for MIDI ?
  • Next by thread: Re: Timing mechanism for MIDI ?
  • Index(es):
    • Date
    • Thread