diff --git a/packages/ghaf-audio-control/src/lib/include/GhafAudioControl/AppListRow.hpp b/packages/ghaf-audio-control/src/lib/include/GhafAudioControl/AppListRow.hpp index 028890c..020bd12 100644 --- a/packages/ghaf-audio-control/src/lib/include/GhafAudioControl/AppListRow.hpp +++ b/packages/ghaf-audio-control/src/lib/include/GhafAudioControl/AppListRow.hpp @@ -82,8 +82,6 @@ class AppRaw final : public Glib::Object } private: - [[nodiscard]] bool sendSinkVolume(); - void onSoundEnabledChange(); void onSoundVolumeChange(); diff --git a/packages/ghaf-audio-control/src/lib/src/AppList.cpp b/packages/ghaf-audio-control/src/lib/src/AppList.cpp index 9569471..4fb4740 100644 --- a/packages/ghaf-audio-control/src/lib/src/AppList.cpp +++ b/packages/ghaf-audio-control/src/lib/src/AppList.cpp @@ -182,8 +182,10 @@ Gtk::Widget* AppList::createWidgetsForApp(const Glib::RefPtr& appV auto* stackGrid = Gtk::make_managed(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); diff --git a/packages/ghaf-audio-control/src/lib/src/AppListRow.cpp b/packages/ghaf-audio-control/src/lib/src/AppListRow.cpp index 1efd9d1..f552796 100644 --- a/packages/ghaf-audio-control/src/lib/src/AppListRow.cpp +++ b/packages/ghaf-audio-control/src/lib/src/AppListRow.cpp @@ -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(); @@ -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 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() diff --git a/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/AudioControlBackend.cpp b/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/AudioControlBackend.cpp index c9c765e..356b01e 100644 --- a/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/AudioControlBackend.cpp +++ b/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/AudioControlBackend.cpp @@ -6,7 +6,6 @@ #include #include - #include #include @@ -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((masks | ...)); @@ -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)))); }; @@ -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).update(info); }); - } else - { m_sources.add(index, std::make_shared(info, *m_context->get())); - } } void AudioControlBackend::deleteSource(Sources::IndexT index) @@ -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: @@ -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(data); auto sinkPredicate = [&info](const ISink& sink) -> bool diff --git a/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/GeneralDevide.cpp b/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/GeneralDevide.cpp index a8eca45..7076e51 100644 --- a/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/GeneralDevide.cpp +++ b/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/GeneralDevide.cpp @@ -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 @@ -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; } } } diff --git a/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/Helpers.cpp b/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/Helpers.cpp index dcc0d7f..c09a44b 100644 --- a/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/Helpers.cpp +++ b/packages/ghaf-audio-control/src/lib/src/Backends/PulseAudio/Helpers.cpp @@ -5,9 +5,10 @@ #include -#include #include +#include + namespace ghaf::AudioControl::Backend::PulseAudio { @@ -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)));