From e17ccfd815c2b470fdd9ffde917313cf97d8502f Mon Sep 17 00:00:00 2001 From: NickCulbertson Date: Mon, 7 Apr 2025 11:53:34 -0400 Subject: [PATCH 1/3] Update KeyContainer.swift --- Sources/Keyboard/KeyContainer.swift | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Sources/Keyboard/KeyContainer.swift b/Sources/Keyboard/KeyContainer.swift index 6094ec0..0f280f3 100644 --- a/Sources/Keyboard/KeyContainer.swift +++ b/Sources/Keyboard/KeyContainer.swift @@ -32,16 +32,7 @@ public struct KeyContainer: View { func rect(rect: CGRect) -> some View { content(pitch, model.touchedPitches.contains(pitch) || model.externallyActivatedPitches.contains(pitch)) - .contentShape(Rectangle()) // Added to improve tap/click reliability - .gesture( - TapGesture().onEnded { _ in - if model.externallyActivatedPitches.contains(pitch) { - model.externallyActivatedPitches.remove(pitch) - } else { - model.externallyActivatedPitches.add(pitch) - } - } - ) + .contentShape(Rectangle()) .preference(key: KeyRectsKey.self, value: [KeyRectInfo(rect: rect, pitch: pitch, From d0e7a0857c78af9d2e8bd2c56a9e7a20724c85a0 Mon Sep 17 00:00:00 2001 From: NickCulbertson Date: Mon, 7 Apr 2025 19:16:41 -0400 Subject: [PATCH 2/3] Revert "Update KeyContainer.swift" This reverts commit e17ccfd815c2b470fdd9ffde917313cf97d8502f. --- Sources/Keyboard/KeyContainer.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/Keyboard/KeyContainer.swift b/Sources/Keyboard/KeyContainer.swift index 0f280f3..6094ec0 100644 --- a/Sources/Keyboard/KeyContainer.swift +++ b/Sources/Keyboard/KeyContainer.swift @@ -32,7 +32,16 @@ public struct KeyContainer: View { func rect(rect: CGRect) -> some View { content(pitch, model.touchedPitches.contains(pitch) || model.externallyActivatedPitches.contains(pitch)) - .contentShape(Rectangle()) + .contentShape(Rectangle()) // Added to improve tap/click reliability + .gesture( + TapGesture().onEnded { _ in + if model.externallyActivatedPitches.contains(pitch) { + model.externallyActivatedPitches.remove(pitch) + } else { + model.externallyActivatedPitches.add(pitch) + } + } + ) .preference(key: KeyRectsKey.self, value: [KeyRectInfo(rect: rect, pitch: pitch, From 879f8af675061fc323b3fa8ec250b44a51b2abd0 Mon Sep 17 00:00:00 2001 From: NickCulbertson Date: Mon, 7 Apr 2025 19:21:57 -0400 Subject: [PATCH 3/3] Latching Toggle --- Sources/Keyboard/KeyContainer.swift | 12 +++++++----- Sources/Keyboard/Keyboard.swift | 1 + Sources/Keyboard/KeyboardModel.swift | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/Keyboard/KeyContainer.swift b/Sources/Keyboard/KeyContainer.swift index 6094ec0..30f453b 100644 --- a/Sources/Keyboard/KeyContainer.swift +++ b/Sources/Keyboard/KeyContainer.swift @@ -32,13 +32,15 @@ public struct KeyContainer: View { func rect(rect: CGRect) -> some View { content(pitch, model.touchedPitches.contains(pitch) || model.externallyActivatedPitches.contains(pitch)) - .contentShape(Rectangle()) // Added to improve tap/click reliability + .contentShape(Rectangle()) .gesture( TapGesture().onEnded { _ in - if model.externallyActivatedPitches.contains(pitch) { - model.externallyActivatedPitches.remove(pitch) - } else { - model.externallyActivatedPitches.add(pitch) + if model.latching { + if model.externallyActivatedPitches.contains(pitch) { + model.externallyActivatedPitches.remove(pitch) + } else { + model.externallyActivatedPitches.add(pitch) + } } } ) diff --git a/Sources/Keyboard/Keyboard.swift b/Sources/Keyboard/Keyboard.swift index 0e71575..54fa42b 100644 --- a/Sources/Keyboard/Keyboard.swift +++ b/Sources/Keyboard/Keyboard.swift @@ -81,6 +81,7 @@ public struct Keyboard: View where Content: View { }.onAppear { model.noteOn = noteOn model.noteOff = noteOff + model.latching = latching } } } diff --git a/Sources/Keyboard/KeyboardModel.swift b/Sources/Keyboard/KeyboardModel.swift index 4a10b87..274ee3d 100644 --- a/Sources/Keyboard/KeyboardModel.swift +++ b/Sources/Keyboard/KeyboardModel.swift @@ -9,6 +9,7 @@ public class KeyboardModel: ObservableObject { var noteOn: (Pitch, CGPoint) -> Void = { _, _ in } var noteOff: (Pitch) -> Void = { _ in } var normalizedPoints = Array(repeating: CGPoint.zero, count: 128) + var latching: Bool = false var touchLocations: [CGPoint] = [] { didSet {