mixer: add clearer pulseaudio control naming
[apps/mixer.git] / app / paclient.h
1 /*
2  * Copyright (C) 2016,2017 Konsulko Group
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <pulse/pulseaudio.h>
18
19 #include <QtCore/QHash>
20 #include <QtCore/QObject>
21
22 const char * const channel_position_string[] =
23 {
24         "Mono",
25         "Front Left",
26         "Front Right",
27         "Center",
28         "Rear Center",
29         "Rear Left",
30         "Rear Right",
31         "LFE",
32         "Left Center",
33         "Right Center",
34         "Side Left",
35         "Side Right",
36 };
37
38 enum control_type
39 {
40         C_SOURCE,
41         C_SINK
42 };
43
44 typedef struct
45 {
46         uint32_t type;
47         uint32_t index;
48         pa_cvolume cvolume;
49 } CState;
50
51 class PaClient : public QObject
52 {
53         Q_OBJECT
54         public:
55                 PaClient();
56                 ~PaClient();
57
58                 void init();
59                 void close();
60
61                 inline pa_context *context() const
62                 {
63                         return m_ctx;
64                 }
65
66                 inline void lock()
67                 {
68                         pa_threaded_mainloop_lock(m_ml);
69                 }
70
71                 inline void unlock()
72                 {
73                         pa_threaded_mainloop_unlock(m_ml);
74                 }
75
76                 void addOneControlState(int type, int index, const pa_cvolume *cvolume);
77
78                 QHash<int, pa_cvolume *> sink_states();
79                 QHash<int, pa_cvolume *> source_states();
80
81         public slots:
82                 void setVolume(uint32_t type, uint32_t index, uint32_t channel, uint32_t volume);
83
84         signals:
85                 void controlAdded(int cindex, QString name, QString desc, int type, int channel, const char *cdesc, int volume);
86                 void volumeExternallyChanged(uint32_t type, uint32_t cindex, uint32_t channel, uint32_t volume);
87
88         private:
89                 bool m_init;
90                 pa_threaded_mainloop *m_ml;
91                 pa_mainloop_api *m_mlapi;
92                 pa_context *m_ctx;
93                 QHash<int, pa_cvolume *> m_sink_states;
94                 QHash<int, pa_cvolume *> m_source_states;
95
96         public slots:
97 };