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 @available checks for new canvas keyboard and removed #Preview macro #25

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions Demo/KeyboardDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = W22K9JG3J6;
DEVELOPMENT_TEAM = UNPG3B9P9H;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down Expand Up @@ -367,7 +367,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = W22K9JG3J6;
DEVELOPMENT_TEAM = UNPG3B9P9H;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down
111 changes: 20 additions & 91 deletions Demo/Shared/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,109 +66,38 @@ struct ContentView: View {

var body: some View {
HStack {
Keyboard(layout: .verticalIsomorphic(pitchRange: Pitch(48) ... Pitch(77))).frame(width: 100)
VStack {
HStack {
Stepper("Lowest Note: \(Pitch(intValue: lowNote).note(in: .C).description)",
onIncrement: {
if lowNote < 126, highNote > lowNote + 12 {
lowNote += 1
}
},
if lowNote < 126, highNote > lowNote + 12 {
lowNote += 1
}
},
onDecrement: {
if lowNote > 0 {
lowNote -= 1
}
})
if lowNote > 0 {
lowNote -= 1
}
})
Stepper("Highest Note: \(Pitch(intValue: highNote).note(in: .C).description)",
onIncrement: {
if highNote < 126 {
highNote += 1
}
},
onDecrement: {
if highNote > 1, highNote > lowNote + 12 {
highNote -= 1
}

})
}
Keyboard(layout: .piano(pitchRange: Pitch(intValue: lowNote) ... Pitch(intValue: highNote)),
noteOn: noteOnWithVerticalVelocity(pitch:point:), noteOff: noteOff)
.frame(minWidth: 100, minHeight: 100)

HStack {
Stepper("Root: \(root.description)",
onIncrement: {
let allSharpNotes = (0...11).map { Note(pitch: Pitch(intValue: $0)).noteClass }
var index = allSharpNotes.firstIndex(of: root.canonicalNote.noteClass) ?? 0
index += 1
if index > 11 { index = 0}
if index < 0 { index = 1}
rootIndex = index
root = allSharpNotes[index]
if highNote < 126 {
highNote += 1
}
},
onDecrement: {
let allSharpNotes = (0...11).map { Note(pitch: Pitch(intValue: $0)).noteClass }
var index = allSharpNotes.firstIndex(of: root.canonicalNote.noteClass) ?? 0
index -= 1
if index > 11 { index = 0}
if index < 0 { index = 1}
rootIndex = index
root = allSharpNotes[index]
})

Stepper("Scale: \(scale.description)",
onIncrement: { scaleIndex += 1 },
onDecrement: { scaleIndex -= 1 })
}
Keyboard(layout: .isomorphic(pitchRange:
Pitch(intValue: 12 + rootIndex) ... Pitch(intValue: 84 + rootIndex),
root: root,
scale: scale),
noteOn: noteOnWithReversedVerticalVelocity(pitch:point:), noteOff: noteOff)
.frame(minWidth: 100, minHeight: 100)

Keyboard(layout: .guitar(),
noteOn: noteOn, noteOff: noteOff) { pitch, isActivated in
KeyboardKey(pitch: pitch,
isActivated: isActivated,
text: pitch.note(in: .F).description,
pressedColor: Color(PitchColor.newtonian[Int(pitch.pitchClass)]),
alignment: .center)
}
.frame(minWidth: 100, minHeight: 100)

Keyboard(layout: .isomorphic(pitchRange: Pitch(48) ... Pitch(65))) { pitch, isActivated in
KeyboardKey(pitch: pitch,
isActivated: isActivated,
text: pitch.note(in: .F).description,
pressedColor: Color(PitchColor.newtonian[Int(pitch.pitchClass)]))
}
.frame(minWidth: 100, minHeight: 100)

Keyboard(latching: true, noteOn: noteOn, noteOff: noteOff) { pitch, isActivated in
if isActivated {
ZStack {
Rectangle().foregroundColor(.black)
VStack {
Spacer()
Text(pitch.note(in: .C).description).font(.largeTitle)
}.padding()
if highNote > 1, highNote > lowNote + 12 {
highNote -= 1
}

} else {
Rectangle().foregroundColor(randomColors[Int(pitch.intValue) % 12])
}

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)

})
}
.frame(minWidth: 100, minHeight: 100)
Keyboard(layout: .piano(pitchRange: Pitch(intValue: lowNote) ... Pitch(intValue: highNote)),
noteOn: noteOnWithVerticalVelocity(pitch:point:), noteOff: noteOff)
.frame(minWidth: 100)
.frame(height: 100)
}
Keyboard(
layout: .verticalPiano(pitchRange: Pitch(48) ... Pitch(77),
initialSpacerRatio: evenSpacingInitialSpacerRatio,
spacerRatio: evenSpacingSpacerRatio,
relativeBlackKeyWidth: evenSpacingRelativeBlackKeyWidth)
).frame(width: 100)

}
.background(colorScheme == .dark ?
Color.clear : Color(red: 0.9, green: 0.9, blue: 0.9))
Expand Down
17 changes: 10 additions & 7 deletions Sources/Keyboard/MIDIMonitorKeyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import SwiftUI
import Tonic

@available(iOS 15, macOS 12.0, *)
extension GraphicsContext {
func fill(rect: CGRect, with color: Color) {
fill(Path(roundedRect: rect, cornerRadius: 0), with: GraphicsContext.Shading.color(color))
}
}

@available(iOS 15, macOS 12.0, *)
struct MIDIMonitorKeyboard: View {

var layout: KeyboardLayout
var activatedPitches: PitchSet
var colorFunction: (Pitch)->Color
Expand Down Expand Up @@ -87,9 +88,11 @@ struct MIDIMonitorKeyboard: View {
}

var p = PitchSet(pitches: [Pitch(65), Pitch(68), Pitch(71), Pitch(74)])
#Preview {
MIDIMonitorKeyboard(layout: .piano(pitchRange: Pitch(61)...Pitch(88)),
activatedPitches: p,
colorFunction: { x in Color(cgColor: PitchColor.helmholtz[Int(x.pitchClass)])}
).frame(width: 600, height: 100)
}

//MARK: - we can have preview macro after Xcode 15 is released
Copy link

Choose a reason for hiding this comment

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

Comment Spacing Violation: Prefer at least one space after slashes for comments. (comment_spacing)
Mark Violation: MARK comment should be in valid format. e.g. '// MARK: ...' or '// MARK: - ...' (mark)

//#Preview {
Copy link

Choose a reason for hiding this comment

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

Comment Spacing Violation: Prefer at least one space after slashes for comments. (comment_spacing)

// MIDIMonitorKeyboard(layout: .piano(pitchRange: Pitch(61)...Pitch(88)),
// activatedPitches: p,
// colorFunction: { x in Color(cgColor: PitchColor.helmholtz[Int(x.pitchClass)])}
// ).frame(width: 600, height: 100)
//}
Copy link

Choose a reason for hiding this comment

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

Comment Spacing Violation: Prefer at least one space after slashes for comments. (comment_spacing)

Loading