mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-05-28 14:42:34 +02:00
2019-08-26 Fred Gleason <fredg@paravelsystems.com>
* Reimplemented the '--autogen' directive in rdalsaconfig(8). * Added a '--rewrite' directive in rdalsaconfig(8).
This commit is contained in:
parent
9df39e2bb4
commit
a658fda4fc
@ -18962,3 +18962,6 @@
|
||||
2019-08-26 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Reimplemented the '--manage-daemons' directive in
|
||||
rdalsaconfig(8).
|
||||
2019-08-26 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Reimplemented the '--autogen' directive in rdalsaconfig(8).
|
||||
* Added a '--rewrite' directive in rdalsaconfig(8).
|
||||
|
@ -43,6 +43,7 @@ RDAlsaCard::RDAlsaCard(snd_ctl_t *ctl,int index)
|
||||
card_pcm_names.push_back(snd_pcm_info_get_name(pcm_info)+
|
||||
QString().sprintf("[%02d]",pcm+1));
|
||||
snd_ctl_pcm_next_device(ctl,&pcm);
|
||||
card_enableds.push_back(false);
|
||||
}
|
||||
}
|
||||
snd_pcm_info_free(pcm_info);
|
||||
@ -86,6 +87,18 @@ QString RDAlsaCard::mixerName() const
|
||||
}
|
||||
|
||||
|
||||
bool RDAlsaCard::isEnabled(int pcm_num) const
|
||||
{
|
||||
return card_enableds.at(pcm_num);
|
||||
}
|
||||
|
||||
|
||||
void RDAlsaCard::setEnabled(int pcm_num,bool state)
|
||||
{
|
||||
card_enableds[pcm_num]=state;
|
||||
}
|
||||
|
||||
|
||||
QString RDAlsaCard::dump() const
|
||||
{
|
||||
QString ret=QString().sprintf("Card %d\n",index());
|
||||
|
@ -38,6 +38,8 @@ class RDAlsaCard
|
||||
QString mixerName() const;
|
||||
int pcmQuantity() const;
|
||||
QString pcmName(int n) const;
|
||||
bool isEnabled(int pcm_num) const;
|
||||
void setEnabled(int pcm_num,bool state);
|
||||
QString dump() const;
|
||||
|
||||
private:
|
||||
@ -48,6 +50,7 @@ class RDAlsaCard
|
||||
QString card_long_name;
|
||||
QString card_mixer_name;
|
||||
QStringList card_pcm_names;
|
||||
QList<bool> card_enableds;
|
||||
};
|
||||
|
||||
|
||||
|
@ -43,6 +43,7 @@
|
||||
//
|
||||
QString alsa_filename;
|
||||
bool alsa_autogen=false;
|
||||
bool alsa_rewrite=false;
|
||||
bool alsa_manage_daemons=false;
|
||||
bool alsa_daemon_start_needed=false;
|
||||
|
||||
@ -230,6 +231,21 @@ void MainWidget::closeEvent(QCloseEvent *e)
|
||||
|
||||
void MainWidget::LoadConfig(const QString &filename)
|
||||
{
|
||||
if(!alsa_system_model->loadConfig(filename)) {
|
||||
return;
|
||||
}
|
||||
for(int i=0;i<alsa_system_model->rowCount();i++) {
|
||||
if(alsa_system_model->isEnabled(i)) {
|
||||
alsa_system_list->selectionModel()->
|
||||
select(alsa_system_model->index(i,0),QItemSelectionModel::Select);
|
||||
}
|
||||
else {
|
||||
alsa_system_list->selectionModel()->
|
||||
select(alsa_system_model->index(i,0),QItemSelectionModel::Deselect);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
FILE *f=NULL;
|
||||
char line[1024];
|
||||
int istate=0;
|
||||
@ -309,11 +325,20 @@ void MainWidget::LoadConfig(const QString &filename)
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::SaveConfig(const QString &filename) const
|
||||
{
|
||||
for(int i=0;i<alsa_system_model->rowCount();i++) {
|
||||
QItemSelectionModel *sel=alsa_system_list->selectionModel();
|
||||
alsa_system_model->setEnabled(i,sel->isRowSelected(i,QModelIndex()));
|
||||
}
|
||||
alsa_system_model->saveConfig(filename);
|
||||
|
||||
|
||||
/*
|
||||
QString tempfile=filename+"-temp";
|
||||
FILE *f=NULL;
|
||||
|
||||
@ -346,6 +371,51 @@ void MainWidget::SaveConfig(const QString &filename) const
|
||||
|
||||
fclose(f);
|
||||
rename(tempfile.toUtf8(),filename.toUtf8());
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
Autogen::Autogen()
|
||||
: QObject()
|
||||
{
|
||||
QString err_msg;
|
||||
|
||||
//
|
||||
// Open the Database
|
||||
//
|
||||
rda=new RDApplication("RDAlsaConfig","rdalsaconfig",RDALSACONFIG_USAGE);
|
||||
if(!rda->open(&err_msg,NULL,false)) {
|
||||
fprintf(stderr,"rdalsaconfig: unable to open database [%s]\n",
|
||||
(const char *)err_msg.toUtf8());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
StopDaemons();
|
||||
|
||||
RDAlsaModel *model=new RDAlsaModel(rda->system()->sampleRate());
|
||||
if(alsa_rewrite) {
|
||||
if(!model->loadConfig(alsa_filename)) {
|
||||
fprintf(stderr,"rdalsaconfig: unable to load file \"%s\"\n",
|
||||
(const char *)alsa_filename.toUtf8());
|
||||
StartDaemons();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if(alsa_autogen) {
|
||||
for(int i=0;i<model->rowCount();i++) {
|
||||
model->setEnabled(i,true);
|
||||
}
|
||||
}
|
||||
if(!model->saveConfig(alsa_filename)) {
|
||||
fprintf(stderr,"rdalsaconfig: unable to load file \"%s\"\n",
|
||||
(const char *)alsa_filename.toUtf8());
|
||||
StartDaemons();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
StartDaemons();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
@ -364,11 +434,20 @@ int main(int argc,char *argv[])
|
||||
if(cmd->key(i)=="--autogen") {
|
||||
alsa_autogen=true;
|
||||
}
|
||||
if(cmd->key(i)=="--rewrite") {
|
||||
alsa_rewrite=true;
|
||||
}
|
||||
if(cmd->key(i)=="--manage-daemons") {
|
||||
alsa_manage_daemons=true;
|
||||
}
|
||||
}
|
||||
|
||||
if(alsa_autogen||alsa_rewrite) {
|
||||
QCoreApplication a(argc,argv);
|
||||
new Autogen();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
//
|
||||
// Start GUI
|
||||
//
|
||||
|
@ -65,4 +65,12 @@ class MainWidget : public QWidget
|
||||
};
|
||||
|
||||
|
||||
class Autogen : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Autogen();
|
||||
};
|
||||
|
||||
|
||||
#endif // RDALSACONFIG_H
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <qstringlist.h>
|
||||
|
||||
#include <rdapplication.h>
|
||||
#include <rdalsamodel.h>
|
||||
|
||||
RDAlsaModel::RDAlsaModel(unsigned samprate,QObject *parent)
|
||||
@ -151,6 +152,164 @@ int RDAlsaModel::pcmNumber(const QModelIndex &index) const
|
||||
}
|
||||
|
||||
|
||||
bool RDAlsaModel::isEnabled(int row) const
|
||||
{
|
||||
return model_alsa_cards.at(model_card_index.at(row))->
|
||||
isEnabled(model_pcm_index.at(row));
|
||||
}
|
||||
|
||||
|
||||
void RDAlsaModel::setEnabled(int row,bool state)
|
||||
{
|
||||
return model_alsa_cards.at(model_card_index.at(row))->
|
||||
setEnabled(model_pcm_index.at(row),state);
|
||||
}
|
||||
|
||||
|
||||
bool RDAlsaModel::loadConfig(const QString &filename)
|
||||
{
|
||||
FILE *f=NULL;
|
||||
char line[1024];
|
||||
int istate=0;
|
||||
int port=0;
|
||||
QString card_id=0;
|
||||
int card_num=0;
|
||||
bool ok=false;
|
||||
int device=0;
|
||||
QStringList list;
|
||||
bool active_line=false;
|
||||
QModelIndex index;
|
||||
|
||||
if((f=fopen(filename.toUtf8(),"r"))==NULL) {
|
||||
return false;
|
||||
}
|
||||
while(fgets(line,1024,f)!=NULL) {
|
||||
QString str=line;
|
||||
str.replace("\n","");
|
||||
if(str==START_MARKER) {
|
||||
active_line=true;
|
||||
}
|
||||
if(str==END_MARKER) {
|
||||
active_line=false;
|
||||
}
|
||||
if((str!=START_MARKER)&&(str!=END_MARKER)) {
|
||||
if(active_line) {
|
||||
switch(istate) {
|
||||
case 0:
|
||||
if(str.left(6)=="pcm.rd") {
|
||||
port=str.mid(6,1).toInt();
|
||||
istate=1;
|
||||
}
|
||||
else {
|
||||
if(str.left(6)=="ctl.rd") {
|
||||
istate=10;
|
||||
}
|
||||
else {
|
||||
model_other_lines.push_back(str+"\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
list=str.split(" ",QString::SkipEmptyParts);
|
||||
if(list[0]=="}") {
|
||||
if((port>=0)&&(port<RD_MAX_CARDS)) {
|
||||
for(int i=0;i<model_alsa_cards.size();i++) {
|
||||
RDAlsaCard *card=model_alsa_cards.at(i);
|
||||
card_num=card_id.toUInt(&ok);
|
||||
if(ok) {
|
||||
if(card_num==card->index()) {
|
||||
if((device>=0)&&(device<card->pcmQuantity())) {
|
||||
card->setEnabled(device,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(card_id==card->id()) {
|
||||
if((device>=0)&&(device<card->pcmQuantity())) {
|
||||
card->setEnabled(device,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
card_id="";
|
||||
device=0;
|
||||
istate=0;
|
||||
}
|
||||
else {
|
||||
if(list.size()==2) {
|
||||
if(list[0]=="card") {
|
||||
card_id=list[1].trimmed();
|
||||
}
|
||||
if(list[0]=="device") {
|
||||
device=list[1].toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 10:
|
||||
if(str.left(1)=="}") {
|
||||
istate=0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
model_other_lines.push_back(str+"\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RDAlsaModel::saveConfig(const QString &filename)
|
||||
{
|
||||
QString tempfile=filename+"-temp";
|
||||
FILE *f=NULL;
|
||||
int index=0;
|
||||
|
||||
if((f=fopen(tempfile.toUtf8(),"w"))==NULL) {
|
||||
return false;
|
||||
}
|
||||
for(int i=0;i<model_other_lines.size();i++) {
|
||||
fprintf(f,model_other_lines.at(i));
|
||||
}
|
||||
fprintf(f,"%s\n",START_MARKER);
|
||||
for(int i=0;i<model_alsa_cards.size();i++) {
|
||||
RDAlsaCard *card=model_alsa_cards.at(i);
|
||||
for(int j=0;j<card->pcmQuantity();j++) {
|
||||
if(card->isEnabled(j)) {
|
||||
fprintf(f,"pcm.rd%d {\n",index);
|
||||
fprintf(f," type hw\n");
|
||||
fprintf(f," card %s\n",(const char *)card->id().toUtf8());
|
||||
fprintf(f," device %d\n",j);
|
||||
fprintf(f," rate %u\n",rda->system()->sampleRate());
|
||||
if(card->id()=="Axia") {
|
||||
fprintf(f," channels 2\n");
|
||||
}
|
||||
fprintf(f,"}\n");
|
||||
fprintf(f,"ctl.rd%d {\n",index);
|
||||
fprintf(f," type hw\n");
|
||||
fprintf(f," card %s\n",(const char *)card->id().toUtf8());
|
||||
fprintf(f,"}\n");
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
fprintf(f,"%s\n",END_MARKER);
|
||||
|
||||
fclose(f);
|
||||
rename(tempfile.toUtf8(),filename.toUtf8());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void RDAlsaModel::LoadSystemConfig()
|
||||
{
|
||||
snd_ctl_t *snd_ctl=NULL;
|
||||
|
@ -45,6 +45,10 @@ class RDAlsaModel : public QAbstractListModel
|
||||
QModelIndex indexOf(const QString &card_id,int pcm_num) const;
|
||||
RDAlsaCard *card(const QModelIndex &index) const;
|
||||
int pcmNumber(const QModelIndex &index) const;
|
||||
bool isEnabled(int row) const;
|
||||
void setEnabled(int row,bool state);
|
||||
bool loadConfig(const QString &filename);
|
||||
bool saveConfig(const QString &filename);
|
||||
|
||||
private:
|
||||
void LoadSystemConfig();
|
||||
@ -52,6 +56,7 @@ class RDAlsaModel : public QAbstractListModel
|
||||
QList<int> model_card_index;
|
||||
QList<int> model_pcm_index;
|
||||
unsigned model_sample_rate;
|
||||
QStringList model_other_lines;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user