1

我正在尝试创建一种使用 CoreMIDI 将 MIDI 信息输出到虚拟客户端的方法。“动作”方法是 MIDIReceived,它将 MIDI 数据以 MIDI 数据包的形式发送到虚拟客户端。

下面,我创建了一个接受 MIDI 字节作为参数的方法,该方法应将其添加到 MIDI 数据包列表中,然后使用 MIDIReceived 将其发送到虚拟客户端。

它不起作用。

我已经测试了这段代码,但没有尝试使用自定义方法——即手动输入 midi 字节数据,它工作正常。

我相信我遇到的问题是我无法正确地将字节数组传递给该方法。

我得到的对象消息的错误是“预期的表达式”。

如何将字节数组传递给方法?(最好不使用 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

如您所见,我想做的只是创建一种将 MIDI 数据传输到虚拟源的简单方法,但这样做时遇到了一些麻烦。

4

1 回答 1

1

这是固定的,功能齐全的代码。谢谢您的帮助!

#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
于 2013-04-26T14:36:59.013 回答