Skip to content

Commit

Permalink
fix(examples): adjust to changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Apr 10, 2024
1 parent e2d9651 commit efbcf19
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 55 deletions.
81 changes: 39 additions & 42 deletions examples/channels/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ int main()
{
auto [sender, receiver] = pw::channel<recipe>();

auto thread = [](recipe::receiver receiver)
{
auto thread = [](recipe::receiver receiver) {
auto loop = pw::main_loop::create();
auto context = pw::context::create(loop);
auto core = context->core();
Expand All @@ -37,46 +36,44 @@ int main()

bool exit = false;

receiver.attach(loop,
[&]<typename T>(const T &msg)
receiver.attach(loop, [&]<typename T>(const T &msg) {
if constexpr (std::same_as<T, create_virtual_mic>)
{
auto node = core->create<pw::node>(pw::factory{
.name = "adapter",
.props =
{
if constexpr (std::same_as<T, create_virtual_mic>)
{
auto node = core->create<pw::node>(pw::factory{
.name = "adapter",
.props =
{
{"node.name", msg.name},
{"media.class", "Audio/Source/Virtual"},
{"factory.name", "support.null-audio-sink"},
},
});

created.emplace_back(std::move(node.get()));
}
else if constexpr (std::same_as<T, check_node>)
{
auto &mic = created.back();

if (!mic.has_value())
{
std::cerr << "Failed to create node!" << std::endl;

auto error = mic.error();
std::cerr << error.message << std::endl;

return;
}

std::cout << "Created successfully!" << std::endl;
std::cout << mic.value().id() << std::endl;
}
else if constexpr (std::same_as<T, terminate>)
{
exit = true;
loop->quit();
}
});
{"node.name", msg.name},
{"media.class", "Audio/Source/Virtual"},
{"factory.name", "support.null-audio-sink"},
},
});

created.emplace_back(std::move(node.get()));
}
else if constexpr (std::same_as<T, check_node>)
{
auto &mic = created.back();

if (!mic.has_value())
{
std::cerr << "Failed to create node!" << std::endl;

auto error = mic.error();
std::cerr << error.message << std::endl;

return;
}

std::cout << "Created successfully!" << std::endl;
std::cout << mic.value().id() << std::endl;
}
else if constexpr (std::same_as<T, terminate>)
{
exit = true;
loop->quit();
}
});

while (!exit)
{
Expand All @@ -95,4 +92,4 @@ int main()
t1.join();

return 0;
}
}
15 changes: 7 additions & 8 deletions examples/mute-microphone/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#include <iostream>

#include <rohrkabel/device/device.hpp>
#include <rohrkabel/registry/registry.hpp>
#include <rohrkabel/spa/pod/object/body.hpp>

#include <rohrkabel/registry/events.hpp>
#include <rohrkabel/registry/registry.hpp>

namespace pw = pipewire;

int main()
Expand All @@ -18,8 +20,7 @@ int main()

auto listener = reg->listen();

auto on_global = [&](const pipewire::global &global)
{
auto on_global = [&](const pipewire::global &global) {
if (global.type != pipewire::device::type)
{
return;
Expand Down Expand Up @@ -61,12 +62,10 @@ int main()
auto params = device.params();
core->update();

auto get_mute = [](const pw::spa::pod &pod)
{
auto get_mute = [](const pw::spa::pod &pod) {
// NOLINTNEXTLINE
auto impl = [](const pw::spa::pod_prop *parent, const pw::spa::pod &pod,
auto &self) -> std::optional<pw::spa::pod_prop>
{
auto &self) -> std::optional<pw::spa::pod_prop> {
if (pod.type() == pw::spa::pod_type::object)
{
for (const auto &item : pod.body<pw::spa::pod_object_body>())
Expand Down Expand Up @@ -125,4 +124,4 @@ int main()
device.set_param(13, pods.at(13).get());
core.sync();
*/
*/
5 changes: 3 additions & 2 deletions examples/roundtrip/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <iostream>

#include <rohrkabel/node/node.hpp>

#include <rohrkabel/registry/events.hpp>
#include <rohrkabel/registry/registry.hpp>

namespace pw = pipewire;
Expand All @@ -15,8 +17,7 @@ int main()

auto listener = reg->listen();

auto on_global = [&](const pw::global &global)
{
auto on_global = [&](const pw::global &global) {
if (global.type != pw::node::type)
{
return;
Expand Down
7 changes: 4 additions & 3 deletions examples/virtual-mic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <rohrkabel/node/node.hpp>

#include <rohrkabel/metadata/metadata.hpp>

#include <rohrkabel/registry/events.hpp>
#include <rohrkabel/registry/registry.hpp>

namespace pw = pipewire;
Expand All @@ -25,8 +27,7 @@ int main()

auto listener = reg->listen();

auto on_global = [&](const pw::global &global)
{
auto on_global = [&](const pw::global &global) {
if (global.type == pw::metadata::type)
{
auto metadata = reg->bind<pw::metadata>(global.id).get();
Expand Down Expand Up @@ -180,4 +181,4 @@ int main()

std::cin.get();
return 0;
}
}

0 comments on commit efbcf19

Please sign in to comment.