#pragma once

#include "MidiDocument.h"
#include "MetaMidiEvent.h"
#include "MidiTrack.h"
#include "MidiChannelEvent.h"
#include "File.h"
#include <string>

class MidiReader
{
    static constexpr const char TrackChunkLabel[] = "MTrk";
    static constexpr const char HeaderLabel[] = "MThd";

public:

    MidiReader();

    void Read(const std::string& path);

    MidiDocument* GetDocument() const;

private:

    bool ProcessHeader();
    bool ProcessTrackChunk(bool debug=false);
    int ProcessEvent(MidiTrack* track);

private:

    std::unique_ptr<File> mFile;
    MidiDocumentPtr mDocument;
    int mLastMidiChannel {0};
    MidiChannelEvent::Type mLastChannelEventType;
};
