From 47a5eceb3b81b8a015fbaa69a02b984f04a9f0dd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 27 May 2022 12:33:13 -0400 Subject: Avoid "else" after "return" --- .clang-tidy | 1 - src/control.c | 7 +++++-- src/jalv.c | 8 ++++---- src/jalv_console.c | 6 ++++-- src/jalv_gtk.c | 53 ++++++++++++++++++++++++++++++++++++----------------- src/jalv_qt.cpp | 34 ++++++++++++++++++++-------------- src/symap.c | 15 +++++++++++---- 7 files changed, 80 insertions(+), 44 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 0a8f425..457d5a1 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,5 @@ Checks: > *, - -*-else-after-return, -*-magic-numbers, -*-named-parameter, -*-narrowing-conversions, diff --git a/src/control.c b/src/control.c index 9b362ed..8b619a9 100644 --- a/src/control.c +++ b/src/control.c @@ -1,5 +1,5 @@ /* - Copyright 2007-2016 David Robillard + Copyright 2007-2022 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -32,9 +32,12 @@ scale_point_cmp(const ScalePoint* a, const ScalePoint* b) { if (a->value < b->value) { return -1; - } else if (a->value == b->value) { + } + + if (a->value == b->value) { return 0; } + return 1; } diff --git a/src/jalv.c b/src/jalv.c index 78420fd..9de7f31 100644 --- a/src/jalv.c +++ b/src/jalv.c @@ -1,5 +1,5 @@ /* - Copyright 2007-2016 David Robillard + Copyright 2007-2022 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -614,10 +614,10 @@ jalv_send_to_ui(Jalv* jalv, zix_ring_write(jalv->plugin_events, evbuf, sizeof(evbuf)); zix_ring_write(jalv->plugin_events, (const char*)body, size); return true; - } else { - fprintf(stderr, "Plugin => UI buffer overflow!\n"); - return false; } + + fprintf(stderr, "Plugin => UI buffer overflow!\n"); + return false; } bool diff --git a/src/jalv_console.c b/src/jalv_console.c index a08f08a..13eb330 100644 --- a/src/jalv_console.c +++ b/src/jalv_console.c @@ -1,5 +1,5 @@ /* - Copyright 2007-2016 David Robillard + Copyright 2007-2022 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -76,7 +76,9 @@ jalv_init(int* argc, char*** argv, JalvOptions* opts) for (; a < *argc && (*argv)[a][0] == '-'; ++a) { if ((*argv)[a][1] == 'h') { return print_usage((*argv)[0], true); - } else if ((*argv)[a][1] == 's') { + } + + if ((*argv)[a][1] == 's') { opts->show_ui = true; } else if ((*argv)[a][1] == 'p') { opts->print_controls = true; diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c index 2e32c98..f909425 100644 --- a/src/jalv_gtk.c +++ b/src/jalv_gtk.c @@ -1,5 +1,5 @@ /* - Copyright 2007-2017 David Robillard + Copyright 2007-2022 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -551,13 +551,20 @@ get_atom_double(Jalv* jalv, { if (type == jalv->forge.Int || type == jalv->forge.Bool) { return *(const int32_t*)body; - } else if (type == jalv->forge.Long) { + } + + if (type == jalv->forge.Long) { return *(const int64_t*)body; - } else if (type == jalv->forge.Float) { + } + + if (type == jalv->forge.Float) { return *(const float*)body; - } else if (type == jalv->forge.Double) { + } + + if (type == jalv->forge.Double) { return *(const double*)body; } + return NAN; } @@ -623,7 +630,9 @@ patch_set_get(Jalv* jalv, if (!*property) { fprintf(stderr, "patch:Set message with no property\n"); return 1; - } else if ((*property)->atom.type != jalv->forge.URID) { + } + + if ((*property)->atom.type != jalv->forge.URID) { fprintf(stderr, "patch:Set property is not a URID\n"); return 1; } @@ -642,7 +651,9 @@ patch_put_get(Jalv* jalv, if (!*body) { fprintf(stderr, "patch:Put message with no body\n"); return 1; - } else if (!lv2_atom_forge_is_object_type(&jalv->forge, (*body)->atom.type)) { + } + + if (!lv2_atom_forge_is_object_type(&jalv->forge, (*body)->atom.type)) { fprintf(stderr, "patch:Put body is not an object\n"); return 1; } @@ -661,7 +672,9 @@ on_request_value(LV2UI_Feature_Handle handle, if (!control) { return LV2UI_REQUEST_VALUE_ERR_UNKNOWN; - } else if (control->value_type != jalv->forge.Path) { + } + + if (control->value_type != jalv->forge.Path) { return LV2UI_REQUEST_VALUE_ERR_UNSUPPORTED; } @@ -710,16 +723,22 @@ jalv_ui_port_event(Jalv* jalv, suil_instance_port_event(jalv->ui_instance, port_index, buffer_size, protocol, buffer); return; - } else if (protocol == 0 && (Controller*)jalv->ports[port_index].widget) { + } + + if (protocol == 0 && (Controller*)jalv->ports[port_index].widget) { control_changed(jalv, (Controller*)jalv->ports[port_index].widget, buffer_size, jalv->forge.Float, buffer); return; - } else if (protocol == 0) { + } + + if (protocol == 0) { return; // No widget (probably notOnGUI) - } else if (protocol != jalv->urids.atom_eventTransfer) { + } + + if (protocol != jalv->urids.atom_eventTransfer) { fprintf(stderr, "Unknown port event protocol\n"); return; } @@ -1140,14 +1159,14 @@ build_control_widget(Jalv* jalv, GtkWidget* window) gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, 8, 8); gtk_container_add(GTK_CONTAINER(alignment), port_table); return alignment; - } else { - gtk_widget_destroy(port_table); - GtkWidget* button = gtk_button_new_with_label("Close"); - g_signal_connect_swapped(button, "clicked", - G_CALLBACK(gtk_widget_destroy), window); - gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - return button; } + + gtk_widget_destroy(port_table); + GtkWidget* button = gtk_button_new_with_label("Close"); + g_signal_connect_swapped(button, "clicked", + G_CALLBACK(gtk_widget_destroy), window); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + return button; } static void diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp index 2bf61f9..b92c2c1 100644 --- a/src/jalv_qt.cpp +++ b/src/jalv_qt.cpp @@ -1,5 +1,5 @@ /* - Copyright 2007-2016 David Robillard + Copyright 2007-2022 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -134,9 +134,9 @@ FlowLayout::horizontalSpacing() const { if (m_hSpace >= 0) { return m_hSpace; - } else { - return smartSpacing(QStyle::PM_LayoutHorizontalSpacing); } + + return smartSpacing(QStyle::PM_LayoutHorizontalSpacing); } int @@ -144,9 +144,9 @@ FlowLayout::verticalSpacing() const { if (m_vSpace >= 0) { return m_vSpace; - } else { - return smartSpacing(QStyle::PM_LayoutVerticalSpacing); } + + return smartSpacing(QStyle::PM_LayoutVerticalSpacing); } int @@ -166,9 +166,9 @@ FlowLayout::takeAt(int index) { if (index >= 0 && index < itemList.size()) { return itemList.takeAt(index); - } else { - return nullptr; } + + return nullptr; } Qt::Orientations @@ -273,12 +273,14 @@ FlowLayout::smartSpacing(QStyle::PixelMetric pm) const QObject* parent = this->parent(); if (!parent) { return -1; - } else if (parent->isWidgetType()) { + } + + if (parent->isWidgetType()) { QWidget* pw = static_cast(parent); return pw->style()->pixelMetric(pm, nullptr, pw); - } else { - return static_cast(parent)->spacing(); } + + return static_cast(parent)->spacing(); } class PresetAction : public QAction @@ -575,13 +577,17 @@ Control::getValue() { if (isEnum) { return scalePoints[dial->value()]; - } else if (isInteger) { + } + + if (isInteger) { return dial->value(); - } else if (isLogarithmic) { + } + + if (isLogarithmic) { return min * powf(max / min, (float)dial->value() / (steps - 1)); - } else { - return (float)dial->value() / steps; } + + return (float)dial->value() / steps; } int diff --git a/src/symap.c b/src/symap.c index 71a46f0..b699269 100644 --- a/src/symap.c +++ b/src/symap.c @@ -1,5 +1,5 @@ /* - Copyright 2011-2014 David Robillard + Copyright 2011-2022 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -100,7 +100,9 @@ symap_search(const Symap* map, const char* sym, bool* exact) *exact = false; if (map->size == 0) { return 0; // Empty map, insert at 0 - } else if (strcmp(map->symbols[map->index[map->size - 1] - 1], sym) < 0) { + } + + if (strcmp(map->symbols[map->index[map->size - 1] - 1], sym) < 0) { return map->size; // Greater than last element, append } @@ -116,7 +118,9 @@ symap_search(const Symap* map, const char* sym, bool* exact) if (cmp == 0) { *exact = true; return i; - } else if (cmp > 0) { + } + + if (cmp > 0) { if (i == 0) { break; // Avoid underflow } @@ -178,9 +182,12 @@ symap_unmap(Symap* map, uint32_t id) { if (id == 0) { return NULL; - } else if (id <= map->size) { + } + + if (id <= map->size) { return map->symbols[id - 1]; } + return NULL; } -- cgit v1.2.1