gpt4 book ai didi

cocoa - 核心 MIDI : when I send a MIDIPacketList using MIDISend() only the first packet is being sent

转载 作者:行者123 更新时间:2023-12-03 16:54:41 28 4
gpt4 key购买 nike

我正在尝试发送包含两个数据包的 MIDIPacketList,这两个数据包描述与 x-y 样式 Controller 相关的 Controller 位置更改消息。

我尝试实现的功能采用 x 和 y 位置,然后创建数据包并将它们发送到选定的目标设备,如下所示:

- (void)matrixCtrlSetPosX:(int)posX PosY:()posY {

MIDIPacketList packetList;
packetList.numPackets = 2;

packetList.packet[0].length = 3;
packetList.packet[0].data[0] = 0xB0; // status: controller change
packetList.packet[0].data[1] = 0x32; // controller number 50
packetList.packet[0].data[2] = (Byte)posX; // value (x position)
packetList.packet[0].timeStamp = 0;

packetList.packet[1].length = 3;
packetList.packet[1].data[0] = 0xB0; // status: controller change
packetList.packet[1].data[1] = 0x33; // controller number 51
packetList.packet[1].data[2] = (Byte)posY; // value (y position)
packetList.packet[1].timeStamp = 0;

CheckError(MIDISend(_outputPort, _destinationEndpoint, &packetList), "Couldn't send MIDI packet list");
}

我遇到的问题是该程序似乎只发送第一个数据包。

我尝试将输出拆分为两个单独的 MIDIPacketList,并两次调用 MIDISend(),这确实有效,但我确信在构建 MIDI 数据包列表时一定有一些琐碎的事情我错过了,以便一次调用 MIDISend() 可以发送两条消息。我似乎无法弄清楚问题出在哪里!这里的任何人都有这样做的经验,还是我完全以错误的方式处理这件事?

最佳答案

仅声明 MIDIPacketList 不会分配内存或设置结构。有一个将数据包添加到列表中的过程。这是一个快速但肮脏的例子:

- (void)matrixCtrlSetPosX:(int)posX PosY:(int)posY {
MIDITimeStamp timestamp = 0;
const ByteCount MESSAGELENGTH = 6;
Byte buffer[1024]; // storage space for MIDI Packets
MIDIPacketList *packetlist = (MIDIPacketList*)buffer;
MIDIPacket *currentpacket = MIDIPacketListInit(packetlist);
Byte msgs[MESSAGELENGTH] = {0xB0, 0x32, (Byte)posX, 0xB0, 0x33, (Byte)posY};
currentpacket = MIDIPacketListAdd(packetlist, sizeof(buffer),
currentpacket, timestamp, MESSAGELENGTH, msgs);

CheckError(MIDISend(_outputPort, _destinationEndpoint, packetlist), "Couldn't send MIDI packet list");
}

我从 testout.c 中改编了这段代码,发现 here

关于cocoa - 核心 MIDI : when I send a MIDIPacketList using MIDISend() only the first packet is being sent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15283406/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com