aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/JackDriver.cpp6
-rw-r--r--src/engine/Machine.cpp16
-rw-r--r--src/engine/Makefile.am6
-rw-r--r--src/engine/SMFDriver.cpp26
-rw-r--r--src/engine/machina/Driver.hpp25
-rw-r--r--src/engine/machina/Engine.hpp11
-rw-r--r--src/engine/machina/JackDriver.hpp12
-rw-r--r--src/engine/machina/Makefile.am7
-rw-r--r--src/engine/machina/MidiDriver.hpp56
-rw-r--r--src/engine/machina/SMFDriver.hpp18
10 files changed, 96 insertions, 87 deletions
diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp
index 0261dd5..ee5a0d6 100644
--- a/src/engine/JackDriver.cpp
+++ b/src/engine/JackDriver.cpp
@@ -39,6 +39,12 @@ JackDriver::JackDriver(SharedPtr<Machine> machine)
}
+JackDriver::~JackDriver()
+{
+ detach();
+}
+
+
void
JackDriver::attach(const std::string& client_name)
{
diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp
index f76dd5c..844d2ce 100644
--- a/src/engine/Machine.cpp
+++ b/src/engine/Machine.cpp
@@ -22,6 +22,8 @@
#include "machina/Edge.hpp"
#include "machina/MidiAction.hpp"
+using namespace std;
+
namespace Machina {
@@ -231,8 +233,12 @@ Machine::write_state(Raul::RDFWriter& writer)
RdfId(RdfId::RESOURCE, "rdf:type"),
RdfId(RdfId::RESOURCE, "machina:Machine"));
+ size_t count = 0;
+
for (Nodes::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n) {
-
+
+ cerr << "Writing node " << count++ << " state." << endl;
+
(*n)->write_state(writer);
if ((*n)->is_initial()) {
@@ -246,11 +252,17 @@ Machine::write_state(Raul::RDFWriter& writer)
}
}
+ count = 0;
+
for (Nodes::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n) {
+
+ cerr << "Writing node " << count++ << " edges: ";
for (Node::Edges::const_iterator e = (*n)->outgoing_edges().begin();
e != (*n)->outgoing_edges().end(); ++e) {
+ cerr << ".";
+
(*e)->write_state(writer);
writer.write(RdfId(RdfId::RESOURCE, ""),
@@ -258,6 +270,8 @@ Machine::write_state(Raul::RDFWriter& writer)
(*e)->id());
}
+ cerr << endl;
+
}
}
diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am
index 74308fd..eab7970 100644
--- a/src/engine/Makefile.am
+++ b/src/engine/Makefile.am
@@ -5,7 +5,6 @@ lib_LTLIBRARIES = libmachina.la
libmachina_la_CXXFLAGS = @RAUL_CFLAGS@ @JACK_CFLAGS@ @GLIBMM_CFLAGS@
libmachina_la_LIBADD = @RAUL_LIBS@ @JACK_LIBS@ @GLIBMM_LIBS@
-
libmachina_la_SOURCES = \
Node.cpp \
Edge.cpp \
@@ -13,7 +12,10 @@ libmachina_la_SOURCES = \
Machine.cpp \
Loader.cpp \
MidiAction.cpp \
- JackDriver.cpp \
SMFDriver.cpp \
Engine.cpp \
LearnRequest.cpp
+
+if WITH_JACK
+ JackDriver.cpp
+endif
diff --git a/src/engine/SMFDriver.cpp b/src/engine/SMFDriver.cpp
index cdf2ad7..60ee1af 100644
--- a/src/engine/SMFDriver.cpp
+++ b/src/engine/SMFDriver.cpp
@@ -18,6 +18,7 @@
#include <list>
#include <iostream>
#include <glibmm/convert.h>
+#include <raul/SharedPtr.h>
#include <raul/midi_events.h>
#include <raul/SMFWriter.h>
#include <raul/SMFReader.h>
@@ -30,6 +31,13 @@ using namespace std;
namespace Machina {
+SMFDriver::SMFDriver(SharedPtr<Machine> machine)
+ : Driver(machine)
+{
+ _writer = SharedPtr<Raul::SMFWriter>(new Raul::SMFWriter());
+}
+
+
/** Learn a single track from the MIDI file at @a uri
*
* @track selects which track of the MIDI file to import, starting from 1.
@@ -43,7 +51,11 @@ SMFDriver::learn(const string& filename, unsigned track, Raul::BeatTime max_dura
SharedPtr<Machine> m(new Machine());
Raul::SMFReader reader;
- reader.open(filename);
+
+ if (!reader.open(filename)) {
+ cerr << "Unable to open MIDI file " << filename << endl;
+ return SharedPtr<Machine>();
+ }
if (track > reader.num_tracks())
return SharedPtr<Machine>();
@@ -67,7 +79,10 @@ SMFDriver::learn(const string& filename, Raul::BeatTime max_duration)
SharedPtr<Machine> m(new Machine());
Raul::SMFReader reader;
- reader.open(filename);
+ if (!reader.open(filename)) {
+ cerr << "Unable to open MIDI file " << filename << endl;
+ return SharedPtr<Machine>();
+ }
for (unsigned t=1; t <= reader.num_tracks(); ++t) {
learn_track(m, reader, t, max_duration);
@@ -87,7 +102,8 @@ SMFDriver::learn_track(SharedPtr<Machine> m,
Raul::BeatTime max_duration)
{
const bool found_track = reader.seek_to_track(track);
- assert(found_track);
+ if (!found_track)
+ return;
list<SharedPtr<Node> > active_nodes;
@@ -113,7 +129,7 @@ SMFDriver::learn_track(SharedPtr<Machine> m,
//cerr << "t = " << t << endl;
if (ev_size > 0) {
if ((buf[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
- cerr << "NOTE ON: " << (int)buf[1] << ", channel = " << (int)(buf[0] & 0x0F) << endl;
+ //cerr << "NOTE ON: " << (int)buf[1] << ", channel = " << (int)(buf[0] & 0x0F) << endl;
SharedPtr<Node> node(new Node());
node->add_enter_action(SharedPtr<Action>(new MidiAction(ev_size, buf)));
assert(connect_node_end_time <= t);
@@ -195,7 +211,7 @@ SMFDriver::learn_track(SharedPtr<Machine> m,
void
SMFDriver::run(SharedPtr<Machine> machine, Raul::BeatTime max_time)
{
- Raul::TimeSlice time(1.0/(double)_ppqn, 120);
+ Raul::TimeSlice time(1.0/(double)_writer->ppqn(), 120);
time.set_length(time.beats_to_ticks(max_time));
machine->set_sink(shared_from_this());
machine->run(time);
diff --git a/src/engine/machina/Driver.hpp b/src/engine/machina/Driver.hpp
index f2816ba..b900da0 100644
--- a/src/engine/machina/Driver.hpp
+++ b/src/engine/machina/Driver.hpp
@@ -15,22 +15,29 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef MACHINA_JACKDRIVER_HPP
-#define MACHINA_JACKDRIVER_HPP
+#ifndef MACHINA_DRIVER_HPP
+#define MACHINA_DRIVER_HPP
-#include <raul/JackDriver.h>
+#include <raul/MIDISink.h>
-namespace Machine {
+namespace Machina {
+class Machine;
-class JackDriver : public Raul::JackDriver {
+
+class Driver : public Raul::MIDISink {
public:
- JackDriver(SharedPtr<Machine> machine);
+ Driver(SharedPtr<Machine> machine) : _machine(machine) {}
+ virtual ~Driver() {}
- virtual void set_machine(SharedPtr<Machine> machine);
+ SharedPtr<Machine> machine() { return _machine; }
+ virtual void set_machine(SharedPtr<Machine> machine) { _machine = machine; }
+
+ virtual void set_bpm(double bpm) = 0;
+ virtual void set_quantization(double quantization) = 0;
-protected:
- virtual void on_process(jack_nframes_t nframes);
+ virtual void activate() {}
+ virtual void deactivate() {}
private:
SharedPtr<Machine> _machine;
diff --git a/src/engine/machina/Engine.hpp b/src/engine/machina/Engine.hpp
index 32fab23..82c21ba 100644
--- a/src/engine/machina/Engine.hpp
+++ b/src/engine/machina/Engine.hpp
@@ -20,22 +20,21 @@
#include <glibmm/ustring.h>
#include <raul/SharedPtr.h>
-#include "machina/JackDriver.hpp"
+#include "machina/Driver.hpp"
namespace Machina {
class Machine;
-class JackDriver;
class Engine {
public:
- Engine(SharedPtr<JackDriver> driver)
+ Engine(SharedPtr<Driver> driver)
: _driver(driver)
{ }
- SharedPtr<JackDriver> driver() { return _driver; }
- SharedPtr<Machine> machine() { return _driver->machine(); }
+ SharedPtr<Driver> driver() { return _driver; }
+ SharedPtr<Machine> machine() { return _driver->machine(); }
SharedPtr<Machine> load_machine(const Glib::ustring& uri);
SharedPtr<Machine> learn_midi(const Glib::ustring& uri);
@@ -44,7 +43,7 @@ public:
void set_quantization(double beat_fraction);
private:
- SharedPtr<JackDriver> _driver;
+ SharedPtr<Driver> _driver;
};
diff --git a/src/engine/machina/JackDriver.hpp b/src/engine/machina/JackDriver.hpp
index 0754741..13005c0 100644
--- a/src/engine/machina/JackDriver.hpp
+++ b/src/engine/machina/JackDriver.hpp
@@ -18,14 +18,15 @@
#ifndef MACHINA_JACKDRIVER_HPP
#define MACHINA_JACKDRIVER_HPP
+#include <boost/enable_shared_from_this.hpp>
#include <raul/JackDriver.h>
#include <raul/SharedPtr.h>
#include <raul/DoubleBuffer.h>
#include <raul/Semaphore.h>
#include <jack/midiport.h>
#include "Machine.hpp"
-#include "MidiDriver.hpp"
-#include <boost/enable_shared_from_this.hpp>
+#include "Driver.hpp"
+
namespace Machina {
@@ -38,15 +39,18 @@ class Node;
* "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 Raul::JackDriver, public Machina::MidiDriver,
+class JackDriver : public Raul::JackDriver,
+ public Machina::Driver,
public boost::enable_shared_from_this<JackDriver> {
public:
JackDriver(SharedPtr<Machine> machine = SharedPtr<Machine>());
void attach(const std::string& client_name);
void detach();
+
+ void activate() { Raul::JackDriver::activate(); }
+ void deactivate() { Raul::JackDriver::deactivate(); }
- SharedPtr<Machine> machine() { return _machine; }
void set_machine(SharedPtr<Machine> machine);
void write_event(Raul::BeatTime time,
diff --git a/src/engine/machina/Makefile.am b/src/engine/machina/Makefile.am
index 4501028..ff8eab5 100644
--- a/src/engine/machina/Makefile.am
+++ b/src/engine/machina/Makefile.am
@@ -7,8 +7,11 @@ libmachinainclude_HEADERS = \
Edge.hpp \
Machine.hpp \
Loader.hpp \
- JackDriver.hpp \
MidiAction.hpp \
- MidiDriver.hpp \
+ Driver.hpp \
LearnRequest.hpp \
Engine.hpp
+
+if WITH_JACK
+ JackDriver.hpp
+endif
diff --git a/src/engine/machina/MidiDriver.hpp b/src/engine/machina/MidiDriver.hpp
deleted file mode 100644
index a4d712c..0000000
--- a/src/engine/machina/MidiDriver.hpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/* This file is part of Machina.
- * Copyright (C) 2007 Dave 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_MIDIDRIVER_HPP
-#define MACHINA_MIDIDRIVER_HPP
-
-#include <raul/TimeSlice.h>
-#include "machina/types.hpp"
-
-namespace Machina {
-
-class Node;
-
-
-class MidiDriver : public Raul::MIDISink {
-public:
- virtual ~MidiDriver() {}
-
- /** Emit a MIDI event at the given time */
- /*virtual void write_event(Raul::BeatTime time,
- size_t size,
- const unsigned char* event) = 0;
- */
-
- /** Beginning of current cycle in absolute time.
- */
- //virtual Raul::TickTime cycle_start() = 0;
-
- /** Length of current cycle in ticks.
- *
- * A "tick" is the smallest recognizable unit of (discrete) time.
- * Ticks could be single audio frames, MIDI clock at a certain ppqn, etc.
- */
- //virtual Raul::TickCount cycle_length() = 0;
-
-};
-
-
-} // namespace Machina
-
-#endif // MACHINA_MIDIDRIVER_HPP
-
diff --git a/src/engine/machina/SMFDriver.hpp b/src/engine/machina/SMFDriver.hpp
index 3e74726..0d58db3 100644
--- a/src/engine/machina/SMFDriver.hpp
+++ b/src/engine/machina/SMFDriver.hpp
@@ -24,7 +24,7 @@
#include <raul/SMFWriter.h>
#include <raul/SMFReader.h>
#include "machina/types.hpp"
-#include "machina/MidiDriver.hpp"
+#include "machina/Driver.hpp"
namespace Machina {
@@ -32,15 +32,29 @@ class Node;
class Machine;
-class SMFDriver : public Raul::SMFWriter,
+class SMFDriver : public Driver,
public boost::enable_shared_from_this<SMFDriver> {
public:
+ SMFDriver(SharedPtr<Machine> machine = SharedPtr<Machine>());
+
SharedPtr<Machine> learn(const std::string& filename, Raul::BeatTime max_duration=0);
SharedPtr<Machine> learn(const std::string& filename, unsigned track, Raul::BeatTime max_duration=0);
void run(SharedPtr<Machine> machine, Raul::BeatTime max_time);
+
+ void write_event(Raul::BeatTime time,
+ size_t ev_size,
+ const unsigned char* ev) throw (std::logic_error)
+ { _writer->write_event(time, ev_size, ev); }
+
+ void set_bpm(double /*bpm*/) { }
+ void set_quantization(double /*quantization*/) { }
+
+ SharedPtr<Raul::SMFWriter> writer() { return _writer; }
private:
+ SharedPtr<Raul::SMFWriter> _writer;
+
void learn_track(SharedPtr<Machine> machine,
Raul::SMFReader& reader,
unsigned track,