aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
l---------autowaf.py1
-rw-r--r--src/engine/Engine.cpp2
-rw-r--r--src/engine/Evolver.cpp10
-rw-r--r--src/engine/JackDriver.cpp45
-rw-r--r--src/engine/LearnRequest.cpp4
-rw-r--r--src/engine/MachineBuilder.cpp6
-rw-r--r--src/engine/Problem.cpp30
-rw-r--r--src/engine/Recorder.cpp2
-rw-r--r--src/engine/SMFDriver.cpp27
-rw-r--r--src/engine/machina/Driver.hpp2
-rw-r--r--src/engine/machina/Engine.hpp2
-rw-r--r--src/engine/machina/Evolver.hpp5
-rw-r--r--src/engine/machina/JackDriver.hpp9
-rw-r--r--src/engine/machina/LearnRequest.hpp6
-rw-r--r--src/engine/machina/MachineBuilder.hpp6
-rw-r--r--src/engine/machina/Mutation.hpp2
-rw-r--r--src/engine/machina/Problem.hpp7
-rw-r--r--src/engine/machina/Recorder.hpp2
-rw-r--r--src/engine/machina/SMFDriver.hpp6
-rw-r--r--src/engine/wscript33
-rw-r--r--src/gui/EdgeView.cpp2
-rw-r--r--src/gui/GladeXml.hpp5
-rw-r--r--src/gui/MachinaCanvas.cpp10
-rw-r--r--src/gui/MachinaGUI.cpp10
-rw-r--r--src/gui/MachinaGUI.hpp4
-rw-r--r--src/gui/NodePropertiesWindow.cpp5
-rw-r--r--src/gui/main.cpp4
-rw-r--r--src/gui/wscript44
l---------waf1
-rw-r--r--wscript66
30 files changed, 267 insertions, 91 deletions
diff --git a/autowaf.py b/autowaf.py
new file mode 120000
index 0000000..4410d0d
--- /dev/null
+++ b/autowaf.py
@@ -0,0 +1 @@
+../autowaf.py \ No newline at end of file
diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp
index 0724018..f25c4d4 100644
--- a/src/engine/Engine.cpp
+++ b/src/engine/Engine.cpp
@@ -67,7 +67,7 @@ Engine::import_machine(const Glib::ustring& uri)
* Safe to call while engine is processing.
*/
SharedPtr<Machine>
-Engine::import_midi(const Glib::ustring& uri, Raul::TimeStamp q, Raul::TimeDuration duration)
+Engine::import_midi(const Glib::ustring& uri, double q, Raul::TimeDuration duration)
{
SharedPtr<SMFDriver> file_driver(new SMFDriver());
SharedPtr<Machine> m = file_driver->learn(uri, q, duration);
diff --git a/src/engine/Evolver.cpp b/src/engine/Evolver.cpp
index 3cb2dd8..af126d6 100644
--- a/src/engine/Evolver.cpp
+++ b/src/engine/Evolver.cpp
@@ -16,9 +16,9 @@
*/
#include <iostream>
-#include "eugene/core/Mutation.hpp"
-#include "eugene/core/HybridMutation.hpp"
-#include "eugene/core/TournamentSelection.hpp"
+#include "eugene/Mutation.hpp"
+#include "eugene/HybridMutation.hpp"
+#include "eugene/TournamentSelection.hpp"
#include "machina/Evolver.hpp"
#include "machina/Mutation.hpp"
#include "machina/Problem.hpp"
@@ -30,8 +30,8 @@ using namespace boost;
namespace Machina {
-Evolver::Evolver(const string& target_midi, SharedPtr<Machine> seed)
- : _problem(new Problem(target_midi, seed))
+Evolver::Evolver(TimeUnit unit, const string& target_midi, SharedPtr<Machine> seed)
+ : _problem(new Problem(unit, target_midi, seed))
, _seed_fitness(-FLT_MAX)
{
SharedPtr<Eugene::HybridMutation<Machine> > m(new HybridMutation<Machine>());
diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp
index 809efb9..5363a5a 100644
--- a/src/engine/JackDriver.cpp
+++ b/src/engine/JackDriver.cpp
@@ -33,9 +33,10 @@ 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)
, _bpm(120.0)
- , _quantization(machine->time().unit())
+ , _quantization(0.0f)
, _record_time(machine->time().unit())
, _recording(0)
{
@@ -55,7 +56,7 @@ JackDriver::attach(const std::string& client_name)
if (jack_client()) {
- _cycle_time.set_tick_rate(1/(double)sample_rate());
+ //_cycle_time.set_tick_rate(1/(double)sample_rate());
_input_port = jack_port_register(jack_client(),
"in",
@@ -187,6 +188,7 @@ JackDriver::write_event(Raul::TimeStamp time,
size_t size,
const byte* event) throw (std::logic_error)
{
+#if 0
if (!_output_port)
return;
@@ -225,17 +227,20 @@ JackDriver::write_event(Raul::TimeStamp time,
event, size);
#endif
}
+#endif
}
void
JackDriver::on_process(jack_nframes_t nframes)
{
+#if 0
_cycle_time.set_bpm(_bpm.get());
- // (N.B. start time set at end of previous cycle)
- _cycle_time.set_offset(0);
- _cycle_time.set_length(nframes);
+ TimeStamp start(TimeUnit(TimeUnit::FRAMES, 0));
+ TimeDuration length(TimeUnit(TimeUnit::FRAMES, nframes));
+ _cycle_time.set_offset(start);
+ _cycle_time.set_length(length);
assert(_output_port);
#ifdef JACK_MIDI_NEEDS_NFRAMES
@@ -256,7 +261,7 @@ 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(0);
+ _cycle_time.set_start(start);
_machine_changed.post(); // Signal we're done with it
}
@@ -268,7 +273,7 @@ JackDriver::on_process(jack_nframes_t nframes)
machine->set_sink(shared_from_this());
if (_recording.get())
- _record_time += nframes;
+ _record_time += length;
if (_stop.pending())
machine->reset(_cycle_time.start_beats());
@@ -280,31 +285,31 @@ JackDriver::on_process(jack_nframes_t nframes)
while (true) {
- const BeatCount run_dur_beats = machine->run(_cycle_time);
- const TickCount run_dur_ticks = _cycle_time.beats_to_ticks(run_dur_beats);
+ const TimeDuration run_dur_beats = machine->run(_cycle_time);
+ const TimeDuration run_dur_ticks = _cycle_time.beats_to_ticks(run_dur_beats);
// Machine didn't run at all (empty, or no initial states)
- if (run_dur_beats == 0) {
+ if (run_dur_beats == TimeDuration(_frames_unit, 0, 0)) {
machine->reset(machine->time()); // Try again next cycle
- _cycle_time.set_start(0);
+ _cycle_time.set_start(TimeStamp(_frames_unit, 0, 0));
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);
+ const TimeStamp finish_offset = _cycle_time.offset_ticks() + run_dur_ticks;
+ assert(finish_offset < length);
machine->reset(machine->time());
- _cycle_time.set_start(0);
- _cycle_time.set_length(nframes - finish_offset);
+ _cycle_time.set_start(TimeStamp(_frames_unit, 0, 0));
+ _cycle_time.set_length(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(0);
+ _cycle_time.set_start(TimeStamp(_frames_unit, 0, 0));
} else {
_cycle_time.set_start(
_cycle_time.start_ticks() + _cycle_time.length_ticks());
@@ -321,9 +326,10 @@ end:
_last_machine = machine;
if (_stop.pending()) {
- _cycle_time.set_start(0);
+ _cycle_time.set_start(TimeStamp(_frames_unit, 0, 0));
_stop.finish();
}
+#endif
}
@@ -342,11 +348,10 @@ void
JackDriver::start_record()
{
// FIXME: Choose an appropriate maximum ringbuffer size
- _recorder = SharedPtr<Recorder>(new Recorder(
- 1024, (1.0/(double)sample_rate()) * (_bpm.get() / 60.0), _quantization.get()));
+ /*_recorder = SharedPtr<Recorder>(new Recorder(1024, _frames_unit, _quantization.get()));
_recorder->start();
_record_time = 0;
- _recording = 1;
+ _recording = 1;*/
}
diff --git a/src/engine/LearnRequest.cpp b/src/engine/LearnRequest.cpp
index 00401dc..782cfff 100644
--- a/src/engine/LearnRequest.cpp
+++ b/src/engine/LearnRequest.cpp
@@ -28,9 +28,9 @@ LearnRequest::finish(TimeStamp time)
_node->set_enter_action(_enter_action);
_node->set_exit_action(_exit_action);
- TimeDuration duration = Raul::Quantizer::quantize(_quantization, time - _start_time);
+ //TimeDuration duration = Raul::Quantizer::quantize(_quantization, time - _start_time);
- _node->set_duration(duration);
+ //_node->set_duration(duration);
}
diff --git a/src/engine/MachineBuilder.cpp b/src/engine/MachineBuilder.cpp
index 21280e0..180d843 100644
--- a/src/engine/MachineBuilder.cpp
+++ b/src/engine/MachineBuilder.cpp
@@ -29,7 +29,7 @@ using namespace Raul;
namespace Machina {
-MachineBuilder::MachineBuilder(SharedPtr<Machine> machine, Raul::TimeStamp q)
+MachineBuilder::MachineBuilder(SharedPtr<Machine> machine, double q)
: _quantization(q)
, _time(machine->time().unit()) // = 0
, _machine(machine)
@@ -63,8 +63,9 @@ MachineBuilder::is_delay_node(SharedPtr<Node> node) const
/** Set the duration of a node, with quantization.
*/
void
-MachineBuilder::set_node_duration(SharedPtr<Node> node, Raul::TimeStamp d) const
+MachineBuilder::set_node_duration(SharedPtr<Node> node, Raul::TimeDuration d) const
{
+#if 0
Raul::TimeStamp q_dur = Quantizer::quantize(_quantization, d);
// Never quantize a note to duration 0
@@ -72,6 +73,7 @@ MachineBuilder::set_node_duration(SharedPtr<Node> node, Raul::TimeStamp d) const
q_dur = _quantization; // Round up
node->set_duration(q_dur);
+#endif
}
diff --git a/src/engine/Problem.cpp b/src/engine/Problem.cpp
index daf3ace..0660d0c 100644
--- a/src/engine/Problem.cpp
+++ b/src/engine/Problem.cpp
@@ -27,15 +27,16 @@
#include "machina/Edge.hpp"
#include "raul/SMFReader.hpp"
#include "raul/midi_events.h"
-#include "eugene/core/Problem.hpp"
+#include "eugene/Problem.hpp"
using namespace std;
namespace Machina {
-Problem::Problem(const std::string& target_midi, SharedPtr<Machine> seed)
- : _target(*this)
+Problem::Problem(TimeUnit unit, const std::string& target_midi, SharedPtr<Machine> seed)
+ : _unit(unit)
+ , _target(*this)
, _seed(new Machine(*seed.get()))
{
Raul::SMFReader smf;
@@ -49,7 +50,7 @@ Problem::Problem(const std::string& target_midi, SharedPtr<Machine> seed)
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(0, ev_size, buf);
#if 0
//_target._length += delta_time / (double)smf.ppqn();
if ((buf[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
@@ -82,7 +83,7 @@ Problem::fitness(const Machine& const_machine) const
SharedPtr<Evaluator> eval(new Evaluator(*this));
- machine.reset(0.0f);
+ //machine.reset();
machine.deactivate();
machine.activate();
machine.set_sink(eval);
@@ -91,20 +92,21 @@ Problem::fitness(const Machine& const_machine) const
static const unsigned ppqn = 19200;
Raul::TimeSlice time(1.0/(double)ppqn, 120);
- time.set_start(0);
- time.set_length(2*ppqn);
+ time.set_start(TimeStamp(_unit, 0, 0));
+ time.set_length(TimeDuration(_unit, 2*ppqn));
machine.run(time);
if (eval->n_notes() == 0)
return 0.0f; // bad dog
- time.set_start(time.start_ticks() + 2*ppqn);
+ TimeStamp end(_unit, time.start_ticks().ticks() + 2*ppqn);
+ time.set_start(end);
while (eval->n_notes() < _target.n_notes()) {
machine.run(time);
if (machine.is_finished())
machine.reset(time.start_ticks());
- time.set_start(time.start_ticks() + 2*ppqn);
+ time.set_start(end);
}
eval->compute();
@@ -158,9 +160,9 @@ Problem::fitness(const Machine& const_machine) const
void
-Problem::Evaluator::write_event(Raul::BeatTime time,
- size_t ev_size,
- const uint8_t* ev) throw (std::logic_error)
+Problem::Evaluator::write_event(Raul::TimeStamp time,
+ size_t ev_size,
+ const uint8_t* ev) throw (std::logic_error)
{
if ((ev[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
@@ -217,11 +219,11 @@ Problem::initial_population(size_t gene_size, size_t pop_size) const
// FIXME: ignores _seed and builds based on MIDI
// evolution of the visible machine would be nice..
- SharedPtr<Machine> base = SharedPtr<Machine>(new Machine());
+ SharedPtr<Machine> base = SharedPtr<Machine>(new Machine(_unit));
for (uint8_t i=0; i < 128; ++i) {
if (_target._counts[i] > 0) {
//cout << "Initial note: " << (int)i << endl;
- SharedPtr<Node> node(new Node(1/2.0));
+ SharedPtr<Node> node(new Node(TimeDuration(_unit, 1/2.0)));
node->set_enter_action(ActionFactory::note_on(i));
node->set_exit_action(ActionFactory::note_off(i));
node->set_selector(true);
diff --git a/src/engine/Recorder.cpp b/src/engine/Recorder.cpp
index 302a66e..03ea7d0 100644
--- a/src/engine/Recorder.cpp
+++ b/src/engine/Recorder.cpp
@@ -26,7 +26,7 @@ using namespace Raul;
namespace Machina {
-Recorder::Recorder(size_t buffer_size, TimeUnit unit, TimeStamp q)
+Recorder::Recorder(size_t buffer_size, TimeUnit unit, double q)
: _unit(unit)
, _record_buffer(buffer_size)
, _builder(new MachineBuilder(SharedPtr<Machine>(new Machine(unit)), q))
diff --git a/src/engine/SMFDriver.cpp b/src/engine/SMFDriver.cpp
index cf4c9da..6d23368 100644
--- a/src/engine/SMFDriver.cpp
+++ b/src/engine/SMFDriver.cpp
@@ -46,9 +46,9 @@ SMFDriver::SMFDriver(SharedPtr<Machine> machine)
* @return the resulting machine.
*/
SharedPtr<Machine>
-SMFDriver::learn(const string& filename, unsigned track, Raul::TimeStamp q, Raul::TimeDuration max_duration)
+SMFDriver::learn(const string& filename, unsigned track, double q, Raul::TimeDuration max_duration)
{
- assert(q.unit() == max_duration.unit());
+ //assert(q.unit() == max_duration.unit());
SharedPtr<Machine> m(new Machine(max_duration.unit()));
SharedPtr<MachineBuilder> builder = SharedPtr<MachineBuilder>(new MachineBuilder(m, q));
Raul::SMFReader reader;
@@ -77,8 +77,9 @@ SMFDriver::learn(const string& filename, unsigned track, Raul::TimeStamp q, Raul
* This will result in one disjoint subgraph in the machine for each track.
*/
SharedPtr<Machine>
-SMFDriver::learn(const string& filename, Raul::TimeStamp q, Raul::TimeStamp max_duration)
+SMFDriver::learn(const string& filename, double q, Raul::TimeStamp max_duration)
{
+#if 0
SharedPtr<Machine> m(new Machine(q.unit()));
SharedPtr<MachineBuilder> builder = SharedPtr<MachineBuilder>(new MachineBuilder(m, q));
Raul::SMFReader reader;
@@ -98,6 +99,7 @@ SMFDriver::learn(const string& filename, Raul::TimeStamp q, Raul::TimeStamp max_
if (m->nodes().size() > 1)
return m;
else
+#endif
return SharedPtr<Machine>();
}
@@ -106,20 +108,22 @@ void
SMFDriver::learn_track(SharedPtr<MachineBuilder> builder,
Raul::SMFReader& reader,
unsigned track,
- Raul::TimeStamp q,
+ double q,
Raul::TimeDuration max_duration)
{
const bool found_track = reader.seek_to_track(track);
if (!found_track)
return;
+#if 0
+ uint8_5 buf[4];
+ uint32_t ev_size;
+ uint32_t ev_delta_time;
+
+ uint64_t t = 0;
+ uint64_t unquantized_t = 0;
- Raul::TimeStamp unquantized_t(q.unit(), 0, 0);
- Raul::TimeStamp t(q.unit(), 0, 0);
- unsigned char buf[4];
- uint32_t ev_size;
- Raul::TimeStamp ev_time(q.unit());
- while (reader.read_event(4, buf, &ev_size, &ev_time) >= 0) {
- unquantized_t += ev_time;
+ 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);
@@ -130,6 +134,7 @@ SMFDriver::learn_track(SharedPtr<MachineBuilder> builder,
if (ev_size > 0)
builder->event(TimeStamp(t.unit(), 0, 0), ev_size, buf);
}
+#endif
builder->resolve();
}
diff --git a/src/engine/machina/Driver.hpp b/src/engine/machina/Driver.hpp
index d087d88..f412574 100644
--- a/src/engine/machina/Driver.hpp
+++ b/src/engine/machina/Driver.hpp
@@ -34,7 +34,7 @@ public:
virtual void set_machine(SharedPtr<Machine> machine) { _machine = machine; }
virtual void set_bpm(double bpm) = 0;
- virtual void set_quantization(Raul::TimeStamp q) = 0;
+ virtual void set_quantization(double q) = 0;
virtual void activate() {}
virtual void deactivate() {}
diff --git a/src/engine/machina/Engine.hpp b/src/engine/machina/Engine.hpp
index 02a9fc6..92384a8 100644
--- a/src/engine/machina/Engine.hpp
+++ b/src/engine/machina/Engine.hpp
@@ -44,7 +44,7 @@ public:
SharedPtr<Machine> load_machine(const Glib::ustring& uri);
SharedPtr<Machine> import_machine(const Glib::ustring& uri);
- SharedPtr<Machine> import_midi(const Glib::ustring& uri, Raul::TimeStamp q, Raul::TimeDuration d);
+ SharedPtr<Machine> import_midi(const Glib::ustring& uri, double q, Raul::TimeDuration d);
void set_bpm(double bpm);
void set_quantization(double beat_fraction);
diff --git a/src/engine/machina/Evolver.hpp b/src/engine/machina/Evolver.hpp
index edf68db..1b847db 100644
--- a/src/engine/machina/Evolver.hpp
+++ b/src/engine/machina/Evolver.hpp
@@ -20,7 +20,8 @@
#include "raul/SharedPtr.hpp"
#include "raul/Thread.hpp"
-#include "eugene/core/GAImpl.hpp"
+#include "raul/TimeStamp.hpp"
+#include "eugene/GAImpl.hpp"
#include "Schrodinbit.hpp"
namespace Eugene { template <typename G> class HybridMutation; }
@@ -33,7 +34,7 @@ class Problem;
class Evolver : public Raul::Thread {
public:
- Evolver(const string& target_midi, SharedPtr<Machine> seed);
+ Evolver(Raul::TimeUnit unit, const string& target_midi, SharedPtr<Machine> seed);
void seed(SharedPtr<Machine> parent);
bool improvement() { return _improvement; }
diff --git a/src/engine/machina/JackDriver.hpp b/src/engine/machina/JackDriver.hpp
index 54c7b1a..40c2868 100644
--- a/src/engine/machina/JackDriver.hpp
+++ b/src/engine/machina/JackDriver.hpp
@@ -60,8 +60,8 @@ public:
size_t size,
const unsigned char* event) throw (std::logic_error);
- void set_bpm(double bpm) { _bpm.set(bpm); }
- void set_quantization(Raul::TimeStamp q) { _quantization.set(q); }
+ void set_bpm(double bpm) { _bpm.set(bpm); }
+ void set_quantization(double q) { _quantization.set(q); }
void stop();
@@ -81,10 +81,11 @@ private:
jack_port_t* _input_port;
jack_port_t* _output_port;
+ Raul::TimeUnit _frames_unit;
Raul::TimeSlice _cycle_time;
- Raul::DoubleBuffer<double> _bpm;
- Raul::DoubleBuffer<Raul::TimeStamp> _quantization;
+ Raul::DoubleBuffer<double> _bpm;
+ Raul::DoubleBuffer<double> _quantization;
Raul::Command _stop;
diff --git a/src/engine/machina/LearnRequest.hpp b/src/engine/machina/LearnRequest.hpp
index 4a65675..edc76c9 100644
--- a/src/engine/machina/LearnRequest.hpp
+++ b/src/engine/machina/LearnRequest.hpp
@@ -43,7 +43,7 @@ public:
return ret;
}
- void start(TimeStamp q, Raul::TimeStamp time)
+ void start(double q, Raul::TimeStamp time)
{ _started = true; _start_time = time; _quantization = q; }
void finish(TimeStamp time);
@@ -58,7 +58,7 @@ private:
LearnRequest(SharedPtr<Raul::Maid> maid, SharedPtr<Node> node)
: _started(false)
, _start_time(TimeUnit(TimeUnit::BEATS, 19200), 0, 0) // irrelevant
- , _quantization(TimeUnit(TimeUnit::BEATS, 19200), 1, 0) // irrelevant
+ , _quantization(0) // irrelevant
, _node(node)
, _enter_action(new MidiAction(4, NULL))
, _exit_action(new MidiAction(4, NULL))
@@ -69,7 +69,7 @@ private:
bool _started;
TimeStamp _start_time;
- TimeStamp _quantization;
+ double _quantization;
SharedPtr<Node> _node;
SharedPtr<MidiAction> _enter_action;
SharedPtr<MidiAction> _exit_action;
diff --git a/src/engine/machina/MachineBuilder.hpp b/src/engine/machina/MachineBuilder.hpp
index 4e0e28d..2c9d0a2 100644
--- a/src/engine/machina/MachineBuilder.hpp
+++ b/src/engine/machina/MachineBuilder.hpp
@@ -30,7 +30,7 @@ class Node;
class MachineBuilder {
public:
MachineBuilder(SharedPtr<Machine> machine,
- Raul::TimeStamp quantization);
+ double quantization);
void set_time(Raul::TimeStamp time) { _time = time; }
@@ -43,7 +43,7 @@ public:
private:
bool is_delay_node(SharedPtr<Node> node) const;
- void set_node_duration(SharedPtr<Node> node, Raul::TimeStamp d) const;
+ void set_node_duration(SharedPtr<Node> node, Raul::TimeDuration d) const;
SharedPtr<Node>
connect_nodes(SharedPtr<Machine> m,
@@ -56,7 +56,7 @@ private:
typedef std::list<std::pair<Raul::TimeStamp, SharedPtr<Node> > > PolyList;
PolyList _poly_nodes;
- Raul::TimeStamp _quantization;
+ double _quantization;
Raul::TimeStamp _time;
SharedPtr<Machine> _machine;
diff --git a/src/engine/machina/Mutation.hpp b/src/engine/machina/Mutation.hpp
index 628222b..6d97d29 100644
--- a/src/engine/machina/Mutation.hpp
+++ b/src/engine/machina/Mutation.hpp
@@ -21,7 +21,7 @@
#include "config.h"
#if HAVE_EUGENE
- #include "eugene/core/Mutation.hpp"
+ #include "eugene/Mutation.hpp"
#define SUPER : public Eugene::Mutation<Machine>
#else
#define SUPER
diff --git a/src/engine/machina/Problem.hpp b/src/engine/machina/Problem.hpp
index d487f46..9f15e09 100644
--- a/src/engine/machina/Problem.hpp
+++ b/src/engine/machina/Problem.hpp
@@ -23,13 +23,14 @@
#include <map>
#include "raul/MIDISink.hpp"
#include "machina/Machine.hpp"
+#include "eugene/Problem.hpp"
namespace Machina {
class Problem : public Eugene::Problem<Machine> {
public:
- Problem(const std::string& target_midi, SharedPtr<Machine> seed = SharedPtr<Machine>());
+ Problem(TimeUnit unit, const std::string& target_midi, SharedPtr<Machine> seed = SharedPtr<Machine>());
void seed(SharedPtr<Machine> parent) { _seed = parent; }
@@ -86,7 +87,7 @@ private:
for (uint8_t i=0; i < 128; ++i)
_counts[i] = 0;
}
- void write_event(Raul::BeatTime time,
+ void write_event(TimeStamp time,
size_t ev_size,
const uint8_t* ev) throw (std::logic_error);
void compute();
@@ -106,6 +107,8 @@ private:
uint8_t _first_note;
};
+ TimeUnit _unit;
+
Evaluator _target;
SharedPtr<Machine> _seed;
diff --git a/src/engine/machina/Recorder.hpp b/src/engine/machina/Recorder.hpp
index aa5040a..6a91ba6 100644
--- a/src/engine/machina/Recorder.hpp
+++ b/src/engine/machina/Recorder.hpp
@@ -30,7 +30,7 @@ class MachineBuilder;
class Recorder : public Raul::Slave {
public:
- Recorder(size_t buffer_size, TimeUnit unit, TimeStamp q);
+ Recorder(size_t buffer_size, TimeUnit unit, double q);
inline void write(Raul::TimeStamp time, size_t size, const unsigned char* buf) {
_record_buffer.write(time, size, buf);
diff --git a/src/engine/machina/SMFDriver.hpp b/src/engine/machina/SMFDriver.hpp
index 9cbef26..5e1e9f8 100644
--- a/src/engine/machina/SMFDriver.hpp
+++ b/src/engine/machina/SMFDriver.hpp
@@ -39,12 +39,12 @@ public:
SMFDriver(SharedPtr<Machine> machine = SharedPtr<Machine>());
SharedPtr<Machine> learn(const std::string& filename,
- Raul::TimeStamp q,
+ double q,
Raul::TimeDuration max_duration);
SharedPtr<Machine> learn(const std::string& filename,
unsigned track,
- Raul::TimeStamp q,
+ double q,
Raul::TimeDuration max_duration);
void run(SharedPtr<Machine> machine, Raul::TimeStamp max_time);
@@ -65,7 +65,7 @@ private:
void learn_track(SharedPtr<MachineBuilder> builder,
Raul::SMFReader& reader,
unsigned track,
- Raul::TimeStamp q,
+ double q,
Raul::TimeDuration max_duration);
};
diff --git a/src/engine/wscript b/src/engine/wscript
new file mode 100644
index 0000000..be489de
--- /dev/null
+++ b/src/engine/wscript
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+import Params
+import autowaf
+
+def build(bld):
+ core_source = '''
+ Action.cpp
+ ActionFactory.cpp
+ Edge.cpp
+ Engine.cpp
+ Evolver.cpp
+ JackDriver.cpp
+ LearnRequest.cpp
+ Loader.cpp
+ Machine.cpp
+ MachineBuilder.cpp
+ MidiAction.cpp
+ Mutation.cpp
+ Node.cpp
+ Problem.cpp
+ RaulJackDriver.cpp
+ Recorder.cpp
+ SMFDriver.cpp
+ '''
+
+ obj = bld.create_obj('cpp', 'shlib')
+ obj.source = core_source
+ obj.includes = ['.', '..']
+ obj.name = 'libmachina_engine'
+ obj.target = 'machina_engine'
+ core_libs = 'GLIBMM GTHREAD RAUL REDLANDMM JACK EUGENE'
+ autowaf.use_lib(bld, obj, core_libs)
+
diff --git a/src/gui/EdgeView.cpp b/src/gui/EdgeView.cpp
index fb9fb07..46d3e77 100644
--- a/src/gui/EdgeView.cpp
+++ b/src/gui/EdgeView.cpp
@@ -75,7 +75,7 @@ EdgeView::EdgeView(SharedPtr<Canvas> canvas,
double
EdgeView::length_hint() const
{
- return _edge->tail().lock()->duration() * 10;
+ return _edge->tail().lock()->duration().ticks() * 10;
}
diff --git a/src/gui/GladeXml.hpp b/src/gui/GladeXml.hpp
index 66e2a99..09ba044 100644
--- a/src/gui/GladeXml.hpp
+++ b/src/gui/GladeXml.hpp
@@ -19,6 +19,7 @@
#include <string>
#include <gtkmm.h>
#include <libglademm/xml.h>
+#include "config.h"
class GladeXml
{
@@ -31,13 +32,13 @@ public:
std::ifstream fs(glade_filename.c_str());
if (fs.fail()) { // didn't find it, check PKGDATADIR
fs.clear();
- glade_filename = PKGDATADIR;
+ glade_filename = MACHINA_DATA_DIR;
glade_filename += "/machina.glade";
fs.open(glade_filename.c_str());
if (fs.fail()) {
std::cerr << "Unable to find machina.glade in current directory or "
- << PKGDATADIR << "." << std::endl;
+ << MACHINA_DATA_DIR << "." << std::endl;
exit(EXIT_FAILURE);
}
fs.close();
diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp
index 717960e..222f1a8 100644
--- a/src/gui/MachinaCanvas.cpp
+++ b/src/gui/MachinaCanvas.cpp
@@ -17,6 +17,7 @@
#include <map>
#include "raul/SharedPtr.hpp"
+#include "raul/TimeStamp.hpp"
#include "machina/Node.hpp"
#include "machina/Machine.hpp"
#include "machina/Action.hpp"
@@ -27,6 +28,7 @@
#include "NodeView.hpp"
#include "EdgeView.hpp"
+using namespace Raul;
using namespace FlowCanvas;
@@ -57,11 +59,12 @@ MachinaCanvas::node_clicked(WeakPtr<NodeView> item, GdkEventButton* event)
SharedPtr<NodeView> last = _last_clicked.lock();
if (last) {
- if (node != last)
+ if (node != last) {
if (get_connection(last, node))
disconnect_node(last, node);
else
connect_node(last, node);
+ }
last->set_default_base_color();
_last_clicked.reset();
@@ -78,7 +81,7 @@ bool
MachinaCanvas::canvas_event(GdkEvent* event)
{
static int last = 0;
-
+
SharedPtr<Machina::Machine> machine = _app->machine();
if (!machine)
return false;
@@ -92,7 +95,8 @@ MachinaCanvas::canvas_event(GdkEvent* event)
string name = string("Note")+(char)(last++ +'0');
- SharedPtr<Machina::Node> node(new Machina::Node(1.0, false));
+ TimeDuration dur(TimeUnit(TimeUnit::BEATS, 0), 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/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp
index d7927df..761fb8d 100644
--- a/src/gui/MachinaGUI.cpp
+++ b/src/gui/MachinaGUI.cpp
@@ -44,6 +44,7 @@ using namespace Machina;
MachinaGUI::MachinaGUI(SharedPtr<Machina::Engine> engine)
: _refresh(false)
, _evolve(false)
+ , _unit(TimeUnit::BEATS, 19200)
, _engine(engine)
, _maid(new Raul::Maid(32))
{
@@ -285,7 +286,7 @@ void
MachinaGUI::evolve_toggled()
{
if (_evolve_button->get_active()) {
- _evolver = SharedPtr<Evolver>(new Evolver(_target_filename, _engine->machine()));
+ _evolver = SharedPtr<Evolver>(new Evolver(_unit, _target_filename, _engine->machine()));
_evolve = true;
stop_clicked();
_engine->driver()->set_machine(SharedPtr<Machine>());
@@ -535,7 +536,8 @@ MachinaGUI::menu_import_midi()
if (result == Gtk::RESPONSE_OK) {
SharedPtr<Machina::SMFDriver> file_driver(new Machina::SMFDriver());
- double length = length_sb->get_value_as_int();
+ double length_dbl = length_sb->get_value_as_int();
+ Raul::TimeStamp length(_unit, length_dbl);
SharedPtr<Machina::Machine> machine = file_driver->learn(dialog.get_filename(), 0.0, length);
@@ -574,8 +576,8 @@ MachinaGUI::menu_export_midi()
_engine->driver()->deactivate();
const SharedPtr<Machina::Machine> m = _engine->machine();
m->set_sink(file_driver->writer());
- file_driver->writer()->start(dialog.get_filename());
- file_driver->run(m, 32); // TODO: solve halting problem
+ file_driver->writer()->start(dialog.get_filename(), TimeStamp(_unit, 0.0));
+ file_driver->run(m, TimeStamp(_unit, 32.0)); // TODO: solve halting problem
m->set_sink(_engine->driver());
m->reset(m->time());
file_driver->writer()->finish();
diff --git a/src/gui/MachinaGUI.hpp b/src/gui/MachinaGUI.hpp
index 342cedf..c539bd0 100644
--- a/src/gui/MachinaGUI.hpp
+++ b/src/gui/MachinaGUI.hpp
@@ -90,10 +90,12 @@ protected:
string _save_uri;
string _target_filename;
+
+ Raul::TimeUnit _unit;
boost::shared_ptr<MachinaCanvas> _canvas;
boost::shared_ptr<Machina::Engine> _engine;
-
+
SharedPtr<Raul::Maid> _maid;
SharedPtr<Machina::Evolver> _evolver;
diff --git a/src/gui/NodePropertiesWindow.cpp b/src/gui/NodePropertiesWindow.cpp
index 9f2e77a..d74d4b5 100644
--- a/src/gui/NodePropertiesWindow.cpp
+++ b/src/gui/NodePropertiesWindow.cpp
@@ -64,7 +64,8 @@ NodePropertiesWindow::apply_clicked()
action->event()[1] = note;
}
- double duration = _duration_spinbutton->get_value();
+ double duration_dbl = _duration_spinbutton->get_value();
+ TimeStamp duration(TimeUnit(TimeUnit::BEATS, 19200), duration_dbl);
_node->set_duration(duration);
_node->set_changed();
}
@@ -102,7 +103,7 @@ NodePropertiesWindow::set_node(SharedPtr<Machina::Node> node)
} else {
_note_spinbutton->hide();
}
- _duration_spinbutton->set_value(node->duration());
+ _duration_spinbutton->set_value(node->duration().to_double());
}
diff --git a/src/gui/main.cpp b/src/gui/main.cpp
index 3fc80aa..e819ac2 100644
--- a/src/gui/main.cpp
+++ b/src/gui/main.cpp
@@ -45,6 +45,7 @@ main(int argc, char** argv)
SharedPtr<Machina::Machine> machine;
// Load machine, if given
+#if 0
if (argc >= 2) {
const string filename = argv[1];
cout << "Building machine from MIDI file " << filename << endl;
@@ -64,9 +65,10 @@ main(int argc, char** argv)
machine = Loader(rdf_world).load(filename);
}
}
+#endif
if (!machine)
- machine = SharedPtr<Machine>(new Machine());
+ machine = SharedPtr<Machine>(new Machine(TimeUnit(TimeUnit::BEATS, 0)));
// Build engine
SharedPtr<Driver> driver;
diff --git a/src/gui/wscript b/src/gui/wscript
new file mode 100644
index 0000000..3e461bf
--- /dev/null
+++ b/src/gui/wscript
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+import Params
+import autowaf
+
+def build(bld):
+ obj = bld.create_obj('cpp', 'shlib')
+ obj.source = '''
+ EdgeView.cpp
+ MachinaCanvas.cpp
+ MachinaGUI.cpp
+ NodePropertiesWindow.cpp
+ NodeView.cpp
+ '''
+
+ obj.includes = ['.', '..', '../engine']
+ obj.name = 'libmachina_gui'
+ obj.target = 'machina_gui'
+ obj.uselib_local = 'libmachina_engine'
+ autowaf.use_lib(bld, obj, '''
+ FLOWCANVAS
+ GLADEMM
+ GLIBMM
+ GNOMECANVASMM
+ GTKMM
+ RAUL
+ REDLANDMM
+ SIGCPP
+ EUGENE
+ ''')
+
+ # GUI runtime files
+ install_files('DATADIR', 'machina', 'machina.glade')
+ install_files('DATADIR', 'machina', 'machina.svg')
+
+ # Executable
+ obj = bld.create_obj('cpp', 'program')
+ obj.target = 'machina_gui'
+ obj.source = 'main.cpp'
+ obj.includes = ['.', '../engine']
+ obj.defines = 'VERSION=\\\"' + bld.env()['MACHINA_VERSION'] + '\\\"'
+ obj.uselib_local = 'libmachina_engine libmachina_gui'
+ autowaf.use_lib(bld, obj, 'GTHREAD GLIBMM REDLANDMM RAUL MACHINA EUGENE')
+
+ autowaf.build_wrapper(bld, 'machina.in', obj)
diff --git a/waf b/waf
new file mode 120000
index 0000000..9770e60
--- /dev/null
+++ b/waf
@@ -0,0 +1 @@
+../waf \ No newline at end of file
diff --git a/wscript b/wscript
new file mode 100644
index 0000000..0ef2f51
--- /dev/null
+++ b/wscript
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+import os
+import Params
+import autowaf
+
+# Version of this package (even if built as a child)
+MACHINA_VERSION = '0.5.0'
+
+# Variables for 'waf dist'
+APPNAME = 'machina'
+VERSION = MACHINA_VERSION
+
+# Mandatory variables
+srcdir = '.'
+blddir = 'build'
+
+def set_options(opt):
+ autowaf.set_options(opt)
+
+def configure(conf):
+ autowaf.configure(conf)
+ autowaf.check_tool(conf, 'compiler_cxx')
+ autowaf.check_pkg(conf, 'glibmm-2.4', destvar='GLIBMM', vnum='2.14.0', mandatory=True)
+ autowaf.check_pkg(conf, 'gthread-2.0', destvar='GTHREAD', vnum='2.14.0', mandatory=True)
+ autowaf.check_pkg(conf, 'gtkmm-2.4', destvar='GTKMM', vnum='2.11.12', mandatory=False)
+ autowaf.check_pkg(conf, 'jack', destvar='JACK', vnum='0.109.0', mandatory=True)
+ autowaf.check_pkg(conf, 'raul', destvar='RAUL', vnum='0.5.1', mandatory=True)
+ autowaf.check_pkg(conf, 'flowcanvas', destvar='FLOWCANVAS', vnum='0.5.1', mandatory=False)
+ autowaf.check_pkg(conf, 'libglademm-2.4', destvar='GLADEMM', vnum='2.6.0', mandatory=False)
+ autowaf.check_pkg(conf, 'redlandmm', destvar='REDLANDMM', vnum='0.0.0', mandatory=False)
+ autowaf.check_pkg(conf, 'eugene', destvar='EUGENE', vnum='0.0.0', mandatory=True)
+
+ # Check for posix_memalign (OSX, amazingly, doesn't have it)
+ fe = conf.create_function_enumerator()
+ fe.headers = ['stdlib.h']
+ fe.function = 'posix_memalign'
+ fe.define = 'HAVE_POSIX_MEMALIGN'
+ fe.run()
+
+ build_gui = conf.env['HAVE_GLADEMM'] == 1 and conf.env['HAVE_FLOWCANVAS'] == 1
+
+ conf.define('MACHINA_VERSION', MACHINA_VERSION)
+ conf.define('BUILD_GUI', build_gui)
+ if conf.env['BUNDLE']:
+ conf.define('MACHINA_DATA_DIR', os.path.normpath(
+ conf.env['DATADIRNAME'] + 'machina'))
+ else:
+ conf.define('MACHINA_DATA_DIR', os.path.normpath(
+ conf.env['DATADIR'] + 'machina'))
+
+ conf.write_config_header('config.h')
+
+ autowaf.print_summary(conf)
+ autowaf.display_header('Machina Configuration')
+ autowaf.display_msg("Jack", str(conf.env['HAVE_JACK'] == 1), 'YELLOW')
+ autowaf.display_msg("Build GUI", str(conf.env['BUILD_GUI'] == 1), 'YELLOW')
+ print
+
+def build(bld):
+ bld.add_subdirs('src/engine')
+
+ if bld.env()['BUILD_GUI']:
+ bld.add_subdirs('src/gui')
+
+ #bld.add_subdirs('src/machina')
+