Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Sources/Keyboard/KeyContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public struct KeyContainer<Content: View>: 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)
}
}
}
)
Expand Down
1 change: 1 addition & 0 deletions Sources/Keyboard/Keyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public struct Keyboard<Content>: View where Content: View {
}.onAppear {
model.noteOn = noteOn
model.noteOff = noteOff
model.latching = latching
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Keyboard/KeyboardModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down