@@ -6,19 +6,17 @@ public struct Keyboard<Content>: View where Content: View {
6
6
7
7
@StateObject var model : KeyboardModel = KeyboardModel ( )
8
8
9
- var pitchRange : ClosedRange < Pitch >
10
9
var latching : Bool
11
10
var noteOn : ( Pitch ) -> Void
12
11
var noteOff : ( Pitch ) -> Void
13
12
var layout : KeyboardLayout
14
13
15
- public init ( pitchRange : ClosedRange < Pitch > = ( Pitch ( 60 ) ... Pitch ( 72 ) ) ,
14
+ public init ( layout : KeyboardLayout = . piano ( pitchRange : ( Pitch ( 60 ) ... Pitch ( 72 ) ) ) ,
16
15
latching: Bool = false ,
17
- layout : KeyboardLayout = . piano ,
16
+
18
17
noteOn: @escaping ( Pitch ) -> Void = { _ in } ,
19
18
noteOff: @escaping ( Pitch ) -> Void = { _ in } ,
20
19
@ViewBuilder content: @escaping ( Pitch , Bool ) -> Content ) {
21
- self . pitchRange = pitchRange
22
20
self . latching = latching
23
21
self . layout = layout
24
22
self . noteOn = noteOn
@@ -29,13 +27,13 @@ public struct Keyboard<Content>: View where Content: View {
29
27
public var body : some View {
30
28
Group {
31
29
switch layout {
32
- case . piano:
30
+ case . piano( let pitchRange ) :
33
31
Piano ( content: content, model: model, pitchRange: pitchRange, latching: latching)
34
- case . isomorphic:
32
+ case . isomorphic( let pitchRange ) :
35
33
Isomorphic ( content: content, model: model, pitchRange: pitchRange, latching: latching)
36
34
case . guitar( let openPitches, let fretCount) :
37
35
Guitar ( content: content, model: model, openPitches: openPitches, fretCount: fretCount, latching: latching)
38
- case . pianoRoll:
36
+ case . pianoRoll( let pitchRange ) :
39
37
PianoRoll ( content: content, model: model, pitchRange: pitchRange, latching: latching)
40
38
}
41
39
@@ -52,26 +50,28 @@ public struct Keyboard<Content>: View where Content: View {
52
50
53
51
extension Keyboard where Content == KeyboardKey {
54
52
55
- public init ( pitchRange : ClosedRange < Pitch > = ( Pitch ( 60 ) ... Pitch ( 72 ) ) ,
53
+ public init ( layout : KeyboardLayout = . piano ( pitchRange : ( Pitch ( 60 ) ... Pitch ( 72 ) ) ) ,
56
54
latching: Bool = false ,
57
- layout: KeyboardLayout = . piano,
58
55
noteOn: @escaping ( Pitch ) -> Void = { _ in } ,
59
56
noteOff: @escaping ( Pitch ) -> Void = { _ in } ) {
60
- self . pitchRange = pitchRange
61
- self . latching = latching
62
57
self . layout = layout
58
+ self . latching = latching
63
59
self . noteOn = noteOn
64
60
self . noteOff = noteOff
61
+
65
62
var alignment : Alignment = . bottom
63
+
64
+ var flatTop = false
66
65
switch layout {
67
66
case . guitar( _, _) :
68
67
alignment = . center
69
- case . pianoRoll:
70
- alignment = . trailing
71
- default :
68
+ case . isomorphic( _) :
72
69
alignment = . bottom
73
-
70
+ case . piano( _) :
71
+ flatTop = true
72
+ case . pianoRoll( _) :
73
+ alignment = . trailing
74
74
}
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) }
76
76
}
77
77
}
0 commit comments