aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/machina
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-03-31 05:28:01 +0000
committerDavid Robillard <d@drobilla.net>2007-03-31 05:28:01 +0000
commitf8883a56e44a42e97ca84392fdbff61e11540fcd (patch)
tree745eef6b5685b9f668c48b36ae6c761bee49b271 /src/engine/machina
parentdd6be02a7478225f19f02432919b64b96b733172 (diff)
downloadmachina-f8883a56e44a42e97ca84392fdbff61e11540fcd.tar.gz
machina-f8883a56e44a42e97ca84392fdbff61e11540fcd.tar.bz2
machina-f8883a56e44a42e97ca84392fdbff61e11540fcd.zip
Realtime MIDI recording.
git-svn-id: http://svn.drobilla.net/lad/machina@383 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/machina')
-rw-r--r--src/engine/machina/Driver.hpp4
-rw-r--r--src/engine/machina/JackDriver.hpp11
-rw-r--r--src/engine/machina/MachineBuilder.hpp69
-rw-r--r--src/engine/machina/Makefile.am4
-rw-r--r--src/engine/machina/Recorder.hpp53
-rw-r--r--src/engine/machina/SMFDriver.hpp28
6 files changed, 153 insertions, 16 deletions
diff --git a/src/engine/machina/Driver.hpp b/src/engine/machina/Driver.hpp
index a1a38a2..bf4d2be 100644
--- a/src/engine/machina/Driver.hpp
+++ b/src/engine/machina/Driver.hpp
@@ -39,6 +39,10 @@ public:
virtual void activate() {}
virtual void deactivate() {}
+ virtual bool recording() { return false; }
+ virtual void start_record() {}
+ virtual void finish_record() {}
+
protected:
SharedPtr<Machine> _machine;
};
diff --git a/src/engine/machina/JackDriver.hpp b/src/engine/machina/JackDriver.hpp
index a048c0c..47b718d 100644
--- a/src/engine/machina/JackDriver.hpp
+++ b/src/engine/machina/JackDriver.hpp
@@ -22,11 +22,12 @@
#include <raul/JackDriver.h>
#include <raul/SharedPtr.h>
#include <raul/DoubleBuffer.h>
+#include <raul/MIDIRingBuffer.h>
#include <raul/Semaphore.h>
#include <jack/midiport.h>
#include "Machine.hpp"
#include "Driver.hpp"
-
+#include "Recorder.hpp"
namespace Machina {
@@ -61,6 +62,10 @@ public:
void set_bpm(double bpm) { _bpm.set(bpm); }
void set_quantization(double quantization) { _quantization.set(quantization); }
+ bool recording() { return _recording.get(); }
+ void start_record();
+ void finish_record();
+
private:
void process_input(SharedPtr<Machine> machine,
const Raul::TimeSlice& time);
@@ -76,6 +81,10 @@ private:
Raul::DoubleBuffer<double> _bpm;
Raul::DoubleBuffer<double> _quantization;
+
+ Raul::TickTime _record_time;
+ Raul::AtomicInt _recording;
+ SharedPtr<Recorder> _recorder;
};
diff --git a/src/engine/machina/MachineBuilder.hpp b/src/engine/machina/MachineBuilder.hpp
new file mode 100644
index 0000000..a01ebd2
--- /dev/null
+++ b/src/engine/machina/MachineBuilder.hpp
@@ -0,0 +1,69 @@
+/* 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_MACHINEBUILDER_HPP
+#define MACHINA_MACHINEBUILDER_HPP
+
+#include <list>
+#include <raul/types.h>
+#include <raul/SharedPtr.h>
+
+namespace Machina {
+
+class Machine;
+class Node;
+
+
+class MachineBuilder {
+public:
+ MachineBuilder(SharedPtr<Machine> machine);
+
+ void set_time(Raul::BeatTime time) { _time = time; }
+
+ void event(Raul::BeatTime time_offset, size_t size, unsigned char* buf);
+
+ void reset();
+ void resolve();
+
+ SharedPtr<Machine> finish();
+
+private:
+ bool is_delay_node(SharedPtr<Node> node) const;
+
+ SharedPtr<Node>
+ connect_nodes(SharedPtr<Machine> m,
+ SharedPtr<Node> tail, Raul::BeatTime tail_end_time,
+ SharedPtr<Node> head, Raul::BeatTime head_start_time);
+
+ typedef std::list<SharedPtr<Node> > ActiveList;
+ ActiveList _active_nodes;
+
+ typedef std::list<std::pair<Raul::BeatTime, SharedPtr<Node> > > PolyList;
+ PolyList _poly_nodes;
+
+ Raul::BeatTime _time;
+
+ SharedPtr<Machine> _machine;
+ SharedPtr<Node> _initial_node;
+ SharedPtr<Node> _connect_node;
+ Raul::BeatTime _connect_node_end_time;
+};
+
+
+} // namespace Machina
+
+#endif // MACHINA_MACHINEBUILDER_HPP
diff --git a/src/engine/machina/Makefile.am b/src/engine/machina/Makefile.am
index ce19080..5907be5 100644
--- a/src/engine/machina/Makefile.am
+++ b/src/engine/machina/Makefile.am
@@ -11,7 +11,9 @@ libmachinainclude_HEADERS = \
ActionFactory.hpp \
Driver.hpp \
LearnRequest.hpp \
- Engine.hpp
+ Engine.hpp \
+ Recorder.hpp \
+ MachineBuilder.hpp
if WITH_JACK
JackDriver.hpp
diff --git a/src/engine/machina/Recorder.hpp b/src/engine/machina/Recorder.hpp
new file mode 100644
index 0000000..b969df0
--- /dev/null
+++ b/src/engine/machina/Recorder.hpp
@@ -0,0 +1,53 @@
+/* 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_RECORDER_HPP
+#define MACHINA_RECORDER_HPP
+
+#include <raul/types.h>
+#include <raul/Slave.h>
+#include <raul/SharedPtr.h>
+#include <raul/MIDIRingBuffer.h>
+#include "Machine.hpp"
+
+namespace Machina {
+
+class MachineBuilder;
+
+
+class Recorder : public Raul::Slave {
+public:
+ Recorder(size_t buffer_size, double tick_rate);
+
+ inline void write(Raul::TickTime time, size_t size, const unsigned char* buf) {
+ _record_buffer.write(time, size, buf);
+ }
+
+ SharedPtr<Machine> finish();
+
+private:
+ virtual void _whipped();
+
+ double _tick_rate;
+ Raul::MIDIRingBuffer _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 7fec256..7b22a26 100644
--- a/src/engine/machina/SMFDriver.hpp
+++ b/src/engine/machina/SMFDriver.hpp
@@ -25,6 +25,7 @@
#include <raul/SMFReader.h>
#include "machina/types.hpp"
#include "machina/Driver.hpp"
+#include "machina/MachineBuilder.hpp"
namespace Machina {
@@ -37,8 +38,14 @@ class SMFDriver : public Driver,
public:
SMFDriver(SharedPtr<Machine> machine = SharedPtr<Machine>());
- SharedPtr<Machine> learn(const std::string& filename, double q=0.0, Raul::BeatTime max_duration=0);
- SharedPtr<Machine> learn(const std::string& filename, unsigned track, double q=0.0, Raul::BeatTime max_duration=0);
+ SharedPtr<Machine> learn(const std::string& filename,
+ double q=0.0,
+ Raul::BeatTime max_duration=0);
+
+ SharedPtr<Machine> learn(const std::string& filename,
+ unsigned track,
+ double q=0.0,
+ Raul::BeatTime max_duration=0);
void run(SharedPtr<Machine> machine, Raul::BeatTime max_time);
@@ -54,19 +61,12 @@ public:
private:
SharedPtr<Raul::SMFWriter> _writer;
-
- bool is_delay_node(SharedPtr<Node> node) const;
-
- SharedPtr<Node>
- connect_nodes(SharedPtr<Machine> m,
- SharedPtr<Node> tail, Raul::BeatTime tail_end_time,
- SharedPtr<Node> head, Raul::BeatTime head_start_time);
- void learn_track(SharedPtr<Machine> machine,
- Raul::SMFReader& reader,
- unsigned track,
- double q,
- Raul::BeatTime max_duration=0);
+ void learn_track(SharedPtr<MachineBuilder> builder,
+ Raul::SMFReader& reader,
+ unsigned track,
+ double q,
+ Raul::BeatTime max_duration=0);
};