Skip to content

Commit

Permalink
Merge pull request #11 from baz2142/audio-control-devices
Browse files Browse the repository at this point in the history
Audio control: Speakers and microphones support
  • Loading branch information
brianmcgillion authored Oct 18, 2024
2 parents 974ab95 + bd1e30f commit b8263bb
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 157 deletions.
13 changes: 11 additions & 2 deletions packages/ghaf-audio-control/src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <GhafAudioControl/AudioControl.hpp>
#include <GhafAudioControl/Backends/PulseAudio/AudioControlBackend.hpp>
#include <GhafAudioControl/utils/Debug.hpp>
#include <GhafAudioControl/utils/Logger.hpp>
#include <GhafAudioControl/widgets/AudioControl.hpp>

#include <glibmm/main.h>
#include <glibmm/optioncontext.h>
Expand Down Expand Up @@ -36,6 +36,7 @@ int GtkClient(const std::string& pulseAudioServerAddress, const std::string& app
{
auto app = Gtk::Application::create();
Gtk::ApplicationWindow window;
window.set_title("Ghaf Audio Control");

AudioControl audioControl{std::make_unique<Backend::PulseAudio::AudioControlBackend>(pulseAudioServerAddress), GetAppVmsList(appVms)};

Expand Down Expand Up @@ -81,5 +82,13 @@ int main(int argc, char** argv)
return 1;
}

return GtkClient(pulseServerAddress, appVms);
try
{
return GtkClient(pulseServerAddress, appVms);
}
catch (const std::exception& e)
{
Logger::error(std::format("Exception: {}", e.what()));
return 1;
}
}
18 changes: 8 additions & 10 deletions packages/ghaf-audio-control/src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ add_library(${LIBRARY_NAME})

target_sources(${LIBRARY_NAME}
PRIVATE
src/AppList.cpp
src/AudioControl.cpp

src/Backends/PulseAudio/AudioControlBackend.cpp
src/Backends/PulseAudio/GeneralDevide.cpp
src/Backends/PulseAudio/Helpers.cpp
Expand All @@ -26,14 +23,16 @@ PRIVATE
src/Backends/PulseAudio/SourceOutput.cpp
src/Backends/PulseAudio/Volume.cpp

src/models/AppVmModel.cpp
src/models/DeviceListModel.cpp
src/models/DeviceModel.cpp

src/utils/ConnectionContainer.cpp
src/utils/Debug.cpp
src/utils/Logger.cpp

src/widgets/AppVmWidget.cpp
src/widgets/AppList.cpp
src/widgets/AudioControl.cpp
src/widgets/DeviceListWidget.cpp
src/widgets/DeviceWidget.cpp
src/widgets/SinkWidget.cpp

Expand All @@ -42,9 +41,6 @@ PUBLIC
TYPE HEADERS
BASE_DIRS include
FILES
include/GhafAudioControl/AppList.hpp
include/GhafAudioControl/AudioControl.hpp

include/GhafAudioControl/Backends/PulseAudio/AudioControlBackend.hpp
include/GhafAudioControl/Backends/PulseAudio/GeneralDevice.hpp
include/GhafAudioControl/Backends/PulseAudio/Helpers.hpp
Expand All @@ -57,7 +53,7 @@ PUBLIC
include/GhafAudioControl/IAudioControlBackend.hpp
include/GhafAudioControl/Volume.hpp

include/GhafAudioControl/models/AppVmModel.hpp
include/GhafAudioControl/models/DeviceListModel.hpp
include/GhafAudioControl/models/DeviceModel.hpp

include/GhafAudioControl/utils/ConnectionContainer.hpp
Expand All @@ -66,7 +62,9 @@ PUBLIC
include/GhafAudioControl/utils/RaiiWrap.hpp
include/GhafAudioControl/utils/ScopeExit.hpp

include/GhafAudioControl/widgets/AppVmWidget.hpp
include/GhafAudioControl/widgets/AppList.hpp
include/GhafAudioControl/widgets/AudioControl.hpp
include/GhafAudioControl/widgets/DeviceListWidget.hpp
include/GhafAudioControl/widgets/DeviceWidget.hpp
include/GhafAudioControl/widgets/SinkWidget.hpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Sink final : public IAudioControlBackend::ISink
void update(const pa_sink_info& info)
{
m_device.update(info);
m_onUpdate();
}

void update(const pa_card_info& info)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <GhafAudioControl/IAudioControlBackend.hpp>
#include <GhafAudioControl/models/DeviceModel.hpp>

#include <glibmm/object.h>
#include <glibmm/property.h>

#include <giomm/liststore.h>

namespace ghaf::AudioControl
{

class DeviceListModel final : public Glib::Object
{
private:
explicit DeviceListModel(std::string name, std::string namePrefix = "");

public:
static Glib::RefPtr<DeviceListModel> create(std::string name, std::string namePrefix = "");

static int compare(const Glib::RefPtr<const DeviceListModel>& a, const Glib::RefPtr<const DeviceListModel>& b);

void addDevice(IAudioControlBackend::ISink::Ptr sink);

[[nodiscard]] Glib::RefPtr<Gio::ListStore<DeviceModel>> getDeviceModels() noexcept
{
return m_devices;
}

[[nodiscard]] auto getAppNameProperty() const
{
return m_name.get_proxy();
}

[[nodiscard]] auto getNamePrefix() const
{
return m_namePrefix;
}

private:
Glib::Property<Glib::ustring> m_name;
std::string m_namePrefix;

Glib::RefPtr<Gio::ListStore<DeviceModel>> m_devices;
std::map<IAudioControlBackend::IDevice::IntexT, sigc::connection> m_deviceConnections;
};

} // namespace ghaf::AudioControl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once

#include <GhafAudioControl/models/AppVmModel.hpp>
#include <GhafAudioControl/models/DeviceListModel.hpp>

#include <gtkmm/box.h>
#include <gtkmm/cssprovider.h>
Expand All @@ -30,10 +30,7 @@ class AppList final : public Gtk::Box

private:
Gtk::ListBox m_listBox;

Glib::RefPtr<Gtk::CssProvider> m_cssProvider;
Glib::RefPtr<Gio::ListStore<AppVmModel>> m_appsModel;
std::map<AppVmModel::AppIdType, std::vector<Glib::RefPtr<Glib::Binding>>> m_appsBindings;
Glib::RefPtr<Gio::ListStore<DeviceListModel>> m_appsModel;
};

} // namespace ghaf::AudioControl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

#pragma once

#include <GhafAudioControl/AppList.hpp>
#include <GhafAudioControl/IAudioControlBackend.hpp>
#include <GhafAudioControl/widgets/AppList.hpp>
#include <GhafAudioControl/widgets/DeviceListWidget.hpp>

#include <gtkmm/menubutton.h>
#include <gtkmm/popover.h>
Expand Down Expand Up @@ -46,9 +47,16 @@ class AudioControl final : public Gtk::Box
void onPulseError(std::string_view error);

private:
AppList m_appList;
std::unique_ptr<IAudioControlBackend> m_audioControl;

AppList m_appList;

Glib::RefPtr<DeviceListModel> m_sinksModel;
DeviceListWidget m_sinks;

Glib::RefPtr<DeviceListModel> m_sourcesModel;
DeviceListWidget m_sources;

ConnectionContainer m_connections;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,36 @@

#pragma once

#include <GhafAudioControl/models/AppVmModel.hpp>
#include <GhafAudioControl/widgets/DeviceWidget.hpp>
#include <GhafAudioControl/models/DeviceListModel.hpp>

#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/cssprovider.h>
#include <gtkmm/label.h>
#include <gtkmm/listbox.h>
#include <gtkmm/revealer.h>
#include <gtkmm/separator.h>
#include <gtkmm/stack.h>

#include <glibmm/binding.h>

namespace ghaf::AudioControl
{

class AppVmWidget final : public Gtk::Box
class DeviceListWidget : public Gtk::Box
{
public:
explicit AppVmWidget(Glib::RefPtr<AppVmModel> model);
explicit DeviceListWidget(Glib::RefPtr<DeviceListModel> devicesModel);

void reveal(bool reveal = true);

private:
void onDeviceChange(guint position, guint removed, guint added);

std::string getName() const;

private:
Glib::RefPtr<AppVmModel> m_model;
Glib::RefPtr<DeviceListModel> m_model;

Gtk::Box m_revealerBox;
Gtk::ListBox m_listBox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ constexpr auto PropertyAppVmName = "application.process.host";
GeneralDeviceImpl::GeneralDeviceImpl(const pa_sink_info& info, pa_context& context)
: m_index(info.index)
, m_cardIndex(info.card)
, m_name(info.name)
, m_description(info.description)
, m_name(info.description)
, m_description(info.name)
, m_context(context)
, m_channel_map(info.channel_map)
, m_volume(info.volume)
Expand All @@ -29,8 +29,8 @@ GeneralDeviceImpl::GeneralDeviceImpl(const pa_sink_info& info, pa_context& conte
GeneralDeviceImpl::GeneralDeviceImpl(const pa_source_info& info, pa_context& context)
: m_index(info.index)
, m_cardIndex(info.card)
, m_name(info.name)
, m_description(info.description)
, m_name(info.description)
, m_description(info.name)
, m_context(context)
, m_channel_map(info.channel_map)
, m_volume(info.volume)
Expand Down Expand Up @@ -125,8 +125,8 @@ void GeneralDeviceImpl::update(const pa_sink_info& info)
const std::lock_guard l{m_mutex};

m_cardIndex = info.card;
m_name = info.name;
m_description = info.description;
m_name = info.description;
m_description = info.name;
m_channel_map = info.channel_map;
m_volume = info.volume;
m_isMuted = static_cast<bool>(info.mute);
Expand All @@ -137,8 +137,8 @@ void GeneralDeviceImpl::update(const pa_source_info& info)
const std::lock_guard l{m_mutex};

m_cardIndex = info.card;
m_name = info.name;
m_description = info.description;
m_name = info.description;
m_description = info.name;
m_channel_map = info.channel_map;
m_volume = info.volume;
m_isMuted = static_cast<bool>(info.mute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ uint32_t Source::getCardIndex() const
void Source::update(const pa_source_info& info)
{
m_device.update(info);
m_onUpdate();
}

void Source::update(const pa_card_info& info)
Expand Down
Loading

0 comments on commit b8263bb

Please sign in to comment.