aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-11-17 06:01:02 +0000
committerDavid Robillard <d@drobilla.net>2008-11-17 06:01:02 +0000
commita22ca975556ef1516302f5e559748f9a37dbcd99 (patch)
treeeb328b572987769284931e2d74474556d2725c80 /src/engine
parent3e3a237c0272d322d102e30b60ddea6dca69d077 (diff)
downloadmachina-a22ca975556ef1516302f5e559748f9a37dbcd99.tar.gz
machina-a22ca975556ef1516302f5e559748f9a37dbcd99.tar.bz2
machina-a22ca975556ef1516302f5e559748f9a37dbcd99.zip
Run. Sorta.
git-svn-id: http://svn.drobilla.net/lad/trunk/machina@1757 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/JackDriver.cpp17
-rw-r--r--src/engine/Machine.cpp18
-rw-r--r--src/engine/Problem.cpp2
-rw-r--r--src/engine/SMFDriver.cpp2
4 files changed, 20 insertions, 19 deletions
diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp
index ac24fc4..03a3de2 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, 120.0)
+ , _cycle_time(48000, 19200, 120.0)
, _bpm(120.0)
, _quantization(0.0f)
, _record_time(machine->time().unit())
@@ -238,6 +238,8 @@ JackDriver::on_process(jack_nframes_t nframes)
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
@@ -280,19 +282,18 @@ JackDriver::on_process(jack_nframes_t nframes)
goto end;
while (true) {
-
- const TimeDuration run_dur_beats = machine->run(_cycle_time);
- const TimeDuration run_dur_ticks = _cycle_time.beats_to_ticks(run_dur_beats);
+ const TimeDuration run_dur = machine->run(_cycle_time);
+ 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_beats == TimeDuration(_frames_unit, 0, 0)) {
+ if (run_dur_frames.ticks() == 0) {
machine->reset(machine->time()); // Try again next cycle
- _cycle_time.set_slice(TimeStamp(_frames_unit, 0, 0), run_dur_ticks);
+ _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_ticks < _cycle_time.length_ticks()) {
- const TimeStamp finish_offset = _cycle_time.offset_ticks() + run_dur_ticks;
+ } else if (run_dur_frames < _cycle_time.length_ticks()) {
+ const TimeStamp finish_offset = _cycle_time.offset_ticks() + run_dur_frames;
assert(finish_offset < length);
machine->reset(machine->time());
diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp
index 4106a98..7530637 100644
--- a/src/engine/Machine.cpp
+++ b/src/engine/Machine.cpp
@@ -34,7 +34,7 @@ Machine::Machine(TimeUnit unit)
: _active_nodes(MAX_ACTIVE_NODES, SharedPtr<Node>())
, _is_activated(false)
, _is_finished(false)
- , _time(unit)
+ , _time(unit, 0, 0)
{
}
@@ -49,7 +49,7 @@ Machine::Machine(const Machine& copy)
, _active_nodes(MAX_ACTIVE_NODES, SharedPtr<Node>())
, _is_activated(false)
, _is_finished(false)
- , _time(copy.time().unit())
+ , _time(copy.time())
, _sink(copy._sink)
{
map< SharedPtr<Node>, SharedPtr<Node> > replacements;
@@ -76,7 +76,7 @@ Machine::operator=(const Machine& other)
_active_nodes = std::vector< SharedPtr<Node> >(MAX_ACTIVE_NODES, SharedPtr<Node>());
_is_activated = false;
_is_finished = false;
- _time = 0;
+ _time = other._time;
_pending_learn = SharedPtr<LearnRequest>();
_sink = other._sink;
_nodes.clear();
@@ -181,7 +181,7 @@ Machine::reset(Raul::TimeStamp time)
_active_nodes.at(i).reset();
}
- _time = 0;
+ _time = TimeStamp(_time.unit(), 0, 0);
_is_finished = false;
}
@@ -307,7 +307,8 @@ Machine::run(const Raul::TimeSlice& time)
SharedPtr<Raul::MIDISink> sink = _sink.lock();
- const TimeStamp cycle_end = time.start_ticks() + time.length_ticks();
+ const TimeStamp cycle_end_frames = time.start_ticks() + time.length_ticks();
+ const TimeStamp cycle_end = time.ticks_to_beats(cycle_end_frames);
assert(_is_activated);
@@ -349,16 +350,15 @@ Machine::run(const Raul::TimeSlice& time)
break;
// Earliest active state ends this cycle
- } else if (time.beats_to_ticks(earliest->exit_time()) <= cycle_end) {
+ } else if (earliest->exit_time() <= cycle_end) {
this_time += earliest->exit_time() - _time;
- _time = time.ticks_to_beats(
- time.beats_to_ticks(earliest->exit_time()));
+ _time = earliest->exit_time();
exit_node(sink, earliest);
// Earliest active state ends in the future, done this cycle
} else {
_time = cycle_end;
- this_time = time.length_beats(); // ran the entire cycle
+ this_time = cycle_end; // ran the entire cycle
break;
}
diff --git a/src/engine/Problem.cpp b/src/engine/Problem.cpp
index 5a6485f..c5522e3 100644
--- a/src/engine/Problem.cpp
+++ b/src/engine/Problem.cpp
@@ -91,7 +91,7 @@ Problem::fitness(const Machine& const_machine) const
// FIXME: timing stuff here isn't right at all...
static const unsigned ppqn = 19200;
- Raul::TimeSlice time(1.0/(double)ppqn, 120);
+ Raul::TimeSlice time(ppqn, ppqn, 120.0);
time.set_slice(TimeStamp(_unit, 0, 0), TimeDuration(_unit, 2*ppqn));
machine.run(time);
diff --git a/src/engine/SMFDriver.cpp b/src/engine/SMFDriver.cpp
index 42dbcd6..f482652 100644
--- a/src/engine/SMFDriver.cpp
+++ b/src/engine/SMFDriver.cpp
@@ -141,7 +141,7 @@ void
SMFDriver::run(SharedPtr<Machine> machine, Raul::TimeStamp max_time)
{
// FIXME: unit kludge (tempo only)
- Raul::TimeSlice time(1.0/(double)_writer->unit().ppt(), 120);
+ Raul::TimeSlice time(machine->time().unit().ppt(), _writer->unit().ppt(), 120.0);
time.set_slice(TimeStamp(max_time.unit(), 0, 0), time.beats_to_ticks(max_time));
machine->set_sink(shared_from_this());
machine->run(time);