I'm trying to create a method that outputs MIDI information to a virtual client using CoreMIDI. The "action" method is MIDIReceived, which sends midi data in the form of MIDI packets to a virtual client.
Below, I've created a method that accepts a MIDI byte as a parameter, which the method should add to a MIDI Packet List which is then sent to a virtual client with MIDIReceived.
It doesn't work.
I've tested this code without trying to use a custom method-- that is, manually inputing midi byte data, and it works fine.
The problem I have, I believe, is that I'm not able to properly pass a byte array to the method.
The error I get for the object message is "expected expression".
How can I pass a byte array to a method? (preferably without using NSData)?
#import "AppDelegate.h"
#import <CoreMIDI/CoreMIDI.h>
MIDIClientRef theMidiClient;
MIDIEndpointRef midiOut;
char pktBuffer[1024];
MIDIPacketList *pktList = (MIDIPacketList*) pktBuffer;
MIDIPacket *pkt;
@interface PacketCreateAndSend : NSObject
-(void) packetOut:(Byte*)midiByte;
@end
@implementation PacketCreateAndSend
-(void) packetOut:(Byte*)midiByte{
Byte testByte = *midiByte;
//initialize MIDI packet list:
pkt = MIDIPacketListInit(pktList);
//add packet to MIDI packet list
pkt = MIDIPacketListAdd(pktList, 1024, pkt, 0, 3, &testByte);
//send packet list to virtual client:
MIDIReceived(midiOut, pktList);
}
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
//create MIDI client and source:
MIDIClientCreate(CFSTR("Magical MIDI"), NULL, NULL, &theMidiClient);
MIDISourceCreate(theMidiClient, CFSTR("virtual MIDI created"), &midiOut);
//create instance of PacketCreateAndSend object:
PacketCreateAndSend *testObject = [PacketCreateAndSend new];
//(here is where the error occurs)
//message object with MIDI byte data:
[testObject packetOut:{0x90, 0x3d, 0x3d}];
}
@end
As you can see, all I want to do is create a simple way to transmit MIDI data to a virtual source, but am having some trouble doing so.
Here is the fixed, fully functional code. Thanks for the help!