libremidi update to v5.4.3 and added virtual midi out as default
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <libremidi/cmidi2.hpp>
|
||||
#include <libremidi/detail/conversion.hpp>
|
||||
#include <libremidi/detail/midi_in.hpp>
|
||||
|
||||
#include <libremidi/cmidi2.hpp>
|
||||
#include <cmath>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cinttypes>
|
||||
#include <span>
|
||||
|
||||
namespace libremidi
|
||||
NAMESPACE_LIBREMIDI
|
||||
{
|
||||
static inline int64_t system_ns() noexcept
|
||||
LIBREMIDI_STATIC int64_t system_ns() noexcept
|
||||
{
|
||||
namespace clk = std::chrono;
|
||||
return clk::duration_cast<clk::nanoseconds>(clk::steady_clock::now().time_since_epoch()).count();
|
||||
@@ -29,7 +31,7 @@ struct timestamp_backend_info
|
||||
bool has_samples{};
|
||||
};
|
||||
|
||||
template<typename Configuration>
|
||||
template <typename Configuration>
|
||||
struct input_state_machine_base
|
||||
{
|
||||
const Configuration& configuration;
|
||||
@@ -107,12 +109,12 @@ struct input_state_machine : input_state_machine_base<input_configuration>
|
||||
{
|
||||
message.bytes.clear();
|
||||
message.timestamp = {};
|
||||
state = main;
|
||||
m_state = main;
|
||||
}
|
||||
|
||||
bool has_finished_sysex(std::span<const uint8_t> 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 +141,22 @@ private:
|
||||
void on_bytes_multi_segmented(
|
||||
const message_callback& cb, std::span<const uint8_t> 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 +172,17 @@ private:
|
||||
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 +194,7 @@ private:
|
||||
if (configuration.ignore_timing)
|
||||
{
|
||||
size = 0;
|
||||
iByte += 2;
|
||||
i_byte += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -209,7 +211,7 @@ private:
|
||||
if (configuration.ignore_timing)
|
||||
{
|
||||
size = 0;
|
||||
iByte += 1;
|
||||
i_byte += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -222,7 +224,7 @@ private:
|
||||
if (configuration.ignore_sensing)
|
||||
{
|
||||
size = 0;
|
||||
iByte += 1;
|
||||
i_byte += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -238,14 +240,14 @@ private:
|
||||
// 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 +258,7 @@ private:
|
||||
const message_callback& cb, std::span<const uint8_t> bytes, bool finished_sysex)
|
||||
{
|
||||
if (finished_sysex)
|
||||
state = main;
|
||||
m_state = main;
|
||||
|
||||
if (configuration.ignore_sysex)
|
||||
{
|
||||
@@ -283,7 +285,7 @@ private:
|
||||
// SYSEX start
|
||||
case 0xF0: {
|
||||
if (!finished_sysex)
|
||||
state = in_sysex;
|
||||
m_state = in_sysex;
|
||||
|
||||
if (!this->configuration.ignore_sysex)
|
||||
{
|
||||
@@ -328,7 +330,7 @@ private:
|
||||
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 +348,7 @@ private:
|
||||
{
|
||||
main,
|
||||
in_sysex
|
||||
} state{main};
|
||||
} m_state{main};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -413,22 +415,20 @@ private:
|
||||
on_bytes_segmented(const ump_callback& cb, std::span<const uint32_t> bytes, int64_t timestamp)
|
||||
{
|
||||
// Filter according to message type
|
||||
switch(cmidi2_ump_get_message_type(bytes.data()))
|
||||
switch (cmidi2_ump_get_message_type(bytes.data()))
|
||||
{
|
||||
case CMIDI2_MESSAGE_TYPE_UTILITY:
|
||||
{
|
||||
case CMIDI2_MESSAGE_TYPE_UTILITY: {
|
||||
// All the utility messages are about timing
|
||||
if (this->configuration.ignore_timing)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
case CMIDI2_MESSAGE_TYPE_SYSTEM:
|
||||
{
|
||||
case CMIDI2_MESSAGE_TYPE_SYSTEM: {
|
||||
if (this->configuration.ignore_timing)
|
||||
{
|
||||
auto status = cmidi2_ump_get_system_message_byte2(bytes.data());
|
||||
switch(status)
|
||||
switch (status)
|
||||
{
|
||||
case CMIDI2_SYSTEM_STATUS_MIDI_TIME_CODE:
|
||||
case CMIDI2_SYSTEM_STATUS_SONG_POSITION:
|
||||
@@ -437,22 +437,33 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
if (this->configuration.ignore_sensing)
|
||||
{
|
||||
auto status = cmidi2_ump_get_system_message_byte2(bytes.data());
|
||||
if(status == CMIDI2_SYSTEM_STATUS_ACTIVE_SENSING)
|
||||
return;
|
||||
}
|
||||
break;
|
||||
if (this->configuration.ignore_sensing)
|
||||
{
|
||||
auto status = cmidi2_ump_get_system_message_byte2(bytes.data());
|
||||
if (status == CMIDI2_SYSTEM_STATUS_ACTIVE_SENSING)
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CMIDI2_MESSAGE_TYPE_SYSEX7:
|
||||
case CMIDI2_MESSAGE_TYPE_SYSEX8_MDS:
|
||||
{
|
||||
case CMIDI2_MESSAGE_TYPE_SYSEX8_MDS: {
|
||||
if (this->configuration.ignore_sysex)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
case CMIDI2_MESSAGE_TYPE_MIDI_1_CHANNEL: {
|
||||
if (this->configuration.midi1_channel_events_to_midi2)
|
||||
{
|
||||
libremidi::ump msg;
|
||||
cmidi2_ump_upgrade_midi1_channel_voice_to_midi2(bytes.data(), msg.data);
|
||||
msg.timestamp = timestamp;
|
||||
cb(std::move(msg));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
libremidi::ump msg;
|
||||
|
||||
Reference in New Issue
Block a user