mirror of
https://github.com/LMMS/lmms.git
synced 2026-03-10 18:19:42 -04:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ) );
|
||||
}
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
@@ -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