Add Audio-device listing support for alsa-pcm

Added a AlsaDeviceListModel, will do the same for other devices as well
This commit is contained in:
Paul Giblock
2009-10-13 23:12:33 -04:00
parent a3cac6ae79
commit a45a211f2b
3 changed files with 103 additions and 9 deletions

View File

@@ -107,7 +107,7 @@ trackWidget {
/* border-bottom: 1px solid rgb(0, 0, 0);*/
background-color: rgb(0, 0, 0);
}
nameLabel, effectLabel, sf2InstrumentView > QLabel {
nameLabel, effectLabel, sf2InstrumentView > QLabel, QComboBox {
font-size:10px;
}

View File

@@ -35,10 +35,11 @@
#include <alsa/asoundlib.h>
#include "AudioDevice.h"
#include "QAbstractListModel"
class lcdSpinBox;
class QLineEdit;
class QComboBox;
class AudioAlsa : public AudioDevice, public QThread
@@ -54,6 +55,23 @@ public:
}
static QString probeDevice();
class DeviceListModel : public QAbstractListModel
{
public:
// iface = {"pcm", "rawmidi", "timer", "seq"}
// stream = {SND_PCM_STREAM_CAPTURE, SND_PCM_STREAM_PLAYBACK}
DeviceListModel( const char * _iface, snd_pcm_stream_t stream );
int rowCount( const QModelIndex & parent = QModelIndex() ) const;
QVariant data( const QModelIndex & index,
int role = Qt::DisplayRole ) const;
private:
typedef QPair<QString,QString> StringPair;
typedef QList<StringPair> DeviceList;
DeviceList m_devices;
};
class setupWidget : public AudioDevice::setupWidget
@@ -65,9 +83,14 @@ public:
virtual void saveSettings();
private:
QLineEdit * m_device;
QComboBox * m_device;
lcdSpinBox * m_channels;
void poo(const QString & s)
{
printf("Got %s\n", qPrintable( s ) );
}
} ;

View File

@@ -22,7 +22,7 @@
*
*/
#include <QtGui/QLineEdit>
#include <QtGui/QComboBox>
#include <QtGui/QLabel>
#include "AudioAlsa.h"
@@ -491,16 +491,87 @@ int AudioAlsa::setSWParams()
AudioAlsa::DeviceListModel::DeviceListModel(
const char * _iface, snd_pcm_stream_t _stream )
{
void **hints, **n;
char *name, *descr, *io;
const char *filter;
if (snd_device_name_hint(-1, _iface, &hints) < 0)
return;
n = hints;
filter = _stream == SND_PCM_STREAM_CAPTURE ? "Input" : "Output";
while (*n != NULL) {
name = snd_device_name_get_hint(*n, "NAME");
descr = snd_device_name_get_hint(*n, "DESC");
io = snd_device_name_get_hint(*n, "IOID");
// Filter out non-null or filtered items
if (io != NULL && strcmp(io, filter) != 0)
continue;
m_devices.append(StringPair(name, descr));
if (name != NULL)
free(name);
if (descr != NULL)
free(descr);
if (io != NULL)
free(io);
n++;
}
snd_device_name_free_hint(hints);
}
int AudioAlsa::DeviceListModel::rowCount(
const QModelIndex & parent ) const
{
return m_devices.count();
}
QVariant AudioAlsa::DeviceListModel::data(
const QModelIndex & index,
int role ) const
{
switch( role )
{
case Qt::DisplayRole:
return m_devices.at(index.row()).first;
case Qt::ToolTipRole:
case Qt::StatusTipRole:
return m_devices.at(index.row()).second;
default:
return QVariant();
};
}
AudioAlsa::setupWidget::setupWidget( QWidget * _parent ) :
AudioDevice::setupWidget( AudioAlsa::name(), _parent )
{
m_device = new QLineEdit( AudioAlsa::probeDevice(), this );
m_device->setGeometry( 10, 20, 160, 20 );
m_device = new QComboBox( this );
m_device->setGeometry( 10, 20, 180, 20 );
m_device->setModel(
new DeviceListModel( "pcm", SND_PCM_STREAM_PLAYBACK ) );
m_device->setEditable( true );
m_device->setInsertPolicy( QComboBox::NoInsert );
m_device->setEditText( AudioAlsa::probeDevice() );
// Why doesn't Qt already do this?
connect( m_device, SIGNAL(currentIndexChanged(const QString &)),
this, SLOT(poo(const QString &)) );
QLabel * dev_lbl = new QLabel( tr( "DEVICE" ), this );
dev_lbl->setFont( pointSize<6>( dev_lbl->font() ) );
dev_lbl->setGeometry( 10, 40, 160, 10 );
dev_lbl->setGeometry( 10, 40, 180, 10 );
lcdSpinBoxModel * m = new lcdSpinBoxModel( /* this */ );
m->setRange( DEFAULT_CHANNELS, SURROUND_CHANNELS );
@@ -511,7 +582,7 @@ AudioAlsa::setupWidget::setupWidget( QWidget * _parent ) :
m_channels = new lcdSpinBox( 1, this );
m_channels->setModel( m );
m_channels->setLabel( tr( "CHANNELS" ) );
m_channels->move( 180, 20 );
m_channels->move( 200, 20 );
}
@@ -529,7 +600,7 @@ AudioAlsa::setupWidget::~setupWidget()
void AudioAlsa::setupWidget::saveSettings()
{
configManager::inst()->setValue( "audioalsa", "device",
m_device->text() );
m_device->currentText() );
configManager::inst()->setValue( "audioalsa", "channels",
QString::number( m_channels->value<int>() ) );
}