working on win32 uwp! and libremidi update
This commit is contained in:
+159
-48
@@ -10,7 +10,8 @@
|
||||
|
||||
namespace libremidi
|
||||
{
|
||||
LIBREMIDI_INLINE auto make_midi_out(auto base_conf, std::any api_conf)
|
||||
static LIBREMIDI_INLINE std::unique_ptr<midi_out_api>
|
||||
make_midi_out_impl(auto base_conf, std::any api_conf)
|
||||
{
|
||||
std::unique_ptr<midi_out_api> ptr;
|
||||
auto from_api = [&]<typename T>(T& /*backend*/) mutable {
|
||||
@@ -26,23 +27,66 @@ LIBREMIDI_INLINE auto make_midi_out(auto base_conf, std::any api_conf)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE midi_out::midi_out(const output_configuration& base_conf) noexcept
|
||||
static LIBREMIDI_INLINE std::unique_ptr<midi_out_api>
|
||||
make_midi_out(const output_configuration& base_conf)
|
||||
{
|
||||
for (const auto& api : available_apis())
|
||||
{
|
||||
try
|
||||
{
|
||||
impl_ = make_midi_out(base_conf, midi_out_configuration_for(api));
|
||||
if (auto ret = make_midi_out_impl(base_conf, midi_out_configuration_for(api)))
|
||||
return ret;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
|
||||
if (impl_)
|
||||
return;
|
||||
}
|
||||
if (!impl_)
|
||||
impl_ = std::make_unique<midi_out_dummy>(output_configuration{}, dummy_configuration{});
|
||||
|
||||
for (const auto& api : available_ump_apis())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (auto ret = make_midi_out_impl(base_conf, midi_out_configuration_for(api)))
|
||||
return ret;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_unique<midi_out_dummy>(output_configuration{}, dummy_configuration{});
|
||||
}
|
||||
|
||||
static LIBREMIDI_INLINE std::unique_ptr<midi_out_api>
|
||||
make_midi_out(const output_configuration& base_conf, const std::any& api_conf)
|
||||
{
|
||||
if (!api_conf.has_value())
|
||||
{
|
||||
return make_midi_out(base_conf);
|
||||
}
|
||||
else if (auto api_p = std::any_cast<libremidi::API>(&api_conf))
|
||||
{
|
||||
if (*api_p == libremidi::API::UNSPECIFIED)
|
||||
{
|
||||
return make_midi_out(base_conf);
|
||||
}
|
||||
else
|
||||
{
|
||||
return make_midi_out_impl(base_conf, midi_out_configuration_for(*api_p));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (auto api = libremidi::midi_api(api_conf); api == libremidi::API::UNSPECIFIED)
|
||||
return make_midi_out(base_conf);
|
||||
else
|
||||
return make_midi_out_impl(base_conf, api_conf);
|
||||
}
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE midi_out::midi_out(const output_configuration& base_conf) noexcept
|
||||
: impl_{make_midi_out(base_conf)}
|
||||
{
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
@@ -50,7 +94,11 @@ midi_out::midi_out(output_configuration base_conf, std::any api_conf)
|
||||
: impl_{make_midi_out(base_conf, api_conf)}
|
||||
{
|
||||
if (!impl_)
|
||||
throw midi_exception("Could not open midi out for the given api");
|
||||
{
|
||||
error_handler e;
|
||||
e.libremidi_handle_error(base_conf, "Could not open midi out for the given api");
|
||||
impl_ = std::make_unique<midi_out_dummy>(output_configuration{}, dummy_configuration{});
|
||||
}
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE midi_out::~midi_out() = default;
|
||||
@@ -61,6 +109,7 @@ LIBREMIDI_INLINE midi_out::midi_out(midi_out&& other) noexcept
|
||||
other.impl_
|
||||
= std::make_unique<libremidi::midi_out_dummy>(output_configuration{}, dummy_configuration{});
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE midi_out& midi_out::operator=(midi_out&& other) noexcept
|
||||
{
|
||||
this->impl_ = std::move(other.impl_);
|
||||
@@ -70,9 +119,12 @@ LIBREMIDI_INLINE midi_out& midi_out::operator=(midi_out&& other) noexcept
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::set_port_name(std::string_view portName) const
|
||||
stdx::error midi_out::set_port_name(std::string_view portName) const
|
||||
{
|
||||
impl_->set_port_name(portName);
|
||||
if(impl_->is_port_open())
|
||||
return impl_->set_port_name(portName);
|
||||
|
||||
return std::errc::not_connected;
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
@@ -82,36 +134,48 @@ libremidi::API midi_out::get_current_api() const noexcept
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::open_port(const output_port& port, std::string_view portName) const
|
||||
stdx::error midi_out::open_port(const output_port& port, std::string_view portName) const
|
||||
{
|
||||
if (impl_->is_port_open())
|
||||
return;
|
||||
if (auto err = impl_->is_client_open(); err != stdx::error{})
|
||||
return std::errc::not_connected;
|
||||
|
||||
if (impl_->open_port(port, portName))
|
||||
if (impl_->is_port_open())
|
||||
return std::errc::operation_not_supported;
|
||||
|
||||
auto ret = impl_->open_port(port, portName);
|
||||
if (ret == stdx::error{})
|
||||
{
|
||||
impl_->connected_ = true;
|
||||
impl_->port_open_ = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::open_virtual_port(std::string_view portName) const
|
||||
stdx::error midi_out::open_virtual_port(std::string_view portName) const
|
||||
{
|
||||
if (auto err = impl_->is_client_open(); err != stdx::error{})
|
||||
return std::errc::not_connected;
|
||||
|
||||
if (impl_->is_port_open())
|
||||
return;
|
||||
return std::errc::operation_not_supported;
|
||||
|
||||
if (impl_->open_virtual_port(portName))
|
||||
{
|
||||
auto ret = impl_->open_virtual_port(portName);
|
||||
if (ret == stdx::error{})
|
||||
impl_->port_open_ = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::close_port() const
|
||||
stdx::error midi_out::close_port() const
|
||||
{
|
||||
impl_->close_port();
|
||||
if (auto err = impl_->is_client_open(); err != stdx::error{})
|
||||
return std::errc::not_connected;
|
||||
|
||||
auto ret = impl_->close_port();
|
||||
impl_->connected_ = false;
|
||||
impl_->port_open_ = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
@@ -127,89 +191,136 @@ bool midi_out::is_port_connected() const noexcept
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_message(const libremidi::message& message) const
|
||||
stdx::error midi_out::send_message(const libremidi::message& message) const
|
||||
{
|
||||
send_message(message.bytes.data(), message.bytes.size());
|
||||
return send_message(message.bytes.data(), message.bytes.size());
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_message(std::span<const unsigned char> message) const
|
||||
stdx::error midi_out::send_message(std::span<const unsigned char> message) const
|
||||
{
|
||||
send_message(message.data(), message.size());
|
||||
return send_message(message.data(), message.size());
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_message(unsigned char b0) const
|
||||
stdx::error midi_out::send_message(unsigned char b0) const
|
||||
{
|
||||
send_message(&b0, 1);
|
||||
return send_message(&b0, 1);
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_message(unsigned char b0, unsigned char b1) const
|
||||
stdx::error midi_out::send_message(unsigned char b0, unsigned char b1) const
|
||||
{
|
||||
send_message(std::to_array({b0, b1}));
|
||||
return send_message(std::to_array({b0, b1}));
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_message(unsigned char b0, unsigned char b1, unsigned char b2) const
|
||||
stdx::error midi_out::send_message(unsigned char b0, unsigned char b1, unsigned char b2) const
|
||||
{
|
||||
send_message(std::to_array({b0, b1, b2}));
|
||||
return send_message(std::to_array({b0, b1, b2}));
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_message(const unsigned char* message, size_t size) const
|
||||
stdx::error midi_out::send_message(const unsigned char* message, size_t size) const
|
||||
{
|
||||
#if defined(LIBREMIDI_ASSERTIONS)
|
||||
assert(size > 0);
|
||||
#endif
|
||||
|
||||
impl_->send_message(message, size);
|
||||
return impl_->send_message(message, size);
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_ump(const uint32_t* message, size_t size) const
|
||||
int64_t midi_out::current_time()
|
||||
{
|
||||
return impl_->current_time();
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
stdx::error midi_out::schedule_message(int64_t ts, const unsigned char* message, size_t size) const
|
||||
{
|
||||
#if defined(LIBREMIDI_ASSERTIONS)
|
||||
assert(size > 0);
|
||||
#endif
|
||||
|
||||
return impl_->schedule_message(ts, message, size);
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
stdx::error midi_out::send_ump(const uint32_t* message, size_t size) const
|
||||
{
|
||||
#if defined(LIBREMIDI_ASSERTIONS)
|
||||
assert(size > 0);
|
||||
assert(size <= 4);
|
||||
#endif
|
||||
|
||||
impl_->send_ump(message, size);
|
||||
return impl_->send_ump(message, size);
|
||||
}
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_ump(const libremidi::ump& message) const
|
||||
stdx::error midi_out::send_ump(const libremidi::ump& message) const
|
||||
{
|
||||
send_ump(message.data, message.size());
|
||||
return send_ump(message.data, message.size());
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_ump(std::span<const uint32_t> message) const
|
||||
stdx::error midi_out::send_ump(std::span<const uint32_t> message) const
|
||||
{
|
||||
send_ump(message.data(), message.size());
|
||||
return send_ump(message.data(), message.size());
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_ump(uint32_t b0) const
|
||||
stdx::error midi_out::send_ump(uint32_t b0) const
|
||||
{
|
||||
send_ump(&b0, 1);
|
||||
return send_ump(&b0, 1);
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_ump(uint32_t b0, uint32_t b1) const
|
||||
stdx::error midi_out::send_ump(uint32_t b0, uint32_t b1) const
|
||||
{
|
||||
send_ump(std::to_array({b0, b1}));
|
||||
return send_ump(std::to_array({b0, b1}));
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_ump(uint32_t b0, uint32_t b1, uint32_t b2) const
|
||||
stdx::error midi_out::send_ump(uint32_t b0, uint32_t b1, uint32_t b2) const
|
||||
{
|
||||
send_ump(std::to_array({b0, b1, b2}));
|
||||
return send_ump(std::to_array({b0, b1, b2}));
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
void midi_out::send_ump(uint32_t b0, uint32_t b1, uint32_t b2, uint32_t b3) const
|
||||
stdx::error midi_out::send_ump(uint32_t b0, uint32_t b1, uint32_t b2, uint32_t b3) const
|
||||
{
|
||||
send_ump(std::to_array({b0, b1, b2, b3}));
|
||||
return send_ump(std::to_array({b0, b1, b2, b3}));
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
stdx::error midi_out::send_ump(int32_t b0) const
|
||||
{
|
||||
return send_ump(reinterpret_cast<uint32_t*>(&b0), 1);
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
stdx::error midi_out::send_ump(int64_t b01) const
|
||||
{
|
||||
auto ptr = reinterpret_cast<uint32_t*>(&b01);
|
||||
uint32_t msg[2]{ptr[1], ptr[0]};
|
||||
return send_ump(msg, 2);
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
stdx::error midi_out::send_ump(uint64_t b01) const
|
||||
{
|
||||
auto ptr = reinterpret_cast<uint32_t*>(&b01);
|
||||
uint32_t msg[2]{ptr[1], ptr[0]};
|
||||
return send_ump(msg, 2);
|
||||
}
|
||||
|
||||
LIBREMIDI_INLINE
|
||||
stdx::error midi_out::schedule_ump(int64_t ts, const uint32_t* message, size_t size) const
|
||||
{
|
||||
#if defined(LIBREMIDI_ASSERTIONS)
|
||||
assert(size > 0);
|
||||
#endif
|
||||
|
||||
return impl_->schedule_ump(ts, message, size);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user