Skip to content

Commit

Permalink
Views for demos
Browse files Browse the repository at this point in the history
  • Loading branch information
aure committed Sep 11, 2022
1 parent 6edc7b3 commit e2d814f
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 267 deletions.
9 changes: 6 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import PackageDescription

let package = Package(
name: "AudioKitUI",
platforms: [.macOS(.v12), .iOS(.v14)],
platforms: [.macOS(.v12), .iOS(.v15)],
products: [.library(name: "AudioKitUI", targets: ["AudioKitUI"])],
dependencies: [.package(url: "https://github.com/AudioKit/AudioKit.git", from: "5.3.0")],
dependencies: [
.package(url: "https://github.com/AudioKit/AudioKit.git", from: "5.3.0"),
.package(url: "https://github.com/AudioKit/Controls.git", from: "1.1.0"),
],
targets: [
.target(name: "AudioKitUI", dependencies: ["AudioKit"], resources: [.process("Resources")]),
.target(name: "AudioKitUI", dependencies: ["AudioKit", "Controls"], resources: [.process("Resources")]),
.testTarget(name: "AudioKitUITests", dependencies: ["AudioKitUI"]),
]
)
18 changes: 18 additions & 0 deletions Sources/AudioKitUI/Controls/ADSRWidget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import AudioKit
import AVFoundation
import SwiftUI

struct ADSRWidget: UIViewRepresentable {
typealias UIViewType = ADSRView
var callback: (AUValue, AUValue, AUValue, AUValue) -> Void

func makeUIView(context _: Context) -> ADSRView {
let view = ADSRView(callback: callback)
view.bgColor = .systemBackground
return view
}

func updateUIView(_: ADSRView, context _: Context) {
//
}
}
261 changes: 0 additions & 261 deletions Sources/AudioKitUI/Controls/MultitouchGestureRecognizer.swift

This file was deleted.

76 changes: 76 additions & 0 deletions Sources/AudioKitUI/Controls/ParameterEditor2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright AudioKit. All Rights Reserved. Revision History at http://github.com/AudioKit/AudioKitUI/

import AudioKit
import Controls
import SwiftUI
import CoreMIDI

/// Hack to get SwiftUI to poll and refresh our UI.
class Refresher: ObservableObject {
@Published var version = 0
}

public struct ParameterEditor2: View {
var param: NodeParameter
@StateObject var refresher = Refresher()

public init(param: NodeParameter) {
self.param = param
}

func floatToDoubleRange(_ floatRange: ClosedRange<Float>) -> ClosedRange<Double> {
Double(floatRange.lowerBound) ... Double(floatRange.upperBound)
}

func getBinding() -> Binding<Float> {
Binding(
get: { param.value },
set: { param.value = $0; refresher.version += 1}
)
}

func getIntBinding() -> Binding<Int> {
Binding(get: { Int(param.value) }, set: { param.value = AUValue($0); refresher.version += 1 })
}

func intValues() -> [Int] {
Array(Int(param.range.lowerBound) ... Int(param.range.upperBound))
}
var format: String {
if (param.range.upperBound - param.range.lowerBound) > 20 {
return "%0.0f"
} else {
return "%0.2f"
}
}

public var body: some View {
VStack(alignment: .center) {
Text(param.def.name).font(.title2)
Text("\(String(format: format, param.value))")

switch param.def.unit {
case .boolean:
Toggle(isOn: Binding(get: { param.value == 1.0 }, set: {
param.value = $0 ? 1.0 : 0.0; refresher.version += 1
}), label: { Text(param.def.name) })
case .indexed:
if param.range.upperBound - param.range.lowerBound < 5 {
Picker(param.def.name, selection: getIntBinding()) {
ForEach(intValues(), id: \.self) { value in
Text("\(value)").tag(value)
}
}
.pickerStyle(.segmented)
} else {
SmallKnob(value: getBinding(), range: param.range)
.frame(maxHeight: 200)

}
default:
SmallKnob(value: getBinding(), range: param.range)
.frame(maxHeight: 200)
}
}
}
}
Loading

0 comments on commit e2d814f

Please sign in to comment.