diff options
author | David Robillard <d@drobilla.net> | 2024-07-17 11:33:25 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-07-17 12:30:47 -0400 |
commit | 175c04323ad1aaaa1e0c949b8de411d5e2cece74 (patch) | |
tree | ac359693858f9ba2e619f2d9fc9b809af637a82e /src/server | |
parent | 973db12fe33bab8e6efca80deca358b4998d5eb2 (diff) | |
download | ingen-175c04323ad1aaaa1e0c949b8de411d5e2cece74.tar.gz ingen-175c04323ad1aaaa1e0c949b8de411d5e2cece74.tar.bz2 ingen-175c04323ad1aaaa1e0c949b8de411d5e2cece74.zip |
Avoid C-style casts and some size type conversions
Aside from the syntactic cast changes, reduces some size types to 32-bits,
since they can never be so large in practice. This eliminates some type
conversions and shaves a few bytes.
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/.clang-tidy | 1 | ||||
-rw-r--r-- | src/server/BufferFactory.cpp | 2 | ||||
-rw-r--r-- | src/server/BufferFactory.hpp | 2 | ||||
-rw-r--r-- | src/server/DirectDriver.hpp | 7 | ||||
-rw-r--r-- | src/server/Driver.hpp | 2 | ||||
-rw-r--r-- | src/server/Engine.cpp | 18 | ||||
-rw-r--r-- | src/server/Engine.hpp | 6 | ||||
-rw-r--r-- | src/server/GraphImpl.cpp | 2 | ||||
-rw-r--r-- | src/server/JackDriver.cpp | 7 | ||||
-rw-r--r-- | src/server/JackDriver.hpp | 5 | ||||
-rw-r--r-- | src/server/PortAudioDriver.hpp | 13 | ||||
-rw-r--r-- | src/server/events/Delete.cpp | 2 | ||||
-rw-r--r-- | src/server/events/Get.cpp | 6 | ||||
-rw-r--r-- | src/server/ingen_lv2.cpp | 11 |
14 files changed, 45 insertions, 39 deletions
diff --git a/src/server/.clang-tidy b/src/server/.clang-tidy index ccc90183..bb3d2c63 100644 --- a/src/server/.clang-tidy +++ b/src/server/.clang-tidy @@ -12,7 +12,6 @@ Checks: > -cert-dcl37-c, -cert-dcl51-cpp, -cppcoreguidelines-pro-bounds-constant-array-index, - -cppcoreguidelines-pro-type-cstyle-cast, -cppcoreguidelines-pro-type-static-cast-downcast, -google-readability-todo, -google-runtime-int, diff --git a/src/server/BufferFactory.cpp b/src/server/BufferFactory.cpp index 1afbf93f..0df5a025 100644 --- a/src/server/BufferFactory.cpp +++ b/src/server/BufferFactory.cpp @@ -109,7 +109,7 @@ BufferFactory::default_size(LV2_URID type) const } if (type == _uris.atom_Sequence) { - if (_seq_size == 0) { + if (_seq_size == 0U) { return _engine.sequence_size(); } diff --git a/src/server/BufferFactory.hpp b/src/server/BufferFactory.hpp index 657ce7d2..2f6c95ba 100644 --- a/src/server/BufferFactory.hpp +++ b/src/server/BufferFactory.hpp @@ -111,7 +111,7 @@ private: std::mutex _mutex; Engine& _engine; URIs& _uris; - uint32_t _seq_size{0}; + uint32_t _seq_size{0U}; BufferRef _silent_buffer; }; diff --git a/src/server/DirectDriver.hpp b/src/server/DirectDriver.hpp index 2361034c..46187527 100644 --- a/src/server/DirectDriver.hpp +++ b/src/server/DirectDriver.hpp @@ -29,6 +29,7 @@ #include <boost/intrusive/slist.hpp> #include <cstddef> +#include <cstdint> #include <string> namespace boost::intrusive { @@ -53,7 +54,7 @@ public: DirectDriver(Engine& engine, double sample_rate, SampleCount block_length, - size_t seq_size) + uint32_t seq_size) : _engine(engine) , _sample_rate(sample_rate) , _block_length(block_length) @@ -100,7 +101,7 @@ public: SampleCount block_length() const override { return _block_length; } - size_t seq_size() const override { return _seq_size; } + uint32_t seq_size() const override { return _seq_size; } SampleCount sample_rate() const override { return _sample_rate; } @@ -120,7 +121,7 @@ private: Ports _ports; SampleCount _sample_rate; SampleCount _block_length; - size_t _seq_size; + uint32_t _seq_size; }; } // namespace server diff --git a/src/server/Driver.hpp b/src/server/Driver.hpp index 83436389..7f0f4c40 100644 --- a/src/server/Driver.hpp +++ b/src/server/Driver.hpp @@ -98,7 +98,7 @@ public: virtual SampleCount block_length() const = 0; /** Return the event buffer size in bytes */ - virtual size_t seq_size() const = 0; + virtual uint32_t seq_size() const = 0; /** Return the sample rate in Hz */ virtual SampleRate sample_rate() const = 0; diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index c4c492b7..cc3012d4 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -104,11 +104,14 @@ Engine::Engine(ingen::World& world) } for (int i = 0; i < world.conf().option("threads").get<int32_t>(); ++i) { + const bool is_threaded = (i > 0); _notifications.emplace_back( - std::make_unique<raul::RingBuffer>(uint32_t(24 * event_queue_size()))); + std::make_unique<raul::RingBuffer>(24U * event_queue_size())); _run_contexts.emplace_back( - std::make_unique<RunContext>( - *this, _notifications.back().get(), unsigned(i), i > 0)); + std::make_unique<RunContext>(*this, + _notifications.back().get(), + static_cast<unsigned>(i), + is_threaded)); } _world.lv2_features().add_feature(_worker->schedule_feature()); @@ -295,16 +298,17 @@ Engine::block_length() const return _driver->block_length(); } -size_t +uint32_t Engine::sequence_size() const { return _driver->seq_size(); } -size_t +uint32_t Engine::event_queue_size() const { - return _world.conf().option("queue-size").get<int32_t>(); + return static_cast<uint32_t>( + std::max(0, _world.conf().option("queue-size").get<int32_t>())); } void @@ -378,7 +382,7 @@ Engine::reset_load() } void -Engine::init(double sample_rate, uint32_t block_length, size_t seq_size) +Engine::init(double sample_rate, uint32_t block_length, uint32_t seq_size) { set_driver(std::make_shared<DirectDriver>( *this, sample_rate, block_length, seq_size)); diff --git a/src/server/Engine.hpp b/src/server/Engine.hpp index f0f19740..6557ac53 100644 --- a/src/server/Engine.hpp +++ b/src/server/Engine.hpp @@ -88,7 +88,7 @@ public: Engine& operator=(const Engine&) = delete; // EngineBase methods - void init(double sample_rate, uint32_t block_length, size_t seq_size) override; + void init(double sample_rate, uint32_t block_length, uint32_t seq_size) override; bool supports_dynamic_ports() const override; bool activate() override; void deactivate() override; @@ -173,8 +173,8 @@ public: SampleRate sample_rate() const; SampleCount block_length() const; - size_t sequence_size() const; - size_t event_queue_size() const; + uint32_t sequence_size() const; + uint32_t event_queue_size() const; size_t n_threads() const { return _run_contexts.size(); } bool atomic_bundles() const { return _atomic_bundles; } diff --git a/src/server/GraphImpl.cpp b/src/server/GraphImpl.cpp index 0d3c5234..8435818b 100644 --- a/src/server/GraphImpl.cpp +++ b/src/server/GraphImpl.cpp @@ -331,7 +331,7 @@ bool GraphImpl::has_port_with_index(uint32_t index) const { BufferFactory& bufs = *_engine.buffer_factory(); - const auto index_atom = bufs.forge().make(int32_t(index)); + const auto index_atom = bufs.forge().make(static_cast<int32_t>(index)); for (const auto& p : _inputs) { if (p.has_property(bufs.uris().lv2_index, index_atom)) { diff --git a/src/server/JackDriver.cpp b/src/server/JackDriver.cpp index d991879e..0589a021 100644 --- a/src/server/JackDriver.cpp +++ b/src/server/JackDriver.cpp @@ -52,6 +52,7 @@ #include <cassert> #include <chrono> +#include <cstdint> #include <map> #include <string> #include <utility> @@ -109,7 +110,8 @@ JackDriver::attach(const std::string& server_name, _sample_rate = jack_get_sample_rate(_client); _block_length = jack_get_buffer_size(_client); - _seq_size = jack_port_type_get_buffer_size(_client, JACK_DEFAULT_MIDI_TYPE); + _seq_size = static_cast<uint32_t>( + jack_port_type_get_buffer_size(_client, JACK_DEFAULT_MIDI_TYPE)); _fallback_buffer = AudioBufPtr( static_cast<float*>( @@ -522,7 +524,8 @@ JackDriver::_block_length_cb(jack_nframes_t nframes) { if (_engine.root_graph()) { _block_length = nframes; - _seq_size = jack_port_type_get_buffer_size(_client, JACK_DEFAULT_MIDI_TYPE); + _seq_size = static_cast<uint32_t>( + jack_port_type_get_buffer_size(_client, JACK_DEFAULT_MIDI_TYPE)); _engine.root_graph()->set_buffer_size( _engine.run_context(), *_engine.buffer_factory(), PortType::AUDIO, _engine.buffer_factory()->audio_buffer_size(nframes)); diff --git a/src/server/JackDriver.hpp b/src/server/JackDriver.hpp index bd1b3477..28931e9e 100644 --- a/src/server/JackDriver.hpp +++ b/src/server/JackDriver.hpp @@ -33,7 +33,6 @@ #include <jack/types.h> #include <atomic> -#include <cstddef> #include <cstdint> #include <exception> #include <memory> @@ -100,7 +99,7 @@ public: jack_client_t* jack_client() const { return _client; } SampleCount block_length() const override { return _block_length; } - size_t seq_size() const override { return _seq_size; } + uint32_t seq_size() const override { return _seq_size; } SampleCount sample_rate() const override { return _sample_rate; } SampleCount frame_time() const override { @@ -157,7 +156,7 @@ protected: std::atomic<bool> _flag{false}; jack_client_t* _client{nullptr}; jack_nframes_t _block_length{0}; - size_t _seq_size{0}; + uint32_t _seq_size{0}; jack_nframes_t _sample_rate{0}; uint32_t _midi_event_type; bool _is_activated{false}; diff --git a/src/server/PortAudioDriver.hpp b/src/server/PortAudioDriver.hpp index c0a28ba9..c8a83479 100644 --- a/src/server/PortAudioDriver.hpp +++ b/src/server/PortAudioDriver.hpp @@ -29,7 +29,6 @@ #include <portaudio.h> #include <atomic> -#include <cstddef> #include <cstdint> #include <memory> @@ -77,7 +76,7 @@ public: int real_time_priority() override { return 80; } SampleCount block_length() const override { return _block_length; } - size_t seq_size() const override { return _seq_size; } + uint32_t seq_size() const override { return _seq_size; } SampleCount sample_rate() const override { return _sample_rate; } private: @@ -118,14 +117,14 @@ protected: Ports _ports; PaStreamParameters _inputParameters; PaStreamParameters _outputParameters; - raul::Semaphore _sem{0}; + raul::Semaphore _sem{0U}; std::unique_ptr<FrameTimer> _timer; PaStream* _stream{nullptr}; - size_t _seq_size{4096}; + uint32_t _seq_size{4096U}; uint32_t _block_length; - uint32_t _sample_rate{48000}; - uint32_t _n_inputs{0}; - uint32_t _n_outputs{0}; + uint32_t _sample_rate{48000U}; + uint32_t _n_inputs{0U}; + uint32_t _n_outputs{0U}; std::atomic<bool> _flag{false}; bool _is_activated{false}; }; diff --git a/src/server/events/Delete.cpp b/src/server/events/Delete.cpp index 62653752..bcebe2ba 100644 --- a/src/server/events/Delete.cpp +++ b/src/server/events/Delete.cpp @@ -225,7 +225,7 @@ Delete::undo(Interface& target) if (c.first != _msg.uri.path()) { target.set_property(path_to_uri(c.first), uris.lv2_index, - forge.make(int32_t(c.second.first))); + forge.make(static_cast<int32_t>(c.second.first))); } } } diff --git a/src/server/events/Get.cpp b/src/server/events/Get.cpp index 9efef123..385e55f3 100644 --- a/src/server/events/Get.cpp +++ b/src/server/events/Get.cpp @@ -105,11 +105,11 @@ Get::post_process() URIs& uris = _engine.world().uris(); Properties props = { { uris.param_sampleRate, - uris.forge.make(int32_t(_engine.sample_rate())) }, + uris.forge.make(static_cast<int32_t>(_engine.sample_rate())) }, { uris.bufsz_maxBlockLength, - uris.forge.make(int32_t(_engine.block_length())) }, + uris.forge.make(static_cast<int32_t>(_engine.block_length())) }, { uris.ingen_numThreads, - uris.forge.make(int32_t(_engine.n_threads())) } }; + uris.forge.make(static_cast<int32_t>(_engine.n_threads())) } }; const Properties load_props = _engine.load_properties(); props.insert(load_props.begin(), load_props.end()); diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp index d474693d..f5b4e79f 100644 --- a/src/server/ingen_lv2.cpp +++ b/src/server/ingen_lv2.cpp @@ -113,7 +113,7 @@ class LV2Driver : public Driver, public ingen::AtomSink public: LV2Driver(Engine& engine, SampleCount block_length, - size_t seq_size, + uint32_t seq_size, SampleCount sample_rate) : _engine(engine) , _main_sem(0) @@ -388,7 +388,7 @@ public: } SampleCount block_length() const override { return _block_length; } - size_t seq_size() const override { return _seq_size; } + uint32_t seq_size() const override { return _seq_size; } SampleCount sample_rate() const override { return _sample_rate; } SampleCount frame_time() const override { return _frame_time; } @@ -412,7 +412,7 @@ private: GraphImpl* _root_graph{nullptr}; uint32_t _notify_capacity{0}; SampleCount _block_length; - size_t _seq_size; + uint32_t _seq_size; SampleCount _sample_rate; SampleCount _frame_time{0}; raul::Semaphore _to_ui_overflow_sem{0}; @@ -552,7 +552,7 @@ ingen_instantiate(const LV2_Descriptor* descriptor, block_length = 4096; plugin->world->log().warn("No maximum block length given\n"); } - if (seq_size == 0) { + if (seq_size < 1) { seq_size = 16384; plugin->world->log().warn("No maximum sequence size given\n"); } @@ -575,7 +575,8 @@ ingen_instantiate(const LV2_Descriptor* descriptor, ThreadManager::set_flag(THREAD_PRE_PROCESS); ThreadManager::single_threaded = true; - auto* driver = new LV2Driver(*engine, block_length, seq_size, rate); + auto* driver = new LV2Driver( + *engine, block_length, static_cast<uint32_t>(seq_size), rate); engine->set_driver(std::shared_ptr<Driver>(driver)); engine->activate(); |