Skip to content

Commit

Permalink
Prevent out of range crash
Browse files Browse the repository at this point in the history
  • Loading branch information
aure committed Aug 11, 2024
1 parent 60abb82 commit 6d020f7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Sources/Tonic/Pitch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ extension Pitch: IntRepresentable {
}

public init(intValue: Int) {
midiNoteNumber = Int8(intValue)
if intValue < 0 {
midiNoteNumber = 0
} else if intValue > 127 {
midiNoteNumber = 127
} else {
midiNoteNumber = Int8(intValue)
}
}
}

Expand Down

0 comments on commit 6d020f7

Please sign in to comment.