From cee33ba4c0859b117be94df6ccbf3eb756a850af Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 10 Feb 2007 07:30:56 +0000 Subject: Finished MIDI genericification. Work on MIDI learn. git-svn-id: http://svn.drobilla.net/lad/machina@299 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/JackDriver.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 6 deletions(-) (limited to 'src/engine/JackDriver.cpp') diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp index f6f0ea6..ff78520 100644 --- a/src/engine/JackDriver.cpp +++ b/src/engine/JackDriver.cpp @@ -15,15 +15,16 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "machina/JackDriver.hpp" - #include +#include "machina/JackDriver.hpp" +#include "machina/MidiAction.hpp" namespace Machina { JackDriver::JackDriver() - : _output_port(NULL) + : _input_port(NULL) + , _output_port(NULL) , _current_cycle_start(0) , _current_cycle_nframes(0) { @@ -36,6 +37,11 @@ JackDriver::attach(const std::string& client_name) Raul::JackDriver::attach(client_name, "debug"); if (jack_client()) { + _input_port = jack_port_register(jack_client(), + "out", + JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, + 0); + _output_port = jack_port_register(jack_client(), "out", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, @@ -47,7 +53,9 @@ JackDriver::attach(const std::string& client_name) void JackDriver::detach() { + jack_port_unregister(jack_client(), _input_port); jack_port_unregister(jack_client(), _output_port); + _input_port = NULL; _output_port = NULL; Raul::JackDriver::detach(); @@ -65,6 +73,47 @@ JackDriver::stamp_to_offset(Timestamp stamp) } +void +JackDriver::learn(SharedPtr node) +{ + _learn_enter_action = SharedPtr(new MidiAction(shared_from_this(), 4, NULL)); + _learn_exit_action = SharedPtr(new MidiAction(shared_from_this(), 4, NULL)); + _learn_node = node; +} + + +void +JackDriver::process_input(jack_nframes_t nframes) +{ + //if (_learn_node) { + void* jack_buffer = jack_port_get_buffer(_input_port, nframes); + const jack_nframes_t event_count = jack_midi_get_event_count(jack_buffer, nframes); + + for (jack_nframes_t i=0; i < event_count; ++i) { + jack_midi_event_t ev; + jack_midi_event_get(&ev, jack_buffer, i, nframes); + + std::cerr << "EVENT: " << (char)ev.buffer[0] << "\n"; + + } + //} +} + + +void +JackDriver::write_event(Timestamp time, + size_t size, + const byte* event) +{ + const FrameCount nframes = _current_cycle_nframes; + const FrameCount offset = stamp_to_offset(time); + + jack_midi_event_write( + jack_port_get_buffer(_output_port, nframes), offset, + event, size, nframes); +} + + void JackDriver::on_process(jack_nframes_t nframes) { @@ -79,10 +128,8 @@ JackDriver::on_process(jack_nframes_t nframes) bool machine_done = ! _machine->run(_current_cycle_nframes); - if (machine_done && _machine->time() == 0) { - _machine->reset(); + if (machine_done && _machine->is_finished()) return; - } if (!machine_done) { _current_cycle_start += _current_cycle_nframes; -- cgit v1.2.1