Skip to content

Commit c075267

Browse files
Fix Stuck Keys (#32)
* Update KeyContainer.swift * Revert "Update KeyContainer.swift" This reverts commit e17ccfd. * Latching Toggle
1 parent f1f3ae9 commit c075267

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Sources/Keyboard/KeyContainer.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ public struct KeyContainer<Content: View>: View {
3232

3333
func rect(rect: CGRect) -> some View {
3434
content(pitch, model.touchedPitches.contains(pitch) || model.externallyActivatedPitches.contains(pitch))
35-
.contentShape(Rectangle()) // Added to improve tap/click reliability
35+
.contentShape(Rectangle())
3636
.gesture(
3737
TapGesture().onEnded { _ in
38-
if model.externallyActivatedPitches.contains(pitch) {
39-
model.externallyActivatedPitches.remove(pitch)
40-
} else {
41-
model.externallyActivatedPitches.add(pitch)
38+
if model.latching {
39+
if model.externallyActivatedPitches.contains(pitch) {
40+
model.externallyActivatedPitches.remove(pitch)
41+
} else {
42+
model.externallyActivatedPitches.add(pitch)
43+
}
4244
}
4345
}
4446
)

Sources/Keyboard/Keyboard.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public struct Keyboard<Content>: View where Content: View {
8181
}.onAppear {
8282
model.noteOn = noteOn
8383
model.noteOff = noteOff
84+
model.latching = latching
8485
}
8586
}
8687
}

Sources/Keyboard/KeyboardModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class KeyboardModel: ObservableObject {
99
var noteOn: (Pitch, CGPoint) -> Void = { _, _ in }
1010
var noteOff: (Pitch) -> Void = { _ in }
1111
var normalizedPoints = Array(repeating: CGPoint.zero, count: 128)
12+
var latching: Bool = false
1213

1314
var touchLocations: [CGPoint] = [] {
1415
didSet {

0 commit comments

Comments
 (0)