• 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
How to tell which midi track is associated with a packet?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to tell which midi track is associated with a packet?


  • Subject: How to tell which midi track is associated with a packet?
  • From: "Patrick J. Collins" <email@hidden>
  • Date: Sat, 14 May 2016 17:31:11 -0700 (PDT)

Hi everyone,

I've been struggling to find any information about this online...

Basically, I have an array of instruments, and I simply want my midi read proc
to forward the midi packet for a given track to the instrument at the array
index of the track number.

I don't understand how the track number is accessible within the data received in my midiReadProc...

Thanks in advance, here is my code to illustrate what I am doing:

  static void midiReadProc(const MIDIPacketList *pktlist,
                           void *refCon,
                           void *connRefCon) {

      struct MidiData *midiData = (struct MidiData *)refCon;
      NSArray *instruments = midiData->instruments;

      MIDIPacket *packet = (MIDIPacket *)pktlist->packet;
      for (int i=0; i < pktlist->numPackets; i++) {
          [[instruments objectAtIndex:????] writePacket:*packet];
                                      ^^^^  How do I know which instrument / track number this packet is for???
          packet = MIDIPacketNext(packet);
      }
  }

  -(void)playMidi:(NSData *)midi {
      OSStatus result = noErr;
      MIDIClientRef virtualMidi;
      result = MIDIClientCreate(CFSTR("client"),
                                NULL,
                                NULL,
                                &virtualMidi);

      NSAssert(result == noErr, @"MIDIClientCreate failed. Error code: %d", (int)result);

      sequence = 0;
      player   = 0;

      NewMusicSequence(&sequence);
      MusicSequenceFileLoadData(sequence, (__bridge CFDataRef) midi, 0, 0);

      UInt32 numberOfTracks = 0;
      MusicSequenceGetTrackCount(sequence, &numberOfTracks);

      NSMutableArray *instruments = [NSMutableArray arrayWithCapacity:16];
      for (int i = 1; i <= numberOfTracks; i++) {
          Instrument *instrument = [[Instrument alloc] init];
          [instruments addObject:instrument];
      }
      self.instruments = [instruments copy];
      struct MidiData initialized = {0};
      midiData = initialized;
      midiData.instruments = self.instruments;

      MIDIEndpointRef virtualEndpoint;
      result = MIDIDestinationCreate(virtualMidi, CFSTR("destination"), midiReadProc, &midiData, &virtualEndpoint);

      NSAssert(result == noErr, @"MIDIDestinationCreate failed. Error code: %d", (int)result);

      MusicSequenceSetMIDIEndpoint(sequence, virtualEndpoint);
      NewMusicPlayer(&player);
      MusicPlayerSetSequence(player, sequence);
      MusicPlayerPreroll(player);
      MusicPlayerStart(player);
  }

Patrick J. Collins
http://collinatorstudios.com

 _______________________________________________
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: How to tell which midi track is associated with a packet?
      • From: "Patrick J. Collins" <email@hidden>
  • Prev by Date: Re: Logic build for testing AU?
  • Next by Date: Re: How to tell which midi track is associated with a packet?
  • Previous by thread: Sample rates with AVPlayer using AURemoteIO & AUVoiceProcessingIO
  • Next by thread: Re: How to tell which midi track is associated with a packet?
  • Index(es):
    • Date
    • Thread