diff options
Diffstat (limited to 'src/engine/MidiAction.cpp')
-rw-r--r-- | src/engine/MidiAction.cpp | 75 |
1 files changed, 33 insertions, 42 deletions
diff --git a/src/engine/MidiAction.cpp b/src/engine/MidiAction.cpp index f1f1ccb..30de67a 100644 --- a/src/engine/MidiAction.cpp +++ b/src/engine/MidiAction.cpp @@ -14,11 +14,10 @@ along with Machina. If not, see <http://www.gnu.org/licenses/>. */ -#include <iostream> - -#include "raul/Atom.hpp" - +#include "lv2/lv2plug.in/ns/ext/midi/midi.h" +#include "machina/URIs.hpp" #include "machina/types.hpp" +#include "raul/Atom.hpp" #include "MIDISink.hpp" #include "MidiAction.hpp" @@ -27,11 +26,8 @@ namespace machina { /** Create a MIDI action. * - * Creating a NULL MIDIAction is okay, pass event=NULL and - * the action will simply do nothing until a set_event (for MIDI learning). - * - * Memory management of @event is the caller's responsibility - * (ownership is not taken). + * Creating a NULL MidiAction is okay, pass event=NULL and the action will + * simply do nothing until a set_event (for MIDI learning). */ MidiAction::MidiAction(size_t size, const byte* event) @@ -47,13 +43,6 @@ MidiAction::~MidiAction() delete[] _event.load(); } -/** Set the MIDI event to be emitted when the action executes. - * - * Returns pointer to old event (caller's responsibility to free if non-NULL). - * Safe to call concurrently with execute. - * - * Returns true on success. - */ bool MidiAction::set_event(size_t size, const byte* new_event) { @@ -71,42 +60,44 @@ MidiAction::set_event(size_t size, const byte* new_event) } } -/** Execute the action. - * - * Safe to call concurrently with set_event. - */ void MidiAction::execute(MIDISink* sink, Raul::TimeStamp time) { - const byte* const event = _event.load(); - - if (event) { - if (sink) { - sink->write_event(time, _size, event); - } - } else { - std::cerr << "NULL MIDI ACTION"; + const byte* const ev = _event.load(); + if (ev && sink) { + sink->write_event(time, _size, ev); } } void MidiAction::write_state(Sord::Model& model) { - using namespace Raul; - - Action::write_state(model); - - model.add_statement(rdf_id(model.world()), - Sord::Curie(model.world(), "rdf:type"), - Sord::Curie(model.world(), "machina:MidiAction")); + const uint8_t* ev = event(); + const uint8_t type = (ev[0] & 0xF0); + if (type == LV2_MIDI_MSG_NOTE_ON) { + model.add_statement( + rdf_id(model.world()), + Sord::URI(model.world(), MACHINA_URI_RDF "type"), + Sord::URI(model.world(), LV2_MIDI__NoteOn)); + } else if (type == LV2_MIDI_MSG_NOTE_OFF) { + model.add_statement( + rdf_id(model.world()), + Sord::URI(model.world(), MACHINA_URI_RDF "type"), + Sord::URI(model.world(), LV2_MIDI__NoteOff)); + } else { + std::cerr << "warning: Unable to serialise MIDI event" << std::endl; + } - // FIXME: Assumes note on/note off - std::cerr << "FIXME: AtomRDF" << std::endl; - /* - model.add_statement(rdf_id(model.world()), - Sord::Curie(model.world(), "machina:midiNote"), - AtomRDF::atom_to_node(model, Atom((int)(_event.get()[1])))); - */ + model.add_statement( + rdf_id(model.world()), + Sord::URI(model.world(), LV2_MIDI__noteNumber), + Sord::Literal::integer(model.world(), (int)ev[1])); + if (ev[2] != 64) { + model.add_statement( + rdf_id(model.world()), + Sord::URI(model.world(), LV2_MIDI__velocity), + Sord::Literal::integer(model.world(), (int)ev[2])); + } } } // namespace machina |