diff options
author | David Robillard <d@drobilla.net> | 2020-11-28 23:20:45 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-11-28 23:20:45 +0100 |
commit | 228815993b4ecc31a345628fd85e6b75e564ecfe (patch) | |
tree | 06515a5e069dbfee55683767046a288f73719c43 /src | |
parent | f95ca1978dd463d1e6c640bb00d4d420ccb9d593 (diff) | |
download | patchage-228815993b4ecc31a345628fd85e6b75e564ecfe.tar.gz patchage-228815993b4ecc31a345628fd85e6b75e564ecfe.tar.bz2 patchage-228815993b4ecc31a345628fd85e6b75e564ecfe.zip |
Reduce use of raw new and delete
Diffstat (limited to 'src')
-rw-r--r-- | src/Configuration.cpp | 2 | ||||
-rw-r--r-- | src/Configuration.hpp | 2 | ||||
-rw-r--r-- | src/Patchage.cpp | 92 | ||||
-rw-r--r-- | src/Patchage.hpp | 13 | ||||
-rw-r--r-- | src/PatchageCanvas.cpp | 4 | ||||
-rw-r--r-- | src/PatchageModule.cpp | 8 |
6 files changed, 58 insertions, 63 deletions
diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 04b705a..8b0f03a 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -81,7 +81,7 @@ Configuration::Configuration() bool Configuration::get_module_location(const std::string& name, SignalDirection type, - Coord& loc) + Coord& loc) const { std::map<std::string, ModuleSettings>::const_iterator i = _module_settings.find(name); diff --git a/src/Configuration.hpp b/src/Configuration.hpp index 81b9e84..1a6ac6c 100644 --- a/src/Configuration.hpp +++ b/src/Configuration.hpp @@ -51,7 +51,7 @@ public: bool get_module_location(const std::string& name, SignalDirection type, - Coord& loc); + Coord& loc) const; void set_module_location(const std::string& name, SignalDirection type, diff --git a/src/Patchage.cpp b/src/Patchage.cpp index 1df1903..f3dfc2e 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -125,8 +125,6 @@ port_order(const GanvPort* a, const GanvPort* b, void*) Patchage::Patchage(int argc, char** argv) : _xml(UIFile::open("patchage")) - , _jack_driver(nullptr) - , _conf(nullptr) , _gtk_main(nullptr) , INIT_WIDGET(_about_win) , INIT_WIDGET(_main_scrolledwin) @@ -176,7 +174,6 @@ Patchage::Patchage(int argc, char** argv) , _alsa_driver_autoattach(true) #endif { - _conf = new Configuration(); _canvas = std::make_shared<PatchageCanvas>(_connector, 1600 * 2, 1200 * 2); while (argc > 0) { @@ -291,21 +288,21 @@ Patchage::Patchage(int argc, char** argv) _canvas->widget().show(); _main_win->present(); - _conf->set_font_size(_canvas->get_default_font_size()); - _conf->load(); - _canvas->set_zoom(_conf->get_zoom()); - _canvas->set_font_size(_conf->get_font_size()); - if (_conf->get_sort_ports()) { + _conf.set_font_size(_canvas->get_default_font_size()); + _conf.load(); + _canvas->set_zoom(_conf.get_zoom()); + _canvas->set_font_size(_conf.get_font_size()); + if (_conf.get_sort_ports()) { _canvas->set_port_order(port_order, nullptr); } - _main_win->resize(static_cast<int>(_conf->get_window_size().x), - static_cast<int>(_conf->get_window_size().y)); + _main_win->resize(static_cast<int>(_conf.get_window_size().x), + static_cast<int>(_conf.get_window_size().y)); - _main_win->move(static_cast<int>(_conf->get_window_location().x), - static_cast<int>(_conf->get_window_location().y)); + _main_win->move(static_cast<int>(_conf.get_window_location().x), + static_cast<int>(_conf.get_window_location().y)); - _legend = new Legend(*_conf); + _legend = new Legend(_conf); _legend->signal_color_changed.connect( sigc::mem_fun(this, &Patchage::on_legend_color_change)); _legend_alignment->add(*Gtk::manage(_legend)); @@ -322,18 +319,18 @@ Patchage::Patchage(int argc, char** argv) #endif #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) - _jack_driver = new JackDriver( - _log, [this](const PatchageEvent& event) { on_driver_event(event); }); + _jack_driver = std::unique_ptr<JackDriver>{new JackDriver( + _log, [this](const PatchageEvent& event) { on_driver_event(event); })}; - _connector.add_driver(PortID::Type::jack, _jack_driver); + _connector.add_driver(PortID::Type::jack, _jack_driver.get()); _jack_driver->signal_detached.connect( sigc::mem_fun(this, &Patchage::driver_detached)); - _menu_jack_connect->signal_activate().connect( - sigc::bind(sigc::mem_fun(_jack_driver, &JackDriver::attach), true)); + _menu_jack_connect->signal_activate().connect(sigc::bind( + sigc::mem_fun(_jack_driver.get(), &JackDriver::attach), true)); _menu_jack_disconnect->signal_activate().connect( - sigc::mem_fun(_jack_driver, &JackDriver::detach)); + sigc::mem_fun(_jack_driver.get(), &JackDriver::detach)); #endif #ifdef HAVE_ALSA @@ -345,9 +342,9 @@ Patchage::Patchage(int argc, char** argv) connect_widgets(); update_state(); - _menu_view_toolbar->set_active(_conf->get_show_toolbar()); - _menu_view_sprung_layout->set_active(_conf->get_sprung_layout()); - _menu_view_sort_ports->set_active(_conf->get_sort_ports()); + _menu_view_toolbar->set_active(_conf.get_show_toolbar()); + _menu_view_sprung_layout->set_active(_conf.get_sprung_layout()); + _menu_view_sort_ports->set_active(_conf.get_sort_ports()); g_signal_connect( _main_win->gobj(), "configure-event", G_CALLBACK(configure_cb), this); @@ -380,14 +377,12 @@ Patchage::Patchage(int argc, char** argv) Patchage::~Patchage() { #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) - delete _jack_driver; + _jack_driver.reset(); #endif #ifdef HAVE_ALSA _alsa_driver.reset(); #endif - delete _conf; - _about_win.destroy(); _xml.reset(); } @@ -421,7 +416,7 @@ Patchage::idle_callback() // Initial run, attach if (_attach) { attach(); - _menu_view_messages->set_active(_conf->get_show_messages()); + _menu_view_messages->set_active(_conf.get_show_messages()); _attach = false; } @@ -515,7 +510,7 @@ Patchage::update_load() void Patchage::zoom(double z) { - _conf->set_zoom(z); + _conf.set_zoom(z); _canvas->set_zoom(z); } @@ -554,8 +549,8 @@ Patchage::store_window_location() int size_y = 0; _main_win->get_size(size_x, size_y); - _conf->set_window_location({double(loc_x), double(loc_y)}); - _conf->set_window_size({double(size_x), double(size_y)}); + _conf.set_window_location({double(loc_x), double(loc_y)}); + _conf.set_window_size({double(size_x), double(size_y)}); } void @@ -678,7 +673,7 @@ Patchage::on_sprung_layout_toggled() const bool sprung = _menu_view_sprung_layout->get_active(); _canvas->set_sprung_layout(sprung); - _conf->set_sprung_layout(sprung); + _conf.set_sprung_layout(sprung); } void @@ -718,7 +713,7 @@ Patchage::on_view_sort_ports() { const bool sort_ports = this->sort_ports(); _canvas->set_port_order(sort_ports ? port_order : nullptr, nullptr); - _conf->set_sort_ports(sort_ports); + _conf.set_sort_ports(sort_ports); refresh(); } @@ -727,7 +722,7 @@ Patchage::on_zoom_in() { const float zoom = _canvas->get_zoom() * 1.25; _canvas->set_zoom(zoom); - _conf->set_zoom(zoom); + _conf.set_zoom(zoom); } void @@ -735,21 +730,21 @@ Patchage::on_zoom_out() { const float zoom = _canvas->get_zoom() * 0.75; _canvas->set_zoom(zoom); - _conf->set_zoom(zoom); + _conf.set_zoom(zoom); } void Patchage::on_zoom_normal() { _canvas->set_zoom(1.0); - _conf->set_zoom(1.0); + _conf.set_zoom(1.0); } void Patchage::on_zoom_full() { _canvas->zoom_full(); - _conf->set_zoom(_canvas->get_zoom()); + _conf.set_zoom(_canvas->get_zoom()); } void @@ -757,7 +752,7 @@ Patchage::on_increase_font_size() { const float points = _canvas->get_font_size() + 1.0; _canvas->set_font_size(points); - _conf->set_font_size(points); + _conf.set_font_size(points); } void @@ -765,14 +760,14 @@ Patchage::on_decrease_font_size() { const float points = _canvas->get_font_size() - 1.0; _canvas->set_font_size(points); - _conf->set_font_size(points); + _conf.set_font_size(points); } void Patchage::on_normal_font_size() { _canvas->set_font_size(_canvas->get_default_font_size()); - _conf->set_font_size(_canvas->get_default_font_size()); + _conf.set_font_size(_canvas->get_default_font_size()); } static inline guint @@ -804,8 +799,7 @@ update_port_colors(GanvNode* node, void* data) for (Ganv::Port* p : *pmod) { auto* port = dynamic_cast<PatchagePort*>(p); if (port) { - const uint32_t rgba = - patchage->conf()->get_port_color(port->type()); + const uint32_t rgba = patchage->conf().get_port_color(port->type()); port->set_fill_color(rgba); port->set_border_color(highlight_color(rgba, 0x20)); } @@ -820,14 +814,14 @@ update_edge_color(GanvEdge* edge, void* data) auto* tail = dynamic_cast<PatchagePort*>((edgemm)->get_tail()); if (tail) { - edgemm->set_color(patchage->conf()->get_port_color(tail->type())); + edgemm->set_color(patchage->conf().get_port_color(tail->type())); } } void Patchage::on_legend_color_change(PortType id, const std::string&, uint32_t rgba) { - _conf->set_port_color(id, rgba); + _conf.set_port_color(id, rgba); _canvas->for_each_node(update_port_colors, this); _canvas->for_each_edge(update_edge_color, this); } @@ -836,14 +830,14 @@ void Patchage::on_messages_resized(Gtk::Allocation&) { const int max_pos = _main_paned->get_allocation().get_height(); - _conf->set_messages_height(max_pos - _main_paned->get_position()); + _conf.set_messages_height(max_pos - _main_paned->get_position()); } void Patchage::save() { - _conf->set_zoom(_canvas->get_zoom()); // Can be changed by ganv - _conf->save(); + _conf.set_zoom(_canvas->get_zoom()); // Can be changed by ganv + _conf.save(); } void @@ -915,7 +909,7 @@ Patchage::on_view_messages() if (!_pane_initialized) { const int min_height = _log.min_height(); const int max_pos = _main_paned->get_allocation().get_height(); - const int conf_height = _conf->get_messages_height(); + const int conf_height = _conf.get_messages_height(); _main_paned->set_position(max_pos - std::max(conf_height, min_height)); @@ -925,10 +919,10 @@ Patchage::on_view_messages() _log_scrolledwindow->show(); _status_text->scroll_to_mark(_status_text->get_buffer()->get_insert(), 0); - _conf->set_show_messages(true); + _conf.set_show_messages(true); } else { _log_scrolledwindow->hide(); - _conf->set_show_messages(false); + _conf.set_show_messages(false); } } @@ -940,7 +934,7 @@ Patchage::on_view_toolbar() } else { _toolbar->hide(); } - _conf->set_show_toolbar(_menu_view_toolbar->get_active()); + _conf.set_show_toolbar(_menu_view_toolbar->get_active()); } bool diff --git a/src/Patchage.hpp b/src/Patchage.hpp index 8c0ccb5..ba34dcc 100644 --- a/src/Patchage.hpp +++ b/src/Patchage.hpp @@ -75,10 +75,11 @@ public: const std::shared_ptr<PatchageCanvas>& canvas() const { return _canvas; } - Gtk::Window* window() { return _main_win.get(); } - ILog& log() { return _log; } - Metadata& metadata() { return _metadata; } - Configuration* conf() const { return _conf; } + Gtk::Window* window() { return _main_win.get(); } + ILog& log() { return _log; } + Metadata& metadata() { return _metadata; } + const Configuration& conf() const { return _conf; } + Configuration& conf() { return _conf; } void attach(); void save(); @@ -159,8 +160,8 @@ protected: std::shared_ptr<PatchageCanvas> _canvas; - JackDriver* _jack_driver; - Configuration* _conf; + std::unique_ptr<JackDriver> _jack_driver; + Configuration _conf; Gtk::Main* _gtk_main; diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index bb9c484..27c860a 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -88,7 +88,7 @@ PatchageCanvas::create_port(Patchage& patchage, // Determine the module type to place the port on in case of splitting SignalDirection module_type = SignalDirection::duplex; - if (patchage.conf()->get_module_split(client_name, info.is_terminal)) { + if (patchage.conf().get_module_split(client_name, info.is_terminal)) { module_type = info.direction; } @@ -116,7 +116,7 @@ PatchageCanvas::create_port(Patchage& patchage, port_name, info.label, info.direction == SignalDirection::input, - patchage.conf()->get_port_color(info.type), + patchage.conf().get_port_color(info.type), patchage.show_human_names(), info.order); diff --git a/src/PatchageModule.cpp b/src/PatchageModule.cpp index 9b56856..a4d2fe9 100644 --- a/src/PatchageModule.cpp +++ b/src/PatchageModule.cpp @@ -110,7 +110,7 @@ PatchageModule::load_location() { Coord loc; - if (_app->conf()->get_module_location(_name, _type, loc)) { + if (_app->conf().get_module_location(_name, _type, loc)) { move_to(loc.x, loc.y); } else { move_to(20 + rand() % 640, 20 + rand() % 480); @@ -120,14 +120,14 @@ PatchageModule::load_location() void PatchageModule::store_location(double x, double y) { - _app->conf()->set_module_location(_name, _type, {x, y}); + _app->conf().set_module_location(_name, _type, {x, y}); } void PatchageModule::split() { assert(_type == SignalDirection::duplex); - _app->conf()->set_module_split(_name, true); + _app->conf().set_module_split(_name, true); _app->refresh(); } @@ -135,7 +135,7 @@ void PatchageModule::join() { assert(_type != SignalDirection::duplex); - _app->conf()->set_module_split(_name, false); + _app->conf().set_module_split(_name, false); _app->refresh(); } |