From f8fefe7d8e417c29537e8c9fa7703107d69f66b5 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 27 Sep 2022 16:53:57 -0400 Subject: Fix implicit integer conversions --- meson/suppressions/meson.build | 1 - src/gui/rgba.hpp | 2 +- src/server/ControlBindings.cpp | 29 ++++++++++++++++++----------- src/server/ControlBindings.hpp | 2 +- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/meson/suppressions/meson.build b/meson/suppressions/meson.build index 2f1a986a..b3884c18 100644 --- a/meson/suppressions/meson.build +++ b/meson/suppressions/meson.build @@ -27,7 +27,6 @@ if is_variable('cpp') '-Wno-format-nonliteral', '-Wno-global-constructors', '-Wno-implicit-float-conversion', - '-Wno-implicit-int-conversion', '-Wno-nullability-extension', '-Wno-padded', '-Wno-reserved-id-macro', diff --git a/src/gui/rgba.hpp b/src/gui/rgba.hpp index 18d904ac..0d2c57aa 100644 --- a/src/gui/rgba.hpp +++ b/src/gui/rgba.hpp @@ -35,7 +35,7 @@ rgba_to_uint(uint8_t r, uint8_t g, uint8_t b, uint8_t a) inline uint8_t mono_interpolate(uint8_t v1, uint8_t v2, float f) { - return static_cast(rintf((v2) * (f) + (v1) * (1 - (f)))); + return static_cast(rintf((v2) * (f) + (v1) * (1 - (f)))); } #define RGBA_R(x) (static_cast(x) >> 24) diff --git a/src/server/ControlBindings.cpp b/src/server/ControlBindings.cpp index e4f7e104..1ea417d2 100644 --- a/src/server/ControlBindings.cpp +++ b/src/server/ControlBindings.cpp @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -74,6 +75,12 @@ ControlBindings::port_binding(PortImpl* port) const return binding_key(binding); } +static int16_t +get_atom_num(const LV2_Atom* const atom) +{ + return static_cast(reinterpret_cast(atom)->body); +} + ControlBindings::Key ControlBindings::binding_key(const Atom& binding) const { @@ -93,7 +100,7 @@ ControlBindings::binding_key(const Atom& binding) const } else if (num->type != uris.atom_Int) { _engine.log().rt_error("Bender channel not an integer\n"); } else { - key = Key(Type::MIDI_BENDER, reinterpret_cast(num)->body); + key = Key(Type::MIDI_BENDER, get_atom_num(num)); } } else if (obj->otype == uris.midi_ChannelPressure) { lv2_atom_object_body_get(binding.size(), @@ -106,7 +113,7 @@ ControlBindings::binding_key(const Atom& binding) const } else if (num->type != uris.atom_Int) { _engine.log().rt_error("Pressure channel not an integer\n"); } else { - key = Key(Type::MIDI_CHANNEL_PRESSURE, reinterpret_cast(num)->body); + key = Key(Type::MIDI_CHANNEL_PRESSURE, get_atom_num(num)); } } else if (obj->otype == uris.midi_Controller) { lv2_atom_object_body_get(binding.size(), @@ -119,7 +126,7 @@ 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, reinterpret_cast(num)->body); + key = Key(Type::MIDI_CC, get_atom_num(num)); } } else if (obj->otype == uris.midi_NoteOn) { lv2_atom_object_body_get(binding.size(), @@ -132,7 +139,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, reinterpret_cast(num)->body); + key = Key(Type::MIDI_NOTE, get_atom_num(num)); } } } else if (binding.type()) { @@ -142,7 +149,7 @@ ControlBindings::binding_key(const Atom& binding) const } ControlBindings::Key -ControlBindings::midi_event_key(uint16_t, const uint8_t* buf, uint16_t& value) +ControlBindings::midi_event_key(const uint8_t* buf, uint16_t& value) { switch (lv2_midi_message_type(buf)) { case LV2_MIDI_MSG_CONTROLLER: @@ -150,7 +157,7 @@ ControlBindings::midi_event_key(uint16_t, const uint8_t* buf, uint16_t& value) return {Type::MIDI_CC, static_cast(((buf[0] & 0x0FU) << 8U) | buf[1])}; case LV2_MIDI_MSG_BENDER: - value = (buf[2] << 7U) + buf[1]; + value = static_cast((buf[2] << 7U) + buf[1]); return {Type::MIDI_BENDER, static_cast((buf[0] & 0x0FU))}; case LV2_MIDI_MSG_CHANNEL_PRESSURE: value = buf[1]; @@ -202,7 +209,7 @@ ControlBindings::port_value_changed(RunContext& ctx, case Type::MIDI_CC: size = 3; buf[0] = LV2_MIDI_MSG_CONTROLLER; - buf[1] = key.num; + buf[1] = static_cast(key.num); buf[2] = static_cast(value); break; case Type::MIDI_CHANNEL_PRESSURE: @@ -223,7 +230,7 @@ ControlBindings::port_value_changed(RunContext& ctx, } else if (value == 0) { buf[0] = LV2_MIDI_MSG_NOTE_OFF; } - buf[1] = key.num; + buf[1] = static_cast(key.num); buf[2] = 0x64; // MIDI spec default break; default: @@ -326,9 +333,9 @@ ControlBindings::port_value_to_control(RunContext& ctx, switch (type) { case Type::MIDI_CC: case Type::MIDI_CHANNEL_PRESSURE: - return lrintf(normal * 127.0f); + return static_cast(lrintf(normal * 127.0f)); case Type::MIDI_BENDER: - return lrintf(normal * 16383.0f); + return static_cast(lrintf(normal * 16383.0f)); case Type::MIDI_NOTE: return (value > 0.0f) ? 1 : 0; default: @@ -451,7 +458,7 @@ ControlBindings::pre_process(RunContext& ctx, Buffer* buffer) LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { if (ev->body.type == uris.midi_MidiEvent) { const auto* buf = static_cast(LV2_ATOM_BODY(&ev->body)); - const Key key = midi_event_key(ev->body.size, buf, value); + const Key key = midi_event_key(buf, value); if (_learn_binding && !!key) { finish_learn(ctx, key); // Learn new binding diff --git a/src/server/ControlBindings.hpp b/src/server/ControlBindings.hpp index b3b79c15..d72fd2fd 100644 --- a/src/server/ControlBindings.hpp +++ b/src/server/ControlBindings.hpp @@ -138,7 +138,7 @@ private: boost::intrusive::compare>; static Key - midi_event_key(uint16_t size, const uint8_t* buf, uint16_t& value); + midi_event_key(const uint8_t* buf, uint16_t& value); void set_port_value(RunContext& ctx, PortImpl* port, -- cgit v1.2.1