Browse Source

Add midi::Message::toString().

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
a99ba7f352
3 changed files with 27 additions and 5 deletions
  1. +7
    -5
      include/midi.hpp
  2. +3
    -0
      src/context.cpp
  3. +17
    -0
      src/midi.cpp

+ 7
- 5
include/midi.hpp View File

@@ -75,6 +75,8 @@ struct Message {
return;
bytes[2] = value & 0x7f;
}

std::string toString();
};

////////////////////
@@ -151,7 +153,7 @@ struct InputDevice : Device {
/** Not public. Use Driver::unsubscribeInput(). */
void unsubscribe(Input* input);
/** Called when a MIDI message is received from the device. */
void onMessage(const Message &message);
void onMessage(const Message& message);
};

struct OutputDevice : Device {
@@ -161,7 +163,7 @@ struct OutputDevice : Device {
/** Not public. Use Driver::unsubscribeOutput(). */
void unsubscribe(Output* output);
/** Sends a MIDI message to the device. */
virtual void sendMessage(const Message &message) {}
virtual void sendMessage(const Message& message) {}
};

////////////////////
@@ -229,14 +231,14 @@ struct Input : Port {

std::vector<int> getChannels() override;

virtual void onMessage(const Message &message) {}
virtual void onMessage(const Message& message) {}
};


struct InputQueue : Input {
int queueMaxSize = 8192;
std::queue<Message> queue;
void onMessage(const Message &message) override;
void onMessage(const Message& message) override;
};


@@ -254,7 +256,7 @@ struct Output : Port {

std::vector<int> getChannels() override;

void sendMessage(const Message &message);
void sendMessage(const Message& message);
};




+ 3
- 0
src/context.cpp View File

@@ -11,7 +11,10 @@ namespace rack {


Context::~Context() {
// Deleting NULL is safe in C++.

// Set pointers to NULL so other objects will segfault when attempting to access them

delete patch;
patch = NULL;



+ 17
- 0
src/midi.cpp View File

@@ -12,6 +12,23 @@ namespace midi {

static std::vector<std::pair<int, Driver*>> drivers;

std::string Message::toString() {
std::string s;
for (size_t i = 0; i < bytes.size(); i++) {
if (i > 0)
s += " ";
uint8_t b = bytes[i];
// We could use string::f() here, but use faster method instead.
// s += string::f("%02x", b);
uint8_t b1 = (b & 0x0f) >> 0;
uint8_t b2 = (b & 0xf0) >> 4;
s += b2 < 0xa ? ('0' + b2) : ('a' + b2 - 0xa);
s += b1 < 0xa ? ('0' + b1) : ('a' + b1 - 0xa);
}
return s;
}


////////////////////
// Device
////////////////////


Loading…
Cancel
Save