Skip to content

Commit

Permalink
Added ability to control height of black keys on .piano layout
Browse files Browse the repository at this point in the history
  • Loading branch information
maksutovic committed Jun 26, 2023
1 parent 238ac6c commit 5bb8cdf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
5 changes: 3 additions & 2 deletions Sources/Keyboard/Keyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ public struct Keyboard<Content>: View where Content: View {
public var body: some View {
ZStack {
switch layout {
case let .piano(pitchRange, initialSpacerRatio, spacerRatio, relativeBlackKeyWidth):
case let .piano(pitchRange, initialSpacerRatio, spacerRatio, relativeBlackKeyWidth, relativeBlackKeyHeight):
Piano(content: content,
keyboard: model,
spacer: PianoSpacer(pitchRange: pitchRange,
initialSpacerRatio: initialSpacerRatio,
spacerRatio: spacerRatio,
relativeBlackKeyWidth: relativeBlackKeyWidth))
relativeBlackKeyWidth: relativeBlackKeyWidth,
relativeBlackKeyHeight: relativeBlackKeyHeight))
case let .isomorphic(pitchRange, root, scale):
Isomorphic(content: content,
model: model,
Expand Down
3 changes: 2 additions & 1 deletion Sources/Keyboard/Layouts/KeyboardLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public enum KeyboardLayout: Equatable, Hashable {
case piano(pitchRange: ClosedRange<Pitch>,
initialSpacerRatio: [Letter: CGFloat] = PianoSpacer.defaultInitialSpacerRatio,
spacerRatio: [Letter: CGFloat] = PianoSpacer.defaultSpacerRatio,
relativeBlackKeyWidth: CGFloat = PianoSpacer.defaultRelativeBlackKeyWidth)
relativeBlackKeyWidth: CGFloat = PianoSpacer.defaultRelativeBlackKeyWidth,
relativeBlackKeyHeight: CGFloat = PianoSpacer.defaultRelativeBlackKeyHeight)

/// For piano roll, jam strip type views
case verticalIsomorphic(pitchRange: ClosedRange<Pitch>,
Expand Down
6 changes: 1 addition & 5 deletions Sources/Keyboard/Layouts/Piano.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ struct Piano<Content>: View where Content: View {
}
}
}

// This space pushes the black keys up.
// XXX: perhaps we should give the user control of
// the spacing.
Spacer().frame(height: geo.size.height * 0.47)
Spacer().frame(height: geo.size.height * (1 - spacer.relativeBlackKeyHeight))
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion Sources/Keyboard/Layouts/PianoSpacer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ public struct PianoSpacer {
.B: 10.0 / 16.0
]
public static let defaultRelativeBlackKeyWidth: CGFloat = 9.0 / 16.0

/// Default value for Black Key Height
public static let defaultRelativeBlackKeyHeight: CGFloat = 0.53

public var pitchRange: ClosedRange<Pitch>
public var initialSpacerRatio: [Letter: CGFloat]
public var spacerRatio: [Letter: CGFloat]
public var relativeBlackKeyWidth: CGFloat
public var relativeBlackKeyWidth: CGFloat = PianoSpacer.defaultRelativeBlackKeyWidth
/// The smaller the number, the shorter the black keys appear. A value of 1 approximates an isomorphic keyboard
public var relativeBlackKeyHeight: CGFloat = PianoSpacer.defaultRelativeBlackKeyHeight
}

extension PianoSpacer {
Expand Down

0 comments on commit 5bb8cdf

Please sign in to comment.