• 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 22:00:08 +1100

What if scheduling ahead of time is not possible?

I might describe my situation a bit more clearly. I have a number of threads each with an input source on its runloop which, when triggered, goes and checks the current values of certain UI parameters and uses the values to figure out which MIDI note to play and then sends it to a previously specified device or software synth. The program requires each of these MIDI playing threads to play a regular metronomic stream of notes, e.g. one thread might output a note every 100 ms, and another every 250 ms, and another every 123 ms. Generally though, the user would want all of the threads to output on some simple subdivision on a common tempo.

So I was thinking that an extra 'timer' thread might be used to send triggers to all of the note players, so that they'd be kept in synch. I suppose the fundamental time unit would have to be a common divisor of all the different periods.

Is this a good way to think about it? Or is there something simpler or better that I can do? What's the best timing accuracy I can hope for in this real-time scenario?

Thanks,

Aengus.



On Tue, Dec 9, 2008 at 12:43 PM, William Stewart <email@hidden> wrote:
and... just using Brian's idea for a thread to do those timing tasks is fine. For the music sequencer (which I still don't understand why you can't use, but moving on...) we do:

(1) If it is just midi, we have a thread we use to schedule events ahead of time - basically what Brian described
(2) If it is midi and audio, then we schedule both (the audio rendering events and the midi out) from the audio thread, but we still have MIDI being scheduled ahead of time
(3) If it is audio only, well, we don't schedule any midi ;)

Bill


On Dec 8, 2008, at 3:08 PM, Brian Willoughby wrote:

At the very least, you should design your program so that you schedule MIDI events slightly ahead of time.  The reason for this is that some MIDI interfaces can take time-stamping MIDI data directly at the hardware level, and then deliver the messages precisely on time.  This potential feature depends upon a correctly-implemented MIDI driver which has an accurate connection to the CoreAudioClock, but folks who make such MIDI interfaces are undoubtedly doing this.  I'm talking about the multi-port MIDI interfaces with custom USB drivers.

I'm not sure how far in advance you should schedule things, but I guess the limit is that if the user presses stop, and queued MIDI events will still fire.  As long as the scheduling is short enough that the transport delay is not objectionable, then you should make sure you're feeding MIDI events significantly ahead of the playback position.

For virtual MIDI instruments, this can help because it would allow MIDI events to be scheduled on a sample-accurate basis within the rendering buffer.

The key is that audio is scheduled according to the CoreAudioClock, and CoreMIDI also is scheduled according to the same clock.  Therefore, you should be running your application clock on the same reference.

Brian Willoughby
Sound Consulting


On Dec 8, 2008, at 14:41, Carlos Eduardo Mello wrote:

On Dec 8, 2008, at 8:20PM, William Stewart wrote:
core audio clock gives you a much finer resolution - but given your description below, I'm really not at all sure what you are doing, and it seems to me that you have already decided on how you should basically implement what ever it is you are doing

Basically, I am writting a sequencer application. Nothing too fancy, just a basic multi track sequencer.
The interesting stuff is in the user interface and in a couple of specific features on data edditing.
And no. I haven't decided on anything related to playback or input. I am just just slowly experimenting with the CoreMIDI API to see what I should use. So your help will be  mostly invaluable.

- Let me see if I understand your suggestion: I should use the CoreAudio clocking facility in order to schedule my MIDI messages?
- Are there any samples on that specific type of code?
- Is it necessary to use threads other than the main? (the reason I ask is because I will need keep track of playback time in order to display visual cues for the user...)
_______________________________________________
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



--
____________________
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: 
 >Timing mechanism for MIDI ? (From: "Aengus Martin" <email@hidden>)
 >Re: Timing mechanism for MIDI ? (From: "Marcelo Cicconet" <email@hidden>)
 >Re: Timing mechanism for MIDI ? (From: William Stewart <email@hidden>)
 >Re: Timing mechanism for MIDI ? (From: Carlos Eduardo Mello <email@hidden>)
 >Re: Timing mechanism for MIDI ? (From: Brian Willoughby <email@hidden>)
 >Re: Timing mechanism for MIDI ? (From: William Stewart <email@hidden>)

  • Prev by Date: Re: PCI Audio Driver and takeTimeStamp
  • 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