CoreMidi.framework发送midi命令

发布于 2024-09-30 02:06:52 字数 106 浏览 4 评论 0原文

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

有人可以举个例子吗?

以利亚

there is an app called FreeStyler, that you can control using midi commands. In my mac app I want to send midi signals.

Can someone show an example of this?

Elijah

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠我空喜 2024-10-07 02:06:52

这就是向我的 blofeld 合成器发送一条消息所需要的。我希望它有帮助。您可以使用 MIDIObjectGetProperties 查找连接到 Mac 的所有 MIDI 设备的唯一 ID。

#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;

}

This is what it took to send a note to my blofeld synth. I hope it helps. You can use MIDIObjectGetProperties to find the uniqueIDs for all the midi devices connected to your mac.

#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;

}
极度宠爱 2024-10-07 02:06:52

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

Your application will need to use the CoreMIDI framework to send or receive MIDI, which I can tell you from experience is not a lot of fun to work with directly. You might want to try the vvopensource framework, which is a MIDI framework designed for cocoa.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文