// melody_validator.h — note-sequence validator (P1). Pure logic, no I/O.
#pragma once
#include <stdbool.h>
#include <stddef.h>

#define MELODY_MAX_NOTES 32

typedef struct {
    int    expected[MELODY_MAX_NOTES];   // MIDI note numbers (0-127)
    size_t count;
    int    tolerance;                    // accepted deviation in semitones (>=0; negative clamped to 0)
    size_t pos;
} melody_validator_t;

// expected: array of `count` MIDI note numbers (0-127, caller-bounded).
// tolerance: maximum deviation in semitones from an expected note (>=0; negative clamped to 0).
// Repeated notes ARE permitted in the expected sequence (unlike seq_validator).
// m and expected must be non-NULL; no internal NULL checks are performed.
void melody_validator_init(melody_validator_t *m, const int *expected,
                           size_t count, int tolerance);

// Feed one detected note (MIDI number 0-127). True when the full melody is matched.
// On mismatch, resets and allows the current note to seed index 0 if it fits.
bool melody_validator_feed(melody_validator_t *m, int note);
