1367e8192ae1dccb5ea81610949d2561d94b307a
[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/QObject>
20
21 const char * const channel_position_string[] =
22 {
23         "Mono",
24         "Front Left",
25         "Front Right",
26         "Center",
27         "Rear Center",
28         "Rear Left",
29         "Rear Right",
30         "LFE",
31         "Left Center",
32         "Right Center",
33         "Side Left",
34         "Side Right",
35 };
36
37 enum control_type
38 {
39         C_SOURCE,
40         C_SINK
41 };
42
43 typedef struct
44 {
45         uint32_t type;
46         uint32_t index;
47         pa_cvolume cvolume;
48 } CState;
49
50 class PaClient : public QObject
51 {
52         Q_OBJECT
53         public:
54                 PaClient();
55                 ~PaClient();
56
57                 void init();
58                 void close();
59
60                 inline pa_context *context() const
61                 {
62                         return m_ctx;
63                 }
64
65                 inline void lock()
66                 {
67                         pa_threaded_mainloop_lock(m_ml);
68                 }
69
70                 inline void unlock()
71                 {
72                         pa_threaded_mainloop_unlock(m_ml);
73                 }
74
75                 void addOneControlState(int type, int index, const pa_cvolume *cvolume);
76
77         public slots:
78                 void setVolume(uint32_t type, uint32_t index, uint32_t channel, uint32_t volume);
79
80         signals:
81                 void controlAdded(int cindex, QString desc, int type, int channel, const char *cdesc, int volume);
82
83         private:
84                 bool m_init;
85                 pa_threaded_mainloop *m_ml;
86                 pa_mainloop_api *m_mlapi;
87                 pa_context *m_ctx;
88                 QList<CState *> m_cstatelist;
89 };