Files
viseq/include/libremidi/backends/emscripten/midi_out.cpp
T

64 lines
1.7 KiB
C++
Raw Normal View History

2024-10-09 02:01:23 +02:00
#if defined(__EMSCRIPTEN__)
#include <libremidi/backends/emscripten/midi_access.hpp>
#include <libremidi/backends/emscripten/midi_out.hpp>
namespace libremidi
{
LIBREMIDI_INLINE midi_out_emscripten::midi_out_emscripten(
output_configuration&& conf, emscripten_output_configuration&& apiconf)
: configuration{std::move(conf), std::move(apiconf)}
{
2024-10-28 19:24:18 +01:00
client_open_ = stdx::error{};
2024-10-09 02:01:23 +02:00
}
LIBREMIDI_INLINE midi_out_emscripten::~midi_out_emscripten()
{
// Close a connection if it exists.
midi_out_emscripten::close_port();
2024-10-28 19:24:18 +01:00
client_open_ = std::errc::not_connected;
2024-10-09 02:01:23 +02:00
}
LIBREMIDI_INLINE libremidi::API midi_out_emscripten::get_current_api() const noexcept
{
return libremidi::API::WEBMIDI;
}
2024-10-28 19:24:18 +01:00
LIBREMIDI_INLINE stdx::error midi_out_emscripten::open_port(int portNumber, std::string_view)
2024-10-09 02:01:23 +02:00
{
auto& midi = webmidi_helpers::midi_access_emscripten::instance();
if (portNumber >= midi.output_count())
{
2024-10-28 19:24:18 +01:00
libremidi_handle_error(
this->configuration, "no MIDI output sources found.");
return std::errc::invalid_argument;
2024-10-09 02:01:23 +02:00
}
portNumber_ = portNumber;
2024-10-28 19:24:18 +01:00
return stdx::error{};
2024-10-09 02:01:23 +02:00
}
2024-10-28 19:24:18 +01:00
LIBREMIDI_INLINE stdx::error midi_out_emscripten::open_port(const output_port& p, std::string_view nm)
2024-10-09 02:01:23 +02:00
{
return open_port(p.port, nm);
}
2024-10-28 19:24:18 +01:00
LIBREMIDI_INLINE stdx::error midi_out_emscripten::close_port() {
return stdx::error{};
2024-10-09 02:01:23 +02:00
}
2024-10-28 19:24:18 +01:00
LIBREMIDI_INLINE stdx::error midi_out_emscripten::send_message(const unsigned char* message, size_t size)
2024-10-09 02:01:23 +02:00
{
if (portNumber_ < 0)
2024-10-28 19:24:18 +01:00
libremidi_handle_error(
2024-10-09 02:01:23 +02:00
this->configuration,
2024-10-28 19:24:18 +01:00
"trying to send a message without an open "
2024-10-09 02:01:23 +02:00
"port.");
webmidi_helpers::midi_access_emscripten::instance().send_message(
portNumber_, reinterpret_cast<const char*>(message), size);
2024-10-28 19:24:18 +01:00
return stdx::error{};
2024-10-09 02:01:23 +02:00
}
}
#endif