diff --git a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift index df6805ac..81b9feb8 100644 --- a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift +++ b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift @@ -35,30 +35,34 @@ class InstrumentSFZConductor: ObservableObject, HasAudioEngine { struct InstrumentSFZView: View { @StateObject var conductor = InstrumentSFZConductor() @Environment(\.colorScheme) var colorScheme + @Environment(\.horizontalSizeClass) var horizontalSizeClass var body: some View { - HStack { - ForEach(0...7, id: \.self) { - ParameterRow(param: conductor.instrument.parameters[$0]) - } - }.padding(5) - HStack { - ForEach(8...15, id: \.self) { - ParameterRow(param: conductor.instrument.parameters[$0]) - } - }.padding(5) - HStack { - ForEach(16...23, id: \.self) { - ParameterRow(param: conductor.instrument.parameters[$0]) - } - }.padding(5) - HStack { - ForEach(24...30, id: \.self) { - ParameterRow(param: conductor.instrument.parameters[$0]) + let instrumentParams = conductor.instrument.parameters + let paramsPerLine = horizontalSizeClass == .compact ? 6 : 8 + let instrumentParamsChunked = instrumentParams.chunked(into: paramsPerLine) + + GeometryReader { geoProxy in + VStack { + let paramRows = ForEach(0.. [[Element]] { + return stride(from: 0, to: count, by: size).map { + Array(self[$0 ..< Swift.min($0 + size, count)]) + } + } +} + +extension NodeParameter: Hashable { + public func hash(into hasher: inout Hasher) { + hasher.combine(def.identifier) + } +} + +extension NodeParameter: Equatable { + public static func == (lhs: NodeParameter, rhs: NodeParameter) -> Bool { + // NodeParameter wraps AUParameter which should + // conform to equtable as they are NSObjects + return lhs.parameter == rhs.parameter + } +} diff --git a/Cookbook/CookbookCommon/Sources/CookbookCommon/Reusable Components/ParameterRow.swift b/Cookbook/CookbookCommon/Sources/CookbookCommon/Reusable Components/ParameterRow.swift index d6870f6a..48026fac 100644 --- a/Cookbook/CookbookCommon/Sources/CookbookCommon/Reusable Components/ParameterRow.swift +++ b/Cookbook/CookbookCommon/Sources/CookbookCommon/Reusable Components/ParameterRow.swift @@ -56,9 +56,9 @@ public struct ParameterRow: View { .frame(height: 50) switch param.def.unit { case .boolean: - Toggle(isOn: Binding(get: { param.value == 1.0 }, set: { + 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()) {