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 {