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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
/***************************************************************************
alsa-sound-configuration.cpp - description
-------------------
begin : Thu Sep 30 2004
copyright : (C) 2004 by Martin Witte
email : witte@kawo1.rwth-aachen.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <tqcheckbox.h>
#include <tqgroupbox.h>
#include <tqlayout.h>
#include <tqscrollview.h>
#include <kurlrequester.h>
#include <knuminput.h>
#include <klineedit.h>
#include <kcombobox.h>
#include <ktabwidget.h>
#include <tdelocale.h>
#include "alsa-mixer-element.h"
#include "alsa-sound-configuration.h"
#include "alsa-sound.h"
AlsaSoundConfiguration::AlsaSoundConfiguration (TQWidget *parent, AlsaSoundDevice *dev)
: AlsaSoundConfigurationUI(parent),
m_SoundDevice (dev),
m_groupMixerLayout(NULL),
m_groupMixerScrollView(NULL),
m_groupMixerSubFrame(NULL),
m_dirty(true),
m_ignore_updates(false)
{
TQObject::connect(m_comboPlaybackCard, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotSetDirty()));
TQObject::connect(m_comboCaptureCard, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotSetDirty()));
TQObject::connect(m_comboPlaybackDevice, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotSetDirty()));
TQObject::connect(m_comboCaptureDevice, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotSetDirty()));
TQObject::connect(editHWBufferSize, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotSetDirty()));
TQObject::connect(editBufferSize, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotSetDirty()));
TQObject::connect(chkDisablePlayback, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetDirty()));
TQObject::connect(chkDisableCapture, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetDirty()));
TQObject::connect(m_comboPlaybackCard, TQT_SIGNAL(activated(const TQString &)),
this, TQT_SLOT(slotPlaybackCardSelected(const TQString &)));
TQObject::connect(m_comboCaptureCard, TQT_SIGNAL(activated(const TQString &)),
this, TQT_SLOT(slotCaptureCardSelected(const TQString &)));
m_groupMixer->setColumnLayout(0, Qt::Horizontal );
TQHBoxLayout *tmp_layout = new TQHBoxLayout( m_groupMixer->layout() );
m_groupMixerScrollView = new TQScrollView (m_groupMixer);
m_groupMixerScrollView->setFrameShape(TQFrame::NoFrame);
m_groupMixerScrollView->setFrameShadow(TQFrame::Plain);
m_groupMixerScrollView->enableClipper(true);
m_groupMixerScrollView->setResizePolicy(TQScrollView::AutoOneFit);
//m_groupMixerScrollView->setHScrollBarMode(TQScrollView::AlwaysOn);
tmp_layout->addWidget(m_groupMixerScrollView);
int card = -1;
int ret = 0;
int idx_playback = 0;
int idx_capture = 0;
while ((ret = snd_card_next(&card)) == 0) {
char *name = NULL;
if (card >= 0 && snd_card_get_longname(card, &name) == 0) {
if (name) {
m_name2card[name] = card;
m_card2name[card] = name;
if (listSoundDevices(NULL, NULL, NULL, NULL, card, SND_PCM_STREAM_PLAYBACK)) {
m_comboPlaybackCard->insertItem(name);
m_playbackCard2idx[card] = idx_playback++;
}
if (listSoundDevices(NULL, NULL, NULL, NULL, card, SND_PCM_STREAM_CAPTURE)) {
m_comboCaptureCard->insertItem(name);
m_captureCard2idx[card] = idx_capture++;
}
}
} else {
break;
}
}
slotCancel();
}
AlsaSoundConfiguration::~AlsaSoundConfiguration ()
{
}
void AlsaSoundConfiguration::slotPlaybackCardSelected(const TQString &cardname)
{
if (!m_name2card.contains(cardname))
return;
listSoundDevices(m_comboPlaybackDevice, &m_playbackDeviceName2dev, &m_dev2playbackDeviceName, &m_playbackDevice2idx, m_name2card[cardname], SND_PCM_STREAM_PLAYBACK);
}
void AlsaSoundConfiguration::slotCaptureCardSelected(const TQString &cardname)
{
if (!m_name2card.contains(cardname))
return;
saveCaptureMixerSettings();
listSoundDevices(m_comboCaptureDevice, &m_captureDeviceName2dev, &m_dev2captureDeviceName, &m_captureDevice2idx, m_name2card[cardname], SND_PCM_STREAM_CAPTURE);
m_currentCaptureCard = m_name2card[cardname];
TQStringList vol_list, sw_list, all_list;
TQMap<TQString, AlsaMixerElement> vol_ch2id, sw_ch2id;
AlsaSoundDevice::getCaptureMixerChannels(m_name2card[cardname], NULL, vol_list, vol_ch2id, sw_list, sw_ch2id, &all_list);
for (TQMapIterator<TQString, QAlsaMixerElement*> it = m_MixerElements.begin(); it != m_MixerElements.end(); ++it) {
delete *it;
}
m_MixerElements.clear();
if (m_groupMixerSubFrame)
delete m_groupMixerSubFrame;
m_groupMixerSubFrame = new TQFrame(m_groupMixerScrollView->viewport());
m_groupMixerSubFrame->setSizePolicy(TQSizePolicy::Maximum, TQSizePolicy::Maximum);
m_groupMixerScrollView->addChild(m_groupMixerSubFrame);
int rows = 1;
int cols = (all_list.count()+rows-1)/rows;
m_groupMixerLayout = new TQGridLayout( m_groupMixerSubFrame, rows, cols, 0, 0 );
m_groupMixerLayout->setAlignment( TQt::AlignBottom );
int idx = 0;
for (TQValueListConstIterator<TQString> it = all_list.begin(); it != all_list.end(); ++it, ++idx) {
QAlsaMixerElement *e = new QAlsaMixerElement(m_groupMixerSubFrame, *it,
sw_list.contains(*it), vol_list.contains(*it));
TQObject::connect(e, TQT_SIGNAL(sigDirty()), this, TQT_SLOT(slotSetDirty()));
m_groupMixerLayout->addWidget(e, idx > cols, idx % cols);
e->show();
m_MixerElements.insert(*it, e);
}
restoreCaptureMixerSettings();
m_groupMixerSubFrame->show();
}
void AlsaSoundConfiguration::saveCaptureMixerSettings()
{
for (TQMapIterator<TQString, QAlsaMixerElement*> it = m_MixerElements.begin(); it != m_MixerElements.end(); ++it) {
const TQString &name = it.key();
int card = m_currentCaptureCard;
TQString id = AlsaConfigMixerSetting::getIDString(card, name);
QAlsaMixerElement *e = *it;
float vol = e->getVolume();
bool use = e->getOverride();
bool active = e->getActive();
e->slotResetDirty();
m_MixerSettings[id] = AlsaConfigMixerSetting(card,name,use,active,vol);
}
}
void AlsaSoundConfiguration::restoreCaptureMixerSettings()
{
for (TQMapIterator<TQString, QAlsaMixerElement*> it = m_MixerElements.begin(); it != m_MixerElements.end(); ++it) {
const TQString &name = it.key();
int card = m_currentCaptureCard;
TQString id = AlsaConfigMixerSetting::getIDString(card, name);
QAlsaMixerElement *e = *it;
if (m_MixerSettings.contains(id)) {
const AlsaConfigMixerSetting &s = m_MixerSettings[id];
e->setVolume(s.m_volume);
e->setOverride(s.m_use);
e->setActive(s.m_active);
e->slotResetDirty();
} else {
if (name == "ADC") {
e->setOverride(true);
e->setActive(true);
e->setVolume(1.0);
}
else if (name == "Digital") {
e->setOverride(true);
e->setActive(true);
e->setVolume(1.0);
}
else if (name == "Wave") {
e->setOverride(true);
e->setActive(false);
e->setVolume(0);
}
else if (name == "Capture") {
e->setOverride(true);
e->setActive(true);
e->setVolume(0.01);
}
e->slotSetDirty();
}
}
}
int AlsaSoundConfiguration::listSoundDevices(KComboBox *combobox, TQMap<TQString, int> *devname2dev, TQMap<int, TQString> *dev2devname, TQMap<int, int> *dev2idx, int card, snd_pcm_stream_t stream)
{
snd_ctl_t *handle = NULL;
int dev = -1;
snd_ctl_card_info_t *info = NULL;
snd_pcm_info_t *pcminfo = NULL;
snd_ctl_card_info_alloca(&info);
snd_pcm_info_alloca (&pcminfo);
TQString ctlname = "hw:"+TQString::number(card);
if (combobox)
combobox->clear();
if (devname2dev)
devname2dev->clear();
if (dev2devname)
dev2devname->clear();
if (dev2idx)
dev2idx->clear();
int count = 0;
if (snd_ctl_open (&handle, ctlname.ascii(), 0) == 0) {
if (snd_ctl_card_info(handle, info) == 0) {
dev = -1;
while (1) {
if (snd_ctl_pcm_next_device(handle, &dev) < 0) {
//logError("snd_ctl_pcm_next_device");
}
if (dev < 0)
break;
snd_pcm_info_set_device(pcminfo, dev);
snd_pcm_info_set_subdevice(pcminfo, 0);
snd_pcm_info_set_stream(pcminfo, stream);
int err = 0;
if ((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) {
if (err != -ENOENT) {
//logError(TQString("control digital audio info (%1): %2").arg(card).arg(snd_strerror(err)));
}
continue;
}
const char *dev_name = snd_pcm_info_get_name(pcminfo);
TQString devname = i18n("context-card-plus-device-number", "%1 device %2").arg(dev_name).arg(dev);
if (combobox)
combobox->insertItem(devname);
if (devname2dev)
(*devname2dev)[devname] = dev;
if (dev2devname)
(*dev2devname)[dev] = devname;
if (dev2idx)
(*dev2idx)[dev] = count;
++count;
}
}
snd_ctl_close(handle);
}
return count;
}
void AlsaSoundConfiguration::slotOK()
{
if (!m_dirty)
return;
if (m_SoundDevice) {
m_SoundDevice->setHWBufferSize ( editHWBufferSize ->value() * 1024);
m_SoundDevice->setBufferSize ( editBufferSize ->value() * 1024);
m_SoundDevice->enablePlayback (!chkDisablePlayback->isChecked());
m_SoundDevice->enableCapture (!chkDisableCapture ->isChecked());
int card = m_name2card[m_comboPlaybackCard->currentText()];
int device = m_playbackDeviceName2dev[m_comboPlaybackDevice->currentText()];
m_SoundDevice->setPlaybackDevice( card, device);
card = m_name2card[m_comboCaptureCard->currentText()];
device = m_captureDeviceName2dev[m_comboCaptureDevice->currentText()];
m_SoundDevice->setCaptureDevice ( card, device);
saveCaptureMixerSettings();
m_SoundDevice->setCaptureMixerSettings(m_MixerSettings);
}
m_dirty = false;
}
void AlsaSoundConfiguration::slotCancel()
{
if (!m_dirty)
return;
m_ignore_updates = true;
int card = m_SoundDevice ? m_SoundDevice->getPlaybackCard() : 0;
int dev = m_SoundDevice ? m_SoundDevice->getPlaybackDevice() : 0;
m_comboPlaybackCard ->setCurrentItem(m_playbackCard2idx[card]);
slotPlaybackCardSelected(m_comboPlaybackCard->currentText());
m_comboPlaybackDevice->setCurrentItem(m_playbackDevice2idx[dev]);
card = m_SoundDevice ? m_SoundDevice->getCaptureCard() : 0;
dev = m_SoundDevice ? m_SoundDevice->getCaptureDevice() : 0;
m_comboCaptureCard ->setCurrentItem(m_captureCard2idx[card]);
slotCaptureCardSelected(m_comboCaptureCard->currentText());
m_comboCaptureDevice->setCurrentItem(m_captureDevice2idx[dev]);
//IErrorLogClient::staticLogDebug(TQString("capture: card = %1(%2), dev = %3").arg(card).arg(m_captureCard2idx[card]).arg(dev));
editHWBufferSize ->setValue (m_SoundDevice ? m_SoundDevice->getHWBufferSize()/1024 : 4);
editBufferSize ->setValue (m_SoundDevice ? m_SoundDevice->getBufferSize()/1024 : 4);
chkDisablePlayback->setChecked(m_SoundDevice ? !m_SoundDevice->isPlaybackEnabled() : false);
chkDisableCapture ->setChecked(m_SoundDevice ? !m_SoundDevice->isCaptureEnabled() : false);
//IErrorLogClient::staticLogDebug(TQString("capture: card = %1").arg(m_comboCaptureCard->currentText()));
if (m_SoundDevice)
m_MixerSettings = m_SoundDevice->getCaptureMixerSettings();
else
m_MixerSettings.clear();
restoreCaptureMixerSettings();
m_ignore_updates = false;
m_dirty = false;
}
void AlsaSoundConfiguration::slotUpdateConfig()
{
slotSetDirty();
slotCancel();
}
void AlsaSoundConfiguration::slotSetDirty()
{
if (!m_dirty && !m_ignore_updates) {
m_dirty = true;
//emit sigDirty();
}
}
#include "alsa-sound-configuration.moc"
|