libremidi update to v5.4.3 and added virtual midi out as default
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <libremidi/config.hpp>
|
||||
|
||||
namespace libremidi
|
||||
NAMESPACE_LIBREMIDI
|
||||
{
|
||||
|
||||
struct emscripten_input_configuration
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace libremidi
|
||||
NAMESPACE_LIBREMIDI
|
||||
{
|
||||
namespace webmidi_helpers
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ EMSCRIPTEN_KEEPALIVE
|
||||
void libremidi_devices_input(int port, double timestamp, int len, char* bytes);
|
||||
}
|
||||
|
||||
namespace libremidi
|
||||
NAMESPACE_LIBREMIDI
|
||||
{
|
||||
namespace webmidi_helpers
|
||||
{
|
||||
@@ -37,16 +37,25 @@ public:
|
||||
|
||||
int input_count() const noexcept
|
||||
{
|
||||
if (!available())
|
||||
return 0;
|
||||
|
||||
return EM_ASM_INT(return globalThis.__libreMidi_currentInputs.length;);
|
||||
}
|
||||
|
||||
int output_count() const noexcept
|
||||
{
|
||||
if (!available())
|
||||
return 0;
|
||||
|
||||
return EM_ASM_INT(return globalThis.__libreMidi_currentOutputs.length;);
|
||||
}
|
||||
|
||||
void load_current_infos() noexcept
|
||||
{
|
||||
if (!available())
|
||||
return;
|
||||
|
||||
#define get_js_string(variable_to_read, ...) \
|
||||
(char*)EM_ASM_INT( \
|
||||
{ \
|
||||
@@ -206,6 +215,9 @@ public:
|
||||
|
||||
stdx::error send_message(int port_index, const char* bytes, int len)
|
||||
{
|
||||
if (!available())
|
||||
return std::errc::operation_not_supported;
|
||||
|
||||
const auto& id = m_current_outputs[port_index].id;
|
||||
EM_ASM(
|
||||
{
|
||||
@@ -216,6 +228,8 @@ public:
|
||||
output.send(Array.from(bytes));
|
||||
},
|
||||
bytes, len, id.c_str());
|
||||
|
||||
return stdx::error{};
|
||||
}
|
||||
|
||||
const std::vector<device_information>& inputs() const noexcept { return m_current_inputs; }
|
||||
@@ -248,6 +262,9 @@ private:
|
||||
|
||||
void start_stream(int port_index)
|
||||
{
|
||||
if (!available())
|
||||
return;
|
||||
|
||||
// Isn't life great...
|
||||
// https://github.com/Planeshifter/emscripten-examples/tree/master/01_PassingArrays
|
||||
const auto& id = m_current_inputs[port_index].id;
|
||||
@@ -282,6 +299,9 @@ private:
|
||||
|
||||
void stop_stream(int port_index)
|
||||
{
|
||||
if (!available())
|
||||
return;
|
||||
|
||||
const auto& id = m_current_inputs[port_index].id;
|
||||
EM_ASM(const id = UTF8ToString($1);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace libremidi
|
||||
NAMESPACE_LIBREMIDI
|
||||
{
|
||||
LIBREMIDI_INLINE midi_in_emscripten::midi_in_emscripten(
|
||||
input_configuration&& conf, emscripten_input_configuration&& apiconf)
|
||||
@@ -32,13 +32,12 @@ LIBREMIDI_INLINE stdx::error midi_in_emscripten::open_port(int portNumber, std::
|
||||
|
||||
if (portNumber < 0 || portNumber >= midi.input_count())
|
||||
{
|
||||
libremidi_handle_error(
|
||||
this->configuration, "no MIDI output sources found.");
|
||||
libremidi_handle_error(this->configuration, "no MIDI output sources found.");
|
||||
return std::errc::invalid_argument;
|
||||
}
|
||||
|
||||
midi.open_input(portNumber, *this);
|
||||
portNumber_ = portNumber;
|
||||
m_portNumber = portNumber;
|
||||
return stdx::error{};
|
||||
}
|
||||
|
||||
@@ -52,7 +51,7 @@ LIBREMIDI_INLINE stdx::error midi_in_emscripten::close_port()
|
||||
{
|
||||
auto& midi = webmidi_helpers::midi_access_emscripten::instance();
|
||||
|
||||
midi.close_input(portNumber_, *this);
|
||||
midi.close_input(m_portNumber, *this);
|
||||
|
||||
return stdx::error{};
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <libremidi/detail/midi_in.hpp>
|
||||
#include <libremidi/detail/midi_stream_decoder.hpp>
|
||||
|
||||
namespace libremidi
|
||||
NAMESPACE_LIBREMIDI
|
||||
{
|
||||
class midi_in_emscripten final
|
||||
: public midi1::in_api
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
void on_input(double ts, unsigned char* begin, unsigned char* end);
|
||||
|
||||
private:
|
||||
int portNumber_{};
|
||||
int m_portNumber{};
|
||||
|
||||
midi1::input_state_machine m_processing{this->configuration};
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <libremidi/backends/emscripten/midi_access.hpp>
|
||||
#include <libremidi/backends/emscripten/midi_out.hpp>
|
||||
|
||||
namespace libremidi
|
||||
NAMESPACE_LIBREMIDI
|
||||
{
|
||||
LIBREMIDI_INLINE midi_out_emscripten::midi_out_emscripten(
|
||||
output_configuration&& conf, emscripten_output_configuration&& apiconf)
|
||||
@@ -29,34 +29,36 @@ LIBREMIDI_INLINE stdx::error midi_out_emscripten::open_port(int portNumber, std:
|
||||
|
||||
if (portNumber >= midi.output_count())
|
||||
{
|
||||
libremidi_handle_error(
|
||||
this->configuration, "no MIDI output sources found.");
|
||||
libremidi_handle_error(this->configuration, "no MIDI output sources found.");
|
||||
return std::errc::invalid_argument;
|
||||
}
|
||||
|
||||
portNumber_ = portNumber;
|
||||
m_portNumber = portNumber;
|
||||
return stdx::error{};
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE stdx::error midi_out_emscripten::open_port(const output_port& p, std::string_view nm)
|
||||
LIBREMIDI_INLINE stdx::error
|
||||
midi_out_emscripten::open_port(const output_port& p, std::string_view nm)
|
||||
{
|
||||
return open_port(p.port, nm);
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE stdx::error midi_out_emscripten::close_port() {
|
||||
LIBREMIDI_INLINE stdx::error midi_out_emscripten::close_port()
|
||||
{
|
||||
return stdx::error{};
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE stdx::error midi_out_emscripten::send_message(const unsigned char* message, size_t size)
|
||||
LIBREMIDI_INLINE stdx::error
|
||||
midi_out_emscripten::send_message(const unsigned char* message, size_t size)
|
||||
{
|
||||
if (portNumber_ < 0)
|
||||
if (m_portNumber < 0)
|
||||
libremidi_handle_error(
|
||||
this->configuration,
|
||||
"trying to send a message without an open "
|
||||
"port.");
|
||||
|
||||
webmidi_helpers::midi_access_emscripten::instance().send_message(
|
||||
portNumber_, reinterpret_cast<const char*>(message), size);
|
||||
m_portNumber, reinterpret_cast<const char*>(message), size);
|
||||
return stdx::error{};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <libremidi/backends/emscripten/helpers.hpp>
|
||||
#include <libremidi/detail/midi_out.hpp>
|
||||
|
||||
namespace libremidi
|
||||
NAMESPACE_LIBREMIDI
|
||||
{
|
||||
class midi_out_emscripten final
|
||||
: public midi1::out_api
|
||||
@@ -28,6 +28,6 @@ public:
|
||||
stdx::error send_message(const unsigned char* message, size_t size) override;
|
||||
|
||||
private:
|
||||
int portNumber_{-1};
|
||||
int m_portNumber{-1};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace libremidi
|
||||
NAMESPACE_LIBREMIDI
|
||||
{
|
||||
LIBREMIDI_INLINE observer_emscripten::observer_emscripten(
|
||||
observer_configuration&& conf, emscripten_observer_configuration&& apiconf)
|
||||
@@ -42,7 +42,8 @@ static auto to_port_info(int index, const webmidi_helpers::device_information& d
|
||||
-> std::conditional_t<Input, input_port, output_port>
|
||||
{
|
||||
return {
|
||||
{.client = 0,
|
||||
{.api = libremidi::API::WEBMIDI,
|
||||
.client = 0,
|
||||
.port = (uint64_t)index,
|
||||
.manufacturer = "",
|
||||
.device_name = "",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace libremidi
|
||||
NAMESPACE_LIBREMIDI
|
||||
{
|
||||
class observer_emscripten final : public observer_api
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user