3
* Copyright (C) 2002 George Staikos <staikos@kde.org>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public License
16
* along with this library; see the file COPYING.LIB. If not, write to
17
* the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
24
#include "kdetv_oss.h"
27
#include <kmessagebox.h>
31
#include <qcombobox.h>
35
#include <sys/ioctl.h>
38
#include <sys/types.h>
42
#if defined(__linux__)
43
#include <sys/soundcard.h>
44
#elif defined(__FreeBSD__)
45
#include "machine/soundcard.h"
46
#elif defined(__NetBSD__)
47
#include <soundcard.h>
51
const char *const devNames[] = SOUND_DEVICE_LABELS;
54
QWidget *KdetvOSS::configWidget(QWidget *parent, const char *name)
56
QFrame *w = new QFrame(parent, name);
57
QGridLayout *g = new QGridLayout(w, 7, 7);
59
g->addMultiCellWidget(new QLabel(i18n("Physical mixer:"), w), 0, 0, 0, 2);
60
_cfg_devs = new QComboBox(w, "Device List");
61
g->addMultiCellWidget(_cfg_devs, 0, 0, 3, 7);
64
_cfg_devs->insertStringList(_devlist);
66
connect(_cfg_devs, SIGNAL(activated(const QString&)),
67
this, SLOT(deviceChanged(const QString&)));
69
g->addMultiCellWidget(new QLabel(i18n("Mixer device:"), w), 1, 1, 0, 2);
70
_cfg_mixers = new QComboBox(w, "Mixer List");
71
g->addMultiCellWidget(_cfg_mixers, 1, 1, 3, 7);
74
_cfg_mixers->insertStringList(_mixerMap[_devlist[0]]);
75
//kdDebug() << "Mixer size: " << _mixers.count()
76
// << " Dev size: " << _devlist.count() << endl;
78
if (!_dev.isEmpty()) {
79
for (int i = 0; i < _cfg_devs->count(); i++) {
80
if (_cfg_devs->text(i) == _dev) {
81
_cfg_devs->setCurrentItem(i);
82
_cfg_devs->setEditText(_dev);
87
KMessageBox::error(0L,
88
i18n("No mixers found. Check you OSS driver installation."),
89
i18n("No OSS Mixers Found"));
94
if (!_currentMixer.isEmpty()) {
95
for (int i = 0; i < _cfg_mixers->count(); i++) {
96
if (_cfg_mixers->text(i) == _currentMixer) {
97
_cfg_mixers->setCurrentItem(i);
98
_cfg_mixers->setEditText(_currentMixer);
104
//kdDebug() << "Kdetv OSS plugin: Created a configuration widget!" << endl;
109
KdetvOSS::KdetvOSS(Kdetv *ktv, QObject *parent, const char* name)
110
: KdetvMixerPlugin(ktv, "ossmixer", parent,name), _muted(false)
112
kdDebug() << "Kdetv OSS plugin loaded successfully." << endl;
119
dev = "/dev/mixer%1";
120
if (!access("/dev/sound/mixer", R_OK|W_OK)) {
121
// we are using devfs, so change the device divining string
122
dev = "/dev/sound/mixer%1";
123
_devlist << "/dev/sound/mixer";
125
if (!access("/dev/mixer", R_OK|W_OK)) {
126
_devlist << "/dev/mixer";
128
for (int i = 0; i < 9; i++) {
129
if (!access(dev.arg(i).local8Bit(), R_OK|W_OK)) {
130
_devlist << dev.arg(i);
134
if (!access("/dev/dsp", R_OK|W_OK)) {
135
_devlist << "/dev/dsp";
138
for (int i = 0; i < 9; i++) {
139
if (!access(dev.arg(i).local8Bit(), R_OK|W_OK)) {
140
_devlist << dev.arg(i);
148
_cfg->setGroup("Mixer");
149
_dev = _cfg->readEntry("Device", "");
150
_currentMixer = _cfg->readEntry("Mixer", "");
151
if (!_devlist.contains(_dev)) {
156
if (!_devlist.isEmpty()) {
159
_fd = open(_dev.latin1(), O_RDWR);
161
_mixers = _mixerMap[_dev];
162
setMixer(_currentMixer.isEmpty() ? i18n("Vol")
167
preMuteLevels.left = -1;
168
preMuteLevels.right = -1;
172
KdetvOSS::~KdetvOSS()
174
kdDebug() << "Kdetv OSS plugin unloaded." << endl;
180
void KdetvOSS::saveConfig()
186
QString nd = _cfg_devs->currentText();
187
_fd = open(nd.local8Bit(), O_RDWR);
191
setMixer(_cfg_mixers->currentText());
192
_mixers = _mixerMap[_dev];
193
_cfg->setGroup("Mixer");
194
_cfg->writeEntry("Device", nd);
195
_cfg->writeEntry("Mixer", _currentMixer);
197
kdDebug() << "OSS successfully opened mixer " << _dev
198
<< " (" << _currentMixer << ")" << endl;
201
emit volumeChanged(_left, _right);
205
void KdetvOSS::deviceChanged(const QString& dev)
207
_cfg_mixers->clear();
208
_cfg_mixers->insertStringList(_mixerMap[dev]);
212
int KdetvOSS::setMixer(const QString& mixer)
214
for (int i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
215
if (mixer == devNames[i]) {
216
kdDebug() << "OSS Plugin switched to mixer: " << devNames[i] << endl;
218
_currentMixer = mixer;
228
int KdetvOSS::probeDevices()
230
QStringList killList;
236
for (QStringList::ConstIterator it = _devlist.constBegin(); it != _devlist.constEnd(); ++it) {
237
_fd = open((*it).local8Bit(), O_RDWR);
243
_mixerMap[*it].clear();
245
if (-1 != ioctl(_fd, SOUND_MIXER_READ_DEVMASK, &_mask)) {
247
for (int i = 0; i < SOUND_MIXER_NRDEVICES; i++)
248
if (_mask & (1 << i)) {
249
kdDebug() << "OSS Plugin found a mixer for " << *it << " (" << i << "): " << devNames[i] << endl;
250
_mixerMap[*it] << devNames[i];
254
if (_mixerMap[*it].isEmpty()) {
261
for (QStringList::ConstIterator it = killList.constBegin(); it != killList.constEnd(); ++it)
262
_devlist.remove(*it);
266
if (!_dev.isEmpty()) {
267
_fd = open(_dev.latin1(), O_RDWR);
271
_mixers = _mixerMap[_dev];
272
if (_mixers.count() > 0) {
273
setMixer(_mixers[0]);
282
int KdetvOSS::setVolume(int left, int right)
284
// Unmute if already muted...
287
preMuteLevels.right = preMuteLevels.left = -1;
290
//kdDebug() << "KdetvOSS::setVolume: Left = " << left << ", right = "
292
int vol = left + (right << 8);
297
if (-1 == ioctl(_fd, MIXER_WRITE(_devnum), &vol))
307
int KdetvOSS::volume()
312
vol = preMuteLevels.left + (preMuteLevels.right << 8);
317
if (-1 == ioctl(_fd, MIXER_READ(_devnum), &vol)) {
322
_right = (vol >> 8) & 0xff;
329
int KdetvOSS::volumeLeft()
331
return volume() & 0xff;
335
int KdetvOSS::volumeRight()
337
return (volume() >> 8) & 0xff;
341
int KdetvOSS::setMuted(bool mute)
344
// If we are already muted, ignore the request.
345
if (mute != _muted) {
346
preMuteLevels.right = _right;
347
preMuteLevels.left = _left;
354
if (-1 == ioctl(_fd, MIXER_WRITE(_devnum), &vol))
361
if (preMuteLevels.left != -1 && preMuteLevels.right != -1) {
362
setVolume (preMuteLevels.left, preMuteLevels.right);
363
preMuteLevels.right = preMuteLevels.left = -1;
370
bool KdetvOSS::muted()
377
KdetvOSS* create_oss(Kdetv *ktv)
379
return new KdetvOSS(ktv, 0, "OSS plugin");
383
#include "kdetv_oss.moc"