AKMIDICallbackInstrument实施问题 [英] AKMIDICallbackInstrument implementation issue

查看:122
本文介绍了AKMIDICallbackInstrument实施问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新到AudioKit的最新版本后,我将几个AKCallbackInstrument实例更改为新的AKMIDICallbackInstrument类,该类现在将前者合并为旧行为.但是,这样做的时候,我遇到了这个奇怪的错误.也许我想念斯威夫特的细微差别?

Updating to the latest version of AudioKit left me changing several AKCallbackInstrument instances over to the new AKMIDICallbackInstrument class which now incorporates the former as legacy behavior. When doing so however, I ran into this weird error. Maybe a Swift nuance I am missing?

let callback = AKMIDICallbackInstrument() { status, note, velocity in
    if status == .noteOn {  //errors out
       // do something
    }
}

状态 .noteOn 错误进行比较: 表达类型'Bool'在没有更多上下文的情况下是模棱两可的.".这是有道理的,因为AKMIDICallbackInstrument不再返回状态为AKMIDIStatus的状态,而是直接返回了MIDIByte(UInt8)的状态.使用直接MIDI命令数字即可.

Comparing status to .noteOn errors out with: "Expression type 'Bool' is ambiguous without more context.". Makes sense, because AKMIDICallbackInstrument is not returning an AKMIDIStatus in status anymore, but a straight MIDIByte (UInt8). Using direct MIDI command numerics works.

let callback = AKMIDICallbackInstrument() { status, note, velocity in
    if status == 0x90 {
       // do something
    }
}

因此,我们有一个问题和一个可能的解决方案.我只是不确定这是否可行,AKMIDICallbackInstrument尚未发布文档.

So we have a problem and a potential solution. I'm just not sure that this is the way to go and AKMIDICallbackInstrument didn't hit the docs yet.

推荐答案

目前,您可以像这样将MIDIByte转换为AKMIDIStatus:

For the time being, you can convert the MIDIByte to AKMIDIStatus like this:

let status = AKMIDIStatus(rawValue: Int(statusByte >> 4))

在develop分支上,有一个用于AKMIDIStatus的新初始化程序,该初始化程序直接将MIDIByte作为参数使它变得更简单.

On the develop branch, there is a new initializer for AKMIDIStatus that directly takes MIDIByte as a parameter to make this a little easier.

这篇关于AKMIDICallbackInstrument实施问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆