diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/JackDriver.cpp | 40 | ||||
-rw-r--r-- | src/engine/Machine.cpp | 2 | ||||
-rw-r--r-- | src/engine/MachineBuilder.cpp | 4 | ||||
-rw-r--r-- | src/engine/Problem.cpp | 9 | ||||
-rw-r--r-- | src/engine/SMFDriver.cpp | 19 | ||||
-rw-r--r-- | src/engine/machina/JackDriver.hpp | 1 | ||||
-rw-r--r-- | src/gui/MachinaCanvas.cpp | 2 | ||||
-rw-r--r-- | src/gui/main.cpp | 2 |
8 files changed, 36 insertions, 43 deletions
diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp index 5363a5a..ac24fc4 100644 --- a/src/engine/JackDriver.cpp +++ b/src/engine/JackDriver.cpp @@ -33,8 +33,9 @@ JackDriver::JackDriver(SharedPtr<Machine> machine) , _machine_changed(0) , _input_port(NULL) , _output_port(NULL) - , _frames_unit(TimeUnit::FRAMES, 48000.0) - , _cycle_time(1/48000.0, 120.0) + , _frames_unit(TimeUnit::FRAMES, 48000) + , _beats_unit(TimeUnit::BEATS, 19200) + , _cycle_time(48000, 120.0) , _bpm(120.0) , _quantization(0.0f) , _record_time(machine->time().unit()) @@ -188,7 +189,6 @@ JackDriver::write_event(Raul::TimeStamp time, size_t size, const byte* event) throw (std::logic_error) { -#if 0 if (!_output_port) return; @@ -205,8 +205,8 @@ JackDriver::write_event(Raul::TimeStamp time, return; } - const TickCount nframes = _cycle_time.length_ticks(); - const TickCount offset = _cycle_time.beats_to_ticks(time) + const TimeDuration nframes = _cycle_time.length_ticks(); + const TimeStamp offset = _cycle_time.beats_to_ticks(time) + _cycle_time.offset_ticks() - _cycle_time.start_ticks(); if ( ! (offset < _cycle_time.offset_ticks() + nframes)) { @@ -223,24 +223,21 @@ JackDriver::write_event(Raul::TimeStamp time, event, size, nframes); #else jack_midi_event_write( - jack_port_get_buffer(_output_port, nframes), offset, + jack_port_get_buffer(_output_port, nframes.ticks()), offset.ticks(), event, size); #endif } -#endif } void JackDriver::on_process(jack_nframes_t nframes) { -#if 0 _cycle_time.set_bpm(_bpm.get()); - TimeStamp start(TimeUnit(TimeUnit::FRAMES, 0)); - TimeDuration length(TimeUnit(TimeUnit::FRAMES, nframes)); - _cycle_time.set_offset(start); - _cycle_time.set_length(length); + TimeStamp start(_cycle_time.ticks_unit(), 0, 0); + TimeDuration length(_cycle_time.ticks_unit(), nframes, 0); + _cycle_time.set_slice(start, length); assert(_output_port); #ifdef JACK_MIDI_NEEDS_NFRAMES @@ -261,7 +258,6 @@ JackDriver::on_process(jack_nframes_t nframes) _last_machine->reset(_last_machine->time()); // Exit all active states _last_machine.reset(); // Cut our reference } - _cycle_time.set_start(start); _machine_changed.post(); // Signal we're done with it } @@ -291,7 +287,7 @@ JackDriver::on_process(jack_nframes_t nframes) // Machine didn't run at all (empty, or no initial states) if (run_dur_beats == TimeDuration(_frames_unit, 0, 0)) { machine->reset(machine->time()); // Try again next cycle - _cycle_time.set_start(TimeStamp(_frames_unit, 0, 0)); + _cycle_time.set_slice(TimeStamp(_frames_unit, 0, 0), run_dur_ticks); goto end; // Machine ran for portion of cycle (finished) @@ -301,18 +297,20 @@ JackDriver::on_process(jack_nframes_t nframes) machine->reset(machine->time()); - _cycle_time.set_start(TimeStamp(_frames_unit, 0, 0)); - _cycle_time.set_length(TimeDuration(_frames_unit, nframes - finish_offset.ticks())); + _cycle_time.set_slice(TimeStamp(_frames_unit, 0, 0), + TimeDuration(_frames_unit, nframes - finish_offset.ticks())); _cycle_time.set_offset(finish_offset); // Machine ran for entire cycle } else { if (machine->is_finished()) { machine->reset(machine->time()); - _cycle_time.set_start(TimeStamp(_frames_unit, 0, 0)); + _cycle_time.set_slice(TimeStamp(_frames_unit, 0, 0), + TimeStamp(_frames_unit, 0, 0)); } else { - _cycle_time.set_start( - _cycle_time.start_ticks() + _cycle_time.length_ticks()); + _cycle_time.set_slice( + _cycle_time.start_ticks() + _cycle_time.length_ticks(), + TimeStamp(_frames_unit, 0, 0)); } break; @@ -326,10 +324,10 @@ end: _last_machine = machine; if (_stop.pending()) { - _cycle_time.set_start(TimeStamp(_frames_unit, 0, 0)); + _cycle_time.set_slice(TimeStamp(_frames_unit, 0, 0), + TimeStamp(_frames_unit, 0, 0)); _stop.finish(); } -#endif } diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp index 99dd93e..4106a98 100644 --- a/src/engine/Machine.cpp +++ b/src/engine/Machine.cpp @@ -349,7 +349,7 @@ Machine::run(const Raul::TimeSlice& time) break; // Earliest active state ends this cycle - } else if (earliest->exit_time() <= cycle_end) { + } else if (time.beats_to_ticks(earliest->exit_time()) <= cycle_end) { this_time += earliest->exit_time() - _time; _time = time.ticks_to_beats( time.beats_to_ticks(earliest->exit_time())); diff --git a/src/engine/MachineBuilder.cpp b/src/engine/MachineBuilder.cpp index 180d843..f3d6387 100644 --- a/src/engine/MachineBuilder.cpp +++ b/src/engine/MachineBuilder.cpp @@ -65,15 +65,13 @@ MachineBuilder::is_delay_node(SharedPtr<Node> node) const void MachineBuilder::set_node_duration(SharedPtr<Node> node, Raul::TimeDuration d) const { -#if 0 - Raul::TimeStamp q_dur = Quantizer::quantize(_quantization, d); + Raul::TimeStamp q_dur = Quantizer::quantize(TimeStamp(d.unit(), _quantization), d); // Never quantize a note to duration 0 if (q_dur.is_zero() && ( node->enter_action() || node->exit_action() )) q_dur = _quantization; // Round up node->set_duration(q_dur); -#endif } diff --git a/src/engine/Problem.cpp b/src/engine/Problem.cpp index 0660d0c..5a6485f 100644 --- a/src/engine/Problem.cpp +++ b/src/engine/Problem.cpp @@ -50,7 +50,7 @@ Problem::Problem(TimeUnit unit, const std::string& target_midi, SharedPtr<Machin uint32_t delta_time; while (smf.read_event(4, buf, &ev_size, &delta_time) >= 0) { // time ignored -// _target.write_event(0, ev_size, buf); + _target.write_event(TimeStamp(_unit, 0.0), ev_size, buf); #if 0 //_target._length += delta_time / (double)smf.ppqn(); if ((buf[0] & 0xF0) == MIDI_CMD_NOTE_ON) { @@ -92,21 +92,20 @@ Problem::fitness(const Machine& const_machine) const static const unsigned ppqn = 19200; Raul::TimeSlice time(1.0/(double)ppqn, 120); - time.set_start(TimeStamp(_unit, 0, 0)); - time.set_length(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); - time.set_start(end); + time.set_slice(end, TimeStamp(_unit, 0, 0)); while (eval->n_notes() < _target.n_notes()) { machine.run(time); if (machine.is_finished()) machine.reset(time.start_ticks()); - time.set_start(end); + time.set_slice(end, TimeStamp(end.unit(), 0, 0)); } eval->compute(); diff --git a/src/engine/SMFDriver.cpp b/src/engine/SMFDriver.cpp index 6d23368..42dbcd6 100644 --- a/src/engine/SMFDriver.cpp +++ b/src/engine/SMFDriver.cpp @@ -79,8 +79,7 @@ SMFDriver::learn(const string& filename, unsigned track, double q, Raul::TimeDur SharedPtr<Machine> SMFDriver::learn(const string& filename, double q, Raul::TimeStamp max_duration) { -#if 0 - SharedPtr<Machine> m(new Machine(q.unit())); + SharedPtr<Machine> m(new Machine(max_duration.unit())); SharedPtr<MachineBuilder> builder = SharedPtr<MachineBuilder>(new MachineBuilder(m, q)); Raul::SMFReader reader; @@ -99,7 +98,6 @@ SMFDriver::learn(const string& filename, double q, Raul::TimeStamp max_duration) if (m->nodes().size() > 1) return m; else -#endif return SharedPtr<Machine>(); } @@ -114,27 +112,26 @@ SMFDriver::learn_track(SharedPtr<MachineBuilder> builder, const bool found_track = reader.seek_to_track(track); if (!found_track) return; -#if 0 - uint8_5 buf[4]; + + uint8_t buf[4]; uint32_t ev_size; uint32_t ev_delta_time; uint64_t t = 0; - uint64_t unquantized_t = 0; + double unquantized_t = 0; while (reader.read_event(4, buf, &ev_size, &ev_delta_time) >= 0) { unquantized_t += ev_delta_time; t = Raul::Quantizer::quantize(q, unquantized_t); - builder->set_time(t); + builder->set_time(TimeStamp(max_duration.unit(), (double)t)); - if ((!max_duration.is_zero()) && t > max_duration) + if ((!max_duration.is_zero()) && t > max_duration.to_double()) break; if (ev_size > 0) - builder->event(TimeStamp(t.unit(), 0, 0), ev_size, buf); + builder->event(TimeStamp(max_duration.unit(), 0, 0), ev_size, buf); } -#endif builder->resolve(); } @@ -145,7 +142,7 @@ SMFDriver::run(SharedPtr<Machine> machine, Raul::TimeStamp max_time) { // FIXME: unit kludge (tempo only) Raul::TimeSlice time(1.0/(double)_writer->unit().ppt(), 120); - time.set_length(time.beats_to_ticks(max_time)); + time.set_slice(TimeStamp(max_time.unit(), 0, 0), time.beats_to_ticks(max_time)); machine->set_sink(shared_from_this()); machine->run(time); } diff --git a/src/engine/machina/JackDriver.hpp b/src/engine/machina/JackDriver.hpp index 40c2868..5982f87 100644 --- a/src/engine/machina/JackDriver.hpp +++ b/src/engine/machina/JackDriver.hpp @@ -82,6 +82,7 @@ private: jack_port_t* _output_port; Raul::TimeUnit _frames_unit; + Raul::TimeUnit _beats_unit; Raul::TimeSlice _cycle_time; Raul::DoubleBuffer<double> _bpm; diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index 222f1a8..26c805b 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -95,7 +95,7 @@ MachinaCanvas::canvas_event(GdkEvent* event) string name = string("Note")+(char)(last++ +'0'); - TimeDuration dur(TimeUnit(TimeUnit::BEATS, 0), 1.0); + TimeDuration dur(machine->time().unit(), 1.0); SharedPtr<Machina::Node> node(new Machina::Node(dur, false)); SharedPtr<NodeView> view(new NodeView(_app->window(), shared_from_this(), node, name, x, y)); diff --git a/src/gui/main.cpp b/src/gui/main.cpp index e819ac2..8d17479 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -68,7 +68,7 @@ main(int argc, char** argv) #endif if (!machine) - machine = SharedPtr<Machine>(new Machine(TimeUnit(TimeUnit::BEATS, 0))); + machine = SharedPtr<Machine>(new Machine(TimeUnit(TimeUnit::BEATS, 19200))); // Build engine SharedPtr<Driver> driver; |