diff options
Diffstat (limited to 'src/server')
38 files changed, 272 insertions, 196 deletions
diff --git a/src/server/BlockFactory.cpp b/src/server/BlockFactory.cpp index 9e1693df..2368109e 100644 --- a/src/server/BlockFactory.cpp +++ b/src/server/BlockFactory.cpp @@ -149,7 +149,7 @@ BlockFactory::load_lv2_plugins() using Types = std::vector<SPtr<LilvNode>>; Types types; for (unsigned t = PortType::ID::AUDIO; t <= PortType::ID::ATOM; ++t) { - const URI& uri(PortType((PortType::ID)t).uri()); + const URI& uri(PortType(static_cast<PortType::ID>(t)).uri()); types.push_back( SPtr<LilvNode>(lilv_new_uri(_world.lilv_world(), uri.c_str()), lilv_node_free)); diff --git a/src/server/BlockImpl.cpp b/src/server/BlockImpl.cpp index ba0bdc77..06bd13c5 100644 --- a/src/server/BlockImpl.cpp +++ b/src/server/BlockImpl.cpp @@ -57,7 +57,7 @@ BlockImpl::~BlockImpl() assert(!_activated); if (is_linked()) { - ((GraphImpl*)_parent)->remove_block(*this); + reinterpret_cast<GraphImpl*>(_parent)->remove_block(*this); } } diff --git a/src/server/BlockImpl.hpp b/src/server/BlockImpl.hpp index 15a4e075..54fcd221 100644 --- a/src/server/BlockImpl.hpp +++ b/src/server/BlockImpl.hpp @@ -179,7 +179,10 @@ public: uint32_t size); /** The Graph this Block belongs to. */ - GraphImpl* parent_graph() const override { return (GraphImpl*)_parent; } + GraphImpl* parent_graph() const override + { + return reinterpret_cast<GraphImpl*>(_parent); + } uint32_t num_ports() const override { return _ports ? _ports->size() : 0; } diff --git a/src/server/Buffer.cpp b/src/server/Buffer.cpp index c3430858..509cbc01 100644 --- a/src/server/Buffer.cpp +++ b/src/server/Buffer.cpp @@ -131,14 +131,14 @@ Buffer::render_sequence(const RunContext& context, const Buffer* src, bool add) { const LV2_URID atom_Float = _factory.uris().atom_Float; const auto* seq = src->get<const LV2_Atom_Sequence>(); - const auto* init = (const LV2_Atom_Float*)src->value(); + const auto* init = reinterpret_cast<const LV2_Atom_Float*>(src->value()); float value = init ? init->body : 0.0f; SampleCount offset = context.offset(); LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { if (ev->time.frames >= offset && ev->body.type == atom_Float) { write_block(value, offset, ev->time.frames, add); - value = ((const LV2_Atom_Float*)&ev->body)->body; + value = reinterpret_cast<const LV2_Atom_Float*>(&ev->body)->body; offset = ev->time.frames; } } @@ -192,7 +192,7 @@ Buffer::port_data(PortType port_type, SampleCount offset) if (_type == _factory.uris().atom_Float) { return &get<LV2_Atom_Float>()->body; } else if (_type == _factory.uris().atom_Sound) { - return (Sample*)_buf + offset; + return static_cast<Sample*>(_buf) + offset; } break; case PortType::ID::ATOM: @@ -225,7 +225,7 @@ float Buffer::peak(const RunContext& context) const { #ifdef __SSE__ - const auto* const vbuf = (const __m128*)samples(); + const auto* const vbuf = reinterpret_cast<const __m128*>(samples()); __m128 vpeak = mm_abs_ps(vbuf[0]); const SampleCount nblocks = context.nframes() / 4; @@ -270,7 +270,7 @@ Buffer::prepare_write(RunContext&) if (_type == _factory.uris().atom_Sequence) { auto* atom = get<LV2_Atom>(); - atom->type = (LV2_URID)_factory.uris().atom_Sequence; + atom->type = static_cast<LV2_URID>(_factory.uris().atom_Sequence); atom->size = sizeof(LV2_Atom_Sequence_Body); _latest_event = 0; } @@ -282,7 +282,7 @@ Buffer::prepare_output_write(RunContext&) if (_type == _factory.uris().atom_Sequence) { auto* atom = get<LV2_Atom>(); - atom->type = (LV2_URID)_factory.uris().atom_Chunk; + atom->type = static_cast<LV2_URID>(_factory.uris().atom_Chunk); atom->size = _capacity - sizeof(LV2_Atom); _latest_event = 0; } @@ -305,9 +305,9 @@ Buffer::append_event(int64_t frames, return false; } - auto* seq = (LV2_Atom_Sequence*)atom; - auto* ev = (LV2_Atom_Event*)( - (uint8_t*)seq + lv2_atom_total_size(&seq->atom)); + auto* seq = reinterpret_cast<LV2_Atom_Sequence*>(atom); + auto* ev = reinterpret_cast<LV2_Atom_Event*>( + reinterpret_cast<uint8_t*>(seq) + lv2_atom_total_size(&seq->atom)); ev->time.frames = frames; ev->body.size = size; @@ -324,20 +324,23 @@ Buffer::append_event(int64_t frames, bool Buffer::append_event(int64_t frames, const LV2_Atom* body) { - return append_event(frames, body->size, body->type, (const uint8_t*)(body + 1)); + return append_event(frames, + body->size, + body->type, + reinterpret_cast<const uint8_t*>(body + 1)); } bool Buffer::append_event_buffer(const Buffer* buf) { - auto* seq = (LV2_Atom_Sequence*)get<LV2_Atom>(); - auto* bseq = (const LV2_Atom_Sequence*)buf->get<LV2_Atom>(); + auto* seq = reinterpret_cast<LV2_Atom_Sequence*>(get<LV2_Atom>()); + auto* bseq = reinterpret_cast<const LV2_Atom_Sequence*>(buf->get<LV2_Atom>()); if (seq->atom.type == _factory.uris().atom_Chunk) { clear(); // Chunk initialized with prepare_output_write(), clear } const uint32_t total_size = lv2_atom_total_size(&seq->atom); - uint8_t* const end = (uint8_t*)seq + total_size; + uint8_t* const end = reinterpret_cast<uint8_t*>(seq) + total_size; const uint32_t n_bytes = bseq->atom.size - sizeof(bseq->body); if (sizeof(LV2_Atom) + total_size + n_bytes >= _capacity) { return false; // Not enough space @@ -444,7 +447,7 @@ void* Buffer::aligned_alloc(size_t size) { #ifdef HAVE_POSIX_MEMALIGN void* buf; - if (!posix_memalign((void**)&buf, 16, size)) { + if (!posix_memalign(static_cast<void**>(&buf), 16, size)) { memset(buf, 0, size); return buf; } diff --git a/src/server/Buffer.hpp b/src/server/Buffer.hpp index 1cbb0f29..c784f661 100644 --- a/src/server/Buffer.hpp +++ b/src/server/Buffer.hpp @@ -94,9 +94,10 @@ public: /// Audio or float buffers only inline const Sample* samples() const { if (is_control()) { - return (const Sample*)LV2_ATOM_BODY_CONST(get<LV2_Atom_Float>()); + return static_cast<const Sample*>( + LV2_ATOM_BODY_CONST(get<LV2_Atom_Float>())); } else if (is_audio()) { - return (const Sample*)_buf; + return static_cast<const Sample*>(_buf); } return nullptr; } @@ -104,9 +105,9 @@ public: /// Audio buffers only inline Sample* samples() { if (is_control()) { - return (Sample*)LV2_ATOM_BODY(get<LV2_Atom_Float>()); + return static_cast<Sample*>(LV2_ATOM_BODY(get<LV2_Atom_Float>())); } else if (is_audio()) { - return (Sample*)_buf; + return static_cast<Sample*>(_buf); } return nullptr; } @@ -116,7 +117,7 @@ public: if (is_audio() || is_control()) { return samples()[offset]; } else if (_value_buffer) { - return ((const LV2_Atom_Float*)value())->body; + return reinterpret_cast<const LV2_Atom_Float*>(value())->body; } return 0.0f; } diff --git a/src/server/BufferFactory.cpp b/src/server/BufferFactory.cpp index 23b44884..657484d8 100644 --- a/src/server/BufferFactory.cpp +++ b/src/server/BufferFactory.cpp @@ -170,7 +170,8 @@ BufferFactory::create(LV2_URID type, LV2_URID value_type, uint32_t capacity) if (capacity == 0) { capacity = default_size(type); } else if (type == _uris.atom_Float) { - capacity = std::max(capacity, (uint32_t)sizeof(LV2_Atom_Float)); + capacity = + std::max(capacity, static_cast<uint32_t>(sizeof(LV2_Atom_Float))); } else if (type == _uris.atom_Sound) { capacity = std::max(capacity, default_size(_uris.atom_Sound)); } diff --git a/src/server/ClientUpdate.cpp b/src/server/ClientUpdate.cpp index cb3c34dc..0c0f9203 100644 --- a/src/server/ClientUpdate.cpp +++ b/src/server/ClientUpdate.cpp @@ -69,7 +69,7 @@ ClientUpdate::put_block(const BlockImpl* block) const URIs& uris = plugin->uris(); if (uris.ingen_Graph == plugin->type()) { - put_graph((const GraphImpl*)block); + put_graph(static_cast<const GraphImpl*>(block)); } else { put(block->uri(), block->properties()); for (size_t j = 0; j < block->num_ports(); ++j) { diff --git a/src/server/ControlBindings.cpp b/src/server/ControlBindings.cpp index 3e123a16..8ab4aef7 100644 --- a/src/server/ControlBindings.cpp +++ b/src/server/ControlBindings.cpp @@ -79,7 +79,7 @@ ControlBindings::binding_key(const Atom& binding) const Key key; LV2_Atom* num = nullptr; if (binding.type() == uris.atom_Object) { - const auto* obj = (const LV2_Atom_Object_Body*)binding.get_body(); + const auto* obj = static_cast<const LV2_Atom_Object_Body*>(binding.get_body()); if (obj->otype == uris.midi_Bender) { key = Key(Type::MIDI_BENDER); } else if (obj->otype == uris.midi_ChannelPressure) { @@ -87,7 +87,7 @@ ControlBindings::binding_key(const Atom& binding) const } else if (obj->otype == uris.midi_Controller) { lv2_atom_object_body_get(binding.size(), obj, - (LV2_URID)uris.midi_controllerNumber, + uris.midi_controllerNumber.urid(), &num, nullptr); if (!num) { @@ -95,12 +95,12 @@ ControlBindings::binding_key(const Atom& binding) const } else if (num->type != uris.atom_Int) { _engine.log().rt_error("Controller number not an integer\n"); } else { - key = Key(Type::MIDI_CC, ((LV2_Atom_Int*)num)->body); + key = Key(Type::MIDI_CC, reinterpret_cast<LV2_Atom_Int*>(num)->body); } } else if (obj->otype == uris.midi_NoteOn) { lv2_atom_object_body_get(binding.size(), obj, - (LV2_URID)uris.midi_noteNumber, + uris.midi_noteNumber.urid(), &num, nullptr); if (!num) { @@ -108,7 +108,7 @@ ControlBindings::binding_key(const Atom& binding) const } else if (num->type != uris.atom_Int) { _engine.log().rt_error("Note number not an integer\n"); } else { - key = Key(Type::MIDI_NOTE, ((LV2_Atom_Int*)num)->body); + key = Key(Type::MIDI_NOTE, reinterpret_cast<LV2_Atom_Int*>(num)->body); } } } else if (binding.type()) { @@ -199,7 +199,10 @@ ControlBindings::port_value_changed(RunContext& ctx, break; } if (size > 0) { - _feedback->append_event(ctx.nframes() - 1, size, (LV2_URID)uris.midi_MidiEvent, buf); + _feedback->append_event(ctx.nframes() - 1, + size, + static_cast<LV2_URID>(uris.midi_MidiEvent), + buf); } } } @@ -237,10 +240,10 @@ ControlBindings::control_to_port_value(RunContext& context, switch (type) { case Type::MIDI_CC: case Type::MIDI_CHANNEL_PRESSURE: - normal = (float)value / 127.0f; + normal = static_cast<float>(value) / 127.0f; break; case Type::MIDI_BENDER: - normal = (float)value / 16383.0f; + normal = static_cast<float>(value) / 16383.0f; break; case Type::MIDI_NOTE: normal = (value == 0) ? 0.0f : 1.0f; @@ -250,7 +253,7 @@ ControlBindings::control_to_port_value(RunContext& context, } if (port->is_logarithmic()) { - normal = (expf(normal) - 1.0f) / ((float)M_E - 1.0f); + normal = (expf(normal) - 1.0f) / (static_cast<float>(M_E) - 1.0f); } float min = 0.0f; @@ -286,7 +289,7 @@ ControlBindings::port_value_to_control(RunContext& context, } if (port->is_logarithmic()) { - normal = logf(normal * ((float)M_E - 1.0f) + 1.0f); + normal = logf(normal * (static_cast<float>(M_E) - 1.0f) + 1.0f); } switch (type) { @@ -367,7 +370,7 @@ ControlBindings::finish_learn(RunContext& context, Key key) LV2_Atom buf[16]; memset(buf, 0, sizeof(buf)); - lv2_atom_forge_set_buffer(&_forge, (uint8_t*)buf, sizeof(buf)); + lv2_atom_forge_set_buffer(&_forge, reinterpret_cast<uint8_t*>(buf), sizeof(buf)); forge_binding(uris, &_forge, key.type, key.num); const LV2_Atom* atom = buf; context.notify(uris.midi_binding, @@ -412,7 +415,7 @@ ControlBindings::pre_process(RunContext& ctx, Buffer* buffer) auto* seq = buffer->get<LV2_Atom_Sequence>(); LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { if (ev->body.type == uris.midi_MidiEvent) { - const auto* buf = (const uint8_t*)LV2_ATOM_BODY(&ev->body); + const auto* buf = static_cast<const uint8_t*>(LV2_ATOM_BODY(&ev->body)); const Key key = midi_event_key(ev->body.size, buf, value); if (_learn_binding && !!key) { diff --git a/src/server/FrameTimer.hpp b/src/server/FrameTimer.hpp index 57acbaa5..344ed201 100644 --- a/src/server/FrameTimer.hpp +++ b/src/server/FrameTimer.hpp @@ -37,11 +37,13 @@ public: static constexpr double us_per_s = 1000000.0; FrameTimer(uint32_t period_size, uint32_t sample_rate) - : tper(((double)period_size / (double)sample_rate) * us_per_s) - , omega(2 * PI * bandwidth / us_per_s * tper) - , b(sqrt(2) * omega) - , c(omega * omega) - , nper(period_size) + : tper((static_cast<double>(period_size) / + static_cast<double>(sample_rate)) * + us_per_s) + , omega(2 * PI * bandwidth / us_per_s * tper) + , b(sqrt(2) * omega) + , c(omega * omega) + , nper(period_size) { } @@ -53,7 +55,7 @@ public: } // Calculate loop error - const double e = ((double)usec - t1); + const double e = (static_cast<double>(usec) - t1); // Update loop t0 = t1; @@ -71,7 +73,7 @@ public: return 0; } - const double delta = (double)usec - t0; + const double delta = static_cast<double>(usec) - t0; const double period = t1 - t0; return n0 + std::round(delta / period * nper); } diff --git a/src/server/JackDriver.cpp b/src/server/JackDriver.cpp index 6d15f3a8..af4dde8f 100644 --- a/src/server/JackDriver.cpp +++ b/src/server/JackDriver.cpp @@ -122,7 +122,7 @@ JackDriver::attach(const std::string& server_name, return false; } } else { - _client = (jack_client_t*)jack_client; + _client = static_cast<jack_client_t*>(jack_client); } _sample_rate = jack_get_sample_rate(_client); @@ -223,7 +223,7 @@ JackDriver::add_port(RunContext& context, EnginePort* port) DuplexPort* graph_port = port->graph_port(); if (graph_port->is_a(PortType::AUDIO) || graph_port->is_a(PortType::CV)) { const SampleCount nframes = context.nframes(); - jack_port_t* jport = (jack_port_t*)port->handle(); + jack_port_t* jport = static_cast<jack_port_t*>(port->handle()); void* jbuf = jack_port_get_buffer(jport, nframes); /* Jack fails to return a buffer if this is too soon after registering @@ -267,7 +267,7 @@ JackDriver::register_port(EnginePort& port) void JackDriver::unregister_port(EnginePort& port) { - if (jack_port_unregister(_client, (jack_port_t*)port.handle())) { + if (jack_port_unregister(_client, static_cast<jack_port_t*>(port.handle()))) { _engine.log().error("Failed to unregister Jack port\n"); } @@ -281,8 +281,9 @@ JackDriver::rename_port(const Raul::Path& old_path, EnginePort* eport = get_port(old_path); if (eport) { #ifdef HAVE_JACK_PORT_RENAME - jack_port_rename( - _client, (jack_port_t*)eport->handle(), new_path.substr(1).c_str()); + jack_port_rename(_client, + static_cast<jack_port_t*>(eport->handle()), + new_path.substr(1).c_str()); #else jack_port_set_name((jack_port_t*)eport->handle(), new_path.substr(1).c_str()); @@ -298,7 +299,9 @@ JackDriver::port_property(const Raul::Path& path, #ifdef HAVE_JACK_METADATA EnginePort* eport = get_port(path); if (eport) { - const jack_port_t* const jport = (const jack_port_t*)eport->handle(); + const jack_port_t* const jport = + static_cast<const jack_port_t*>(eport->handle()); + port_property_internal(jport, uri, value); } #endif @@ -352,7 +355,7 @@ JackDriver::pre_process_port(RunContext& context, EnginePort* port) { const URIs& uris = context.engine().world().uris(); const SampleCount nframes = context.nframes(); - jack_port_t* jack_port = (jack_port_t*)port->handle(); + jack_port_t* jack_port = static_cast<jack_port_t*>(port->handle()); DuplexPort* graph_port = port->graph_port(); Buffer* graph_buf = graph_port->buffer(0).get(); void* jack_buf = jack_port_get_buffer(jack_port, nframes); @@ -387,7 +390,7 @@ JackDriver::post_process_port(RunContext& context, EnginePort* port) { const URIs& uris = context.engine().world().uris(); const SampleCount nframes = context.nframes(); - jack_port_t* jack_port = (jack_port_t*)port->handle(); + jack_port_t* jack_port = static_cast<jack_port_t*>(port->handle()); DuplexPort* graph_port = port->graph_port(); void* jack_buf = port->buffer(); @@ -405,7 +408,9 @@ JackDriver::post_process_port(RunContext& context, EnginePort* port) jack_midi_clear_buffer(jack_buf); LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { - const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY(&ev->body); + const uint8_t* buf = + static_cast<const uint8_t*>(LV2_ATOM_BODY(&ev->body)); + if (ev->body.type == _midi_event_type) { jack_midi_event_write( jack_buf, ev->time.frames, buf, ev->body.size); @@ -443,7 +448,10 @@ JackDriver::append_time_events(RunContext& context, // Build an LV2 position object to append to the buffer LV2_Atom pos_buf[16]; LV2_Atom_Forge_Frame frame; - lv2_atom_forge_set_buffer(&_forge, (uint8_t*)pos_buf, sizeof(pos_buf)); + lv2_atom_forge_set_buffer(&_forge, + reinterpret_cast<uint8_t*>(pos_buf), + sizeof(pos_buf)); + lv2_atom_forge_object(&_forge, &frame, 0, uris.time_Position); lv2_atom_forge_key(&_forge, uris.time_frame); lv2_atom_forge_long(&_forge, pos->frame); @@ -464,9 +472,11 @@ JackDriver::append_time_events(RunContext& context, } // Append position to buffer at offset 0 (start of this cycle) - LV2_Atom* lpos = (LV2_Atom*)pos_buf; - buffer.append_event( - 0, lpos->size, lpos->type, (const uint8_t*)LV2_ATOM_BODY_CONST(lpos)); + LV2_Atom* lpos = static_cast<LV2_Atom*>(pos_buf); + buffer.append_event(0, + lpos->size, + lpos->type, + static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(lpos))); } /**** Jack Callbacks ****/ @@ -564,7 +574,7 @@ JackDriver::_session_cb(jack_session_event_t* event) URI(std::string("file://") + event->session_dir)); } - event->command_line = (char*)malloc(cmd.size() + 1); + event->command_line = static_cast<char*>(malloc(cmd.size() + 1)); memcpy(event->command_line, cmd.c_str(), cmd.size() + 1); jack_session_reply(_client, event); diff --git a/src/server/JackDriver.hpp b/src/server/JackDriver.hpp index 00b1836a..433fd21a 100644 --- a/src/server/JackDriver.hpp +++ b/src/server/JackDriver.hpp @@ -108,20 +108,20 @@ private: // Static JACK callbacks which call the non-static callbacks (methods) inline static void thread_init_cb(void* const jack_driver) { - return ((JackDriver*)jack_driver)->_thread_init_cb(); + return static_cast<JackDriver*>(jack_driver)->_thread_init_cb(); } inline static void shutdown_cb(void* const jack_driver) { - return ((JackDriver*)jack_driver)->_shutdown_cb(); + return static_cast<JackDriver*>(jack_driver)->_shutdown_cb(); } inline static int process_cb(jack_nframes_t nframes, void* const jack_driver) { - return ((JackDriver*)jack_driver)->_process_cb(nframes); + return static_cast<JackDriver*>(jack_driver)->_process_cb(nframes); } inline static int block_length_cb(jack_nframes_t nframes, void* const jack_driver) { - return ((JackDriver*)jack_driver)->_block_length_cb(nframes); + return static_cast<JackDriver*>(jack_driver)->_block_length_cb(nframes); } #ifdef INGEN_JACK_SESSION inline static void session_cb(jack_session_event_t* event, void* jack_driver) { - ((JackDriver*)jack_driver)->_session_cb(event); + static_cast<JackDriver*>(jack_driver)->_session_cb(event); } #endif diff --git a/src/server/LV2Block.cpp b/src/server/LV2Block.cpp index 124390ff..99f846a4 100644 --- a/src/server/LV2Block.cpp +++ b/src/server/LV2Block.cpp @@ -94,8 +94,8 @@ LV2Block::make_instance(URIs& uris, const LV2_Options_Interface* options_iface = nullptr; if (lilv_plugin_has_extension_data(lplug, uris.opt_interface)) { - options_iface = (const LV2_Options_Interface*) - lilv_instance_get_extension_data(inst, LV2_OPTIONS__interface); + options_iface = static_cast<const LV2_Options_Interface*>( + lilv_instance_get_extension_data(inst, LV2_OPTIONS__interface)); } for (uint32_t p = 0; p < num_ports(); ++p) { @@ -137,7 +137,7 @@ LV2Block::make_instance(URIs& uris, options_iface->get(inst->lv2_handle, options); if (options[0].value) { - LV2_URID type = *(const LV2_URID*)options[0].value; + LV2_URID type = *static_cast<const LV2_URID*>(options[0].value); if (type == _uris.lv2_ControlPort) { port->set_type(PortType::CONTROL, 0); } else if (type == _uris.lv2_CVPort) { @@ -460,9 +460,9 @@ LV2Block::instantiate(BufferFactory& bufs, const LilvState* state) // FIXME: Polyphony + worker? if (lilv_plugin_has_feature(plug, uris.work_schedule)) { - _worker_iface = (const LV2_Worker_Interface*) + _worker_iface = static_cast<const LV2_Worker_Interface*>( lilv_instance_get_extension_data(instance(0), - LV2_WORKER__interface); + LV2_WORKER__interface)); } return ret; @@ -558,7 +558,7 @@ LV2Block::work_respond(LV2_Worker_Respond_Handle handle, uint32_t size, const void* data) { - auto* block = (LV2Block*)handle; + auto* block = static_cast<LV2Block*>(handle); auto* r = new LV2Block::Response(size, data); block->_responses.push_back(*r); return LV2_WORKER_SUCCESS; @@ -673,7 +673,7 @@ get_port_value(const char* port_symbol, uint32_t* size, uint32_t* type) { - auto* const block = (LV2Block*)user_data; + auto* const block = static_cast<LV2Block*>(user_data); auto* const port = block->port_by_symbol(port_symbol); if (port && port->is_input() && port->value().is_valid()) { diff --git a/src/server/LV2Block.hpp b/src/server/LV2Block.hpp index 9b454b07..5ef8c69a 100644 --- a/src/server/LV2Block.hpp +++ b/src/server/LV2Block.hpp @@ -107,7 +107,7 @@ protected: bool preparing); inline LilvInstance* instance(uint32_t voice) { - return (LilvInstance*)(*_instances)[voice]->instance; + return static_cast<LilvInstance*>((*_instances)[voice]->instance); } using Instances = Raul::Array<SPtr<Instance>>; diff --git a/src/server/LV2Options.hpp b/src/server/LV2Options.hpp index fbe46eee..852a30a5 100644 --- a/src/server/LV2Options.hpp +++ b/src/server/LV2Options.hpp @@ -51,7 +51,7 @@ public: { LV2_OPTIONS_INSTANCE, 0, 0, 0, 0, nullptr } }; - LV2_Feature* f = (LV2_Feature*)malloc(sizeof(LV2_Feature)); + LV2_Feature* f = static_cast<LV2_Feature*>(malloc(sizeof(LV2_Feature))); f->URI = LV2_OPTIONS__options; f->data = malloc(sizeof(options)); memcpy(f->data, options, sizeof(options)); diff --git a/src/server/Load.hpp b/src/server/Load.hpp index 2d806684..f69d0659 100644 --- a/src/server/Load.hpp +++ b/src/server/Load.hpp @@ -40,7 +40,9 @@ struct Load mean = load; changed = true; } else { - const float a = mean + ((float)load - mean) / (float)++n; + const float a = mean + (static_cast<float>(load) - mean) / + static_cast<float>(++n); + if (a != mean) { changed = floorf(a) != floorf(mean); mean = a; diff --git a/src/server/NodeImpl.cpp b/src/server/NodeImpl.cpp index 47d4a990..7d13f07f 100644 --- a/src/server/NodeImpl.cpp +++ b/src/server/NodeImpl.cpp @@ -54,7 +54,7 @@ NodeImpl::get_property(const URI& key) const GraphImpl* NodeImpl::parent_graph() const { - return dynamic_cast<GraphImpl*>((BlockImpl*)_parent); + return dynamic_cast<GraphImpl*>(reinterpret_cast<BlockImpl*>(_parent)); } } // namespace server diff --git a/src/server/PortAudioDriver.cpp b/src/server/PortAudioDriver.cpp index 38b04842..de8c36cb 100644 --- a/src/server/PortAudioDriver.cpp +++ b/src/server/PortAudioDriver.cpp @@ -243,9 +243,14 @@ PortAudioDriver::pre_process_port(RunContext& context, } if (port->is_input()) { - port->set_buffer(((float**)inputs)[port->driver_index()]); + const float* const* const ins = + static_cast<const float* const*>(inputs); + + port->set_buffer(const_cast<float*>(ins[port->driver_index()])); } else { - port->set_buffer(((float**)outputs)[port->driver_index()]); + float* const* const outs = static_cast<float* const*>(inputs); + + port->set_buffer(outs[port->driver_index()]); memset(port->buffer(), 0, _block_length * sizeof(float)); } diff --git a/src/server/PortAudioDriver.hpp b/src/server/PortAudioDriver.hpp index 679223ad..3b7c6a94 100644 --- a/src/server/PortAudioDriver.hpp +++ b/src/server/PortAudioDriver.hpp @@ -88,7 +88,7 @@ private: const PaStreamCallbackTimeInfo* time, PaStreamCallbackFlags flags, void* handle) { - return ((PortAudioDriver*)handle)->process_cb( + return static_cast<PortAudioDriver*>(handle)->process_cb( inputs, outputs, nframes, time, flags); } diff --git a/src/server/PortImpl.cpp b/src/server/PortImpl.cpp index ab5e4ee8..7bbb5185 100644 --- a/src/server/PortImpl.cpp +++ b/src/server/PortImpl.cpp @@ -91,7 +91,7 @@ PortImpl::PortImpl(BufferFactory& bufs, set_type(type, buffer_type); remove_property(uris.lv2_index, uris.patch_wildcard); - set_property(uris.lv2_index, bufs.forge().make((int32_t)index)); + set_property(uris.lv2_index, bufs.forge().make(static_cast<int32_t>(index))); if (has_value()) { set_property(uris.ingen_value, value); @@ -249,7 +249,9 @@ PortImpl::set_voice_value(const RunContext& context, switch (_type.id()) { case PortType::CONTROL: if (buffer(voice)->value()) { - ((LV2_Atom_Float*)buffer(voice)->value())->body = value; + const_cast<LV2_Atom_Float*>( + reinterpret_cast<const LV2_Atom_Float*>(buffer(voice)->value())) + ->body = value; } _voices->at(voice).set_state.set(context, context.start(), value); break; @@ -277,7 +279,7 @@ PortImpl::set_voice_value(const RunContext& context, buffer(voice)->append_event(offset, sizeof(value), _bufs.uris().atom_Float, - (const uint8_t*)&value); + reinterpret_cast<const uint8_t*>(&value)); } _voices->at(voice).set_state.set(context, time, value); } else { @@ -319,7 +321,7 @@ PortImpl::update_set_state(const RunContext& context, uint32_t v) buf->clear(); buf->append_event( 0, sizeof(float), _bufs.uris().atom_Float, - (const uint8_t*)&state.value); + reinterpret_cast<const uint8_t*>(&state.value)); } else { buf->set_block(state.value, 0, context.nframes()); } @@ -483,7 +485,7 @@ PortImpl::monitor(RunContext& context, bool send_now) uninitialized Chunk, so do nothing. */ } else if (_monitored) { /* Sequence explicitly monitored, send everything. */ - const auto* seq = (const LV2_Atom_Sequence*)atom; + const auto* seq = reinterpret_cast<const LV2_Atom_Sequence*>(atom); LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { context.notify(uris.ingen_activity, context.start() + ev->time.frames, @@ -495,7 +497,7 @@ PortImpl::monitor(RunContext& context, bool send_now) } else if (value && value->type == _bufs.uris().atom_Float) { /* Float sequence, monitor as a control. */ key = uris.ingen_value; - val = ((const LV2_Atom_Float*)buffer(0)->value())->body; + val = reinterpret_cast<const LV2_Atom_Float*>(buffer(0)->value())->body; } else if (atom->size > sizeof(LV2_Atom_Sequence_Body)) { /* General sequence, send activity for blinkenlights. */ const int32_t one = 1; @@ -503,7 +505,7 @@ PortImpl::monitor(RunContext& context, bool send_now) context.start(), this, sizeof(int32_t), - (LV2_URID)uris.atom_Bool, + static_cast<LV2_URID>(uris.atom_Bool), &one); _force_monitor_update = false; } diff --git a/src/server/PortImpl.hpp b/src/server/PortImpl.hpp index 5392d9b7..bde5a946 100644 --- a/src/server/PortImpl.hpp +++ b/src/server/PortImpl.hpp @@ -99,7 +99,7 @@ public: GraphType graph_type() const override { return GraphType::PORT; } /** A port's parent is always a block, so static cast should be safe */ - BlockImpl* parent_block() const { return (BlockImpl*)_parent; } + BlockImpl* parent_block() const { return reinterpret_cast<BlockImpl*>(_parent); } /** Set the the voices (buffers) for this port in the audio thread. */ void set_voices(RunContext& context, MPtr<Voices>&& voices); diff --git a/src/server/PreProcessor.cpp b/src/server/PreProcessor.cpp index 61a3598e..33da71d7 100644 --- a/src/server/PreProcessor.cpp +++ b/src/server/PreProcessor.cpp @@ -149,11 +149,11 @@ PreProcessor::process(RunContext& context, PostProcessor& dest, size_t limit) const uint64_t start = engine.cycle_start_time(context); const uint64_t end = engine.current_time(); fprintf(stderr, "Processed %zu events in %u us\n", - n_processed, (unsigned)(end - start)); + n_processed, static_cast<unsigned>(end - start)); } #endif - auto* next = (Event*)last->next(); + auto* next = static_cast<Event*>(last->next()); last->next(nullptr); dest.append(context, head, last); @@ -245,7 +245,7 @@ PreProcessor::run() wait_for_block_state(BlockState::UNBLOCKED); } - back = (Event*)ev->next(); + back = static_cast<Event*>(ev->next()); } } diff --git a/src/server/RunContext.hpp b/src/server/RunContext.hpp index 9190d172..0ba4916b 100644 --- a/src/server/RunContext.hpp +++ b/src/server/RunContext.hpp @@ -101,7 +101,7 @@ public: * less time to avoid a dropout when running in real time). */ inline uint64_t duration() const { - return (uint64_t)_nframes * 1e6 / _rate; + return static_cast<uint64_t>(_nframes) * 1e6 / _rate; } inline void locate(FrameTime s, SampleCount nframes) { diff --git a/src/server/SocketListener.cpp b/src/server/SocketListener.cpp index b4b50a14..08a719fd 100644 --- a/src/server/SocketListener.cpp +++ b/src/server/SocketListener.cpp @@ -52,7 +52,7 @@ get_link_target(const char* link_path) } // Allocate buffer and read link target - char* target = (char*)calloc(1, link_stat.st_size + 1); + char* target = static_cast<char*>(calloc(1, link_stat.st_size + 1)); if (readlink(link_path, target, link_stat.st_size) != -1) { const std::string result(target); free(target); diff --git a/src/server/ThreadManager.hpp b/src/server/ThreadManager.hpp index 17f2c6ff..5f59208f 100644 --- a/src/server/ThreadManager.hpp +++ b/src/server/ThreadManager.hpp @@ -37,13 +37,13 @@ class INGEN_API ThreadManager { public: static inline void set_flag(ThreadFlag f) { #ifndef NDEBUG - flags = ((unsigned)flags | f); + flags = (static_cast<unsigned>(flags) | f); #endif } static inline void unset_flag(ThreadFlag f) { #ifndef NDEBUG - flags = ((unsigned)flags & (~f)); + flags = (static_cast<unsigned>(flags) & (~f)); #endif } diff --git a/src/server/UndoStack.cpp b/src/server/UndoStack.cpp index a94617a5..d9e00075 100644 --- a/src/server/UndoStack.cpp +++ b/src/server/UndoStack.cpp @@ -29,9 +29,9 @@ #include <iterator> #include <memory> -#define NS_RDF (const uint8_t*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#" +#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" -#define USTR(s) ((const uint8_t*)(s)) +#define USTR(s) reinterpret_cast<const uint8_t*>(s) namespace ingen { namespace server { @@ -62,22 +62,22 @@ UndoStack::ignore_later_event(const LV2_Atom* first, return false; } - const auto* f = (const LV2_Atom_Object*)first; - const auto* s = (const LV2_Atom_Object*)second; + const auto* f = reinterpret_cast<const LV2_Atom_Object*>(first); + const auto* s = reinterpret_cast<const LV2_Atom_Object*>(second); if (f->body.otype == _uris.patch_Set && f->body.otype == s->body.otype) { const LV2_Atom* f_subject = nullptr; const LV2_Atom* f_property = nullptr; const LV2_Atom* s_subject = nullptr; const LV2_Atom* s_property = nullptr; lv2_atom_object_get(f, - (LV2_URID)_uris.patch_subject, &f_subject, - (LV2_URID)_uris.patch_property, &f_property, + _uris.patch_subject.urid(), &f_subject, + _uris.patch_property.urid(), &f_property, 0); lv2_atom_object_get(s, - (LV2_URID)_uris.patch_subject, &s_subject, - (LV2_URID)_uris.patch_property, &s_property, + _uris.patch_subject.urid(), &s_subject, + _uris.patch_property.urid(), &s_property, 0); - return (lv2_atom_equals(f_subject, s_subject) && + return (lv2_atom_equals(f_subject, s_subject) && lv2_atom_equals(f_property, s_property)); } @@ -149,7 +149,7 @@ struct ListContext { const SerdNode node = start_node(writer); // node rdf:first value - p = serd_node_from_string(SERD_URI, NS_RDF "first"); + p = serd_node_from_string(SERD_URI, USTR(NS_RDF "first")); flags = SERD_LIST_CONT; serd_writer_write_statement(writer, flags|oflags, nullptr, &node, &p, value, nullptr, nullptr); @@ -159,12 +159,15 @@ struct ListContext { void end_node(SerdWriter*, const SerdNode* node) { // Prepare for next call: node rdf:rest ... s = *node; - p = serd_node_from_string(SERD_URI, NS_RDF "rest"); + p = serd_node_from_string(SERD_URI, USTR(NS_RDF "rest")); } void end(SerdWriter* writer) { - const SerdNode nil = serd_node_from_string(SERD_URI, NS_RDF "nil"); - serd_writer_write_statement(writer, flags, nullptr, &s, &p, &nil, nullptr, nullptr); + const SerdNode nil = + serd_node_from_string(SERD_URI, USTR(NS_RDF "nil")); + + serd_writer_write_statement( + writer, flags, nullptr, &s, &p, &nil, nullptr, nullptr); } BlankIDs& ids; @@ -195,7 +198,10 @@ UndoStack::write_entry(Sratom* sratom, for (const LV2_Atom* atom : entry.events) { const SerdNode node = ctx.start_node(writer); - p = serd_node_from_string(SERD_URI, NS_RDF "first"); + p = serd_node_from_string(SERD_URI, + reinterpret_cast<const uint8_t*>(NS_RDF + "first")); + ctx.flags = SERD_LIST_CONT; sratom_write(sratom, &_map.urid_unmap_feature()->urid_unmap, SERD_LIST_CONT, &node, &p, @@ -219,23 +225,25 @@ UndoStack::save(FILE* stream, const char* name) SerdURI base_uri; serd_uri_parse(base.buf, &base_uri); - SerdWriter* writer = serd_writer_new( - SERD_TURTLE, - (SerdStyle)(SERD_STYLE_RESOLVED|SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED), - env, - &base_uri, - serd_file_sink, - stream); + SerdWriter* writer = + serd_writer_new(SERD_TURTLE, + static_cast<SerdStyle>(SERD_STYLE_RESOLVED | + SERD_STYLE_ABBREVIATED | + SERD_STYLE_CURIED), + env, + &base_uri, + serd_file_sink, + stream); // Configure sratom to write directly to the writer (and thus the socket) Sratom* sratom = sratom_new(&_map.urid_map_feature()->urid_map); sratom_set_sink(sratom, - (const char*)base.buf, - (SerdStatementSink)serd_writer_write_statement, - (SerdEndSink)serd_writer_end_anon, + reinterpret_cast<const char*>(base.buf), + reinterpret_cast<SerdStatementSink>(serd_writer_write_statement), + reinterpret_cast<SerdEndSink>(serd_writer_end_anon), writer); - SerdNode s = serd_node_from_string(SERD_BLANK, (const uint8_t*)name); + SerdNode s = serd_node_from_string(SERD_BLANK, USTR(name)); SerdNode p = serd_node_from_string(SERD_URI, USTR(INGEN_NS "entries")); BlankIDs ids('u'); diff --git a/src/server/UndoStack.hpp b/src/server/UndoStack.hpp index 04021b99..92f32131 100644 --- a/src/server/UndoStack.hpp +++ b/src/server/UndoStack.hpp @@ -71,7 +71,7 @@ public: void push_event(const LV2_Atom* ev) { const uint32_t size = lv2_atom_total_size(ev); - LV2_Atom* copy = (LV2_Atom*)malloc(size); + LV2_Atom* copy = static_cast<LV2_Atom*>(malloc(size)); memcpy(copy, ev, size); events.push_front(copy); } diff --git a/src/server/Worker.cpp b/src/server/Worker.cpp index 68926278..e0d198d7 100644 --- a/src/server/Worker.cpp +++ b/src/server/Worker.cpp @@ -40,7 +40,7 @@ schedule(LV2_Worker_Schedule_Handle handle, uint32_t size, const void* data) { - auto* block = (LV2Block*)handle; + auto* block = static_cast<LV2Block*>(handle); Engine& engine = block->parent_graph()->engine(); return engine.worker()->request(block, size, data); @@ -51,7 +51,7 @@ schedule_sync(LV2_Worker_Schedule_Handle handle, uint32_t size, const void* data) { - auto* block = (LV2Block*)handle; + auto* block = static_cast<LV2Block*>(handle); Engine& engine = block->parent_graph()->engine(); return engine.sync_worker()->request(block, size, data); @@ -95,11 +95,12 @@ Worker::Schedule::feature(World&, Node* n) return SPtr<LV2_Feature>(); } - auto* data = (LV2_Worker_Schedule*)malloc(sizeof(LV2_Worker_Schedule)); + auto* data = static_cast<LV2_Worker_Schedule*>(malloc(sizeof(LV2_Worker_Schedule))); + data->handle = block; data->schedule_work = synchronous ? schedule_sync : schedule; - auto* f = (LV2_Feature*)malloc(sizeof(LV2_Feature)); + auto* f = static_cast<LV2_Feature*>(malloc(sizeof(LV2_Feature))); f->URI = LV2_WORKER__schedule; f->data = data; @@ -112,7 +113,7 @@ Worker::Worker(Log& log, uint32_t buffer_size, bool synchronous) , _sem(0) , _requests(buffer_size) , _responses(buffer_size) - , _buffer((uint8_t*)malloc(buffer_size)) + , _buffer(static_cast<uint8_t*>(malloc(buffer_size))) , _buffer_size(buffer_size) , _thread(nullptr) , _exit_flag(false) diff --git a/src/server/events/CreatePort.cpp b/src/server/events/CreatePort.cpp index d0dcbaf3..e6862731 100644 --- a/src/server/events/CreatePort.cpp +++ b/src/server/events/CreatePort.cpp @@ -172,8 +172,8 @@ CreatePort::pre_process(PreProcessContext&) _update = _graph_port->properties(); - assert(_graph_port->index() == (uint32_t)index_i->second.get<int32_t>()); - assert(_graph->num_ports_non_rt() == (uint32_t)old_n_ports + 1); + assert(_graph_port->index() == static_cast<uint32_t>(index_i->second.get<int32_t>())); + assert(_graph->num_ports_non_rt() == static_cast<uint32_t>(old_n_ports) + 1u); assert(_ports_array->size() == _graph->num_ports_non_rt()); assert(_graph_port->index() < _ports_array->size()); return Event::pre_process_done(Status::SUCCESS); diff --git a/src/server/events/Delete.cpp b/src/server/events/Delete.cpp index 5d605bca..f5f2e272 100644 --- a/src/server/events/Delete.cpp +++ b/src/server/events/Delete.cpp @@ -121,9 +121,9 @@ Delete::pre_process(PreProcessContext& ctx) _port_index_changes.emplace( port->path(), std::make_pair(port->index(), i)); port->remove_property(uris.lv2_index, uris.patch_wildcard); - port->set_property( - uris.lv2_index, - _engine.buffer_factory()->forge().make((int32_t)i)); + port->set_property(uris.lv2_index, + _engine.buffer_factory()->forge().make( + static_cast<int32_t>(i))); } } } diff --git a/src/server/events/Delta.cpp b/src/server/events/Delta.cpp index 0a7b05ea..eb70d046 100644 --- a/src/server/events/Delta.cpp +++ b/src/server/events/Delta.cpp @@ -148,7 +148,7 @@ s_add_set_event(const char* port_symbol, uint32_t size, uint32_t type) { - ((Delta*)user_data)->add_set_event(port_symbol, value, size, type); + static_cast<Delta*>(user_data)->add_set_event(port_symbol, value, size, type); } static LilvNode* diff --git a/src/server/events/SetPortValue.cpp b/src/server/events/SetPortValue.cpp index 2eecf9ce..f341737c 100644 --- a/src/server/events/SetPortValue.cpp +++ b/src/server/events/SetPortValue.cpp @@ -116,7 +116,7 @@ SetPortValue::apply(RunContext& context) if (!buf->append_event(_time - context.start(), _value.size(), _value.type(), - (const uint8_t*)_value.get_body())) { + reinterpret_cast<const uint8_t*>(_value.get_body()))) { _status = Status::NO_SPACE; } } else if (buf->type() == uris.atom_URID) { diff --git a/src/server/ingen_jack.cpp b/src/server/ingen_jack.cpp index 37aa9c7b..8421ed94 100644 --- a/src/server/ingen_jack.cpp +++ b/src/server/ingen_jack.cpp @@ -29,20 +29,23 @@ using namespace ingen; struct IngenJackModule : public ingen::Module { void load(ingen::World& world) override { - if (((server::Engine*)world.engine().get())->driver()) { + server::Engine* const engine = + static_cast<server::Engine*>(world.engine().get()); + + if (engine->driver()) { world.log().warn("Engine already has a driver\n"); return; } - server::JackDriver* driver = new server::JackDriver( - *(server::Engine*)world.engine().get()); - const Atom& s = world.conf().option("jack-server"); - const std::string server_name = s.is_valid() ? s.ptr<char>() : ""; + server::JackDriver* driver = new server::JackDriver(*engine); + const Atom& s = world.conf().option("jack-server"); + const std::string server_name = s.is_valid() ? s.ptr<char>() : ""; + driver->attach(server_name, world.conf().option("jack-name").ptr<char>(), nullptr); - ((server::Engine*)world.engine().get())->set_driver( - SPtr<server::Driver>(driver)); + + engine->set_driver(SPtr<server::Driver>(driver)); } }; diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp index 90bfaef3..e368d8f1 100644 --- a/src/server/ingen_lv2.cpp +++ b/src/server/ingen_lv2.cpp @@ -103,7 +103,8 @@ void signal_main(RunContext& context, LV2Driver* driver); inline size_t ui_ring_size(SampleCount block_length) { - return std::max((size_t)8192, (size_t)block_length * 16); + return std::max(static_cast<size_t>(8192u), + static_cast<size_t>(block_length) * 16u); } class LV2Driver : public ingen::server::Driver @@ -148,11 +149,17 @@ public: if (graph_port->is_a(PortType::AUDIO) || graph_port->is_a(PortType::CV)) { graph_port->set_driver_buffer(lv2_buf, nframes * sizeof(float)); } else if (graph_port->buffer_type() == uris.atom_Sequence) { - graph_port->set_driver_buffer(lv2_buf, lv2_atom_total_size((LV2_Atom*)lv2_buf)); + graph_port->set_driver_buffer(lv2_buf, + lv2_atom_total_size( + static_cast<LV2_Atom*>(lv2_buf))); + if (graph_port->symbol() == "control") { // TODO: Safe to use index? - LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)lv2_buf; - bool enqueued = false; - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + LV2_Atom_Sequence* seq = + reinterpret_cast<LV2_Atom_Sequence*>(lv2_buf); + + bool enqueued = false; + LV2_ATOM_SEQUENCE_FOREACH(seq, ev) + { if (AtomReader::is_message(uris, &ev->body)) { enqueued = enqueue_message(&ev->body) || enqueued; } @@ -186,7 +193,8 @@ public: _engine.locate(_frame_time, nframes); // Notify buffer is a Chunk with size set to the available space - _notify_capacity = ((LV2_Atom_Sequence*)_ports[1]->buffer())->atom.size; + _notify_capacity = + static_cast<LV2_Atom_Sequence*>(_ports[1]->buffer())->atom.size; for (auto& p : _ports) { pre_process_port(_engine.run_context(), p); @@ -261,15 +269,19 @@ public: void append_time_events(RunContext& context, Buffer& buffer) override { const URIs& uris = _engine.world().uris(); - LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)_ports[0]->buffer(); + LV2_Atom_Sequence* seq = + static_cast<LV2_Atom_Sequence*>(_ports[0]->buffer()); + LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { if (ev->body.type == uris.atom_Object) { - const LV2_Atom_Object* obj = (LV2_Atom_Object*)&ev->body; + const LV2_Atom_Object* obj = + reinterpret_cast<LV2_Atom_Object*>(&ev->body); + if (obj->body.otype == uris.time_Position) { buffer.append_event(ev->time.frames, ev->body.size, ev->body.type, - (const uint8_t*)(&ev->body + 1)); + reinterpret_cast<const uint8_t*>(&ev->body + 1)); } } } @@ -317,12 +329,14 @@ public: buf = realloc(buf, sizeof(LV2_Atom) + atom.size); memcpy(buf, &atom, sizeof(LV2_Atom)); - if (!_from_ui.read(atom.size, (char*)buf + sizeof(LV2_Atom))) { - _engine.log().rt_error("Error reading body from from-UI ring\n"); + if (!_from_ui.read(atom.size, + static_cast<char*>(buf) + sizeof(LV2_Atom))) { + _engine.log().rt_error( + "Error reading body from from-UI ring\n"); break; } - _reader.write((LV2_Atom*)buf); + _reader.write(static_cast<LV2_Atom*>(buf)); read += sizeof(LV2_Atom) + atom.size; } free(buf); @@ -334,7 +348,9 @@ public: return; } - LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)_ports[1]->buffer(); + LV2_Atom_Sequence* seq = + static_cast<LV2_Atom_Sequence*>(_ports[1]->buffer()); + if (!seq) { _engine.log().rt_error("Notify output not connected\n"); return; @@ -358,8 +374,8 @@ public: break; // Output port buffer full, resume next time } - LV2_Atom_Event* ev = (LV2_Atom_Event*)( - (uint8_t*)seq + lv2_atom_total_size(&seq->atom)); + LV2_Atom_Event* ev = reinterpret_cast<LV2_Atom_Event*>( + reinterpret_cast<uint8_t*>(seq) + lv2_atom_total_size(&seq->atom)); ev->time.frames = 0; // TODO: Time? ev->body = atom; @@ -486,13 +502,13 @@ ingen_instantiate(const LV2_Descriptor* descriptor, const LV2_Options_Option* options = nullptr; for (int i = 0; features[i]; ++i) { if (!strcmp(features[i]->URI, LV2_URID__map)) { - map = (LV2_URID_Map*)features[i]->data; + map = static_cast<LV2_URID_Map*>(features[i]->data); } else if (!strcmp(features[i]->URI, LV2_URID__unmap)) { - unmap = (LV2_URID_Unmap*)features[i]->data; + unmap = static_cast<LV2_URID_Unmap*>(features[i]->data); } else if (!strcmp(features[i]->URI, LV2_LOG__log)) { - log = (LV2_Log_Log*)features[i]->data; + log = static_cast<LV2_Log_Log*>(features[i]->data); } else if (!strcmp(features[i]->URI, LV2_OPTIONS__options)) { - options = (const LV2_Options_Option*)features[i]->data; + options = static_cast<const LV2_Options_Option*>(features[i]->data); } } @@ -509,10 +525,14 @@ ingen_instantiate(const LV2_Descriptor* descriptor, set_bundle_path(bundle_path); const std::string manifest_path = ingen::bundle_file_path("manifest.ttl"); - SerdNode manifest_node = serd_node_new_file_uri( - (const uint8_t*)manifest_path.c_str(), nullptr, nullptr, true); - - Lib::Graphs graphs = find_graphs(URI((const char*)manifest_node.buf)); + SerdNode manifest_node = + serd_node_new_file_uri(reinterpret_cast<const uint8_t*>( + manifest_path.c_str()), + nullptr, + nullptr, + true); + + Lib::Graphs graphs = find_graphs(URI(reinterpret_cast<const char*>(manifest_node.buf))); serd_node_free(&manifest_node); const LV2Graph* graph = nullptr; @@ -541,9 +561,9 @@ ingen_instantiate(const LV2_Descriptor* descriptor, if (options) { for (const LV2_Options_Option* o = options; o->key; ++o) { if (o->key == bufsz_max && o->type == atom_Int) { - block_length = *(const int32_t*)o->value; + block_length = *static_cast<const int32_t*>(o->value); } else if (o->key == bufsz_seq && o->type == atom_Int) { - seq_size = *(const int32_t*)o->value; + seq_size = *static_cast<const int32_t*>(o->value); } } } @@ -607,7 +627,7 @@ ingen_instantiate(const LV2_Descriptor* descriptor, engine->register_client(client); driver->set_instantiated(true); - return (LV2_Handle)plugin; + return static_cast<LV2_Handle>(plugin); } static void @@ -615,8 +635,8 @@ ingen_connect_port(LV2_Handle instance, uint32_t port, void* data) { using namespace ingen::server; - IngenPlugin* me = (IngenPlugin*)instance; - server::Engine* engine = (server::Engine*)me->world->engine().get(); + IngenPlugin* me = static_cast<IngenPlugin*>(instance); + server::Engine* engine = static_cast<server::Engine*>(me->world->engine().get()); const SPtr<LV2Driver>& driver = static_ptr_cast<LV2Driver>(engine->driver()); if (port < driver->ports().size()) { driver->ports().at(port)->set_buffer(data); @@ -628,7 +648,7 @@ ingen_connect_port(LV2_Handle instance, uint32_t port, void* data) static void ingen_activate(LV2_Handle instance) { - IngenPlugin* me = (IngenPlugin*)instance; + IngenPlugin* me = static_cast<IngenPlugin*>(instance); SPtr<server::Engine> engine = static_ptr_cast<server::Engine>(me->world->engine()); const SPtr<LV2Driver>& driver = static_ptr_cast<LV2Driver>(engine->driver()); engine->activate(); @@ -638,7 +658,7 @@ ingen_activate(LV2_Handle instance) static void ingen_run(LV2_Handle instance, uint32_t sample_count) { - IngenPlugin* me = (IngenPlugin*)instance; + IngenPlugin* me = static_cast<IngenPlugin*>(instance); SPtr<server::Engine> engine = static_ptr_cast<server::Engine>(me->world->engine()); const SPtr<LV2Driver>& driver = static_ptr_cast<LV2Driver>(engine->driver()); @@ -651,7 +671,7 @@ ingen_run(LV2_Handle instance, uint32_t sample_count) static void ingen_deactivate(LV2_Handle instance) { - IngenPlugin* me = (IngenPlugin*)instance; + IngenPlugin* me = static_cast<IngenPlugin*>(instance); me->world->engine()->deactivate(); if (me->main) { me->main->join(); @@ -662,7 +682,7 @@ ingen_deactivate(LV2_Handle instance) static void ingen_cleanup(LV2_Handle instance) { - IngenPlugin* me = (IngenPlugin*)instance; + IngenPlugin* me = static_cast<IngenPlugin*>(instance); me->world->set_engine(SPtr<ingen::server::Engine>()); me->world->set_interface(SPtr<ingen::Interface>()); if (me->main) { @@ -681,9 +701,9 @@ get_state_features(const LV2_Feature* const* features, { for (int i = 0; features[i]; ++i) { if (map && !strcmp(features[i]->URI, LV2_STATE__mapPath)) { - *map = (LV2_State_Map_Path*)features[i]->data; + *map = static_cast<LV2_State_Map_Path*>(features[i]->data); } else if (make && !strcmp(features[i]->URI, LV2_STATE__makePath)) { - *make = (LV2_State_Make_Path*)features[i]->data; + *make = static_cast<LV2_State_Make_Path*>(features[i]->data); } } } @@ -695,7 +715,7 @@ ingen_save(LV2_Handle instance, uint32_t flags, const LV2_Feature* const* features) { - IngenPlugin* plugin = (IngenPlugin*)instance; + IngenPlugin* plugin = static_cast<IngenPlugin*>(instance); LV2_State_Map_Path* map_path = nullptr; LV2_State_Make_Path* make_path = nullptr; @@ -742,7 +762,7 @@ ingen_restore(LV2_Handle instance, uint32_t flags, const LV2_Feature* const* features) { - IngenPlugin* plugin = (IngenPlugin*)instance; + IngenPlugin* plugin = static_cast<IngenPlugin*>(instance); LV2_State_Map_Path* map_path = nullptr; get_state_features(features, &map_path, nullptr); @@ -757,8 +777,8 @@ ingen_restore(LV2_Handle instance, uint32_t valflags; // Get abstract path to graph file - const char* path = (const char*)retrieve( - handle, ingen_file, &size, &type, &valflags); + const char* path = static_cast<const char*>( + retrieve(handle, ingen_file, &size, &type, &valflags)); if (!path) { return LV2_STATE_ERR_NO_PROPERTY; } @@ -821,10 +841,14 @@ Lib::Lib(const char* bundle_path) { ingen::set_bundle_path(bundle_path); const std::string manifest_path = ingen::bundle_file_path("manifest.ttl"); - SerdNode manifest_node = serd_node_new_file_uri( - (const uint8_t*)manifest_path.c_str(), nullptr, nullptr, true); + SerdNode manifest_node = + serd_node_new_file_uri(reinterpret_cast<const uint8_t*>( + manifest_path.c_str()), + nullptr, + nullptr, + true); - graphs = find_graphs(URI((const char*)manifest_node.buf)); + graphs = find_graphs(URI(reinterpret_cast<const char*>(manifest_node.buf))); serd_node_free(&manifest_node); } @@ -832,14 +856,14 @@ Lib::Lib(const char* bundle_path) static void lib_cleanup(LV2_Lib_Handle handle) { - Lib* lib = (Lib*)handle; + Lib* lib = static_cast<Lib*>(handle); delete lib; } static const LV2_Descriptor* lib_get_plugin(LV2_Lib_Handle handle, uint32_t index) { - Lib* lib = (Lib*)handle; + Lib* lib = static_cast<Lib*>(handle); return index < lib->graphs.size() ? &lib->graphs[index]->descriptor : nullptr; } @@ -853,7 +877,7 @@ lv2_lib_descriptor(const char* bundle_path, Lib* lib = new Lib(bundle_path); // FIXME: memory leak. I think the LV2_Lib_Descriptor API is botched :( - LV2_Lib_Descriptor* desc = (LV2_Lib_Descriptor*)malloc(desc_size); + LV2_Lib_Descriptor* desc = static_cast<LV2_Lib_Descriptor*>(malloc(desc_size)); desc->handle = lib; desc->size = desc_size; desc->cleanup = lib_cleanup; diff --git a/src/server/ingen_portaudio.cpp b/src/server/ingen_portaudio.cpp index f4e633d0..09229f91 100644 --- a/src/server/ingen_portaudio.cpp +++ b/src/server/ingen_portaudio.cpp @@ -28,16 +28,17 @@ using namespace ingen; struct IngenPortAudioModule : public ingen::Module { void load(ingen::World& world) override { - if (((server::Engine*)world.engine().get())->driver()) { + server::Engine* const engine = + static_cast<server::Engine*>(world.engine().get()); + + if (engine->driver()) { world.log().warn("Engine already has a driver\n"); return; } - server::PortAudioDriver* driver = new server::PortAudioDriver( - *(server::Engine*)world.engine().get()); + server::PortAudioDriver* driver = new server::PortAudioDriver(*engine); driver->attach(); - ((server::Engine*)world.engine().get())->set_driver( - SPtr<server::Driver>(driver)); + engine->set_driver(SPtr<server::Driver>(driver)); } }; diff --git a/src/server/internals/Controller.cpp b/src/server/internals/Controller.cpp index b8738e1e..1a6bb483 100644 --- a/src/server/internals/Controller.cpp +++ b/src/server/internals/Controller.cpp @@ -114,7 +114,7 @@ ControllerNode::run(RunContext& context) LV2_Atom_Sequence* seq = midi_in->get<LV2_Atom_Sequence>(); const BufferRef midi_out = _midi_out_port->buffer(0); LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { - const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY(&ev->body); + const uint8_t* buf = static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&ev->body)); if (ev->body.type == _midi_in_port->bufs().uris().midi_MidiEvent && ev->body.size >= 3 && lv2_midi_message_type(buf) == LV2_MIDI_MSG_CONTROLLER) { diff --git a/src/server/internals/Note.cpp b/src/server/internals/Note.cpp index cfc0c157..0d375eac 100644 --- a/src/server/internals/Note.cpp +++ b/src/server/internals/Note.cpp @@ -167,8 +167,12 @@ NoteNode::run(RunContext& context) Buffer* const midi_in = _midi_in_port->buffer(0).get(); LV2_Atom_Sequence* seq = midi_in->get<LV2_Atom_Sequence>(); LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { - const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY_CONST(&ev->body); - const FrameTime time = context.start() + (FrameTime)ev->time.frames; + const uint8_t* buf = + static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&ev->body)); + + const FrameTime time = + context.start() + static_cast<FrameTime>(ev->time.frames); + if (ev->body.type == _midi_in_port->bufs().uris().midi_MidiEvent && ev->body.size >= 3) { switch (lv2_midi_message_type(buf)) { @@ -198,8 +202,11 @@ NoteNode::run(RunContext& context) } break; case LV2_MIDI_MSG_BENDER: - bend(context, time, (((((uint16_t)buf[2] << 7) | buf[1]) - 8192.0f) - / 8192.0f)); + bend(context, + time, + ((((static_cast<uint16_t>(buf[2]) << 7) | buf[1]) - + 8192.0f) / + 8192.0f)); break; case LV2_MIDI_MSG_CHANNEL_PRESSURE: channel_pressure(context, time, buf[1] / 127.0f); @@ -218,7 +225,7 @@ static inline float note_to_freq(uint8_t num) { static const float A4 = 440.0f; - return A4 * powf(2.0f, (float)(num - 57.0f) / 12.0f); + return A4 * powf(2.0f, static_cast<float>(num - 57.0f) / 12.0f); } void @@ -286,7 +293,7 @@ NoteNode::note_on(RunContext& context, uint8_t note_num, uint8_t velocity, Frame assert(_keys[voice->note].voice == voice_num); _freq_port->set_voice_value(context, voice_num, time, note_to_freq(note_num)); - _num_port->set_voice_value(context, voice_num, time, (float)note_num); + _num_port->set_voice_value(context, voice_num, time, static_cast<float>(note_num)); _vel_port->set_voice_value(context, voice_num, time, velocity / 127.0f); _gate_port->set_voice_value(context, voice_num, time, 1.0f); if (!double_trigger) { diff --git a/src/server/internals/Trigger.cpp b/src/server/internals/Trigger.cpp index 4ceae3c8..f9c21438 100644 --- a/src/server/internals/Trigger.cpp +++ b/src/server/internals/Trigger.cpp @@ -115,7 +115,7 @@ TriggerNode::run(RunContext& context) LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { const int64_t t = ev->time.frames; - const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY(&ev->body); + const uint8_t* buf = static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&ev->body)); bool emit = false; if (ev->body.type == _midi_in_port->bufs().uris().midi_MidiEvent && ev->body.size >= 3) { @@ -156,7 +156,7 @@ TriggerNode::note_on(RunContext& context, uint8_t note_num, uint8_t velocity, Fr const uint32_t offset = time - context.start(); if (_learning) { - _note_port->set_control_value(context, time, (float)note_num); + _note_port->set_control_value(context, time, static_cast<float>(note_num)); _note_port->force_monitor_update(); _learning = false; } diff --git a/src/server/mix.cpp b/src/server/mix.cpp index 5f77eda2..e6f999f4 100644 --- a/src/server/mix.cpp +++ b/src/server/mix.cpp @@ -29,7 +29,7 @@ is_end(const Buffer* buf, const LV2_Atom_Event* ev) { const LV2_Atom* atom = buf->get<const LV2_Atom>(); return lv2_atom_sequence_is_end( - (const LV2_Atom_Sequence_Body*)LV2_ATOM_BODY_CONST(atom), + static_cast<const LV2_Atom_Sequence_Body*>(LV2_ATOM_BODY_CONST(atom)), atom->size, ev); } @@ -96,7 +96,7 @@ mix(const RunContext& context, if (first) { dst->append_event( first->time.frames, first->body.size, first->body.type, - (const uint8_t*)LV2_ATOM_BODY_CONST(&first->body)); + static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&first->body))); iters[first_i] = lv2_atom_sequence_next(first); if (is_end(srcs[first_i], iters[first_i])) { |