• 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: behaviour of MIDIFlushOutput
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: behaviour of MIDIFlushOutput


  • Subject: Re: behaviour of MIDIFlushOutput
  • From: Doug Wyatt <email@hidden>
  • Date: Wed, 10 Sep 2008 17:01:55 -0700


On Sep 9, 2008, at 21:24 , Evan Laforge wrote:

Hi, new to mac programming here.

Could someone explain the behaviour of the MIDIFlushOutput function?
I'm seeing something strange.  It looks like scheduled note-offs are
retained, but played right after the flush, and *sometimes* a pitch
bend becomes a pitchbend to 0 (i.e. lowest position).  The following
program reproduces this on my machine (System 10.5.4):

#include <CoreAudio/HostTime.h>
#include <CoreMIDI/CoreMIDI.h>

MIDIClientRef client;
MIDIPortRef port;
MIDIEndpointRef dest;
MIDITimeStamp start;

void
send(double offset, Byte b0, Byte b1, Byte b2)
{
   Byte bytes[3] = {b0, b1, b2};
   MIDIPacketList packets;
   MIDIPacket *packet = MIDIPacketListInit(&packets);
   MIDITimeStamp ts = start + offset * 1000000;

I don't know where you're getting the idea that time stamp ticks are 1/100000ths of a second. The right constant is CAHostTimeBase::GetFrequency().

   MIDIPacketListAdd(&packets, sizeof packets, packet, ts, 3, bytes);
   MIDISend(port, dest, &packets);
}

int
main(int argc, char **argv)
{
   MIDIClientCreate(CFSTR("core midi"), NULL, NULL, &client);
   MIDIOutputPortCreate(client, CFSTR("output port"), &port);
   dest = MIDIGetDestination(0);
   start = AudioGetCurrentHostTime();

   send(0, 144, 53, 70);
   send(400, 128, 53, 70);
   send(500, 144, 55, 70);
   send(900, 128, 55, 70);
   send(1000, 144, 57, 70);
   send(1000, 224, 102, 76); // pitchbend
   send(1400, 128, 57, 70);
   usleep(500000);
   MIDIFlushOutput(NULL);
   sleep(3);
   return 0;
}

When run, here's what a separate midi monitor shows:

(175987598,"IAC Driver IAC Bus 1",ChannelMessage 0 (NoteOn 53 70))
(175987998,"IAC Driver IAC Bus 1",ChannelMessage 0 (NoteOff 53 70))
(175988098,"IAC Driver IAC Bus 1",ChannelMessage 0 (NoteOn 55 70))
(175988099,"IAC Driver IAC Bus 1",ChannelMessage 0 (NoteOff 55 64))
(175988099,"IAC Driver IAC Bus 1",ChannelMessage 0 (NoteOff 57 64))
(175988099,"IAC Driver IAC Bus 1",ChannelMessage 0 (PitchBend (-1.0)))

Notice how I got an extra NoteOff 57, even though the NoteOn was
descheduled by the flush.  And more worryingly, the PitchBend -1,
which screws up synth state.  Obviously, this is over IAC, I haven't
tried an external port yet.

The extra note-off is because flush is protecting itself against a race and generating a note-off for a scheduled note-on without regard for whether the note-on has really been played. 

Thanks for catching a bug about pitch bend; CoreMIDI is stupidly sending 0xEn 0x00 0x00 instead 0xEn 0x00 0x40 to reset it to the center.

Doug


--
Doug Wyatt
Core Audio, Apple

 _______________________________________________
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: behaviour of MIDIFlushOutput
      • From: "Evan Laforge" <email@hidden>
References: 
 >behaviour of MIDIFlushOutput (From: "Evan Laforge" <email@hidden>)

  • Prev by Date: Re: Multi-bus rendering
  • Next by Date: Re: Examples for AudioFileStream and AudioConverter?
  • Previous by thread: behaviour of MIDIFlushOutput
  • Next by thread: Re: behaviour of MIDIFlushOutput
  • Index(es):
    • Date
    • Thread