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
+42 -29
View File
@@ -37,16 +37,18 @@ public:
jack_ringbuffer_free(ringbuffer);
}
void write(const unsigned char* data, int64_t sz) const noexcept
stdx::error write(const unsigned char* data, int64_t sz) const noexcept
{
if (static_cast<std::size_t>(sz + size_sz) > ringbuffer_space)
return;
return std::errc::no_buffer_space;
while (jack_ringbuffer_write_space(ringbuffer) < sz + size_sz)
sched_yield();
jack_ringbuffer_write(ringbuffer, reinterpret_cast<char*>(&sz), size_sz);
jack_ringbuffer_write(ringbuffer, reinterpret_cast<const char*>(data), sz);
return stdx::error{};
}
void read(void* jack_events) const noexcept
@@ -74,6 +76,7 @@ class midi_out_jack
, public error_handler
{
public:
using midi_api::client_open_;
struct
: output_configuration
, jack_output_configuration
@@ -87,39 +90,36 @@ public:
~midi_out_jack() override { }
void set_client_name(std::string_view) override
{
warning(configuration, "midi_out_jack: set_client_name unsupported");
}
libremidi::API get_current_api() const noexcept override { return libremidi::API::JACK_MIDI; }
bool open_port(const output_port& port, std::string_view portName) override
stdx::error open_port(const output_port& port, std::string_view portName) override
{
if (!create_local_port(*this, portName, JackPortIsOutput))
return false;
if (auto err = create_local_port(*this, portName, JackPortIsOutput); err != stdx::error{})
return err;
// Connecting to the output
if (jack_connect(this->client, jack_port_name(this->port), port.port_name.c_str()) != 0)
if (int err = jack_connect(this->client, jack_port_name(this->port), port.port_name.c_str());
err != 0 && err != EEXIST)
{
error<invalid_parameter_error>(
configuration, "JACK: could not connect to port" + port.port_name);
return false;
libremidi_handle_error(
configuration, "could not connect to port" + port.port_name);
return from_errc(err);
}
return true;
return stdx::error{};
}
bool open_virtual_port(std::string_view portName) override
stdx::error open_virtual_port(std::string_view portName) override
{
return create_local_port(*this, portName, JackPortIsOutput);
}
void close_port() override { return do_close_port(); }
stdx::error close_port() override { return do_close_port(); }
void set_port_name(std::string_view portName) override
stdx::error set_port_name(std::string_view portName) override
{
jack_port_rename(this->client, this->port, portName.data());
int ret = jack_port_rename(this->client, this->port, portName.data());
return from_errc(ret);
}
};
@@ -131,8 +131,14 @@ public:
, queue{configuration.ringbuffer_size}
{
auto status = connect(*this);
if (status != jack_status_t{})
warning(configuration, "midi_out_jack_queued: " + std::to_string((int)jack_status_t{}));
if (!this->client)
{
libremidi_handle_error(configuration, "Could not create JACK client");
client_open_ = from_jack_status(status);
return;
}
client_open_ = stdx::error{};
}
~midi_out_jack_queued() override
@@ -142,9 +148,9 @@ public:
disconnect(*this);
}
void send_message(const unsigned char* message, std::size_t size) override
stdx::error send_message(const unsigned char* message, std::size_t size) override
{
queue.write(message, size);
return queue.write(message, size);
}
int process(jack_nframes_t nframes)
@@ -168,10 +174,15 @@ public:
: midi_out_jack{std::move(conf), std::move(apiconf)}
{
auto status = connect(*this);
if (status != jack_status_t{})
warning(configuration, "midi_out_jack_direct: " + std::to_string((int)jack_status_t{}));
if (!this->client)
{
libremidi_handle_error(configuration, "Could not create JACK client");
client_open_ = from_jack_status(status);
return;
}
buffer_size = jack_get_buffer_size(this->client);
client_open_ = stdx::error{};
}
~midi_out_jack_direct() override
@@ -188,10 +199,11 @@ public:
return 0;
}
void send_message(const unsigned char* message, size_t size) override
stdx::error send_message(const unsigned char* message, size_t size) override
{
void* buff = jack_port_get_buffer(this->port, buffer_size);
jack_midi_event_write(buff, 0, message, size);
int ret = jack_midi_event_write(buff, 0, message, size);
return from_errc(ret);
}
int convert_timestamp(int64_t user) const noexcept
@@ -207,10 +219,11 @@ public:
}
}
void schedule_message(int64_t ts, const unsigned char* message, size_t size) override
stdx::error schedule_message(int64_t ts, const unsigned char* message, size_t size) override
{
void* buff = jack_port_get_buffer(this->port, buffer_size);
jack_midi_event_write(buff, convert_timestamp(ts), message, size);
int ret = jack_midi_event_write(buff, convert_timestamp(ts), message, size);
return from_errc(ret);
}
int buffer_size{};