working on win32 uwp! and libremidi update
This commit is contained in:
@@ -26,83 +26,73 @@ public:
|
||||
midi_out_impl(output_configuration&& conf, alsa_raw_output_configuration&& apiconf)
|
||||
: configuration{std::move(conf), std::move(apiconf)}
|
||||
{
|
||||
client_open_ = stdx::error{};
|
||||
}
|
||||
|
||||
~midi_out_impl() override
|
||||
{
|
||||
// Close a connection if it exists.
|
||||
midi_out_impl::close_port();
|
||||
client_open_ = std::errc::not_connected;
|
||||
}
|
||||
|
||||
libremidi::API get_current_api() const noexcept override { return libremidi::API::ALSA_RAW; }
|
||||
|
||||
bool open_virtual_port(std::string_view) override
|
||||
{
|
||||
warning(configuration, "midi_out_alsa_raw: open_virtual_port unsupported");
|
||||
return false;
|
||||
}
|
||||
void set_client_name(std::string_view) override
|
||||
{
|
||||
warning(configuration, "midi_out_alsa_raw: set_client_name unsupported");
|
||||
}
|
||||
void set_port_name(std::string_view) override
|
||||
{
|
||||
warning(configuration, "midi_out_alsa_raw: set_port_name unsupported");
|
||||
}
|
||||
|
||||
int connect_port(const char* portname)
|
||||
stdx::error connect_port(const char* portname)
|
||||
{
|
||||
constexpr int mode = SND_RAWMIDI_SYNC;
|
||||
int status = snd.rawmidi.open(NULL, &midiport_, portname, mode);
|
||||
if (status < 0)
|
||||
{
|
||||
error<driver_error>(
|
||||
this->configuration, "midi_out_alsa_raw::open_port: cannot open device.");
|
||||
return status;
|
||||
libremidi_handle_error(
|
||||
this->configuration, "cannot open device.");
|
||||
return from_errc(status);
|
||||
}
|
||||
return status;
|
||||
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
|
||||
{
|
||||
return connect_port(raw_from_port_handle(p.port).to_string().c_str()) == 0;
|
||||
return connect_port(raw_from_port_handle(p.port).to_string().c_str());
|
||||
}
|
||||
|
||||
void close_port() override
|
||||
stdx::error close_port() override
|
||||
{
|
||||
if (midiport_)
|
||||
snd.rawmidi.close(midiport_);
|
||||
midiport_ = nullptr;
|
||||
|
||||
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 (!midiport_)
|
||||
error<invalid_use_error>(
|
||||
libremidi_handle_error(
|
||||
this->configuration,
|
||||
"midi_out_alsa_raw::send_message: trying to send a message without an open "
|
||||
"trying to send a message without an open "
|
||||
"port.");
|
||||
|
||||
if (!this->configuration.chunking)
|
||||
{
|
||||
write(message, size);
|
||||
return write(message, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
write_chunked(message, size);
|
||||
return write_chunked(message, size);
|
||||
}
|
||||
}
|
||||
|
||||
bool write(const unsigned char* message, size_t size)
|
||||
stdx::error write(const unsigned char* message, size_t size)
|
||||
{
|
||||
if (snd.rawmidi.write(midiport_, message, size) < 0)
|
||||
if (auto err = snd.rawmidi.write(midiport_, message, size); err < 0)
|
||||
{
|
||||
error<driver_error>(
|
||||
this->configuration, "midi_out_alsa_raw::send_message: cannot write message.");
|
||||
return false;
|
||||
libremidi_handle_error(
|
||||
this->configuration, "cannot write message.");
|
||||
return from_errc(err);
|
||||
}
|
||||
|
||||
return true;
|
||||
return stdx::error{};
|
||||
}
|
||||
|
||||
std::size_t get_chunk_size() const noexcept
|
||||
@@ -125,7 +115,7 @@ public:
|
||||
}
|
||||
|
||||
// inspired from ALSA amidi.c source code
|
||||
void write_chunked(const unsigned char* const begin, size_t size)
|
||||
stdx::error write_chunked(const unsigned char* const begin, size_t size)
|
||||
{
|
||||
const unsigned char* data = begin;
|
||||
const unsigned char* end = begin + size;
|
||||
@@ -135,8 +125,8 @@ public:
|
||||
// Send the first buffer
|
||||
std::size_t len = chunk_size;
|
||||
|
||||
if (!write(data, len))
|
||||
return;
|
||||
if (auto err = write(data, len); err != stdx::error{})
|
||||
return err;
|
||||
|
||||
data += len;
|
||||
|
||||
@@ -149,11 +139,11 @@ public:
|
||||
{
|
||||
if (!configuration.chunking->wait(
|
||||
std::chrono::microseconds((chunk_size - available) * 320), written_bytes))
|
||||
return;
|
||||
return std::errc::protocol_error;
|
||||
};
|
||||
|
||||
if (!configuration.chunking->wait(configuration.chunking->interval, written_bytes))
|
||||
return;
|
||||
return std::errc::protocol_error;
|
||||
|
||||
// Write more data
|
||||
len = end - data;
|
||||
@@ -165,11 +155,13 @@ public:
|
||||
if (len > chunk_size)
|
||||
len = chunk_size;
|
||||
|
||||
if (!write(data, len))
|
||||
return;
|
||||
if (auto err = write(data, len); err != stdx::error{})
|
||||
return err;
|
||||
|
||||
data += len;
|
||||
}
|
||||
|
||||
return stdx::error{};
|
||||
}
|
||||
|
||||
snd_rawmidi_t* midiport_{};
|
||||
|
||||
Reference in New Issue
Block a user