#pragma once

#include "base/base_core.h"

struct MidiEngine;

struct MidiDeviceInfo {
    char    name[64];
    S32 id;
    B32    is_input;
    B32    active;      // true when note(s) currently held
    B32    releasing;   // true during release flash
    S32 velocity;    // last note-on velocity (0-127)
    S32 note;        // last MIDI note number (0-127)
};

MidiEngine     *midi_create();
void            midi_destroy(MidiEngine *engine);
void            midi_refresh_devices(MidiEngine *engine);
S32         midi_get_device_count(MidiEngine *engine);
MidiDeviceInfo *midi_get_device(MidiEngine *engine, S32 index);

void            midi_open_all_inputs(MidiEngine *engine);
void            midi_close_all_inputs(MidiEngine *engine);
void            midi_update(MidiEngine *engine, F32 dt);
B32            midi_is_input_active(MidiEngine *engine, S32 device_index);

// Per-note state: returns true if note (0-127) is currently held on any input device
B32            midi_is_note_held(MidiEngine *engine, S32 note);
// Returns the last note-on velocity (0-127) for a given note, or 0 if not held
S32         midi_get_note_velocity(MidiEngine *engine, S32 note);
