summaryrefslogtreecommitdiff
path: root/src/audio/devices.hpp
blob: 54d1713ed76bbfa71ef4174904423a94dfcdb6e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#ifdef WITH_VOICE

// clang-format off

#include <gtkmm/liststore.h>

#ifndef USE_PORTAUDIO
#include <miniaudio.h>
#else
#include <portaudio.h>
#endif

#include <optional>

// clang-format on

class AudioDevices {
public:
    AudioDevices();

    Glib::RefPtr<Gtk::ListStore> GetPlaybackDeviceModel();
    Glib::RefPtr<Gtk::ListStore> GetCaptureDeviceModel();

	#ifndef USE_PORTAUDIO
    void SetDevices(ma_device_info *pPlayback, ma_uint32 playback_count, ma_device_info *pCapture, ma_uint32 capture_count);
	#else
	/* call Pa directly */
	void SetDevices();
	#endif

#ifdef USE_PORTAUDIO
    [[nodiscard]] std::optional<PaDeviceIndex> GetPlaybackDeviceIDFromModel(const Gtk::TreeModel::iterator &iter) const;
    [[nodiscard]] std::optional<PaDeviceIndex> GetCaptureDeviceIDFromModel(const Gtk::TreeModel::iterator &iter) const;

    [[nodiscard]] std::optional<PaDeviceIndex> GetDefaultPlayback() const;
    [[nodiscard]] std::optional<PaDeviceIndex> GetDefaultCapture() const;
#else
    [[nodiscard]] std::optional<ma_device_id> GetPlaybackDeviceIDFromModel(const Gtk::TreeModel::iterator &iter) const;
    [[nodiscard]] std::optional<ma_device_id> GetCaptureDeviceIDFromModel(const Gtk::TreeModel::iterator &iter) const;

    [[nodiscard]] std::optional<ma_device_id> GetDefaultPlayback() const;
    [[nodiscard]] std::optional<ma_device_id> GetDefaultCapture() const;
#endif

    void SetActivePlaybackDevice(const Gtk::TreeModel::iterator &iter);
    void SetActiveCaptureDevice(const Gtk::TreeModel::iterator &iter);

    Gtk::TreeModel::iterator GetActivePlaybackDevice();
    Gtk::TreeModel::iterator GetActiveCaptureDevice();

private:
    class PlaybackColumns : public Gtk::TreeModel::ColumnRecord {
    public:
        PlaybackColumns();

        Gtk::TreeModelColumn<Glib::ustring> Name;
#ifdef USE_PORTAUDIO
        Gtk::TreeModelColumn<PaDeviceIndex> DeviceID;
#else
        Gtk::TreeModelColumn<ma_device_id> DeviceID;
#endif
    };
    PlaybackColumns m_playback_columns;
    Glib::RefPtr<Gtk::ListStore> m_playback;
    Gtk::TreeModel::iterator m_active_playback_iter;
    Gtk::TreeModel::iterator m_default_playback_iter;

    class CaptureColumns : public Gtk::TreeModel::ColumnRecord {
    public:
        CaptureColumns();

        Gtk::TreeModelColumn<Glib::ustring> Name;
#ifndef USE_PORTAUDIO
        Gtk::TreeModelColumn<ma_device_id> DeviceID;
#else /* USE_PORTAUDIO */
        Gtk::TreeModelColumn<PaDeviceIndex> DeviceID;
#endif /* USE_PORTAUDIO */
    };
    CaptureColumns m_capture_columns;
    Glib::RefPtr<Gtk::ListStore> m_capture;
    Gtk::TreeModel::iterator m_active_capture_iter;
    Gtk::TreeModel::iterator m_default_capture_iter;
};
#endif