diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..77f2779 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,10 @@ +Checks: '-*,performance-*,clang-*,boost-*,concurrency-*,portability-*,-boost-use-ranges,-performance-enum-size' +CheckOptions: + - { key: readability-identifier-naming.NamespaceCase, value: lower_case } + - { key: readability-identifier-naming.ClassCase, value: lower_case } + - { key: readability-identifier-naming.PrivateMemberPrefix, value: m_ } + - { key: readability-identifier-naming.StructCase, value: lower_case } + - { key: readability-identifier-naming.FunctionCase, value: lower_case } + - { key: readability-identifier-naming.VariableCase, value: lower_case } + - { key: readability-identifier-naming.GlobalConstantCase, value: lower_case } + diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..5112038 --- /dev/null +++ b/.clangd @@ -0,0 +1,7 @@ +Diagnostics: + ClangTidy: + Add: [performance*, boost*, clang*, concurrency*, portability*] + Remove: [modernize*, readability*, llvm-qualified-auto, misc-non-private-member-variables-in-classes, cppcoreguidelines-pro-type-reinterpret-cast, llvmlibc-*, altera-*, misc-no-recursion] +CompileFlags: + Add: -Wno-gnu-zero-variadic-macro-arguments + Remove: [-Wgnu-zero-variadic-macro-arguments, -mno-direct-extern-access] diff --git a/include/libremidi/backends/alsa_raw/config.hpp b/include/libremidi/backends/alsa_raw/config.hpp index 446ce9b..ace8343 100644 --- a/include/libremidi/backends/alsa_raw/config.hpp +++ b/include/libremidi/backends/alsa_raw/config.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include diff --git a/include/libremidi/backends/alsa_raw/helpers.hpp b/include/libremidi/backends/alsa_raw/helpers.hpp index 1783a5a..c47d80c 100644 --- a/include/libremidi/backends/alsa_raw/helpers.hpp +++ b/include/libremidi/backends/alsa_raw/helpers.hpp @@ -2,10 +2,17 @@ #include #include #include +#include -#include +#include + +#include +#include +#include +#include #include #include +#include #include // Credits: greatly inspired from diff --git a/include/libremidi/backends/alsa_raw/midi_in.hpp b/include/libremidi/backends/alsa_raw/midi_in.hpp index fda1b36..a3409fd 100644 --- a/include/libremidi/backends/alsa_raw/midi_in.hpp +++ b/include/libremidi/backends/alsa_raw/midi_in.hpp @@ -200,7 +200,7 @@ class midi_in_alsa_raw_threaded : public midi_in_impl midi_in_alsa_raw_threaded(input_configuration&& conf, alsa_raw_input_configuration&& apiconf) : midi_in_impl{std::move(conf), std::move(apiconf)} { - if (this->termination_event < 0) + if (this->m_termination_event < 0) { libremidi_handle_error(this->configuration, "error creating eventfd."); return; @@ -220,7 +220,7 @@ class midi_in_alsa_raw_threaded : public midi_in_impl private: void run_thread(auto parse_func) { - fds_.push_back(this->termination_event); + fds_.push_back(this->m_termination_event); const auto period = std::chrono::duration_cast(this->configuration.poll_period) .count(); @@ -233,7 +233,7 @@ class midi_in_alsa_raw_threaded : public midi_in_impl continue; else if (err < 0) return; - else if (termination_event.ready(fds_.back())) + else if (m_termination_event.ready(fds_.back())) break; err = do_read_events(parse_func, {fds_.data(), fds_.size() - 1}); @@ -250,11 +250,11 @@ class midi_in_alsa_raw_threaded : public midi_in_impl { if (configuration.timestamps == timestamp_mode::NoTimestamp) { - this->thread_ = std::thread{[this] { run_thread(&midi_in_impl::read_input_buffer); }}; + this->m_thread = std::thread{[this] { run_thread(&midi_in_impl::read_input_buffer); }}; } else { - this->thread_ = std::thread{ + this->m_thread = std::thread{ [this] { run_thread(&midi_in_impl::read_input_buffer_with_timestamps); }}; } return stdx::error{}; @@ -282,16 +282,16 @@ class midi_in_alsa_raw_threaded : public midi_in_impl stdx::error close_port() override { - termination_event.notify(); - if (thread_.joinable()) - thread_.join(); - termination_event.consume(); // Reset to zero + m_termination_event.notify(); + if (m_thread.joinable()) + m_thread.join(); + m_termination_event.consume(); // Reset to zero return midi_in_impl::close_port(); } - std::thread thread_; - eventfd_notifier termination_event{}; + std::thread m_thread; + eventfd_notifier m_termination_event{}; }; class midi_in_alsa_raw_manual : public midi_in_impl diff --git a/include/libremidi/backends/alsa_raw/observer.hpp b/include/libremidi/backends/alsa_raw/observer.hpp index 68f2afb..bb950da 100644 --- a/include/libremidi/backends/alsa_raw/observer.hpp +++ b/include/libremidi/backends/alsa_raw/observer.hpp @@ -31,24 +31,24 @@ class observer_impl_base if (!configuration.has_callbacks()) return; - fds[0] = this->udev; - fds[1] = termination_event; - fds[2] = timer_fd; + m_fds[0] = this->m_udev; + m_fds[1] = m_termination_event; + m_fds[2] = m_timer_fd; // Set-up initial state if (configuration.notify_in_constructor) this->check_devices(); // Start thread - thread = std::thread{[this] { this->run(); }}; + m_thread = std::thread{[this] { this->run(); }}; } ~observer_impl_base() { - termination_event.notify(); + m_termination_event.notify(); - if (thread.joinable()) - thread.join(); + if (m_thread.joinable()) + m_thread.join(); } std::vector get_input_ports() const noexcept override @@ -82,7 +82,7 @@ class observer_impl_base { for (;;) { - if (int err = poll(fds, 3, -1); err < 0) + if (int err = poll(m_fds, 3, -1); err < 0) { if (err == -EAGAIN) continue; @@ -91,41 +91,41 @@ class observer_impl_base } // Check udev - if (fds[0].revents & POLLIN) + if (m_fds[0].revents & POLLIN) { - udev_device* dev = udev.udev.monitor_receive_device(udev.monitor); + udev_device* dev = m_udev.udev.monitor_receive_device(m_udev.monitor); if (!dev) continue; - std::string_view act = udev.udev.device_get_action(dev); - std::string_view ss = udev.udev.device_get_subsystem(dev); + std::string_view act = m_udev.udev.device_get_action(dev); + std::string_view ss = m_udev.udev.device_get_subsystem(dev); if (!act.empty() && ss == "snd_seq") { if (act == "add" || act == "remove") { // Check every 100 milliseconds for ten seconds - this->timer_fd.restart(configuration.poll_period.count()); - timer_check_counts = 100; + this->m_timer_fd.restart(configuration.poll_period.count()); + m_timer_check_counts = 100; } } - udev.udev.device_unref(dev); + m_udev.udev.device_unref(dev); - fds[0].revents = 0; + m_fds[0].revents = 0; } // Check eventfd - if (fds[1].revents & POLLIN) + if (m_fds[1].revents & POLLIN) { break; } // Check timer - if (fds[2].revents & POLLIN) + if (m_fds[2].revents & POLLIN) { - if (this->timer_check_counts-- <= 0) - this->timer_fd.cancel(); - fds[2].revents = 0; + if (this->m_timer_check_counts-- <= 0) + this->m_timer_fd.cancel(); + m_fds[2].revents = 0; check_devices(); } @@ -133,7 +133,7 @@ class observer_impl_base } template - auto to_port_info(alsa_raw::alsa_raw_port_info p) const noexcept + auto to_port_info(const alsa_raw::alsa_raw_port_info& p) const noexcept -> std::conditional_t { return { @@ -151,7 +151,7 @@ class observer_impl_base new_devs.enumerate_cards(); - for (auto& in_prev : current_inputs) + for (auto& in_prev : m_current_inputs) { if (auto it = std::find(new_devs.inputs.begin(), new_devs.inputs.end(), in_prev); it == new_devs.inputs.end()) @@ -165,8 +165,8 @@ class observer_impl_base for (auto& in_next : new_devs.inputs) { - if (auto it = std::find(current_inputs.begin(), current_inputs.end(), in_next); - it == current_inputs.end()) + if (auto it = std::find(m_current_inputs.begin(), m_current_inputs.end(), in_next); + it == m_current_inputs.end()) { if (auto& cb = this->configuration.input_added) { @@ -175,7 +175,7 @@ class observer_impl_base } } - for (auto& out_prev : current_outputs) + for (auto& out_prev : m_current_outputs) { if (auto it = std::find(new_devs.outputs.begin(), new_devs.outputs.end(), out_prev); it == new_devs.outputs.end()) @@ -189,8 +189,8 @@ class observer_impl_base for (auto& out_next : new_devs.outputs) { - if (auto it = std::find(current_outputs.begin(), current_outputs.end(), out_next); - it == current_outputs.end()) + if (auto it = std::find(m_current_outputs.begin(), m_current_outputs.end(), out_next); + it == m_current_outputs.end()) { if (auto& cb = this->configuration.output_added) { @@ -198,19 +198,19 @@ class observer_impl_base } } } - current_inputs = std::move(new_devs.inputs); - current_outputs = std::move(new_devs.outputs); + m_current_inputs = std::move(new_devs.inputs); + m_current_outputs = std::move(new_devs.outputs); } - udev_helper udev{}; - eventfd_notifier termination_event{}; - timerfd_timer timer_fd{}; - int timer_check_counts = 0; - std::thread thread; - std::vector current_inputs; - std::vector current_outputs; + udev_helper m_udev{}; + eventfd_notifier m_termination_event{}; + timerfd_timer m_timer_fd{}; + int m_timer_check_counts = 0; + std::thread m_thread; + std::vector m_current_inputs; + std::vector m_current_outputs; - pollfd fds[3]{}; + pollfd m_fds[3]{}; }; } #else diff --git a/include/libremidi/backends/alsa_raw_ump/config.hpp b/include/libremidi/backends/alsa_raw_ump/config.hpp index 9674b2c..39c71b6 100644 --- a/include/libremidi/backends/alsa_raw_ump/config.hpp +++ b/include/libremidi/backends/alsa_raw_ump/config.hpp @@ -1,6 +1,9 @@ #pragma once #include +#include +#include + namespace libremidi::alsa_raw_ump { struct input_configuration diff --git a/include/libremidi/backends/alsa_raw_ump/helpers.hpp b/include/libremidi/backends/alsa_raw_ump/helpers.hpp index 5b16ca9..6c22ed5 100644 --- a/include/libremidi/backends/alsa_raw_ump/helpers.hpp +++ b/include/libremidi/backends/alsa_raw_ump/helpers.hpp @@ -3,6 +3,8 @@ #include #include +#include + namespace libremidi::alsa_raw_ump { struct midi2_enumerator : alsa_raw::enumerator diff --git a/include/libremidi/backends/alsa_raw_ump/midi_in.hpp b/include/libremidi/backends/alsa_raw_ump/midi_in.hpp index e4b1640..80724c0 100644 --- a/include/libremidi/backends/alsa_raw_ump/midi_in.hpp +++ b/include/libremidi/backends/alsa_raw_ump/midi_in.hpp @@ -194,7 +194,7 @@ class midi_in_impl_threaded : public midi_in_impl libremidi::ump_input_configuration&& conf, alsa_raw_ump::input_configuration&& apiconf) : midi_in_impl{std::move(conf), std::move(apiconf)} { - if (this->termination_event < 0) + if (this->m_termination_event < 0) { libremidi_handle_error(this->configuration, "error creating eventfd."); return; @@ -206,14 +206,14 @@ class midi_in_impl_threaded : public midi_in_impl ~midi_in_impl_threaded() { // Close a connection if it exists. - this->close_port(); + midi_in_impl_threaded::close_port(); client_open_ = std::errc::not_connected; } private: void run_thread(auto parse_func) { - fds_.push_back(this->termination_event); + fds_.push_back(this->m_termination_event); const auto period = std::chrono::duration_cast(this->configuration.poll_period) .count(); @@ -226,7 +226,7 @@ class midi_in_impl_threaded : public midi_in_impl continue; else if (err < 0) return; - else if (termination_event.ready(fds_.back())) + else if (m_termination_event.ready(fds_.back())) break; err = do_read_events(parse_func, {fds_.data(), fds_.size() - 1}); @@ -243,11 +243,11 @@ class midi_in_impl_threaded : public midi_in_impl { if (configuration.timestamps == timestamp_mode::NoTimestamp) { - this->thread_ = std::thread{[this] { run_thread(&midi_in_impl::read_input_buffer); }}; + this->m_thread = std::thread{[this] { run_thread(&midi_in_impl::read_input_buffer); }}; } else { - this->thread_ = std::thread{ + this->m_thread = std::thread{ [this] { run_thread(&midi_in_impl::read_input_buffer_with_timestamps); }}; } return stdx::error{}; @@ -275,16 +275,16 @@ class midi_in_impl_threaded : public midi_in_impl stdx::error close_port() override { - termination_event.notify(); - if (thread_.joinable()) - thread_.join(); - termination_event.consume(); // Reset to zero + m_termination_event.notify(); + if (m_thread.joinable()) + m_thread.join(); + m_termination_event.consume(); // Reset to zero return midi_in_impl::close_port(); } - std::thread thread_; - eventfd_notifier termination_event{}; + std::thread m_thread; + eventfd_notifier m_termination_event{}; }; class midi_in_impl_manual : public midi_in_impl @@ -299,7 +299,7 @@ class midi_in_impl_manual : public midi_in_impl ~midi_in_impl_manual() { // Close a connection if it exists. - this->close_port(); + midi_in_impl_manual::close_port(); client_open_ = std::errc::not_connected; } diff --git a/include/libremidi/backends/alsa_raw_ump/midi_out.hpp b/include/libremidi/backends/alsa_raw_ump/midi_out.hpp index f350cde..26c7155 100644 --- a/include/libremidi/backends/alsa_raw_ump/midi_out.hpp +++ b/include/libremidi/backends/alsa_raw_ump/midi_out.hpp @@ -1,12 +1,17 @@ #pragma once #include #include +#include #include +#include +#include #include -#include -#include +#include +#include +#include +#include namespace libremidi::alsa_raw_ump { diff --git a/include/libremidi/backends/alsa_seq/helpers.hpp b/include/libremidi/backends/alsa_seq/helpers.hpp index 0500a28..b7d50cf 100644 --- a/include/libremidi/backends/alsa_seq/helpers.hpp +++ b/include/libremidi/backends/alsa_seq/helpers.hpp @@ -58,7 +58,7 @@ inline constexpr std::pair seq_from_port_handle(port_handle p) noexcep inline void for_all_ports( const libasound& snd, snd_seq_t* seq, - std::function func) + const std::function& func) { snd_seq_client_info_t* cinfo{}; snd_seq_client_info_alloca(&cinfo); diff --git a/include/libremidi/backends/alsa_seq/midi_in.hpp b/include/libremidi/backends/alsa_seq/midi_in.hpp index 8065097..27625bd 100644 --- a/include/libremidi/backends/alsa_seq/midi_in.hpp +++ b/include/libremidi/backends/alsa_seq/midi_in.hpp @@ -353,7 +353,7 @@ class midi_in_alsa_threaded : public midi_in_impl{std::move(conf), std::move(apiconf)} { - if (this->termination_event < 0) + if (this->m_termination_event < 0) { this->libremidi_handle_error(this->configuration, "error creating eventfd."); return; @@ -364,7 +364,7 @@ class midi_in_alsa_threaded : public midi_in_implclose_port(); + midi_in_alsa_threaded::close_port(); this->client_open_ = std::errc::not_connected; } @@ -399,7 +399,7 @@ class midi_in_alsa_threaded : public midi_in_implthread = std::thread([this] { thread_handler(); }); + this->m_thread = std::thread([this] { thread_handler(); }); return stdx::error{}; } catch (const std::system_error& e) @@ -415,12 +415,12 @@ class midi_in_alsa_threaded : public midi_in_implthread.joinable()) - this->thread.join(); + if (this->m_thread.joinable()) + this->m_thread.join(); - termination_event.consume(); + m_termination_event.consume(); return stdx::error{}; } @@ -428,7 +428,7 @@ class midi_in_alsa_threaded : public midi_in_implseq, POLLIN) + 1; auto poll_fds = (struct pollfd*)alloca(poll_fd_count * sizeof(struct pollfd)); - poll_fds[0] = this->termination_event; + poll_fds[0] = this->m_termination_event; alsa_data::snd.seq.poll_descriptors(this->seq, poll_fds + 1, poll_fd_count - 1, POLLIN); const auto period @@ -442,7 +442,7 @@ class midi_in_alsa_threaded : public midi_in_impl= 0) { // We got our stop-thread signal - if (termination_event.ready(poll_fds[0])) + if (m_termination_event.ready(poll_fds[0])) { break; } @@ -467,8 +467,8 @@ class midi_in_alsa_threaded : public midi_in_impl @@ -497,7 +497,7 @@ class midi_in_alsa_manual : public midi_in_implclose_port(); } + ~midi_in_alsa_manual() { midi_in_alsa_manual::close_port(); } stdx::error open_port(const input_port& pt, std::string_view local_port_name) override { diff --git a/include/libremidi/backends/alsa_seq/midi_out.hpp b/include/libremidi/backends/alsa_seq/midi_out.hpp index 0eea4ba..aaa91cf 100644 --- a/include/libremidi/backends/alsa_seq/midi_out.hpp +++ b/include/libremidi/backends/alsa_seq/midi_out.hpp @@ -30,7 +30,7 @@ class midi_out_impl final return; } - if (snd.midi.event_new(this->bufferSize, &this->coder) < 0) + if (snd.midi.event_new(this->m_bufferSize, &this->coder) < 0) { libremidi_handle_error(this->configuration, "error initializing MIDI event parser."); return; @@ -68,8 +68,9 @@ class midi_out_impl final stdx::error open_port(const output_port& p, std::string_view portName) override { - unsigned int nSrc = this->get_port_count(SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE); - if (nSrc < 1) + unsigned int n_src + = this->get_port_count(SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE); + if (n_src < 1) { libremidi_handle_error(this->configuration, "no MIDI output sources found!"); return make_error_code(std::errc::no_such_device); @@ -122,9 +123,9 @@ class midi_out_impl final stdx::error send_message(const unsigned char* message, std::size_t size) override { int64_t result{}; - if (size > this->bufferSize) + if (size > this->m_bufferSize) { - this->bufferSize = size; + this->m_bufferSize = size; result = snd.midi.event_resize_buffer(this->coder, size); if (result != 0) { @@ -146,8 +147,8 @@ class midi_out_impl final // FIXME direct is set but snd_seq_event_output_direct is not used... snd_seq_ev_set_direct(&ev); - const int64_t nBytes = size; // signed to avoir potential overflow with size - offset below - result = snd.midi.event_encode(this->coder, message + offset, (long)(nBytes - offset), &ev); + const int64_t n_bytes = size; // signed to avoir potential overflow with size - offset below + result = snd.midi.event_encode(this->coder, message + offset, (long)(n_bytes - offset), &ev); if (result < 0) { libremidi_handle_warning(this->configuration, "event parsing error!"); @@ -174,6 +175,6 @@ class midi_out_impl final } private: - uint64_t bufferSize{32}; + uint64_t m_bufferSize{32}; }; } diff --git a/include/libremidi/backends/alsa_seq/observer.hpp b/include/libremidi/backends/alsa_seq/observer.hpp index ea8d75b..3bbbf43 100644 --- a/include/libremidi/backends/alsa_seq/observer.hpp +++ b/include/libremidi/backends/alsa_seq/observer.hpp @@ -131,7 +131,7 @@ class observer_impl } template - auto to_port_info(port_info p) const noexcept + auto to_port_info(const port_info& p) const noexcept -> std::conditional_t { static_assert(sizeof(this->seq) <= sizeof(libremidi::client_handle)); @@ -200,7 +200,7 @@ class observer_impl if (p.client == snd.seq.client_id(seq)) return; - knownClients_[{p.client, p.port}] = p; + m_knownClients[{p.client, p.port}] = p; if (p.isInput && configuration.input_added) { configuration.input_added(to_port_info(p)); @@ -214,11 +214,11 @@ class observer_impl void unregister_port(int client, int port) { - auto it = knownClients_.find({client, port}); - if (it != knownClients_.end()) + auto it = m_knownClients.find({client, port}); + if (it != m_knownClients.end()) { auto p = it->second; - knownClients_.erase(it); + m_knownClients.erase(it); if (p.isInput && configuration.input_removed) { @@ -263,7 +263,7 @@ class observer_impl } private: - std::map, port_info> knownClients_; + std::map, port_info> m_knownClients; }; template @@ -275,9 +275,9 @@ class observer_threaded : public observer_impl { // Create relevant descriptors auto& snd = alsa_data::snd; - const auto N = snd.seq.poll_descriptors_count(this->seq, POLLIN); - descriptors_.resize(N + 1); - snd.seq.poll_descriptors(this->seq, descriptors_.data(), N, POLLIN); + const auto n = snd.seq.poll_descriptors_count(this->seq, POLLIN); + descriptors_.resize(n + 1); + snd.seq.poll_descriptors(this->seq, descriptors_.data(), n, POLLIN); descriptors_.back() = this->termination_event; // Start the listening thread diff --git a/include/libremidi/backends/alsa_seq/shared_handler.hpp b/include/libremidi/backends/alsa_seq/shared_handler.hpp index f9434a0..580344c 100644 --- a/include/libremidi/backends/alsa_seq/shared_handler.hpp +++ b/include/libremidi/backends/alsa_seq/shared_handler.hpp @@ -61,7 +61,7 @@ struct shared_handler : public libremidi::shared_context { auto clt = std::make_shared(client_name); - auto cb = [client = std::weak_ptr{clt}](const libremidi::alsa_seq::poll_parameters& params) { + auto cb = [client = std::weak_ptr{clt}](libremidi::alsa_seq::poll_parameters params) { if (auto clt = client.lock()) { clt->events.push( @@ -74,8 +74,7 @@ struct shared_handler : public libremidi::shared_context auto stop_cb = [client = std::weak_ptr{clt}](snd_seq_addr_t id) { if (auto clt = client.lock()) { - clt->events.push( - {.type = shared_handler::event_type::callback_removed, .payload = std::move(id)}); + clt->events.push({.type = shared_handler::event_type::callback_removed, .payload = id}); clt->queue_event.notify(); } return true; @@ -134,7 +133,7 @@ struct shared_handler : public libremidi::shared_context break; } case callback_removed: - auto addr = std::move(*std::get_if(&ev.payload)); + auto addr = *std::get_if(&ev.payload); if (auto index = index_of_address(addr); index >= 0) { addresses.erase(addresses.begin() + index); @@ -146,15 +145,14 @@ struct shared_handler : public libremidi::shared_context } // Look for who's ready - for (int64_t i = 0, N = std::ssize(fds) - 2; i < N; i++) + for (int64_t i = 0, n = std::ssize(fds) - 2; i < n; i++) { if (fds[i].revents & POLLIN) { // Read alsa event snd_seq_event_t* ev{}; event_handle handle{snd}; - int result = 0; - while ((result = snd.seq.event_input(client, &ev)) > 0) + while (snd.seq.event_input(client, &ev) > 0) { handle.reset(ev); diff --git a/include/libremidi/backends/alsa_seq_ump/midi_out.hpp b/include/libremidi/backends/alsa_seq_ump/midi_out.hpp index 46760d6..3cfb063 100644 --- a/include/libremidi/backends/alsa_seq_ump/midi_out.hpp +++ b/include/libremidi/backends/alsa_seq_ump/midi_out.hpp @@ -64,8 +64,9 @@ class midi_out_impl final stdx::error open_port(const output_port& p, std::string_view portName) override { - unsigned int nSrc = this->get_port_count(SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE); - if (nSrc < 1) + unsigned int n_src + = this->get_port_count(SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE); + if (n_src < 1) { libremidi_handle_error(this->configuration, "no MIDI output sources found!"); return make_error_code(std::errc::no_such_device); @@ -133,7 +134,8 @@ class midi_out_impl final libremidi_handle_warning(this->configuration, "error sending MIDI message to port."); return static_cast(-ret); } - return std::errc{0}; + static_assert(std::errc{0} == std::errc{}); + return std::errc{}; }; segment_ump_stream(ump_stream, count, write_func, []() {}); diff --git a/include/libremidi/backends/dummy.hpp b/include/libremidi/backends/dummy.hpp index dd51b99..971e2ed 100644 --- a/include/libremidi/backends/dummy.hpp +++ b/include/libremidi/backends/dummy.hpp @@ -25,11 +25,12 @@ class midi_in_dummy final , public error_handler { public: - explicit midi_in_dummy(const input_configuration& configuration, input_api_configuration) + explicit midi_in_dummy(const input_configuration& configuration, const input_api_configuration&) { libremidi_handle_warning(configuration, "This class provides no functionality."); } - explicit midi_in_dummy(const ump_input_configuration& configuration, input_api_configuration) + explicit midi_in_dummy( + const ump_input_configuration& configuration, const input_api_configuration&) { libremidi_handle_warning(configuration, "This class provides no functionality."); } @@ -60,7 +61,8 @@ class midi_out_dummy final , public error_handler { public: - explicit midi_out_dummy(const output_configuration& configuration, output_api_configuration) + explicit midi_out_dummy( + const output_configuration& configuration, const output_api_configuration&) { libremidi_handle_warning(configuration, "This class provides no functionality."); } diff --git a/include/libremidi/backends/emscripten/midi_in.hpp b/include/libremidi/backends/emscripten/midi_in.hpp index 4833903..feacd37 100644 --- a/include/libremidi/backends/emscripten/midi_in.hpp +++ b/include/libremidi/backends/emscripten/midi_in.hpp @@ -31,7 +31,7 @@ class midi_in_emscripten final void on_input(double ts, unsigned char* begin, unsigned char* end); private: - int portNumber_{}; + int m_portNumber{}; midi1::input_state_machine m_processing{this->configuration}; }; diff --git a/include/libremidi/backends/emscripten/midi_out.hpp b/include/libremidi/backends/emscripten/midi_out.hpp index f6f2137..a62849d 100644 --- a/include/libremidi/backends/emscripten/midi_out.hpp +++ b/include/libremidi/backends/emscripten/midi_out.hpp @@ -28,6 +28,6 @@ class midi_out_emscripten final stdx::error send_message(const unsigned char* message, size_t size) override; private: - int portNumber_{-1}; + int m_portNumber{-1}; }; } diff --git a/include/libremidi/backends/jack/helpers.hpp b/include/libremidi/backends/jack/helpers.hpp index 60eee90..113d2b4 100644 --- a/include/libremidi/backends/jack/helpers.hpp +++ b/include/libremidi/backends/jack/helpers.hpp @@ -5,7 +5,9 @@ #include #include -#include +#include +#include +#include namespace libremidi { @@ -132,7 +134,7 @@ struct jack_helpers : jack_client {.token = this_instance, .callback = [&self, p = std::weak_ptr{this->port.impl}](jack_nframes_t nf) -> int { if (auto pt = p.lock()) - if (auto ppt = pt->load()) + if (pt->load()) self.process(nf); self.thread_lock.check_client_released(); diff --git a/include/libremidi/backends/jack/midi_in.hpp b/include/libremidi/backends/jack/midi_in.hpp index c51b9b6..c051c15 100644 --- a/include/libremidi/backends/jack/midi_in.hpp +++ b/include/libremidi/backends/jack/midi_in.hpp @@ -4,8 +4,6 @@ #include #include -#include - namespace libremidi { class midi_in_jack final @@ -96,8 +94,8 @@ class midi_in_jack final this->client, ¤t_frames, ¤t_usecs, &next_usecs, &period_usecs); // We have midi events in buffer - uint32_t evCount = jack_midi_get_event_count(buff); - for (uint32_t j = 0; j < evCount; j++) + uint32_t ev_count = jack_midi_get_event_count(buff); + for (uint32_t j = 0; j < ev_count; j++) { jack_midi_event_t event{}; jack_midi_event_get(&event, buff, j); diff --git a/include/libremidi/backends/jack/midi_out.hpp b/include/libremidi/backends/jack/midi_out.hpp index 7077541..1a2fd91 100644 --- a/include/libremidi/backends/jack/midi_out.hpp +++ b/include/libremidi/backends/jack/midi_out.hpp @@ -128,7 +128,7 @@ class midi_out_jack_queued final : public midi_out_jack public: midi_out_jack_queued(output_configuration&& conf, jack_output_configuration&& apiconf) : midi_out_jack{std::move(conf), std::move(apiconf)} - , queue{configuration.ringbuffer_size} + , m_queue{configuration.ringbuffer_size} { auto status = connect(*this); if (!this->client) @@ -150,7 +150,7 @@ class midi_out_jack_queued final : public midi_out_jack stdx::error send_message(const unsigned char* message, std::size_t size) override { - return queue.write(message, size); + return m_queue.write(message, size); } int process(jack_nframes_t nframes) @@ -158,13 +158,13 @@ class midi_out_jack_queued final : public midi_out_jack void* buff = jack_port_get_buffer(this->port, nframes); jack_midi_clear_buffer(buff); - this->queue.read(buff); + this->m_queue.read(buff); return 0; } private: - jack_queue queue; + jack_queue m_queue; }; class midi_out_jack_direct final : public midi_out_jack diff --git a/include/libremidi/backends/keyboard/config.hpp b/include/libremidi/backends/keyboard/config.hpp index efa565d..401728e 100644 --- a/include/libremidi/backends/keyboard/config.hpp +++ b/include/libremidi/backends/keyboard/config.hpp @@ -141,7 +141,7 @@ struct kbd_input_configuration // First argument is on key press, second on key release std::function set_input_scancode_callbacks - = [](scancode_callback, scancode_callback) { }; + = [](const scancode_callback&, const scancode_callback&) { }; std::map scancode_map #if defined(__APPLE__) diff --git a/include/libremidi/backends/linux/alsa.hpp b/include/libremidi/backends/linux/alsa.hpp index 2820d5e..f6ab94c 100644 --- a/include/libremidi/backends/linux/alsa.hpp +++ b/include/libremidi/backends/linux/alsa.hpp @@ -2,7 +2,7 @@ #include -#include +#include // IWYU pragma: export #if defined(SND_LIB_VERSION) #if __has_include() && SND_LIB_VERSION >= ((1 << 16) | (2 << 8) | 6) diff --git a/include/libremidi/backends/linux/pipewire.hpp b/include/libremidi/backends/linux/pipewire.hpp index c14bd39..4554e30 100644 --- a/include/libremidi/backends/linux/pipewire.hpp +++ b/include/libremidi/backends/linux/pipewire.hpp @@ -67,12 +67,12 @@ class libpipewire bool available{true}; private: - dylib_loader library; + dylib_loader m_library; libpipewire() - : library("libpipewire-0.3.so.0") + : m_library("libpipewire-0.3.so.0") { - if (!library) + if (!m_library) { available = false; return; @@ -81,52 +81,54 @@ class libpipewire // in terms of regex: // decltype\(&::([a-z_]+)\) [a-z_]+{}; // \1 = library.symbol("\1"); - init = library.symbol("pw_init"); - deinit = library.symbol("pw_deinit"); + init = m_library.symbol("pw_init"); + deinit = m_library.symbol("pw_deinit"); - context_new = library.symbol("pw_context_new"); - context_connect = library.symbol("pw_context_connect"); - context_destroy = library.symbol("pw_context_destroy"); + context_new = m_library.symbol("pw_context_new"); + context_connect = m_library.symbol("pw_context_connect"); + context_destroy = m_library.symbol("pw_context_destroy"); - core_disconnect = library.symbol("pw_core_disconnect"); + core_disconnect = m_library.symbol("pw_core_disconnect"); proxy_add_listener - = library.symbol("pw_proxy_add_listener"); - proxy_destroy = library.symbol("pw_proxy_destroy"); - - main_loop_new = library.symbol("pw_main_loop_new"); - main_loop_destroy = library.symbol("pw_main_loop_destroy"); - main_loop_quit = library.symbol("pw_main_loop_quit"); - main_loop_run = library.symbol("pw_main_loop_run"); + = m_library.symbol("pw_proxy_add_listener"); + proxy_destroy = m_library.symbol("pw_proxy_destroy"); + + main_loop_new = m_library.symbol("pw_main_loop_new"); + main_loop_destroy + = m_library.symbol("pw_main_loop_destroy"); + main_loop_quit = m_library.symbol("pw_main_loop_quit"); + main_loop_run = m_library.symbol("pw_main_loop_run"); main_loop_get_loop - = library.symbol("pw_main_loop_get_loop"); + = m_library.symbol("pw_main_loop_get_loop"); - properties_new = library.symbol("pw_properties_new"); - properties_free = library.symbol("pw_properties_free"); - properties_get = library.symbol("pw_properties_get"); + properties_new = m_library.symbol("pw_properties_new"); + properties_free = m_library.symbol("pw_properties_free"); + properties_get = m_library.symbol("pw_properties_get"); - filter_new_simple = library.symbol("pw_filter_new_simple"); + filter_new_simple + = m_library.symbol("pw_filter_new_simple"); filter_get_node_id - = library.symbol("pw_filter_get_node_id"); + = m_library.symbol("pw_filter_get_node_id"); filter_get_properties - = library.symbol("pw_filter_get_properties"); - filter_add_port = library.symbol("pw_filter_add_port"); + = m_library.symbol("pw_filter_get_properties"); + filter_add_port = m_library.symbol("pw_filter_add_port"); filter_remove_port - = library.symbol("pw_filter_remove_port"); - filter_update_properties - = library.symbol("pw_filter_update_properties"); + = m_library.symbol("pw_filter_remove_port"); + filter_update_properties = m_library.symbol( + "pw_filter_update_properties"); filter_update_params - = library.symbol("pw_filter_update_params"); - filter_get_time = library.symbol("pw_filter_get_time"); - filter_destroy = library.symbol("pw_filter_destroy"); - filter_connect = library.symbol("pw_filter_connect"); + = m_library.symbol("pw_filter_update_params"); + filter_get_time = m_library.symbol("pw_filter_get_time"); + filter_destroy = m_library.symbol("pw_filter_destroy"); + filter_connect = m_library.symbol("pw_filter_connect"); filter_get_dsp_buffer - = library.symbol("pw_filter_get_dsp_buffer"); + = m_library.symbol("pw_filter_get_dsp_buffer"); filter_dequeue_buffer - = library.symbol("pw_filter_dequeue_buffer"); + = m_library.symbol("pw_filter_dequeue_buffer"); filter_queue_buffer - = library.symbol("pw_filter_queue_buffer"); - filter_flush = library.symbol("pw_filter_flush"); + = m_library.symbol("pw_filter_queue_buffer"); + filter_flush = m_library.symbol("pw_filter_flush"); assert(init); assert(deinit); diff --git a/include/libremidi/backends/net/helpers.hpp b/include/libremidi/backends/net/helpers.hpp index 54d4879..11847fc 100644 --- a/include/libremidi/backends/net/helpers.hpp +++ b/include/libremidi/backends/net/helpers.hpp @@ -42,31 +42,34 @@ struct optionally_owned { public: explicit optionally_owned(T* maybe_existing) - : storage{.ref = maybe_existing} + : m_storage{.ref = maybe_existing} { - if (storage.ref) + if (m_storage.ref) { - ownership = unowned; + m_ownership = unowned; return; } else { - std::destroy_at(&storage.ref); - std::construct_at(reinterpret_cast(storage.object)); - ownership = owned; + std::destroy_at(&m_storage.ref); + std::construct_at(reinterpret_cast(m_storage.object)); + m_ownership = owned; } } ~optionally_owned() { if (is_owned()) - std::destroy_at(reinterpret_cast(storage.object)); + std::destroy_at(reinterpret_cast(m_storage.object)); } - T& get() noexcept { return *(is_owned() ? reinterpret_cast(&storage.object) : storage.ref); } + T& get() noexcept + { + return *(is_owned() ? reinterpret_cast(&m_storage.object) : m_storage.ref); + } const T& get() const noexcept { - return *(is_owned() ? reinterpret_cast(&storage.object) : storage.ref); + return *(is_owned() ? reinterpret_cast(&m_storage.object) : m_storage.ref); } optionally_owned(const optionally_owned&) = delete; @@ -74,18 +77,18 @@ struct optionally_owned optionally_owned& operator=(const optionally_owned&) = delete; optionally_owned& operator=(optionally_owned&&) noexcept = delete; - bool is_owned() const noexcept { return ownership == owned; } + bool is_owned() const noexcept { return m_ownership == owned; } private: union { alignas(T) unsigned char object[sizeof(T)]; T* ref; - } storage; + } m_storage; enum { owned, unowned - } ownership{}; + } m_ownership{}; }; } diff --git a/include/libremidi/backends/pipewire/context.hpp b/include/libremidi/backends/pipewire/context.hpp index b9a8635..b46459c 100644 --- a/include/libremidi/backends/pipewire/context.hpp +++ b/include/libremidi/backends/pipewire/context.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -123,7 +124,7 @@ struct pipewire_context } explicit pipewire_context(std::shared_ptr inst) - : global_instance{inst} + : global_instance{std::move(inst)} , owns_main_loop{true} { this->main_loop = pw.main_loop_new(nullptr); @@ -453,12 +454,12 @@ struct pipewire_filter }* port{}; explicit pipewire_filter(std::shared_ptr loop) - : loop{loop} + : loop{std::move(loop)} { } explicit pipewire_filter(std::shared_ptr loop, pw_filter* filter) - : loop{loop} + : loop{std::move(loop)} , filter{filter} { } diff --git a/include/libremidi/backends/pipewire/helpers.hpp b/include/libremidi/backends/pipewire/helpers.hpp index 8c2970c..5757d42 100644 --- a/include/libremidi/backends/pipewire/helpers.hpp +++ b/include/libremidi/backends/pipewire/helpers.hpp @@ -9,8 +9,6 @@ #include #include -#include -#include #include namespace libremidi diff --git a/include/libremidi/backends/pipewire/midi_out.hpp b/include/libremidi/backends/pipewire/midi_out.hpp index e8ae5c5..9d33cc0 100644 --- a/include/libremidi/backends/pipewire/midi_out.hpp +++ b/include/libremidi/backends/pipewire/midi_out.hpp @@ -5,8 +5,6 @@ #include -#include - namespace libremidi { class midi_out_pipewire diff --git a/include/libremidi/client.hpp b/include/libremidi/client.hpp index 068c496..5faa69f 100644 --- a/include/libremidi/client.hpp +++ b/include/libremidi/client.hpp @@ -4,6 +4,7 @@ #include #include +#include namespace libremidi::midi1 { @@ -66,8 +67,8 @@ class client } explicit client(const client_configuration& conf, shared_configurations ctx) - : configuration{conf} - , context{ctx} + : m_configuration{conf} + , m_context{std::move(ctx)} , m_observer{ observer_configuration{ .on_error = conf.on_error, @@ -81,10 +82,10 @@ class client .track_hardware = conf.track_hardware, .track_virtual = conf.track_virtual, .notify_in_constructor = false}, - context.observer} + m_context.observer} { - if (context.context) - context.context->start_processing(); + if (m_context.context) + m_context.context->start_processing(); } ~client() @@ -92,8 +93,8 @@ class client m_inputs.clear(); m_outputs.clear(); - if (context.context) - context.context->stop_processing(); + if (m_context.context) + m_context.context->stop_processing(); } std::vector get_input_ports() const noexcept @@ -116,19 +117,19 @@ class client input_configuration{ .on_message = [this, - port](libremidi::message&& m) { configuration.on_message(port, std::move(m)); }, + port](libremidi::message&& m) { m_configuration.on_message(port, std::move(m)); }, .on_raw_data = {}, .get_timestamp = {}, - .on_error = configuration.on_error, - .on_warning = configuration.on_warning, + .on_error = m_configuration.on_error, + .on_warning = m_configuration.on_warning, - .ignore_sysex = configuration.ignore_sysex, - .ignore_timing = configuration.ignore_timing, - .ignore_sensing = configuration.ignore_sensing, + .ignore_sysex = m_configuration.ignore_sysex, + .ignore_timing = m_configuration.ignore_timing, + .ignore_sensing = m_configuration.ignore_sensing, - .timestamps = configuration.timestamps}, - context.in); + .timestamps = m_configuration.timestamps}, + m_context.in); res.first->second.open_port(port, name); } @@ -141,11 +142,11 @@ class client auto res = m_outputs.try_emplace( port, output_configuration{ - .on_error = configuration.on_error, - .on_warning = configuration.on_warning, + .on_error = m_configuration.on_error, + .on_warning = m_configuration.on_warning, - .timestamps = configuration.timestamps}, - context.out); + .timestamps = m_configuration.timestamps}, + m_context.out); res.first->second.open_port(port, name); } @@ -190,8 +191,8 @@ class client } private: - client_configuration configuration; - shared_configurations context; + client_configuration m_configuration; + shared_configurations m_context; std::map m_inputs; std::map m_outputs; diff --git a/include/libremidi/detail/midi_stream_decoder.hpp b/include/libremidi/detail/midi_stream_decoder.hpp index b69fc6b..228bf0e 100644 --- a/include/libremidi/detail/midi_stream_decoder.hpp +++ b/include/libremidi/detail/midi_stream_decoder.hpp @@ -107,12 +107,12 @@ struct input_state_machine : input_state_machine_base { message.bytes.clear(); message.timestamp = {}; - state = main; + m_state = main; } bool has_finished_sysex(std::span bytes) const noexcept { - return (((bytes.front() == 0xF0) || (state == in_sysex)) && (bytes.back() == 0xF7)); + return (((bytes.front() == 0xF0) || (m_state == in_sysex)) && (bytes.back() == 0xF7)); } // Function to process a byte stream which may contain multiple successive @@ -139,22 +139,22 @@ struct input_state_machine : input_state_machine_base void on_bytes_multi_segmented( const message_callback& cb, std::span bytes, int64_t timestamp) { - int64_t nBytes = bytes.size(); - int64_t iByte = 0; + int64_t n_bytes = bytes.size(); + int64_t i_byte = 0; const bool finished_sysex = has_finished_sysex(bytes); - switch (state) + switch (m_state) { case in_sysex: { return on_continue_sysex(cb, bytes, finished_sysex); } case main: { - while (iByte < nBytes) + while (i_byte < n_bytes) { int64_t size = 1; // We are expecting that the next byte in the packet is a status // byte. - const auto status = bytes[iByte]; + const auto status = bytes[i_byte]; if (!(status & 0x80)) break; @@ -170,17 +170,17 @@ struct input_state_machine : input_state_machine_base if (configuration.ignore_sysex) { size = 0; - iByte = nBytes; + i_byte = n_bytes; } else { - size = nBytes - iByte; + size = n_bytes - i_byte; } - if (bytes[nBytes - 1] != 0xF7) + if (bytes[n_bytes - 1] != 0xF7) { // We know per CoreMIDI API there can't be anything else in this packet - state = in_sysex; + m_state = in_sysex; message.assign(bytes.begin(), bytes.begin() + size); message.timestamp = timestamp; return; @@ -192,7 +192,7 @@ struct input_state_machine : input_state_machine_base if (configuration.ignore_timing) { size = 0; - iByte += 2; + i_byte += 2; } else { @@ -209,7 +209,7 @@ struct input_state_machine : input_state_machine_base if (configuration.ignore_timing) { size = 0; - iByte += 1; + i_byte += 1; } else { @@ -222,7 +222,7 @@ struct input_state_machine : input_state_machine_base if (configuration.ignore_sensing) { size = 0; - iByte += 1; + i_byte += 1; } else { @@ -238,14 +238,14 @@ struct input_state_machine : input_state_machine_base // Now process the actual bytes of the message if (size > 0) { - auto begin = bytes.begin() + iByte; + auto begin = bytes.begin() + i_byte; message.assign(begin, begin + size); message.timestamp = timestamp; cb(std::move(message)); message.clear(); - iByte += size; + i_byte += size; } } } @@ -256,7 +256,7 @@ struct input_state_machine : input_state_machine_base const message_callback& cb, std::span bytes, bool finished_sysex) { if (finished_sysex) - state = main; + m_state = main; if (configuration.ignore_sysex) { @@ -283,7 +283,7 @@ struct input_state_machine : input_state_machine_base // SYSEX start case 0xF0: { if (!finished_sysex) - state = in_sysex; + m_state = in_sysex; if (!this->configuration.ignore_sysex) { @@ -328,7 +328,7 @@ struct input_state_machine : input_state_machine_base return; const bool finished_sysex = has_finished_sysex(bytes); - switch (state) + switch (m_state) { case in_sysex: return on_continue_sysex(cb, bytes, finished_sysex); @@ -346,7 +346,7 @@ struct input_state_machine : input_state_machine_base { main, in_sysex - } state{main}; + } m_state{main}; }; } diff --git a/include/libremidi/detail/semaphore.hpp b/include/libremidi/detail/semaphore.hpp index 255c45f..8cc0c56 100644 --- a/include/libremidi/detail/semaphore.hpp +++ b/include/libremidi/detail/semaphore.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include struct semaphore_pair_lock diff --git a/include/libremidi/libremidi.hpp b/include/libremidi/libremidi.hpp index 29533f2..da95ba7 100644 --- a/include/libremidi/libremidi.hpp +++ b/include/libremidi/libremidi.hpp @@ -84,7 +84,7 @@ class LIBREMIDI_EXPORT observer //! such as jack_observer_configuration, winmm_observer_configuration, etc... //! * if no callbacks are passed, no secondary thread will be created unless absolutely necessary explicit observer(const observer_configuration& conf = {}) noexcept; - explicit observer(observer_configuration conf, observer_api_configuration api_conf); + explicit observer(const observer_configuration& conf, observer_api_configuration api_conf); observer(const observer&) = delete; observer(observer&& other) noexcept; observer& operator=(const observer&) = delete; @@ -98,7 +98,7 @@ class LIBREMIDI_EXPORT observer [[nodiscard]] std::vector get_output_ports() const noexcept; private: - std::unique_ptr impl_; + std::unique_ptr m_impl; }; //! Main class for receiving MIDI 1.0 and 2.0 messages. @@ -111,15 +111,15 @@ class LIBREMIDI_EXPORT midi_in //! Construct a midi_in object with a configuration object for a specific MIDI 1 back-end //! see configuration.hpp for the available configuration types. //! An exception will be thrown if the requested back-end cannot be opened. - explicit midi_in(input_configuration conf, input_api_configuration api_conf); + explicit midi_in(const input_configuration& conf, const input_api_configuration& api_conf); //! Construct a midi_in object with the default MIDI 2 back-end for the platform - explicit midi_in(ump_input_configuration conf) noexcept; + explicit midi_in(const ump_input_configuration& conf) noexcept; //! Construct a midi_in object with a configuration object for a specific MIDI 2 back-end //! see configuration.hpp for the available configuration types. //! An exception will be thrown if the requested back-end cannot be opened. - explicit midi_in(ump_input_configuration conf, input_api_configuration api_conf); + explicit midi_in(const ump_input_configuration& conf, const input_api_configuration& api_conf); midi_in(const midi_in&) = delete; midi_in(midi_in&& other) noexcept; @@ -157,7 +157,7 @@ class LIBREMIDI_EXPORT midi_in timestamp absolute_timestamp() const noexcept; private: - std::unique_ptr impl_; + std::unique_ptr m_impl; }; //! Main class for sending MIDI 1.0 and 2.0 messages. @@ -170,7 +170,7 @@ class LIBREMIDI_EXPORT midi_out //! Construct a midi_out object with a configuration object for a specific back-end //! see configuration.hpp for the available configuration types. //! An exception will be thrown if the requested back-end cannot be opened. - explicit midi_out(output_configuration conf, output_api_configuration api_conf); + explicit midi_out(const output_configuration& conf, const output_api_configuration& api_conf); midi_out(const midi_out&) = delete; midi_out(midi_out&& other) noexcept; @@ -260,7 +260,7 @@ class LIBREMIDI_EXPORT midi_out stdx::error schedule_ump(int64_t timestamp, const uint32_t* message, size_t size) const; private: - std::unique_ptr impl_; + std::unique_ptr m_impl; }; } diff --git a/include/libremidi/message.hpp b/include/libremidi/message.hpp index f730549..e233a2f 100644 --- a/include/libremidi/message.hpp +++ b/include/libremidi/message.hpp @@ -251,12 +251,12 @@ struct meta_events int notated_32nd_notes_per_beat = 96) { int n = 1; - int powTwo = 0; + int pow_two = 0; while (n < denominator) { n <<= 1; - ++powTwo; + ++pow_two; } return { @@ -264,7 +264,7 @@ struct meta_events 0x58, 0x04, static_cast(numerator), - static_cast(powTwo), + static_cast(pow_two), static_cast(clocks_per_click), static_cast(notated_32nd_notes_per_beat)}; } diff --git a/include/libremidi/midi_in.cpp b/include/libremidi/midi_in.cpp index cd3c923..322ba31 100644 --- a/include/libremidi/midi_in.cpp +++ b/include/libremidi/midi_in.cpp @@ -162,19 +162,19 @@ make_midi1_in(const input_configuration& base_conf, const input_api_configuratio /// MIDI 1 constructors LIBREMIDI_INLINE midi_in::midi_in(const input_configuration& base_conf) noexcept - : impl_{make_midi1_in(base_conf)} + : m_impl{make_midi1_in(base_conf)} { } LIBREMIDI_INLINE -midi_in::midi_in(input_configuration base_conf, input_api_configuration api_conf) - : impl_{make_midi1_in(base_conf, api_conf)} +midi_in::midi_in(const input_configuration& base_conf, const input_api_configuration& api_conf) + : m_impl{make_midi1_in(base_conf, api_conf)} { - if (!impl_) + if (!m_impl) { error_handler e; e.libremidi_handle_error(base_conf, "Could not open midi in for the given api"); - impl_ = std::make_unique(input_configuration{}, dummy_configuration{}); + m_impl = std::make_unique(input_configuration{}, dummy_configuration{}); } } @@ -259,45 +259,45 @@ make_midi2_in(const ump_input_configuration& base_conf, const input_api_configur } /// MIDI 2 constructors -LIBREMIDI_INLINE midi_in::midi_in(ump_input_configuration base_conf) noexcept - : impl_{make_midi2_in(base_conf)} +LIBREMIDI_INLINE midi_in::midi_in(const ump_input_configuration& base_conf) noexcept + : m_impl{make_midi2_in(base_conf)} { } LIBREMIDI_INLINE -midi_in::midi_in(ump_input_configuration base_conf, input_api_configuration api_conf) - : impl_{make_midi2_in(base_conf, api_conf)} +midi_in::midi_in(const ump_input_configuration& base_conf, const input_api_configuration& api_conf) + : m_impl{make_midi2_in(base_conf, api_conf)} { - if (!impl_) + if (!m_impl) { error_handler e; e.libremidi_handle_error(base_conf, "Could not open midi in for the given api"); - impl_ = std::make_unique(input_configuration{}, dummy_configuration{}); + m_impl = std::make_unique(input_configuration{}, dummy_configuration{}); } } LIBREMIDI_INLINE midi_in::~midi_in() = default; LIBREMIDI_INLINE midi_in::midi_in(midi_in&& other) noexcept - : impl_{std::move(other.impl_)} + : m_impl{std::move(other.m_impl)} { - other.impl_ + other.m_impl = std::make_unique(input_configuration{}, dummy_configuration{}); } LIBREMIDI_INLINE stdx::error midi_in::set_port_name(std::string_view portName) { - if(impl_->is_port_open()) - return impl_->set_port_name(portName); + if (m_impl->is_port_open()) + return m_impl->set_port_name(portName); return std::errc::not_connected; } LIBREMIDI_INLINE midi_in& midi_in::operator=(midi_in&& other) noexcept { - this->impl_ = std::move(other.impl_); - other.impl_ + this->m_impl = std::move(other.m_impl); + other.m_impl = std::make_unique(input_configuration{}, dummy_configuration{}); return *this; } @@ -305,23 +305,23 @@ LIBREMIDI_INLINE midi_in& midi_in::operator=(midi_in&& other) noexcept LIBREMIDI_INLINE libremidi::API midi_in::get_current_api() const noexcept { - return impl_->get_current_api(); + return m_impl->get_current_api(); } LIBREMIDI_INLINE stdx::error midi_in::open_port(const input_port& port, std::string_view portName) { - if (auto err = impl_->is_client_open(); err != stdx::error{}) + if (auto err = m_impl->is_client_open(); err != stdx::error{}) return std::errc::not_connected; - if (impl_->is_port_open()) + if (m_impl->is_port_open()) return std::errc::operation_not_supported; - auto ret = impl_->open_port(port, portName); + auto ret = m_impl->open_port(port, portName); if (ret == stdx::error{}) { - impl_->connected_ = true; - impl_->port_open_ = true; + m_impl->connected_ = true; + m_impl->port_open_ = true; } return ret; } @@ -329,28 +329,28 @@ stdx::error midi_in::open_port(const input_port& port, std::string_view portName LIBREMIDI_INLINE stdx::error midi_in::open_virtual_port(std::string_view portName) { - if (auto err = impl_->is_client_open(); err != stdx::error{}) + if (auto err = m_impl->is_client_open(); err != stdx::error{}) return std::errc::not_connected; - if (impl_->is_port_open()) + if (m_impl->is_port_open()) return std::errc::operation_not_supported; - auto ret = impl_->open_virtual_port(portName); + auto ret = m_impl->open_virtual_port(portName); if (ret == stdx::error{}) - impl_->port_open_ = true; + m_impl->port_open_ = true; return ret; } LIBREMIDI_INLINE stdx::error midi_in::close_port() { - if (auto err = impl_->is_client_open(); err != stdx::error{}) + if (auto err = m_impl->is_client_open(); err != stdx::error{}) return std::errc::not_connected; - auto ret = impl_->close_port(); + auto ret = m_impl->close_port(); - impl_->connected_ = false; - impl_->port_open_ = false; + m_impl->connected_ = false; + m_impl->port_open_ = false; return ret; } @@ -358,18 +358,18 @@ stdx::error midi_in::close_port() LIBREMIDI_INLINE bool midi_in::is_port_open() const noexcept { - return impl_->is_port_open(); + return m_impl->is_port_open(); } LIBREMIDI_INLINE bool midi_in::is_port_connected() const noexcept { - return impl_->is_port_connected(); + return m_impl->is_port_connected(); } LIBREMIDI_INLINE int64_t midi_in::absolute_timestamp() const noexcept { - return impl_->absolute_timestamp(); + return m_impl->absolute_timestamp(); } } diff --git a/include/libremidi/midi_out.cpp b/include/libremidi/midi_out.cpp index e89b96d..d26bfb8 100644 --- a/include/libremidi/midi_out.cpp +++ b/include/libremidi/midi_out.cpp @@ -23,7 +23,8 @@ make_midi_out_impl(auto base_conf, output_api_configuration api_conf) return false; }; std::apply([&](auto&&... b) { (from_api(b) || ...); }, midi1::available_backends); - std::apply([&](auto&&... b) { (from_api(b) || ...); }, midi2::available_backends); + if (!ptr) + std::apply([&](auto&&... b) { (from_api(b) || ...); }, midi2::available_backends); return ptr; } @@ -85,35 +86,35 @@ make_midi_out(const output_configuration& base_conf, const output_api_configurat } LIBREMIDI_INLINE midi_out::midi_out(const output_configuration& base_conf) noexcept - : impl_{make_midi_out(base_conf)} + : m_impl{make_midi_out(base_conf)} { } LIBREMIDI_INLINE -midi_out::midi_out(output_configuration base_conf, output_api_configuration api_conf) - : impl_{make_midi_out(base_conf, api_conf)} +midi_out::midi_out(const output_configuration& base_conf, const output_api_configuration& api_conf) + : m_impl{make_midi_out(base_conf, api_conf)} { - if (!impl_) + if (!m_impl) { error_handler e; e.libremidi_handle_error(base_conf, "Could not open midi out for the given api"); - impl_ = std::make_unique(output_configuration{}, dummy_configuration{}); + m_impl = std::make_unique(output_configuration{}, dummy_configuration{}); } } LIBREMIDI_INLINE midi_out::~midi_out() = default; LIBREMIDI_INLINE midi_out::midi_out(midi_out&& other) noexcept - : impl_{std::move(other.impl_)} + : m_impl{std::move(other.m_impl)} { - other.impl_ + other.m_impl = std::make_unique(output_configuration{}, dummy_configuration{}); } LIBREMIDI_INLINE midi_out& midi_out::operator=(midi_out&& other) noexcept { - this->impl_ = std::move(other.impl_); - other.impl_ + this->m_impl = std::move(other.m_impl); + other.m_impl = std::make_unique(output_configuration{}, dummy_configuration{}); return *this; } @@ -121,8 +122,8 @@ LIBREMIDI_INLINE midi_out& midi_out::operator=(midi_out&& other) noexcept LIBREMIDI_INLINE stdx::error midi_out::set_port_name(std::string_view portName) const { - if(impl_->is_port_open()) - return impl_->set_port_name(portName); + if (m_impl->is_port_open()) + return m_impl->set_port_name(portName); return std::errc::not_connected; } @@ -130,23 +131,23 @@ stdx::error midi_out::set_port_name(std::string_view portName) const LIBREMIDI_INLINE libremidi::API midi_out::get_current_api() const noexcept { - return impl_->get_current_api(); + return m_impl->get_current_api(); } LIBREMIDI_INLINE stdx::error midi_out::open_port(const output_port& port, std::string_view portName) const { - if (auto err = impl_->is_client_open(); err != stdx::error{}) + if (auto err = m_impl->is_client_open(); err != stdx::error{}) return std::errc::not_connected; - if (impl_->is_port_open()) + if (m_impl->is_port_open()) return std::errc::operation_not_supported; - auto ret = impl_->open_port(port, portName); + auto ret = m_impl->open_port(port, portName); if (ret == stdx::error{}) { - impl_->connected_ = true; - impl_->port_open_ = true; + m_impl->connected_ = true; + m_impl->port_open_ = true; } return ret; } @@ -154,40 +155,40 @@ stdx::error midi_out::open_port(const output_port& port, std::string_view portNa LIBREMIDI_INLINE stdx::error midi_out::open_virtual_port(std::string_view portName) const { - if (auto err = impl_->is_client_open(); err != stdx::error{}) + if (auto err = m_impl->is_client_open(); err != stdx::error{}) return std::errc::not_connected; - if (impl_->is_port_open()) + if (m_impl->is_port_open()) return std::errc::operation_not_supported; - auto ret = impl_->open_virtual_port(portName); + auto ret = m_impl->open_virtual_port(portName); if (ret == stdx::error{}) - impl_->port_open_ = true; + m_impl->port_open_ = true; return ret; } LIBREMIDI_INLINE stdx::error midi_out::close_port() const { - if (auto err = impl_->is_client_open(); err != stdx::error{}) + if (auto err = m_impl->is_client_open(); err != stdx::error{}) return std::errc::not_connected; - auto ret = impl_->close_port(); - impl_->connected_ = false; - impl_->port_open_ = false; + auto ret = m_impl->close_port(); + m_impl->connected_ = false; + m_impl->port_open_ = false; return ret; } LIBREMIDI_INLINE bool midi_out::is_port_open() const noexcept { - return impl_->is_port_open(); + return m_impl->is_port_open(); } LIBREMIDI_INLINE bool midi_out::is_port_connected() const noexcept { - return impl_->is_port_connected(); + return m_impl->is_port_connected(); } LIBREMIDI_INLINE @@ -227,13 +228,13 @@ stdx::error midi_out::send_message(const unsigned char* message, size_t size) co assert(size > 0); #endif - return impl_->send_message(message, size); + return m_impl->send_message(message, size); } LIBREMIDI_INLINE int64_t midi_out::current_time() { - return impl_->current_time(); + return m_impl->current_time(); } LIBREMIDI_INLINE @@ -243,7 +244,7 @@ stdx::error midi_out::schedule_message(int64_t ts, const unsigned char* message, assert(size > 0); #endif - return impl_->schedule_message(ts, message, size); + return m_impl->schedule_message(ts, message, size); } LIBREMIDI_INLINE @@ -254,7 +255,7 @@ stdx::error midi_out::send_ump(const uint32_t* message, size_t size) const assert(size <= 4); #endif - return impl_->send_ump(message, size); + return m_impl->send_ump(message, size); } LIBREMIDI_INLINE stdx::error midi_out::send_ump(const libremidi::ump& message) const @@ -321,6 +322,6 @@ stdx::error midi_out::schedule_ump(int64_t ts, const uint32_t* message, size_t s assert(size > 0); #endif - return impl_->schedule_ump(ts, message, size); + return m_impl->schedule_ump(ts, message, size); } } diff --git a/include/libremidi/observer.cpp b/include/libremidi/observer.cpp index 7b3ad8f..81abe3a 100644 --- a/include/libremidi/observer.cpp +++ b/include/libremidi/observer.cpp @@ -5,17 +5,19 @@ #include #include +#include + namespace libremidi { -static LIBREMIDI_INLINE std::unique_ptr make_observer(auto base_conf) +static LIBREMIDI_INLINE std::unique_ptr make_observer(const auto& base_conf) { for (const auto& api : available_apis()) { try { - if (auto impl_ = make_observer(base_conf, observer_configuration_for(api))) - return impl_; + if (auto impl = make_observer(base_conf, observer_configuration_for(api))) + return impl; } catch (const std::exception& e) { @@ -26,8 +28,8 @@ static LIBREMIDI_INLINE std::unique_ptr make_observer(auto base_co { try { - if (auto impl_ = make_observer(base_conf, observer_configuration_for(api))) - return impl_; + if (auto impl = make_observer(base_conf, observer_configuration_for(api))) + return impl; } catch (const std::exception& e) { @@ -49,12 +51,13 @@ LIBREMIDI_INLINE auto make_observer_impl(auto base_conf, observer_api_configurat return false; }; std::apply([&](auto&&... b) { (from_api(b) || ...); }, midi1::available_backends); - std::apply([&](auto&&... b) { (from_api(b) || ...); }, midi2::available_backends); + if (!ptr) + std::apply([&](auto&&... b) { (from_api(b) || ...); }, midi2::available_backends); return ptr; } LIBREMIDI_INLINE std::unique_ptr -make_observer(auto base_conf, observer_api_configuration api_conf) +make_observer(const auto& base_conf, observer_api_configuration api_conf) { if (std::get_if(&api_conf)) { @@ -81,33 +84,33 @@ make_observer(auto base_conf, observer_api_configuration api_conf) } LIBREMIDI_INLINE observer::observer(const observer_configuration& base_conf) noexcept - : impl_{make_observer(base_conf)} + : m_impl{make_observer(base_conf)} { } LIBREMIDI_INLINE -observer::observer(observer_configuration base_conf, observer_api_configuration api_conf) - : impl_{make_observer(base_conf, api_conf)} +observer::observer(const observer_configuration& base_conf, observer_api_configuration api_conf) + : m_impl{make_observer(base_conf, std::move(api_conf))} { - if (!impl_) + if (!m_impl) { error_handler e; e.libremidi_handle_error(base_conf, "Could not open observer for the given api"); - impl_ = std::make_unique(observer_configuration{}, dummy_configuration{}); + m_impl = std::make_unique(observer_configuration{}, dummy_configuration{}); } } LIBREMIDI_INLINE observer::observer(observer&& other) noexcept - : impl_{std::move(other.impl_)} + : m_impl{std::move(other.m_impl)} { - other.impl_ = std::make_unique( + other.m_impl = std::make_unique( observer_configuration{}, dummy_configuration{}); } LIBREMIDI_INLINE observer& observer::operator=(observer&& other) noexcept { - this->impl_ = std::move(other.impl_); - other.impl_ = std::make_unique( + this->m_impl = std::move(other.m_impl); + other.m_impl = std::make_unique( observer_configuration{}, dummy_configuration{}); return *this; } @@ -118,18 +121,18 @@ observer::~observer() = default; LIBREMIDI_INLINE libremidi::API observer::get_current_api() const noexcept { - return impl_->get_current_api(); + return m_impl->get_current_api(); } LIBREMIDI_INLINE std::vector observer::get_input_ports() const noexcept { - return impl_->get_input_ports(); + return m_impl->get_input_ports(); } LIBREMIDI_INLINE std::vector observer::get_output_ports() const noexcept { - return impl_->get_output_ports(); + return m_impl->get_output_ports(); } } diff --git a/include/libremidi/reader.cpp b/include/libremidi/reader.cpp index 5beb5b1..2d2a543 100644 --- a/include/libremidi/reader.cpp +++ b/include/libremidi/reader.cpp @@ -521,7 +521,7 @@ LIBREMIDI_INLINE reader::reader(bool useAbsolute) : ticksPerBeat(480) , startingTempo(120) - , useAbsoluteTicks(useAbsolute) + , m_useAbsoluteTicks(useAbsolute) { } @@ -549,12 +549,12 @@ try return parse_result::invalid; } - const uint8_t* const dataEnd = dataPtr + size; + const uint8_t* const data_end = dataPtr + size; - uint32_t headerId = read_checked::read_uint32_be(dataPtr, dataEnd); - uint32_t headerLength = read_checked::read_uint32_be(dataPtr, dataEnd); + uint32_t header_id = read_checked::read_uint32_be(dataPtr, data_end); + uint32_t header_length = read_checked::read_uint32_be(dataPtr, data_end); - if (static_cast(headerId) != str_to_headerid("MThd") || headerLength != 6) + if (static_cast(header_id) != str_to_headerid("MThd") || header_length != 6) { #if defined(__LIBREMIDI_DEBUG__) std::cerr << "couldn't parse header" << std::endl; @@ -563,7 +563,7 @@ try } format = read_checked::read_uint16_be( - dataPtr, dataEnd); //@tofix format type -> save for later eventually + dataPtr, data_end); //@tofix format type -> save for later eventually if (format > 2) { #if defined(__LIBREMIDI_DEBUG__) @@ -571,12 +571,12 @@ try #endif return parse_result::invalid; } - int trackCount = read_checked::read_uint16_be(dataPtr, dataEnd); - uint16_t timeDivision = read_checked::read_uint16_be(dataPtr, dataEnd); + int track_count = read_checked::read_uint16_be(dataPtr, data_end); + uint16_t time_division = read_checked::read_uint16_be(dataPtr, data_end); // CBB: deal with the SMPTE style time coding // timeDivision is described here http://www.sonicspot.com/guide/midifiles.html - if (timeDivision & 0x8000) + if (time_division & 0x8000) { #if defined(__LIBREMIDI_DEBUG__) std::cerr << "found SMPTE time frames (unsupported)" << std::endl; @@ -590,18 +590,18 @@ try } startingTempo = 120.0f; // midi default - ticksPerBeat = float(timeDivision); // ticks per beat (a beat is defined as a quarter note) + ticksPerBeat = float(time_division); // ticks per beat (a beat is defined as a quarter note) parse_result result = parse_result::validated; - for (int i = 0; i < trackCount; ++i) + for (int i = 0; i < track_count; ++i) { midi_track track; - headerId = read_checked::read_uint32_be(dataPtr, dataEnd); - headerLength = read_checked::read_uint32_be(dataPtr, dataEnd); + header_id = read_checked::read_uint32_be(dataPtr, data_end); + header_length = read_checked::read_uint32_be(dataPtr, data_end); - if (headerId != str_to_headerid("MTrk")) + if (header_id != str_to_headerid("MTrk")) { #if defined(__LIBREMIDI_DEBUG__) std::cerr << "couldn't find track header" << std::endl; @@ -609,8 +609,8 @@ try return parse_result::incomplete; } - int64_t available = dataEnd - dataPtr; - if (available < headerLength) + int64_t available = data_end - dataPtr; + if (available < header_length) { #if defined(__LIBREMIDI_DEBUG__) std::cerr << "not enough data available" << std::endl; @@ -618,35 +618,35 @@ try return parse_result::incomplete; } - track.reserve(headerLength / 3); + track.reserve(header_length / 3); - const uint8_t* const trackEnd = dataPtr + headerLength; + const uint8_t* const track_end = dataPtr + header_length; - auto runningEvent = message_type::INVALID; + auto running_event = message_type::INVALID; - std::size_t tickCount = 0; + std::size_t tick_count = 0; - while (dataPtr < trackEnd) + while (dataPtr < track_end) { - const auto tick = read_checked::read_variable_length(dataPtr, trackEnd); - if (useAbsoluteTicks) + const auto tick = read_checked::read_variable_length(dataPtr, track_end); + if (m_useAbsoluteTicks) { - tickCount += tick; + tick_count += tick; } else { - tickCount = tick; + tick_count = tick; } try { track_event ev - = parse_event(static_cast(tickCount), i, dataPtr, trackEnd, runningEvent); + = parse_event(static_cast(tick_count), i, dataPtr, track_end, running_event); if (!ev.m.empty()) { if (!ev.m.is_meta_event()) { - runningEvent = static_cast(ev.m.bytes[0]); + running_event = static_cast(ev.m.bytes[0]); } } else @@ -654,7 +654,7 @@ try #if defined(__LIBREMIDI_DEBUG__) std::cerr << "could not read event" << std::endl; #endif - dataPtr = trackEnd; + dataPtr = track_end; result = parse_result::incomplete; continue; } @@ -666,7 +666,7 @@ try #if defined(__LIBREMIDI_DEBUG__) std::cerr << "" << e.what() << std::endl; #endif - dataPtr = trackEnd; + dataPtr = track_end; result = parse_result::incomplete; continue; } @@ -684,7 +684,7 @@ try if (result == parse_result::validated) { - if (dataPtr != dataEnd) + if (dataPtr != data_end) { #if defined(__LIBREMIDI_DEBUG__) std::cerr << "midifile has junk at end: " << std::intptr_t(dataEnd - dataPtr) << std::endl; @@ -706,33 +706,33 @@ catch (const std::exception& e) LIBREMIDI_INLINE double reader::get_end_time() const noexcept { - if (useAbsoluteTicks) + if (m_useAbsoluteTicks) { - double totalLength = 0.; + double total_length = 0.; for (const auto& t : tracks) { if (!t.empty()) { const auto& last_event = t.back(); - if (last_event.tick > totalLength) - totalLength = last_event.tick; + if (last_event.tick > total_length) + total_length = last_event.tick; } } - return totalLength; + return total_length; } else { - double totalLength = 0.; + double total_length = 0.; for (const auto& t : tracks) { - double trackLength = 0.; + double track_length = 0.; for (const auto& e : t) - trackLength += e.tick; + track_length += e.tick; - if (trackLength > totalLength) - totalLength = trackLength; + if (track_length > total_length) + total_length = track_length; } - return totalLength; + return total_length; } } diff --git a/include/libremidi/reader.hpp b/include/libremidi/reader.hpp index 1d99b46..4fda384 100644 --- a/include/libremidi/reader.hpp +++ b/include/libremidi/reader.hpp @@ -66,7 +66,7 @@ class LIBREMIDI_EXPORT reader std::vector tracks; private: - bool useAbsoluteTicks{}; + bool m_useAbsoluteTicks{}; }; } diff --git a/include/libremidi/writer.cpp b/include/libremidi/writer.cpp index 984865c..7a078fc 100644 --- a/include/libremidi/writer.cpp +++ b/include/libremidi/writer.cpp @@ -62,14 +62,14 @@ static LIBREMIDI_INLINE std::ostream& write_be(std::ostream& out, T value) } else { - static constexpr auto N = sizeof(value); + static constexpr auto n = sizeof(value); struct storage { - uint8_t bytes[N]; + uint8_t bytes[n]; }; auto data = std::bit_cast(value); - std::reverse(data.bytes, data.bytes + N); - out.write(reinterpret_cast(data.bytes), static_cast(N)); + std::reverse(data.bytes, data.bytes + n); + out.write(reinterpret_cast(data.bytes), static_cast(n)); } return out; } @@ -146,12 +146,12 @@ void writer::write(std::ostream& out) const util::write_be(out, static_cast(tracks.size())); util::write_be(out, ticksPerQuarterNote); - std::vector trackRawData; + std::vector track_raw_data; for (const auto& event_list : tracks) { - trackRawData.clear(); + track_raw_data.clear(); // Rough estimation of the memory to allocate - trackRawData.reserve(event_list.size() * 3); + track_raw_data.reserve(event_list.size() * 3); for (const auto& event : event_list) { @@ -164,7 +164,7 @@ void writer::write(std::ostream& out) const if (msg.get_meta_event_type() == meta_event_type::END_OF_TRACK) continue; - util::write_variable_length(static_cast(event.tick), trackRawData); + util::write_variable_length(static_cast(event.tick), track_raw_data); if ((msg.get_message_type() == message_type::SYSTEM_EXCLUSIVE) || (event.m.get_message_type() == message_type::EOX)) @@ -176,38 +176,38 @@ void writer::write(std::ostream& out) const // In other words, when creating a 0xf0 or 0xf7 MIDI message, // do not insert the VLV byte length yourself, as this code will // do it for you automatically. - trackRawData.emplace_back(msg.bytes[0]); // 0xf0 or 0xf7; + track_raw_data.emplace_back(msg.bytes[0]); // 0xf0 or 0xf7; - util::write_variable_length(static_cast(msg.size()) - 1, trackRawData); + util::write_variable_length(static_cast(msg.size()) - 1, track_raw_data); - trackRawData.insert( - trackRawData.end(), msg.bytes.data() + 1, msg.bytes.data() + msg.bytes.size()); + track_raw_data.insert( + track_raw_data.end(), msg.bytes.data() + 1, msg.bytes.data() + msg.bytes.size()); } else { // Non-sysex type of message, so just output the bytes of the message: - trackRawData.insert( - trackRawData.end(), msg.bytes.data(), msg.bytes.data() + msg.bytes.size()); + track_raw_data.insert( + track_raw_data.end(), msg.bytes.data(), msg.bytes.data() + msg.bytes.size()); } } - auto size = trackRawData.size(); + auto size = track_raw_data.size(); const auto eot = meta_events::end_of_track(); - if ((size < 3) || !((trackRawData[size - 3] == 0xFF) && (trackRawData[size - 2] == 0x2F))) + if ((size < 3) || !((track_raw_data[size - 3] == 0xFF) && (track_raw_data[size - 2] == 0x2F))) { - trackRawData.emplace_back(0x0); // tick - trackRawData.emplace_back(eot[0]); - trackRawData.emplace_back(eot[1]); - trackRawData.emplace_back(eot[2]); + track_raw_data.emplace_back(0x0); // tick + track_raw_data.emplace_back(eot[0]); + track_raw_data.emplace_back(eot[1]); + track_raw_data.emplace_back(eot[2]); } // Write the track ID marker "MTrk": out.write("MTrk", 4); - util::write_be(out, static_cast(trackRawData.size())); + util::write_be(out, static_cast(track_raw_data.size())); out.write( - reinterpret_cast(trackRawData.data()), - static_cast(trackRawData.size())); + reinterpret_cast(track_raw_data.data()), + static_cast(track_raw_data.size())); } } }