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:
@@ -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>() ) );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user