From f8883a56e44a42e97ca84392fdbff61e11540fcd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 31 Mar 2007 05:28:01 +0000 Subject: Realtime MIDI recording. git-svn-id: http://svn.drobilla.net/lad/machina@383 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/machina/Driver.hpp | 4 ++ src/engine/machina/JackDriver.hpp | 11 +++++- src/engine/machina/MachineBuilder.hpp | 69 +++++++++++++++++++++++++++++++++++ src/engine/machina/Makefile.am | 4 +- src/engine/machina/Recorder.hpp | 53 +++++++++++++++++++++++++++ src/engine/machina/SMFDriver.hpp | 28 +++++++------- 6 files changed, 153 insertions(+), 16 deletions(-) create mode 100644 src/engine/machina/MachineBuilder.hpp create mode 100644 src/engine/machina/Recorder.hpp (limited to 'src/engine/machina') 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; }; 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 #include #include +#include #include #include #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, const Raul::TimeSlice& time); @@ -76,6 +81,10 @@ private: Raul::DoubleBuffer _bpm; Raul::DoubleBuffer _quantization; + + Raul::TickTime _record_time; + Raul::AtomicInt _recording; + SharedPtr _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 + * + * 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 +#include +#include + +namespace Machina { + +class Machine; +class Node; + + +class MachineBuilder { +public: + MachineBuilder(SharedPtr 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 finish(); + +private: + bool is_delay_node(SharedPtr node) const; + + SharedPtr + connect_nodes(SharedPtr m, + SharedPtr tail, Raul::BeatTime tail_end_time, + SharedPtr head, Raul::BeatTime head_start_time); + + typedef std::list > ActiveList; + ActiveList _active_nodes; + + typedef std::list > > PolyList; + PolyList _poly_nodes; + + Raul::BeatTime _time; + + SharedPtr _machine; + SharedPtr _initial_node; + SharedPtr _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 + * + * 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 +#include +#include +#include +#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 finish(); + +private: + virtual void _whipped(); + + double _tick_rate; + Raul::MIDIRingBuffer _record_buffer; + SharedPtr _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 #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 = SharedPtr()); - SharedPtr learn(const std::string& filename, double q=0.0, Raul::BeatTime max_duration=0); - SharedPtr learn(const std::string& filename, unsigned track, double q=0.0, Raul::BeatTime max_duration=0); + SharedPtr learn(const std::string& filename, + double q=0.0, + Raul::BeatTime max_duration=0); + + SharedPtr learn(const std::string& filename, + unsigned track, + double q=0.0, + Raul::BeatTime max_duration=0); void run(SharedPtr machine, Raul::BeatTime max_time); @@ -54,19 +61,12 @@ public: private: SharedPtr _writer; - - bool is_delay_node(SharedPtr node) const; - - SharedPtr - connect_nodes(SharedPtr m, - SharedPtr tail, Raul::BeatTime tail_end_time, - SharedPtr head, Raul::BeatTime head_start_time); - void learn_track(SharedPtr machine, - Raul::SMFReader& reader, - unsigned track, - double q, - Raul::BeatTime max_duration=0); + void learn_track(SharedPtr builder, + Raul::SMFReader& reader, + unsigned track, + double q, + Raul::BeatTime max_duration=0); }; -- cgit v1.2.1