2025-09-17 Fred Gleason <fredg@paravelsystems.com>

* Added a 'librdalsa' convenience library in 'rdalsa/'.
	* Moved the 'RDAlsaCard' class from 'utils/rdalsaconfig/' to
	'rdalsa/' to contain ALSA card quirk information.
	* Refactored the ALSA driver in caed(8) to use 'RDAlsaCard'.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2025-09-17 17:17:09 -04:00
parent 1d608b5321
commit e5340cfce8
13 changed files with 218 additions and 64 deletions

56
rdalsa/Makefile.am Normal file
View File

@@ -0,0 +1,56 @@
## Makefile.am
##
## Makefile.am for rivendell/rdalsa
##
## by Fred Gleason <fredg@paravelsystems.com>
##
## (C) Copyright 2025 Fred Gleason <fredg@paravelsystems.com>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License version 2 as
## published by the Free Software Foundation.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public
## License along with this program; if not, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##
## Use automake to process this into a Makefile.in
AM_CPPFLAGS = -Wall -DPREFIX=\"$(prefix)\" -Wno-strict-aliasing -std=c++11 -fPIC -I$(top_srcdir)/lib @QT5_CFLAGS@ @IMAGEMAGICK_CFLAGS@
LIBS = -L$(top_srcdir)/lib
MOC = @QT_MOC@
CWRAP = ../helpers/cwrap
# The dependency for qt's Meta Object Compiler (moc)
moc_%.cpp: %.h
$(MOC) $< -o $@
# The cwrap dependency
html_%.cpp: %.html
$(CWRAP) -o $@ $<
lib_LTLIBRARIES = librdalsa.la
dist_librdalsa_la_SOURCES = rdalsacard.cpp rdalsacard.h
librdalsa_la_LDFLAGS = -release $(VERSION)
CLEANFILES = *~\
*.idb\
*.ilk\
*.lib\
*.obj\
*.pdb\
*.qm\
moc_*
DISTCLEAN = Makefile
MAINTAINERCLEANFILES = *~\
Makefile\
Makefile.in\
moc_*

169
rdalsa/rdalsacard.cpp Normal file
View File

@@ -0,0 +1,169 @@
// rdalsacard.cpp
//
// Abstract ALSA 'card' information
//
// (C) Copyright 2019-2025 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <QObject>
#include <rdapplication.h>
#include "rdalsacard.h"
RDAlsaCard::RDAlsaCard(snd_ctl_t *ctl,int index)
{
card_enabled=false;
card_index=index;
snd_ctl_card_info_t *card_info;
snd_ctl_card_info_malloc(&card_info);
snd_ctl_card_info(ctl,card_info);
card_id=QString(snd_ctl_card_info_get_id(card_info));
card_driver=QString(snd_ctl_card_info_get_driver(card_info));
card_name=QString(snd_ctl_card_info_get_name(card_info));
card_pretty_name=card_name;
card_long_name=QString(snd_ctl_card_info_get_longname(card_info));
card_pretty_long_name=card_long_name;
card_mixer_name=QString(snd_ctl_card_info_get_mixername(card_info));
card_pretty_mixer_name=card_mixer_name;
card_max_channels_per_pcm=rda->config()->alsaChannelsPerPcm();
//
// Apply Specific Device Quirks
//
if(card_name=="Loopback") { // Fix the opaque name assigned by Wheatstone
card_pretty_name.replace("Loopback","WheatNet");
card_pretty_long_name.replace("Loopback","WheatNet");
card_pretty_mixer_name.replace("Loopback","WheatNet");
if(card_max_channels_per_pcm<0) {
card_max_channels_per_pcm=2;
}
}
snd_ctl_card_info_free(card_info);
}
RDAlsaCard::RDAlsaCard(const QString &id,int index)
{
card_id=id;
card_index=index;
card_driver=QObject::tr("ALSA Driver");
card_name=card_id;
card_pretty_name=card_name;
card_long_name=QObject::tr("ALSA Device")+" "+card_id;
card_pretty_long_name=card_long_name;
card_mixer_name=QObject::tr("[none]");
card_pretty_mixer_name=card_mixer_name;
card_max_channels_per_pcm=rda->config()->alsaChannelsPerPcm();
}
int RDAlsaCard::index() const
{
return card_index;
}
QString RDAlsaCard::id() const
{
return card_id;
}
QString RDAlsaCard::driver() const
{
return card_driver;
}
QString RDAlsaCard::name() const
{
return card_name;
}
QString RDAlsaCard::prettyName() const
{
return card_pretty_name;
}
QString RDAlsaCard::longName() const
{
return card_long_name;
}
QString RDAlsaCard::prettyLongName() const
{
return card_pretty_long_name;
}
QString RDAlsaCard::mixerName() const
{
return card_long_name;
}
QString RDAlsaCard::prettyMixerName() const
{
return card_pretty_mixer_name;
}
bool RDAlsaCard::isEnabled() const
{
return card_enabled;
}
void RDAlsaCard::setEnabled(bool state)
{
card_enabled=state;
}
int RDAlsaCard::maxChannelsPerPcm() const
{
return card_max_channels_per_pcm;
}
QString RDAlsaCard::dump() const
{
QString ret=QString::asprintf("Card %d\n",index());
ret+=" ID: "+id()+"\n";
ret+=" Name: "+name()+"\n";
ret+=" Pretty Name: "+prettyName()+"\n";
ret+=" Long Name: "+longName()+"\n";
ret+=" Pretty Long Name: "+prettyLongName()+"\n";
ret+=" Driver: "+driver()+"\n";
ret+=" Mixer Name: "+mixerName()+"\n";
ret+=" Pretty Mixer Name: "+prettyMixerName()+"\n";
if(maxChannelsPerPcm()<0) {
ret+=" Max Channels Per PCM: [default]\n";
}
else {
ret+=QString::asprintf(" Max Channels Per PCM: %d\n",maxChannelsPerPcm());
}
return ret;
}

64
rdalsa/rdalsacard.h Normal file
View File

@@ -0,0 +1,64 @@
// rdalsacard.h
//
// Abstract ALSA 'card' information
//
// (C) Copyright 2019-2025 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#ifndef RDALSACARD_H
#define RDALSACARD_H
#ifdef ALSA
#include <alsa/asoundlib.h>
#include <QString>
#include <QStringList>
class RDAlsaCard
{
public:
RDAlsaCard(snd_ctl_t *ctl,int index);
RDAlsaCard(const QString &id,int index);
int index() const;
QString id() const;
QString driver() const;
QString name() const;
QString prettyName() const;
QString longName() const;
QString prettyLongName() const;
QString mixerName() const;
QString prettyMixerName() const;
bool isEnabled() const;
void setEnabled(bool state);
int maxChannelsPerPcm() const;
QString dump() const;
private:
int card_index;
QString card_id;
QString card_driver;
QString card_name;
QString card_pretty_name;
QString card_long_name;
QString card_pretty_long_name;
QString card_mixer_name;
QString card_pretty_mixer_name;
int card_max_channels_per_pcm;
bool card_enabled;
};
#endif // ALSA
#endif // RDALSACARD_H