From fb785563b8574aee0b5b0babc3ca96e6f289c5a9 Mon Sep 17 00:00:00 2001 From: mahal raskin Date: Thu, 10 Oct 2024 10:35:47 +0200 Subject: [PATCH 1/9] Easier to debug as parameters of Sampler are only called once --- .../CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift index df6805ac..70d2796f 100644 --- a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift +++ b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift @@ -37,24 +37,25 @@ struct InstrumentSFZView: View { @Environment(\.colorScheme) var colorScheme var body: some View { + let instrumentParams = conductor.instrument.parameters HStack { ForEach(0...7, id: \.self) { - ParameterRow(param: conductor.instrument.parameters[$0]) + ParameterRow(param: instrumentParams[$0]) } }.padding(5) HStack { ForEach(8...15, id: \.self) { - ParameterRow(param: conductor.instrument.parameters[$0]) + ParameterRow(param: instrumentParams[$0]) } }.padding(5) HStack { ForEach(16...23, id: \.self) { - ParameterRow(param: conductor.instrument.parameters[$0]) + ParameterRow(param: instrumentParams[$0]) } }.padding(5) HStack { ForEach(24...30, id: \.self) { - ParameterRow(param: conductor.instrument.parameters[$0]) + ParameterRow(param: instrumentParams[$0]) } }.padding(5) CookbookKeyboard(noteOn: conductor.noteOn, From e1656c4c6b229045c23290b5e41159d08de0366b Mon Sep 17 00:00:00 2001 From: mahal raskin Date: Thu, 10 Oct 2024 10:53:35 +0200 Subject: [PATCH 2/9] Boolean Parameter no longer shows Label twice on Landscape or iPad screens --- .../CookbookCommon/Reusable Components/ParameterRow.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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()) { From c2309a2ad55f6d8dec3a56b2c644c68d094a40ea Mon Sep 17 00:00:00 2001 From: mahal raskin Date: Thu, 10 Oct 2024 10:54:47 +0200 Subject: [PATCH 3/9] Sort instrument parameter alphabetically and wrap in ScrollView --- .../Recipes/MiniApps/InstrumentSFZ.swift | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift index 70d2796f..54641a76 100644 --- a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift +++ b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift @@ -38,26 +38,29 @@ struct InstrumentSFZView: View { var body: some View { let instrumentParams = conductor.instrument.parameters - HStack { - ForEach(0...7, id: \.self) { - ParameterRow(param: instrumentParams[$0]) - } - }.padding(5) - HStack { - ForEach(8...15, id: \.self) { - ParameterRow(param: instrumentParams[$0]) - } - }.padding(5) - HStack { - ForEach(16...23, id: \.self) { - ParameterRow(param: instrumentParams[$0]) - } - }.padding(5) - HStack { - ForEach(24...30, id: \.self) { - ParameterRow(param: instrumentParams[$0]) - } - }.padding(5) + let instrumentParamsSorted = instrumentParams.sorted(by: {$0.def.name < $1.def.name} ) + ScrollView { + HStack { + ForEach(0...7, id: \.self) { + ParameterRow(param: instrumentParamsSorted[$0]) + } + }.padding(5) + HStack { + ForEach(8...15, id: \.self) { + ParameterRow(param: instrumentParamsSorted[$0]) + } + }.padding(5) + HStack { + ForEach(16...23, id: \.self) { + ParameterRow(param: instrumentParamsSorted[$0]) + } + }.padding(5) + HStack { + ForEach(24...30, id: \.self) { + ParameterRow(param: instrumentParamsSorted[$0]) + } + }.padding(5) + } CookbookKeyboard(noteOn: conductor.noteOn, noteOff: conductor.noteOff) .cookbookNavBarTitle("Instrument SFZ") From cc4db3fd4c6170bb24f7aa55f9c042b5cf300734 Mon Sep 17 00:00:00 2001 From: mahal raskin Date: Thu, 10 Oct 2024 13:21:09 +0200 Subject: [PATCH 4/9] Adjusted keyboard height --- .../Recipes/MiniApps/InstrumentSFZ.swift | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift index 54641a76..4031d0bc 100644 --- a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift +++ b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift @@ -39,30 +39,34 @@ struct InstrumentSFZView: View { var body: some View { let instrumentParams = conductor.instrument.parameters let instrumentParamsSorted = instrumentParams.sorted(by: {$0.def.name < $1.def.name} ) - ScrollView { - HStack { - ForEach(0...7, id: \.self) { - ParameterRow(param: instrumentParamsSorted[$0]) + GeometryReader { geoProxy in + VStack { + ScrollView { + HStack { + ForEach(0...7, id: \.self) { + ParameterRow(param: instrumentParamsSorted[$0]) + } + }.padding(5) + HStack { + ForEach(8...15, id: \.self) { + ParameterRow(param: instrumentParamsSorted[$0]) + } + }.padding(5) + HStack { + ForEach(16...23, id: \.self) { + ParameterRow(param: instrumentParamsSorted[$0]) + } + }.padding(5) + HStack { + ForEach(24...30, id: \.self) { + ParameterRow(param: instrumentParamsSorted[$0]) + } + }.padding(5) } - }.padding(5) - HStack { - ForEach(8...15, id: \.self) { - ParameterRow(param: instrumentParamsSorted[$0]) - } - }.padding(5) - HStack { - ForEach(16...23, id: \.self) { - ParameterRow(param: instrumentParamsSorted[$0]) - } - }.padding(5) - HStack { - ForEach(24...30, id: \.self) { - ParameterRow(param: instrumentParamsSorted[$0]) - } - }.padding(5) + CookbookKeyboard(noteOn: conductor.noteOn, + noteOff: conductor.noteOff).frame(height: geoProxy.size.height / 4) + } } - CookbookKeyboard(noteOn: conductor.noteOn, - noteOff: conductor.noteOff) .cookbookNavBarTitle("Instrument SFZ") .onAppear { conductor.start() From 59f2ab48bd1987581e8f93d185e52280b9d80e54 Mon Sep 17 00:00:00 2001 From: mahal raskin Date: Thu, 10 Oct 2024 14:11:42 +0200 Subject: [PATCH 5/9] Make some more room by showing only five instead of eight params in each row. Show all of them and not only the first 30. --- .../Recipes/MiniApps/InstrumentSFZ.swift | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift index 4031d0bc..831b5741 100644 --- a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift +++ b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift @@ -39,29 +39,17 @@ struct InstrumentSFZView: View { var body: some View { let instrumentParams = conductor.instrument.parameters let instrumentParamsSorted = instrumentParams.sorted(by: {$0.def.name < $1.def.name} ) + let instrumentParamsChunked = instrumentParamsSorted.chunked(into: 6) GeometryReader { geoProxy in VStack { ScrollView { - HStack { - ForEach(0...7, id: \.self) { - ParameterRow(param: instrumentParamsSorted[$0]) - } - }.padding(5) - HStack { - ForEach(8...15, id: \.self) { - ParameterRow(param: instrumentParamsSorted[$0]) - } - }.padding(5) - HStack { - ForEach(16...23, id: \.self) { - ParameterRow(param: instrumentParamsSorted[$0]) - } - }.padding(5) - HStack { - ForEach(24...30, id: \.self) { - ParameterRow(param: instrumentParamsSorted[$0]) - } - }.padding(5) + 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 + } +} + From 25e9647acb1976326d58c66ed256f4aca51c309c Mon Sep 17 00:00:00 2001 From: mahal raskin Date: Thu, 10 Oct 2024 14:21:16 +0200 Subject: [PATCH 6/9] Add more params in iPad size --- .../CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift index 831b5741..fc6604de 100644 --- a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift +++ b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift @@ -35,11 +35,14 @@ class InstrumentSFZConductor: ObservableObject, HasAudioEngine { struct InstrumentSFZView: View { @StateObject var conductor = InstrumentSFZConductor() @Environment(\.colorScheme) var colorScheme + @Environment(\.horizontalSizeClass) var horizontalSizeClass var body: some View { let instrumentParams = conductor.instrument.parameters let instrumentParamsSorted = instrumentParams.sorted(by: {$0.def.name < $1.def.name} ) - let instrumentParamsChunked = instrumentParamsSorted.chunked(into: 6) + let paramsPerLine = horizontalSizeClass == .compact ? 6 : 8 + let instrumentParamsChunked = instrumentParamsSorted.chunked(into: paramsPerLine) + GeometryReader { geoProxy in VStack { ScrollView { From 5c6a859d58c1faa73d05906a65739fe72b0b0e90 Mon Sep 17 00:00:00 2001 From: mahal raskin Date: Thu, 10 Oct 2024 17:14:19 +0200 Subject: [PATCH 7/9] Improved layout so it doesn't need a scroll view when enough space is available. --- .../Recipes/MiniApps/InstrumentSFZ.swift | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift index fc6604de..2c69bd36 100644 --- a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift +++ b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift @@ -45,17 +45,23 @@ struct InstrumentSFZView: View { GeometryReader { geoProxy in VStack { - ScrollView { - ForEach(0.. Date: Thu, 10 Oct 2024 17:15:27 +0200 Subject: [PATCH 8/9] no longer sort instrument parameters but show them in their intrinsic order --- .../CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift index 2c69bd36..b9a90459 100644 --- a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift +++ b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift @@ -39,9 +39,8 @@ struct InstrumentSFZView: View { var body: some View { let instrumentParams = conductor.instrument.parameters - let instrumentParamsSorted = instrumentParams.sorted(by: {$0.def.name < $1.def.name} ) let paramsPerLine = horizontalSizeClass == .compact ? 6 : 8 - let instrumentParamsChunked = instrumentParamsSorted.chunked(into: paramsPerLine) + let instrumentParamsChunked = instrumentParams.chunked(into: paramsPerLine) GeometryReader { geoProxy in VStack { From ca7d7a4a94a73b61deffb931625e29f1f261353d Mon Sep 17 00:00:00 2001 From: mahal raskin Date: Thu, 10 Oct 2024 17:21:02 +0200 Subject: [PATCH 9/9] Fixed linter warnings to chill the Hound --- .../Recipes/MiniApps/InstrumentSFZ.swift | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift index b9a90459..81b9feb8 100644 --- a/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift +++ b/Cookbook/CookbookCommon/Sources/CookbookCommon/Recipes/MiniApps/InstrumentSFZ.swift @@ -41,10 +41,10 @@ struct InstrumentSFZView: View { 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.. Bool { + 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 } } -