Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of bounds Int8 when recognizing chords. #46

Open
diquah opened this issue Oct 15, 2024 · 0 comments
Open

Out of bounds Int8 when recognizing chords. #46

diquah opened this issue Oct 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@diquah
Copy link

diquah commented Oct 15, 2024

macOS Version(s) Used to Build

macOS 13 Ventura

Xcode Version(s)

Xcode 14

Description

When recognizing a chord as shown below:

/// INSIDE MY PROJECT

func recognizeChord() -> Chord? {
    var currentPitches: PitchSet = PitchSet()
    for (keyID, pressed) in midiHelper.MIDIKeysDown {
        if pressed {
            currentPitches.add(Pitch(intValue: keyID.clamped(to: 0..<128)))
        }
    }
    let rankings = Chord.getRankedChords(from: currentPitches, allowTheoreticalChords: true)
    return rankings.first
}

The program hard crashes with an out of range exception for the Int8

/// INSIDE TONIC

public var noteNumber: Int8 {
    let octaveBounds = ((octave + 1) * 12) ... ((octave + 2) * 12)
    var note = Int(noteClass.letter.baseNote) + Int(noteClass.accidental.rawValue)
    if noteClass.letter == .B && noteClass.accidental.rawValue > 0 {
        note -= 12
    }
    if noteClass.letter == .C && noteClass.accidental.rawValue < 0 {
        note += 12
    }
    while !octaveBounds.contains(note) {
        note += 12
    }
    return Int8(note) // <--- Error Here
}

The error occurs above D7 (MIDI Key 98).

Crash Logs, Screenshots or Other Attachments (if applicable)

image
@diquah diquah added the bug Something isn't working label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant