From 060866f46ae1a44287960cb21bff64231935fdcf Mon Sep 17 00:00:00 2001 From: David Moreno Montero Date: Thu, 17 Oct 2024 23:32:29 +0200 Subject: [PATCH] Moved the adata buffer into the object itself, fill with 0. Rename to buffer. --- src/local_rawmidi_peer.cpp | 6 +++--- src/local_rawmidi_peer.hpp | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/local_rawmidi_peer.cpp b/src/local_rawmidi_peer.cpp index 6d8a8e0..57777f7 100644 --- a/src/local_rawmidi_peer.cpp +++ b/src/local_rawmidi_peer.cpp @@ -34,6 +34,7 @@ using namespace rtpmididns; local_rawmidi_peer_t::local_rawmidi_peer_t(const std::string &name_, const std::string &device_) : device(device_), name(name_) { + buffer.fill(0); INFO("Creating rawmidi peer=\"{}\", device={}", name, device); fd = open(device.c_str(), O_RDWR | O_NONBLOCK); if (fd < 0) { @@ -89,13 +90,12 @@ void local_rawmidi_peer_t::read_midi() { if (fd < 0) { return; } - std::array adata; - ssize_t count = read(fd, adata.data(), adata.size()); + ssize_t count = read(fd, buffer.data(), buffer.size()); if (count <= 0) { return; } - rtpmidid::packet_t packet(adata.begin(), (uint32_t)count); + rtpmidid::packet_t packet(buffer.begin(), (uint32_t)count); // FIXME: Even if received several message in the stream, send one by one. // Maybe would be better send full packets, but would need some stack space or diff --git a/src/local_rawmidi_peer.hpp b/src/local_rawmidi_peer.hpp index dd93f01..6749767 100644 --- a/src/local_rawmidi_peer.hpp +++ b/src/local_rawmidi_peer.hpp @@ -37,6 +37,7 @@ class local_rawmidi_peer_t : public midipeer_t { int fd = -1; rtpmidid::poller_t::listener_t fd_listener; midi_normalizer_t midi_normalizer; + std::array buffer; local_rawmidi_peer_t(const std::string &name, const std::string &device); ~local_rawmidi_peer_t() override;