very, very simple WP with midi CC out

This commit is contained in:
Sebastian
2024-10-09 02:01:23 +02:00
commit 3d6fc151f1
126 changed files with 19539 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
#pragma once
#include <libremidi/cmidi2.hpp>
#include <cinttypes>
#include <cstdint>
namespace libremidi
{
enum class segmentation_error
{
no_error,
need_space,
other
};
/**
* Utility function to segment an ump stream into individual messages.
* Used to send a stream to APIs that work message-by-message.
*/
inline void
segment_ump_stream(const uint32_t* ump_stream, int64_t count, auto write_func, auto realloc_func)
{
while (count > 0)
{
// Handle NOOP (or padding)
while (count > 0 && ump_stream[0] == 0)
{
count--;
ump_stream++;
}
if (count == 0)
break;
const auto ump_bytes = cmidi2_ump_get_num_bytes(ump_stream[0]);
// FIXME std::expected, propagate the error back to caller?
switch (write_func(ump_stream, ump_bytes))
{
case segmentation_error::no_error:
break;
case segmentation_error::need_space:
// Try again if we didn't have enough space in the OS queue
realloc_func();
if (write_func(ump_stream, ump_bytes) != segmentation_error::no_error)
return;
break;
case segmentation_error::other:
return;
}
const auto ump_uints = ump_bytes / 4;
ump_stream += ump_uints;
count -= ump_uints;
}
}
}