midi checkpoint
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "synth/AudioEngine.hpp"
|
||||
#include "synth/KeyboardController.hpp"
|
||||
#include "synth/Scope.hpp"
|
||||
#include "synth/MidiController.hpp"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
@@ -24,6 +25,7 @@ int main(int argc, char* argv[]) {
|
||||
NoteQueue queue = NoteQueue();
|
||||
ScopeBuffer scopeBuffer = ScopeBuffer(512);
|
||||
KeyboardController keyboard(&config, &logger, &queue);
|
||||
MidiController midi(&config, &logger, &queue);
|
||||
Synth synth(&config, &logger, &scopeBuffer, &queue);
|
||||
|
||||
// audio synthesizer doohickey
|
||||
@@ -33,12 +35,11 @@ int main(int argc, char* argv[]) {
|
||||
// attach backend gui components
|
||||
qmlRegisterType<TimerComponent>("AppDemo", 1, 0, "TimerComponent");
|
||||
qmlRegisterType<Scope>("AppDemo", 1, 0, "Scope");
|
||||
// attach backend services to qml
|
||||
engine.rootContext()->setContextProperty("keyboardController", &keyboard);
|
||||
engine.rootContext()->setContextProperty("scopeBuffer", &scopeBuffer);
|
||||
|
||||
// load qml
|
||||
//engine.loadFromModule("sonobulus", "Main");
|
||||
//engine.load(QUrl("qrc:/Main.qml"));
|
||||
engine.load(QUrl::fromLocalFile("ui/Main.qml")); // ugh
|
||||
|
||||
if(engine.rootObjects().isEmpty()) {
|
||||
|
||||
@@ -4,14 +4,20 @@
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
MidiController::MidiController(NoteQueue& queue) : noteQueue_(queue) {
|
||||
MidiController::MidiController(ConfigService* config, LoggerService* logger, NoteQueue* queue) :
|
||||
config_(config), logger_(logger), noteQueue_(queue) {
|
||||
try {
|
||||
#ifdef WIN32
|
||||
midiIn_ = std::make_unique<RtMidiIn>(RtMidi::WINDOWS_MM);
|
||||
#else
|
||||
midiIn_ = std::make_unique<RtMidiIn>(RtMidi::LINUX_ALSA);
|
||||
#endif
|
||||
midiIn_->ignoreTypes(false, false, false);
|
||||
} catch (RtMidiError& e) {
|
||||
std::cout << "RtMidi init failed: " << e.getMessage() << std::endl;
|
||||
}
|
||||
// TODO: this still doesnt work on windows
|
||||
|
||||
openDefaultPort();
|
||||
}
|
||||
|
||||
MidiController::~MidiController() {
|
||||
@@ -100,7 +106,7 @@ void MidiController::handleMessage(const std::vector<unsigned char>& msg) {
|
||||
void MidiController::noteOn(uint8_t note, uint8_t vel) {
|
||||
sustainedNotes_.erase(note);
|
||||
|
||||
noteQueue_.push({
|
||||
noteQueue_->push({
|
||||
NoteEventType::NoteOn,
|
||||
static_cast<uint8_t>(note),
|
||||
vel / 127.0f,
|
||||
@@ -114,7 +120,7 @@ void MidiController::noteOff(uint8_t note) {
|
||||
sustainedNotes_.insert(note);
|
||||
return;
|
||||
}
|
||||
noteQueue_.push({
|
||||
noteQueue_->push({
|
||||
NoteEventType::NoteOff,
|
||||
static_cast<uint8_t>(note),
|
||||
0.0f,
|
||||
|
||||
@@ -4,13 +4,16 @@
|
||||
|
||||
#include <RtMidi.h>
|
||||
#include <memory>
|
||||
#include "NoteQueue.hpp"
|
||||
#include <unordered_set>
|
||||
|
||||
#include "NoteQueue.hpp"
|
||||
#include "ConfigService.hpp"
|
||||
#include "LoggerService.hpp"
|
||||
|
||||
class MidiController {
|
||||
public:
|
||||
|
||||
MidiController(NoteQueue& queue);
|
||||
MidiController(ConfigService* config, LoggerService* logger, NoteQueue* queue);
|
||||
~MidiController();
|
||||
|
||||
bool openDefaultPort();
|
||||
@@ -27,7 +30,9 @@ private:
|
||||
void noteOff(uint8_t note);
|
||||
|
||||
std::unique_ptr<RtMidiIn> midiIn_;
|
||||
NoteQueue& noteQueue_;
|
||||
ConfigService* config_;
|
||||
LoggerService* logger_;
|
||||
NoteQueue* noteQueue_;
|
||||
|
||||
bool sustainDown_ = false;
|
||||
std::unordered_set<uint8_t> sustainedNotes_;
|
||||
|
||||
Reference in New Issue
Block a user