Skip to content

Commit

Permalink
Fix more missed warnings when building in linux
Browse files Browse the repository at this point in the history
Mostly more of the same of the previous commit.
Also removes a few missed checks for LIBREMIDI_HAS_SPAN since C++20 is the minimum now.

Signed-off-by: Gabe Gonzalez II <[email protected]>
  • Loading branch information
lilggamegenius authored and jcelerier committed Jan 10, 2024
1 parent 741a30f commit cc36bbf
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 107 deletions.
35 changes: 19 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ option(LIBREMIDI_FIND_BOOST "Actively look for Boost" OFF)
option(LIBREMIDI_EXAMPLES "Enable examples" OFF)
option(LIBREMIDI_TESTS "Enable tests" OFF)
option(LIBREMIDI_CI "To be enabled only in CI, some tests cannot run there" OFF)
option(LIBREMIDI_NO_WARNINGS "Disables warnings from library compilation" OFF)

### C++ features ###
if(NOT CMAKE_CXX_STANDARD)
Expand Down Expand Up @@ -178,22 +179,24 @@ else()
set(_private PRIVATE)
endif()

if(MSVC)
set(WARNING_FLAGS
/W4
)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
set(WARNING_FLAGS
-Werror # Turns all warnings into errors
-Wall # Enable most warning messages.
-Wextra # Print extra (possibly unwanted) warnings.
#-Wpedantic # Issue warnings needed for strict compliance to the standard.
)
else()
message(WARNING "CMake flags for compiler aren't set for compiler ${CMAKE_CXX_COMPILER_ID}")
endif()

target_compile_options(libremidi PUBLIC ${WARNING_FLAGS})
if(NOT LIBREMIDI_NO_WARNINGS)
if(MSVC)
set(WARNING_FLAGS
/W4
)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
set(WARNING_FLAGS
-Werror # Turns all warnings into errors
-Wall # Enable most warning messages.
-Wextra # Print extra (possibly unwanted) warnings.
#-Wpedantic # Issue warnings needed for strict compliance to the standard.
)
else()
message(WARNING "CMake flags for compiler aren't set for compiler ${CMAKE_CXX_COMPILER_ID}")
endif()

target_compile_options(libremidi PRIVATE ${WARNING_FLAGS})
endif ()

add_library(libremidi::libremidi ALIAS libremidi)

Expand Down
2 changes: 1 addition & 1 deletion include/libremidi/backends/alsa_raw/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct LIBREMIDI_EXPORT chunking_parameters
*/
std::function<bool(std::chrono::microseconds, int)> wait = chunking_parameters::default_wait;

static bool default_wait(std::chrono::microseconds time_to_wait, int written_bytes)
static bool default_wait(std::chrono::microseconds time_to_wait, int /*written_bytes*/)
{
std::this_thread::sleep_for(time_to_wait);
return true;
Expand Down
37 changes: 19 additions & 18 deletions include/libremidi/backends/alsa_raw/midi_in.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <alsa/asoundlib.h>

#include <atomic>
#include <thread>

namespace libremidi::alsa_raw
Expand Down Expand Up @@ -53,7 +52,7 @@ class midi_in_impl
[[nodiscard]] int do_init_port(const char* portname)
{
constexpr int mode = SND_RAWMIDI_NONBLOCK;
if (int err = snd.rawmidi.open(&midiport_, nullptr, portname, mode); err < 0)
if (const int err = snd.rawmidi.open(&midiport_, nullptr, portname, mode); err < 0)
{
error<driver_error>(this->configuration, "midi_in_alsa_raw::open_port: cannot open device.");
return err;
Expand All @@ -62,33 +61,33 @@ class midi_in_impl
snd_rawmidi_params_t* params{};
snd_rawmidi_params_alloca(&params);

if (int err = snd.rawmidi.params_current(midiport_, params); err < 0)
if (const int err = snd.rawmidi.params_current(midiport_, params); err < 0)
return err;
if (int err = snd.rawmidi.params_set_no_active_sensing(midiport_, params, 1); err < 0)
if (const int err = snd.rawmidi.params_set_no_active_sensing(midiport_, params, 1); err < 0)
return err;
#if LIBREMIDI_ALSA_HAS_RAWMIDI_TREAD
if (configuration.timestamps == timestamp_mode::NoTimestamp)
{
if (int err = snd.rawmidi.params_set_read_mode(midiport_, params, SND_RAWMIDI_READ_STANDARD);
if (const int err = snd.rawmidi.params_set_read_mode(midiport_, params, SND_RAWMIDI_READ_STANDARD);
err < 0)
return err;
if (int err = snd.rawmidi.params_set_clock_type(midiport_, params, SND_RAWMIDI_CLOCK_NONE);
if (const int err = snd.rawmidi.params_set_clock_type(midiport_, params, SND_RAWMIDI_CLOCK_NONE);
err < 0)
return err;
}
else
{
if (int err = snd.rawmidi.params_set_read_mode(midiport_, params, SND_RAWMIDI_READ_TSTAMP);
if (const int err = snd.rawmidi.params_set_read_mode(midiport_, params, SND_RAWMIDI_READ_TSTAMP);
err < 0)
return err;
if (int err
if (const int err
= snd.rawmidi.params_set_clock_type(midiport_, params, SND_RAWMIDI_CLOCK_MONOTONIC);
err < 0)
return err;
}
#endif

if (int err = snd.rawmidi.params(midiport_, params); err < 0)
if (const int err = snd.rawmidi.params(midiport_, params); err < 0)
return err;

return init_pollfd();
Expand All @@ -101,7 +100,7 @@ class midi_in_impl

[[nodiscard]] int init_pollfd()
{
int num_fds = snd.rawmidi.poll_descriptors_count(this->midiport_);
const int num_fds = snd.rawmidi.poll_descriptors_count(this->midiport_);

this->fds_.clear();
this->fds_.resize(num_fds);
Expand All @@ -119,7 +118,7 @@ class midi_in_impl
else
{
unsigned short res{};
int err
const int err
= snd.rawmidi.poll_descriptors_revents(this->midiport_, fds.data(), fds.size(), &res);
if (err < 0)
return err;
Expand Down Expand Up @@ -160,7 +159,7 @@ class midi_in_impl
case timestamp_mode::NoTimestamp:
break;
case timestamp_mode::Relative: {
auto t = int64_t(ts.tv_sec) * nanos + int64_t(ts.tv_nsec);
const auto t = static_cast<int64_t>(ts.tv_sec) * nanos + static_cast<int64_t>(ts.tv_nsec);
if (firstMessage == true)
{
firstMessage = false;
Expand All @@ -177,13 +176,15 @@ class midi_in_impl
case timestamp_mode::SystemMonotonic:
res = int64_t(ts.tv_sec) * nanos + int64_t(ts.tv_nsec);
break;
default:
break;
}
}

#if LIBREMIDI_ALSA_HAS_RAWMIDI_TREAD
int read_input_buffer_with_timestamps()
{
static const constexpr int nbytes = 1024;
static constexpr int nbytes = 1024;

unsigned char bytes[nbytes];
struct timespec ts;
Expand Down Expand Up @@ -236,10 +237,10 @@ class midi_in_alsa_raw_threaded : public midi_in_impl
}
}

~midi_in_alsa_raw_threaded()
~midi_in_alsa_raw_threaded() override
{
// Close a connection if it exists.
this->close_port();
this->midi_in_alsa_raw_threaded::close_port();
}

private:
Expand Down Expand Up @@ -292,9 +293,9 @@ class midi_in_alsa_raw_threaded : public midi_in_impl
return true;
}

bool open_port(const input_port& port, std::string_view name) override
bool open_port(const input_port& port, std::string_view /*name*/) override
{
if (int err = midi_in_impl::init_port(port); err < 0)
if (const int err = midi_in_impl::init_port(port); err < 0)
return false;
if (!start_thread())
return false;
Expand Down Expand Up @@ -347,7 +348,7 @@ class midi_in_alsa_raw_manual : public midi_in_impl
}
}

bool open_port(const input_port& p, std::string_view name) override
bool open_port(const input_port& p, std::string_view /*name*/) override
{
if (midi_in_impl::init_port(p) < 0)
return false;
Expand Down
6 changes: 3 additions & 3 deletions include/libremidi/backends/alsa_raw/midi_out.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class midi_out_impl final
const std::size_t chunk_size = std::min(get_chunk_size(), size);

// Send the first buffer
int len = chunk_size;
std::size_t len = chunk_size;

if (!write(data, len))
return;
Expand All @@ -156,10 +156,10 @@ class midi_out_impl final
return;

// Write more data
int len = end - data;
len = end - data;

// Maybe until the end of the sysex
if (auto sysex_end = (unsigned char*)memchr(data, 0xf7, len))
if (const auto sysex_end = static_cast<const unsigned char*>(memchr(data, 0xf7, len)))
len = sysex_end - data + 1;

if (len > chunk_size)
Expand Down
2 changes: 1 addition & 1 deletion include/libremidi/backends/alsa_seq/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ struct alsa_data
}

[[nodiscard]] int create_port(
auto& self, std::string_view portName, unsigned int caps, unsigned int type,
auto& /*self*/, std::string_view portName, unsigned int caps, unsigned int type,
std::optional<int> queue)
{
if (this->vport < 0)
Expand Down
10 changes: 5 additions & 5 deletions include/libremidi/backends/jack/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <weakjack/weak_libjack.h>
#elif __has_include(<weak_libjack.h>)
#include <weak_libjack.h>
#elif __has_include(<jack/jack.h>)
#elif __has_include(<jack/jack.h> )
#include <jack/jack.h>
#include <jack/midiport.h>
#include <jack/ringbuffer.h>
Expand Down Expand Up @@ -39,7 +39,7 @@ struct jack_client
}
else
{
auto short_name = jack_port_short_name(port);
const auto short_name = jack_port_short_name(port);
if (short_name && strlen(short_name) > 0)
return short_name;
return jack_port_name(port);
Expand All @@ -51,7 +51,7 @@ struct jack_client
-> std::conditional_t<Input, input_port, output_port>
{
return {{
.client = std::uintptr_t(client),
.client = reinterpret_cast<std::uintptr_t>(client),
.port = 0,
.manufacturer = "",
.device_name = "",
Expand All @@ -61,7 +61,7 @@ struct jack_client
}

template <bool Input>
static auto get_ports(jack_client_t* client, const char* pattern, JackPortFlags flags) noexcept
static auto get_ports(jack_client_t* client, const char* pattern, const JackPortFlags flags) noexcept
-> std::vector<std::conditional_t<Input, input_port, output_port>>
{
std::vector<std::conditional_t<Input, input_port, output_port>> ret;
Expand Down Expand Up @@ -214,7 +214,7 @@ struct jack_helpers : jack_client
if (portName.empty())
portName = flags & JackPortIsInput ? "i" : "o";

if (self.configuration.client_name.size() + portName.size() + 1 + 1 >= jack_port_name_size())
if (self.configuration.client_name.size() + portName.size() + 2u >= static_cast<size_t>(jack_port_name_size()))
{
self.template error<invalid_use_error>(
self.configuration, "JACK: port name length limit exceeded");
Expand Down
2 changes: 1 addition & 1 deletion include/libremidi/backends/jack/midi_in.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class midi_in_jack final
}

void set_timestamp(
jack_nframes_t frame, jack_nframes_t start_frames, jack_time_t abs_usec,
jack_nframes_t frame, jack_nframes_t start_frames, jack_time_t /*abs_usec*/,
libremidi::message& msg) noexcept
{
switch (configuration.timestamps)
Expand Down
16 changes: 8 additions & 8 deletions include/libremidi/backends/jack/midi_out.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ struct jack_queue
jack_ringbuffer_free(ringbuffer);
}

void write(const unsigned char* data, int32_t sz) noexcept
void write(const unsigned char* data, int32_t sz) const noexcept
{
if (sz + size_sz > ringbuffer_space)
if (static_cast<int32_t>(sz + size_sz) > ringbuffer_space)
return;

while (jack_ringbuffer_write_space(ringbuffer) < size_sz + sz)
while (jack_ringbuffer_write_space(ringbuffer) < sz + size_sz)
sched_yield();

jack_ringbuffer_write(ringbuffer, (char*)&sz, size_sz);
jack_ringbuffer_write(ringbuffer, (const char*)data, sz);
jack_ringbuffer_write(ringbuffer, reinterpret_cast<char*>(&sz), size_sz);
jack_ringbuffer_write(ringbuffer, reinterpret_cast<const char*>(data), sz);
}

void read(void* jack_events) noexcept
void read(void* jack_events) const noexcept
{
int32_t sz;
while (jack_ringbuffer_peek(ringbuffer, (char*)&sz, size_sz) == size_sz
while (jack_ringbuffer_peek(ringbuffer, reinterpret_cast<char*>(&sz), size_sz) == size_sz
&& jack_ringbuffer_read_space(ringbuffer) >= size_sz + sz)
{
jack_ringbuffer_read_advance(ringbuffer, size_sz);

if (auto midi = jack_midi_event_reserve(jack_events, 0, sz))
jack_ringbuffer_read(ringbuffer, (char*)midi, sz);
jack_ringbuffer_read(ringbuffer, reinterpret_cast<char*>(midi), sz);
else
jack_ringbuffer_read_advance(ringbuffer, sz);
}
Expand Down
4 changes: 2 additions & 2 deletions include/libremidi/backends/jack/observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ class observer_jack final

jack_set_port_rename_callback(
this->client,
+[](jack_port_id_t p, const char* old_name, const char* new_name, void* arg) {
auto& self = *(observer_jack*)arg;
+[](jack_port_id_t p, const char* /*old_name*/, const char* /*new_name*/, void* arg) {
const auto& self = *static_cast<observer_jack*>(arg);

auto port = jack_port_by_id(self.client, p);
if (!port)
Expand Down
4 changes: 2 additions & 2 deletions include/libremidi/backends/winmm/midi_in.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class midi_in_winmm final
bool do_open(unsigned int portNumber)
{
MMRESULT result = midiInOpen(
&this->inHandle, portNumber, reinterpret_cast<DWORD_PTR>(&midiInputCallback), reinterpret_cast<DWORD_PTR>(this),
&this->inHandle, portNumber, std::bit_cast<DWORD_PTR>(&midiInputCallback), std::bit_cast<DWORD_PTR>(this),
CALLBACK_FUNCTION);
if (result != MMSYSERR_NOERROR)
{
Expand All @@ -78,7 +78,7 @@ class midi_in_winmm final
this->sysexBuffer.resize(bufferCount);
for (std::size_t i = 0; i < bufferCount; ++i)
{
this->sysexBuffer[i] = reinterpret_cast<MIDIHDR*>(new char[sizeof(MIDIHDR)]);
this->sysexBuffer[i] = new MIDIHDR;
this->sysexBuffer[i]->lpData = new char[configuration.sysex_buffer_size];
this->sysexBuffer[i]->dwBufferLength = static_cast<DWORD>(configuration.sysex_buffer_size);
this->sysexBuffer[i]->dwUser = i; // We use the dwUser parameter as buffer indicator
Expand Down
2 changes: 1 addition & 1 deletion include/libremidi/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct client_configuration
//! Set a callback function to be invoked for incoming MIDI messages.
//! Mandatory!
std::function<void(const libremidi::input_port&, message&&)> on_message
= []([[maybe_unused]] const libremidi::input_port& port, libremidi::message&&) {};
= [](const libremidi::input_port& /*port*/, libremidi::message&&) {};

//! Observation callbacks for when ports are added or removed
input_port_callback input_added;
Expand Down
1 change: 1 addition & 0 deletions include/libremidi/cmidi2.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#ifndef CMIDI2_H_INCLUDED
#define CMIDI2_H_INCLUDED
#pragma GCC system_header // Todo: remove before commit

#include <stdbool.h>
#include <stdint.h>
Expand Down
Loading

0 comments on commit cc36bbf

Please sign in to comment.