1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/MIDITypes.h"
8 #include "mozilla/dom/MIDIPortBinding.h"
10 mozilla::LazyLogModule
gWebMIDILog("WebMIDI");
12 void LogMIDIMessage(const mozilla::dom::MIDIMessage
& aMessage
,
13 const nsAString
& aPortId
,
14 mozilla::dom::MIDIPortType aDirection
) {
15 if (MOZ_LOG_TEST(gWebMIDILog
, mozilla::LogLevel::Debug
)) {
16 if (MOZ_LOG_TEST(gWebMIDILog
, mozilla::LogLevel::Verbose
)) {
17 uint32_t byteCount
= aMessage
.data().Length();
18 nsAutoCString logMessage
;
19 // Log long messages inline with the timestamp and the length, log
20 // longer messages a bit like xxd
21 logMessage
.AppendPrintf(
22 "%s %s length=%u", NS_ConvertUTF16toUTF8(aPortId
).get(),
23 aDirection
== mozilla::dom::MIDIPortType::Input
? "->" : "<-",
27 logMessage
.AppendPrintf(" [");
29 for (uint32_t i
= 0; i
< byteCount
- 1; i
++) {
30 logMessage
.AppendPrintf("%x ", aMessage
.data()[i
]);
32 logMessage
.AppendPrintf("%x]", aMessage
.data()[byteCount
- 1]);
35 for (uint32_t i
= 0; i
< byteCount
; i
++) {
37 logMessage
.AppendPrintf("\n%08u:\t", i
);
39 logMessage
.AppendPrintf("%x ", aMessage
.data()[i
]);
42 MOZ_LOG(gWebMIDILog
, mozilla::LogLevel::Verbose
,
43 ("%s", logMessage
.get()));