gpt4 book ai didi

ios - CoreMIDI Thru Connection 是如何在 swift 4.2 中创建的?

转载 作者:行者123 更新时间:2023-11-28 07:30:30 25 4
gpt4 key购买 nike

当传递两个有效的 MIDIEndPointRefs 时,以下构建并运行并在末尾打印非错误控制台消息。但是 MIDI 事件并没有像预期的那样从源传递到目标。是不是少了什么?

func createThru2(source:MIDIEndpointRef?, dest:MIDIEndpointRef?)  {

var connectionRef = MIDIThruConnectionRef()
var params = MIDIThruConnectionParams()
MIDIThruConnectionParamsInitialize(&params)

if let s = source {
let thruEnd = MIDIThruConnectionEndpoint(endpointRef: s, uniqueID: MIDIUniqueID(1))
params.sources.0 = thruEnd
params.numSources = 1
print("thru source is \(s)")
}

if let d = dest {
let thruEnd = MIDIThruConnectionEndpoint(endpointRef: d, uniqueID: MIDIUniqueID(2))
params.destinations.0 = thruEnd
params.numDestinations = 1
print("thru dest is \(d)")
}

var localParams = params
let nsdata = withUnsafePointer(to: &params) { p in
NSData(bytes: p, length: MIDIThruConnectionParamsSize(&localParams))
}

let status = MIDIThruConnectionCreate(nil, nsdata, &connectionRef)
if status == noErr {
print("created thru")
} else {
print("error creating thru \(status)")
}
}

最佳答案

您的代码在 macOS 10.13.6 上的 Swift 5 中运行良好。建立直通连接并将 MIDI 事件从源传递到目标。所以问题似乎不是您发布的功能,而是您提供的端点或使用 Swift 4.2 的问题。

我使用了以下代码来调用您的函数:

var source:MIDIEndpointRef = MIDIGetSource(5)
var dest:MIDIEndpointRef = MIDIGetDestination(9)

createThru2(source:source, dest:dest)

5 是 MIDI 键盘,9 是我的音频接口(interface)上的 MIDI 端口。

关于ios - CoreMIDI Thru Connection 是如何在 swift 4.2 中创建的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54871326/

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