CoreMidi.framework发送midi命令

时间:2010-10-30 12:57:13

标签: objective-c macos midi

有一个名为FreeStyler的应用程序,您可以使用midi命令进行控制。在我的mac应用程序中,我想发送midi信号。

有人可以举例说明这个吗?

利亚

2 个答案:

答案 0 :(得分:3)

这是向我的blofeld合成器发送音符所花费的。我希望它有所帮助。您可以使用MIDIObjectGetProperties查找连接到Mac的所有midi设备的uniqueID。

#import <Foundation/Foundation.h>

#import <CoreMIDI/CoreMIDI.h>

MIDIEndpointRef getEndpointWithUniqueID(MIDIUniqueID id){

    MIDIObjectRef endPoint;

    MIDIObjectType foundObj;

    MIDIObjectFindByUniqueID(id, &endPoint, &foundObj);

    return (MIDIEndpointRef) endPoint;

}

MIDIClientRef getMidiClient(){

    MIDIClientRef midiClient;

    NSString *outPortName =@"blofeldOut";

    MIDIClientCreate((CFStringRef)outPortName, NULL, NULL, &midiClient);

    return midiClient;

}

MIDIPortRef getOutPutPort(){

    MIDIPortRef outPort;

    NSString *outPortName =@"blofeldOut";

    MIDIOutputPortCreate(getMidiClient(), (CFStringRef)outPortName, &outPort);

    return outPort;

}

MIDIPacketList getMidiPacketList(){

    MIDIPacketList packetList;

    packetList.numPackets = 1;

    MIDIPacket* firstPacket = &packetList.packet[0];

    firstPacket->timeStamp = 0; // send immediately

    firstPacket->length = 3;

    firstPacket->data[0] = 0x90;

    firstPacket->data[1] = 60;

    firstPacket->data[2] = 64;

    // TODO: add end note sequence

    return packetList;

}

void play_note(void) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 

    MIDIPacketList packetList=getMidiPacketList();

    MIDIUniqueID blofeldEndpointID = -934632258;

    MIDIEndpointRef blofeldEndpoint = getEndpointWithUniqueID(blofeldEndpointID);

    MIDISend(getOutPutPort(), blofeldEndpoint, &packetList);

    MIDIEndpointDispose(blofeldEndpoint);

    [pool drain];

}

int main (int argc, const char * argv[]) {

    play_note();

    return 0;

}

答案 1 :(得分:1)

您的应用程序需要使用CoreMIDI框架来发送或接收MIDI,我可以从经验告诉您直接使用它并不是很有趣。您可能想尝试vvopensource框架,这是一个为cocoa设计的MIDI框架。