aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine/JackDriver.cpp28
-rw-r--r--src/engine/Machine.cpp8
-rw-r--r--src/engine/Node.cpp6
-rw-r--r--src/engine/Problem.cpp6
4 files changed, 27 insertions, 21 deletions
diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp
index 68aca43..b5aafe6 100644
--- a/src/engine/JackDriver.cpp
+++ b/src/engine/JackDriver.cpp
@@ -35,7 +35,7 @@ JackDriver::JackDriver(SharedPtr<Machine> machine)
, _output_port(NULL)
, _frames_unit(TimeUnit::FRAMES, 48000)
, _beats_unit(TimeUnit::BEATS, 19200)
- , _cycle_time(48000, 19200, 120.0)
+ , _cycle_time(48000, MACHINA_PPQN, 120.0)
, _bpm(120.0)
, _quantization(0.0f)
, _record_time(machine->time().unit())
@@ -124,7 +124,7 @@ void
JackDriver::process_input(SharedPtr<Machine> machine, const TimeSlice& time)
{
// We only actually read Jack input at the beginning of a cycle
- assert(time.offset_ticks().is_zero());
+ //assert(time.offset_ticks().is_zero());
assert(_input_port);
if (_recording.get()) {
@@ -235,19 +235,19 @@ JackDriver::on_process(jack_nframes_t nframes)
{
_cycle_time.set_bpm(_bpm.get());
- TimeStamp start(_cycle_time.ticks_unit(), 0, 0);
- TimeDuration length(_cycle_time.ticks_unit(), nframes, 0);
- _cycle_time.set_slice(start, length);
-
- _cycle_time.set_offset(TimeStamp(_cycle_time.ticks_unit(), 0, 0));
-
assert(_output_port);
#ifdef JACK_MIDI_NEEDS_NFRAMES
jack_midi_clear_buffer(jack_port_get_buffer(_output_port, nframes), nframes);
#else
jack_midi_clear_buffer(jack_port_get_buffer(_output_port, nframes));
#endif
-
+
+ TimeStamp length_ticks(TimeStamp(_cycle_time.ticks_unit(), nframes));
+ TimeStamp length_beats(_cycle_time.ticks_to_beats(length_ticks));
+
+ _cycle_time.set_length(length_ticks);
+ _cycle_time.set_offset(TimeStamp(_cycle_time.ticks_unit(), 0, 0));
+
/* Take a reference to machine here and use only it during the process
* cycle so _machine can be switched with set_machine during a cycle. */
SharedPtr<Machine> machine = _machine;
@@ -271,7 +271,7 @@ JackDriver::on_process(jack_nframes_t nframes)
machine->set_sink(shared_from_this());
if (_recording.get())
- _record_time += length;
+ _record_time += length_beats;
if (_stop.pending())
machine->reset(_cycle_time.start_beats());
@@ -286,15 +286,16 @@ JackDriver::on_process(jack_nframes_t nframes)
const TimeDuration run_dur_frames = _cycle_time.beats_to_ticks(run_dur);
// Machine didn't run at all (empty, or no initial states)
- if (run_dur_frames.ticks() == 0) {
+
+ if (run_dur.is_zero()) {
machine->reset(machine->time()); // Try again next cycle
_cycle_time.set_slice(TimeStamp(_cycle_time.ticks_unit(), 0, 0), run_dur_frames);
goto end;
// Machine ran for portion of cycle (finished)
- } else if (run_dur_frames < _cycle_time.length_ticks()) {
+ } else if (machine->is_finished()) {
const TimeStamp finish_offset = _cycle_time.offset_ticks() + run_dur_frames;
- assert(finish_offset < length);
+ assert(finish_offset < length_ticks);
machine->reset(machine->time());
@@ -319,7 +320,6 @@ JackDriver::on_process(jack_nframes_t nframes)
}
end:
-
/* Remember the last machine run, in case a switch happens and
* we need to finalize it next cycle. */
_last_machine = machine;
diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp
index 7530637..7dcac34 100644
--- a/src/engine/Machine.cpp
+++ b/src/engine/Machine.cpp
@@ -221,7 +221,7 @@ Machine::enter_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node> node)
* while all actions are still MIDI notes... */
size_t index = (rand() % MAX_ACTIVE_NODES);
for (size_t i=0; i < MAX_ACTIVE_NODES; ++i) {
- if (_active_nodes.at(index)== NULL) {
+ if (_active_nodes.at(index) == NULL) {
node->enter(sink, _time);
assert(node->is_active());
_active_nodes.at(index) = node;
@@ -290,9 +290,9 @@ Machine::exit_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node> node)
}
-/** Run the machine for @a nframes frames.
+/** Run the machine for a (real) time slice.
*
- * Returns the duration of time the machine actually ran (from 0 to nframes).
+ * Returns the duration of time the machine actually ran.
*
* Caller can check is_finished() to determine if the machine still has any
* active states. If not, time() will return the exact time stamp the
@@ -363,7 +363,7 @@ Machine::run(const Raul::TimeSlice& time)
}
}
-
+
//assert(this_time <= time.length_beats());
return this_time;
}
diff --git a/src/engine/Node.cpp b/src/engine/Node.cpp
index b9b7605..9ca4157 100644
--- a/src/engine/Node.cpp
+++ b/src/engine/Node.cpp
@@ -16,6 +16,7 @@
*/
#include <cassert>
+#include <iostream>
#include "raul/Atom.hpp"
#include "raul/AtomRDF.hpp"
#include "redlandmm/World.hpp"
@@ -25,6 +26,7 @@
#include "machina/ActionFactory.hpp"
using namespace Raul;
+using namespace std;
namespace Machina {
@@ -133,6 +135,8 @@ Node::enter(SharedPtr<MIDISink> sink, TimeStamp time)
_changed = true;
_is_active = true;
_enter_time = time;
+
+ cerr << "ENTERING " << this << endl;
if (sink && _enter_action)
_enter_action->execute(sink, time);
@@ -144,6 +148,8 @@ Node::exit(SharedPtr<MIDISink> sink, TimeStamp time)
{
assert(_is_active);
+ cerr << "EXITING " << this << endl;
+
if (sink && _exit_action)
_exit_action->execute(sink, time);
diff --git a/src/engine/Problem.cpp b/src/engine/Problem.cpp
index c5522e3..6de61a3 100644
--- a/src/engine/Problem.cpp
+++ b/src/engine/Problem.cpp
@@ -90,15 +90,15 @@ Problem::fitness(const Machine& const_machine) const
// FIXME: timing stuff here isn't right at all...
- static const unsigned ppqn = 19200;
+ static const unsigned ppqn = MACHINA_PPQN;
Raul::TimeSlice time(ppqn, ppqn, 120.0);
- time.set_slice(TimeStamp(_unit, 0, 0), TimeDuration(_unit, 2*ppqn));
+ time.set_slice(TimeStamp(_unit, 0, 0), TimeDuration(_unit, 2 * ppqn));
machine.run(time);
if (eval->n_notes() == 0)
return 0.0f; // bad dog
- TimeStamp end(_unit, time.start_ticks().ticks() + 2*ppqn);
+ TimeStamp end(_unit, time.start_ticks().ticks() + 2 * ppqn);
time.set_slice(end, TimeStamp(_unit, 0, 0));
while (eval->n_notes() < _target.n_notes()) {