gpt4 book ai didi

swift - 使用 CoreMIDI 发送系统独有消息

转载 作者:搜寻专家 更新时间:2023-10-31 22:27:28 24 4
gpt4 key购买 nike

我正在开发一个使用 MIDI 的 MacOS 应用程序。我想做的是将 SysEx 消息发送到 MIDI 设备。现在,我在 Java 中做过一次,但从未在 Swift 中做过。

因为 coremidi 库对我来说几乎是全新的,所以我不知道它是如何工作的。到目前为止,我发现我必须编写一个 MIDISysexSendRequest,我已经走到这一步了:

let SysEx = MIDISysexSendRequest(destination: self.endpointRef, data: UnsafePointer<UInt8>, bytesToSend: 8, complete: complete, reserved: (UInt8, UInt8, UInt8), completionProc: completionProc, completionRefCon: nil)

在这方面,有几件事让我感到困惑:

  • 我应该以什么方式组成data 变量?我知道我想发送什么字节,只是不知道如何为 Swift 格式化它
  • reserved 应该是什么?

我找不到任何我可以使用的示例或引用。有人可以帮助我/

提前致谢。

最佳答案

Reserved 表示您不能使用它,如:“reserved for internal use”

struct MIDISysexSendRequest
{
MIDIEndpointRef destination;
const Byte * data;
UInt32 bytesToSend;
Boolean complete;
Byte reserved[3];
MIDICompletionProc completionProc;
void * __nullable completionRefCon;
};

/*!
@struct MIDISysexSendRequest
@abstract A request to transmit a system-exclusive event.

@field destination
The endpoint to which the event is to be sent.
@field data
Initially, a pointer to the sys-ex event to be sent.
MIDISendSysex will advance this pointer as bytes are
sent.
@field bytesToSend
Initially, the number of bytes to be sent. MIDISendSysex
will decrement this counter as bytes are sent.
@field complete
The client may set this to true at any time to abort
transmission. The implementation sets this to true when
all bytes have been sent.
@field completionProc
Called when all bytes have been sent, or after the client
has set complete to true.
@field completionRefCon
Passed as a refCon to completionProc.

@discussion
This represents a request to send a single system-exclusive MIDI event to
a MIDI destination asynchronously.
*/

注意保留变量甚至没有出现在 header 中。

快速谷歌显示了许多使用 MIDI 的 swift 编写的项目。浏览其中一些以查看工作示例。

我看到的第一个似乎非常适合了解事情是如何完成的。它甚至有很多 .java 文件,因此您可能更容易了解它与 swift 的关系(或如何连接它们)。

看这里:MIDI in Swift

在 CoreMIDI 框架中有一个名为“MIDIServices.h”的文件(finder 会为您找到它)。它有很多关于 MIDI 的信息。

祝你好运!! 🍀

关于swift - 使用 CoreMIDI 发送系统独有消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44410914/

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