working on win32 uwp! and libremidi update

This commit is contained in:
Sebastian @ HfG
2024-10-28 19:24:18 +01:00
parent 06cb6d8319
commit 1e3755148c
106 changed files with 8474 additions and 2198 deletions
+31 -48
View File
@@ -1,6 +1,7 @@
#pragma once
#include <libremidi/backends/winmm/config.hpp>
#include <libremidi/backends/winmm/helpers.hpp>
#include <libremidi/backends/winmm/observer.hpp>
#include <libremidi/detail/midi_out.hpp>
namespace libremidi
@@ -20,55 +21,34 @@ public:
midi_out_winmm(output_configuration&& conf, winmm_output_configuration&& apiconf)
: configuration{std::move(conf), std::move(apiconf)}
{
// We'll issue a warning here if no devices are available but not
// throw an error since the user can plug something in later.
if (midiOutGetNumDevs() == 0)
{
warning(
configuration,
"midi_out_winmm::initialize: no MIDI output devices currently "
"available.");
}
this->client_open_ = stdx::error{};
}
~midi_out_winmm() override
{
// Close a connection if it exists.
midi_out_winmm::close_port();
}
bool open_virtual_port(std::string_view) override
{
warning(configuration, "midi_out_winmm: open_virtual_port unsupported");
return false;
}
void set_client_name(std::string_view) override
{
warning(configuration, "midi_out_winmm: set_client_name unsupported");
}
void set_port_name(std::string_view) override
{
warning(configuration, "midi_out_winmm: set_port_name unsupported");
this->client_open_ = std::errc::not_connected;
}
libremidi::API get_current_api() const noexcept override { return libremidi::API::WINDOWS_MM; }
[[nodiscard]] bool do_open(unsigned int portNumber)
[[nodiscard]] stdx::error do_open(unsigned int portNumber)
{
MMRESULT result = midiOutOpen(&this->outHandle, portNumber, 0, 0, CALLBACK_NULL);
if (result != MMSYSERR_NOERROR)
{
error<driver_error>(
libremidi_handle_error(
configuration,
"midi_out_winmm::open_port: error creating Windows MM MIDI output "
"error creating Windows MM MIDI output "
"port.");
return false;
return from_mmerr(result);
}
return true;
return stdx::error{};
}
bool open_port(const output_port& p, std::string_view) override
stdx::error open_port(const output_port& p, std::string_view) override
{
observer_winmm obs{{}, winmm_observer_configuration{}};
auto ports = obs.get_output_ports();
@@ -85,29 +65,30 @@ public:
if (p.port_name == port.port_name)
return do_open(port.port);
}
error<invalid_parameter_error>(
configuration, "midi_out_winmm::open_port: port not found: " + p.port_name);
return false;
libremidi_handle_error(
configuration, "port not found: " + p.port_name);
return std::errc::invalid_argument;
}
void close_port() override
stdx::error close_port() override
{
if (this->outHandle)
midiOutClose(this->outHandle);
this->outHandle = nullptr;
connected_ = false;
return stdx::error{};
}
void send_message(const unsigned char* message, size_t size) override
stdx::error send_message(const unsigned char* message, size_t size) override
{
if (!connected_)
return;
return std::errc::not_connected;
if (size == 0)
{
warning(configuration, "midi_out_winmm::send_message: message argument is empty!");
return;
libremidi_handle_warning(configuration, "message argument is empty!");
return std::errc::invalid_argument;
}
if (message[0] == 0xF0)
@@ -126,18 +107,18 @@ public:
auto result = midiOutPrepareHeader(this->outHandle, &sysex, sizeof(MIDIHDR));
if (result != MMSYSERR_NOERROR)
{
error<driver_error>(
configuration, "midi_out_winmm::send_message: error preparing sysex header.");
return;
libremidi_handle_error(
configuration, "error preparing sysex header.");
return from_mmerr(result);
}
// Send the message.
result = midiOutLongMsg(this->outHandle, &sysex, sizeof(MIDIHDR));
if (result != MMSYSERR_NOERROR)
{
error<driver_error>(
configuration, "midi_out_winmm::send_message: error sending sysex message.");
return;
libremidi_handle_error(
configuration, "error sending sysex message.");
return from_mmerr(result);
}
// Unprepare the buffer and MIDIHDR.
@@ -152,11 +133,11 @@ public:
// Make sure the message size isn't too big.
if (size > 3)
{
warning(
libremidi_handle_warning(
configuration,
"midi_out_winmm::send_message: message size is greater than 3 bytes "
"message size is greater than 3 bytes "
"(and not sysex)!");
return;
return std::errc::message_size;
}
// Pack MIDI bytes into double word.
@@ -167,10 +148,12 @@ public:
auto result = midiOutShortMsg(this->outHandle, packet);
if (result != MMSYSERR_NOERROR)
{
error<driver_error>(
configuration, "midi_out_winmm::send_message: error sending MIDI message.");
libremidi_handle_error(
configuration, "error sending MIDI message.");
return from_mmerr(result);
}
}
return stdx::error{};
}
private: