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