working on win32 uwp! and libremidi update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <libremidi/backends/linux/pipewire.hpp>
|
||||
#include <libremidi/detail/memory.hpp>
|
||||
#include <libremidi/error.hpp>
|
||||
|
||||
#include <pipewire/filter.h>
|
||||
#include <pipewire/pipewire.h>
|
||||
@@ -128,7 +129,7 @@ struct pipewire_context
|
||||
this->main_loop = pw.main_loop_new(nullptr);
|
||||
if (!this->main_loop)
|
||||
{
|
||||
// libremidi::logger().error("PipeWire: main_loop_new failed!");
|
||||
// libremidi::logger().libremidi_handle_error("main_loop_new failed!");
|
||||
return;
|
||||
}
|
||||
initialize();
|
||||
@@ -139,28 +140,28 @@ struct pipewire_context
|
||||
this->lp = pw.main_loop_get_loop(this->main_loop);
|
||||
if (!lp)
|
||||
{
|
||||
// libremidi::logger().error("PipeWire: main_loop_get_loop failed!");
|
||||
// libremidi::logger().libremidi_handle_error("main_loop_get_loop failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
this->context = pw.context_new(lp, nullptr, 0);
|
||||
if (!this->context)
|
||||
{
|
||||
// libremidi::logger().error("PipeWire: context_new failed!");
|
||||
// libremidi::logger().libremidi_handle_error("context_new failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
this->core = pw.context_connect(this->context, nullptr, 0);
|
||||
if (!this->core)
|
||||
{
|
||||
// libremidi::logger().error("PipeWire: context_connect failed!");
|
||||
// libremidi::logger().libremidi_handle_error("context_connect failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
this->registry = pw_core_get_registry(this->core, PW_VERSION_REGISTRY, 0);
|
||||
if (!this->registry)
|
||||
{
|
||||
// libremidi::logger().error("PipeWire: core_get_registry failed!");
|
||||
// libremidi::logger().libremidi_handle_error("core_get_registry failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -297,7 +298,6 @@ struct pipewire_context
|
||||
|
||||
if (!proxy)
|
||||
{
|
||||
std::cerr << "PipeWire: could not allocate link\n";
|
||||
pw.properties_free(props);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -476,7 +476,7 @@ struct pipewire_filter
|
||||
PW_KEY_MEDIA_TYPE, "Midi",
|
||||
PW_KEY_MEDIA_CATEGORY, "Filter",
|
||||
PW_KEY_MEDIA_ROLE, "DSP",
|
||||
PW_KEY_MEDIA_NAME, "libremidi",
|
||||
PW_KEY_MEDIA_NAME, "",
|
||||
#if defined(PW_KEY_NODE_LOCK_RATE)
|
||||
PW_KEY_NODE_LOCK_RATE, "true",
|
||||
#endif
|
||||
@@ -498,7 +498,7 @@ struct pipewire_filter
|
||||
pw.filter_destroy(this->filter);
|
||||
}
|
||||
|
||||
void create_local_port(std::string_view port_name, spa_direction direction)
|
||||
stdx::error create_local_port(std::string_view port_name, spa_direction direction)
|
||||
{
|
||||
// clang-format off
|
||||
this->port = (struct port*)pw.filter_add_port(
|
||||
@@ -512,7 +512,9 @@ struct pipewire_filter
|
||||
nullptr),
|
||||
nullptr, 0);
|
||||
// clang-format on
|
||||
assert(port);
|
||||
if (!port)
|
||||
return std::errc::invalid_argument;
|
||||
return stdx::error{};
|
||||
}
|
||||
|
||||
void set_port_buffer(int bytes)
|
||||
@@ -537,31 +539,41 @@ struct pipewire_filter
|
||||
pw.filter_update_params(this->filter, this->port, params, 1);
|
||||
}
|
||||
|
||||
void remove_port()
|
||||
stdx::error remove_port()
|
||||
{
|
||||
assert(this->port);
|
||||
pw.filter_remove_port(this->port);
|
||||
int ret = pw.filter_remove_port(this->port);
|
||||
this->port = nullptr;
|
||||
return from_errc(ret);
|
||||
}
|
||||
|
||||
void rename_port(std::string_view port_name)
|
||||
stdx::error rename_port(std::string_view port_name)
|
||||
{
|
||||
assert(this->port);
|
||||
spa_dict_item items[1] = {
|
||||
SPA_DICT_ITEM_INIT(PW_KEY_PORT_NAME, port_name.data()),
|
||||
};
|
||||
|
||||
auto properties = SPA_DICT_INIT(items, 1);
|
||||
pw.filter_update_properties(this->filter, this->port, &properties);
|
||||
this->port = nullptr;
|
||||
}
|
||||
|
||||
void start_filter()
|
||||
{
|
||||
if (pw.filter_connect(this->filter, PW_FILTER_FLAG_RT_PROCESS, NULL, 0) < 0)
|
||||
if (this->port)
|
||||
{
|
||||
std::cerr << "can't connect\n";
|
||||
return;
|
||||
spa_dict_item items[1] = {
|
||||
SPA_DICT_ITEM_INIT(PW_KEY_PORT_NAME, port_name.data()),
|
||||
};
|
||||
|
||||
auto properties = SPA_DICT_INIT(items, 1);
|
||||
int ret = pw.filter_update_properties(this->filter, this->port, &properties);
|
||||
return from_errc(ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::errc::not_connected;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] stdx::error start_filter()
|
||||
{
|
||||
if (int ret = pw.filter_connect(this->filter, PW_FILTER_FLAG_RT_PROCESS, NULL, 0); ret < 0)
|
||||
{
|
||||
return from_errc(ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
return stdx::error{};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user