Passing bytearray as a method parameter (CoreMIDI implementation)

I am trying to create a method that outputs MIDI information to a virtual client using CoreMIDI. The β€œaction” method is MIDIReceived, which transmits MIDI data in the form of MIDI packets to a virtual client.

Below, I created a method that takes MIDI bytes as a parameter that the method should add to the list of MIDI packets, which is then sent to the virtual client with MIDIReceived.

This does not work.

I tested this code without trying to use my own method, that is, manually entering data in mini-bytes, and it works fine.

The problem, I suppose, is that I cannot correctly pass an array of bytes to the method.

The error I get for the object message is the "expected expression".

How to pass an array of bytes 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 an easy way to transfer MIDI data to a virtual source, but I have some problems with this.

+1
source share
1 answer

Here is a fixed, fully functional code. Thanks for the help!

 #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{ pkt = MIDIPacketListInit(pktList); pkt = MIDIPacketListAdd(pktList, 1024, pkt, 0, 3, midiByte); MIDIReceived(midiOut, pktList); } @end @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { //initialize MIDI client and source: MIDIClientCreate(CFSTR("Magical MIDI"), NULL, NULL, &theMidiClient); MIDISourceCreate(theMidiClient, CFSTR("virtual MIDI created"), &midiOut); PacketCreateAndSend *testObject = [PacketCreateAndSend new]; Byte byteArray[] = {0x90, 0x3d, 0x3d}; //send the midi packet: [testObject packetOut:byteArray]; } @end 
+1
source

Source: https://habr.com/ru/post/1205220/


All Articles