Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to control height of black keys on .piano layout #24

Merged
merged 1 commit into from
Jun 26, 2023
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
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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)

/// 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
Loading