From 08e702ada89b951466c7b9c787663e0a57846e5a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 14 Jan 2013 02:42:29 +0000 Subject: Make quantize spinner control step record and new node length. Only quantize non-step recording if quantize checkbox is enabled. git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4977 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/JackDriver.cpp | 7 +++---- src/engine/JackDriver.hpp | 7 ------- src/engine/MachineBuilder.cpp | 2 +- src/engine/SMFDriver.hpp | 5 ----- src/engine/machina/Driver.hpp | 22 +++++++++++++++------- src/gui/MachinaCanvas.cpp | 3 ++- src/gui/MachinaGUI.cpp | 25 ++++++++----------------- src/gui/MachinaGUI.hpp | 7 +++++-- src/gui/machina.ui | 35 +++++++++++++++++++++-------------- 9 files changed, 55 insertions(+), 58 deletions(-) diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp index 840573e..8eada7c 100644 --- a/src/engine/JackDriver.cpp +++ b/src/engine/JackDriver.cpp @@ -41,8 +41,6 @@ JackDriver::JackDriver(Raul::Forge& forge, SPtr machine) , _context(forge, 48000, MACHINA_PPQN, 120.0) , _frames_unit(TimeUnit::FRAMES, 48000) , _beats_unit(TimeUnit::BEATS, 19200) - , _bpm(120.0) - , _quantization(0.0f) , _stop(0) , _stop_flag(false) , _record_dur(_frames_unit) // = 0 @@ -421,17 +419,18 @@ JackDriver::set_play_state(PlayState state) finish_record(); } } - _play_state = state; + Driver::set_play_state(state); } void JackDriver::start_record(bool step) { + const double q = (step || _quantize_record) ? _quantization.get() : 0.0; switch (_play_state) { case PlayState::STOPPED: case PlayState::PLAYING: _recorder = SPtr( - new Recorder(_forge, 1024, _beats_unit, _quantization.get(), step)); + new Recorder(_forge, 1024, _beats_unit, q, step)); _recorder->start(); _record_dur = 0; break; diff --git a/src/engine/JackDriver.hpp b/src/engine/JackDriver.hpp index 14ed626..a67afbc 100644 --- a/src/engine/JackDriver.hpp +++ b/src/engine/JackDriver.hpp @@ -22,7 +22,6 @@ #include #include -#include "raul/DoubleBuffer.hpp" #include "raul/Semaphore.hpp" #include "machina/Context.hpp" @@ -61,9 +60,6 @@ public: size_t size, const unsigned char* event); - void set_bpm(double bpm) { _bpm.set(bpm); } - void set_quantization(double q) { _quantization.set(q); } - void set_play_state(PlayState state); void start_transport() { jack_transport_start(_client); } @@ -112,9 +108,6 @@ private: Raul::TimeUnit _frames_unit; Raul::TimeUnit _beats_unit; - Raul::DoubleBuffer _bpm; - Raul::DoubleBuffer _quantization; - Raul::Semaphore _stop; bool _stop_flag; diff --git a/src/engine/MachineBuilder.cpp b/src/engine/MachineBuilder.cpp index 566944e..d812b06 100644 --- a/src/engine/MachineBuilder.cpp +++ b/src/engine/MachineBuilder.cpp @@ -37,7 +37,7 @@ MachineBuilder::MachineBuilder(SPtr machine, double q, bool step) , _initial_node(machine->initial_node()) // duration 0 , _connect_node(_initial_node) , _connect_node_end_time(_time) // = 0 - , _step_duration(machine->time().unit(), 1, 0) + , _step_duration(_time.unit(), q) , _step(step) {} diff --git a/src/engine/SMFDriver.hpp b/src/engine/SMFDriver.hpp index 1e40ab6..6199fc1 100644 --- a/src/engine/SMFDriver.hpp +++ b/src/engine/SMFDriver.hpp @@ -52,11 +52,6 @@ public: 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*/) {} - - void set_play_state(PlayState state) {} - SPtr writer() { return _writer; } private: diff --git a/src/engine/machina/Driver.hpp b/src/engine/machina/Driver.hpp index 1fad9b3..f21bb07 100644 --- a/src/engine/machina/Driver.hpp +++ b/src/engine/machina/Driver.hpp @@ -19,6 +19,7 @@ #include +#include "raul/DoubleBuffer.hpp" #include "raul/RingBuffer.hpp" #include "machina/types.hpp" @@ -36,6 +37,9 @@ public: : _forge(forge) , _machine(machine) , _play_state(PlayState::STOPPED) + , _bpm(120.0) + , _quantization(0.125) + , _quantize_record(0) {} enum class PlayState { @@ -59,9 +63,10 @@ public: _updates = b; } - virtual void set_bpm(double bpm) = 0; - virtual void set_quantization(double q) = 0; - virtual void set_play_state(PlayState state) = 0; + virtual void set_bpm(double bpm) { _bpm.set(bpm); } + virtual void set_quantization(double q) { _quantization.set(q); } + virtual void set_quantize_record(bool q) { _quantize_record = q; } + virtual void set_play_state(PlayState state) { _play_state = state; } virtual bool is_activated() const { return false; } virtual void activate() {} @@ -70,10 +75,13 @@ public: PlayState play_state() const { return _play_state.load(); } protected: - Raul::Forge& _forge; - SPtr _machine; - SPtr _updates; - std::atomic _play_state; + Raul::Forge& _forge; + SPtr _machine; + SPtr _updates; + std::atomic _play_state; + Raul::DoubleBuffer _bpm; + Raul::DoubleBuffer _quantization; + bool _quantize_record; }; } // namespace machina diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index 15aaf57..3413a9f 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -186,7 +186,8 @@ MachinaCanvas::action_create_node(double x, double y) _app->forge().make_urid(URIs::instance().machina_Node)); obj.set(URIs::instance().machina_canvas_x, _app->forge().make((float)x)); obj.set(URIs::instance().machina_canvas_y, _app->forge().make((float)y)); - obj.set(URIs::instance().machina_duration, _app->forge().make(1.0f)); + obj.set(URIs::instance().machina_duration, + _app->forge().make((float)_app->default_length())); _app->controller()->create(obj); } diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index 5057f5a..2147c27 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -149,6 +149,8 @@ MachinaGUI::MachinaGUI(SPtr engine) _bpm_spinbutton->signal_changed().connect( sigc::mem_fun(this, &MachinaGUI::tempo_changed)); _quantize_checkbutton->signal_toggled().connect( + sigc::mem_fun(this, &MachinaGUI::quantize_record_changed)); + _quantize_spinbutton->signal_changed().connect( sigc::mem_fun(this, &MachinaGUI::quantize_changed)); _mutate_button->signal_clicked().connect( @@ -176,8 +178,6 @@ MachinaGUI::MachinaGUI(SPtr engine) sigc::bind(sigc::mem_fun(this, &MachinaGUI::mutate), SPtr(), 6)); - connect_widgets(); - _canvas->widget().show(); _main_window->present(); @@ -375,7 +375,6 @@ MachinaGUI::update_toolbar() _record_button->set_active(state == Driver::PlayState::RECORDING); _step_record_button->set_active(state == Driver::PlayState::STEP_RECORDING); _play_button->set_active(state == Driver::PlayState::PLAYING); - _quantize_spinbutton->set_sensitive(_quantize_checkbutton->get_active()); } void @@ -386,31 +385,23 @@ MachinaGUI::rebuild_canvas() } void -MachinaGUI::quantize_changed() +MachinaGUI::quantize_record_changed() { - if (_quantize_checkbutton->get_active()) { - _engine->set_quantization(1.0 / _quantize_spinbutton->get_value()); - } else { - _engine->set_quantization(0.0); - } - update_toolbar(); + _engine->driver()->set_quantize_record(_quantize_checkbutton->get_active()); } void -MachinaGUI::tempo_changed() +MachinaGUI::quantize_changed() { - _engine->set_bpm(_bpm_spinbutton->get_value_as_int()); + _engine->set_quantization(1.0 / _quantize_spinbutton->get_value()); } -/** Update the sensitivity status of menus to reflect the present. - */ void -MachinaGUI::connect_widgets() +MachinaGUI::tempo_changed() { + _engine->set_bpm(_bpm_spinbutton->get_value_as_int()); } -using namespace std; - void MachinaGUI::menu_file_quit() { diff --git a/src/gui/MachinaGUI.hpp b/src/gui/MachinaGUI.hpp index e917ff8..4bbb238 100644 --- a/src/gui/MachinaGUI.hpp +++ b/src/gui/MachinaGUI.hpp @@ -66,6 +66,10 @@ public: SPtr controller() { return _controller; } + double default_length() const { + return 1 / (double)_quantize_spinbutton->get_value(); + } + inline void queue_refresh() { _refresh = true; } void on_new_object(SPtr object); @@ -76,8 +80,6 @@ public: } protected: - void connect_widgets(); - void menu_file_quit(); void menu_file_open(); void menu_file_save(); @@ -116,6 +118,7 @@ protected: void chain_toggled(); void fan_toggled(); + void quantize_record_changed(); void quantize_changed(); void tempo_changed(); diff --git a/src/gui/machina.ui b/src/gui/machina.ui index 62d3459..cc03739 100644 --- a/src/gui/machina.ui +++ b/src/gui/machina.ui @@ -2,6 +2,13 @@ + + 1 + 480 + 120 + 1 + 10 + gtk-media-record True @@ -65,13 +72,6 @@ along with Machina; if not, write to the Free Software Foundation, Inc., - - 1 - 480 - 120 - 1 - 10 - False 8 @@ -175,11 +175,11 @@ selection to many nodes. closebutton1 - + 1 256 - 16 - 2 + 8 + 1 8 @@ -533,6 +533,7 @@ selection to many nodes. True True + Playback tempo 3 3 @@ -590,12 +591,12 @@ selection to many nodes. 4 - 1/ + Quantize 1/ False True True False - Quantization + Quantize recorded notes True True @@ -608,9 +609,8 @@ selection to many nodes. True - False True - Quantize note type + Note type for quantization False False True @@ -1105,4 +1105,11 @@ selection to many nodes. node_properties_ok_button + + 1 + 256 + 8 + 1 + 8 + -- cgit v1.2.1