aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/JackDriver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/JackDriver.cpp')
-rw-r--r--src/engine/JackDriver.cpp147
1 files changed, 68 insertions, 79 deletions
diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp
index 5319d53..d13bbdd 100644
--- a/src/engine/JackDriver.cpp
+++ b/src/engine/JackDriver.cpp
@@ -178,91 +178,76 @@ JackDriver::set_machine(SharedPtr<Machine> machine)
}
void
-JackDriver::process_input(SharedPtr<Machine> machine,
- const Raul::TimeSlice& time)
+JackDriver::read_input_recording(SharedPtr<Machine> machine,
+ const Raul::TimeSlice& time)
{
- // We only actually read Jack input at the beginning of a cycle
- //assert(time.offset_ticks().is_zero());
- assert(_input_port);
-
- if (_recording) {
-
- const jack_nframes_t nframes = time.length_ticks().ticks();
- void* jack_buffer = jack_port_get_buffer(_input_port,
- nframes);
- const jack_nframes_t event_count = jack_midi_get_event_count(
- jack_buffer);
-
- for (jack_nframes_t i = 0; i < event_count; ++i) {
- jack_midi_event_t ev;
- jack_midi_event_get(&ev, jack_buffer, i);
-
- const TimeStamp rel_time_frames = TimeStamp(_frames_unit, ev.time);
- const TimeStamp time_frames = _record_dur + rel_time_frames;
- _recorder->write(time.ticks_to_beats(
- time_frames), ev.size, ev.buffer);
- }
+ const jack_nframes_t nframes = time.length_ticks().ticks();
+ void* buf = jack_port_get_buffer(_input_port, nframes);
+ const jack_nframes_t n_events = jack_midi_get_event_count(buf);
+
+ for (jack_nframes_t i = 0; i < n_events; ++i) {
+ jack_midi_event_t ev;
+ jack_midi_event_get(&ev, buf, i);
+
+ const TimeStamp rel_time_frames = TimeStamp(_frames_unit, ev.time);
+ const TimeStamp time_frames = _record_dur + rel_time_frames;
+ _recorder->write(time.ticks_to_beats(
+ time_frames), ev.size, ev.buffer);
+ }
- if (event_count > 0) {
- _recorder->whip();
- }
+ if (n_events > 0) {
+ _recorder->whip();
+ }
- _record_dur += time.length_ticks();
+ _record_dur += time.length_ticks();
+}
- } else {
+void
+JackDriver::read_input_playing(SharedPtr<Machine> machine,
+ const Raul::TimeSlice& time)
+{
+ const jack_nframes_t nframes = time.length_ticks().ticks();
+ void* buf = jack_port_get_buffer(_input_port, nframes);
+ const jack_nframes_t n_events = jack_midi_get_event_count(buf);
+
+ for (jack_nframes_t i = 0; i < n_events; ++i) {
+ jack_midi_event_t ev;
+ jack_midi_event_get(&ev, buf, i);
+
+ if (ev.buffer[0] == 0x90) {
+ const SharedPtr<LearnRequest> learn = machine->pending_learn();
+ if (learn) {
+ learn->enter_action()->set_event(ev.size, ev.buffer);
+ learn->start(_quantization.get(),
+ TimeStamp(TimeUnit::frames(sample_rate()),
+ jack_last_frame_time(_client)
+ + ev.time, 0));
+ }
- const jack_nframes_t nframes = time.length_ticks().ticks();
-
- void* jack_buffer = jack_port_get_buffer(_input_port,nframes);
-
- const jack_nframes_t event_count = jack_midi_get_event_count(
- jack_buffer);
-
- for (jack_nframes_t i = 0; i < event_count; ++i) {
- jack_midi_event_t ev;
- jack_midi_event_get(&ev, jack_buffer, i);
-
- if (ev.buffer[0] == 0x90) {
-
- const SharedPtr<LearnRequest> learn = machine->pending_learn();
- if (learn) {
- learn->enter_action()->set_event(ev.size, ev.buffer);
- learn->start(_quantization.get(),
- TimeStamp(TimeUnit::frames(sample_rate()),
- jack_last_frame_time(_client)
- + ev.time, 0));
- }
-
- } else if (ev.buffer[0] == 0x80) {
-
- const SharedPtr<LearnRequest> learn = machine->pending_learn();
-
- if (learn) {
- if (learn->started()) {
- learn->exit_action()->set_event(ev.size, ev.buffer);
- learn->finish(
- TimeStamp(TimeUnit::frames(sample_rate()),
- jack_last_frame_time(_client) + ev.time,
- 0));
-
- const uint64_t id = Stateful::next_id();
- write_set(_updates, id,
- URIs::instance().rdf_type,
- _forge.make_urid(URIs::instance().
- machina_MidiAction));
- write_set(_updates, learn->node()->id(),
- URIs::instance().machina_enter_action,
- _forge.make((int32_t)id));
- write_set(_updates, id,
- URIs::instance().machina_note_number,
- _forge.make((int32_t)ev.buffer[1]));
-
- machine->clear_pending_learn();
- }
- }
+ } else if (ev.buffer[0] == 0x80) {
+ const SharedPtr<LearnRequest> learn = machine->pending_learn();
+ if (learn && learn->started()) {
+ learn->exit_action()->set_event(ev.size, ev.buffer);
+ learn->finish(
+ TimeStamp(TimeUnit::frames(sample_rate()),
+ jack_last_frame_time(_client) + ev.time,
+ 0));
+
+ const uint64_t id = Stateful::next_id();
+ write_set(_updates, id,
+ URIs::instance().rdf_type,
+ _forge.make_urid(URIs::instance().
+ machina_MidiAction));
+ write_set(_updates, learn->node()->id(),
+ URIs::instance().machina_enter_action,
+ _forge.make((int32_t)id));
+ write_set(_updates, id,
+ URIs::instance().machina_note_number,
+ _forge.make((int32_t)ev.buffer[1]));
+
+ machine->clear_pending_learn();
}
}
-
}
}
@@ -359,7 +344,11 @@ JackDriver::on_process(jack_nframes_t nframes)
machine->reset(_context.sink(), _context.time().start_beats());
}
- process_input(machine, _context.time());
+ if (_recording) {
+ read_input_recording(machine, _context.time());
+ } else {
+ read_input_playing(machine, _context.time());
+ }
if (machine->is_empty() || !machine->is_activated()) {
goto end;