gpt4 book ai didi

swift - nsslider.integerValue 要求我在更新值之前专注于另一个应用程序

转载 作者:IT王子 更新时间:2023-10-29 05:31:46 25 4
gpt4 key购买 nike

我的 macOS 应用程序中有一个 NSSlider,名为 wave_mode_slider。我想要做的是更新输入时所述 slider 的值。所以,我所做的是:

self.wave_mode_slider?.integerValue = ("\(params[2])" as NSString).integerValue

这会将 slider (白点)的值设置为预期的输入值。但是,在我看到任何实际结果之前,我必须在应用程序外部单击,这会导致 slider 的白点跳转到它的新值。如此处所示:enter image description here

有没有办法让 slider 立即更新?

我的 slider 是这样创建的:

    self.wave_mode_slider = NSSlider(frame:CGRect(x: 10, y: 100, width: 20, height: 300))
self.wave_mode_slider?.cell = OWOWSliderVertical()
self.wave_mode_slider?.maxValue = 127
self.wave_mode_slider?.target = self
self.view?.addSubview(self.wave_mode_slider!)

我尝试将 slider 的 isContinuous 属性设置为 true,但这并没有改变结果。


编辑:

    var midiClient : MIDIClientRef = 0
var inPort : MIDIPortRef = 0
let observer = UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque())

MIDIClientCreate("WobClient" as CFString, nil, nil, &midiClient)
MIDIInputPortCreate(midiClient, "WobClient_InPort" as CFString, {
(pktList: UnsafePointer<MIDIPacketList>, readProcRefCon: UnsafeMutableRawPointer?, srcConnRefCon: UnsafeMutableRawPointer?) -> Void in
let packetList : MIDIPacketList = pktList.pointee
var packet : MIDIPacket = packetList.packet
let mySelf = Unmanaged<Wob>.fromOpaque(srcConnRefCon!).takeUnretainedValue()
for _ in 1...packetList.numPackets {
let bytes = Mirror(reflecting: packet.data).children
var params : [UInt64] = []

var i = packet.length
for (_, attr) in bytes.enumerated() {
let string = String(format: "%02X ", attr.value as! UInt8)
params.append(UInt64(strtoul(string, nil, 16)))
i -= 1

if (i <= 0) {
break
}
}

// print(("\(params[2])" as NSString).integerValue)
mySelf.setWaveSliderValue(value: ("\(params[2])" as NSString).integerValue)
packet = MIDIPacketNext(&packet).pointee
}

}, nil, &inPort)

MIDIPortConnectSource(inPort, self.source, observer)

这是我获得值(value)的地方

最佳答案

最后很简单,一看到Willeke关于线程的评论,我就用主线程设置值:

DispatchQueue.main.async {
mySelf.wave_mode_slider?.floatValue = ("\(params[2])" as NSString).floatValue
}

关于swift - nsslider.integerValue 要求我在更新值之前专注于另一个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43719570/

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