传递一个字节组作为方法的一个参数(CoreMIDI实现) [英] passing a bytearray as a parameter of a method (CoreMIDI implementation)

查看:247
本文介绍了传递一个字节组作为方法的一个参数(CoreMIDI实现)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建的MIDI信息输出到使用CoreMIDI虚拟客户机的方法。 动作的方法是MIDIReceived,它发送的MIDI数据中的MIDI数据包的形式的虚拟客户端。

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.

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

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.

这是行不通的。

我测试过这个code,但不尝试使用自定义method--就是手动输入查询MIDI字节的数据,并能正常工作。

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.

我得到的对象消息的错误是预期前pression。

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

我如何传递一个字节数组的方法? (preferably不使用NSData的)?

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

正如你所看到的,我想做的就是创建一个简单的方式传输MIDI数据到一个虚拟源,但我有一些麻烦这样做。

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.

推荐答案

下面是固定的,功能齐全的code。感谢您的帮助!

Here is the 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

这篇关于传递一个字节组作为方法的一个参数(CoreMIDI实现)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆