diff options
-rw-r--r-- | .reuse/dep5 | 5 | ||||
-rw-r--r-- | .suppress.cppcheck | 4 | ||||
-rw-r--r-- | meson.build | 22 | ||||
-rw-r--r-- | meson_options.txt | 8 | ||||
-rwxr-xr-x | osx/bundleify.sh | 10 | ||||
-rw-r--r-- | src/AlsaDriver.cpp | 19 | ||||
-rw-r--r-- | src/CanvasModule.hpp | 2 | ||||
-rw-r--r-- | src/CanvasPort.hpp | 2 | ||||
-rw-r--r-- | src/Configuration.hpp | 3 | ||||
-rw-r--r-- | src/Drivers.cpp | 11 | ||||
-rw-r--r-- | src/Drivers.hpp | 4 | ||||
-rw-r--r-- | src/JackLibDriver.cpp | 5 | ||||
-rw-r--r-- | src/Legend.cpp | 1 | ||||
-rw-r--r-- | src/Patchage.cpp | 11 | ||||
-rw-r--r-- | src/Reactor.cpp | 4 | ||||
-rw-r--r-- | src/UIFile.hpp | 7 | ||||
-rw-r--r-- | src/handle_event.cpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 1 |
18 files changed, 73 insertions, 48 deletions
diff --git a/.reuse/dep5 b/.reuse/dep5 index 0685ea3..44e287b 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -7,6 +7,11 @@ Files: .clant.json .includes.imp INSTALL.md NEWS Copyright: 2020-2021 David Robillard <d@drobilla.net> License: 0BSD OR GPL-3.0-or-later +Files: .suppress.cppcheck +Copyright: 2024 David Robillard <d@drobilla.net> +Comment: Contributed to the Commons as a tool configuration +License: 0BSD OR GPL-3.0-or-later + Files: AUTHORS README.md patchage.desktop.in Copyright: 2006-2014 David Robillard <d@drobilla.net> License: 0BSD OR GPL-3.0-or-later diff --git a/.suppress.cppcheck b/.suppress.cppcheck new file mode 100644 index 0000000..c03733a --- /dev/null +++ b/.suppress.cppcheck @@ -0,0 +1,4 @@ +constParameterCallback +constVariablePointer +missingReturn +normalCheckLevelMaxBranches diff --git a/meson.build b/meson.build index 32c79d4..cf9d198 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,7 @@ project( ) patchage_src_root = meson.current_source_dir() +patchage_build_root = meson.current_build_dir() major_version = meson.project_version().split('.')[0] version_suffix = '@0@-@1@'.format(meson.project_name(), major_version) @@ -121,6 +122,7 @@ gtkmm_dep = dependency( ganv_dep = dependency( 'ganv-1', + fallback: ['ganv', 'ganv_dep'], include_type: 'system', version: '>= 1.8.2', ) @@ -267,6 +269,26 @@ if get_option('lint') suite: 'data', ) endif + + # Check code with cppcheck + cppcheck = find_program('cppcheck', required: false) + if cppcheck.found() + compdb_path = join_paths(patchage_build_root, 'compile_commands.json') + suppress_path = join_paths(patchage_src_root, '.suppress.cppcheck') + test( + 'cppcheck', + cppcheck, + args: [ + '--enable=warning,style,performance,portability', + '--error-exitcode=1', + '--project=' + compdb_path, + '--suppressions-list=' + suppress_path, + '-q', + ], + suite: 'code', + timeout: 60, + ) + endif endif # Check licensing metadata diff --git a/meson_options.txt b/meson_options.txt index edc88cd..be37ed4 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,16 +1,16 @@ # Copyright 2022-2023 David Robillard <d@drobilla.net> # SPDX-License-Identifier: 0BSD OR GPL-3.0-or-later -option('alsa', type: 'feature', value: 'auto', yield: true, +option('alsa', type: 'feature', yield: true, description: 'Build ALSA sequencer support') option('checks', type: 'feature', value: 'enabled', yield: true, description: 'Check for platform-specific features') -option('jack', type: 'feature', value: 'auto', yield: true, +option('jack', type: 'feature', yield: true, description: 'Build JACK audio and MIDI support') -option('jack_dbus', type: 'feature', value: 'auto', yield: true, +option('jack_dbus', type: 'feature', yield: true, description: 'Use JACK via D-Bus') option('lint', type: 'boolean', value: false, yield: true, @@ -19,7 +19,7 @@ option('lint', type: 'boolean', value: false, yield: true, option('strict', type: 'boolean', value: false, yield: true, description: 'Enable ultra-strict warnings') -option('tests', type: 'feature', value: 'auto', yield: true, +option('tests', type: 'feature', yield: true, description: 'Build tests') option('title', type: 'string', value: 'Patchage', diff --git a/osx/bundleify.sh b/osx/bundleify.sh index 559795b..665ff9d 100755 --- a/osx/bundleify.sh +++ b/osx/bundleify.sh @@ -36,7 +36,7 @@ done chmod -R 755 $bundle/Contents/lib/* # Copy libraries depended on by the executable to bundle -libs="`otool -L $exe | grep '\.dylib\|\.so' | grep '/User\|/usr/local' | sed 's/(.*//'`" +libs="$(otool -L $exe | grep '\.dylib\|\.so' | grep '/User\|/usr/local' | sed 's/(.*//')" for l in $libs; do cp $l $bundle/Contents/lib/; done @@ -48,7 +48,7 @@ while true; do # Copy all libraries this library depends on to bundle for l in $(find $bundle -name '*.dylib' -or -name '*.so'); do - reclibs="`otool -L $l | grep '\.dylib\|\.so' | grep '/User\|/usr/local' | sed 's/(.*//'`" + reclibs="$(otool -L $l | grep '\.dylib\|\.so' | grep '/User\|/usr/local' | sed 's/(.*//')" for rl in $reclibs; do cp $rl $bundle/Contents/lib/; done @@ -68,15 +68,15 @@ echo "Bundled libraries:" echo "$libs" for l in $libs; do - lname=`echo $l | sed 's/.*\///'` + lname=$(echo $l | sed 's/.*\///') lid="@executable_path/lib/$lname" lpath="$bundle/Contents/lib/$lname" install_name_tool -id $lid $lpath install_name_tool -change $l $lid $exe - for j in `find $bundle -name '*.so' -or -name '*.dylib'`; do + for j in $(find $bundle -name '*.so' -or -name '*.dylib'); do install_name_tool -change $l $lid $j done; done echo "External library references:" -otool -L $exe `find $bundle -name '*.so' -or -name '*.dylib'` | grep -v ':' | grep -v '@executable_path' | sort | uniq +otool -L $exe $(find $bundle -name '*.so' -or -name '*.dylib') | grep -v ':' | grep -v '@executable_path' | sort | uniq diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index 7671402..8424adf 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -133,10 +133,7 @@ AlsaDriver::AlsaDriver(ILog& log, EventSink emit_event) , _log(log) {} -AlsaDriver::~AlsaDriver() -{ - detach(); -} +AlsaDriver::~AlsaDriver() = default; void AlsaDriver::attach(bool /*launch_daemon*/) @@ -395,16 +392,16 @@ AlsaDriver::disconnect(const PortID& tail_id, const PortID& head_id) bool AlsaDriver::create_refresh_port() { - snd_seq_port_info_t* port_info = nullptr; - snd_seq_port_info_alloca(&port_info); - snd_seq_port_info_set_name(port_info, "System Announcement Receiver"); - snd_seq_port_info_set_type(port_info, SND_SEQ_PORT_TYPE_APPLICATION); - snd_seq_port_info_set_capability(port_info, + snd_seq_port_info_t* info = nullptr; + snd_seq_port_info_alloca(&info); + snd_seq_port_info_set_name(info, "System Announcement Receiver"); + snd_seq_port_info_set_type(info, SND_SEQ_PORT_TYPE_APPLICATION); + snd_seq_port_info_set_capability(info, SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE | SND_SEQ_PORT_CAP_NO_EXPORT); - int ret = snd_seq_create_port(_seq, port_info); + int ret = snd_seq_create_port(_seq, info); if (ret) { _log.error( fmt::format("[ALSA] Error creating port ({})", snd_strerror(ret))); @@ -413,7 +410,7 @@ AlsaDriver::create_refresh_port() // Subscribe the port to the system announcer ret = snd_seq_connect_from(_seq, - snd_seq_port_info_get_port(port_info), + snd_seq_port_info_get_port(info), SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE); if (ret) { diff --git a/src/CanvasModule.hpp b/src/CanvasModule.hpp index e15a6b8..e0483cb 100644 --- a/src/CanvasModule.hpp +++ b/src/CanvasModule.hpp @@ -52,7 +52,7 @@ public: CanvasPort* get_port(const PortID& id); SignalDirection type() const { return _type; } - ClientID id() const { return _id; } + const ClientID& id() const { return _id; } const std::string& name() const { return _name; } protected: diff --git a/src/CanvasPort.hpp b/src/CanvasPort.hpp index 0fc2f04..b75ecf5 100644 --- a/src/CanvasPort.hpp +++ b/src/CanvasPort.hpp @@ -90,7 +90,7 @@ public: } PortType type() const { return _type; } - PortID id() const { return _id; } + const PortID& id() const { return _id; } const std::string& name() const { return _name; } const std::string& human_name() const { return _human_name; } const std::optional<int>& order() const { return _order; } diff --git a/src/Configuration.hpp b/src/Configuration.hpp index d956bd8..ffaee6e 100644 --- a/src/Configuration.hpp +++ b/src/Configuration.hpp @@ -74,8 +74,7 @@ public: // Set a global port color setting void set_setting(setting::PortColor new_setting) { - auto& color = _port_colors[static_cast<unsigned>(new_setting.type)]; - + const auto& color = _port_colors[static_cast<unsigned>(new_setting.type)]; if (color != new_setting.color) { set_port_color(new_setting.type, new_setting.color); } diff --git a/src/Drivers.cpp b/src/Drivers.cpp index 94efd14..7104b00 100644 --- a/src/Drivers.cpp +++ b/src/Drivers.cpp @@ -27,6 +27,17 @@ Drivers::Drivers(ILog& log, Driver::EventSink emit_event) })} {} +Drivers::~Drivers() +{ + if (_alsa_driver) { + _alsa_driver->detach(); + } + + if (_jack_driver) { + _jack_driver->detach(); + } +} + void Drivers::refresh() { diff --git a/src/Drivers.hpp b/src/Drivers.hpp index 6bb9eb4..a281d2e 100644 --- a/src/Drivers.hpp +++ b/src/Drivers.hpp @@ -4,13 +4,13 @@ #ifndef PATCHAGE_DRIVERS_HPP #define PATCHAGE_DRIVERS_HPP -#include "AudioDriver.hpp" #include "Driver.hpp" #include <memory> namespace patchage { +class AudioDriver; class ILog; enum class ClientType; @@ -26,7 +26,7 @@ public: Drivers(Drivers&&) = delete; Drivers& operator=(Drivers&&) = delete; - ~Drivers() = default; + ~Drivers(); /// Refresh all drivers and emit results to the event sink void refresh(); diff --git a/src/JackLibDriver.cpp b/src/JackLibDriver.cpp index 6df5b02..b540347 100644 --- a/src/JackLibDriver.cpp +++ b/src/JackLibDriver.cpp @@ -104,10 +104,7 @@ JackLibDriver::JackLibDriver(ILog& log, EventSink emit_event) , _log{log} {} -JackLibDriver::~JackLibDriver() -{ - detach(); -} +JackLibDriver::~JackLibDriver() = default; void JackLibDriver::attach(const bool launch_daemon) diff --git a/src/Legend.cpp b/src/Legend.cpp index 0733e2f..ff0f7fe 100644 --- a/src/Legend.cpp +++ b/src/Legend.cpp @@ -9,7 +9,6 @@ #include "patchage_config.h" #include <gdkmm/color.h> -#include <glibmm/signalproxy.h> #include <glibmm/ustring.h> #include <gtkmm/box.h> #include <gtkmm/colorbutton.h> diff --git a/src/Patchage.cpp b/src/Patchage.cpp index 82c12df..54f81f0 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -46,7 +46,6 @@ PATCHAGE_RESTORE_WARNINGS #include <glibmm/main.h> #include <glibmm/miscutils.h> #include <glibmm/propertyproxy.h> -#include <glibmm/signalproxy.h> #include <glibmm/ustring.h> #include <gobject/gclosure.h> #include <gtk/gtk.h> @@ -172,8 +171,7 @@ update_labels(GanvNode* node, void* data) const bool human_names = *static_cast<const bool*>(data); if (GANV_IS_MODULE(node)) { Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node)); - auto* pmod = dynamic_cast<CanvasModule*>(gmod); - if (pmod) { + if (dynamic_cast<const CanvasModule*>(gmod)) { for (Ganv::Port* gport : *gmod) { auto* pport = dynamic_cast<CanvasPort*>(gport); if (pport) { @@ -205,12 +203,11 @@ update_port_colors(GanvNode* node, void* data) } Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node)); - auto* pmod = dynamic_cast<CanvasModule*>(gmod); - if (!pmod) { + if (!dynamic_cast<CanvasModule*>(gmod)) { return; } - for (Ganv::Port* p : *pmod) { + for (Ganv::Port* p : *gmod) { auto* port = dynamic_cast<CanvasPort*>(p); if (port) { const uint32_t rgba = patchage->conf().get_port_color(port->type()); @@ -227,7 +224,7 @@ update_edge_color(GanvEdge* edge, void* data) Ganv::Edge* edgemm = Glib::wrap(edge); if (edgemm) { - auto* tail = dynamic_cast<CanvasPort*>((edgemm)->get_tail()); + const auto* tail = dynamic_cast<const CanvasPort*>((edgemm)->get_tail()); if (tail) { edgemm->set_color(patchage->conf().get_port_color(tail->type())); } diff --git a/src/Reactor.cpp b/src/Reactor.cpp index 7163539..8bb89d3 100644 --- a/src/Reactor.cpp +++ b/src/Reactor.cpp @@ -191,11 +191,11 @@ Reactor::module_name(const ClientID& client) { // Note that split modules always have the same name - if (CanvasModule* mod = find_module(client, SignalDirection::input)) { + if (const CanvasModule* mod = find_module(client, SignalDirection::input)) { return mod->name(); } - if (CanvasModule* mod = find_module(client, SignalDirection::output)) { + if (const CanvasModule* mod = find_module(client, SignalDirection::output)) { return mod->name(); } diff --git a/src/UIFile.hpp b/src/UIFile.hpp index cd07aad..1f2c39f 100644 --- a/src/UIFile.hpp +++ b/src/UIFile.hpp @@ -13,9 +13,7 @@ #include <glibmm/refptr.h> #include <gtkmm/builder.h> -#include <fstream> #include <iostream> -#include <sstream> #include <stdexcept> #include <string> @@ -53,10 +51,7 @@ public: return Gtk::Builder::create_from_file(ui_filename); } - std::stringstream ss; - ss << "Unable to find " << ui_filename << "\n"; - throw std::runtime_error(ss.str()); - return {}; + throw std::runtime_error("Unable to find " + ui_filename); } }; diff --git a/src/handle_event.cpp b/src/handle_event.cpp index d75c42d..4564a27 100644 --- a/src/handle_event.cpp +++ b/src/handle_event.cpp @@ -79,7 +79,7 @@ public: { _metadata.set_port(event.id, event.info); - auto* const port = + const auto* const port = _canvas.create_port(_conf, _metadata, event.id, event.info); if (!port) { diff --git a/src/main.cpp b/src/main.cpp index 0f4d1b0..3ae4c7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,7 +146,6 @@ main(int argc, char** argv) patchage::Patchage patchage(options); Gtk::Main::run(*patchage.window()); patchage.save(); - } catch (std::exception& e) { std::cerr << "patchage: error: " << e.what() << "\n"; return 1; |