aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/JackDriver.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-02-10 07:30:56 +0000
committerDavid Robillard <d@drobilla.net>2007-02-10 07:30:56 +0000
commitcee33ba4c0859b117be94df6ccbf3eb756a850af (patch)
treee7e69de57c531538b2ded16bac31c2c705bc0fa6 /src/engine/JackDriver.cpp
parent87c0a475bd76ca33883eeafc2a86bc89a84eec2f (diff)
downloadmachina-cee33ba4c0859b117be94df6ccbf3eb756a850af.tar.gz
machina-cee33ba4c0859b117be94df6ccbf3eb756a850af.tar.bz2
machina-cee33ba4c0859b117be94df6ccbf3eb756a850af.zip
Finished MIDI genericification.
Work on MIDI learn. git-svn-id: http://svn.drobilla.net/lad/machina@299 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/JackDriver.cpp')
-rw-r--r--src/engine/JackDriver.cpp59
1 files changed, 53 insertions, 6 deletions
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 <iostream>
+#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();
@@ -66,6 +74,47 @@ JackDriver::stamp_to_offset(Timestamp stamp)
void
+JackDriver::learn(SharedPtr<Node> node)
+{
+ _learn_enter_action = SharedPtr<MidiAction>(new MidiAction(shared_from_this(), 4, NULL));
+ _learn_exit_action = SharedPtr<MidiAction>(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)
{
//std::cerr << "======================================================\n";
@@ -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;