diff options
author | David Robillard <d@drobilla.net> | 2007-12-04 23:03:45 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-12-04 23:03:45 +0000 |
commit | 2ab01419f334b834710a41fd26a538df3522cf49 (patch) | |
tree | bd1c1f1662797d9ca50f9bd8eddb1b44908d1e37 /src/engine/JackDriver.cpp | |
parent | 1760218d029892fc9ba3b25e06479cce319f20a0 (diff) | |
download | machina-2ab01419f334b834710a41fd26a538df3522cf49.tar.gz machina-2ab01419f334b834710a41fd26a538df3522cf49.tar.bz2 machina-2ab01419f334b834710a41fd26a538df3522cf49.zip |
Fix stuck notes on stop.
git-svn-id: http://svn.drobilla.net/lad/machina@948 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/JackDriver.cpp')
-rw-r--r-- | src/engine/JackDriver.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp index 37bf20d..3517250 100644 --- a/src/engine/JackDriver.cpp +++ b/src/engine/JackDriver.cpp @@ -23,6 +23,7 @@ #include "jack_compat.h" using namespace Raul; +using namespace std; namespace Machina { @@ -117,8 +118,6 @@ JackDriver::process_input(SharedPtr<Machine> machine, const TimeSlice& time) assert(time.offset_ticks() == 0); assert(_input_port); - using namespace std; - if (_recording.get()) { const jack_nframes_t nframes = time.length_ticks(); @@ -245,7 +244,7 @@ JackDriver::on_process(jack_nframes_t nframes) if (_last_machine) { assert(!_last_machine.unique()); // Realtime, can't delete _last_machine->set_sink(shared_from_this()); - _last_machine->reset(); // Exit all active states + _last_machine->reset(_last_machine->time()); // Exit all active states _last_machine.reset(); // Cut our reference } _cycle_time.set_start(0); @@ -254,14 +253,17 @@ JackDriver::on_process(jack_nframes_t nframes) if (_recording.get()) _record_time += nframes; - + if (!machine) return; + if (_stop.pending()) + machine->reset(_cycle_time.start_beats()); + process_input(machine, _cycle_time); if (machine->is_empty() || !machine->is_activated()) - return; + goto end; while (true) { @@ -270,16 +272,16 @@ JackDriver::on_process(jack_nframes_t nframes) // Machine didn't run at all (empty, or no initial states) if (run_dur_beats == 0) { - machine->reset(); // Try again next cycle + machine->reset(machine->time()); // Try again next cycle _cycle_time.set_start(0); - return; + goto end; // Machine ran for portion of cycle (finished) } else if (run_dur_ticks < _cycle_time.length_ticks()) { const TickCount finish_offset = _cycle_time.offset_ticks() + run_dur_ticks; assert(finish_offset < nframes); - machine->reset(); + machine->reset(machine->time()); _cycle_time.set_start(0); _cycle_time.set_length(nframes - finish_offset); @@ -288,7 +290,7 @@ JackDriver::on_process(jack_nframes_t nframes) // Machine ran for entire cycle } else { if (machine->is_finished()) { - machine->reset(); + machine->reset(machine->time()); _cycle_time.set_start(0); } else { _cycle_time.set_start( @@ -302,17 +304,22 @@ JackDriver::on_process(jack_nframes_t nframes) /* Remember the last machine run, in case a switch happens and * we need to finalize it next cycle. */ _last_machine = machine; + +end: + if (_stop.pending()) { + _cycle_time.set_start(0); + _stop.finish(); + } } void -JackDriver::reset() +JackDriver::stop() { - /* FIXME: This should signal the audio thread and wait for it - * to exit all active states to resolve stuck notes, then reset. */ - _machine->deactivate(); - _machine->reset(); - _cycle_time.set_start(0); + if (recording()) + finish_record(); + + _stop(); // waits } |