From 358c0a4140406c8c38138a88aa03a4fc0ec6e7ee Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 1 Aug 2020 11:50:31 +0200 Subject: Use modern casts --- src/gui/App.cpp | 2 +- src/gui/GraphBox.cpp | 3 ++- src/gui/GraphCanvas.cpp | 23 +++++++++++++---------- src/gui/GraphPortModule.cpp | 2 +- src/gui/GraphTreeWindow.cpp | 2 +- src/gui/GraphView.cpp | 5 +++-- src/gui/MessagesWindow.cpp | 4 ++-- src/gui/NodeModule.cpp | 10 +++++++--- src/gui/Port.cpp | 2 +- src/gui/ingen_gui_lv2.cpp | 12 ++++++------ src/gui/rgba.hpp | 18 +++++++++--------- 11 files changed, 46 insertions(+), 37 deletions(-) (limited to 'src/gui') diff --git a/src/gui/App.cpp b/src/gui/App.cpp index dfa34998..92279906 100644 --- a/src/gui/App.cpp +++ b/src/gui/App.cpp @@ -354,7 +354,7 @@ App::status_text() const return fmt( "%2.1f kHz / %.1f ms, %s, %s DSP", (_sample_rate / 1e3f), - (_block_length * 1e3f / (float)_sample_rate), + (_block_length * 1e3f / static_cast(_sample_rate)), ((_n_threads == 1) ? "1 thread" : fmt("%1% threads", _n_threads)), fraction_label(_max_run_load)); } diff --git a/src/gui/GraphBox.cpp b/src/gui/GraphBox.cpp index 5ce54d99..7fe1a643 100644 --- a/src/gui/GraphBox.cpp +++ b/src/gui/GraphBox.cpp @@ -873,7 +873,8 @@ GraphBox::event_animate_signals_toggled() _app->interface()->set_property( URI("ingen:/clients/this"), _app->uris().ingen_broadcast, - _app->forge().make((bool)_menu_animate_signals->get_active())); + _app->forge().make( + static_cast(_menu_animate_signals->get_active()))); } void diff --git a/src/gui/GraphCanvas.cpp b/src/gui/GraphCanvas.cpp index 40a0c675..391b8729 100644 --- a/src/gui/GraphCanvas.cpp +++ b/src/gui/GraphCanvas.cpp @@ -67,7 +67,8 @@ port_order(const GanvPort* a, const GanvPort* b, void* data) const Port* pa = dynamic_cast(Glib::wrap(a)); const Port* pb = dynamic_cast(Glib::wrap(b)); if (pa && pb) { - return ((int)pa->model()->index() - (int)pb->model()->index()); + return (static_cast(pa->model()->index()) - + static_cast(pb->model()->index())); } return 0; } @@ -261,7 +262,7 @@ GraphCanvas::build() static void show_module_human_names(GanvNode* node, void* data) { - bool b = *(bool*)data; + bool b = *static_cast(data); if (GANV_IS_MODULE(node)) { Ganv::Module* module = Glib::wrap(GANV_MODULE(node)); NodeModule* nmod = dynamic_cast(module); @@ -518,8 +519,8 @@ GraphCanvas::on_event(GdkEvent* event) case GDK_BUTTON_PRESS: if (event->button.button == 3) { _auto_position_count = 1; - _menu_x = (int)event->button.x_root; - _menu_y = (int)event->button.y_root; + _menu_x = static_cast(event->button.x_root); + _menu_y = static_cast(event->button.y_root); show_menu(false, event->button.button, event->button.time); ret = true; } @@ -569,7 +570,7 @@ destroy_node(GanvNode* node, void* data) return; } - App* app = (App*)data; + App* app = static_cast(data); Ganv::Module* module = Glib::wrap(GANV_MODULE(node)); NodeModule* node_module = dynamic_cast(module); @@ -588,7 +589,7 @@ destroy_node(GanvNode* node, void* data) static void destroy_arc(GanvEdge* arc, void* data) { - App* app = (App*)data; + App* app = static_cast(data); Ganv::Edge* arcmm = Glib::wrap(arc); Port* tail = dynamic_cast(arcmm->get_tail()); @@ -611,7 +612,7 @@ GraphCanvas::destroy_selection() static void serialise_node(GanvNode* node, void* data) { - Serialiser* serialiser = (Serialiser*)data; + Serialiser* serialiser = static_cast(data); if (!GANV_IS_MODULE(node)) { return; } @@ -632,7 +633,7 @@ serialise_node(GanvNode* node, void* data) static void serialise_arc(GanvEdge* arc, void* data) { - Serialiser* serialiser = (Serialiser*)data; + Serialiser* serialiser = static_cast(data); if (!GANV_IS_EDGE(arc)) { return; } @@ -879,9 +880,11 @@ GraphCanvas::get_initial_data(Resource::Graph ctx) Properties result; const URIs& uris = _app.uris(); result.emplace(uris.ingen_canvasX, - Property(_app.forge().make((float)_menu_x), ctx)); + Property(_app.forge().make(static_cast(_menu_x)), + ctx)); result.emplace(uris.ingen_canvasY, - Property(_app.forge().make((float)_menu_y), ctx)); + Property(_app.forge().make(static_cast(_menu_y)), + ctx)); return result; } diff --git a/src/gui/GraphPortModule.cpp b/src/gui/GraphPortModule.cpp index 1947f355..336dced7 100644 --- a/src/gui/GraphPortModule.cpp +++ b/src/gui/GraphPortModule.cpp @@ -83,7 +83,7 @@ GraphPortModule::create(GraphCanvas& canvas, const SPtr& model) App& GraphPortModule::app() const { - return ((GraphCanvas*)canvas())->app(); + return static_cast(canvas())->app(); } bool diff --git a/src/gui/GraphTreeWindow.cpp b/src/gui/GraphTreeWindow.cpp index 68f6e392..dd80c906 100644 --- a/src/gui/GraphTreeWindow.cpp +++ b/src/gui/GraphTreeWindow.cpp @@ -188,7 +188,7 @@ GraphTreeWindow::event_graph_enabled_toggled(const Glib::ustring& path_str) if (_enable_signal) { _app->set_property(pm->uri(), _app->uris().ingen_enabled, - _app->forge().make((bool)!pm->enabled())); + _app->forge().make(static_cast(!pm->enabled()))); } } diff --git a/src/gui/GraphView.cpp b/src/gui/GraphView.cpp index 36c6caed..ca12e1ef 100644 --- a/src/gui/GraphView.cpp +++ b/src/gui/GraphView.cpp @@ -120,14 +120,15 @@ GraphView::process_toggled() _app->set_property(_graph->uri(), _app->uris().ingen_enabled, - _app->forge().make((bool)_process_but->get_active())); + _app->forge().make( + static_cast(_process_but->get_active()))); } void GraphView::poly_changed() { const int poly = _poly_spin->get_value_as_int(); - if (_enable_signal && poly != (int)_graph->internal_poly()) { + if (_enable_signal && poly != static_cast(_graph->internal_poly())) { _app->set_property(_graph->uri(), _app->uris().ingen_polyphony, _app->forge().make(poly)); diff --git a/src/gui/MessagesWindow.cpp b/src/gui/MessagesWindow.cpp index 84d29679..d8003a33 100644 --- a/src/gui/MessagesWindow.cpp +++ b/src/gui/MessagesWindow.cpp @@ -41,8 +41,8 @@ MessagesWindow::MessagesWindow(BaseObjectType* cobject, _close_button->signal_clicked().connect(sigc::mem_fun(this, &Window::hide)); for (int s = Gtk::STATE_NORMAL; s <= Gtk::STATE_INSENSITIVE; ++s) { - _textview->modify_base((Gtk::StateType)s, Gdk::Color("#000000")); - _textview->modify_text((Gtk::StateType)s, Gdk::Color("#EEEEEC")); + _textview->modify_base(static_cast(s), Gdk::Color("#000000")); + _textview->modify_text(static_cast(s), Gdk::Color("#EEEEEC")); } } diff --git a/src/gui/NodeModule.cpp b/src/gui/NodeModule.cpp index 5984dbe1..7cecfd46 100644 --- a/src/gui/NodeModule.cpp +++ b/src/gui/NodeModule.cpp @@ -163,7 +163,7 @@ NodeModule::create(GraphCanvas& canvas, App& NodeModule::app() const { - return ((GraphCanvas*)canvas())->app(); + return static_cast(canvas())->app(); } void @@ -268,7 +268,9 @@ NodeModule::embed_gui(bool embed) if (!_plugin_ui->instantiate()) { app().log().error("Failed to instantiate LV2 UI\n"); } else { - GtkWidget* c_widget = (GtkWidget*)_plugin_ui->get_widget(); + GtkWidget* c_widget = + static_cast(_plugin_ui->get_widget()); + _gui_widget = Glib::wrap(c_widget); Gtk::Container* container = new Gtk::EventBox(); @@ -362,7 +364,9 @@ NodeModule::popup_gui() return false; } - GtkWidget* c_widget = (GtkWidget*)_plugin_ui->get_widget(); + GtkWidget* c_widget = + static_cast(_plugin_ui->get_widget()); + _gui_widget = Glib::wrap(c_widget); _gui_window = new Gtk::Window(); diff --git a/src/gui/Port.cpp b/src/gui/Port.cpp index 14f87fc1..73ad837a 100644 --- a/src/gui/Port.cpp +++ b/src/gui/Port.cpp @@ -194,7 +194,7 @@ Port::on_value_changed(double value) return; // Non-float, unsupported } - if (current_value.get() == (float)value) { + if (current_value.get() == static_cast(value)) { return; // No change } diff --git a/src/gui/ingen_gui_lv2.cpp b/src/gui/ingen_gui_lv2.cpp index 4817e9ae..e1c1eef7 100644 --- a/src/gui/ingen_gui_lv2.cpp +++ b/src/gui/ingen_gui_lv2.cpp @@ -119,11 +119,11 @@ instantiate(const LV2UI_Descriptor* descriptor, LV2_Log_Log* log = nullptr; for (int i = 0; features[i]; ++i) { if (!strcmp(features[i]->URI, LV2_URID__map)) { - map = (LV2_URID_Map*)features[i]->data; + map = static_cast(features[i]->data); } else if (!strcmp(features[i]->URI, LV2_URID__unmap)) { - unmap = (LV2_URID_Unmap*)features[i]->data; + unmap = static_cast(features[i]->data); } else if (!strcmp(features[i]->URI, LV2_LOG__log)) { - log = (LV2_Log_Log*)features[i]->data; + log = static_cast(features[i]->data); } } @@ -183,7 +183,7 @@ instantiate(const LV2UI_Descriptor* descriptor, static void cleanup(LV2UI_Handle handle) { - ingen::IngenLV2UI* ui = (ingen::IngenLV2UI*)handle; + ingen::IngenLV2UI* ui = static_cast(handle); delete ui; } @@ -194,8 +194,8 @@ port_event(LV2UI_Handle handle, uint32_t format, const void* buffer) { - ingen::IngenLV2UI* ui = (ingen::IngenLV2UI*)handle; - const LV2_Atom* atom = (const LV2_Atom*)buffer; + ingen::IngenLV2UI* ui = static_cast(handle); + const LV2_Atom* atom = static_cast(buffer); ui->reader->write(atom); } diff --git a/src/gui/rgba.hpp b/src/gui/rgba.hpp index f31e958c..949a80d7 100644 --- a/src/gui/rgba.hpp +++ b/src/gui/rgba.hpp @@ -25,22 +25,22 @@ namespace gui { static inline uint32_t rgba_to_uint(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { - return ((((uint32_t)(r)) << 24) | - (((uint32_t)(g)) << 16) | - (((uint32_t)(b)) << 8) | - (((uint32_t)(a)))); + return ((static_cast(r) << 24) | + (static_cast(g) << 16) | + (static_cast(b) << 8) | + (static_cast(a))); } static inline uint8_t mono_interpolate(uint8_t v1, uint8_t v2, float f) { - return ((int)rint((v2) * (f) + (v1) * (1 - (f)))); + return static_cast(rint((v2) * (f) + (v1) * (1 - (f)))); } -#define RGBA_R(x) (((uint32_t)(x)) >> 24) -#define RGBA_G(x) ((((uint32_t)(x)) >> 16) & 0xFF) -#define RGBA_B(x) ((((uint32_t)(x)) >> 8) & 0xFF) -#define RGBA_A(x) (((uint32_t)(x)) & 0xFF) +#define RGBA_R(x) (static_cast(x) >> 24) +#define RGBA_G(x) ((static_cast(x) >> 16) & 0xFF) +#define RGBA_B(x) ((static_cast(x) >> 8) & 0xFF) +#define RGBA_A(x) (static_cast(x) & 0xFF) static inline uint32_t rgba_interpolate(uint32_t c1, uint32_t c2, float f) -- cgit v1.2.1