diff --git a/src/KeyboardController.cpp b/src/KeyboardController.cpp index 5319d24..d9edb1f 100644 --- a/src/KeyboardController.cpp +++ b/src/KeyboardController.cpp @@ -45,7 +45,8 @@ void KeyboardController::handleKeyPress(QKeyEvent* e) { queue_.push({ NoteEventType::NoteOn, it->second, - 0.8f + 0.8f, + std::chrono::high_resolution_clock::now() }); } @@ -59,6 +60,7 @@ void KeyboardController::handleKeyRelease(QKeyEvent* e) { queue_.push({ NoteEventType::NoteOff, it->second, - 0.8f + 0.8f, + std::chrono::high_resolution_clock::now() }); } \ No newline at end of file diff --git a/src/MidiController.cpp b/src/MidiController.cpp index fce6773..88b7d59 100644 --- a/src/MidiController.cpp +++ b/src/MidiController.cpp @@ -68,7 +68,8 @@ void MidiController::handleMessage(const std::vector& msg) { noteQueue_.push({ NoteEventType::NoteOn, static_cast(note), - vel / 127.0f + vel / 127.0f, + std::chrono::high_resolution_clock::now() }); } // Note Off (or Note On with velocity 0) @@ -76,7 +77,10 @@ void MidiController::handleMessage(const std::vector& msg) { noteQueue_.push({ NoteEventType::NoteOff, static_cast(note), - 0.0f + 0.0f, + std::chrono::high_resolution_clock::now() }); } + + std::cout << "MidiHandleMessage start (0)" << std::endl; } \ No newline at end of file diff --git a/src/NoteQueue.cpp b/src/NoteQueue.cpp index 9630c67..0655a6b 100644 --- a/src/NoteQueue.cpp +++ b/src/NoteQueue.cpp @@ -1,5 +1,6 @@ #include "NoteQueue.h" +#include bool NoteQueue::push(const NoteEvent& event) { size_t head = head_.load(std::memory_order_relaxed); @@ -9,6 +10,9 @@ bool NoteQueue::push(const NoteEvent& event) { buffer_[head] = event; head_.store(next, std::memory_order_relaxed); + + std::cout << "Notequeue::push: " << std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - event.timestamp) << std::endl; + return true; } @@ -19,5 +23,8 @@ bool NoteQueue::pop(NoteEvent& event) { event = buffer_[tail]; tail_.store((tail + 1) % SIZE, std::memory_order_release); + + std::cout << "Notequeue::pop: " << std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - event.timestamp) << std::endl; + return true; } diff --git a/src/NoteQueue.h b/src/NoteQueue.h index d3c3c5d..8d87e6f 100644 --- a/src/NoteQueue.h +++ b/src/NoteQueue.h @@ -4,6 +4,7 @@ #include #include #include +#include enum class NoteEventType { NoteOn, @@ -14,6 +15,7 @@ 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; }; // the queue is to keep track of note events from the UI/input thread to the audio engine thread diff --git a/src/synth/Synth.cpp b/src/synth/Synth.cpp index 126e6ee..2e25212 100644 --- a/src/synth/Synth.cpp +++ b/src/synth/Synth.cpp @@ -31,6 +31,10 @@ inline float Synth::getParam(ParamId id) { } void Synth::handleNoteEvent(const NoteEvent& event) { + + std::cout << "Synth::handleNoteEvent: " << std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - event.timestamp) << std::endl; + lastTime = event.timestamp; + if(event.type == NoteEventType::NoteOn) { // TODO: find quietest voice and assign a note to it instead of just the first inactive one @@ -106,4 +110,6 @@ void Synth::process(float* out, uint32_t nFrames, uint32_t sampleRate) { } } + //std::cout << "Notequeue::push: " << std::chrono::high_resolution_clock::now() - lastTime << std::endl; + } \ No newline at end of file diff --git a/src/synth/Synth.h b/src/synth/Synth.h index 6e9bb33..5a22b93 100644 --- a/src/synth/Synth.h +++ b/src/synth/Synth.h @@ -52,4 +52,6 @@ private: // for the scope ScopeBuffer* scope_ = nullptr; + std::chrono::time_point lastTime; + };