-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.swift
More file actions
104 lines (104 loc) · 2.82 KB
/
View.swift
File metadata and controls
104 lines (104 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// View.swift
// mc.auv3_tilde
//
// Created by Kota on 7/25/R7.
//
import SwiftUI
import CoreAudioKit
struct View: SwiftUI.View {
weak var core: Optional<Core>
@State var select: AudioComponentDescription = .init()
var components: Array<AVAudioUnitComponent> {
Core.manager.components(matching: select)
}
var types: Array<AudioComponentComponent> {
[.init(id: 0, description: "ANY")] + Set(components.map {
.init(id: $0.audioComponentDescription.componentType, description: $0.typeName)
}).sorted(using: KeyPathComparator(\.description))
}
var manufacturers: Array<AudioComponentComponent> {
[.init(id: 0, description: "ANY")] + Set(components.map {
.init(id: $0.audioComponentDescription.componentManufacturer, description: $0.manufacturerName)
}).sorted(using: KeyPathComparator(\.description))
}
var body: some SwiftUI.View {
VStack {
HStack {
Picker("Type", selection: $select.componentType) {
ForEach(types, id: \.id) {
Text($0.description)
}
}
.pickerStyle(.menu)
Picker("Manufacturer", selection: $select.componentManufacturer) {
ForEach(manufacturers, id: \.id) {
Text($0.description)
}
}
.pickerStyle(.menu)
}
List {
ForEach(components) { component in
Button(component.name, systemImage: "waveform.circle") {
if case.some(let core) = core {
core.load(description: component.audioComponentDescription)
}
}
}
}
}.padding(.all)
}
}
struct UnitView: SwiftUI.View {
weak var core: Optional<Core>
@ObservedObject var unit: AUAudioUnit
var factoryPreset: Binding<Int> {
.init {
unit.currentPreset.map(\.number) ?? 0
} set: {
core?.preset(factory: $0)
}
}
var userPreset: Binding<Int> {
.init {
unit.currentPreset.map(\.number) ?? 0
} set: {
core?.preset(load: $0)
}
}
var body: some SwiftUI.View {
Group {
if let factoryPreset = unit.factoryPresets {
Picker("Factory Preset", selection: self.factoryPreset) {
ForEach(factoryPreset, id: \.number) {
Text($0.name)
}
}.pickerStyle(.automatic)
.padding(.all)
}
if unit.supportsUserPresets {
Picker("User Preset", selection: self.userPreset) {
ForEach(unit.userPresets, id: \.number) {
Text($0.name)
}
}.pickerStyle(.automatic)
.padding(.all)
}
if let parameterTree = unit.parameterTree {
ScrollView {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 150), spacing: 20)],
alignment: .center,
spacing: 30) {
ForEach(parameterTree.allParameters, id: \.address, content: AquaKnobView.init(parameter:))
}.padding()
}
}
}.background(Rectangle()
.fill(LinearGradient(gradient: Gradient(colors: [.aquaPanelBrushedMetalStart, .aquaPanelBrushedMetalEnd]),
startPoint: .top,
endPoint: .bottom))
.edgesIgnoringSafeArea(.all)
)
}
}