// the note queue is a wrapper for a FIFO array to which the midi/keyboard controller enters note events into and the synthesizer consumes from #pragma once #include #include #include #include #include "ConfigService.hpp" #include "LoggerService.hpp" enum NoteEventType { NoteOn = 0, NoteOff }; struct NoteEvent { NoteEventType type; // noteOn or noteOff uint8_t note; // 0-128, a keyboard goes 0-87 float velocity; // 0-1, from a midi instrument its 0-127 though std::chrono::time_point timestamp; }; class NoteQueue { public: NoteQueue(); NoteQueue(ConfigService* config, LoggerService* logger); ~NoteQueue() = default; bool push(const NoteEvent& event); bool pop(NoteEvent& event); private: ConfigService* config_; LoggerService* logger_; static constexpr size_t SYNTH_NOTE_QUEUE_SIZE = 128; // TODO: config std::array buffer_; std::atomic head_{ 0 }; std::atomic tail_{ 0 }; };