clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

commit 564d6074a9ffa0586d58b4c73eb3ca5a0606a8e9
parent aa411bc0e8dd6dc1c2a2a33e7bce878d49ce0894
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Tue,  7 Sep 2021 21:42:45 +0200

Refactoring/cleanup

Diffstat:
Mexamples/common/param-queue.hh | 12++++++------
Mexamples/common/param-queue.hxx | 34+++++++++++++++++-----------------
Mexamples/glue/clap-plugin.cc | 208++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mexamples/glue/clap-plugin.hh | 88++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mexamples/gui/application.cc | 82++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mexamples/gui/application.hh | 16++++++++--------
Mexamples/gui/parameter-proxy.cc | 52++++++++++++++++++++++++++--------------------------
Mexamples/gui/parameter-proxy.hh | 44++++++++++++++++++++++----------------------
Mexamples/gui/plugin-proxy.cc | 12++++++------
Mexamples/gui/plugin-proxy.hh | 2+-
Mexamples/host/CMakeLists.txt | 2--
Mexamples/host/application.cc | 48++++++++++++++++++++++++------------------------
Mexamples/host/application.hh | 20++++++++++----------
Mexamples/host/audio-settings-widget.cc | 42+++++++++++++++++++++---------------------
Mexamples/host/audio-settings-widget.hh | 6+++---
Mexamples/host/audio-settings.cc | 16++++++++--------
Mexamples/host/audio-settings.hh | 18+++++++++---------
Dexamples/host/device-reference.cc | 1-
Mexamples/host/device-reference.hh | 4++--
Mexamples/host/engine.cc | 148++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mexamples/host/engine.hh | 34+++++++++++++++++-----------------
Mexamples/host/main-window.cc | 56++++++++++++++++++++++++++++----------------------------
Mexamples/host/main-window.hh | 16++++++++--------
Mexamples/host/midi-settings-widget.cc | 14+++++++-------
Mexamples/host/midi-settings-widget.hh | 2+-
Mexamples/host/midi-settings.cc | 8++++----
Mexamples/host/midi-settings.hh | 6+++---
Mexamples/host/plugin-host.cc | 452++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mexamples/host/plugin-host.hh | 112++++++++++++++++++++++++++++++++++++++++----------------------------------------
Dexamples/host/plugin-info.cc | 3---
Mexamples/host/plugin-info.hh | 8++++----
Mexamples/host/plugin-param.cc | 28++++++++++++++--------------
Mexamples/host/plugin-param.hh | 32++++++++++++++++----------------
Mexamples/host/plugin-parameters-widget.cc | 240++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mexamples/host/plugin-parameters-widget.hh | 52++++++++++++++++++++++++++--------------------------
Mexamples/host/plugin-quick-control-widget.cc | 48++++++++++++++++++++++++------------------------
Mexamples/host/plugin-quick-control-widget.hh | 6+++---
Mexamples/host/plugin-quick-controls-widget.cc | 30+++++++++++++++---------------
Mexamples/host/plugin-quick-controls-widget.hh | 6+++---
Mexamples/host/settings-dialog.cc | 6+++---
Mexamples/host/settings-dialog.hh | 4++--
Mexamples/host/settings-widget.cc | 10+++++-----
Mexamples/host/settings-widget.hh | 12++++--------
Mexamples/host/settings.cc | 8++++----
Mexamples/host/settings.hh | 8++++----
Mexamples/io/buffer.hh | 30+++++++++++++++---------------
Mexamples/io/remote-channel.cc | 78+++++++++++++++++++++++++++++++++++++++---------------------------------------
Mexamples/io/remote-channel.hh | 22+++++++++++-----------
Mexamples/plugins/abstract-gui.hh | 4++--
Mexamples/plugins/core-plugin.cc | 90++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mexamples/plugins/core-plugin.hh | 40++++++++++++++++++++--------------------
Mexamples/plugins/dc-offset/dc-offset.cc | 22+++++++++++-----------
Mexamples/plugins/dc-offset/dc-offset.hh | 4++--
Mexamples/plugins/gain/gain.cc | 18+++++++++---------
Mexamples/plugins/gain/gain.hh | 2+-
Mexamples/plugins/parameter-interpolator.hh | 54+++++++++++++++++++++++++++---------------------------
Mexamples/plugins/parameters.cc | 16++++++++--------
Mexamples/plugins/parameters.hh | 98+++++++++++++++++++++++++++++++++++++------------------------------------------
Mexamples/plugins/remote-gui.cc | 76++++++++++++++++++++++++++++++++++++++--------------------------------------
Mexamples/plugins/remote-gui.hh | 12++++++------
Mexamples/plugins/stream-helper.hh | 12++++++------
61 files changed, 1309 insertions(+), 1325 deletions(-)

diff --git a/examples/common/param-queue.hh b/examples/common/param-queue.hh @@ -16,16 +16,16 @@ public: void setCapacity(size_t capacity); - void set(clap_id id, const value_type& value); + void set(clap_id id, const value_type &value); void producerDone(); - void consume(const std::function<void(clap_id id, const value_type& value)> consumer); + void consume(const std::function<void(clap_id id, const value_type &value)> consumer); void reset(); private: - queue_type queues_[2]; - std::atomic<queue_type *> free_ = nullptr; - std::atomic<queue_type *> producer_ = nullptr; - std::atomic<queue_type *> consumer_ = nullptr; + queue_type _queues[2]; + std::atomic<queue_type *> _free = nullptr; + std::atomic<queue_type *> _producer = nullptr; + std::atomic<queue_type *> _consumer = nullptr; }; \ No newline at end of file diff --git a/examples/common/param-queue.hxx b/examples/common/param-queue.hxx @@ -9,51 +9,51 @@ ParamQueue<T>::ParamQueue() { reset(); } template<typename T> void ParamQueue<T>::reset() { - for (auto &q : queues_) + for (auto &q : _queues) q.clear(); - free_ = &queues_[0]; - producer_ = &queues_[1]; - consumer_ = nullptr; + _free = &_queues[0]; + _producer = &_queues[1]; + _consumer = nullptr; } template<typename T> void ParamQueue<T>::setCapacity(size_t capacity) { - for (auto &q : queues_) + for (auto &q : _queues) q.reserve(2 * capacity); } template<typename T> void ParamQueue<T>::set(clap_id id, const value_type& value) { - producer_.load()->emplace(id, value); + _producer.load()->emplace(id, value); } template<typename T> void ParamQueue<T>::producerDone() { - if (consumer_) + if (_consumer) return; - consumer_.store(producer_.load()); - producer_.store(free_.load()); - free_.store(nullptr); + _consumer.store(_producer.load()); + _producer.store(_free.load()); + _free.store(nullptr); - assert(producer_); + assert(_producer); } template<typename T> void ParamQueue<T>::consume(const std::function<void(clap_id, const value_type& value)> consumer) { assert(consumer); - if (!consumer_) + if (!_consumer) return; - for (auto &x : *consumer_) + for (auto &x : *_consumer) consumer(x.first, x.second); - consumer_.load()->clear(); - if (free_) + _consumer.load()->clear(); + if (_free) return; - free_ = consumer_.load(); - consumer_ = nullptr; + _free = _consumer.load(); + _consumer = nullptr; } diff --git a/examples/glue/clap-plugin.cc b/examples/glue/clap-plugin.cc @@ -10,7 +10,7 @@ namespace clap { - Plugin::Plugin(const clap_plugin_descriptor *desc, const clap_host *host) : host_(host) { + Plugin::Plugin(const clap_plugin_descriptor *desc, const clap_host *host) : _host(host) { plugin_.plugin_data = this; plugin_.desc = desc; plugin_.init = Plugin::clapInit; @@ -57,13 +57,13 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin.activate"); - if (self.isActive_) { + if (self._isActive) { self.hostMisbehaving("Plugin was activated twice"); - if (sample_rate != self.sampleRate_) { + if (sample_rate != self._sampleRate) { std::ostringstream msg; msg << "The plugin was activated twice and with different sample rates: " - << self.sampleRate_ << " and " << sample_rate + << self._sampleRate << " and " << sample_rate << ". The host must deactivate the plugin first." << std::endl << "Simulating deactivation."; self.hostMisbehaving(msg.str()); @@ -78,17 +78,17 @@ namespace clap { return false; } - assert(!self.isActive_); - assert(self.sampleRate_ == 0); + assert(!self._isActive); + assert(self._sampleRate == 0); if (!self.activate(sample_rate)) { - assert(!self.isActive_); - assert(self.sampleRate_ == 0); + assert(!self._isActive); + assert(self._sampleRate == 0); return false; } - self.isActive_ = true; - self.sampleRate_ = sample_rate; + self._isActive = true; + self._sampleRate = sample_rate; return true; } @@ -96,50 +96,50 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin.deactivate"); - if (!self.isActive_) { + if (!self._isActive) { self.hostMisbehaving("The plugin was deactivated twice."); return; } self.deactivate(); - self.isActive_ = false; - self.sampleRate_ = 0; + self._isActive = false; + self._sampleRate = 0; } bool Plugin::clapStartProcessing(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureAudioThread("clap_plugin.start_processing"); - if (!self.isActive_) { + if (!self._isActive) { self.hostMisbehaving("Host called clap_plugin.start_processing() on a deactivated plugin"); return false; } - if (self.isProcessing_) { + if (self._isProcessing) { self.hostMisbehaving("Host called clap_plugin.start_processing() twice"); return true; } - self.isProcessing_ = self.startProcessing(); - return self.isProcessing_; + self._isProcessing = self.startProcessing(); + return self._isProcessing; } void Plugin::clapStopProcessing(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureAudioThread("clap_plugin.stop_processing"); - if (!self.isActive_) { + if (!self._isActive) { self.hostMisbehaving("Host called clap_plugin.stop_processing() on a deactivated plugin"); return; } - if (!self.isProcessing_) { + if (!self._isProcessing) { self.hostMisbehaving("Host called clap_plugin.stop_processing() twice"); return; } self.stopProcessing(); - self.isProcessing_ = false; + self._isProcessing = false; } clap_process_status Plugin::clapProcess(const clap_plugin *plugin, @@ -147,12 +147,12 @@ namespace clap { auto &self = from(plugin); self.ensureAudioThread("clap_plugin.process"); - if (!self.isActive_) { + if (!self._isActive) { self.hostMisbehaving("Host called clap_plugin.process() on a deactivated plugin"); return CLAP_PROCESS_ERROR; } - if (!self.isProcessing_) { + if (!self._isProcessing) { self.hostMisbehaving( "Host called clap_plugin.process() without calling clap_plugin.start_processing()"); return CLAP_PROCESS_ERROR; @@ -166,39 +166,39 @@ namespace clap { self.ensureMainThread("clap_plugin.extension"); if (!strcmp(id, CLAP_EXT_STATE) && self.implementsState()) - return &pluginState_; + return &_pluginState; if (!strcmp(id, CLAP_EXT_PRESET_LOAD) && self.implementsPresetLoad()) - return &pluginPresetLoad_; + return &_pluginPresetLoad; if (!strcmp(id, CLAP_EXT_RENDER) && self.implementsRender()) - return &pluginRender_; + return &_pluginRender; if (!strcmp(id, CLAP_EXT_TRACK_INFO) && self.implementsTrackInfo()) - return &pluginTrackInfo_; + return &_pluginTrackInfo; if (!strcmp(id, CLAP_EXT_LATENCY) && self.implementsLatency()) - return &pluginLatency_; + return &_pluginLatency; if (!strcmp(id, CLAP_EXT_AUDIO_PORTS) && self.implementsAudioPorts()) - return &pluginAudioPorts_; + return &_pluginAudioPorts; if (!strcmp(id, CLAP_EXT_PARAMS) && self.implementsParams()) - return &pluginParams_; + return &_pluginParams; if (!strcmp(id, CLAP_EXT_QUICK_CONTROLS) && self.implementQuickControls()) - return &pluginQuickControls_; + return &_pluginQuickControls; if (!strcmp(id, CLAP_EXT_NOTE_NAME) && self.implementsNoteName()) - return &pluginNoteName_; + return &_pluginNoteName; if (!strcmp(id, CLAP_EXT_THREAD_POOL) && self.implementsThreadPool()) - return &pluginThreadPool_; + return &_pluginThreadPool; if (!strcmp(id, CLAP_EXT_TIMER_SUPPORT) && self.implementsTimerSupport()) - return &pluginTimerSupport_; + return &_pluginTimerSupport; if (!strcmp(id, CLAP_EXT_FD_SUPPORT) && self.implementsFdSupport()) - return &pluginFdSupport_; + return &_pluginFdSupport; if (!strcmp(id, CLAP_EXT_GUI) && self.implementsGui()) - return &pluginGui_; + return &_pluginGui; if (!strcmp(id, CLAP_EXT_GUI_X11) && self.implementsGuiX11()) - return &pluginGuiX11_; + return &_pluginGuiX11; if (!strcmp(id, CLAP_EXT_GUI_WIN32) && self.implementsGuiWin32()) - return &pluginGuiWin32_; + return &_pluginGuiWin32; if (!strcmp(id, CLAP_EXT_GUI_COCOA) && self.implementsGuiCocoa()) - return &pluginGuiCocoa_; + return &_pluginGuiCocoa; if (!strcmp(id, CLAP_EXT_GUI_FREE_STANDING) && self.implementsGuiFreeStanding()) - return &pluginGuiFreeStanding_; + return &_pluginGuiFreeStanding; return from(plugin).extension(id); } @@ -208,25 +208,25 @@ namespace clap { assert(!ptr); assert(id); - if (host_->get_extension) - ptr = static_cast<const T *>(host_->get_extension(host_, id)); + if (_host->get_extension) + ptr = static_cast<const T *>(_host->get_extension(_host, id)); } void Plugin::initInterfaces() noexcept { - initInterface(hostLog_, CLAP_EXT_LOG); - initInterface(hostThreadCheck_, CLAP_EXT_THREAD_CHECK); - initInterface(hostThreadPool_, CLAP_EXT_THREAD_POOL); - initInterface(hostAudioPorts_, CLAP_EXT_AUDIO_PORTS); - initInterface(hostTimerSupport_, CLAP_EXT_TIMER_SUPPORT); - initInterface(hostFdSupport_, CLAP_EXT_FD_SUPPORT); - initInterface(hostEventFilter_, CLAP_EXT_EVENT_FILTER); - initInterface(hostFileReference_, CLAP_EXT_FILE_REFERENCE); - initInterface(hostLatency_, CLAP_EXT_LATENCY); - initInterface(hostGui_, CLAP_EXT_GUI); - initInterface(hostParams_, CLAP_EXT_PARAMS); - initInterface(hostTrackInfo_, CLAP_EXT_TRACK_INFO); - initInterface(hostState_, CLAP_EXT_STATE); - initInterface(hostNoteName_, CLAP_EXT_NOTE_NAME); + initInterface(_hostLog, CLAP_EXT_LOG); + initInterface(_hostThreadCheck, CLAP_EXT_THREAD_CHECK); + initInterface(_hostThreadPool, CLAP_EXT_THREAD_POOL); + initInterface(_hostAudioPorts, CLAP_EXT_AUDIO_PORTS); + initInterface(_hostTimerSupport, CLAP_EXT_TIMER_SUPPORT); + initInterface(_hostFdSupport, CLAP_EXT_FD_SUPPORT); + initInterface(_hostEventFilter, CLAP_EXT_EVENT_FILTER); + initInterface(_hostFileReference, CLAP_EXT_FILE_REFERENCE); + initInterface(_hostLatency, CLAP_EXT_LATENCY); + initInterface(_hostGui, CLAP_EXT_GUI); + initInterface(_hostParams, CLAP_EXT_PARAMS); + initInterface(_hostTrackInfo, CLAP_EXT_TRACK_INFO); + initInterface(_hostState, CLAP_EXT_STATE); + initInterface(_hostNoteName, CLAP_EXT_NOTE_NAME); } //-------------------// @@ -602,7 +602,7 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.size"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving("clap_plugin_gui.size() was called without a prior call to " "clap_plugin_gui.create()"); return false; @@ -615,7 +615,7 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.can_resize"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving("clap_plugin_gui.can_resize() was called without a prior call to " "clap_plugin_gui.create()"); return false; @@ -629,7 +629,7 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.round_size"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving("clap_plugin_gui.round_size() was called without a prior call to " "clap_plugin_gui.create()"); return; @@ -643,7 +643,7 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.set_size"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving("clap_plugin_gui.set_size() was called without a prior call to " "clap_plugin_gui.create()"); return false; @@ -673,7 +673,7 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.set_scale"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving("clap_plugin_gui.set_scale() was called without a prior call to " "clap_plugin_gui.create()"); return; @@ -686,13 +686,13 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.show"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving( "clap_plugin_gui.show() was called without a prior call to clap_plugin_gui.create()"); return; } - if (!self.isGuiAttached_) { + if (!self._isGuiAttached) { self.hostMisbehaving("clap_plugin_gui.show() but the gui was not attached first"); return; } @@ -704,13 +704,13 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.hide"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving( "clap_plugin_gui.hide() was called without a prior call to clap_plugin_gui.create()"); return; } - if (!self.isGuiAttached_) { + if (!self._isGuiAttached) { self.hostMisbehaving("clap_plugin_gui.hide() but the gui was not attached first"); return; } @@ -722,7 +722,7 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.create"); - if (self.isGuiCreated_) { + if (self._isGuiCreated) { self.hostMisbehaving( "clap_plugin_gui.create() was called while the plugin gui was already created"); return true; @@ -731,8 +731,8 @@ namespace clap { if (!self.guiCreate()) return false; - self.isGuiCreated_ = true; - self.isGuiAttached_ = false; + self._isGuiCreated = true; + self._isGuiAttached = false; return true; } @@ -740,15 +740,15 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.destroy"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving( "clap_plugin_gui.destroy() was called while the plugin gui not created"); return; } self.guiDestroy(); - self.isGuiCreated_ = false; - self.isGuiAttached_ = false; + self._isGuiCreated = false; + self._isGuiAttached = false; } //---------------------// @@ -760,13 +760,13 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui_x11.attach"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving( "clap_plugin_gui_x11.attach() was called without a prior call to clap_plugin_gui.create()"); return false; } - if (self.isGuiAttached_) { + if (self._isGuiAttached) { self.hostMisbehaving("clap_plugin_gui_x11.attach() but the gui was already attached"); return true; } @@ -774,7 +774,7 @@ namespace clap { if (!self.guiX11Attach(display_name, window)) return false; - self.isGuiAttached_ = true; + self._isGuiAttached = true; return true; } @@ -785,13 +785,13 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui_win32.attach"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving( "clap_plugin_gui_win32.attach() was called without a prior call to clap_plugin_gui.create()"); return false; } - if (self.isGuiAttached_) { + if (self._isGuiAttached) { self.hostMisbehaving("clap_plugin_gui_win32.attach() but the gui was already attached"); return true; } @@ -799,7 +799,7 @@ namespace clap { if (!self.guiWin32Attach(window)) return false; - self.isGuiAttached_ = true; + self._isGuiAttached = true; return true; } @@ -810,13 +810,13 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui_cocoa.attach"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving( "clap_plugin_gui_cocoa.attach() was called without a prior call to clap_plugin_gui.create()"); return false; } - if (self.isGuiAttached_) { + if (self._isGuiAttached) { self.hostMisbehaving("clap_plugin_gui_cocoa.attach() but the gui was already attached"); return true; } @@ -824,7 +824,7 @@ namespace clap { if (!self.guiCocoaAttach(nsView)) return false; - self.isGuiAttached_ = true; + self._isGuiAttached = true; return true; } @@ -835,13 +835,13 @@ namespace clap { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui_free_standing.open"); - if (!self.isGuiCreated_) { + if (!self._isGuiCreated) { self.hostMisbehaving( "clap_plugin_gui_free_standing.open() was called without a prior call to clap_plugin_gui.create()"); return false; } - if (self.isGuiAttached_) { + if (self._isGuiAttached) { self.hostMisbehaving("clap_plugin_gui_free_standing.open() but the gui was already attached"); return true; } @@ -849,7 +849,7 @@ namespace clap { if (!self.guiFreeStandingOpen()) return false; - self.isGuiAttached_ = true; + self._isGuiAttached = true; return true; } @@ -858,7 +858,7 @@ namespace clap { ///////////// void Plugin::log(clap_log_severity severity, const char *msg) const noexcept { if (canUseHostLog()) - hostLog_->log(host_, severity, msg); + _hostLog->log(_host, severity, msg); else std::clog << msg << std::endl; } @@ -871,18 +871,18 @@ namespace clap { // Interface consistency check // ///////////////////////////////// - bool Plugin::canUseHostLog() const noexcept { return hostLog_ && hostLog_->log; } + bool Plugin::canUseHostLog() const noexcept { return _hostLog && _hostLog->log; } bool Plugin::canUseThreadCheck() const noexcept { - return hostThreadCheck_ && hostThreadCheck_->is_audio_thread && - hostThreadCheck_->is_main_thread; + return _hostThreadCheck && _hostThreadCheck->is_audio_thread && + _hostThreadCheck->is_main_thread; } bool Plugin::canUseTimerSupport() const noexcept { - if (!hostTimerSupport_) + if (!_hostTimerSupport) return false; - auto &x = *hostTimerSupport_; + auto &x = *_hostTimerSupport; if (x.register_timer && x.unregister_timer) return true; @@ -891,10 +891,10 @@ namespace clap { } bool Plugin::canUseFdSupport() const noexcept { - if (!hostFdSupport_) + if (!_hostFdSupport) return false; - auto &x = *hostFdSupport_; + auto &x = *_hostFdSupport; if (x.modify_fd && x.register_fd && x.unregister_fd) return true; @@ -903,10 +903,10 @@ namespace clap { } bool Plugin::canUseParams() const noexcept { - if (!hostParams_) + if (!_hostParams) return false; - if (hostParams_->rescan && hostParams_->clear) + if (_hostParams->rescan && _hostParams->clear) return true; hostMisbehaving("clap_host_params is partially implemented"); @@ -914,10 +914,10 @@ namespace clap { } bool Plugin::canUseLatency() const noexcept { - if (!hostLatency_) + if (!_hostLatency) return false; - if (hostLatency_->changed) + if (_hostLatency->changed) return true; hostMisbehaving("clap_host_latency is partially implemented"); @@ -925,10 +925,10 @@ namespace clap { } bool Plugin::canUseState() const noexcept { - if (!hostState_) + if (!_hostState) return false; - if (hostState_->mark_dirty) + if (_hostState->mark_dirty) return true; hostMisbehaving("clap_host_state is partially implemented"); @@ -936,10 +936,10 @@ namespace clap { } bool Plugin::canUseTrackInfo() const noexcept { - if (!hostTrackInfo_) + if (!_hostTrackInfo) return false; - if (hostTrackInfo_->get) + if (_hostTrackInfo->get) return true; hostMisbehaving("clap_host_track_info is partially implemented"); @@ -951,16 +951,16 @@ namespace clap { ///////////////////// void Plugin::checkMainThread() const noexcept { - if (!hostThreadCheck_ || !hostThreadCheck_->is_main_thread || - hostThreadCheck_->is_main_thread(host_)) + if (!_hostThreadCheck || !_hostThreadCheck->is_main_thread || + _hostThreadCheck->is_main_thread(_host)) return; std::terminate(); } void Plugin::ensureMainThread(const char *method) const noexcept { - if (!hostThreadCheck_ || !hostThreadCheck_->is_main_thread || - hostThreadCheck_->is_main_thread(host_)) + if (!_hostThreadCheck || !_hostThreadCheck->is_main_thread || + _hostThreadCheck->is_main_thread(_host)) return; std::ostringstream msg; @@ -971,8 +971,8 @@ namespace clap { } void Plugin::ensureAudioThread(const char *method) const noexcept { - if (!hostThreadCheck_ || !hostThreadCheck_->is_audio_thread || - hostThreadCheck_->is_audio_thread(host_)) + if (!_hostThreadCheck || !_hostThreadCheck->is_audio_thread || + _hostThreadCheck->is_audio_thread(_host)) return; std::ostringstream msg; diff --git a/examples/glue/clap-plugin.hh b/examples/glue/clap-plugin.hh @@ -68,7 +68,7 @@ namespace clap { virtual bool stateLoad(clap_istream *stream) noexcept { return false; } void stateMarkDirty() const noexcept { if (canUseState()) - hostState_->mark_dirty(host_); + _hostState->mark_dirty(_host); } //-------------------------// @@ -231,30 +231,30 @@ namespace clap { ////////////////////// // Processing State // ////////////////////// - bool isActive() const noexcept { return isActive_; } - bool isProcessing() const noexcept { return isProcessing_; } + bool isActive() const noexcept { return _isActive; } + bool isProcessing() const noexcept { return _isProcessing; } int sampleRate() const noexcept { - assert(isActive_ && "sample rate is only known if the plugin is active"); - assert(sampleRate_ > 0); - return sampleRate_; + assert(_isActive && "sample rate is only known if the plugin is active"); + assert(_sampleRate > 0); + return _sampleRate; } protected: - const clap_host *const host_ = nullptr; - const clap_host_log *hostLog_ = nullptr; - const clap_host_thread_check *hostThreadCheck_ = nullptr; - const clap_host_thread_pool *hostThreadPool_ = nullptr; - const clap_host_audio_ports *hostAudioPorts_ = nullptr; - const clap_host_event_filter *hostEventFilter_ = nullptr; - const clap_host_file_reference *hostFileReference_ = nullptr; - const clap_host_latency *hostLatency_ = nullptr; - const clap_host_gui *hostGui_ = nullptr; - const clap_host_timer_support *hostTimerSupport_ = nullptr; - const clap_host_fd_support *hostFdSupport_ = nullptr; - const clap_host_params *hostParams_ = nullptr; - const clap_host_track_info *hostTrackInfo_ = nullptr; - const clap_host_state *hostState_ = nullptr; - const clap_host_note_name *hostNoteName_ = nullptr; + const clap_host *const _host = nullptr; + const clap_host_log *_hostLog = nullptr; + const clap_host_thread_check *_hostThreadCheck = nullptr; + const clap_host_thread_pool *_hostThreadPool = nullptr; + const clap_host_audio_ports *_hostAudioPorts = nullptr; + const clap_host_event_filter *_hostEventFilter = nullptr; + const clap_host_file_reference *_hostFileReference = nullptr; + const clap_host_latency *_hostLatency = nullptr; + const clap_host_gui *_hostGui = nullptr; + const clap_host_timer_support *_hostTimerSupport = nullptr; + const clap_host_fd_support *_hostFdSupport = nullptr; + const clap_host_params *_hostParams = nullptr; + const clap_host_track_info *_hostTrackInfo = nullptr; + const clap_host_state *_hostState = nullptr; + const clap_host_note_name *_hostNoteName = nullptr; private: ///////////////////// @@ -371,39 +371,39 @@ namespace clap { static bool clapGuiFreeStandingOpen(const clap_plugin *plugin) noexcept; // interfaces - static const constexpr clap_plugin_render pluginRender_ = { + static const constexpr clap_plugin_render _pluginRender = { clapRenderSetMode, }; - static const constexpr clap_plugin_thread_pool pluginThreadPool_ = { + static const constexpr clap_plugin_thread_pool _pluginThreadPool = { clapThreadPoolExec, }; - static const constexpr clap_plugin_state pluginState_ = { + static const constexpr clap_plugin_state _pluginState = { clapStateSave, clapStateLoad, }; - static const constexpr clap_plugin_preset_load pluginPresetLoad_ = { + static const constexpr clap_plugin_preset_load _pluginPresetLoad = { clapPresetLoadFromFile, }; - static const constexpr clap_plugin_track_info pluginTrackInfo_ = { + static const constexpr clap_plugin_track_info _pluginTrackInfo = { clapTrackInfoChanged, }; - static const constexpr clap_plugin_audio_ports pluginAudioPorts_ = { + static const constexpr clap_plugin_audio_ports _pluginAudioPorts = { clapAudioPortsCount, clapAudioPortsInfo }; - static const constexpr clap_plugin_audio_ports_config pluginAudioPortsConfig_ = { + static const constexpr clap_plugin_audio_ports_config _pluginAudioPortsConfig = { clapAudioPortsConfigCount, clapAudioPortsGetConfig, clapAudioPortsSetConfig, }; - static const constexpr clap_plugin_params pluginParams_ = { + static const constexpr clap_plugin_params _pluginParams = { clapParamsCount, clapParamsInfo, clapParamsValue, @@ -411,31 +411,31 @@ namespace clap { clapParamsTextToValue, }; - static const constexpr clap_plugin_quick_controls pluginQuickControls_ = { + static const constexpr clap_plugin_quick_controls _pluginQuickControls = { clapQuickControlsPageCount, clapQuickControlsPageInfo, clapQuickControlsSelectPage, clapQuickControlsSelectedPage, }; - static const constexpr clap_plugin_latency pluginLatency_ = { + static const constexpr clap_plugin_latency _pluginLatency = { clapLatencyGet, }; - static const constexpr clap_plugin_note_name pluginNoteName_ = { + static const constexpr clap_plugin_note_name _pluginNoteName = { clapNoteNameCount, clapNoteNameGet, }; - static const constexpr clap_plugin_timer_support pluginTimerSupport_ = { + static const constexpr clap_plugin_timer_support _pluginTimerSupport = { clapOnTimer }; - static const constexpr clap_plugin_fd_support pluginFdSupport_ = { + static const constexpr clap_plugin_fd_support _pluginFdSupport = { clapOnFd, }; - static const constexpr clap_plugin_gui pluginGui_ = { + static const constexpr clap_plugin_gui _pluginGui = { clapGuiCreate, clapGuiDestroy, clapGuiSetScale, @@ -447,28 +447,28 @@ namespace clap { clapGuiHide, }; - static const constexpr clap_plugin_gui_x11 pluginGuiX11_ = { + static const constexpr clap_plugin_gui_x11 _pluginGuiX11 = { clapGuiX11Attach, }; - static const constexpr clap_plugin_gui_win32 pluginGuiWin32_ = { + static const constexpr clap_plugin_gui_win32 _pluginGuiWin32 = { clapGuiWin32Attach, }; - static const constexpr clap_plugin_gui_cocoa pluginGuiCocoa_ = { + static const constexpr clap_plugin_gui_cocoa _pluginGuiCocoa = { clapGuiCocoaAttach, }; - static const constexpr clap_plugin_gui_free_standing pluginGuiFreeStanding_ = { + static const constexpr clap_plugin_gui_free_standing _pluginGuiFreeStanding = { clapGuiFreeStandingOpen, }; // state - bool isActive_ = false; - bool isProcessing_ = false; - double sampleRate_ = 0; + bool _isActive = false; + bool _isProcessing = false; + double _sampleRate = 0; - bool isGuiCreated_ = false; - bool isGuiAttached_ = false; + bool _isGuiCreated = false; + bool _isGuiAttached = false; }; } // namespace clap \ No newline at end of file diff --git a/examples/gui/application.cc b/examples/gui/application.cc @@ -9,7 +9,7 @@ #include "application.hh" Application::Application(int &argc, char **argv) - : QGuiApplication(argc, argv), quickView_(new QQuickView()) { + : QGuiApplication(argc, argv), _quickView(new QQuickView()) { bool waitForDebbugger = false; while (waitForDebbugger) @@ -31,64 +31,64 @@ Application::Application(int &argc, char **argv) parser.process(*this); - pluginProxy_ = new PluginProxy(this); + _pluginProxy = new PluginProxy(this); - auto qmlContext = quickView_->engine()->rootContext(); + auto qmlContext = _quickView->engine()->rootContext(); for (const auto &str : parser.values(qmlLibOpt)) - quickView_->engine()->addImportPath(str); - qmlContext->setContextProperty("plugin", pluginProxy_); + _quickView->engine()->addImportPath(str); + qmlContext->setContextProperty("plugin", _pluginProxy); - quickView_->setSource(parser.value(skinOpt) + "/main.qml"); + _quickView->setSource(parser.value(skinOpt) + "/main.qml"); auto socket = parser.value(socketOpt).toULongLong(); - socketReadNotifier_.reset(new QSocketNotifier(socket, QSocketNotifier::Read, this)); - connect(socketReadNotifier_.get(), + _socketReadNotifier.reset(new QSocketNotifier(socket, QSocketNotifier::Read, this)); + connect(_socketReadNotifier.get(), &QSocketNotifier::activated, [this](QSocketDescriptor socket, QSocketNotifier::Type type) { - remoteChannel_->onRead(); - if (!remoteChannel_->isOpen()) + _remoteChannel->onRead(); + if (!_remoteChannel->isOpen()) quit(); }); - socketWriteNotifier_.reset(new QSocketNotifier(socket, QSocketNotifier::Write, this)); - connect(socketWriteNotifier_.get(), + _socketWriteNotifier.reset(new QSocketNotifier(socket, QSocketNotifier::Write, this)); + connect(_socketWriteNotifier.get(), &QSocketNotifier::activated, [this](QSocketDescriptor socket, QSocketNotifier::Type type) { - remoteChannel_->onWrite(); - if (!remoteChannel_->isOpen()) { + _remoteChannel->onWrite(); + if (!_remoteChannel->isOpen()) { quit(); } }); - socketErrorNotifier_.reset(new QSocketNotifier(socket, QSocketNotifier::Exception, this)); - connect(socketErrorNotifier_.get(), + _socketErrorNotifier.reset(new QSocketNotifier(socket, QSocketNotifier::Exception, this)); + connect(_socketErrorNotifier.get(), &QSocketNotifier::activated, [this](QSocketDescriptor socket, QSocketNotifier::Type type) { - remoteChannel_->onError(); + _remoteChannel->onError(); quit(); }); - remoteChannel_.reset(new clap::RemoteChannel( + _remoteChannel.reset(new clap::RemoteChannel( [this](const clap::RemoteChannel::Message &msg) { onMessage(msg); }, *this, socket, false)); - socketReadNotifier_->setEnabled(true); - socketWriteNotifier_->setEnabled(false); - socketErrorNotifier_->setEnabled(false); + _socketReadNotifier->setEnabled(true); + _socketWriteNotifier->setEnabled(false); + _socketErrorNotifier->setEnabled(false); QCoreApplication::arguments(); } void Application::modifyFd(clap_fd_flags flags) { - socketReadNotifier_->setEnabled(flags & CLAP_FD_READ); - socketWriteNotifier_->setEnabled(flags & CLAP_FD_WRITE); - socketErrorNotifier_->setEnabled(flags & CLAP_FD_ERROR); + _socketReadNotifier->setEnabled(flags & CLAP_FD_READ); + _socketWriteNotifier->setEnabled(flags & CLAP_FD_WRITE); + _socketErrorNotifier->setEnabled(flags & CLAP_FD_ERROR); } void Application::removeFd() { - socketReadNotifier_.reset(); - socketWriteNotifier_.reset(); - socketErrorNotifier_.reset(); + _socketReadNotifier.reset(); + _socketWriteNotifier.reset(); + _socketErrorNotifier.reset(); quit(); } @@ -96,21 +96,21 @@ void Application::onMessage(const clap::RemoteChannel::Message &msg) { switch (msg.type) { case clap::messages::kDestroyRequest: clap::messages::DestroyResponse rp; - remoteChannel_->sendResponseAsync(rp, msg.cookie); + _remoteChannel->sendResponseAsync(rp, msg.cookie); quit(); break; case clap::messages::kDefineParameterRequest: { clap::messages::DefineParameterRequest rq; msg.get(rq); - pluginProxy_->defineParameter(rq.info); + _pluginProxy->defineParameter(rq.info); break; } case clap::messages::kParameterValueRequest: { clap::messages::ParameterValueRequest rq; msg.get(rq); - auto p = pluginProxy_->param(rq.paramId); + auto p = _pluginProxy->param(rq.paramId); p->setValueFromPlugin(rq.value); p->setModulationFromPlugin(rq.modulation); break; @@ -118,10 +118,10 @@ void Application::onMessage(const clap::RemoteChannel::Message &msg) { case clap::messages::kSizeRequest: { clap::messages::SizeResponse rp; - auto rootItem = quickView_->rootObject(); + auto rootItem = _quickView->rootObject(); rp.width = rootItem ? rootItem->width() : 500; rp.height = rootItem ? rootItem->height() : 300; - remoteChannel_->sendResponseAsync(rp, msg.cookie); + _remoteChannel->sendResponseAsync(rp, msg.cookie); break; } @@ -131,13 +131,13 @@ void Application::onMessage(const clap::RemoteChannel::Message &msg) { msg.get(rq); #ifdef Q_OS_LINUX - hostWindow_.reset(QWindow::fromWinId(rq.window)); - quickView_->setParent(hostWindow_.get()); + _hostWindow.reset(QWindow::fromWinId(rq.window)); + _quickView->setParent(_hostWindow.get()); sync(); rp.succeed = true; #endif - remoteChannel_->sendResponseAsync(rp, msg.cookie); + _remoteChannel->sendResponseAsync(rp, msg.cookie); break; } @@ -152,7 +152,7 @@ void Application::onMessage(const clap::RemoteChannel::Message &msg) { rp.succeed = true; #endif - remoteChannel_->sendResponseAsync(rp, msg.cookie); + _remoteChannel->sendResponseAsync(rp, msg.cookie); break; } @@ -168,21 +168,21 @@ void Application::onMessage(const clap::RemoteChannel::Message &msg) { rp.succeed = true; #endif - remoteChannel_->sendResponseAsync(rp, msg.cookie); + _remoteChannel->sendResponseAsync(rp, msg.cookie); break; } case clap::messages::kShowRequest: { - quickView_->show(); + _quickView->show(); clap::messages::ShowResponse rp; - remoteChannel_->sendResponseAsync(rp, msg.cookie); + _remoteChannel->sendResponseAsync(rp, msg.cookie); break; } case clap::messages::kHideRequest: { - quickView_->hide(); + _quickView->hide(); clap::messages::HideResponse rp; - remoteChannel_->sendResponseAsync(rp, msg.cookie); + _remoteChannel->sendResponseAsync(rp, msg.cookie); break; } } diff --git a/examples/gui/application.hh b/examples/gui/application.hh @@ -15,7 +15,7 @@ class Application : public QGuiApplication, public clap::RemoteChannel::EventCon public: Application(int& argc, char **argv); - clap::RemoteChannel& remoteChannel() const { return *remoteChannel_; } + clap::RemoteChannel& remoteChannel() const { return *_remoteChannel; } void modifyFd(clap_fd_flags flags) override; void removeFd() override; @@ -24,13 +24,13 @@ public: private: void onMessage(const clap::RemoteChannel::Message& msg); - QQuickView *quickView_ = nullptr; - std::unique_ptr<QSocketNotifier> socketReadNotifier_; - std::unique_ptr<QSocketNotifier> socketWriteNotifier_; - std::unique_ptr<QSocketNotifier> socketErrorNotifier_; + QQuickView *_quickView = nullptr; + std::unique_ptr<QSocketNotifier> _socketReadNotifier; + std::unique_ptr<QSocketNotifier> _socketWriteNotifier; + std::unique_ptr<QSocketNotifier> _socketErrorNotifier; - std::unique_ptr<QWindow> hostWindow_ = nullptr; + std::unique_ptr<QWindow> _hostWindow = nullptr; - std::unique_ptr<clap::RemoteChannel> remoteChannel_; - PluginProxy *pluginProxy_ = nullptr; + std::unique_ptr<clap::RemoteChannel> _remoteChannel; + PluginProxy *_pluginProxy = nullptr; }; \ No newline at end of file diff --git a/examples/gui/parameter-proxy.cc b/examples/gui/parameter-proxy.cc @@ -3,23 +3,23 @@ #include "application.hh" ParameterProxy::ParameterProxy(const clap_param_info &info, QObject *parent) - : QObject(parent), id_(info.id), name_(info.name), module_(info.module), - value_(info.default_value), minValue_(info.min_value), maxValue_(info.max_value), - defaultValue_(info.default_value) {} + : QObject(parent), _id(info.id), _name(info.name), _module(info.module), + _value(info.default_value), _minValue(info.min_value), _maxValue(info.max_value), + _defaultValue(info.default_value) {} ParameterProxy::ParameterProxy(clap_id param_id, QObject *parent) - : QObject(parent), id_(param_id) {} + : QObject(parent), _id(param_id) {} void ParameterProxy::redefine(const clap_param_info &info) { - Q_ASSERT(id_ == info.id); + Q_ASSERT(_id == info.id); - if (name_ != info.name) { - name_ = info.name; + if (_name != info.name) { + _name = info.name; nameChanged(); } - if (module_ != info.module) { - module_ = info.module; + if (_module != info.module) { + _module = info.module; moduleChanged(); } @@ -27,65 +27,65 @@ void ParameterProxy::redefine(const clap_param_info &info) { setMaxValueFromPlugin(info.max_value); setDefaultValueFromPlugin(info.default_value); - setValueFromPlugin(std::min(maxValue_, std::max(minValue_, value_))); + setValueFromPlugin(std::min(_maxValue, std::max(_minValue, _value))); } void ParameterProxy::setIsAdjusting(bool isAdjusting) { - if (isAdjusting == isAdjusting_) + if (isAdjusting == _isAdjusting) return; - clap::messages::AdjustRequest rq{id_, value_, isAdjusting ? CLAP_EVENT_PARAM_BEGIN_ADJUST : CLAP_EVENT_PARAM_END_ADJUST}; + clap::messages::AdjustRequest rq{_id, _value, isAdjusting ? CLAP_EVENT_PARAM_BEGIN_ADJUST : CLAP_EVENT_PARAM_END_ADJUST}; Application::instance().remoteChannel().sendRequestAsync(rq); } void ParameterProxy::setValueFromUI(double value) { - value = std::max(minValue_, std::min(maxValue_, value)); - if (value == value_) + value = std::max(_minValue, std::min(_maxValue, value)); + if (value == _value) return; - value_ = value; + _value = value; - clap::messages::AdjustRequest rq{id_, value_, 0}; + clap::messages::AdjustRequest rq{_id, _value, 0}; Application::instance().remoteChannel().sendRequestAsync(rq); valueChanged(); } void ParameterProxy::setValueFromPlugin(double value) { - if (value == value_) + if (value == _value) return; - value_ = value; + _value = value; valueChanged(); } void ParameterProxy::setModulationFromPlugin(double mod) { - if (mod == modulation_) + if (mod == _modulation) return; - modulation_ = mod; + _modulation = mod; modulationChanged(); } void ParameterProxy::setMinValueFromPlugin(double minValue) { - if (minValue == minValue_) + if (minValue == _minValue) return; - minValue_ = minValue; + _minValue = minValue; minValueChanged(); } void ParameterProxy::setMaxValueFromPlugin(double maxValue) { - if (maxValue == maxValue_) + if (maxValue == _maxValue) return; - maxValue_ = maxValue; + _maxValue = maxValue; maxValueChanged(); } void ParameterProxy::setDefaultValueFromPlugin(double defaultValue) { - if (defaultValue == defaultValue_) + if (defaultValue == _defaultValue) return; - defaultValue_ = defaultValue; + _defaultValue = defaultValue; defaultValueChanged(); } \ No newline at end of file diff --git a/examples/gui/parameter-proxy.hh b/examples/gui/parameter-proxy.hh @@ -25,40 +25,40 @@ public: void redefine(const clap_param_info &info); - uint32_t getId() const { return id_; } - const QString &getModule() const { return module_; } - const QString &getName() const { return name_; } + uint32_t getId() const { return _id; } + const QString &getModule() const { return _module; } + const QString &getName() const { return _name; } - double getValue() const { return value_; } + double getValue() const { return _value; } void setValueFromUI(double value); void setValueFromPlugin(double value); double getNormalizedValue() const { return normalize(getValue()); } void setNormalizedValueFromUI(double value) { setValueFromUI(denormalize(value)); } - double getModulation() const { return modulation_; } + double getModulation() const { return _modulation; } void setModulationFromPlugin(double mod); double getNormalizedModulation() const { return normalize(getModulation()); } - bool isAdjusting() const { return isAdjusting_; } + bool isAdjusting() const { return _isAdjusting; } void setIsAdjusting(bool isAdjusting); - double getMinValue() const { return minValue_; } + double getMinValue() const { return _minValue; } void setMinValueFromPlugin(double minValue); - double getMaxValue() const { return maxValue_; } + double getMaxValue() const { return _maxValue; } void setMaxValueFromPlugin(double maxValue); - double getDefaultValue() const { return defaultValue_; } + double getDefaultValue() const { return _defaultValue; } void setDefaultValueFromPlugin(double defaultValue); double normalize(double value) const { - double delta = maxValue_ - minValue_; - return delta != 0 ? std::min(1., std::max(0., (value - minValue_) / delta)) : 0; + double delta = _maxValue - _minValue; + return delta != 0 ? std::min(1., std::max(0., (value - _minValue) / delta)) : 0; } double denormalize(double value) const { - double delta = maxValue_ - minValue_; - return minValue_ + std::min(1., std::max(0., value)) * delta; + double delta = _maxValue - _minValue; + return _minValue + std::min(1., std::max(0., value)) * delta; } signals: @@ -71,13 +71,13 @@ signals: void defaultValueChanged(); private: - const uint32_t id_; - QString name_; - QString module_; - double value_ = 0; - double modulation_ = 0; - double minValue_ = 0; - double maxValue_ = 0; - double defaultValue_ = 0; - bool isAdjusting_ = false; + const uint32_t _id; + QString _name; + QString _module; + double _value = 0; + double _modulation = 0; + double _minValue = 0; + double _maxValue = 0; + double _defaultValue = 0; + bool _isAdjusting = false; }; \ No newline at end of file diff --git a/examples/gui/plugin-proxy.cc b/examples/gui/plugin-proxy.cc @@ -3,12 +3,12 @@ PluginProxy::PluginProxy(QObject *parent) : QObject(parent) {} ParameterProxy *PluginProxy::param(clap_id paramId) { - auto it = parameters_.find(paramId); - if (it != parameters_.end()) + auto it = _parameters.find(paramId); + if (it != _parameters.end()) return it->second; auto *p = new ParameterProxy(paramId, this); - parameters_.emplace(paramId, p); + _parameters.emplace(paramId, p); return p; } @@ -16,9 +16,9 @@ QString PluginProxy::toString() const { return "Plugin"; } void PluginProxy::defineParameter(const clap_param_info &info) { - auto it = parameters_.find(info.id); - if (it != parameters_.end()) + auto it = _parameters.find(info.id); + if (it != _parameters.end()) it->second->redefine(info); else - parameters_.emplace(info.id, new ParameterProxy(info, this)); + _parameters.emplace(info.id, new ParameterProxy(info, this)); } \ No newline at end of file diff --git a/examples/gui/plugin-proxy.hh b/examples/gui/plugin-proxy.hh @@ -19,5 +19,5 @@ public: Q_INVOKABLE QString toString() const; private: - std::unordered_map<clap_id, ParameterProxy *> parameters_; + std::unordered_map<clap_id, ParameterProxy *> _parameters; }; \ No newline at end of file diff --git a/examples/host/CMakeLists.txt b/examples/host/CMakeLists.txt @@ -36,7 +36,6 @@ add_executable(clap-host plugin-quick-controls-widget.hh CMakeLists.txt - device-reference.cc device-reference.hh engine.cc engine.hh @@ -47,7 +46,6 @@ add_executable(clap-host midi-settings.hh midi-settings-widget.cc midi-settings-widget.hh - plugin-info.cc plugin-info.hh plugin-parameters-widget.cc plugin-parameters-widget.hh diff --git a/examples/host/application.cc b/examples/host/application.cc @@ -12,15 +12,15 @@ #include "main-window.hh" #include "settings.hh" -Application *Application::instance_ = nullptr; +Application *Application::_instance = nullptr; Q_DECLARE_METATYPE(int32_t) Q_DECLARE_METATYPE(uint32_t) Application::Application(int argc, char **argv) - : QApplication(argc, argv), settings_(new Settings) { - assert(!instance_); - instance_ = this; + : QApplication(argc, argv), _settings(new Settings) { + assert(!_instance); + _instance = this; setOrganizationDomain("github.com/free-audio/clap"); setOrganizationName("clap"); @@ -31,12 +31,12 @@ Application::Application(int argc, char **argv) loadSettings(); - engine_ = new Engine(*this); + _engine = new Engine(*this); - mainWindow_ = new MainWindow(*this); - mainWindow_->show(); + _mainWindow = new MainWindow(*this); + _mainWindow->show(); - engine_->setParentWindow(mainWindow_->getEmbedWindowId()); + _engine->setParentWindow(_mainWindow->getEmbedWindowId()); /* * This is here JUST because macOS and QT don't process command lines properly @@ -44,25 +44,25 @@ Application::Application(int argc, char **argv) */ if (getenv("CLAP_HOST_FORCE_PLUGIN")) { qWarning() << "Warning: Loading plugin from ENV, not command line"; - pluginPath_ = getenv("CLAP_HOST_FORCE_PLUGIN"); - pluginIndex_ = 0; + _pluginPath = getenv("CLAP_HOST_FORCE_PLUGIN"); + _pluginIndex = 0; } - if (engine_->loadPlugin(pluginPath_, pluginIndex_)) - engine_->start(); + if (_engine->loadPlugin(_pluginPath, _pluginIndex)) + _engine->start(); } Application::~Application() { saveSettings(); - delete engine_; - engine_ = nullptr; + delete _engine; + _engine = nullptr; - delete mainWindow_; - mainWindow_ = nullptr; + delete _mainWindow; + _mainWindow = nullptr; - delete settings_; - settings_ = nullptr; + delete _settings; + _settings = nullptr; } void Application::parseCommandLine() { @@ -86,21 +86,21 @@ void Application::parseCommandLine() { parser.process(*this); - pluginPath_ = parser.value(pluginOpt); - pluginIndex_ = parser.value(pluginIndexOpt).toInt(); + _pluginPath = parser.value(pluginOpt); + _pluginIndex = parser.value(pluginIndexOpt).toInt(); } void Application::loadSettings() { QSettings s; - settings_->load(s); + _settings->load(s); } void Application::saveSettings() const { QSettings s; - settings_->save(s); + _settings->save(s); } void Application::restartEngine() { - engine_->stop(); - engine_->start(); + _engine->stop(); + _engine->start(); } diff --git a/examples/host/application.hh b/examples/host/application.hh @@ -18,29 +18,29 @@ public: Application(int argc, char **argv); ~Application(); - Settings &settings() { return *settings_; } + Settings &settings() { return *_settings; } void parseCommandLine(); void loadSettings(); void saveSettings() const; - MainWindow *mainWindow() const { return mainWindow_; } + MainWindow *mainWindow() const { return _mainWindow; } - static Application &instance() { return *instance_; } + static Application &instance() { return *_instance; } - Engine *engine() { return engine_; } + Engine *engine() { return _engine; } public slots: void restartEngine(); private: - static Application *instance_; + static Application *_instance; - Settings * settings_ = nullptr; - MainWindow *mainWindow_ = nullptr; - Engine * engine_ = nullptr; + Settings * _settings = nullptr; + MainWindow *_mainWindow = nullptr; + Engine * _engine = nullptr; - QString pluginPath_; - int pluginIndex_ = 0; + QString _pluginPath; + int _pluginIndex = 0; }; diff --git a/examples/host/audio-settings-widget.cc b/examples/host/audio-settings-widget.cc @@ -23,7 +23,7 @@ static const std::vector<int> SAMPLE_RATES = { static const std::vector<int> BUFFER_SIZES = {32, 48, 64, 96, 128, 192, 256, 384, 512}; AudioSettingsWidget::AudioSettingsWidget(AudioSettings &audioSettings) - : audioSettings_(audioSettings) { + : _audioSettings(audioSettings) { /* devices */ auto deviceComboBox = new QComboBox(this); auto deviceCount = Pa_GetDeviceCount(); @@ -33,8 +33,8 @@ AudioSettingsWidget::AudioSettingsWidget(AudioSettings &audioSettings) auto deviceInfo = Pa_GetDeviceInfo(i); deviceComboBox->addItem(deviceInfo->name); - if (!deviceFound && audioSettings_.deviceReference().index_ == i && - audioSettings_.deviceReference().name_ == deviceInfo->name) { + if (!deviceFound && _audioSettings.deviceReference()._index == i && + _audioSettings.deviceReference()._name == deviceInfo->name) { deviceComboBox->setCurrentIndex(i); deviceFound = true; selectedDeviceChanged(i); @@ -44,7 +44,7 @@ AudioSettingsWidget::AudioSettingsWidget(AudioSettings &audioSettings) // try to find the device just by its name. for (int i = 0; !deviceFound && i < deviceCount; ++i) { auto deviceInfo = Pa_GetDeviceInfo(i); - if (audioSettings_.deviceReference().name_ == deviceInfo->name) { + if (_audioSettings.deviceReference()._name == deviceInfo->name) { deviceComboBox->setCurrentIndex(i); deviceFound = true; selectedDeviceChanged(i); @@ -55,31 +55,31 @@ AudioSettingsWidget::AudioSettingsWidget(AudioSettings &audioSettings) deviceComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectedDeviceChanged(int))); /* sample rate */ - sampleRateWidget_ = new QComboBox(this); + _sampleRateWidget = new QComboBox(this); for (size_t i = 0; i < SAMPLE_RATES.size(); ++i) { int sr = SAMPLE_RATES[i]; - sampleRateWidget_->addItem(QString::number(sr)); - if (sr == audioSettings_.sampleRate()) { - sampleRateWidget_->setCurrentIndex(i); + _sampleRateWidget->addItem(QString::number(sr)); + if (sr == _audioSettings.sampleRate()) { + _sampleRateWidget->setCurrentIndex(i); selectedSampleRateChanged(i); } } - connect(sampleRateWidget_, + connect(_sampleRateWidget, SIGNAL(currentIndexChanged(int)), this, SLOT(selectedSampleRateChanged(int))); /* buffer size */ - bufferSizeWidget_ = new QComboBox(this); + _bufferSizeWidget = new QComboBox(this); for (size_t i = 0; i < BUFFER_SIZES.size(); ++i) { int bs = BUFFER_SIZES[i]; - bufferSizeWidget_->addItem(QString::number(bs)); - if (bs == audioSettings_.bufferSize()) { - bufferSizeWidget_->setCurrentIndex(i); + _bufferSizeWidget->addItem(QString::number(bs)); + if (bs == _audioSettings.bufferSize()) { + _bufferSizeWidget->setCurrentIndex(i); selectedBufferSizeChanged(i); } } - connect(bufferSizeWidget_, + connect(_bufferSizeWidget, SIGNAL(currentIndexChanged(int)), this, SLOT(selectedBufferSizeChanged(int))); @@ -90,8 +90,8 @@ AudioSettingsWidget::AudioSettingsWidget(AudioSettings &audioSettings) layout->addWidget(new QLabel(tr("Buffer size")), 2, 0); layout->addWidget(deviceComboBox, 0, 1); - layout->addWidget(sampleRateWidget_, 1, 1); - layout->addWidget(bufferSizeWidget_, 2, 1); + layout->addWidget(_sampleRateWidget, 1, 1); + layout->addWidget(_bufferSizeWidget, 2, 1); QGroupBox *groupBox = new QGroupBox(this); groupBox->setLayout(layout); @@ -106,15 +106,15 @@ void AudioSettingsWidget::selectedDeviceChanged(int index) { auto deviceInfo = Pa_GetDeviceInfo(index); DeviceReference ref; - ref.index_ = index; - ref.name_ = deviceInfo->name; - audioSettings_.setDeviceReference(ref); + ref._index = index; + ref._name = deviceInfo->name; + _audioSettings.setDeviceReference(ref); } void AudioSettingsWidget::selectedSampleRateChanged(int index) { - audioSettings_.setSampleRate(sampleRateWidget_->itemText(index).toInt()); + _audioSettings.setSampleRate(_sampleRateWidget->itemText(index).toInt()); } void AudioSettingsWidget::selectedBufferSizeChanged(int index) { - audioSettings_.setBufferSize(bufferSizeWidget_->itemText(index).toInt()); + _audioSettings.setBufferSize(_bufferSizeWidget->itemText(index).toInt()); } diff --git a/examples/host/audio-settings-widget.hh b/examples/host/audio-settings-widget.hh @@ -18,7 +18,7 @@ public slots: void selectedBufferSizeChanged(int index); private: - AudioSettings &audioSettings_; - QComboBox * sampleRateWidget_; - QComboBox * bufferSizeWidget_; + AudioSettings &_audioSettings; + QComboBox * _sampleRateWidget; + QComboBox * _bufferSizeWidget; }; diff --git a/examples/host/audio-settings.cc b/examples/host/audio-settings.cc @@ -10,15 +10,15 @@ static const char DEVICE_INDEX_KEY[] = "Audio/DeviceIndex"; AudioSettings::AudioSettings() {} void AudioSettings::load(QSettings &settings) { - deviceReference_.name_ = settings.value(DEVICE_NAME_KEY).toString(); - deviceReference_.index_ = settings.value(DEVICE_INDEX_KEY).toInt(); - sampleRate_ = settings.value(SAMPLE_RATE_KEY, 44100).toInt(); - bufferSize_ = settings.value(BUFFER_SIZE_KEY, 256).toInt(); + _deviceReference._name = settings.value(DEVICE_NAME_KEY).toString(); + _deviceReference._index = settings.value(DEVICE_INDEX_KEY).toInt(); + _sampleRate = settings.value(SAMPLE_RATE_KEY, 44100).toInt(); + _bufferSize = settings.value(BUFFER_SIZE_KEY, 256).toInt(); } void AudioSettings::save(QSettings &settings) const { - settings.setValue(SAMPLE_RATE_KEY, sampleRate_); - settings.setValue(BUFFER_SIZE_KEY, bufferSize_); - settings.setValue(DEVICE_NAME_KEY, deviceReference_.name_); - settings.setValue(DEVICE_INDEX_KEY, deviceReference_.index_); + settings.setValue(SAMPLE_RATE_KEY, _sampleRate); + settings.setValue(BUFFER_SIZE_KEY, _bufferSize); + settings.setValue(DEVICE_NAME_KEY, _deviceReference._name); + settings.setValue(DEVICE_INDEX_KEY, _deviceReference._index); } diff --git a/examples/host/audio-settings.hh b/examples/host/audio-settings.hh @@ -11,17 +11,17 @@ public: void load(QSettings &settings); void save(QSettings &settings) const; - int sampleRate() const { return sampleRate_; } - void setSampleRate(int sampleRate) { sampleRate_ = sampleRate; } + int sampleRate() const { return _sampleRate; } + void setSampleRate(int sampleRate) { _sampleRate = sampleRate; } - void setDeviceReference(DeviceReference dr) { deviceReference_ = dr; } - const DeviceReference &deviceReference() const { return deviceReference_; } + void setDeviceReference(DeviceReference dr) { _deviceReference = dr; } + const DeviceReference &deviceReference() const { return _deviceReference; } - int bufferSize() const { return bufferSize_; } - void setBufferSize(int bufferSize) { bufferSize_ = bufferSize; } + int bufferSize() const { return _bufferSize; } + void setBufferSize(int bufferSize) { _bufferSize = bufferSize; } private: - DeviceReference deviceReference_; - int sampleRate_ = 44100; - int bufferSize_ = 128; + DeviceReference _deviceReference; + int _sampleRate = 44100; + int _bufferSize = 128; }; diff --git a/examples/host/device-reference.cc b/examples/host/device-reference.cc @@ -1 +0,0 @@ -#include "device-reference.hh" diff --git a/examples/host/device-reference.hh b/examples/host/device-reference.hh @@ -3,6 +3,6 @@ #include <QString> struct DeviceReference { - QString name_ = "(noname)"; - int index_ = 0; + QString _name = "(noname)"; + int _index = 0; }; diff --git a/examples/host/engine.cc b/examples/host/engine.cc @@ -26,12 +26,12 @@ enum MidiStatus { }; Engine::Engine(Application &application) - : QObject(&application), application_(application), settings_(application.settings()), - idleTimer_(this) { - pluginHost_.reset(new PluginHost(*this)); + : QObject(&application), _application(application), _settings(application.settings()), + _idleTimer(this) { + _pluginHost.reset(new PluginHost(*this)); - connect(&idleTimer_, &QTimer::timeout, this, QOverload<>::of(&Engine::callPluginIdle)); - idleTimer_.start(1000 / 30); + connect(&_idleTimer, &QTimer::timeout, this, QOverload<>::of(&Engine::callPluginIdle)); + _idleTimer.start(1000 / 30); } Engine::~Engine() { @@ -42,41 +42,41 @@ Engine::~Engine() { } void Engine::start() { - assert(!audio_); - assert(state_ == kStateStopped); + assert(!_audio); + assert(_state == kStateStopped); - auto & as = settings_.audioSettings(); + auto & as = _settings.audioSettings(); const int bufferSize = 4 * 2 * as.bufferSize(); - inputs_[0] = (float *)calloc(1, bufferSize); - inputs_[1] = (float *)calloc(1, bufferSize); - outputs_[0] = (float *)calloc(1, bufferSize); - outputs_[1] = (float *)calloc(1, bufferSize); + _inputs[0] = (float *)calloc(1, bufferSize); + _inputs[1] = (float *)calloc(1, bufferSize); + _outputs[0] = (float *)calloc(1, bufferSize); + _outputs[1] = (float *)calloc(1, bufferSize); - pluginHost_->setPorts(2, inputs_, 2, outputs_); + _pluginHost->setPorts(2, _inputs, 2, _outputs); /* midi */ PmError midi_err = Pm_OpenInput( - &midi_, settings_.midiSettings().deviceReference().index_, nullptr, 512, nullptr, nullptr); + &_midi, _settings.midiSettings().deviceReference()._index, nullptr, 512, nullptr, nullptr); if (midi_err != pmNoError) { - midi_ = nullptr; + _midi = nullptr; } - pluginHost_->activate(as.sampleRate()); + _pluginHost->activate(as.sampleRate()); /* audio */ - auto deviceInfo = Pa_GetDeviceInfo(as.deviceReference().index_); + auto deviceInfo = Pa_GetDeviceInfo(as.deviceReference()._index); PaStreamParameters params; params.channelCount = 2; - params.device = as.deviceReference().index_; + params.device = as.deviceReference()._index; params.hostApiSpecificStreamInfo = nullptr; params.sampleFormat = paFloat32; params.suggestedLatency = 0; - state_ = kStateRunning; - nframes_ = as.bufferSize(); - PaError err = Pa_OpenStream(&audio_, + _state = kStateRunning; + _nframes = as.bufferSize(); + PaError err = Pa_OpenStream(&_audio, deviceInfo->maxInputChannels >= 2 ? &params : nullptr, &params, as.sampleRate(), @@ -90,27 +90,27 @@ void Engine::start() { return; } - err = Pa_StartStream(audio_); + err = Pa_StartStream(_audio); } void Engine::stop() { - pluginHost_->deactivate(); + _pluginHost->deactivate(); - if (state_ == kStateRunning) - state_ = kStateStopping; + if (_state == kStateRunning) + _state = kStateStopping; - if (audio_) { - Pa_StopStream(audio_); - Pa_CloseStream(audio_); - audio_ = nullptr; + if (_audio) { + Pa_StopStream(_audio); + Pa_CloseStream(_audio); + _audio = nullptr; } - if (midi_) { - Pm_Close(midi_); - midi_ = nullptr; + if (_midi) { + Pm_Close(_midi); + _midi = nullptr; } - state_ = kStateStopped; + _state = kStateStopped; } int Engine::audioCallback(const void * input, @@ -123,27 +123,27 @@ int Engine::audioCallback(const void * input, const float *const in = (const float *)input; float *const out = (float *)output; - assert(thiz->inputs_[0] != nullptr); - assert(thiz->inputs_[1] != nullptr); - assert(thiz->outputs_[0] != nullptr); - assert(thiz->outputs_[1] != nullptr); - assert(frameCount == thiz->nframes_); + assert(thiz->_inputs[0] != nullptr); + assert(thiz->_inputs[1] != nullptr); + assert(thiz->_outputs[0] != nullptr); + assert(thiz->_outputs[1] != nullptr); + assert(frameCount == thiz->_nframes); // copy input if (in) { - for (int i = 0; i < thiz->nframes_; ++i) { - thiz->inputs_[0][i] = in[2 * i]; - thiz->inputs_[1][i] = in[2 * i + 1]; + for (int i = 0; i < thiz->_nframes; ++i) { + thiz->_inputs[0][i] = in[2 * i]; + thiz->_inputs[1][i] = in[2 * i + 1]; } } - thiz->pluginHost_->processBegin(frameCount); + thiz->_pluginHost->processBegin(frameCount); - MidiSettings &ms = thiz->settings_.midiSettings(); + MidiSettings &ms = thiz->_settings.midiSettings(); - if (thiz->midi_) { + if (thiz->_midi) { PmEvent evBuffer[512]; - int numRead = Pm_Read(thiz->midi_, evBuffer, sizeof(evBuffer) / sizeof(evBuffer[0])); + int numRead = Pm_Read(thiz->_midi, evBuffer, sizeof(evBuffer) / sizeof(evBuffer[0])); const PtTimestamp currentTime = Pt_Time(); @@ -155,32 +155,32 @@ int Engine::audioCallback(const void * input, uint8_t data2 = Pm_MessageData2(ev->message); int32_t deltaMs = currentTime - ev->timestamp; - int32_t deltaSample = (deltaMs * thiz->sampleRate_) / 1000; + int32_t deltaSample = (deltaMs * thiz->_sampleRate) / 1000; - if (deltaSample >= thiz->nframes_) - deltaSample = thiz->nframes_ - 1; + if (deltaSample >= thiz->_nframes) + deltaSample = thiz->_nframes - 1; - int32_t sampleOffset = thiz->nframes_ - deltaSample; + int32_t sampleOffset = thiz->_nframes - deltaSample; switch (eventType) { case MIDI_STATUS_NOTE_ON: - thiz->pluginHost_->processNoteOn(sampleOffset, channel, data1, data2); + thiz->_pluginHost->processNoteOn(sampleOffset, channel, data1, data2); ++ev; break; case MIDI_STATUS_NOTE_OFF: - thiz->pluginHost_->processNoteOff(sampleOffset, channel, data1, data2); + thiz->_pluginHost->processNoteOff(sampleOffset, channel, data1, data2); ++ev; break; case MIDI_STATUS_CC: - thiz->pluginHost_->processCC(sampleOffset, channel, data1, data2); + thiz->_pluginHost->processCC(sampleOffset, channel, data1, data2); ++ev; break; case MIDI_STATUS_NOTE_AT: std::cerr << "Note AT key: " << (int)data1 << ", pres: " << (int)data2 << std::endl; - thiz->pluginHost_->processNoteAt(sampleOffset, channel, data1, data2); + thiz->_pluginHost->processNoteAt(sampleOffset, channel, data1, data2); ++ev; break; @@ -190,7 +190,7 @@ int Engine::audioCallback(const void * input, break; case MIDI_STATUS_PITCH_BEND: - thiz->pluginHost_->processPitchBend(sampleOffset, channel, (data2 << 7) | data1); + thiz->_pluginHost->processPitchBend(sampleOffset, channel, (data2 << 7) | data1); ++ev; break; @@ -202,21 +202,21 @@ int Engine::audioCallback(const void * input, } } - thiz->pluginHost_->process(); + thiz->_pluginHost->process(); // copy output - for (int i = 0; i < thiz->nframes_; ++i) { - out[2 * i] = thiz->outputs_[0][i]; - out[2 * i + 1] = thiz->outputs_[1][i]; + for (int i = 0; i < thiz->_nframes; ++i) { + out[2 * i] = thiz->_outputs[0][i]; + out[2 * i + 1] = thiz->_outputs[1][i]; } - thiz->steadyTime_ += frameCount; + thiz->_steadyTime += frameCount; - switch (thiz->state_) { + switch (thiz->_state) { case kStateRunning: return paContinue; case kStateStopping: - thiz->state_ = kStateStopped; + thiz->_state = kStateStopped; return paComplete; default: assert(false && "unreachable"); @@ -225,28 +225,28 @@ int Engine::audioCallback(const void * input, } bool Engine::loadPlugin(const QString &path, int plugin_index) { - if (!pluginHost_->load(path, plugin_index)) + if (!_pluginHost->load(path, plugin_index)) return false; - pluginHost_->setParentWindow(parentWindow_); + _pluginHost->setParentWindow(_parentWindow); return true; } void Engine::unloadPlugin() { - pluginHost_->unload(); + _pluginHost->unload(); - free(inputs_[0]); - free(inputs_[1]); - free(outputs_[0]); - free(outputs_[1]); + free(_inputs[0]); + free(_inputs[1]); + free(_outputs[0]); + free(_outputs[1]); - inputs_[0] = nullptr; - inputs_[1] = nullptr; - outputs_[0] = nullptr; - outputs_[1] = nullptr; + _inputs[0] = nullptr; + _inputs[1] = nullptr; + _outputs[0] = nullptr; + _outputs[1] = nullptr; } void Engine::callPluginIdle() { - if (pluginHost_) - pluginHost_->idle(); + if (_pluginHost) + _pluginHost->idle(); } diff --git a/examples/host/engine.hh b/examples/host/engine.hh @@ -29,7 +29,7 @@ public: kStateStopping, }; - void setParentWindow(WId parentWindow) { parentWindow_ = parentWindow; } + void setParentWindow(WId parentWindow) { _parentWindow = parentWindow; } void start(); void stop(); @@ -40,10 +40,10 @@ public: void setProgram(int8_t program, int8_t bank_msb, int8_t bank_lsb); void loadMidiFile(const QString &path); - bool isRunning() const noexcept { return state_ == kStateRunning; } - int sampleRate() const noexcept { return sampleRate_; } + bool isRunning() const noexcept { return _state == kStateRunning; } + int sampleRate() const noexcept { return _sampleRate; } - PluginHost &pluginHost() const { return *pluginHost_; } + PluginHost &pluginHost() const { return *_pluginHost; } public: void callPluginIdle(); @@ -60,26 +60,26 @@ private: PaStreamCallbackFlags statusFlags, void * userData); - Application &application_; - Settings & settings_; - WId parentWindow_; + Application &_application; + Settings & _settings; + WId _parentWindow; - State state_ = kStateStopped; + State _state = kStateStopped; /* audio & midi streams */ - PaStream *audio_ = nullptr; - PmStream *midi_ = nullptr; + PaStream *_audio = nullptr; + PmStream *_midi = nullptr; /* engine context */ - int64_t steadyTime_ = 0; - int32_t sampleRate_ = 44100; - int32_t nframes_ = 0; + int64_t _steadyTime = 0; + int32_t _sampleRate = 44100; + int32_t _nframes = 0; /* audio buffers */ - float *inputs_[2] = {nullptr, nullptr}; - float *outputs_[2] = {nullptr, nullptr}; + float *_inputs[2] = {nullptr, nullptr}; + float *_outputs[2] = {nullptr, nullptr}; - std::unique_ptr<PluginHost> pluginHost_; + std::unique_ptr<PluginHost> _pluginHost; - QTimer idleTimer_; + QTimer _idleTimer; }; diff --git a/examples/host/main-window.cc b/examples/host/main-window.cc @@ -19,30 +19,30 @@ #include "settings.hh" MainWindow::MainWindow(Application &app) - : QMainWindow(nullptr), application_(app), - settingsDialog_(new SettingsDialog(application_.settings(), this)), - pluginViewWindow_(new QWindow()), - pluginViewWidget_(QWidget::createWindowContainer(pluginViewWindow_)) { + : QMainWindow(nullptr), _application(app), + _settingsDialog(new SettingsDialog(_application.settings(), this)), + _pluginViewWindow(new QWindow()), + _pluginViewWidget(QWidget::createWindowContainer(_pluginViewWindow)) { createMenu(); - setCentralWidget(pluginViewWidget_); - pluginViewWidget_->show(); - pluginViewWidget_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + setCentralWidget(_pluginViewWidget); + _pluginViewWidget->show(); + _pluginViewWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - connect(settingsDialog_, SIGNAL(accepted()), &application_, SLOT(restartEngine())); + connect(_settingsDialog, SIGNAL(accepted()), &_application, SLOT(restartEngine())); auto &pluginHost = app.engine()->pluginHost(); - pluginParametersWindow_ = new QMainWindow(this); - pluginParametersWidget_ = new PluginParametersWidget(pluginParametersWindow_, pluginHost); - pluginParametersWindow_->setCentralWidget(pluginParametersWidget_); + _pluginParametersWindow = new QMainWindow(this); + _pluginParametersWidget = new PluginParametersWidget(_pluginParametersWindow, pluginHost); + _pluginParametersWindow->setCentralWidget(_pluginParametersWidget); - pluginQuickControlsWindow_ = new QMainWindow(this); - pluginQuickControlsWidget_ = - new PluginQuickControlsWidget(pluginQuickControlsWindow_, pluginHost); - pluginQuickControlsWindow_->setCentralWidget(pluginQuickControlsWidget_); + _pluginQuickControlsWindow = new QMainWindow(this); + _pluginQuickControlsWidget = + new PluginQuickControlsWidget(_pluginQuickControlsWindow, pluginHost); + _pluginQuickControlsWindow->setCentralWidget(_pluginQuickControlsWidget); } MainWindow::~MainWindow() {} @@ -97,20 +97,20 @@ void MainWindow::createMenu() { } void MainWindow::showSettingsDialog() { - int result = settingsDialog_->exec(); + int result = _settingsDialog->exec(); if (result == QDialog::Accepted) - application_.restartEngine(); + _application.restartEngine(); } -void MainWindow::showPluginParametersWindow() { pluginParametersWindow_->show(); } -void MainWindow::showPluginQuickControlsWindow() { pluginQuickControlsWindow_->show(); } +void MainWindow::showPluginParametersWindow() { _pluginParametersWindow->show(); } +void MainWindow::showPluginQuickControlsWindow() { _pluginQuickControlsWindow->show(); } -WId MainWindow::getEmbedWindowId() { return pluginViewWidget_->winId(); } +WId MainWindow::getEmbedWindowId() { return _pluginViewWidget->winId(); } void MainWindow::resizePluginView(int width, int height) { - pluginViewWidget_->setMinimumSize(width, height); - pluginViewWidget_->setMaximumSize(width, height); - pluginViewWidget_->show(); + _pluginViewWidget->setMinimumSize(width, height); + _pluginViewWidget->setMaximumSize(width, height); + _pluginViewWidget->show(); adjustSize(); } @@ -120,19 +120,19 @@ void MainWindow::loadNativePluginPreset() if (file.isEmpty()) return; - application_.engine()->pluginHost().loadNativePluginPreset(file.toStdString()); + _application.engine()->pluginHost().loadNativePluginPreset(file.toStdString()); } void MainWindow::togglePluginWindowVisibility() { - bool isVisible = !pluginViewWidget_->isVisible(); - pluginViewWidget_->setVisible(isVisible); - application_.engine()->pluginHost().setPluginWindowVisibility(isVisible); + bool isVisible = !_pluginViewWidget->isVisible(); + _pluginViewWidget->setVisible(isVisible); + _application.engine()->pluginHost().setPluginWindowVisibility(isVisible); } void MainWindow::recreatePluginWindow() { - application_.engine()->pluginHost().setParentWindow(getEmbedWindowId()); + _application.engine()->pluginHost().setParentWindow(getEmbedWindowId()); } void MainWindow::scalePluginWindow() diff --git a/examples/host/main-window.hh b/examples/host/main-window.hh @@ -30,14 +30,14 @@ private: void recreatePluginWindow(); void scalePluginWindow(); - Application & application_; - SettingsDialog *settingsDialog_ = nullptr; - QWindow * pluginViewWindow_ = nullptr; - QWidget * pluginViewWidget_ = nullptr; + Application & _application; + SettingsDialog *_settingsDialog = nullptr; + QWindow * _pluginViewWindow = nullptr; + QWidget * _pluginViewWidget = nullptr; - QMainWindow * pluginParametersWindow_ = nullptr; - PluginParametersWidget *pluginParametersWidget_ = nullptr; + QMainWindow * _pluginParametersWindow = nullptr; + PluginParametersWidget *_pluginParametersWidget = nullptr; - QMainWindow * pluginQuickControlsWindow_ = nullptr; - PluginQuickControlsWidget *pluginQuickControlsWidget_ = nullptr; + QMainWindow * _pluginQuickControlsWindow = nullptr; + PluginQuickControlsWidget *_pluginQuickControlsWidget = nullptr; }; diff --git a/examples/host/midi-settings-widget.cc b/examples/host/midi-settings-widget.cc @@ -9,7 +9,7 @@ #include "midi-settings-widget.hh" #include "midi-settings.hh" -MidiSettingsWidget::MidiSettingsWidget(MidiSettings &midiSettings) : midiSettings_(midiSettings) { +MidiSettingsWidget::MidiSettingsWidget(MidiSettings &midiSettings) : _midiSettings(midiSettings) { auto layout = new QVBoxLayout(this); auto deviceComboBox = new QComboBox; @@ -28,8 +28,8 @@ MidiSettingsWidget::MidiSettingsWidget(MidiSettings &midiSettings) : midiSetting deviceComboBox->addItem(deviceInfo->name); - if (!deviceFound && midiSettings_.deviceReference().index_ == i && - midiSettings_.deviceReference().name_ == deviceInfo->name) { + if (!deviceFound && _midiSettings.deviceReference()._index == i && + _midiSettings.deviceReference()._name == deviceInfo->name) { deviceComboBox->setCurrentIndex(inputIndex); deviceFound = true; selectedDeviceChanged(inputIndex); @@ -45,7 +45,7 @@ MidiSettingsWidget::MidiSettingsWidget(MidiSettings &midiSettings) : midiSetting if (!deviceInfo->input) continue; - if (midiSettings_.deviceReference().name_ == deviceInfo->name) { + if (_midiSettings.deviceReference()._name == deviceInfo->name) { deviceComboBox->setCurrentIndex(inputIndex); deviceFound = true; selectedDeviceChanged(inputIndex); @@ -82,9 +82,9 @@ void MidiSettingsWidget::selectedDeviceChanged(int index) { } DeviceReference ref; - ref.index_ = i; - ref.name_ = deviceInfo->name; - midiSettings_.setDeviceReference(ref); + ref._index = i; + ref._name = deviceInfo->name; + _midiSettings.setDeviceReference(ref); break; } } diff --git a/examples/host/midi-settings-widget.hh b/examples/host/midi-settings-widget.hh @@ -17,5 +17,5 @@ public slots: void selectedDeviceChanged(int index); private: - MidiSettings &midiSettings_; + MidiSettings &_midiSettings; }; diff --git a/examples/host/midi-settings.cc b/examples/host/midi-settings.cc @@ -10,11 +10,11 @@ static const char ARP_KEY[] = "Midi/Arp"; MidiSettings::MidiSettings() {} void MidiSettings::load(QSettings &settings) { - deviceReference_.name_ = settings.value(DEVICE_NAME_KEY).toString(); - deviceReference_.index_ = settings.value(DEVICE_INDEX_KEY).toInt(); + _deviceReference._name = settings.value(DEVICE_NAME_KEY).toString(); + _deviceReference._index = settings.value(DEVICE_INDEX_KEY).toInt(); } void MidiSettings::save(QSettings &settings) const { - settings.setValue(DEVICE_NAME_KEY, deviceReference_.name_); - settings.setValue(DEVICE_INDEX_KEY, deviceReference_.index_); + settings.setValue(DEVICE_NAME_KEY, _deviceReference._name); + settings.setValue(DEVICE_INDEX_KEY, _deviceReference._index); } diff --git a/examples/host/midi-settings.hh b/examples/host/midi-settings.hh @@ -11,9 +11,9 @@ public: void load(QSettings &settings); void save(QSettings &settings) const; - const DeviceReference &deviceReference() const { return deviceReference_; } - void setDeviceReference(const DeviceReference &ref) { deviceReference_ = ref; } + const DeviceReference &deviceReference() const { return _deviceReference; } + void setDeviceReference(const DeviceReference &ref) { _deviceReference = ref; } private: - DeviceReference deviceReference_; + DeviceReference _deviceReference; }; diff --git a/examples/host/plugin-host.cc b/examples/host/plugin-host.cc @@ -24,7 +24,7 @@ enum ThreadType { thread_local ThreadType g_thread_type = Unknown; -PluginHost::PluginHost(Engine &engine) : QObject(&engine), engine_(engine) { +PluginHost::PluginHost(Engine &engine) : QObject(&engine), _engine(engine) { g_thread_type = MainThread; host_.host_data = this; @@ -47,22 +47,22 @@ PluginHost::~PluginHost() { void PluginHost::initThreadPool() { checkForMainThread(); - threadPoolStop_ = false; - threadPoolTaskIndex_ = 0; + _threadPoolStop = false; + _threadPoolTaskIndex = 0; auto N = QThread::idealThreadCount(); - threadPool_.resize(N); + _threadPool.resize(N); for (int i = 0; i < N; ++i) { - threadPool_[i].reset(QThread::create(&PluginHost::threadPoolEntry, this)); - threadPool_[i]->start(QThread::HighestPriority); + _threadPool[i].reset(QThread::create(&PluginHost::threadPoolEntry, this)); + _threadPool[i]->start(QThread::HighestPriority); } } void PluginHost::terminateThreadPool() { checkForMainThread(); - threadPoolStop_ = true; - threadPoolSemaphoreProd_.release(threadPool_.size()); - for (auto &thr : threadPool_) + _threadPoolStop = true; + _threadPoolSemaphoreProd.release(_threadPool.size()); + for (auto &thr : _threadPool) if (thr) thr->wait(); } @@ -70,47 +70,47 @@ void PluginHost::terminateThreadPool() { void PluginHost::threadPoolEntry() { g_thread_type = AudioThreadPool; while (true) { - threadPoolSemaphoreProd_.acquire(); - if (threadPoolStop_) + _threadPoolSemaphoreProd.acquire(); + if (_threadPoolStop) return; - int taskIndex = threadPoolTaskIndex_++; - pluginThreadPool_->exec(plugin_, taskIndex); - threadPoolSemaphoreDone_.release(); + int taskIndex = _threadPoolTaskIndex++; + _pluginThreadPool->exec(_plugin, taskIndex); + _threadPoolSemaphoreDone.release(); } } bool PluginHost::load(const QString &path, int pluginIndex) { checkForMainThread(); - if (library_.isLoaded()) + if (_library.isLoaded()) unload(); - library_.setFileName(path); - library_.setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::DeepBindHint); - if (!library_.load()) { - QString err = library_.errorString(); + _library.setFileName(path); + _library.setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::DeepBindHint); + if (!_library.load()) { + QString err = _library.errorString(); qWarning() << "Failed to load plugin '" << path << "': " << err; return false; } - pluginEntry_ = - reinterpret_cast<const struct clap_plugin_entry *>(library_.resolve("clap_plugin_entry")); - if (!pluginEntry_) { + _pluginEntry = + reinterpret_cast<const struct clap_plugin_entry *>(_library.resolve("clap_plugin_entry")); + if (!_pluginEntry) { qWarning() << "Unable to resolve entry point 'clap_plugin_entry' in '" << path << "'"; - library_.unload(); + _library.unload(); return false; } - pluginEntry_->init(path.toStdString().c_str()); + _pluginEntry->init(path.toStdString().c_str()); - auto count = pluginEntry_->get_plugin_count(); + auto count = _pluginEntry->get_plugin_count(); if (pluginIndex > count) { qWarning() << "plugin index greater than count :" << count; return false; } - auto desc = pluginEntry_->get_plugin_descriptor(pluginIndex); + auto desc = _pluginEntry->get_plugin_descriptor(pluginIndex); if (!desc) { qWarning() << "no plugin descriptor"; return false; @@ -122,12 +122,12 @@ bool PluginHost::load(const QString &path, int pluginIndex) { return false; } - plugin_ = pluginEntry_->create_plugin(&host_, desc->id); - if (!plugin_) { + _plugin = _pluginEntry->create_plugin(&host_, desc->id); + if (!_plugin) { qWarning() << "could not create the plugin with id: " << desc->id; return false; } - plugin_->init(plugin_); + _plugin->init(_plugin); initPluginExtensions(); scanParams(); @@ -138,56 +138,56 @@ bool PluginHost::load(const QString &path, int pluginIndex) { void PluginHost::initPluginExtensions() { checkForMainThread(); - if (pluginExtensionsAreInitialized_) + if (_pluginExtensionsAreInitialized) return; - initPluginExtension(pluginParams_, CLAP_EXT_PARAMS); - initPluginExtension(pluginQuickControls_, CLAP_EXT_QUICK_CONTROLS); - initPluginExtension(pluginAudioPorts_, CLAP_EXT_AUDIO_PORTS); - initPluginExtension(pluginGui_, CLAP_EXT_GUI); - initPluginExtension(pluginGuiX11_, CLAP_EXT_GUI_X11); - initPluginExtension(pluginGuiWin32_, CLAP_EXT_GUI_WIN32); - initPluginExtension(pluginGuiCocoa_, CLAP_EXT_GUI_COCOA); - initPluginExtension(pluginGuiFreeStanding_, CLAP_EXT_GUI_FREE_STANDING); - initPluginExtension(pluginTimerSupport_, CLAP_EXT_TIMER_SUPPORT); - initPluginExtension(pluginFdSupport_, CLAP_EXT_FD_SUPPORT); - initPluginExtension(pluginThreadPool_, CLAP_EXT_THREAD_POOL); - initPluginExtension(pluginPresetLoad_, CLAP_EXT_PRESET_LOAD); - initPluginExtension(pluginState_, CLAP_EXT_STATE); - - pluginExtensionsAreInitialized_ = true; + initPluginExtension(_pluginParams, CLAP_EXT_PARAMS); + initPluginExtension(_pluginQuickControls, CLAP_EXT_QUICK_CONTROLS); + initPluginExtension(_pluginAudioPorts, CLAP_EXT_AUDIO_PORTS); + initPluginExtension(_pluginGui, CLAP_EXT_GUI); + initPluginExtension(_pluginGuiX11, CLAP_EXT_GUI_X11); + initPluginExtension(_pluginGuiWin32, CLAP_EXT_GUI_WIN32); + initPluginExtension(_pluginGuiCocoa, CLAP_EXT_GUI_COCOA); + initPluginExtension(_pluginGuiFreeStanding, CLAP_EXT_GUI_FREE_STANDING); + initPluginExtension(_pluginTimerSupport, CLAP_EXT_TIMER_SUPPORT); + initPluginExtension(_pluginFdSupport, CLAP_EXT_FD_SUPPORT); + initPluginExtension(_pluginThreadPool, CLAP_EXT_THREAD_POOL); + initPluginExtension(_pluginPresetLoad, CLAP_EXT_PRESET_LOAD); + initPluginExtension(_pluginState, CLAP_EXT_STATE); + + _pluginExtensionsAreInitialized = true; } void PluginHost::unload() { checkForMainThread(); - if (!library_.isLoaded()) + if (!_library.isLoaded()) return; - if (pluginGui_) - pluginGui_->destroy(plugin_); + if (_pluginGui) + _pluginGui->destroy(_plugin); deactivate(); - plugin_->destroy(plugin_); - plugin_ = nullptr; - pluginGui_ = nullptr; - pluginAudioPorts_ = nullptr; + _plugin->destroy(_plugin); + _plugin = nullptr; + _pluginGui = nullptr; + _pluginAudioPorts = nullptr; - pluginEntry_->deinit(); - pluginEntry_ = nullptr; + _pluginEntry->deinit(); + _pluginEntry = nullptr; - library_.unload(); + _library.unload(); } bool PluginHost::canActivate() const { checkForMainThread(); - if (!engine_.isRunning()) + if (!_engine.isRunning()) return false; if (isPluginActive()) return false; - if (scheduleRestart_) + if (_scheduleRestart) return false; return true; } @@ -195,7 +195,7 @@ bool PluginHost::canActivate() const { void PluginHost::activate(int32_t sample_rate) { checkForMainThread(); - if (plugin_->activate(plugin_, sample_rate)) + if (_plugin->activate(_plugin, sample_rate)) setPluginState(ActiveAndSleeping); else setPluginState(InactiveWithError); @@ -208,62 +208,62 @@ void PluginHost::deactivate() { return; while (isPluginProcessing() || isPluginSleeping()) { - scheduleDeactivate_ = true; + _scheduleDeactivate = true; QThread::msleep(10); } - scheduleDeactivate_ = false; + _scheduleDeactivate = false; - plugin_->deactivate(plugin_); + _plugin->deactivate(_plugin); setPluginState(Inactive); } void PluginHost::setPorts(int numInputs, float **inputs, int numOutputs, float **outputs) { - audioIn_.channel_count = numInputs; - audioIn_.data32 = inputs; - audioIn_.data64 = nullptr; - audioIn_.constant_mask = 0; - audioIn_.latency = 0; - - audioOut_.channel_count = numOutputs; - audioOut_.data32 = outputs; - audioOut_.data64 = nullptr; - audioOut_.constant_mask = 0; - audioOut_.latency = 0; + _audioIn.channel_count = numInputs; + _audioIn.data32 = inputs; + _audioIn.data64 = nullptr; + _audioIn.constant_mask = 0; + _audioIn.latency = 0; + + _audioOut.channel_count = numOutputs; + _audioOut.data32 = outputs; + _audioOut.data64 = nullptr; + _audioOut.constant_mask = 0; + _audioOut.latency = 0; } void PluginHost::setParentWindow(WId parentWindow) { checkForMainThread(); - if (isGuiCreated_) { - pluginGui_->destroy(plugin_); - isGuiCreated_ = false; - isGuiVisible_ = false; + if (_isGuiCreated) { + _pluginGui->destroy(_plugin); + _isGuiCreated = false; + _isGuiVisible = false; } - if (!pluginGui_->create(plugin_)) + if (!_pluginGui->create(_plugin)) return; - isGuiCreated_ = true; - assert(isGuiVisible_ == false); + _isGuiCreated = true; + assert(_isGuiVisible == false); uint32_t width = 0; uint32_t height = 0; - if (pluginGui_) - pluginGui_->get_size(plugin_, &width, &height); + if (_pluginGui) + _pluginGui->get_size(_plugin, &width, &height); #if defined(Q_OS_LINUX) - if (pluginGuiX11_) - pluginGuiX11_->attach(plugin_, nullptr, parentWindow); + if (_pluginGuiX11) + _pluginGuiX11->attach(_plugin, nullptr, parentWindow); #elif defined(Q_OS_MACX) - if (pluginGuiCocoa_) - pluginGuiCocoa_->attach(plugin_, (void *)parentWindow); + if (_pluginGuiCocoa) + _pluginGuiCocoa->attach(_plugin, (void *)parentWindow); #elif defined(Q_OS_WIN32) - if (pluginEmbedWin32_) - pluginGuiWin32_->attach(plugin_, parentWindow); + if (_pluginEmbedWin32) + _pluginGuiWin32->attach(_plugin, parentWindow); #endif - // else (pluginGuiFreeStanding_) - // pluginGuiFreeStanding_->open(plugin_); + // else (_pluginGuiFreeStanding) + // _pluginGuiFreeStanding->open(_plugin); Application::instance().mainWindow()->resizePluginView(width, height); @@ -273,15 +273,15 @@ void PluginHost::setParentWindow(WId parentWindow) { void PluginHost::setPluginWindowVisibility(bool isVisible) { checkForMainThread(); - if (!isGuiCreated_) + if (!_isGuiCreated) return; - if (isVisible && !isGuiVisible_) { - pluginGui_->show(plugin_); - isGuiVisible_ = true; - } else if (!isVisible && isGuiVisible_) { - pluginGui_->hide(plugin_); - isGuiVisible_ = false; + if (isVisible && !_isGuiVisible) { + _pluginGui->show(_plugin); + _isGuiVisible = true; + } else if (!isVisible && _isGuiVisible) { + _pluginGui->hide(_plugin); + _isGuiVisible = false; } } @@ -309,33 +309,33 @@ void PluginHost::initPluginExtension(const T *&ext, const char *id) { checkForMainThread(); if (!ext) - ext = static_cast<const T *>(plugin_->get_extension(plugin_, id)); + ext = static_cast<const T *>(_plugin->get_extension(_plugin, id)); } const void *PluginHost::clapExtension(const clap_host *host, const char *extension) { checkForMainThread(); PluginHost *h = static_cast<PluginHost *>(host->host_data); - if (!h->plugin_) + if (!h->_plugin) throw std::logic_error("The plugin can't query for extensions during the create method. Wait " "for clap_plugin.init() call."); if (!strcmp(extension, CLAP_EXT_GUI)) - return &h->hostGui_; + return &h->_hostGui; if (!strcmp(extension, CLAP_EXT_LOG)) - return &h->hostLog_; + return &h->_hostLog; if (!strcmp(extension, CLAP_EXT_THREAD_CHECK)) - return &h->hostThreadCheck_; + return &h->_hostThreadCheck; if (!strcmp(extension, CLAP_EXT_TIMER_SUPPORT)) - return &h->hostTimerSupport_; + return &h->_hostTimerSupport; if (!strcmp(extension, CLAP_EXT_FD_SUPPORT)) - return &h->hostFdSupport_; + return &h->_hostFdSupport; if (!strcmp(extension, CLAP_EXT_PARAMS)) - return &h->hostParams_; + return &h->_hostParams; if (!strcmp(extension, CLAP_EXT_QUICK_CONTROLS)) - return &h->hostQuickControls_; + return &h->_hostQuickControls; if (!strcmp(extension, CLAP_EXT_STATE)) - return &h->hostState_; + return &h->_hostState; return nullptr; } @@ -347,7 +347,7 @@ PluginHost *PluginHost::fromHost(const clap_host *host) { if (!h) throw std::invalid_argument("Passed an invalid host pointer because the host_data is null"); - if (!h->plugin_) + if (!h->_plugin) throw std::logic_error( "Called into host interfaces befores the host knows the plugin pointer"); @@ -372,15 +372,15 @@ bool PluginHost::clapThreadPoolRequestExec(const clap_host *host, uint32_t num_t checkForAudioThread(); auto h = fromHost(host); - if (!h->pluginThreadPool_ || !h->pluginThreadPool_->exec) + if (!h->_pluginThreadPool || !h->_pluginThreadPool->exec) throw std::logic_error("Called request_exec() without providing clap_plugin_thread_pool to " "execute the job."); - Q_ASSERT(!h->threadPoolStop_); - Q_ASSERT(!h->threadPool_.empty()); - h->threadPoolTaskIndex_ = 0; - h->threadPoolSemaphoreProd_.release(num_tasks); - h->threadPoolSemaphoreDone_.acquire(num_tasks); + Q_ASSERT(!h->_threadPoolStop); + Q_ASSERT(!h->_threadPool.empty()); + h->_threadPoolTaskIndex = 0; + h->_threadPoolSemaphoreProd.release(num_tasks); + h->_threadPoolSemaphoreDone.acquire(num_tasks); return true; } @@ -389,22 +389,22 @@ bool PluginHost::clapRegisterTimer(const clap_host *host, uint32_t period_ms, cl auto h = fromHost(host); h->initPluginExtensions(); - if (!h->pluginTimerSupport_ || !h->pluginTimerSupport_->on_timer) + if (!h->_pluginTimerSupport || !h->_pluginTimerSupport->on_timer) throw std::logic_error( "Called register_timer() without providing clap_plugin_timer_support.on_timer() to " "receive the timer event."); - auto id = h->nextTimerId_++; + auto id = h->_nextTimerId++; *timer_id = id; auto timer = std::make_unique<QTimer>(); QObject::connect(timer.get(), &QTimer::timeout, [h, id] { checkForMainThread(); - h->pluginTimerSupport_->on_timer(h->plugin_, id); + h->_pluginTimerSupport->on_timer(h->_plugin, id); }); auto t = timer.get(); - h->timers_.emplace(*timer_id, std::move(timer)); + h->_timers.emplace(*timer_id, std::move(timer)); t->start(period_ms); return true; } @@ -413,16 +413,16 @@ bool PluginHost::clapUnregisterTimer(const clap_host *host, clap_id timer_id) { checkForMainThread(); auto h = fromHost(host); - if (!h->pluginTimerSupport_ || !h->pluginTimerSupport_->on_timer) + if (!h->_pluginTimerSupport || !h->_pluginTimerSupport->on_timer) throw std::logic_error( "Called unregister_timer() without providing clap_plugin_timer_support.on_timer() to " "receive the timer event."); - auto it = h->timers_.find(timer_id); - if (it == h->timers_.end()) + auto it = h->_timers.find(timer_id); + if (it == h->_timers.end()) throw std::logic_error("Called unregister_timer() for a timer_id that was not registered."); - h->timers_.erase(it); + h->_timers.erase(it); return true; } @@ -431,16 +431,16 @@ bool PluginHost::clapRegisterFd(const clap_host *host, clap_fd fd, uint32_t flag auto h = fromHost(host); h->initPluginExtensions(); - if (!h->pluginFdSupport_ || !h->pluginFdSupport_->on_fd) + if (!h->_pluginFdSupport || !h->_pluginFdSupport->on_fd) throw std::logic_error("Called register_fd() without providing clap_plugin_fd_support to " "receive the fd event."); - auto it = h->fds_.find(fd); - if (it != h->fds_.end()) + auto it = h->_fds.find(fd); + if (it != h->_fds.end()) throw std::logic_error( "Called register_fd() for a fd that was already registered, use modify_fd() instead."); - h->fds_.emplace(fd, std::make_unique<Notifiers>()); + h->_fds.emplace(fd, std::make_unique<Notifiers>()); h->eventLoopSetFdNotifierFlags(fd, flags); return true; } @@ -449,16 +449,16 @@ bool PluginHost::clapModifyFd(const clap_host *host, clap_fd fd, uint32_t flags) checkForMainThread(); auto h = fromHost(host); - if (!h->pluginFdSupport_ || !h->pluginFdSupport_->on_fd) + if (!h->_pluginFdSupport || !h->_pluginFdSupport->on_fd) throw std::logic_error("Called modify_fd() without providing clap_plugin_fd_support to " "receive the timer event."); - auto it = h->fds_.find(fd); - if (it == h->fds_.end()) + auto it = h->_fds.find(fd); + if (it == h->_fds.end()) throw std::logic_error( "Called modify_fd() for a fd that was not registered, use register_fd() instead."); - h->fds_.emplace(fd, std::make_unique<Notifiers>()); + h->_fds.emplace(fd, std::make_unique<Notifiers>()); h->eventLoopSetFdNotifierFlags(fd, flags); return true; } @@ -467,30 +467,30 @@ bool PluginHost::clapUnregisterFd(const clap_host *host, clap_fd fd) { checkForMainThread(); auto h = fromHost(host); - if (!h->pluginFdSupport_ || !h->pluginFdSupport_->on_fd) + if (!h->_pluginFdSupport || !h->_pluginFdSupport->on_fd) throw std::logic_error("Called unregister_fd() without providing clap_plugin_fd_support to " "receive the fd event."); - auto it = h->fds_.find(fd); - if (it == h->fds_.end()) + auto it = h->_fds.find(fd); + if (it == h->_fds.end()) throw std::logic_error("Called unregister_fd() for a fd that was not registered."); - h->fds_.erase(it); + h->_fds.erase(it); return true; } void PluginHost::eventLoopSetFdNotifierFlags(clap_fd fd, uint32_t flags) { checkForMainThread(); - auto it = fds_.find(fd); - Q_ASSERT(it != fds_.end()); + auto it = _fds.find(fd); + Q_ASSERT(it != _fds.end()); if (flags & CLAP_FD_READ) { if (!it->second->rd) { it->second->rd.reset(new QSocketNotifier(fd, QSocketNotifier::Read)); QObject::connect(it->second->rd.get(), &QSocketNotifier::activated, [this, fd] { checkForMainThread(); - this->pluginFdSupport_->on_fd(this->plugin_, fd, CLAP_FD_READ); + _pluginFdSupport->on_fd(this->_plugin, fd, CLAP_FD_READ); }); } it->second->rd->setEnabled(true); @@ -502,7 +502,7 @@ void PluginHost::eventLoopSetFdNotifierFlags(clap_fd fd, uint32_t flags) { it->second->wr.reset(new QSocketNotifier(fd, QSocketNotifier::Write)); QObject::connect(it->second->wr.get(), &QSocketNotifier::activated, [this, fd] { checkForMainThread(); - this->pluginFdSupport_->on_fd(this->plugin_, fd, CLAP_FD_WRITE); + _pluginFdSupport->on_fd(this->_plugin, fd, CLAP_FD_WRITE); }); } it->second->wr->setEnabled(true); @@ -514,7 +514,7 @@ void PluginHost::eventLoopSetFdNotifierFlags(clap_fd fd, uint32_t flags) { it->second->err.reset(new QSocketNotifier(fd, QSocketNotifier::Exception)); QObject::connect(it->second->err.get(), &QSocketNotifier::activated, [this, fd] { checkForMainThread(); - this->pluginFdSupport_->on_fd(this->plugin_, fd, CLAP_FD_ERROR); + _pluginFdSupport->on_fd(this->_plugin, fd, CLAP_FD_ERROR); }); } it->second->err->setEnabled(true); @@ -532,15 +532,15 @@ bool PluginHost::clapGuiResize(const clap_host *host, uint32_t width, uint32_t h void PluginHost::processBegin(int nframes) { g_thread_type = AudioThread; - process_.frames_count = nframes; - process_.steady_time = engine_.steadyTime_; + _process.frames_count = nframes; + _process.steady_time = _engine._steadyTime; } void PluginHost::processEnd(int nframes) { g_thread_type = Unknown; - process_.frames_count = nframes; - process_.steady_time = engine_.steadyTime_; + _process.frames_count = nframes; + _process.steady_time = _engine._steadyTime; } void PluginHost::processNoteOn(int sampleOffset, int channel, int key, int velocity) { @@ -553,7 +553,7 @@ void PluginHost::processNoteOn(int sampleOffset, int channel, int key, int veloc ev.note.channel = channel; ev.note.velocity = velocity / 127.0; - evIn_.push_back(ev); + _evIn.push_back(ev); } void PluginHost::processNoteOff(int sampleOffset, int channel, int key, int velocity) { @@ -566,7 +566,7 @@ void PluginHost::processNoteOff(int sampleOffset, int channel, int key, int velo ev.note.channel = channel; ev.note.velocity = velocity / 127.0; - evIn_.push_back(ev); + _evIn.push_back(ev); } void PluginHost::processNoteAt(int sampleOffset, int channel, int key, int pressure) { @@ -592,7 +592,7 @@ void PluginHost::processCC(int sampleOffset, int channel, int cc, int value) { ev.midi.data[1] = cc; ev.midi.data[2] = value; - evIn_.push_back(ev); + _evIn.push_back(ev); } static uint32_t clap_host_event_list_size(const struct clap_event_list *list) { @@ -627,24 +627,24 @@ void PluginHost::process() { if (!isPluginProcessing() && !isPluginSleeping()) return; - process_.transport = nullptr; + _process.transport = nullptr; clap_event_list in_ev = { - &evIn_, clap_host_event_list_size, clap_host_event_list_get, clap_host_event_list_push_back}; + &_evIn, clap_host_event_list_size, clap_host_event_list_get, clap_host_event_list_push_back}; clap_event_list out_ev = { - &evOut_, clap_host_event_list_size, clap_host_event_list_get, clap_host_event_list_push_back}; + &_evOut, clap_host_event_list_size, clap_host_event_list_get, clap_host_event_list_push_back}; - process_.in_events = &in_ev; - process_.out_events = &out_ev; + _process.in_events = &in_ev; + _process.out_events = &out_ev; - process_.audio_inputs = &audioIn_; - process_.audio_inputs_count = 1; - process_.audio_outputs = &audioOut_; - process_.audio_outputs_count = 1; + _process.audio_inputs = &_audioIn; + _process.audio_inputs_count = 1; + _process.audio_outputs = &_audioOut; + _process.audio_outputs_count = 1; - evOut_.clear(); - appToEngineValueQueue_.consume([this](clap_id param_id, const ParamQueueValue &value) { + _evOut.clear(); + _appToEngineValueQueue.consume([this](clap_id param_id, const ParamQueueValue &value) { clap_event ev; ev.time = 0; ev.type = CLAP_EVENT_PARAM_VALUE; @@ -654,10 +654,10 @@ void PluginHost::process() { ev.param_value.channel = -1; ev.param_value.value = value.value; ev.param_value.flags = 0; - evIn_.push_back(ev); + _evIn.push_back(ev); }); - appToEngineModQueue_.consume([this](clap_id param_id, const ParamQueueValue &value) { + _appToEngineModQueue.consume([this](clap_id param_id, const ParamQueueValue &value) { clap_event ev; ev.time = 0; ev.type = CLAP_EVENT_PARAM_MOD; @@ -666,38 +666,38 @@ void PluginHost::process() { ev.param_mod.key = -1; ev.param_mod.channel = -1; ev.param_mod.amount = value.value; - evIn_.push_back(ev); + _evIn.push_back(ev); }); // TODO if the plugin was not processing and had audio or events that should // wake it, then we should set it as processing if (!isPluginProcessing()) { - plugin_->start_processing(plugin_); + _plugin->start_processing(_plugin); setPluginState(ActiveAndProcessing); } int32_t status; - if (plugin_ && plugin_->process) - status = plugin_->process(plugin_, &process_); + if (_plugin && _plugin->process) + status = _plugin->process(_plugin, &_process); - for (auto &ev : evOut_) { + for (auto &ev : _evOut) { switch (ev.type) { case CLAP_EVENT_PARAM_VALUE: - engineToAppValueQueue_.set(ev.param_value.param_id, + _engineToAppValueQueue.set(ev.param_value.param_id, {ev.param_value.cookie, ev.param_value.value}); break; } } - evOut_.clear(); - evIn_.clear(); + _evOut.clear(); + _evIn.clear(); - if (scheduleDeactivate_) { - scheduleDeactivate_ = false; - plugin_->stop_processing(plugin_); + if (_scheduleDeactivate) { + _scheduleDeactivate = false; + _plugin->stop_processing(_plugin); setPluginState(ActiveAndReadyToDeactivate); } - engineToAppValueQueue_.producerDone(); + _engineToAppValueQueue.producerDone(); g_thread_type = Unknown; } @@ -705,12 +705,12 @@ void PluginHost::idle() { checkForMainThread(); // Try to send events to the audio engine - appToEngineValueQueue_.producerDone(); - appToEngineModQueue_.producerDone(); + _appToEngineValueQueue.producerDone(); + _appToEngineModQueue.producerDone(); - engineToAppValueQueue_.consume([this](clap_id param_id, const ParamQueueValue &value) { - auto it = params_.find(param_id); - if (it == params_.end()) { + _engineToAppValueQueue.consume([this](clap_id param_id, const ParamQueueValue &value) { + auto it = _params.find(param_id); + if (it == _params.end()) { std::ostringstream msg; msg << "Plugin produced a CLAP_EVENT_PARAM_SET with an unknown param_id: " << param_id; throw std::invalid_argument(msg.str()); @@ -731,8 +731,8 @@ PluginParam &PluginHost::checkValidParamId(const std::string_view &function, throw std::invalid_argument(msg.str()); } - auto it = params_.find(param_id); - if (it == params_.end()) { + auto it = _params.find(param_id); + if (it == _params.end()) { std::ostringstream msg; msg << "Plugin called " << function << " with an invalid " << param_name << " == " << param_id; @@ -761,8 +761,8 @@ void PluginHost::setParamValueByHost(PluginParam &param, double value) { param.setValue(value); - appToEngineValueQueue_.set(param.info().id, {param.info().cookie, value}); - appToEngineValueQueue_.producerDone(); + _appToEngineValueQueue.set(param.info().id, {param.info().cookie, value}); + _appToEngineValueQueue.producerDone(); } void PluginHost::setParamModulationByHost(PluginParam &param, double value) { @@ -770,8 +770,8 @@ void PluginHost::setParamModulationByHost(PluginParam &param, double value) { param.setModulation(value); - appToEngineModQueue_.set(param.info().id, {param.info().cookie, value}); - appToEngineModQueue_.producerDone(); + _appToEngineModQueue.set(param.info().id, {param.info().cookie, value}); + _appToEngineModQueue.producerDone(); } void PluginHost::scanParams() { clapParamsRescan(&host_, CLAP_PARAM_RESCAN_ALL); } @@ -788,12 +788,12 @@ void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) { } // 2. scan the params. - auto count = h->pluginParams_->count(h->plugin_); + auto count = h->_pluginParams->count(h->_plugin); std::unordered_set<clap_id> paramIds(count * 2); for (int32_t i = 0; i < count; ++i) { clap_param_info info; - if (!h->pluginParams_->get_info(h->plugin_, i, &info)) + if (!h->_pluginParams->get_info(h->_plugin, i, &info)) throw std::logic_error("clap_plugin_params.get_info did return false!"); if (info.id == CLAP_INVALID_ID) { @@ -804,11 +804,11 @@ void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) { throw std::logic_error(msg.str()); } - auto it = h->params_.find(info.id); + auto it = h->_params.find(info.id); // check that the parameter is not declared twice if (paramIds.count(info.id) > 0) { - Q_ASSERT(it != h->params_.end()); + Q_ASSERT(it != h->_params.end()); std::ostringstream msg; msg << "the parameter with id: " << info.id << " was declared twice." << std::endl @@ -819,7 +819,7 @@ void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) { } paramIds.insert(info.id); - if (it == h->params_.end()) { + if (it == h->_params.end()) { if (!(flags & CLAP_PARAM_RESCAN_ALL)) { std::ostringstream msg; msg << "a new parameter was declared, but the flag CLAP_PARAM_RESCAN_ALL was not " @@ -831,7 +831,7 @@ void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) { double value = h->getParamValue(info); auto param = std::make_unique<PluginParam>(*h, info, value); h->checkValidParamValue(*param, value); - h->params_.emplace(info.id, std::move(param)); + h->_params.emplace(info.id, std::move(param)); } else { // update param info if (!it->second->isInfoEqualTo(info)) { @@ -877,7 +877,7 @@ void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) { } // remove parameters which are gone - for (auto it = h->params_.begin(); it != h->params_.end();) { + for (auto it = h->_params.begin(); it != h->_params.end();) { if (paramIds.find(it->first) != paramIds.end()) ++it; else { @@ -889,7 +889,7 @@ void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) { << info.id << ", name: " << info.name << ", module: " << info.module << std::endl; throw std::logic_error(msg.str()); } - it = h->params_.erase(it); + it = h->_params.erase(it); } } @@ -900,7 +900,7 @@ void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) { double PluginHost::getParamValue(const clap_param_info &info) { checkForMainThread(); double value; - if (pluginParams_->get_value(plugin_, info.id, &value)) + if (_pluginParams->get_value(_plugin, info.id, &value)) return value; std::ostringstream msg; @@ -912,28 +912,28 @@ double PluginHost::getParamValue(const clap_param_info &info) { void PluginHost::scanQuickControls() { checkForMainThread(); - if (!pluginQuickControls_) + if (!_pluginQuickControls) return; - if (!pluginQuickControls_->get || !pluginQuickControls_->count) { + if (!_pluginQuickControls->get || !_pluginQuickControls->count) { std::ostringstream msg; msg << "clap_plugin_quick_controls is partially implemented."; throw std::logic_error(msg.str()); } quickControlsSetSelectedPage(CLAP_INVALID_ID); - quickControlsPages_.clear(); + _quickControlsPages.clear(); - const auto N = pluginQuickControls_->count(plugin_); + const auto N = _pluginQuickControls->count(_plugin); if (N == 0) return; - quickControlsPages_.reserve(N); + _quickControlsPages.reserve(N); clap_id firstPageId = CLAP_INVALID_ID; for (int i = 0; i < N; ++i) { auto page = std::make_unique<clap_quick_controls_page>(); - if (!pluginQuickControls_->get(plugin_, i, page.get())) { + if (!_pluginQuickControls->get(_plugin, i, page.get())) { std::ostringstream msg; msg << "clap_plugin_quick_controls.get_page(" << i << ") failed, while the page count is " << N; @@ -949,8 +949,8 @@ void PluginHost::scanQuickControls() { if (i == 0) firstPageId = page->id; - auto it = quickControlsPages_.find(page->id); - if (it != quickControlsPages_.end()) { + auto it = _quickControlsPages.find(page->id); + if (it != _quickControlsPages.end()) { std::ostringstream msg; msg << "clap_plugin_quick_controls.get_page(" << i << ") gave twice the same page_id:" << page->id << std::endl @@ -959,30 +959,30 @@ void PluginHost::scanQuickControls() { throw std::invalid_argument(msg.str()); } - quickControlsPages_.emplace(page->id, std::move(page)); + _quickControlsPages.emplace(page->id, std::move(page)); } quickControlsPagesChanged(); - auto pageId = pluginQuickControls_->get_selected(plugin_); + auto pageId = _pluginQuickControls->get_selected(_plugin); quickControlsSetSelectedPage(pageId == CLAP_INVALID_ID ? firstPageId : pageId); } void PluginHost::quickControlsSetSelectedPage(clap_id pageId) { checkForMainThread(); - if (pageId == quickControlsSelectedPage_) + if (pageId == _quickControlsSelectedPage) return; if (pageId != CLAP_INVALID_ID) { - auto it = quickControlsPages_.find(pageId); - if (it == quickControlsPages_.end()) { + auto it = _quickControlsPages.find(pageId); + if (it == _quickControlsPages.end()) { std::ostringstream msg; msg << "quick control page_id " << pageId << " not found"; throw std::invalid_argument(msg.str()); } } - quickControlsSelectedPage_ = pageId; + _quickControlsSelectedPage = pageId; quickControlsSelectedPageChanged(); } @@ -992,10 +992,10 @@ void PluginHost::setQuickControlsSelectedPageByHost(clap_id page_id) { checkForMainThread(); - quickControlsSelectedPage_ = page_id; + _quickControlsSelectedPage = page_id; - if (pluginQuickControls_ && pluginQuickControls_->select) - pluginQuickControls_->select(plugin_, page_id); + if (_pluginQuickControls && _pluginQuickControls->select) + _pluginQuickControls->select(_plugin, page_id); } void PluginHost::clapQuickControlsChanged(const clap_host *host, @@ -1003,7 +1003,7 @@ void PluginHost::clapQuickControlsChanged(const clap_host *host, checkForMainThread(); auto h = fromHost(host); - if (!h->pluginQuickControls_) { + if (!h->_pluginQuickControls) { std::ostringstream msg; msg << "Plugin called clap_host_quick_controls.changed() but does not provide " "clap_plugin_quick_controls"; @@ -1014,7 +1014,7 @@ void PluginHost::clapQuickControlsChanged(const clap_host *host, h->scanQuickControls(); if (flags & CLAP_QUICK_CONTROLS_SELECTED_PAGE_CHANGED) { - auto selectedPageId = h->pluginQuickControls_->get_selected(h->plugin_); + auto selectedPageId = h->_pluginQuickControls->get_selected(h->_plugin); h->quickControlsSetSelectedPage(selectedPageId); } } @@ -1022,13 +1022,13 @@ void PluginHost::clapQuickControlsChanged(const clap_host *host, bool PluginHost::loadNativePluginPreset(const std::string &path) { checkForMainThread(); - if (!pluginPresetLoad_) + if (!_pluginPresetLoad) return false; - if (!pluginPresetLoad_->from_file) + if (!_pluginPresetLoad->from_file) throw std::logic_error("clap_plugin_preset_load does not implement load_from_file"); - return pluginPresetLoad_->from_file(plugin_, path.c_str()); + return _pluginPresetLoad->from_file(_plugin, path.c_str()); } void PluginHost::clapStateMarkDirty(const clap_host *host) { @@ -1036,49 +1036,49 @@ void PluginHost::clapStateMarkDirty(const clap_host *host) { auto h = fromHost(host); - if (!h->pluginState_ || !h->pluginState_->save || !h->pluginState_->load) + if (!h->_pluginState || !h->_pluginState->save || !h->_pluginState->load) throw std::logic_error("Plugin called clap_host_state.set_dirty() but the host does not " "provide a complete clap_plugin_state interface."); - h->stateIsDirty_ = true; + h->_stateIsDirty = true; } void PluginHost::setPluginState(PluginState state) { switch (state) { case Inactive: - Q_ASSERT(state_ == ActiveAndReadyToDeactivate); + Q_ASSERT(_state == ActiveAndReadyToDeactivate); break; case InactiveWithError: - Q_ASSERT(state_ == Inactive); + Q_ASSERT(_state == Inactive); break; case ActiveAndSleeping: - Q_ASSERT(state_ == Inactive || state_ == ActiveAndProcessing); + Q_ASSERT(_state == Inactive || _state == ActiveAndProcessing); break; case ActiveAndProcessing: - Q_ASSERT(state_ == ActiveAndSleeping); + Q_ASSERT(_state == ActiveAndSleeping); break; case ActiveWithError: - Q_ASSERT(state_ == ActiveAndProcessing); + Q_ASSERT(_state == ActiveAndProcessing); break; case ActiveAndReadyToDeactivate: - Q_ASSERT(state_ == ActiveAndProcessing || state_ == ActiveAndSleeping || - state_ == ActiveWithError); + Q_ASSERT(_state == ActiveAndProcessing || _state == ActiveAndSleeping || + _state == ActiveWithError); break; default: std::terminate(); } - state_ = state; + _state = state; } bool PluginHost::isPluginActive() const { - switch (state_) { + switch (_state) { case Inactive: case InactiveWithError: return false; @@ -1087,6 +1087,6 @@ bool PluginHost::isPluginActive() const { } } -bool PluginHost::isPluginProcessing() const { return state_ == ActiveAndProcessing; } +bool PluginHost::isPluginProcessing() const { return _state == ActiveAndProcessing; } -bool PluginHost::isPluginSleeping() const { return state_ == ActiveAndSleeping; } -\ No newline at end of file +bool PluginHost::isPluginSleeping() const { return _state == ActiveAndSleeping; } +\ No newline at end of file diff --git a/examples/host/plugin-host.hh b/examples/host/plugin-host.hh @@ -59,9 +59,9 @@ public: void setParamValueByHost(PluginParam &param, double value); void setParamModulationByHost(PluginParam &param, double value); - auto &params() const { return params_; } - auto &quickControlsPages() const { return quickControlsPages_; } - auto quickControlsSelectedPage() const { return quickControlsSelectedPage_; } + auto &params() const { return _params; } + auto &quickControlsPages() const { return _quickControlsPages; } + auto quickControlsSelectedPage() const { return _quickControlsSelectedPage; } void setQuickControlsSelectedPageByHost(clap_id page_id); bool loadNativePluginPreset(const std::string &path); @@ -125,66 +125,66 @@ private: static void clapStateMarkDirty(const clap_host *host); private: - Engine &engine_; + Engine &_engine; - QLibrary library_; + QLibrary _library; clap_host host_; - static const constexpr clap_host_log hostLog_ = { + static const constexpr clap_host_log _hostLog = { PluginHost::clapLog, }; - static const constexpr clap_host_gui hostGui_ = { + static const constexpr clap_host_gui _hostGui = { PluginHost::clapGuiResize, }; //static const constexpr clap_host_audio_ports hostAudioPorts_; //static const constexpr clap_host_audio_ports_config hostAudioPortsConfig_; - static const constexpr clap_host_params hostParams_ = { + static const constexpr clap_host_params _hostParams = { PluginHost::clapParamsRescan, }; - static const constexpr clap_host_quick_controls hostQuickControls_ = { + static const constexpr clap_host_quick_controls _hostQuickControls = { PluginHost::clapQuickControlsChanged, }; - static const constexpr clap_host_timer_support hostTimerSupport_ = { + static const constexpr clap_host_timer_support _hostTimerSupport = { PluginHost::clapRegisterTimer, PluginHost::clapUnregisterTimer, }; - static const constexpr clap_host_fd_support hostFdSupport_ = { + static const constexpr clap_host_fd_support _hostFdSupport = { PluginHost::clapRegisterFd, PluginHost::clapModifyFd, PluginHost::clapUnregisterFd, }; - static const constexpr clap_host_thread_check hostThreadCheck_ = { + static const constexpr clap_host_thread_check _hostThreadCheck = { PluginHost::clapIsMainThread, PluginHost::clapIsAudioThread, }; - static const constexpr clap_host_thread_pool hostThreadPool_ = { + static const constexpr clap_host_thread_pool _hostThreadPool = { PluginHost::clapThreadPoolRequestExec, }; - static const constexpr clap_host_state hostState_ = { + static const constexpr clap_host_state _hostState = { PluginHost::clapStateMarkDirty, }; - const struct clap_plugin_entry *pluginEntry_ = nullptr; - const clap_plugin *plugin_ = nullptr; - const clap_plugin_params *pluginParams_ = nullptr; - const clap_plugin_quick_controls *pluginQuickControls_ = nullptr; - const clap_plugin_audio_ports *pluginAudioPorts_ = nullptr; - const clap_plugin_gui *pluginGui_ = nullptr; - const clap_plugin_gui_x11 *pluginGuiX11_ = nullptr; - const clap_plugin_gui_win32 *pluginGuiWin32_ = nullptr; - const clap_plugin_gui_cocoa *pluginGuiCocoa_ = nullptr; - const clap_plugin_gui_free_standing *pluginGuiFreeStanding_ = nullptr; - const clap_plugin_timer_support *pluginTimerSupport_ = nullptr; - const clap_plugin_fd_support *pluginFdSupport_ = nullptr; - const clap_plugin_thread_pool *pluginThreadPool_ = nullptr; - const clap_plugin_preset_load *pluginPresetLoad_ = nullptr; - const clap_plugin_state *pluginState_ = nullptr; - - bool pluginExtensionsAreInitialized_ = false; + const struct clap_plugin_entry *_pluginEntry = nullptr; + const clap_plugin *_plugin = nullptr; + const clap_plugin_params *_pluginParams = nullptr; + const clap_plugin_quick_controls *_pluginQuickControls = nullptr; + const clap_plugin_audio_ports *_pluginAudioPorts = nullptr; + const clap_plugin_gui *_pluginGui = nullptr; + const clap_plugin_gui_x11 *_pluginGuiX11 = nullptr; + const clap_plugin_gui_win32 *_pluginGuiWin32 = nullptr; + const clap_plugin_gui_cocoa *_pluginGuiCocoa = nullptr; + const clap_plugin_gui_free_standing *_pluginGuiFreeStanding = nullptr; + const clap_plugin_timer_support *_pluginTimerSupport = nullptr; + const clap_plugin_fd_support *_pluginFdSupport = nullptr; + const clap_plugin_thread_pool *_pluginThreadPool = nullptr; + const clap_plugin_preset_load *_pluginPresetLoad = nullptr; + const clap_plugin_state *_pluginState = nullptr; + + bool _pluginExtensionsAreInitialized = false; /* timers */ - clap_id nextTimerId_ = 0; - std::unordered_map<clap_id, std::unique_ptr<QTimer>> timers_; + clap_id _nextTimerId = 0; + std::unordered_map<clap_id, std::unique_ptr<QTimer>> _timers; /* fd events */ struct Notifiers { @@ -192,36 +192,36 @@ PluginHost::clapParamsRescan, std::unique_ptr<QSocketNotifier> wr; std::unique_ptr<QSocketNotifier> err; }; - std::unordered_map<clap_fd, std::unique_ptr<Notifiers>> fds_; + std::unordered_map<clap_fd, std::unique_ptr<Notifiers>> _fds; /* thread pool */ - std::vector<std::unique_ptr<QThread>> threadPool_; - std::atomic<bool> threadPoolStop_ = {false}; - std::atomic<int> threadPoolTaskIndex_ = {0}; - QSemaphore threadPoolSemaphoreProd_; - QSemaphore threadPoolSemaphoreDone_; + std::vector<std::unique_ptr<QThread>> _threadPool; + std::atomic<bool> _threadPoolStop = {false}; + std::atomic<int> _threadPoolTaskIndex = {0}; + QSemaphore _threadPoolSemaphoreProd; + QSemaphore _threadPoolSemaphoreDone; /* process stuff */ - clap_audio_buffer audioIn_ = {}; - clap_audio_buffer audioOut_ = {}; - std::vector<clap_event> evIn_; - std::vector<clap_event> evOut_; - clap_process process_; + clap_audio_buffer _audioIn = {}; + clap_audio_buffer _audioOut = {}; + std::vector<clap_event> _evIn; + std::vector<clap_event> _evOut; + clap_process _process; /* param update queues */ - std::unordered_map<clap_id, std::unique_ptr<PluginParam>> params_; + std::unordered_map<clap_id, std::unique_ptr<PluginParam>> _params; struct ParamQueueValue { void *cookie; double value; }; - ParamQueue<ParamQueueValue> appToEngineValueQueue_; - ParamQueue<ParamQueueValue> appToEngineModQueue_; - ParamQueue<ParamQueueValue> engineToAppValueQueue_; + ParamQueue<ParamQueueValue> _appToEngineValueQueue; + ParamQueue<ParamQueueValue> _appToEngineModQueue; + ParamQueue<ParamQueueValue> _engineToAppValueQueue; - std::unordered_map<clap_id, std::unique_ptr<clap_quick_controls_page>> quickControlsPages_; - clap_id quickControlsSelectedPage_ = CLAP_INVALID_ID; + std::unordered_map<clap_id, std::unique_ptr<clap_quick_controls_page>> _quickControlsPages; + clap_id _quickControlsSelectedPage = CLAP_INVALID_ID; /* delayed actions */ enum PluginState { @@ -250,12 +250,12 @@ PluginHost::clapParamsRescan, bool isPluginSleeping() const; void setPluginState(PluginState state); - PluginState state_ = Inactive; - bool stateIsDirty_ = false; + PluginState _state = Inactive; + bool _stateIsDirty = false; - bool scheduleRestart_ = false; - bool scheduleDeactivate_ = false; + bool _scheduleRestart = false; + bool _scheduleDeactivate = false; - bool isGuiCreated_ = false; - bool isGuiVisible_ = false; + bool _isGuiCreated = false; + bool _isGuiVisible = false; }; diff --git a/examples/host/plugin-info.cc b/examples/host/plugin-info.cc @@ -1,3 +0,0 @@ -#include "plugin-info.hh" - -PluginInfo::PluginInfo() {} diff --git a/examples/host/plugin-info.hh b/examples/host/plugin-info.hh @@ -4,10 +4,10 @@ class PluginInfo { public: - PluginInfo(); + PluginInfo() = default; private: - QString name_; - QString file_; - QString index_; // in case of shell plugin + QString _name; + QString _file; + QString _index; // in case of shell plugin }; diff --git a/examples/host/plugin-param.cc b/examples/host/plugin-param.cc @@ -2,45 +2,45 @@ #include "plugin-host.hh" PluginParam::PluginParam(PluginHost &pluginHost, const clap_param_info &info, double value) - : QObject(&pluginHost), info_(info), value_(value) {} + : QObject(&pluginHost), _info(info), _value(value) {} void PluginParam::setValue(double v) { - if (value_ == v) + if (_value == v) return; - value_ = v; + _value = v; valueChanged(); } void PluginParam::setModulation(double v) { - if (modulation_ == v) + if (_modulation == v) return; - modulation_ = v; + _modulation = v; modulatedValueChanged(); } bool PluginParam::isValueValid(const double v) const { - return info_.min_value <= v && v <= info_.max_value; + return _info.min_value <= v && v <= _info.max_value; } void PluginParam::printShortInfo(std::ostream &os) const { - os << "id: " << info_.id << ", name: '" << info_.name << "', module: '" << info_.module << "'"; + os << "id: " << _info.id << ", name: '" << _info.name << "', module: '" << _info.module << "'"; } void PluginParam::printInfo(std::ostream &os) const { printShortInfo(os); - os << ", min: " << info_.min_value << ", max: " << info_.max_value; + os << ", min: " << _info.min_value << ", max: " << _info.max_value; } bool PluginParam::isInfoEqualTo(const clap_param_info &info) const { - return !std::memcmp(&info, &info_, sizeof(clap_param_info)); + return !std::memcmp(&info, &_info, sizeof(clap_param_info)); } bool PluginParam::isInfoCriticallyDifferentTo(const clap_param_info &info) const { - assert(info_.id == info.id); - return (info_.flags & CLAP_PARAM_IS_PER_NOTE) == (info.flags & CLAP_PARAM_IS_PER_NOTE) || - (info_.flags & CLAP_PARAM_IS_PER_CHANNEL) == (info.flags & CLAP_PARAM_IS_PER_CHANNEL) || - (info_.flags & CLAP_PARAM_IS_READONLY) == (info.flags & CLAP_PARAM_IS_READONLY) || - info_.min_value != info_.min_value || info_.max_value != info_.max_value; + assert(_info.id == info.id); + return (_info.flags & CLAP_PARAM_IS_PER_NOTE) == (info.flags & CLAP_PARAM_IS_PER_NOTE) || + (_info.flags & CLAP_PARAM_IS_PER_CHANNEL) == (info.flags & CLAP_PARAM_IS_PER_CHANNEL) || + (_info.flags & CLAP_PARAM_IS_READONLY) == (info.flags & CLAP_PARAM_IS_READONLY) || + _info.min_value != _info.min_value || _info.max_value != _info.max_value; } \ No newline at end of file diff --git a/examples/host/plugin-param.hh b/examples/host/plugin-param.hh @@ -14,14 +14,14 @@ class PluginParam : public QObject { public: PluginParam(PluginHost &pluginHost, const clap_param_info &info, double value); - double value() const { return value_; } + double value() const { return _value; } void setValue(double v); - double modulation() const { return modulation_; } + double modulation() const { return _modulation; } void setModulation(double v); double modulatedValue() const { - return std::min(info_.max_value, std::max(info_.min_value, value_ + modulation_)); + return std::min(_info.max_value, std::max(_info.min_value, _value + _modulation)); } bool isValueValid(const double v) const; @@ -29,21 +29,21 @@ public: void printShortInfo(std::ostream &os) const; void printInfo(std::ostream &os) const; - void setInfo(const clap_param_info &info) noexcept { info_ = info; } + void setInfo(const clap_param_info &info) noexcept { _info = info; } bool isInfoEqualTo(const clap_param_info &info) const; bool isInfoCriticallyDifferentTo(const clap_param_info &info) const; - clap_param_info &info() noexcept { return info_; } - const clap_param_info &info() const noexcept { return info_; } + clap_param_info &info() noexcept { return _info; } + const clap_param_info &info() const noexcept { return _info; } - bool isBeingAdjusted() const noexcept { return is_being_adjusted_; } + bool isBeingAdjusted() const noexcept { return _isBeingAdjusted; } void beginAdjust() { - Q_ASSERT(!is_being_adjusted_); - is_being_adjusted_ = true; + Q_ASSERT(!_isBeingAdjusted); + _isBeingAdjusted = true; isBeingAdjustedChanged(); } void endAdjust() { - Q_ASSERT(is_being_adjusted_); - is_being_adjusted_ = false; + Q_ASSERT(_isBeingAdjusted); + _isBeingAdjusted = false; isBeingAdjustedChanged(); } @@ -54,9 +54,9 @@ signals: void modulatedValueChanged(); private: - bool is_being_adjusted_ = false; - clap_param_info info_; - double value_ = 0; - double modulation_ = 0; - std::unordered_map<int64_t, std::string> enum_entries_; + bool _isBeingAdjusted = false; + clap_param_info _info; + double _value = 0; + double _modulation = 0; + std::unordered_map<int64_t, std::string> _enumEntries; }; \ No newline at end of file diff --git a/examples/host/plugin-parameters-widget.cc b/examples/host/plugin-parameters-widget.cc @@ -71,22 +71,22 @@ void PluginParametersWidget::ModuleTreeItem::setData(int column, int role, const //////////////////////////// PluginParametersWidget::PluginParametersWidget(QWidget *parent, PluginHost &pluginHost) - : QWidget(parent), pluginHost_(pluginHost) { + : QWidget(parent), _pluginHost(pluginHost) { - treeWidget_ = new QTreeWidget(this); + _treeWidget = new QTreeWidget(this); // Tree - rootModuleItem_ = new ModuleTreeItem(treeWidget_); - treeWidget_->addTopLevelItem(rootModuleItem_); - treeWidget_->setHeaderHidden(true); - treeWidget_->setAnimated(true); - treeWidget_->setRootIsDecorated(true); - treeWidget_->setSelectionMode(QAbstractItemView::SingleSelection); - treeWidget_->setSelectionBehavior(QAbstractItemView::SelectItems); - treeWidget_->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); + _rootModuleItem = new ModuleTreeItem(_treeWidget); + _treeWidget->addTopLevelItem(_rootModuleItem); + _treeWidget->setHeaderHidden(true); + _treeWidget->setAnimated(true); + _treeWidget->setRootIsDecorated(true); + _treeWidget->setSelectionMode(QAbstractItemView::SingleSelection); + _treeWidget->setSelectionBehavior(QAbstractItemView::SelectItems); + _treeWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); connect( - &pluginHost_, &PluginHost::paramsChanged, this, &PluginParametersWidget::computeDataModel); - connect(treeWidget_, + &_pluginHost, &PluginHost::paramsChanged, this, &PluginParametersWidget::computeDataModel); + connect(_treeWidget, &QTreeWidget::currentItemChanged, this, &PluginParametersWidget::selectionChanged); @@ -98,56 +98,56 @@ PluginParametersWidget::PluginParametersWidget(QWidget *parent, PluginHost &plug infoWidget->setFrameShape(QFrame::StyledPanel); infoWidget->setFrameShadow(QFrame::Sunken); - idLabel_ = new QLabel; - nameLabel_ = new QLabel; - moduleLabel_ = new QLabel; - isPerNoteLabel_ = new QLabel; - isPerChannelLabel_ = new QLabel; - isPeriodicLabel_ = new QLabel; - isReadOnlyLabel_ = new QLabel; - isHiddenLabel_ = new QLabel; - isBypassLabel_ = new QLabel; - isSteppedLabel_ = new QLabel; - minValueLabel_ = new QLabel; - maxValueLabel_ = new QLabel; - defaultValueLabel_ = new QLabel; - isBeingAdjusted_ = new QLabel; - - valueSlider_ = new QSlider; - valueSlider_->setMinimum(0); - valueSlider_->setMaximum(SLIDER_RANGE); - valueSlider_->setOrientation(Qt::Horizontal); - connect(valueSlider_, &QSlider::valueChanged, this, &PluginParametersWidget::sliderValueChanged); - - modulationSlider_ = new QSlider; - modulationSlider_->setMinimum(-SLIDER_RANGE); - modulationSlider_->setMaximum(SLIDER_RANGE); - modulationSlider_->setOrientation(Qt::Horizontal); - connect(modulationSlider_, &QSlider::valueChanged, this, &PluginParametersWidget::sliderModulationChanged); + _idLabel = new QLabel; + _nameLabel = new QLabel; + _moduleLabel = new QLabel; + _isPerNoteLabel = new QLabel; + _isPerChannelLabel = new QLabel; + _isPeriodicLabel = new QLabel; + _isReadOnlyLabel = new QLabel; + _isHiddenLabel = new QLabel; + _isBypassLabel = new QLabel; + _isSteppedLabel = new QLabel; + _minValueLabel = new QLabel; + _maxValueLabel = new QLabel; + _defaultValueLabel = new QLabel; + _isBeingAdjusted = new QLabel; + + _valueSlider = new QSlider; + _valueSlider->setMinimum(0); + _valueSlider->setMaximum(SLIDER_RANGE); + _valueSlider->setOrientation(Qt::Horizontal); + connect(_valueSlider, &QSlider::valueChanged, this, &PluginParametersWidget::sliderValueChanged); + + _modulationSlider = new QSlider; + _modulationSlider->setMinimum(-SLIDER_RANGE); + _modulationSlider->setMaximum(SLIDER_RANGE); + _modulationSlider->setOrientation(Qt::Horizontal); + connect(_modulationSlider, &QSlider::valueChanged, this, &PluginParametersWidget::sliderModulationChanged); auto formLayout = new QFormLayout(infoWidget); - formLayout->addRow(tr("id"), idLabel_); - formLayout->addRow(tr("name"), nameLabel_); - formLayout->addRow(tr("module"), moduleLabel_); - formLayout->addRow(tr("is_per_note"), isPerNoteLabel_); - formLayout->addRow(tr("is_per_channel"), isPerChannelLabel_); - formLayout->addRow(tr("is_periodic"), isPeriodicLabel_); - formLayout->addRow(tr("is_read_only"), isReadOnlyLabel_); - formLayout->addRow(tr("is_hidden"), isHiddenLabel_); - formLayout->addRow(tr("is_bypass"), isBypassLabel_); - formLayout->addRow(tr("is_stepped"), isSteppedLabel_); - formLayout->addRow(tr("min_value"), minValueLabel_); - formLayout->addRow(tr("max_value"), maxValueLabel_); - formLayout->addRow(tr("default_value"), defaultValueLabel_); - formLayout->addRow(tr("is_being_adjusted"), isBeingAdjusted_); - formLayout->addRow(tr("value"), valueSlider_); - formLayout->addRow(tr("modulation"), modulationSlider_); + formLayout->addRow(tr("id"), _idLabel); + formLayout->addRow(tr("name"), _nameLabel); + formLayout->addRow(tr("module"), _moduleLabel); + formLayout->addRow(tr("is_per_note"), _isPerNoteLabel); + formLayout->addRow(tr("is_per_channel"), _isPerChannelLabel); + formLayout->addRow(tr("is_periodic"), _isPeriodicLabel); + formLayout->addRow(tr("is_read_only"), _isReadOnlyLabel); + formLayout->addRow(tr("is_hidden"), _isHiddenLabel); + formLayout->addRow(tr("is_bypass"), _isBypassLabel); + formLayout->addRow(tr("is_stepped"), _isSteppedLabel); + formLayout->addRow(tr("min_value"), _minValueLabel); + formLayout->addRow(tr("max_value"), _maxValueLabel); + formLayout->addRow(tr("default_value"), _defaultValueLabel); + formLayout->addRow(tr("is_being_adjusted"), _isBeingAdjusted); + formLayout->addRow(tr("value"), _valueSlider); + formLayout->addRow(tr("modulation"), _modulationSlider); infoWidget->setLayout(formLayout); // Splitter auto splitter = new QSplitter(); - splitter->addWidget(treeWidget_); + splitter->addWidget(_treeWidget); splitter->addWidget(infoWidget); auto layout = new QHBoxLayout(this); @@ -159,22 +159,22 @@ PluginParametersWidget::PluginParametersWidget(QWidget *parent, PluginHost &plug } void PluginParametersWidget::computeDataModel() { - rootModuleItem_->clear(); - idToParamTreeItem_.clear(); + _rootModuleItem->clear(); + _idToParamTreeItem.clear(); - for (auto &it : pluginHost_.params()) { + for (auto &it : _pluginHost.params()) { auto &param = *it.second; QString path(param.info().module); auto modules = path.split("/", Qt::SkipEmptyParts); - auto module = rootModuleItem_; + auto module = _rootModuleItem; for (auto &m : modules) module = &module->subModule(m); auto item = std::make_unique<ParamTreeItem>(module, param); - idToParamTreeItem_.emplace(param.info().id, std::move(item)); + _idToParamTreeItem.emplace(param.info().id, std::move(item)); } - treeWidget_->sortItems(0, Qt::AscendingOrder); + _treeWidget->sortItems(0, Qt::AscendingOrder); } void PluginParametersWidget::selectionChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) { @@ -197,10 +197,10 @@ void PluginParametersWidget::selectionChanged(QTreeWidgetItem *current, QTreeWid } void PluginParametersWidget::connectToParam(PluginParam *param) { - if (currentParam_) + if (_currentParam) disconnectFromParam(); - currentParam_ = param; + _currentParam = param; connect(param, &PluginParam::infoChanged, this, &PluginParametersWidget::paramInfoChanged); connect(param, &PluginParam::valueChanged, this, &PluginParametersWidget::paramValueChanged); connect(param, @@ -212,14 +212,14 @@ void PluginParametersWidget::connectToParam(PluginParam *param) { } void PluginParametersWidget::disconnectFromParam() { - if (!currentParam_) + if (!_currentParam) return; disconnect( - currentParam_, &PluginParam::infoChanged, this, &PluginParametersWidget::paramInfoChanged); + _currentParam, &PluginParam::infoChanged, this, &PluginParametersWidget::paramInfoChanged); disconnect( - currentParam_, &PluginParam::valueChanged, this, &PluginParametersWidget::paramValueChanged); - disconnect(currentParam_, + _currentParam, &PluginParam::valueChanged, this, &PluginParametersWidget::paramValueChanged); + disconnect(_currentParam, &PluginParam::isBeingAdjustedChanged, this, &PluginParametersWidget::updateParamIsBeingAjustedChanged); @@ -235,73 +235,73 @@ void PluginParametersWidget::updateAll() { } void PluginParametersWidget::updateParamInfo() { - if (!currentParam_) { - idLabel_->setText("-"); - nameLabel_->setText("-"); - moduleLabel_->setText("-"); - isPerNoteLabel_->setText("-"); - isPerChannelLabel_->setText("-"); - isPeriodicLabel_->setText("-"); - isReadOnlyLabel_->setText("-"); - isHiddenLabel_->setText("-"); - isBypassLabel_->setText("-"); - isSteppedLabel_->setText("-"); - minValueLabel_->setText("-"); - maxValueLabel_->setText("-"); - defaultValueLabel_->setText("-"); - isBeingAdjusted_->setText("-"); + if (!_currentParam) { + _idLabel->setText("-"); + _nameLabel->setText("-"); + _moduleLabel->setText("-"); + _isPerNoteLabel->setText("-"); + _isPerChannelLabel->setText("-"); + _isPeriodicLabel->setText("-"); + _isReadOnlyLabel->setText("-"); + _isHiddenLabel->setText("-"); + _isBypassLabel->setText("-"); + _isSteppedLabel->setText("-"); + _minValueLabel->setText("-"); + _maxValueLabel->setText("-"); + _defaultValueLabel->setText("-"); + _isBeingAdjusted->setText("-"); } else { - auto &p = *currentParam_; + auto &p = *_currentParam; auto &i = p.info(); - idLabel_->setText(QString::number(i.id)); - nameLabel_->setText(i.name); - moduleLabel_->setText(i.module); - isPerNoteLabel_->setText(i.flags & CLAP_PARAM_IS_PER_NOTE ? "true" : "false"); - isPerChannelLabel_->setText(i.flags & CLAP_PARAM_IS_PER_CHANNEL ? "true" : "false"); - isPeriodicLabel_->setText(i.flags & CLAP_PARAM_IS_PERIODIC ? "true" : "false"); - isReadOnlyLabel_->setText(i.flags & CLAP_PARAM_IS_READONLY ? "true" : "false"); - isHiddenLabel_->setText(i.flags & CLAP_PARAM_IS_HIDDEN ? "true" : "false"); - isBypassLabel_->setText(i.flags & CLAP_PARAM_IS_BYPASS ? "true" : "false"); - isBeingAdjusted_->setText(p.isBeingAdjusted() ? "true" : "false"); - - isSteppedLabel_->setText("float"); - minValueLabel_->setText(QString::number(i.min_value)); - maxValueLabel_->setText(QString::number(i.max_value)); - defaultValueLabel_->setText(QString::number(i.default_value)); + _idLabel->setText(QString::number(i.id)); + _nameLabel->setText(i.name); + _moduleLabel->setText(i.module); + _isPerNoteLabel->setText(i.flags & CLAP_PARAM_IS_PER_NOTE ? "true" : "false"); + _isPerChannelLabel->setText(i.flags & CLAP_PARAM_IS_PER_CHANNEL ? "true" : "false"); + _isPeriodicLabel->setText(i.flags & CLAP_PARAM_IS_PERIODIC ? "true" : "false"); + _isReadOnlyLabel->setText(i.flags & CLAP_PARAM_IS_READONLY ? "true" : "false"); + _isHiddenLabel->setText(i.flags & CLAP_PARAM_IS_HIDDEN ? "true" : "false"); + _isBypassLabel->setText(i.flags & CLAP_PARAM_IS_BYPASS ? "true" : "false"); + _isBeingAdjusted->setText(p.isBeingAdjusted() ? "true" : "false"); + + _isSteppedLabel->setText("float"); + _minValueLabel->setText(QString::number(i.min_value)); + _maxValueLabel->setText(QString::number(i.max_value)); + _defaultValueLabel->setText(QString::number(i.default_value)); } } void PluginParametersWidget::updateParamIsBeingAjustedChanged() { - if (!currentParam_) { - isBeingAdjusted_->setText("-"); + if (!_currentParam) { + _isBeingAdjusted->setText("-"); } else { - auto &p = *currentParam_; - isBeingAdjusted_->setText(p.isBeingAdjusted() ? "true" : "false"); + auto &p = *_currentParam; + _isBeingAdjusted->setText(p.isBeingAdjusted() ? "true" : "false"); } } void PluginParametersWidget::updateParamValue() { - if (valueSlider_->isSliderDown()) + if (_valueSlider->isSliderDown()) return; - if (!currentParam_) + if (!_currentParam) return; - auto info = currentParam_->info(); - auto v = currentParam_->value(); - valueSlider_->setValue(SLIDER_RANGE * (v - info.min_value) / (info.max_value - info.min_value)); + auto info = _currentParam->info(); + auto v = _currentParam->value(); + _valueSlider->setValue(SLIDER_RANGE * (v - info.min_value) / (info.max_value - info.min_value)); } void PluginParametersWidget::updateParamModulation() { - if (valueSlider_->isSliderDown()) + if (_valueSlider->isSliderDown()) return; - if (!currentParam_) + if (!_currentParam) return; - auto info = currentParam_->info(); - auto v = currentParam_->value(); - valueSlider_->setValue(SLIDER_RANGE * (v - info.min_value) / (info.max_value - info.min_value)); + auto info = _currentParam->info(); + auto v = _currentParam->value(); + _valueSlider->setValue(SLIDER_RANGE * (v - info.min_value) / (info.max_value - info.min_value)); } void PluginParametersWidget::paramInfoChanged() { updateParamInfo(); } @@ -309,28 +309,28 @@ void PluginParametersWidget::paramInfoChanged() { updateParamInfo(); } void PluginParametersWidget::paramValueChanged() { updateParamValue(); } void PluginParametersWidget::sliderValueChanged(int newValue) { - if (!currentParam_) + if (!_currentParam) return; - if (!valueSlider_->isSliderDown()) + if (!_valueSlider->isSliderDown()) return; - auto &info = currentParam_->info(); + auto &info = _currentParam->info(); double value = newValue * (info.max_value - info.min_value) / SLIDER_RANGE + info.min_value; - pluginHost_.setParamValueByHost(*currentParam_, value); + _pluginHost.setParamValueByHost(*_currentParam, value); } void PluginParametersWidget::sliderModulationChanged(int newValue) { - if (!currentParam_) + if (!_currentParam) return; - if (!modulationSlider_->isSliderDown()) + if (!_modulationSlider->isSliderDown()) return; - auto &info = currentParam_->info(); + auto &info = _currentParam->info(); double dist = info.max_value - info.min_value; double value = newValue * dist / SLIDER_RANGE; - pluginHost_.setParamModulationByHost(*currentParam_, value); + _pluginHost.setParamModulationByHost(*_currentParam, value); } \ No newline at end of file diff --git a/examples/host/plugin-parameters-widget.hh b/examples/host/plugin-parameters-widget.hh @@ -25,7 +25,7 @@ public: public: ParamTreeItem(ModuleTreeItem *parent, PluginParam &param); QVariant data(int column, int role) const override; - void setData(int column, int role, const QVariant &value) override; + void setData(int column, int role, const QVariant &value) override; auto &param() { return param_; } auto &param() const { return param_; } @@ -42,13 +42,13 @@ public: void clear(); ModuleTreeItem &subModule(const QString &name); - void addItem(ParamTreeItem *item); + void addItem(ParamTreeItem *item); QVariant data(int column, int role) const override; - void setData(int column, int role, const QVariant &value) override; + void setData(int column, int role, const QVariant &value) override; private: - QString name_; + QString name_; QHash<QString, ModuleTreeItem *> modules_; }; @@ -74,26 +74,26 @@ private: static const constexpr int SLIDER_RANGE = 10000; - PluginHost & pluginHost_; - QTreeWidget * treeWidget_ = nullptr; - std::unordered_map<clap_id, std::unique_ptr<ParamTreeItem>> idToParamTreeItem_; - ModuleTreeItem * rootModuleItem_; - PluginParam * currentParam_ = nullptr; - - QLabel * idLabel_ = nullptr; - QLabel * nameLabel_ = nullptr; - QLabel * moduleLabel_ = nullptr; - QLabel * isPerNoteLabel_ = nullptr; - QLabel * isPerChannelLabel_ = nullptr; - QLabel * isPeriodicLabel_ = nullptr; - QLabel * isReadOnlyLabel_ = nullptr; - QLabel * isHiddenLabel_ = nullptr; - QLabel * isBypassLabel_ = nullptr; - QLabel * isSteppedLabel_ = nullptr; - QLabel * minValueLabel_ = nullptr; - QLabel * maxValueLabel_ = nullptr; - QLabel * defaultValueLabel_ = nullptr; - QLabel * isBeingAdjusted_ = nullptr; - QSlider *valueSlider_ = nullptr; - QSlider *modulationSlider_ = nullptr; + PluginHost &_pluginHost; + QTreeWidget *_treeWidget = nullptr; + std::unordered_map<clap_id, std::unique_ptr<ParamTreeItem>> _idToParamTreeItem; + ModuleTreeItem *_rootModuleItem; + PluginParam *_currentParam = nullptr; + + QLabel *_idLabel = nullptr; + QLabel *_nameLabel = nullptr; + QLabel *_moduleLabel = nullptr; + QLabel *_isPerNoteLabel = nullptr; + QLabel *_isPerChannelLabel = nullptr; + QLabel *_isPeriodicLabel = nullptr; + QLabel *_isReadOnlyLabel = nullptr; + QLabel *_isHiddenLabel = nullptr; + QLabel *_isBypassLabel = nullptr; + QLabel *_isSteppedLabel = nullptr; + QLabel *_minValueLabel = nullptr; + QLabel *_maxValueLabel = nullptr; + QLabel *_defaultValueLabel = nullptr; + QLabel *_isBeingAdjusted = nullptr; + QSlider *_valueSlider = nullptr; + QSlider *_modulationSlider = nullptr; }; diff --git a/examples/host/plugin-quick-control-widget.cc b/examples/host/plugin-quick-control-widget.cc @@ -8,44 +8,44 @@ PluginQuickControlWidget::PluginQuickControlWidget(QWidget *parent, PluginHost &pluginHost) : QWidget(parent), pluginHost_(pluginHost) { - dial_ = new QDial(this); - label_ = new QLabel(this); + _dial = new QDial(this); + _label = new QLabel(this); auto layout = new QVBoxLayout(this); - layout->addWidget(dial_); - layout->addWidget(label_); + layout->addWidget(_dial); + layout->addWidget(_label); setLayout(layout); setPluginParam(nullptr); } void PluginQuickControlWidget::setPluginParam(PluginParam *param) { - if (param_ == param) + if (_param == param) return; - if (param_) + if (_param) disconnectFromParam(); - Q_ASSERT(!param_); + Q_ASSERT(!_param); connectToParam(param); } void PluginQuickControlWidget::connectToParam(PluginParam *param) { - Q_ASSERT(!param_); + Q_ASSERT(!_param); - param_ = param; - connect(param_, &PluginParam::infoChanged, this, &PluginQuickControlWidget::paramInfoChanged); - connect(param_, &PluginParam::valueChanged, this, &PluginQuickControlWidget::paramValueChanged); + _param = param; + connect(_param, &PluginParam::infoChanged, this, &PluginQuickControlWidget::paramInfoChanged); + connect(_param, &PluginParam::valueChanged, this, &PluginQuickControlWidget::paramValueChanged); updateAll(); } void PluginQuickControlWidget::disconnectFromParam() { - Q_ASSERT(param_); + Q_ASSERT(_param); - disconnect(param_, &PluginParam::infoChanged, this, &PluginQuickControlWidget::paramInfoChanged); + disconnect(_param, &PluginParam::infoChanged, this, &PluginQuickControlWidget::paramInfoChanged); disconnect( - param_, &PluginParam::valueChanged, this, &PluginQuickControlWidget::paramValueChanged); + _param, &PluginParam::valueChanged, this, &PluginQuickControlWidget::paramValueChanged); updateAll(); } @@ -55,31 +55,31 @@ void PluginQuickControlWidget::paramInfoChanged() { updateParamInfo(); } void PluginQuickControlWidget::paramValueChanged() { updateParamValue(); } void PluginQuickControlWidget::dialValueChanged(int newValue) { - if (!param_) + if (!_param) return; - if (!dial_->isSliderDown()) + if (!_dial->isSliderDown()) return; - auto &info = param_->info(); + auto &info = _param->info(); double value = newValue * (info.max_value - info.min_value) / DIAL_RANGE + info.min_value; - pluginHost_.setParamValueByHost(*param_, value); + pluginHost_.setParamValueByHost(*_param, value); } void PluginQuickControlWidget::updateParamValue() { - if (!param_) + if (!_param) return; - if (dial_->isSliderDown()) + if (_dial->isSliderDown()) return; - auto info = param_->info(); - auto v = param_->value(); - dial_->setValue(DIAL_RANGE * (v - info.min_value) / (info.max_value - info.min_value)); + auto info = _param->info(); + auto v = _param->value(); + _dial->setValue(DIAL_RANGE * (v - info.min_value) / (info.max_value - info.min_value)); } void PluginQuickControlWidget::updateParamInfo() { - label_->setText(param_ ? param_->info().name : "-"); + _label->setText(_param ? _param->info().name : "-"); } void PluginQuickControlWidget::updateAll() { diff --git a/examples/host/plugin-quick-control-widget.hh b/examples/host/plugin-quick-control-widget.hh @@ -32,7 +32,7 @@ private: PluginHost &pluginHost_; - QDial * dial_ = nullptr; - QLabel * label_ = nullptr; - PluginParam *param_ = nullptr; + QDial *_dial = nullptr; + QLabel *_label = nullptr; + PluginParam *_param = nullptr; }; \ No newline at end of file diff --git a/examples/host/plugin-quick-controls-widget.cc b/examples/host/plugin-quick-controls-widget.cc @@ -7,14 +7,14 @@ #include "plugin-quick-controls-widget.hh" PluginQuickControlsWidget::PluginQuickControlsWidget(QWidget *parent, PluginHost &pluginHost) - : QWidget(parent), pluginHost_(pluginHost) { - chooser_ = new QComboBox(this); - connect(chooser_, + : QWidget(parent), _pluginHost(pluginHost) { + _chooser = new QComboBox(this); + connect(_chooser, &QComboBox::activated, this, &PluginQuickControlsWidget::selectPageFromChooser); - for (auto &qc : controls_) + for (auto &qc : _controls) qc = new PluginQuickControlWidget(this, pluginHost); auto grid = new QGridLayout(); @@ -22,28 +22,28 @@ PluginQuickControlsWidget::PluginQuickControlsWidget(QWidget *parent, PluginHost const auto rowSize = CLAP_QUICK_CONTROLS_COUNT / 2; for (int i = 0; i < CLAP_QUICK_CONTROLS_COUNT; ++i) - grid->addWidget(controls_[i], i / rowSize, i % rowSize); + grid->addWidget(_controls[i], i / rowSize, i % rowSize); auto vbox = new QVBoxLayout(); - vbox->addWidget(chooser_); + vbox->addWidget(_chooser); vbox->addLayout(grid); vbox->setSpacing(3); setLayout(vbox); } void PluginQuickControlsWidget::pagesChanged() { - auto &pages = pluginHost_.quickControlsPages(); - chooser_->clear(); + auto &pages = _pluginHost.quickControlsPages(); + _chooser->clear(); for (auto &it : pages) - chooser_->addItem(it.second->name, it.second->id); + _chooser->addItem(it.second->name, it.second->id); selectedPageChanged(); } void PluginQuickControlsWidget::selectedPageChanged() { - auto pageId = pluginHost_.quickControlsSelectedPage(); - auto &pages = pluginHost_.quickControlsPages(); - auto &params = pluginHost_.params(); + auto pageId = _pluginHost.quickControlsSelectedPage(); + auto &pages = _pluginHost.quickControlsPages(); + auto &params = _pluginHost.params(); auto it = pages.find(pageId); for (int i = 0; i < CLAP_QUICK_CONTROLS_COUNT; ++i) { @@ -56,11 +56,11 @@ void PluginQuickControlsWidget::selectedPageChanged() { param = paramIt->second.get(); } - controls_[i]->setPluginParam(param); + _controls[i]->setPluginParam(param); } } void PluginQuickControlsWidget::selectPageFromChooser(int index) { - clap_id pageId = chooser_->currentData().toUInt(); - pluginHost_.setQuickControlsSelectedPageByHost(pageId); + clap_id pageId = _chooser->currentData().toUInt(); + _pluginHost.setQuickControlsSelectedPageByHost(pageId); } diff --git a/examples/host/plugin-quick-controls-widget.hh b/examples/host/plugin-quick-controls-widget.hh @@ -19,8 +19,8 @@ public: private: void selectPageFromChooser(int index); - PluginHost &pluginHost_; + PluginHost &_pluginHost; - QComboBox *chooser_ = nullptr; - std::array<PluginQuickControlWidget *, CLAP_QUICK_CONTROLS_COUNT> controls_; + QComboBox *_chooser = nullptr; + std::array<PluginQuickControlWidget *, CLAP_QUICK_CONTROLS_COUNT> _controls; }; \ No newline at end of file diff --git a/examples/host/settings-dialog.cc b/examples/host/settings-dialog.cc @@ -7,13 +7,13 @@ #include "settings-dialog.hh" SettingsDialog::SettingsDialog(Settings &settings, QWidget *parent) - : QDialog(parent), settings_(settings) { + : QDialog(parent), _settings(settings) { setModal(true); setWindowTitle(tr("Settings")); QVBoxLayout *vbox = new QVBoxLayout(); - settingsWidget_ = new SettingsWidget(settings); - vbox->addWidget(settingsWidget_); + _settingsWidget = new SettingsWidget(settings); + vbox->addWidget(_settingsWidget); auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); buttons->show(); diff --git a/examples/host/settings-dialog.hh b/examples/host/settings-dialog.hh @@ -10,6 +10,6 @@ public: SettingsDialog(Settings &settings, QWidget *parent = nullptr); private: - Settings & settings_; - SettingsWidget *settingsWidget_ = nullptr; + Settings &_settings; + SettingsWidget *_settingsWidget = nullptr; }; diff --git a/examples/host/settings-widget.cc b/examples/host/settings-widget.cc @@ -6,14 +6,14 @@ #include "settings-widget.hh" #include "settings.hh" -SettingsWidget::SettingsWidget(Settings &settings) : settings_(settings) { +SettingsWidget::SettingsWidget(Settings &settings) : _settings(settings) { QVBoxLayout *layout = new QVBoxLayout(); - audioSettingsWidget_ = new AudioSettingsWidget(settings.audioSettings()); - layout->addWidget(audioSettingsWidget_); + _audioSettingsWidget = new AudioSettingsWidget(settings.audioSettings()); + layout->addWidget(_audioSettingsWidget); - midiSettingsWidget_ = new MidiSettingsWidget(settings.midiSettings()); - layout->addWidget(midiSettingsWidget_); + _midiSettingsWidget = new MidiSettingsWidget(settings.midiSettings()); + layout->addWidget(_midiSettingsWidget); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); setLayout(layout); diff --git a/examples/host/settings-widget.hh b/examples/host/settings-widget.hh @@ -12,13 +12,9 @@ class SettingsWidget : public QWidget { public: explicit SettingsWidget(Settings &settings); -signals: - -public slots: - private: - QTabWidget * tabWidget_ = nullptr; - AudioSettingsWidget *audioSettingsWidget_ = nullptr; - MidiSettingsWidget * midiSettingsWidget_ = nullptr; - Settings & settings_; + QTabWidget *_tabWidget = nullptr; + AudioSettingsWidget *_audioSettingsWidget = nullptr; + MidiSettingsWidget *_midiSettingsWidget = nullptr; + Settings &_settings; }; diff --git a/examples/host/settings.cc b/examples/host/settings.cc @@ -3,11 +3,11 @@ Settings::Settings() {} void Settings::load(QSettings &settings) { - audioSettings_.load(settings); - midiSettings_.load(settings); + _audioSettings.load(settings); + _midiSettings.load(settings); } void Settings::save(QSettings &settings) const { - audioSettings_.save(settings); - midiSettings_.save(settings); + _audioSettings.save(settings); + _midiSettings.save(settings); } diff --git a/examples/host/settings.hh b/examples/host/settings.hh @@ -12,10 +12,10 @@ public: void load(QSettings &settings); void save(QSettings &settings) const; - AudioSettings &audioSettings() { return audioSettings_; } - MidiSettings & midiSettings() { return midiSettings_; } + AudioSettings &audioSettings() { return _audioSettings; } + MidiSettings & midiSettings() { return _midiSettings; } private: - AudioSettings audioSettings_; - MidiSettings midiSettings_; + AudioSettings _audioSettings; + MidiSettings _midiSettings; }; diff --git a/examples/io/buffer.hh b/examples/io/buffer.hh @@ -16,21 +16,21 @@ namespace clap { Buffer<T, CAPACITY> &operator=(const Buffer<T, CAPACITY> &) = delete; Buffer<T, CAPACITY> &operator=(Buffer<T, CAPACITY> &&) = delete; - const T *readPtr() const noexcept { return &data_[roff_]; } - size_t readAvail() const noexcept { return woff_ - roff_; } + const T *readPtr() const noexcept { return &_data[_roff]; } + size_t readAvail() const noexcept { return _woff - _roff; } - T *writePtr() noexcept { return &data_[woff_]; } - size_t writeAvail() const noexcept { return CAPACITY - woff_; } + T *writePtr() noexcept { return &_data[_woff]; } + size_t writeAvail() const noexcept { return CAPACITY - _woff; } /* Consume nbytes from the buffer */ void read(size_t nbytes) noexcept { - roff_ += nbytes; + _roff += nbytes; assert(checkInvariants()); } /* Produce nbytes into the buffer */ void wrote(size_t nbytes) noexcept { - woff_ += nbytes; + _woff += nbytes; assert(checkInvariants()); } @@ -45,17 +45,17 @@ namespace clap { } void rewind() noexcept { - if (woff_ == 0) + if (_woff == 0) return; // this is inefficient but simple // TODO: use scatter/gather IO auto rptr = readPtr(); auto avail = readAvail(); - std::copy(rptr, rptr + avail, &data_[0]); + std::copy(rptr, rptr + avail, &_data[0]); - woff_ -= roff_; - roff_ = 0; + _woff -= _roff; + _roff = 0; assert(checkInvariants()); } @@ -63,14 +63,14 @@ namespace clap { private: #ifndef NDEBUG bool checkInvariants() const noexcept { - assert(woff_ <= data_.size()); - assert(roff_ <= woff_); + assert(_woff <= _data.size()); + assert(_roff <= _woff); return true; } #endif - std::array<T, CAPACITY> data_; - size_t roff_ = 0; - size_t woff_ = 0; + std::array<T, CAPACITY> _data; + size_t _roff = 0; + size_t _woff = 0; }; } // namespace clap \ No newline at end of file diff --git a/examples/io/remote-channel.cc b/examples/io/remote-channel.cc @@ -13,17 +13,17 @@ namespace clap { EventControl &evControl, int socket, bool cookieHalf) - : cookieHalf_(cookieHalf), handler_(handler), evControl_(evControl), socket_(socket) { + : _cookieHalf(cookieHalf), _handler(handler), _evControl(evControl), _socket(socket) { #ifdef __unix__ - int flags = ::fcntl(socket_, F_GETFL); - ::fcntl(socket_, F_SETFL, flags | O_NONBLOCK); + int flags = ::fcntl(_socket, F_GETFL); + ::fcntl(_socket, F_SETFL, flags | O_NONBLOCK); #endif } RemoteChannel::~RemoteChannel() { close(); } void RemoteChannel::onRead() { - ssize_t nbytes = ::read(socket_, inputBuffer_.writePtr(), inputBuffer_.writeAvail()); + ssize_t nbytes = ::read(_socket, _inputBuffer.writePtr(), _inputBuffer.writeAvail()); if (nbytes < 0) { if (errno == EWOULDBLOCK || errno == EAGAIN || errno == EINTR) return; @@ -35,9 +35,9 @@ namespace clap { if (nbytes == 0) return; - inputBuffer_.wrote(nbytes); + _inputBuffer.wrote(nbytes); processInput(); - inputBuffer_.rewind(); + _inputBuffer.rewind(); } void RemoteChannel::write(const void *_data, size_t size) { @@ -51,25 +51,25 @@ namespace clap { } RemoteChannel::WriteBuffer &RemoteChannel::nextWriteBuffer() { - if (outputBuffers_.empty()) { - outputBuffers_.emplace(); - return outputBuffers_.back(); + if (_outputBuffers.empty()) { + _outputBuffers.emplace(); + return _outputBuffers.back(); } - auto &buffer = outputBuffers_.back(); + auto &buffer = _outputBuffers.back(); if (buffer.writeAvail() > 0) return buffer; - outputBuffers_.emplace(); - return outputBuffers_.back(); + _outputBuffers.emplace(); + return _outputBuffers.back(); } void RemoteChannel::onWrite() { - while (!outputBuffers_.empty()) { - auto &buffer = outputBuffers_.front(); + while (!_outputBuffers.empty()) { + auto &buffer = _outputBuffers.front(); for (auto avail = buffer.readAvail(); avail > 0; avail = buffer.readAvail()) { - auto nbytes = ::write(socket_, buffer.readPtr(), avail); + auto nbytes = ::write(_socket, buffer.readPtr(), avail); if (nbytes == -1) { if (errno == EWOULDBLOCK || errno == EAGAIN || errno == EINTR) { modifyFd(CLAP_FD_READ | CLAP_FD_WRITE); @@ -83,7 +83,7 @@ namespace clap { buffer.read(nbytes); } - outputBuffers_.pop(); + _outputBuffers.pop(); } modifyFd(CLAP_FD_READ); @@ -92,29 +92,29 @@ namespace clap { void RemoteChannel::onError() { close(); } void RemoteChannel::close() { - if (socket_ == -1) + if (_socket == -1) return; - evControl_.removeFd(); + _evControl.removeFd(); - ::close(socket_); - socket_ = -1; + ::close(_socket); + _socket = -1; } uint32_t RemoteChannel::computeNextCookie() noexcept { - uint32_t cookie = nextCookie_; - if (cookieHalf_) + uint32_t cookie = _nextCookie; + if (_cookieHalf) cookie |= (1ULL << 31); else cookie &= ~(1ULL << 31); - ++nextCookie_; // overflow is fine + ++_nextCookie; // overflow is fine return cookie; } void RemoteChannel::processInput() { - while (inputBuffer_.readAvail() >= 12) { - const auto *data = inputBuffer_.readPtr(); + while (_inputBuffer.readAvail() >= 12) { + const auto *data = _inputBuffer.readPtr(); Message msg; std::memcpy(&msg.type, data, 4); @@ -123,18 +123,18 @@ namespace clap { msg.data = data + 12; uint32_t totalSize = 12 + msg.size; - if (inputBuffer_.readAvail() < totalSize) + if (_inputBuffer.readAvail() < totalSize) return; - auto it = syncHandlers_.find(msg.cookie); - if (it != syncHandlers_.end()) { + auto it = _syncHandlers.find(msg.cookie); + if (it != _syncHandlers.end()) { it->second(msg); - syncHandlers_.erase(it); + _syncHandlers.erase(it); } else { - handler_(msg); + _handler(msg); } - inputBuffer_.read(totalSize); + _inputBuffer.read(totalSize); } } @@ -150,21 +150,21 @@ namespace clap { bool RemoteChannel::sendMessageSync(const Message &msg, const MessageHandler &handler) { sendMessageAsync(msg); - syncHandlers_.emplace(msg.cookie, handler); + _syncHandlers.emplace(msg.cookie, handler); - while (syncHandlers_.count(msg.cookie) > 0) + while (_syncHandlers.count(msg.cookie) > 0) runOnce(); - syncHandlers_.erase(msg.cookie); + _syncHandlers.erase(msg.cookie); return true; } void RemoteChannel::modifyFd(clap_fd_flags flags) { - if (flags == ioFlags_) + if (flags == _ioFlags) return; - ioFlags_ = flags; - evControl_.modifyFd(flags); + _ioFlags = flags; + _evControl.modifyFd(flags); } void RemoteChannel::runOnce() { @@ -173,8 +173,8 @@ namespace clap { #ifdef __unix__ pollfd pfd; - pfd.fd = socket_; - pfd.events = POLLIN | (ioFlags_ & CLAP_FD_WRITE ? POLLOUT : 0); + pfd.fd = _socket; + pfd.events = POLLIN | (_ioFlags & CLAP_FD_WRITE ? POLLOUT : 0); pfd.revents = 0; int ret = ::poll(&pfd, 1, -1); diff --git a/examples/io/remote-channel.hh b/examples/io/remote-channel.hh @@ -103,8 +103,8 @@ namespace clap { void runOnce(); - clap_fd fd() const { return socket_; } - bool isOpen() const noexcept { return socket_ != -1; } + clap_fd fd() const { return _socket; } + bool isOpen() const noexcept { return _socket != -1; } private: using ReadBuffer = Buffer<uint8_t, 128 * 1024>; @@ -120,16 +120,16 @@ namespace clap { bool sendMessageAsync(const Message &msg); bool sendMessageSync(const Message &msg, const MessageHandler &handler); - const bool cookieHalf_; - uint32_t nextCookie_ = 0; + const bool _cookieHalf; + uint32_t _nextCookie = 0; - MessageHandler handler_; - std::unordered_map<uint32_t /* cookie */, const MessageHandler &> syncHandlers_; - EventControl &evControl_; - clap_fd socket_; - clap_fd_flags ioFlags_ = 0; + MessageHandler _handler; + std::unordered_map<uint32_t /* cookie */, const MessageHandler &> _syncHandlers; + EventControl &_evControl; + clap_fd _socket; + clap_fd_flags _ioFlags = 0; - ReadBuffer inputBuffer_; - std::queue<WriteBuffer> outputBuffers_; + ReadBuffer _inputBuffer; + std::queue<WriteBuffer> _outputBuffers; }; } // namespace clap \ No newline at end of file diff --git a/examples/plugins/abstract-gui.hh b/examples/plugins/abstract-gui.hh @@ -7,7 +7,7 @@ namespace clap { class CorePlugin; class AbstractGui { public: - AbstractGui(CorePlugin &plugin) : plugin_(plugin) {} + AbstractGui(CorePlugin &plugin) : _plugin(plugin) {} virtual ~AbstractGui() = default; virtual void defineParameter(const clap_param_info&) noexcept = 0; @@ -25,7 +25,7 @@ namespace clap { virtual void destroy() noexcept = 0; protected: - CorePlugin &plugin_; + CorePlugin &_plugin; }; } // namespace clap \ No newline at end of file diff --git a/examples/plugins/core-plugin.cc b/examples/plugins/core-plugin.cc @@ -11,7 +11,7 @@ namespace clap { CorePlugin::CorePlugin(std::unique_ptr<PathProvider> &&pathProvider, const clap_plugin_descriptor *desc, const clap_host *host) - : Plugin(desc, host), pathProvider_(std::move(pathProvider)) {} + : Plugin(desc, host), _pathProvider(std::move(pathProvider)) {} bool CorePlugin::init() noexcept { initTrackInfo(); @@ -21,42 +21,42 @@ namespace clap { void CorePlugin::initTrackInfo() noexcept { checkMainThread(); - assert(!hasTrackInfo_); + assert(!_hasTrackInfo); if (!canUseTrackInfo()) return; - hasTrackInfo_ = hostTrackInfo_->get(host_, &trackInfo_); + _hasTrackInfo = _hostTrackInfo->get(_host, &_trackInfo); } void CorePlugin::trackInfoChanged() noexcept { - if (!hostTrackInfo_->get(host_, &trackInfo_)) { - hasTrackInfo_ = false; + if (!_hostTrackInfo->get(_host, &_trackInfo)) { + _hasTrackInfo = false; hostMisbehaving( "clap_host_track_info.get() failed after calling clap_plugin_track_info.changed()"); return; } - hasTrackInfo_ = true; + _hasTrackInfo = true; } bool CorePlugin::implementsAudioPorts() const noexcept { return true; } uint32_t CorePlugin::audioPortsCount(bool is_input) const noexcept { - return is_input ? audioInputs_.size() : audioOutputs_.size(); + return is_input ? _audioInputs.size() : _audioOutputs.size(); } bool CorePlugin::audioPortsInfo(uint32_t index, bool is_input, clap_audio_port_info *info) const noexcept { - *info = is_input ? audioInputs_[index] : audioOutputs_[index]; + *info = is_input ? _audioInputs[index] : _audioOutputs[index]; return true; } - uint32_t CorePlugin::audioPortsConfigCount() const noexcept { return audioConfigs_.size(); } + uint32_t CorePlugin::audioPortsConfigCount() const noexcept { return _audioConfigs.size(); } bool CorePlugin::audioPortsGetConfig(uint32_t index, clap_audio_ports_config *config) const noexcept { - *config = audioConfigs_[index]; + *config = _audioConfigs[index]; return true; } @@ -66,7 +66,7 @@ namespace clap { try { OStream os(stream); boost::archive::text_oarchive ar(os); - ar << parameters_; + ar << _parameters; } catch (...) { return false; } @@ -77,7 +77,7 @@ namespace clap { try { IStream is(stream); boost::archive::text_iarchive ar(is); - ar >> parameters_; + ar >> _parameters; } catch (...) { return false; } @@ -85,14 +85,14 @@ namespace clap { } bool CorePlugin::guiCreate() noexcept { - remoteGui_.reset(new RemoteGui(*this)); + _remoteGui.reset(new RemoteGui(*this)); - if (!remoteGui_->spawn()) { - remoteGui_.reset(); + if (!_remoteGui->spawn()) { + _remoteGui.reset(); return false; } - if (!remoteGui_) + if (!_remoteGui) return false; guiDefineParameters(); @@ -103,64 +103,64 @@ namespace clap { for (int i = 0; i < paramsCount(); ++i) { clap_param_info info; paramsInfo(i, &info); - remoteGui_->defineParameter(info); + _remoteGui->defineParameter(info); } } void CorePlugin::guiDestroy() noexcept { - if (remoteGui_) - remoteGui_.reset(); + if (_remoteGui) + _remoteGui.reset(); } bool CorePlugin::guiSize(uint32_t *width, uint32_t *height) noexcept { - if (!remoteGui_) + if (!_remoteGui) return false; - return remoteGui_->size(width, height); + return _remoteGui->size(width, height); } void CorePlugin::guiSetScale(double scale) noexcept { - if (remoteGui_) - remoteGui_->setScale(scale); + if (_remoteGui) + _remoteGui->setScale(scale); } void CorePlugin::guiShow() noexcept { - if (remoteGui_) - remoteGui_->show(); + if (_remoteGui) + _remoteGui->show(); } void CorePlugin::guiHide() noexcept { - if (remoteGui_) - remoteGui_->hide(); + if (_remoteGui) + _remoteGui->hide(); } void CorePlugin::onFd(clap_fd fd, uint32_t flags) noexcept { - if (remoteGui_ && fd == remoteGui_->fd()) - remoteGui_->onFd(flags); + if (_remoteGui && fd == _remoteGui->fd()) + _remoteGui->onFd(flags); } void CorePlugin::onTimer(clap_id timerId) noexcept { - if (remoteGui_ && timerId == remoteGui_->timerId()) - remoteGui_->onTimer(); + if (_remoteGui && timerId == _remoteGui->timerId()) + _remoteGui->onTimer(); } bool CorePlugin::guiX11Attach(const char *displayName, unsigned long window) noexcept { - if (remoteGui_) - return remoteGui_->attachX11(displayName, window); + if (_remoteGui) + return _remoteGui->attachX11(displayName, window); return false; } bool CorePlugin::guiWin32Attach(clap_hwnd window) noexcept { - if (remoteGui_) - return remoteGui_->attachWin32(window); + if (_remoteGui) + return _remoteGui->attachWin32(window); return false; } bool CorePlugin::guiCocoaAttach(void *nsView) noexcept { - if (remoteGui_) - return remoteGui_->attachCocoa(nsView); + if (_remoteGui) + return _remoteGui->attachCocoa(nsView); return false; } @@ -171,13 +171,13 @@ namespace clap { } void CorePlugin::guiAdjust(clap_id paramId, double value, clap_event_param_flags flags) { - guiToPluginQueue_.set(paramId, {value, flags}); - guiToPluginQueue_.producerDone(); + _guiToPluginQueue.set(paramId, {value, flags}); + _guiToPluginQueue.producerDone(); } void CorePlugin::processGuiEvents(const clap_process *process) { - guiToPluginQueue_.consume([this, process](clap_id paramId, const GuiToPluginValue &value) { - auto p = parameters_.getById(paramId); + _guiToPluginQueue.consume([this, process](clap_id paramId, const GuiToPluginValue &value) { + auto p = _parameters.getById(paramId); if (!p) return; p->setValueSmoothed(value.value, 128); @@ -224,9 +224,9 @@ namespace clap { std::terminate(); } - p->setValueSmoothed(ev->param_value.value, paramSmoothingDuration_); + p->setValueSmoothed(ev->param_value.value, _paramSmoothingDuration); //p->setValueImmediately(ev->param_value.value); - pluginToGuiQueue_.set(p->info().id, {ev->param_value.value, p->modulation()}); + _pluginToGuiQueue.set(p->info().id, {ev->param_value.value, p->modulation()}); } break; } @@ -241,8 +241,8 @@ namespace clap { std::terminate(); } - p->setModulationSmoothed(ev->param_mod.amount, paramSmoothingDuration_); - pluginToGuiQueue_.set(p->info().id, {p->value(), ev->param_mod.amount}); + p->setModulationSmoothed(ev->param_mod.amount, _paramSmoothingDuration); + _pluginToGuiQueue.set(p->info().id, {p->value(), ev->param_mod.amount}); } break; } diff --git a/examples/plugins/core-plugin.hh b/examples/plugins/core-plugin.hh @@ -17,7 +17,7 @@ namespace clap { const clap_plugin_descriptor *desc, const clap_host *host); - const PathProvider &pathProvider() const noexcept { return *pathProvider_; } + const PathProvider &pathProvider() const noexcept { return *_pathProvider; } protected: //-------------// @@ -50,15 +50,15 @@ namespace clap { //--------------------// bool implementsParams() const noexcept override { return true; } - uint32_t paramsCount() const noexcept override { return parameters_.count(); } + uint32_t paramsCount() const noexcept override { return _parameters.count(); } bool paramsInfo(int32_t paramIndex, clap_param_info *info) const noexcept override { - *info = parameters_.getByIndex(paramIndex)->info(); + *info = _parameters.getByIndex(paramIndex)->info(); return true; } virtual bool paramsValue(clap_id paramId, double *value) noexcept override { - *value = parameters_.getById(paramId)->value(); + *value = _parameters.getById(paramId)->value(); return true; } @@ -126,16 +126,16 @@ namespace clap { ////////////////////// // Cached Host Info // ////////////////////// - bool hasTrackInfo() const noexcept { return hasTrackInfo_; } + bool hasTrackInfo() const noexcept { return _hasTrackInfo; } const clap_track_info &trackInfo() const noexcept { - assert(hasTrackInfo_); - return trackInfo_; + assert(_hasTrackInfo); + return _trackInfo; } uint32_t trackChannelCount() const noexcept { - return hasTrackInfo_ ? trackInfo_.channel_count : 2; + return _hasTrackInfo ? _trackInfo.channel_count : 2; } clap_chmap trackChannelMap() const noexcept { - return hasTrackInfo_ ? trackInfo_.channel_map : CLAP_CHMAP_STEREO; + return _hasTrackInfo ? _trackInfo.channel_map : CLAP_CHMAP_STEREO; } //---------------------------// @@ -168,22 +168,22 @@ namespace clap { double mod; }; - ParamQueue<GuiToPluginValue> guiToPluginQueue_; - ParamQueue<PluginToGuiValue> pluginToGuiQueue_; + ParamQueue<GuiToPluginValue> _guiToPluginQueue; + ParamQueue<PluginToGuiValue> _pluginToGuiQueue; - std::unique_ptr<PathProvider> pathProvider_; + std::unique_ptr<PathProvider> _pathProvider; - bool hasTrackInfo_ = false; - clap_track_info trackInfo_; + bool _hasTrackInfo = false; + clap_track_info _trackInfo; - std::vector<clap_audio_port_info> audioInputs_; - std::vector<clap_audio_port_info> audioOutputs_; - std::vector<clap_audio_ports_config> audioConfigs_; + std::vector<clap_audio_port_info> _audioInputs; + std::vector<clap_audio_port_info> _audioOutputs; + std::vector<clap_audio_ports_config> _audioConfigs; - std::unique_ptr<RemoteGui> remoteGui_; + std::unique_ptr<RemoteGui> _remoteGui; - Parameters parameters_; + Parameters _parameters; - static const constexpr uint32_t paramSmoothingDuration_ = 64; + static const constexpr uint32_t _paramSmoothingDuration = 64; }; } // namespace clap \ No newline at end of file diff --git a/examples/plugins/dc-offset/dc-offset.cc b/examples/plugins/dc-offset/dc-offset.cc @@ -29,7 +29,7 @@ namespace clap { DcOffset::DcOffset(const std::string &pluginPath, const clap_host *host) : CorePlugin(PathProvider::create(pluginPath, "dc-offset"), descriptor(), host) { - parameters_.addParameter(clap_param_info{ + _parameters.addParameter(clap_param_info{ kParamIdOffset, 0, nullptr, @@ -40,7 +40,7 @@ namespace clap { 0, }); - offsetParam_ = parameters_.getById(kParamIdOffset); + _offsetParam = _parameters.getById(kParamIdOffset); } bool DcOffset::init() noexcept { @@ -54,7 +54,7 @@ namespace clap { void DcOffset::defineAudioPorts() noexcept { assert(!isActive()); - channelCount_ = trackChannelCount(); + _channelCount = trackChannelCount(); clap_audio_port_info info; info.id = 0; @@ -63,13 +63,13 @@ namespace clap { info.is_cv = false; info.sample_size = 32; info.in_place = true; - info.channel_count = channelCount_; + info.channel_count = _channelCount; info.channel_map = CLAP_CHMAP_UNSPECIFIED; - audioInputs_.clear(); - audioInputs_.push_back(info); - audioOutputs_.clear(); - audioOutputs_.push_back(info); + _audioInputs.clear(); + _audioInputs.push_back(info); + _audioOutputs.clear(); + _audioOutputs.push_back(info); } clap_process_status DcOffset::process(const clap_process *process) noexcept { @@ -88,13 +88,13 @@ namespace clap { /* Process as many samples as possible until the next event */ for (; i < N; ++i) { - const float offset = offsetParam_->step(); - for (int c = 0; c < channelCount_; ++c) + const float offset = _offsetParam->step(); + for (int c = 0; c < _channelCount; ++c) out[c][i] = in[c][i] + offset; } } - pluginToGuiQueue_.producerDone(); + _pluginToGuiQueue.producerDone(); return CLAP_PROCESS_CONTINUE_IF_NOT_QUIET; } diff --git a/examples/plugins/dc-offset/dc-offset.hh b/examples/plugins/dc-offset/dc-offset.hh @@ -18,7 +18,7 @@ namespace clap { clap_process_status process(const clap_process *process) noexcept override; private: - int channelCount_ = 2; - Parameter *offsetParam_ = nullptr; + int _channelCount = 2; + Parameter *_offsetParam = nullptr; }; } // namespace clap \ No newline at end of file diff --git a/examples/plugins/gain/gain.cc b/examples/plugins/gain/gain.cc @@ -28,7 +28,7 @@ namespace clap { Gain::Gain(const std::string &pluginPath, const clap_host *host) : CorePlugin(PathProvider::create(pluginPath, "gain"), descriptor(), host) { - parameters_.addParameter(clap_param_info{ + _parameters.addParameter(clap_param_info{ kParamIdGain, 0, nullptr, @@ -51,7 +51,7 @@ namespace clap { void Gain::defineAudioPorts() noexcept { assert(!isActive()); - channelCount_ = trackChannelCount(); + _channelCount = trackChannelCount(); clap_audio_port_info info; info.id = 0; @@ -60,16 +60,16 @@ namespace clap { info.is_cv = false; info.sample_size = 32; info.in_place = true; - info.channel_count = channelCount_; + info.channel_count = _channelCount; info.channel_map = CLAP_CHMAP_UNSPECIFIED; - audioInputs_.clear(); - audioInputs_.push_back(info); - audioOutputs_.clear(); - audioOutputs_.push_back(info); + _audioInputs.clear(); + _audioInputs.push_back(info); + _audioOutputs.clear(); + _audioOutputs.push_back(info); } - void Gain::deactivate() noexcept { channelCount_ = 0; } + void Gain::deactivate() noexcept { _channelCount = 0; } clap_process_status Gain::process(const clap_process *process) noexcept { float **in = process->audio_inputs[0].data32; @@ -77,7 +77,7 @@ namespace clap { float k = 1; for (int i = 0; i < process->frames_count; ++i) { - for (int c = 0; c < channelCount_; ++c) + for (int c = 0; c < _channelCount; ++c) out[c][i] = k * in[c][i]; } diff --git a/examples/plugins/gain/gain.hh b/examples/plugins/gain/gain.hh @@ -20,6 +20,6 @@ namespace clap { clap_process_status process(const clap_process *process) noexcept override; private: - int channelCount_ = 1; + int _channelCount = 1; }; } // namespace clap \ No newline at end of file diff --git a/examples/plugins/parameter-interpolator.hh b/examples/plugins/parameter-interpolator.hh @@ -14,55 +14,55 @@ namespace clap { void setValue(double val, double mod) { - val0_ = val; - val1_ = val; - mod0_ = mod; - mod1_ = mod; - duration_ = 0; - offset_ = 0; + _val0 = val; + _val1 = val; + _mod0 = mod; + _mod1 = mod; + _duration = 0; + _offset = 0; } void setInterpolationData(double val0, double val1, double mod0, double mod1, uint32_t duration) noexcept { - val0_ = val0; - val1_ = val1; - mod0_ = mod0; - mod1_ = mod1; - duration_ = duration; - offset_ = 0; + _val0 = val0; + _val1 = val1; + _mod0 = mod0; + _mod1 = mod1; + _duration = duration; + _offset = 0; } double value() noexcept { - if (offset_ >= duration_) - return val1_ + mod1_; + if (_offset >= _duration) + return _val1 + _mod1; - const double x = static_cast<double>(offset_) / static_cast<double>(duration_); - const double value = (val1_ + mod1_) * x + (val0_ + mod0_) * (1 - x); + const double x = static_cast<double>(_offset) / static_cast<double>(_duration); + const double value = (_val1 + _mod1) * x + (_val0 + _mod0) * (1 - x); return value; } double mod() noexcept { - if (offset_ >= duration_) - return mod1_; + if (_offset >= _duration) + return _mod1; - const double x = static_cast<double>(offset_) / static_cast<double>(duration_); - const double value = (mod1_) * x + (mod0_) * (1 - x); + const double x = static_cast<double>(_offset) / static_cast<double>(_duration); + const double value = (_mod1) * x + (_mod0) * (1 - x); return value; } void step(uint32_t n) noexcept { - offset_ += n; + _offset += n; } private: - double val0_ = 0; - double val1_ = 0; - double mod0_ = 0; - double mod1_ = 0; - uint32_t duration_ = 0; - uint32_t offset_ = 0; + double _val0 = 0; + double _val1 = 0; + double _mod0 = 0; + double _mod1 = 0; + uint32_t _duration = 0; + uint32_t _offset = 0; }; } // namespace clap \ No newline at end of file diff --git a/examples/plugins/parameters.cc b/examples/plugins/parameters.cc @@ -4,24 +4,24 @@ namespace clap { void clap::Parameters::addParameter(const clap_param_info &info) { - assert(id2param_.find(info.id) == id2param_.end()); + assert(_id2param.find(info.id) == _id2param.end()); auto p = std::make_unique<Parameter>(info); - id2param_.emplace(info.id, p.get()); - params_.emplace_back(std::move(p)); + _id2param.emplace(info.id, p.get()); + _params.emplace_back(std::move(p)); } - size_t Parameters::count() const noexcept { return params_.size(); } + size_t Parameters::count() const noexcept { return _params.size(); } Parameter *Parameters::getByIndex(size_t index) const noexcept { - if (index > params_.size()) + if (index > _params.size()) return nullptr; - return params_[index].get(); + return _params[index].get(); } Parameter *Parameters::getById(clap_id id) const noexcept { - auto it = id2param_.find(id); - if (it == id2param_.end()) + auto it = _id2param.find(id); + if (it == _id2param.end()) return nullptr; return it->second; } diff --git a/examples/plugins/parameters.hh b/examples/plugins/parameters.hh @@ -16,95 +16,89 @@ namespace clap { class Parameter { public: - explicit Parameter(const clap_param_info &info) : info_(info) { info_.cookie = this; } + explicit Parameter(const clap_param_info &info) : _info(info) { _info.cookie = this; } Parameter(const Parameter &) = delete; Parameter(Parameter &&) = delete; Parameter &operator=(const Parameter &) = delete; Parameter &operator=(Parameter &&) = delete; - const double value() const noexcept { return value_; } - const double modulation() const noexcept { return modulation_; } - const double modulatedValue() const noexcept { return value_ + modulation_; } - const clap_param_info &info() const noexcept { return info_; } + const double value() const noexcept { return _value; } + const double modulation() const noexcept { return _modulation; } + const double modulatedValue() const noexcept { return _value + _modulation; } + const clap_param_info &info() const noexcept { return _info; } void setDefaultValue() { - value_ = info_.default_value; - modulation_ = 0; + _value = _info.default_value; + _modulation = 0; } void setValueImmediately(double val) { - value_ = val; - valueRamp_ = 0; - valueSteps_ = 0; + _value = val; + _valueRamp = 0; + _valueSteps = 0; } void setModulationImmediately(double mod) { - modulation_ = mod; - modulationRamp_ = 0; - modulationSteps_ = 0; + _modulation = mod; + _modulationRamp = 0; + _modulationSteps = 0; } - void setValueSmoothed(double val, uint16_t steps) - { + void setValueSmoothed(double val, uint16_t steps) { assert(steps > 0); - valueRamp_ = (val - value_) / steps; - valueSteps_ = steps; + _valueRamp = (val - _value) / steps; + _valueSteps = steps; } - void setModulationSmoothed(double mod, uint16_t steps) - { + void setModulationSmoothed(double mod, uint16_t steps) { assert(steps > 0); - modulationRamp_ = (mod - modulation_) / steps; - modulationSteps_ = steps; + _modulationRamp = (mod - _modulation) / steps; + _modulationSteps = steps; } // Advances the value by 1 samples and return the new value + modulation double step() { - if (valueSteps_ > 0) [[unlikely]] - { - value_ += valueRamp_; - --valueSteps_; + if (_valueSteps > 0) [[unlikely]] { + _value += _valueRamp; + --_valueSteps; } - if (modulationSteps_ > 0) [[unlikely]] - { - modulation_ += modulationRamp_; - --modulationSteps_; + if (_modulationSteps > 0) [[unlikely]] { + _modulation += _modulationRamp; + --_modulationSteps; } - return value_ + modulation_; + return _value + _modulation; } // Advances the value by n samples and return the new value + modulation double step(uint32_t n) { - if (valueSteps_ > 0) [[unlikely]] - { - auto k = std::min<uint32_t>(valueSteps_, n); - value_ += k * valueRamp_; - valueSteps_ -= k; + if (_valueSteps > 0) [[unlikely]] { + auto k = std::min<uint32_t>(_valueSteps, n); + _value += k * _valueRamp; + _valueSteps -= k; } - if (modulationSteps_ > 0) [[unlikely]] - { - auto k = std::min<uint32_t>(valueSteps_, n); - modulation_ += k * modulationRamp_; - modulationSteps_ -= k; + if (_modulationSteps > 0) [[unlikely]] { + auto k = std::min<uint32_t>(_valueSteps, n); + _modulation += k * _modulationRamp; + _modulationSteps -= k; } - return value_ + modulation_; + return _value + _modulation; } private: - clap_param_info info_; + clap_param_info _info; - double value_ = 0; - double modulation_ = 0; + double _value = 0; + double _modulation = 0; - double valueRamp_ = 0; - double modulationRamp_ = 0; + double _valueRamp = 0; + double _modulationRamp = 0; - uint16_t valueSteps_ = 0; - uint16_t modulationSteps_ = 0; + uint16_t _valueSteps = 0; + uint16_t _modulationSteps = 0; }; class Parameters { @@ -127,7 +121,7 @@ namespace clap { template <class Archive> void save(Archive &ar, const unsigned int version) const { std::vector<std::pair<clap_id, double>> values; - for (auto &p : params_) + for (auto &p : _params) values.emplace_back(p->info().id, p->value()); ar << values; @@ -138,7 +132,7 @@ namespace clap { std::vector<std::pair<clap_id, double>> values; ar >> values; - for (auto &p : params_) + for (auto &p : _params) p->setDefaultValue(); for (auto &v : values) { @@ -151,8 +145,8 @@ namespace clap { BOOST_SERIALIZATION_SPLIT_MEMBER() - std::vector<std::unique_ptr<Parameter>> params_; - std::unordered_map<clap_id, Parameter *> id2param_; + std::vector<std::unique_ptr<Parameter>> _params; + std::unordered_map<clap_id, Parameter *> _id2param; }; } // namespace clap diff --git a/examples/plugins/remote-gui.cc b/examples/plugins/remote-gui.cc @@ -12,20 +12,20 @@ namespace clap { RemoteGui::~RemoteGui() { - if (channel_) + if (_channel) destroy(); - assert(!channel_); + assert(!_channel); } bool RemoteGui::spawn() { - assert(child_ == -1); - assert(!channel_); + assert(_child == -1); + assert(!_channel); - if (!plugin_.canUseTimerSupport() || !plugin_.canUseFdSupport()) + if (!_plugin.canUseTimerSupport() || !_plugin.canUseFdSupport()) return false; - auto &pathProvider = plugin_.pathProvider(); + auto &pathProvider = _plugin.pathProvider(); #ifdef __unix__ /* create a socket pair */ @@ -44,14 +44,14 @@ namespace clap { skin.c_str(), qmlLib.c_str()); - child_ = ::fork(); - if (child_ == -1) { + _child = ::fork(); + if (_child == -1) { ::close(sockets[0]); ::close(sockets[1]); return false; } - if (child_ == 0) { + if (_child == 0) { // Child ::close(sockets[0]); char socketStr[16]; @@ -72,10 +72,10 @@ namespace clap { ::close(sockets[1]); } - timerId_ = CLAP_INVALID_ID; - plugin_.hostTimerSupport_->register_timer(plugin_.host_, 1000 / 60, &timerId_); - plugin_.hostFdSupport_->register_fd(plugin_.host_, sockets[0], CLAP_FD_READ | CLAP_FD_ERROR); - channel_.reset(new RemoteChannel( + _timerId = CLAP_INVALID_ID; + _plugin._hostTimerSupport->register_timer(_plugin._host, 1000 / 60, &_timerId); + _plugin._hostFdSupport->register_fd(_plugin._host, sockets[0], CLAP_FD_READ | CLAP_FD_ERROR); + _channel.reset(new RemoteChannel( [this](const RemoteChannel::Message &msg) { onMessage(msg); }, *this, sockets[0], true)); return true; @@ -85,23 +85,23 @@ namespace clap { } void RemoteGui::modifyFd(clap_fd_flags flags) { - plugin_.hostFdSupport_->modify_fd(plugin_.host_, channel_->fd(), flags); + _plugin._hostFdSupport->modify_fd(_plugin._host, _channel->fd(), flags); } void RemoteGui::removeFd() { - plugin_.hostFdSupport_->unregister_fd(plugin_.host_, channel_->fd()); - plugin_.hostTimerSupport_->unregister_timer(plugin_.host_, timerId_); + _plugin._hostFdSupport->unregister_fd(_plugin._host, _channel->fd()); + _plugin._hostTimerSupport->unregister_timer(_plugin._host, _timerId); } - clap_fd RemoteGui::fd() const { return channel_ ? channel_->fd() : -1; } + clap_fd RemoteGui::fd() const { return _channel ? _channel->fd() : -1; } void RemoteGui::onFd(clap_fd_flags flags) { if (flags & CLAP_FD_READ) - channel_->onRead(); + _channel->onRead(); if (flags & CLAP_FD_WRITE) - channel_->onWrite(); + _channel->onWrite(); if (flags & CLAP_FD_ERROR) - channel_->onError(); + _channel->onError(); } void RemoteGui::onMessage(const RemoteChannel::Message &msg) { @@ -109,21 +109,21 @@ namespace clap { case messages::kAdjustRequest: { messages::AdjustRequest rq; msg.get(rq); - plugin_.guiAdjust(rq.paramId, rq.value, rq.flags); + _plugin.guiAdjust(rq.paramId, rq.value, rq.flags); break; } } } void RemoteGui::defineParameter(const clap_param_info &info) noexcept { - channel_->sendRequestAsync(messages::DefineParameterRequest{info}); + _channel->sendRequestAsync(messages::DefineParameterRequest{info}); } bool RemoteGui::size(uint32_t *width, uint32_t *height) noexcept { messages::SizeRequest request; messages::SizeResponse response; - if (!channel_->sendRequestSync(request, response)) + if (!_channel->sendRequestSync(request, response)) return false; *width = response.width; @@ -132,49 +132,49 @@ namespace clap { } void RemoteGui::setScale(double scale) noexcept { - channel_->sendRequestAsync(messages::SetScaleRequest{scale}); + _channel->sendRequestAsync(messages::SetScaleRequest{scale}); } bool RemoteGui::show() noexcept { messages::ShowRequest request; messages::ShowResponse response; - return channel_->sendRequestSync(request, response); + return _channel->sendRequestSync(request, response); } bool RemoteGui::hide() noexcept { messages::HideRequest request; messages::HideResponse response; - return channel_->sendRequestSync(request, response); + return _channel->sendRequestSync(request, response); } void RemoteGui::destroy() noexcept { - if (!channel_) + if (!_channel) return; messages::DestroyRequest request; messages::DestroyResponse response; - channel_->sendRequestSync(request, response); - channel_->close(); - channel_.reset(); + _channel->sendRequestSync(request, response); + _channel->close(); + _channel.reset(); waitChild(); } void RemoteGui::waitChild() { #ifdef __unix__ - if (child_ == -1) + if (_child == -1) return; int stat = 0; int ret; do { - ret = ::waitpid(child_, &stat, 0); + ret = ::waitpid(_child, &stat, 0); } while (ret == -1 && errno == EINTR); - child_ = -1; + _child = -1; #endif } @@ -182,14 +182,14 @@ namespace clap { messages::AttachCocoaRequest request{nsView}; messages::AttachResponse response; - return channel_->sendRequestSync(request, response); + return _channel->sendRequestSync(request, response); } bool RemoteGui::attachWin32(clap_hwnd window) noexcept { messages::AttachWin32Request request{window}; messages::AttachResponse response; - return channel_->sendRequestSync(request, response); + return _channel->sendRequestSync(request, response); } bool RemoteGui::attachX11(const char *display_name, unsigned long window) noexcept { @@ -199,14 +199,14 @@ namespace clap { request.window = window; std::snprintf(request.display, sizeof(request.display), "%s", display_name ?: ""); - return channel_->sendRequestSync(request, response); + return _channel->sendRequestSync(request, response); } void RemoteGui::onTimer() { - plugin_.pluginToGuiQueue_.consume( + _plugin._pluginToGuiQueue.consume( [this](clap_id paramId, const CorePlugin::PluginToGuiValue &value) { messages::ParameterValueRequest rq{paramId, value.value, value.mod}; - channel_->sendRequestAsync(rq); + _channel->sendRequestAsync(rq); }); } diff --git a/examples/plugins/remote-gui.hh b/examples/plugins/remote-gui.hh @@ -38,22 +38,22 @@ namespace clap { clap_fd fd() const; void onFd(clap_fd_flags flags); - clap_id timerId() const noexcept { return timerId_; } + clap_id timerId() const noexcept { return _timerId; } void onTimer(); private: void onMessage(const RemoteChannel::Message& msg); void waitChild(); - std::unique_ptr<RemoteChannel> channel_; + std::unique_ptr<RemoteChannel> _channel; - clap_id timerId_ = CLAP_INVALID_ID; + clap_id _timerId = CLAP_INVALID_ID; #ifdef __unix__ - pid_t child_ = -1; + pid_t _child = -1; #else - STARTUPINFO si; - PROCESS_INFORMATION childInfo_; + STARTUPINFO _si; + PROCESS_INFORMATION _childInfo; #endif }; } // namespace clap \ No newline at end of file diff --git a/examples/plugins/stream-helper.hh b/examples/plugins/stream-helper.hh @@ -8,26 +8,26 @@ namespace clap { class Source : public boost::iostreams::source { public: - explicit Source(clap_istream *is) : is_(is) {} + explicit Source(clap_istream *is) : _is(is) {} - std::streamsize read(char *s, std::streamsize n) noexcept { return is_->read(is_, s, n); } + std::streamsize read(char *s, std::streamsize n) noexcept { return _is->read(_is, s, n); } private: - clap_istream *is_; + clap_istream *_is; }; using IStream = boost::iostreams::stream<Source>; class Sink : public boost::iostreams::sink { public: - explicit Sink(clap_ostream *os) : os_(os) {} + explicit Sink(clap_ostream *os) : _os(os) {} std::streamsize write(const char *s, std::streamsize n) noexcept { - return os_->write(os_, s, n); + return _os->write(_os, s, n); } private: - clap_ostream *os_; + clap_ostream *_os; }; using OStream = boost::iostreams::stream<Sink>;