Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio control plugin detection #5

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ class AppRaw final : public Glib::Object
}

private:
[[nodiscard]] bool sendSinkVolume();

void onSoundEnabledChange();
void onSoundVolumeChange();

Expand Down
6 changes: 4 additions & 2 deletions packages/ghaf-audio-control/src/lib/src/AppList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ Gtk::Widget* AppList::createWidgetsForApp(const Glib::RefPtr<Glib::Object>& appV
auto* stackGrid = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_HORIZONTAL, BoxPlaces);
stackGrid->add(*soundEnableSwitch);
stackGrid->add(*soundScale);
stackGrid->add(*microEnableSwitch);
stackGrid->add(*microScale);

// Disable micro control for now
// stackGrid->add(*microEnableSwitch);
// stackGrid->add(*microScale);

stackGrid->set_valign(Gtk::ALIGN_START);

Expand Down
18 changes: 3 additions & 15 deletions packages/ghaf-audio-control/src/lib/src/AppListRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,6 @@ void AppRaw::updateSource(IAudioControlBackend::ISource::Ptr source)
m_hasSource = m_source != nullptr;
}

bool AppRaw::sendSinkVolume()
{
Logger::debug(std::format("SoundVolume has changed to: {0}", m_soundVolume.get_value()));

if (m_sink)
m_sink->setVolume(Volume::fromPercents(m_soundVolume.get_value()));

return true;
}

void AppRaw::onSoundEnabledChange()
{
const auto isEnabled = m_isSoundEnabled.get_value();
Expand All @@ -112,12 +102,10 @@ void AppRaw::onSoundEnabledChange()

void AppRaw::onSoundVolumeChange()
{
sendSinkVolume();
// if (m_sinkUpdateConnection)
// m_sinkUpdateConnection.disconnect();
Logger::debug(std::format("SoundVolume has changed to: {0}", m_soundVolume.get_value()));

// const sigc::slot<bool> slot = sigc::mem_fun(*this, &AppRaw::sendSinkVolume);
// m_sinkUpdateConnection = Glib::signal_timeout().connect(slot, 200);
if (m_sink)
m_sink->setVolume(Volume::fromPercents(m_soundVolume.get_value()));
}

void AppRaw::onMicroEnabledChange()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <GhafAudioControl/Backends/PulseAudio/AudioControlBackend.hpp>

#include <GhafAudioControl/Backends/PulseAudio/Helpers.hpp>

#include <GhafAudioControl/Backends/PulseAudio/Sink.hpp>
#include <GhafAudioControl/Backends/PulseAudio/Source.hpp>

Expand All @@ -27,6 +26,11 @@ namespace ghaf::AudioControl::Backend::PulseAudio
namespace
{

std::string ToString(const pa_card_port_info& port)
{
return std::format("Port. Name: {}, descript: {}, available: {}", port.name, port.description, port.available);
}

constexpr pa_subscription_mask GetSubscriptionMask(auto... masks)
{
return static_cast<pa_subscription_mask>((masks | ...));
Expand Down Expand Up @@ -86,7 +90,7 @@ constexpr pa_subscription_mask SubscriptionMask = GetSubscriptionMask(pa_subscri

pa_context_set_state_callback(context, contextCallback, &self);

if (auto& server = self.getServerAddress(); pa_context_connect(context, server.empty() ? nullptr : server.c_str(), PA_CONTEXT_NOFAIL, nullptr) < 0)
if (const auto& server = self.getServerAddress(); pa_context_connect(context, server.empty() ? nullptr : server.c_str(), PA_CONTEXT_NOFAIL, nullptr) < 0)
throw std::runtime_error(std::format("pa_context_connect() failed: {}", pa_strerror(pa_context_errno(context))));
};

Expand Down Expand Up @@ -152,13 +156,9 @@ void AudioControlBackend::onSourceInfo(const pa_source_info& info)
const Index index = info.index;

if (auto sourceIt = m_sources.findByKey(index))
{
m_sources.update(*sourceIt, [&info](ISource& source) { dynamic_cast<Source&>(source).update(info); });
}
else
{
m_sources.add(index, std::make_shared<Source>(info, *m_context->get()));
}
}

void AudioControlBackend::deleteSource(Sources::IndexT index)
Expand Down Expand Up @@ -236,9 +236,6 @@ void AudioControlBackend::contextStateCallback(pa_context* context, void* data)

case pa_context_state_t::PA_CONTEXT_FAILED:
self->m_onError(std::format("Connection to the server '{}' has failed", self->getServerAddress()));
// std::this_thread::sleep_for(1s);
// self->m_context = InitContext(*self->m_mainloopApi, AudioControlBackend::contextStateCallback, *self);

break;

case pa_context_state_t::PA_CONTEXT_CONNECTING:
Expand Down Expand Up @@ -290,6 +287,14 @@ void AudioControlBackend::cardInfoCallback(pa_context* context, const pa_card_in
if (info == nullptr)
return;

Logger::debug("\n###############################################");
Logger::debug(std::format("Card. index: {}, name: {}", info->index, info->name));

for (size_t i = 0; i < info->n_ports; ++i)
Logger::info(ToString(*info->ports[i]));

Logger::debug("###############################################\n");

auto* self = static_cast<AudioControlBackend*>(data);

auto sinkPredicate = [&info](const ISink& sink) -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ GeneralDeviceImpl::GeneralDeviceImpl(const pa_source_info& info, pa_context& con
[[nodiscard]] std::string GeneralDeviceImpl::toString() const
{
const std::lock_guard l{m_mutex};
return std::format("index: {}, name: {}, volume: {}, isMuted: {}", m_index, m_description, m_volume.values[0], m_isMuted);
return std::format("index: {}, name: {}, volume: {}, isMuted: {}, cardId: {}", m_index, m_description, m_volume.values[0], m_isMuted, m_cardIndex);
}

[[nodiscard]] std::string GeneralDeviceImpl::getDescription() const
Expand Down Expand Up @@ -126,19 +126,28 @@ void GeneralDeviceImpl::update(const pa_card_info& info)
{
const std::lock_guard l{m_mutex};

m_isEnabled = false;
m_isEnabled = true;

if (m_cardIndex == info.index)
if (m_cardIndex != info.index)
return;

for (size_t i = 0; i < info.n_ports; ++i)
{
for (size_t i = 0; i < info.n_ports; ++i)
{
pa_card_port_info const* port = info.ports[i];
pa_card_port_info const& port = *info.ports[i];

if (m_description == port->description && port->available == PA_PORT_AVAILABLE_YES)
if (m_description.ends_with(port.description))
{
switch (port.type)
{
m_isEnabled = true;
case pa_device_port_type::PA_DEVICE_PORT_TYPE_HDMI:
m_isEnabled = port.available == pa_port_available::PA_PORT_AVAILABLE_YES;
break;

default:
m_isEnabled = true;
}

break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

#include <GhafAudioControl/Backends/PulseAudio/Helpers.hpp>

#include <format>
#include <pulse/error.h>

#include <format>

namespace ghaf::AudioControl::Backend::PulseAudio
{

Expand All @@ -24,7 +25,7 @@ bool PulseCallbackCheck(const pa_context* context, int eol, std::string_view cal

const auto error = pa_context_errno(context);

if (error == PA_ERR_NOENTITY || error == PA_OK)
if (error == pa_error_code::PA_ERR_NOENTITY || error == pa_error_code::PA_OK)
return true;

Logger::error(std::format("pulseCallbackCheck: callback: {} failed with error: {}", callbackName, pa_strerror(error)));
Expand Down