@@ -6,19 +6,17 @@ public struct Keyboard<Content>: View where Content: View {
66
77 @StateObject var model : KeyboardModel = KeyboardModel ( )
88
9- var pitchRange : ClosedRange < Pitch >
109 var latching : Bool
1110 var noteOn : ( Pitch ) -> Void
1211 var noteOff : ( Pitch ) -> Void
1312 var layout : KeyboardLayout
1413
15- public init ( pitchRange : ClosedRange < Pitch > = ( Pitch ( 60 ) ... Pitch ( 72 ) ) ,
14+ public init ( layout : KeyboardLayout = . piano ( pitchRange : ( Pitch ( 60 ) ... Pitch ( 72 ) ) ) ,
1615 latching: Bool = false ,
17- layout : KeyboardLayout = . piano ,
16+
1817 noteOn: @escaping ( Pitch ) -> Void = { _ in } ,
1918 noteOff: @escaping ( Pitch ) -> Void = { _ in } ,
2019 @ViewBuilder content: @escaping ( Pitch , Bool ) -> Content ) {
21- self . pitchRange = pitchRange
2220 self . latching = latching
2321 self . layout = layout
2422 self . noteOn = noteOn
@@ -29,13 +27,13 @@ public struct Keyboard<Content>: View where Content: View {
2927 public var body : some View {
3028 Group {
3129 switch layout {
32- case . piano:
30+ case . piano( let pitchRange ) :
3331 Piano ( content: content, model: model, pitchRange: pitchRange, latching: latching)
34- case . isomorphic:
32+ case . isomorphic( let pitchRange ) :
3533 Isomorphic ( content: content, model: model, pitchRange: pitchRange, latching: latching)
3634 case . guitar( let openPitches, let fretCount) :
3735 Guitar ( content: content, model: model, openPitches: openPitches, fretCount: fretCount, latching: latching)
38- case . pianoRoll:
36+ case . pianoRoll( let pitchRange ) :
3937 PianoRoll ( content: content, model: model, pitchRange: pitchRange, latching: latching)
4038 }
4139
@@ -52,26 +50,28 @@ public struct Keyboard<Content>: View where Content: View {
5250
5351extension Keyboard where Content == KeyboardKey {
5452
55- public init ( pitchRange : ClosedRange < Pitch > = ( Pitch ( 60 ) ... Pitch ( 72 ) ) ,
53+ public init ( layout : KeyboardLayout = . piano ( pitchRange : ( Pitch ( 60 ) ... Pitch ( 72 ) ) ) ,
5654 latching: Bool = false ,
57- layout: KeyboardLayout = . piano,
5855 noteOn: @escaping ( Pitch ) -> Void = { _ in } ,
5956 noteOff: @escaping ( Pitch ) -> Void = { _ in } ) {
60- self . pitchRange = pitchRange
61- self . latching = latching
6257 self . layout = layout
58+ self . latching = latching
6359 self . noteOn = noteOn
6460 self . noteOff = noteOff
61+
6562 var alignment : Alignment = . bottom
63+
64+ var flatTop = false
6665 switch layout {
6766 case . guitar( _, _) :
6867 alignment = . center
69- case . pianoRoll:
70- alignment = . trailing
71- default :
68+ case . isomorphic( _) :
7269 alignment = . bottom
73-
70+ case . piano( _) :
71+ flatTop = true
72+ case . pianoRoll( _) :
73+ alignment = . trailing
7474 }
75- self . content = { KeyboardKey ( pitch: $0, isActivated: $1, flatTop: layout == . piano , alignment: alignment) }
75+ self . content = { KeyboardKey ( pitch: $0, isActivated: $1, flatTop: flatTop , alignment: alignment) }
7676 }
7777}
0 commit comments