-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_library(midi | ||
add_library(midi STATIC | ||
InputNode.cpp | ||
InputObserver.cpp | ||
MidiEngine.cpp | ||
MidiGraph.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "InputNode.hpp" | ||
|
||
#include "MidiProbe.hpp" | ||
|
||
#include <spdlog/spdlog.h> | ||
|
||
mc::midi::InputNode::InputNode(const InputInfo& info) | ||
: m_info(info), m_midi_in(RtMidi::UNSPECIFIED, MidiProbe::get_midi_client_name()) | ||
{ | ||
m_midi_in.setCallback(message_callback, this); | ||
m_midi_in.setErrorCallback(error_callback, nullptr); | ||
m_midi_in.openPort(m_info.m_id); | ||
} | ||
|
||
void mc::midi::InputNode::enable_message_types(const MessageTypeMask& mask) | ||
{ | ||
m_midi_in.ignoreTypes(!mask.m_sysex_enabled, !mask.m_time_enabled, !mask.m_sensing_enabled); | ||
} | ||
|
||
void mc::midi::InputNode::message_callback(double time_stamp, | ||
std::vector<unsigned char>* message, | ||
void* user_data) | ||
{ | ||
auto* instance = static_cast<InputNode*>(user_data); | ||
instance->broadcast_data(*message); | ||
instance->raise_message_received(instance->m_info.m_id, *message); | ||
} | ||
|
||
void mc::midi::InputNode::error_callback(RtMidiError::Type error_code, | ||
const std::string& message, | ||
void* user_data) | ||
{ | ||
spdlog::error("Error {} occured in MIDI input: \"{}\"", static_cast<int>(error_code), message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
#include "InputObserver.hpp" | ||
#include "MidiEngine.hpp" | ||
#include "MidiGraph.hpp" | ||
#include "MidiInfo.hpp" | ||
|
||
#include "RtMidi.h" | ||
|
||
namespace mc::midi | ||
{ | ||
|
||
class InputNode final : public Node, public InputObservable | ||
{ | ||
public: | ||
explicit InputNode(const InputInfo& info); | ||
|
||
void enable_message_types(const MessageTypeMask& mask); | ||
|
||
private: | ||
static void message_callback(double time_stamp, | ||
std::vector<unsigned char>* message, | ||
void* user_data); | ||
|
||
static void error_callback(RtMidiError::Type error_code, | ||
const std::string& message, | ||
void* user_data); | ||
|
||
InputInfo m_info; | ||
RtMidiIn m_midi_in; | ||
}; | ||
|
||
} // namespace mc::midi |