diff options
-rw-r--r-- | src/engine/JackDriver.cpp | 7 | ||||
-rw-r--r-- | src/engine/JackDriver.hpp | 7 | ||||
-rw-r--r-- | src/engine/MachineBuilder.cpp | 2 | ||||
-rw-r--r-- | src/engine/SMFDriver.hpp | 5 | ||||
-rw-r--r-- | src/engine/machina/Driver.hpp | 22 | ||||
-rw-r--r-- | src/gui/MachinaCanvas.cpp | 3 | ||||
-rw-r--r-- | src/gui/MachinaGUI.cpp | 25 | ||||
-rw-r--r-- | src/gui/MachinaGUI.hpp | 7 | ||||
-rw-r--r-- | 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> 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<Recorder>( - 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 <jack/jack.h> #include <jack/midiport.h> -#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<double> _bpm; - Raul::DoubleBuffer<double> _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> 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<SMFWriter> 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 <atomic> +#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> _machine; - SPtr<Raul::RingBuffer> _updates; - std::atomic<PlayState> _play_state; + Raul::Forge& _forge; + SPtr<Machine> _machine; + SPtr<Raul::RingBuffer> _updates; + std::atomic<PlayState> _play_state; + Raul::DoubleBuffer<double> _bpm; + Raul::DoubleBuffer<double> _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<machina::Engine> 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<machina::Engine> engine) sigc::bind(sigc::mem_fun(this, &MachinaGUI::mutate), SPtr<Machine>(), 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<machina::Controller> 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<machina::client::ClientObject> 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 @@ <interface> <requires lib="gtk+" version="2.16"/> <!-- interface-naming-policy toplevel-contextual --> + <object class="GtkAdjustment" id="bpm_adjustment"> + <property name="lower">1</property> + <property name="upper">480</property> + <property name="value">120</property> + <property name="step_increment">1</property> + <property name="page_increment">10</property> + </object> <object class="GtkRadioAction" id="record_action"> <property name="stock_id">gtk-media-record</property> <property name="draw_as_radio">True</property> @@ -65,13 +72,6 @@ along with Machina; if not, write to the Free Software Foundation, Inc., </object> </child> </object> - <object class="GtkAdjustment" id="bpm_adjustment"> - <property name="lower">1</property> - <property name="upper">480</property> - <property name="value">120</property> - <property name="step_increment">1</property> - <property name="page_increment">10</property> - </object> <object class="GtkDialog" id="help_dialog"> <property name="can_focus">False</property> <property name="border_width">8</property> @@ -175,11 +175,11 @@ selection to many nodes.</property> <action-widget response="-7">closebutton1</action-widget> </action-widgets> </object> - <object class="GtkAdjustment" id="quantize_adjustment"> + <object class="GtkAdjustment" id="length_adjustment"> <property name="lower">1</property> <property name="upper">256</property> - <property name="value">16</property> - <property name="step_increment">2</property> + <property name="value">8</property> + <property name="step_increment">1</property> <property name="page_increment">8</property> </object> <object class="GtkWindow" id="machina_win"> @@ -533,6 +533,7 @@ selection to many nodes.</property> <object class="GtkSpinButton" id="bpm_spinbutton"> <property name="visible">True</property> <property name="can_focus">True</property> + <property name="tooltip_text" translatable="yes">Playback tempo</property> <property name="max_length">3</property> <property name="invisible_char">•</property> <property name="width_chars">3</property> @@ -590,12 +591,12 @@ selection to many nodes.</property> <property name="border_width">4</property> <child> <object class="GtkCheckButton" id="quantize_checkbutton"> - <property name="label" translatable="yes">1/</property> + <property name="label" translatable="yes">Quantize 1/</property> <property name="use_action_appearance">False</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">False</property> - <property name="tooltip_text" translatable="yes">Quantization</property> + <property name="tooltip_text" translatable="yes">Quantize recorded notes</property> <property name="use_underline">True</property> <property name="draw_indicator">True</property> </object> @@ -608,9 +609,8 @@ selection to many nodes.</property> <child> <object class="GtkSpinButton" id="quantize_spinbutton"> <property name="visible">True</property> - <property name="sensitive">False</property> <property name="can_focus">True</property> - <property name="tooltip_text" translatable="yes">Quantize note type</property> + <property name="tooltip_text" translatable="yes">Note type for quantization</property> <property name="primary_icon_activatable">False</property> <property name="secondary_icon_activatable">False</property> <property name="primary_icon_sensitive">True</property> @@ -1105,4 +1105,11 @@ selection to many nodes.</property> <action-widget response="-5">node_properties_ok_button</action-widget> </action-widgets> </object> + <object class="GtkAdjustment" id="quantize_adjustment"> + <property name="lower">1</property> + <property name="upper">256</property> + <property name="value">8</property> + <property name="step_increment">1</property> + <property name="page_increment">8</property> + </object> </interface> |