Re: How to tell which midi track is associated with a packet?
Re: How to tell which midi track is associated with a packet?
- Subject: Re: How to tell which midi track is associated with a packet?
- From: "Patrick J. Collins" <email@hidden>
- Date: Sat, 14 May 2016 18:30:49 -0700 (PDT)
Sorry, after doing some more digging, I was not aware that "tracks" are
a sequencer software construct and not actually stored in the midi
data.
So I guess I just need to specify a channel on each track and then do
packet->data[0] & 0xf to get the channel number.
Patrick J. Collins
http://collinatorstudios.com
On Sat, 14 May 2016, Patrick J. Collins wrote:
> 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
_______________________________________________
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