SHMultiSlider is written in Swift 4.2, so your code has to be written in Swift 4.x due to current binary compatibility limitations.
To use CocoaPods add SHMIDIKit to your Podfile
:
pod 'SHMultiSlider'
Then run pod install
.
use_frameworks!
import SHMultiSlider
class ViewController: NSViewController, SHMultiSliderDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let multislider = SHMultiSlider(frame: NSRect(x: 0, y: 0, width: 100, height: 100))
self.view.addSubview(slider)
// IMPORTANT! Set delegate to self, otherwise you won't get any callback
multislider.delegate = self
// Set slider value
multislider.setValue(100)
// Change the text for the label on top
multislider.sourceName = "LFO"
// Change the text for the label on bottom
multislider.targetName = "Pan"
// Set lowerbound of output value, output will be remapped to new range
multislider.slider.setLowerBoundValue(0)
// Set upperbound of output value, output will be remapped to new range
multislider.setUpperBoundValue(100)
// Set input value range
multislider.min = 0
multislider.max = 100
/// Implement delegate methods
// value change callback
func valueChanged(_ sender: SHMultiSlider?, _ newValue: Int) {
print(sender?.identifier, newValue)
}
// boundsChangeCallback
func boundsUpdated(_ sender: SHMultiSlider?, lower: Int, upper: Int) {
print((lower, upper))
}
}
}