AlsaBridge.cpp
branchv_0
changeset 13 334b727f7516
parent 12 15d87fdd6e6c
--- a/AlsaBridge.cpp	Mon Jan 04 15:45:12 2021 +0100
+++ b/AlsaBridge.cpp	Mon Jan 04 17:11:57 2021 +0100
@@ -15,6 +15,7 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 #include <iostream>
+#include <iomanip>
 #include <sstream>
 #include <stdexcept>
 #include <thread>
@@ -75,6 +76,12 @@
 		}
 	}
 
+	std::string toString(const MidiMessage& midiMessage) {
+		std::stringstream result;
+		for (uint8_t b : midiMessage) result << std::hex << std::setw(2) << std::setfill('0') << (int) b;
+		return result.str();
+	}
+
 	void run() {
 		while (!stopped) {
 			{
@@ -93,12 +100,12 @@
 public:
 
 	AlsaBridgeImpl(djmfix::DJMFix* djmFix, const std::string& cardNamePattern, djmfix::logging::Logger* logger) : djmFix(djmFix), logger(logger ? logger : djmfix::logging::blackhole()) {
-		if (djmFix == nullptr) throw std::invalid_argument("need a djmFix for AlsaBridge");
+		if (djmFix == nullptr) throw std::invalid_argument("Need a djmFix for AlsaBridge.");
 
 		std::string deviceName = findDeviceName(std::regex(cardNamePattern));
 
 		int error = snd_rawmidi_open(&input, &output, deviceName.c_str(), SND_RAWMIDI_NONBLOCK);
-		if (error) throw std::invalid_argument("unable to open ALSA device");
+		if (error) throw std::invalid_argument("Unable to open ALSA device.");
 
 
 		djmFix->setMidiSender(this);
@@ -108,7 +115,7 @@
 		// TODO: do not use raw/exclusive access to the MIDI device
 		snd_rawmidi_close(input);
 		snd_rawmidi_close(output);
-		logger->log(L::FINE, "~AlsaBridgeImpl()");
+		logger->log(L::FINER, "~AlsaBridgeImpl()");
 	}
 
 	virtual void start() override {
@@ -125,7 +132,7 @@
 	virtual void send(MidiMessage midiMessage) override {
 		std::lock_guard<std::recursive_mutex> lock(midiMutex);
 		ssize_t length = snd_rawmidi_write(output, midiMessage.data(), midiMessage.size());
-		logger->log(L::INFO, "AlsaBridgeImpl::send(): length = " + std::to_string(length));
+		logger->log(L::FINE, "Sent message: length = " + std::to_string(length) + " data = " + toString(midiMessage));
 	}
 
 };