aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/machina
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/machina')
-rw-r--r--src/engine/machina/Engine.hpp7
-rw-r--r--src/engine/machina/Evolver.hpp3
-rw-r--r--src/engine/machina/JackDriver.hpp127
-rw-r--r--src/engine/machina/MachineBuilder.hpp74
-rw-r--r--src/engine/machina/Node.hpp5
-rw-r--r--src/engine/machina/Problem.hpp124
-rw-r--r--src/engine/machina/Recorder.hpp52
-rw-r--r--src/engine/machina/SMFDriver.hpp11
-rw-r--r--src/engine/machina/Schrodinbit.hpp45
9 files changed, 19 insertions, 429 deletions
diff --git a/src/engine/machina/Engine.hpp b/src/engine/machina/Engine.hpp
index 355a50f..a8a7c9d 100644
--- a/src/engine/machina/Engine.hpp
+++ b/src/engine/machina/Engine.hpp
@@ -18,8 +18,12 @@
#ifndef MACHINA_ENGINE_HPP
#define MACHINA_ENGINE_HPP
+#include <string>
+
#include <glibmm/ustring.h>
+
#include "raul/SharedPtr.hpp"
+
#include "machina/Driver.hpp"
#include "machina/Loader.hpp"
@@ -39,6 +43,9 @@ public:
Redland::World& rdf_world() { return _rdf_world; }
+ static SharedPtr<Driver> new_driver(const std::string& name,
+ SharedPtr<Machine> machine);
+
SharedPtr<Driver> driver() { return _driver; }
SharedPtr<Machine> machine() { return _driver->machine(); }
diff --git a/src/engine/machina/Evolver.hpp b/src/engine/machina/Evolver.hpp
index 013067d..b633bfc 100644
--- a/src/engine/machina/Evolver.hpp
+++ b/src/engine/machina/Evolver.hpp
@@ -18,10 +18,11 @@
#ifndef MACHINA_EVOLVER_HPP
#define MACHINA_EVOLVER_HPP
+#include "eugene/GAImpl.hpp"
#include "raul/SharedPtr.hpp"
#include "raul/Thread.hpp"
#include "raul/TimeStamp.hpp"
-#include "eugene/GAImpl.hpp"
+
#include "Schrodinbit.hpp"
namespace Eugene { template <typename G> class HybridMutation; }
diff --git a/src/engine/machina/JackDriver.hpp b/src/engine/machina/JackDriver.hpp
deleted file mode 100644
index 0b2851b..0000000
--- a/src/engine/machina/JackDriver.hpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/* This file is part of Machina.
- * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
- *
- * Machina is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Machina is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef MACHINA_JACKDRIVER_HPP
-#define MACHINA_JACKDRIVER_HPP
-
-#include <boost/enable_shared_from_this.hpp>
-
-#include <jack/jack.h>
-#include <jack/midiport.h>
-
-#include "raul/Command.hpp"
-#include "raul/DoubleBuffer.hpp"
-#include "raul/EventRingBuffer.hpp"
-#include "raul/Semaphore.hpp"
-#include "raul/SharedPtr.hpp"
-
-#include "Driver.hpp"
-#include "Machine.hpp"
-#include "Recorder.hpp"
-
-namespace Machina {
-
-class MidiAction;
-class Node;
-
-
-/** Realtime JACK Driver.
- *
- * "Ticks" are individual frames when running under this driver, and all code
- * in the processing context must be realtime safe (non-blocking).
- */
-class JackDriver : public Machina::Driver,
- public boost::enable_shared_from_this<JackDriver> {
-public:
- JackDriver(SharedPtr<Machine> machine = SharedPtr<Machine>());
- ~JackDriver();
-
- void attach(const std::string& client_name);
- void detach();
-
- void activate();
- void deactivate();
-
- void set_machine(SharedPtr<Machine> machine);
-
- void write_event(Raul::TimeStamp time,
- size_t size,
- const unsigned char* event) throw (std::logic_error);
-
- void set_bpm(double bpm) { _bpm.set(bpm); }
- void set_quantization(double q) { _quantization.set(q); }
-
- void stop();
-
- bool recording() { return _recording.get(); }
- void start_record(bool step);
- void finish_record();
-
- void start_transport() { jack_transport_start(_client); }
- void stop_transport() { jack_transport_stop(_client); }
-
- void rewind_transport() {
- jack_position_t zero;
- zero.frame = 0;
- zero.valid = (jack_position_bits_t)0;
- jack_transport_reposition(_client, &zero);
- }
-
- bool is_activated() const { return _is_activated; }
- bool is_attached() const { return (_client != NULL); }
- bool is_realtime() const { return _client && jack_is_realtime(_client); }
-
- jack_nframes_t sample_rate() const { return jack_get_sample_rate(_client); }
- jack_client_t* jack_client() const { return _client; }
-
-private:
- void process_input(SharedPtr<Machine> machine,
- const Raul::TimeSlice& time);
-
- static void jack_error_cb(const char* msg);
- static int jack_process_cb(jack_nframes_t nframes, void* me);
- static void jack_shutdown_cb(void* me);
-
- void on_process(jack_nframes_t nframes);
-
- jack_client_t* _client;
-
- Raul::Semaphore _machine_changed;
- SharedPtr<Machine> _last_machine;
-
- jack_port_t* _input_port;
- jack_port_t* _output_port;
-
- Raul::TimeUnit _frames_unit;
- Raul::TimeUnit _beats_unit;
- Raul::TimeSlice _cycle_time;
-
- Raul::DoubleBuffer<double> _bpm;
- Raul::DoubleBuffer<double> _quantization;
-
- Raul::Command _stop;
-
- Raul::TimeDuration _record_dur;
- Raul::AtomicInt _recording;
- SharedPtr<Recorder> _recorder;
- bool _is_activated;
-};
-
-
-} // namespace Machina
-
-#endif // MACHINA_JACKDRIVER_HPP
diff --git a/src/engine/machina/MachineBuilder.hpp b/src/engine/machina/MachineBuilder.hpp
deleted file mode 100644
index d98d91c..0000000
--- a/src/engine/machina/MachineBuilder.hpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/* This file is part of Machina.
- * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
- *
- * Machina is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Machina is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef MACHINA_MACHINEBUILDER_HPP
-#define MACHINA_MACHINEBUILDER_HPP
-
-#include <list>
-#include "raul/SharedPtr.hpp"
-
-namespace Machina {
-
-class Machine;
-class Node;
-
-
-class MachineBuilder {
-public:
- MachineBuilder(SharedPtr<Machine> machine,
- double quantization,
- bool step);
-
- void set_time(Raul::TimeStamp time) { _time = time; }
-
- void event(Raul::TimeStamp time_offset, size_t size, unsigned char* buf);
-
- void reset();
- void resolve();
-
- SharedPtr<Machine> finish();
-
-private:
- bool is_delay_node(SharedPtr<Node> node) const;
- void set_node_duration(SharedPtr<Node> node, Raul::TimeDuration d) const;
-
- SharedPtr<Node>
- connect_nodes(SharedPtr<Machine> m,
- SharedPtr<Node> tail, Raul::TimeStamp tail_end_time,
- SharedPtr<Node> head, Raul::TimeStamp head_start_time);
-
- typedef std::list<SharedPtr<Node> > ActiveList;
- ActiveList _active_nodes;
-
- typedef std::list<std::pair<Raul::TimeStamp, SharedPtr<Node> > > PolyList;
- PolyList _poly_nodes;
-
- double _quantization;
- Raul::TimeStamp _time;
-
- SharedPtr<Machine> _machine;
- SharedPtr<Node> _initial_node;
- SharedPtr<Node> _connect_node;
- Raul::TimeStamp _connect_node_end_time;
-
- bool _step;
-};
-
-
-} // namespace Machina
-
-#endif // MACHINA_MACHINEBUILDER_HPP
diff --git a/src/engine/machina/Node.hpp b/src/engine/machina/Node.hpp
index 7d90265..730c82b 100644
--- a/src/engine/machina/Node.hpp
+++ b/src/engine/machina/Node.hpp
@@ -18,10 +18,11 @@
#ifndef MACHINA_NODE_HPP
#define MACHINA_NODE_HPP
-#include "raul/SharedPtr.hpp"
#include "raul/List.hpp"
-#include "raul/Stateful.hpp"
#include "raul/MIDISink.hpp"
+#include "raul/SharedPtr.hpp"
+#include "raul/Stateful.hpp"
+
#include "Action.hpp"
#include "Schrodinbit.hpp"
diff --git a/src/engine/machina/Problem.hpp b/src/engine/machina/Problem.hpp
deleted file mode 100644
index 182d61a..0000000
--- a/src/engine/machina/Problem.hpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/* This file is part of Machina.
- * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
- *
- * Machina is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Machina is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#ifndef MACHINA_PROBLEM_HPP
-#define MACHINA_PROBLEM_HPP
-
-#include <map>
-#include "raul/MIDISink.hpp"
-#include "machina/Machine.hpp"
-#include "eugene/Problem.hpp"
-
-namespace Machina {
-
-
-class Problem : public Eugene::Problem<Machine> {
-public:
- Problem(TimeUnit unit, const std::string& target_midi, SharedPtr<Machine> seed = SharedPtr<Machine>());
- virtual ~Problem() {}
-
- void seed(SharedPtr<Machine> parent) { _seed = parent; }
-
- float fitness(const Machine& machine) const;
-
- bool fitness_less_than(float a, float b) const { return a < b; }
-
- void clear_fitness_cache() { _fitness.clear(); }
-
- boost::shared_ptr<Population>
- initial_population(size_t gene_size, size_t pop_size) const;
-
-private:
- size_t distance(const std::vector<uint8_t>& source,
- const std::vector<uint8_t>& target) const;
-
- // count
- /*struct FreqEvaluator : public Raul::MIDISink {
- Evaluator(const Problem& problem)
- : _problem(problem), _n_notes(0), _length(0) {
- for (uint8_t i=0; i < 128; ++i)
- _note_frequency[i] = 0;
- }
- void write_event(Raul::BeatTime time,
- size_t ev_size,
- const uint8_t* ev) throw (std::logic_error);
- void compute();
- const Problem& _problem;
-
- size_t n_notes() const { return _n_notes; }
-
- float _note_frequency[128];
- size_t _n_notes;
- double _length;
- };*/
-
- // distance
- /*struct Evaluator : public Raul::MIDISink {
- Evaluator(const Problem& problem) : _problem(problem) {}
- void write_event(Raul::BeatTime time,
- size_t ev_size,
- const uint8_t* ev) throw (std::logic_error);
- void compute();
- const Problem& _problem;
-
- size_t n_notes() const { return _notes.size(); }
-
- std::vector<uint8_t> _notes;
- float _counts[128];
- };*/
-
- struct Evaluator : public Raul::MIDISink {
- Evaluator(const Problem& problem) : _problem(problem), _order(4), _n_notes(0), _first_note(0) {
- for (uint8_t i=0; i < 128; ++i)
- _counts[i] = 0;
- }
- void write_event(TimeStamp time,
- size_t ev_size,
- const uint8_t* ev) throw (std::logic_error);
- void compute();
- const Problem& _problem;
-
- size_t n_notes() const { return _n_notes; }
- uint8_t first_note() const { return _first_note; }
-
- const uint32_t _order;
-
- std::string _read;
-
- typedef std::map<std::string, uint32_t> Patterns;
- Patterns _patterns;
- uint32_t _counts[128];
- size_t _n_notes;
- uint8_t _first_note;
- };
-
- TimeUnit _unit;
-
- Evaluator _target;
- SharedPtr<Machine> _seed;
-
- /// for levenshtein distance
- mutable std::vector< std::vector<uint16_t> > _matrix;
-
- /// memoization
- mutable std::map<Machine*, float> _fitness;
-};
-
-
-} // namespace Machina
-
-#endif // MACHINA_PROBLEM_HPP
diff --git a/src/engine/machina/Recorder.hpp b/src/engine/machina/Recorder.hpp
deleted file mode 100644
index 623dbfe..0000000
--- a/src/engine/machina/Recorder.hpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/* This file is part of Machina.
- * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
- *
- * Machina is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Machina is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef MACHINA_RECORDER_HPP
-#define MACHINA_RECORDER_HPP
-
-#include "raul/Slave.hpp"
-#include "raul/SharedPtr.hpp"
-#include "raul/EventRingBuffer.hpp"
-#include "Machine.hpp"
-
-namespace Machina {
-
-class MachineBuilder;
-
-
-class Recorder : public Raul::Slave {
-public:
- Recorder(size_t buffer_size, TimeUnit unit, double q, bool step);
-
- inline void write(Raul::TimeStamp time, size_t size, const unsigned char* buf) {
- _record_buffer.write(time, size, buf);
- }
-
- SharedPtr<Machine> finish();
-
-private:
- virtual void _whipped();
-
- TimeUnit _unit;
- Raul::EventRingBuffer _record_buffer;
- SharedPtr<MachineBuilder> _builder;
-};
-
-
-} // namespace Machina
-
-#endif // MACHINA_RECORDER_HPP
diff --git a/src/engine/machina/SMFDriver.hpp b/src/engine/machina/SMFDriver.hpp
index 8a22aaa..d66bfa3 100644
--- a/src/engine/machina/SMFDriver.hpp
+++ b/src/engine/machina/SMFDriver.hpp
@@ -20,12 +20,15 @@
#include <boost/enable_shared_from_this.hpp>
#include <glibmm/ustring.h>
-#include "raul/SharedPtr.hpp"
-#include "raul/SMFWriter.hpp"
+
#include "raul/SMFReader.hpp"
-#include "machina/types.hpp"
+#include "raul/SMFWriter.hpp"
+#include "raul/SharedPtr.hpp"
+
#include "machina/Driver.hpp"
-#include "machina/MachineBuilder.hpp"
+#include "machina/types.hpp"
+
+#include "MachineBuilder.hpp"
namespace Machina {
diff --git a/src/engine/machina/Schrodinbit.hpp b/src/engine/machina/Schrodinbit.hpp
deleted file mode 100644
index 7fe1825..0000000
--- a/src/engine/machina/Schrodinbit.hpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/* This file is part of Machina.
- * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
- *
- * Machina is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Machina is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#ifndef SCHRODINBIT_HPP
-#define SCHRODINBIT_HPP
-
-
-/** A flag which becomes false when it's value is observed
- */
-class Schrodinbit {
-public:
- Schrodinbit() : _flag(false) {}
-
- inline operator bool() {
- const bool ret = _flag;
- _flag = false;
- return ret;
- }
-
- inline bool operator=(bool flag) {
- _flag = flag;
- return flag;
- }
-
-private:
- bool _flag;
-};
-
-
-#endif // SCHRODINBIT_HPP
-