Skip to content

Commit 6d020f7

Browse files
committed
Prevent out of range crash
1 parent 60abb82 commit 6d020f7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/Tonic/Pitch.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ extension Pitch: IntRepresentable {
9999
}
100100

101101
public init(intValue: Int) {
102-
midiNoteNumber = Int8(intValue)
102+
if intValue < 0 {
103+
midiNoteNumber = 0
104+
} else if intValue > 127 {
105+
midiNoteNumber = 127
106+
} else {
107+
midiNoteNumber = Int8(intValue)
108+
}
103109
}
104110
}
105111

0 commit comments

Comments
 (0)