mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2026-01-13 08:05:55 +01:00
Initial import of CVS-v2_8_branch
This commit is contained in:
55
utils/rdalsaconfig/Makefile.am
Normal file
55
utils/rdalsaconfig/Makefile.am
Normal file
@@ -0,0 +1,55 @@
|
||||
## automake.am
|
||||
##
|
||||
## Automake.am for utils/rdalsaconfig
|
||||
##
|
||||
## (C) Copyright 2009 Fred Gleason <fredg@paravelsystems.com>
|
||||
##
|
||||
## $Id: Makefile.am,v 1.2.8.1 2012/11/29 01:37:37 cvs Exp $
|
||||
##
|
||||
## 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)\" -DQTDIR=\"@QT_DIR@\" @QT_CXXFLAGS@
|
||||
INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/rdhpi
|
||||
LIBS = @QT_LIBS@ -L$(top_srcdir)/lib -L$(top_srcdir)/rdhpi
|
||||
MOC = @QT_MOC@
|
||||
|
||||
# The dependency for qt's Meta Object Compiler (moc)
|
||||
moc_%.cpp: %.h
|
||||
$(MOC) $< -o $@
|
||||
|
||||
bin_PROGRAMS = rdalsaconfig
|
||||
|
||||
dist_rdalsaconfig_SOURCES = alsaitem.cpp alsaitem.h\
|
||||
rdalsa.cpp rdalsa.h\
|
||||
rdalsaconfig.cpp rdalsaconfig.h
|
||||
|
||||
nodist_rdalsaconfig_SOURCES = moc_rdalsaconfig.cpp
|
||||
|
||||
rdalsaconfig_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @LIBALSA@
|
||||
|
||||
EXTRA_DIST = rdalsaconfig.pro
|
||||
|
||||
CLEANFILES = *~\
|
||||
*.qm\
|
||||
moc_*
|
||||
|
||||
MAINTAINERCLEANFILES = *~\
|
||||
*.tar.gz\
|
||||
aclocal.m4\
|
||||
configure\
|
||||
Makefile.in\
|
||||
moc_*
|
||||
68
utils/rdalsaconfig/alsaitem.cpp
Normal file
68
utils/rdalsaconfig/alsaitem.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
// alsaitem.cpp
|
||||
//
|
||||
// QListBoxItem for ALSA PCM devices.
|
||||
//
|
||||
// (C) Copyright 2009 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// $Id: alsaitem.cpp,v 1.2 2010/07/29 19:32:39 cvs Exp $
|
||||
//
|
||||
// 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 <alsaitem.h>
|
||||
|
||||
AlsaItem::AlsaItem(QListBox *listbox,const QString &text)
|
||||
: QListBoxText(listbox,text)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AlsaItem::AlsaItem(const QString &text)
|
||||
: QListBoxText(text)
|
||||
{
|
||||
alsa_card=-1;
|
||||
alsa_device=-1;
|
||||
}
|
||||
|
||||
|
||||
AlsaItem::AlsaItem(const AlsaItem &item)
|
||||
{
|
||||
setText(item.text());
|
||||
setCard(item.card());
|
||||
setDevice(item.device());
|
||||
}
|
||||
|
||||
|
||||
int AlsaItem::card() const
|
||||
{
|
||||
return alsa_card;
|
||||
}
|
||||
|
||||
|
||||
void AlsaItem::setCard(int card)
|
||||
{
|
||||
alsa_card=card;
|
||||
}
|
||||
|
||||
|
||||
int AlsaItem::device() const
|
||||
{
|
||||
return alsa_device;
|
||||
}
|
||||
|
||||
|
||||
void AlsaItem::setDevice(int device)
|
||||
{
|
||||
alsa_device=device;
|
||||
}
|
||||
46
utils/rdalsaconfig/alsaitem.h
Normal file
46
utils/rdalsaconfig/alsaitem.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// alsaitem.h
|
||||
//
|
||||
// QListBoxItem for ALSA PCM devices.
|
||||
//
|
||||
// (C) Copyright 2009 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// $Id: alsaitem.h,v 1.2 2010/07/29 19:32:39 cvs Exp $
|
||||
//
|
||||
// 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 ALSAITEM_H
|
||||
#define ALSAITEM_H
|
||||
|
||||
#include <qlistbox.h>
|
||||
|
||||
class AlsaItem : public QListBoxText
|
||||
{
|
||||
public:
|
||||
AlsaItem(QListBox *listbox,const QString &text=QString::null);
|
||||
AlsaItem(const QString &text=QString::null);
|
||||
AlsaItem(const AlsaItem &item);
|
||||
int card() const;
|
||||
void setCard(int card);
|
||||
int device() const;
|
||||
void setDevice(int device);
|
||||
|
||||
private:
|
||||
int alsa_card;
|
||||
int alsa_device;
|
||||
};
|
||||
|
||||
|
||||
#endif // ALSAITEM_H
|
||||
298
utils/rdalsaconfig/rdalsa.cpp
Normal file
298
utils/rdalsaconfig/rdalsa.cpp
Normal file
@@ -0,0 +1,298 @@
|
||||
// rdalsa.cpp
|
||||
//
|
||||
// Abstract an ALSA configuration.
|
||||
//
|
||||
// (C) Copyright 2009 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// $Id: rdalsa.cpp,v 1.2 2010/07/29 19:32:39 cvs Exp $
|
||||
//
|
||||
// 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#include <qstringlist.h>
|
||||
|
||||
#include <rdalsa.h>
|
||||
|
||||
RDAlsa::RDAlsa()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
unsigned RDAlsa::cards() const
|
||||
{
|
||||
return card_ids.size();
|
||||
}
|
||||
|
||||
|
||||
QString RDAlsa::cardId(unsigned cardnum) const
|
||||
{
|
||||
if(cardnum>=card_ids.size()) {
|
||||
return QString("[invalid card]");
|
||||
}
|
||||
return card_ids[cardnum];
|
||||
}
|
||||
|
||||
|
||||
QString RDAlsa::cardDriver(unsigned cardnum) const
|
||||
{
|
||||
if(cardnum>=card_drivers.size()) {
|
||||
return QString("[invalid card]");
|
||||
}
|
||||
return card_drivers[cardnum];
|
||||
}
|
||||
|
||||
|
||||
QString RDAlsa::cardName(unsigned cardnum) const
|
||||
{
|
||||
if(cardnum>=card_names.size()) {
|
||||
return QString("[invalid card]");
|
||||
}
|
||||
return card_names[cardnum];
|
||||
}
|
||||
|
||||
|
||||
QString RDAlsa::cardLongName(unsigned cardnum) const
|
||||
{
|
||||
if(cardnum>=card_long_names.size()) {
|
||||
return QString("[invalid card]");
|
||||
}
|
||||
return card_long_names[cardnum];
|
||||
}
|
||||
|
||||
|
||||
QString RDAlsa::cardMixerName(unsigned cardnum) const
|
||||
{
|
||||
if(cardnum>=card_mixer_names.size()) {
|
||||
return QString("[invalid card]");
|
||||
}
|
||||
return card_mixer_names[cardnum];
|
||||
}
|
||||
|
||||
|
||||
int RDAlsa::pcmDevices(unsigned cardnum) const
|
||||
{
|
||||
if(cardnum>=card_pcm_names.size()) {
|
||||
return -1;
|
||||
}
|
||||
return card_pcm_names[cardnum].size();
|
||||
}
|
||||
|
||||
|
||||
QString RDAlsa::pcmName(unsigned cardnum,unsigned pcm) const
|
||||
{
|
||||
if(cardnum>=card_pcm_names.size()) {
|
||||
return QString("[invalid pcm device]");
|
||||
}
|
||||
if(pcm>=card_pcm_names[cardnum].size()) {
|
||||
return QString("[invalid pcm device]");
|
||||
}
|
||||
return card_pcm_names[cardnum][pcm];
|
||||
}
|
||||
|
||||
|
||||
int RDAlsa::rivendellCard(int slot) const
|
||||
{
|
||||
return card_rivendell_cards[slot];
|
||||
}
|
||||
|
||||
|
||||
void RDAlsa::setRivendellCard(int slot,int cardnum)
|
||||
{
|
||||
if(slot>=RD_MAX_CARDS) {
|
||||
return;
|
||||
}
|
||||
card_rivendell_cards[slot]=cardnum;
|
||||
}
|
||||
|
||||
|
||||
int RDAlsa::rivendellDevice(int slot) const
|
||||
{
|
||||
return card_rivendell_devices[slot];
|
||||
}
|
||||
|
||||
|
||||
void RDAlsa::setRivendellDevice(int slot,int devnum)
|
||||
{
|
||||
if(slot>=RD_MAX_CARDS) {
|
||||
return;
|
||||
}
|
||||
card_rivendell_devices[slot]=devnum;
|
||||
}
|
||||
|
||||
|
||||
bool RDAlsa::load(const QString &filename)
|
||||
{
|
||||
LoadSystemConfig();
|
||||
return LoadAsoundConfig(filename);
|
||||
}
|
||||
|
||||
|
||||
bool RDAlsa::save(const QString &filename)
|
||||
{
|
||||
return SaveAsoundConfig(filename);
|
||||
}
|
||||
|
||||
|
||||
void RDAlsa::clear()
|
||||
{
|
||||
card_ids.clear();
|
||||
card_drivers.clear();
|
||||
card_names.clear();
|
||||
card_long_names.clear();
|
||||
card_mixer_names.clear();
|
||||
card_pcm_names.clear();
|
||||
for(unsigned i=0;i<RD_MAX_CARDS;i++) {
|
||||
card_rivendell_cards[i]=-1;
|
||||
card_rivendell_devices[i]=-1;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void RDAlsa::LoadSystemConfig()
|
||||
{
|
||||
snd_ctl_t *snd_ctl=NULL;
|
||||
snd_ctl_card_info_t *card_info;
|
||||
snd_pcm_info_t *pcm_info;
|
||||
int card=0;
|
||||
int pcm=0;
|
||||
|
||||
snd_ctl_card_info_malloc(&card_info);
|
||||
snd_pcm_info_malloc(&pcm_info);
|
||||
while(snd_ctl_open(&snd_ctl,QString().sprintf("hw:%d",card),0)>=0) {
|
||||
snd_ctl_card_info(snd_ctl,card_info);
|
||||
card_ids.push_back(snd_ctl_card_info_get_id(card_info));
|
||||
card_drivers.push_back(snd_ctl_card_info_get_driver(card_info));
|
||||
card_names.push_back(snd_ctl_card_info_get_name(card_info));
|
||||
card_long_names.push_back(snd_ctl_card_info_get_longname(card_info));
|
||||
card_mixer_names.push_back(snd_ctl_card_info_get_mixername(card_info));
|
||||
std::vector<QString> pcms;
|
||||
if(snd_ctl_pcm_info(snd_ctl,pcm_info)==0) {
|
||||
pcm=0;
|
||||
while(pcm>=0) {
|
||||
pcms.push_back(QString().sprintf("%s [%u]",
|
||||
(const char *)snd_pcm_info_get_name(pcm_info),pcm+1));
|
||||
snd_ctl_pcm_next_device(snd_ctl,&pcm);
|
||||
}
|
||||
}
|
||||
card_pcm_names.push_back(pcms);
|
||||
snd_ctl_close(snd_ctl);
|
||||
card++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool RDAlsa::LoadAsoundConfig(const QString &filename)
|
||||
{
|
||||
FILE *f=NULL;
|
||||
char line[1024];
|
||||
int istate=0;
|
||||
int port=0;
|
||||
int card=0;
|
||||
int device=0;
|
||||
QStringList list;
|
||||
|
||||
if((f=fopen(filename,"r"))==NULL) {
|
||||
return false;
|
||||
}
|
||||
while(fgets(line,1024,f)!=NULL) {
|
||||
QString str=line;
|
||||
str.replace("\n","");
|
||||
if((str!=START_MARKER)&&(str!=END_MARKER)) {
|
||||
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 {
|
||||
card_other_lines.push_back(str+"\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
list=list.split(" ",str);
|
||||
if(list[0]=="}") {
|
||||
if((port>=0)&&(port<RD_MAX_CARDS)) {
|
||||
card_rivendell_cards[port]=card;
|
||||
card_rivendell_devices[port]=device;
|
||||
}
|
||||
card=0;
|
||||
device=0;
|
||||
istate=0;
|
||||
}
|
||||
else {
|
||||
if(list.size()==2) {
|
||||
if(list[0]=="card") {
|
||||
card=list[1].toInt();
|
||||
}
|
||||
if(list[0]=="device") {
|
||||
device=list[1].toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 10:
|
||||
if(str.left(1)=="}") {
|
||||
istate=0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RDAlsa::SaveAsoundConfig(const QString &filename)
|
||||
{
|
||||
FILE *f=NULL;
|
||||
|
||||
if((f=fopen(filename,"w"))==NULL) {
|
||||
return false;
|
||||
}
|
||||
for(unsigned i=0;i<card_other_lines.size();i++) {
|
||||
fprintf(f,card_other_lines[i]);
|
||||
}
|
||||
|
||||
fprintf(f,"%s\n",START_MARKER);
|
||||
for(int i=0;i<RD_MAX_CARDS;i++) {
|
||||
if((card_rivendell_cards[i]>=0)&&(card_rivendell_devices[i]>=0)) {
|
||||
fprintf(f,"pcm.rd%d {\n",i);
|
||||
fprintf(f," type hw\n");
|
||||
fprintf(f," card %d\n",card_rivendell_cards[i]);
|
||||
fprintf(f," device %d\n",card_rivendell_devices[i]);
|
||||
fprintf(f,"}\n");
|
||||
fprintf(f,"ctl.rd%d {\n",i);
|
||||
fprintf(f," type hw\n");
|
||||
fprintf(f," card %d\n",card_rivendell_cards[i]);
|
||||
fprintf(f,"}\n");
|
||||
}
|
||||
}
|
||||
fprintf(f,"%s\n",END_MARKER);
|
||||
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
71
utils/rdalsaconfig/rdalsa.h
Normal file
71
utils/rdalsaconfig/rdalsa.h
Normal file
@@ -0,0 +1,71 @@
|
||||
// rdalsa.h
|
||||
//
|
||||
// Abstract an ALSA configuration.
|
||||
//
|
||||
// (C) Copyright 2009 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// $Id: rdalsa.h,v 1.2 2010/07/29 19:32:39 cvs Exp $
|
||||
//
|
||||
// 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 RDALSA_H
|
||||
#define RDALSA_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <qstring.h>
|
||||
|
||||
#include <rd.h>
|
||||
|
||||
#define START_MARKER "# *** Start of Rivendell configuration generated by rdalsaconfig(1) ***"
|
||||
#define END_MARKER "# *** End of Rivendell configuration generated by rdalsaconfig(1) ***"
|
||||
|
||||
class RDAlsa
|
||||
{
|
||||
public:
|
||||
RDAlsa();
|
||||
unsigned cards() const;
|
||||
QString cardId(unsigned cardnum) const;
|
||||
QString cardDriver(unsigned cardnum) const;
|
||||
QString cardName(unsigned cardnum) const;
|
||||
QString cardLongName(unsigned cardnum) const;
|
||||
QString cardMixerName(unsigned cardnum) const;
|
||||
int pcmDevices(unsigned cardnum) const;
|
||||
QString pcmName(unsigned cardnum,unsigned pcm) const;
|
||||
int rivendellCard(int slot) const;
|
||||
void setRivendellCard(int slot,int cardnum);
|
||||
int rivendellDevice(int slot) const;
|
||||
void setRivendellDevice(int slot,int devnum);
|
||||
bool load(const QString &filename);
|
||||
bool save(const QString &filename);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
void LoadSystemConfig();
|
||||
bool LoadAsoundConfig(const QString &filename);
|
||||
bool SaveAsoundConfig(const QString &filename);
|
||||
std::vector<QString> card_ids;
|
||||
std::vector<QString> card_drivers;
|
||||
std::vector<QString> card_names;
|
||||
std::vector<QString> card_long_names;
|
||||
std::vector<QString> card_mixer_names;
|
||||
std::vector<std::vector<QString> > card_pcm_names;
|
||||
int card_rivendell_cards[RD_MAX_CARDS];
|
||||
int card_rivendell_devices[RD_MAX_CARDS];
|
||||
QStringList card_other_lines;
|
||||
};
|
||||
|
||||
|
||||
#endif // RDALSA_H
|
||||
388
utils/rdalsaconfig/rdalsaconfig.cpp
Normal file
388
utils/rdalsaconfig/rdalsaconfig.cpp
Normal file
@@ -0,0 +1,388 @@
|
||||
// rdalsaconfig.cpp
|
||||
//
|
||||
// A Qt-based application to display info about ALSA cards.
|
||||
//
|
||||
// (C) Copyright 2009 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// $Id: rdalsaconfig.cpp,v 1.2.8.3 2014/01/21 21:59:33 cvs Exp $
|
||||
//
|
||||
// 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 <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qwindowsstyle.h>
|
||||
#include <qmessagebox.h>
|
||||
|
||||
#include <rdcmd_switch.h>
|
||||
|
||||
#include <alsaitem.h>
|
||||
#include <rdalsaconfig.h>
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
QString alsa_filename;
|
||||
bool alsa_autogen=false;
|
||||
bool alsa_manage_daemons=false;
|
||||
bool alsa_daemon_start_needed=false;
|
||||
|
||||
void StopDaemons()
|
||||
{
|
||||
if(alsa_manage_daemons) {
|
||||
if(system("/etc/init.d/rivendell status")==0) {
|
||||
system("/etc/init.d/rivendell stop");
|
||||
alsa_daemon_start_needed=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void StartDaemons()
|
||||
{
|
||||
if(alsa_daemon_start_needed) {
|
||||
system("/etc/init.d/rivendell start");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MainWidget::MainWidget(QWidget *parent,const char *name)
|
||||
:QWidget(parent,name)
|
||||
{
|
||||
setCaption(tr("RDAlsaConfig")+" v"+VERSION);
|
||||
|
||||
//
|
||||
// Fix the Window Size
|
||||
//
|
||||
setMinimumWidth(sizeHint().width());
|
||||
setMinimumHeight(sizeHint().height());
|
||||
|
||||
//
|
||||
// Generate Fonts
|
||||
//
|
||||
QFont font("Helvetica",12,QFont::Normal);
|
||||
font.setPixelSize(12);
|
||||
QFont label_font("Helvetica",12,QFont::Bold);
|
||||
label_font.setPixelSize(12);
|
||||
|
||||
//
|
||||
// Available Devices
|
||||
//
|
||||
alsa_system_list=new QListBox(this);
|
||||
alsa_system_list->setFont(font);
|
||||
alsa_system_label=
|
||||
new QLabel(alsa_system_list,tr("Available Sound Devices"),this);
|
||||
alsa_system_label->setFont(label_font);
|
||||
alsa_system_label->setAlignment(AlignLeft|AlignVCenter);
|
||||
|
||||
//
|
||||
// Up Button
|
||||
//
|
||||
alsa_up_button=
|
||||
new RDTransportButton(RDTransportButton::Up,this,"alsa_up_button");
|
||||
connect(alsa_up_button,SIGNAL(clicked()),this,SLOT(upData()));
|
||||
|
||||
//
|
||||
// Down Button
|
||||
//
|
||||
alsa_down_button=
|
||||
new RDTransportButton(RDTransportButton::Down,this,"alsa_down_button");
|
||||
connect(alsa_down_button,SIGNAL(clicked()),this,SLOT(downData()));
|
||||
|
||||
//
|
||||
// Selected Devices
|
||||
//
|
||||
alsa_config_list=new QListBox(this);
|
||||
alsa_config_list->setFont(font);
|
||||
alsa_config_label=new QLabel(alsa_config_list,tr("Active Sound Devices"),this);
|
||||
alsa_config_label->setFont(label_font);
|
||||
alsa_config_label->setAlignment(AlignLeft|AlignVCenter);
|
||||
|
||||
//
|
||||
// Save Button
|
||||
//
|
||||
alsa_save_button=new QPushButton(tr("Save"),this);
|
||||
alsa_save_button->setFont(label_font);
|
||||
connect(alsa_save_button,SIGNAL(clicked()),this,SLOT(saveData()));
|
||||
|
||||
//
|
||||
// Cancel Button
|
||||
//
|
||||
alsa_cancel_button=new QPushButton(tr("Cancel"),this);
|
||||
alsa_cancel_button->setFont(label_font);
|
||||
connect(alsa_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
|
||||
|
||||
//
|
||||
// Load Available Devices and Configuration
|
||||
//
|
||||
alsa_alsa=new RDAlsa();
|
||||
alsa_alsa->load(alsa_filename);
|
||||
LoadList(alsa_system_list,alsa_config_list);
|
||||
|
||||
//
|
||||
// Daemon Management
|
||||
//
|
||||
if(alsa_manage_daemons) {
|
||||
if(geteuid()!=0) {
|
||||
QMessageBox::warning(this,tr("RDAlsaConfig error"),
|
||||
tr("The \"--manage-daemons\" switch requires root permissions."));
|
||||
exit(256);
|
||||
}
|
||||
if(system("/etc/init.d/rivendell status")==0) {
|
||||
int r=QMessageBox::warning(this,tr("RDAlsaConfig warning"),
|
||||
tr("Rivendell audio will be interrupted while running this program.\nContinue?"),
|
||||
QMessageBox::Yes,QMessageBox::No);
|
||||
if(r!=QMessageBox::Yes) {
|
||||
exit(256);
|
||||
}
|
||||
}
|
||||
}
|
||||
StopDaemons();
|
||||
}
|
||||
|
||||
|
||||
MainWidget::~MainWidget()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QSize MainWidget::sizeHint() const
|
||||
{
|
||||
return QSize(400,300);
|
||||
}
|
||||
|
||||
|
||||
QSizePolicy MainWidget::sizePolicy() const
|
||||
{
|
||||
return QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::upData()
|
||||
{
|
||||
MoveItem(alsa_config_list,alsa_system_list);
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::downData()
|
||||
{
|
||||
if(alsa_config_list->count()>=RD_MAX_CARDS) {
|
||||
return;
|
||||
}
|
||||
MoveItem(alsa_system_list,alsa_config_list);
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::saveData()
|
||||
{
|
||||
AlsaItem *item=NULL;
|
||||
|
||||
for(int i=0;i<RD_MAX_CARDS;i++) {
|
||||
if((item=(AlsaItem *)alsa_config_list->item(i))==NULL) {
|
||||
alsa_alsa->setRivendellCard(i,-1);
|
||||
alsa_alsa->setRivendellDevice(i,-1);
|
||||
}
|
||||
else {
|
||||
alsa_alsa->setRivendellCard(i,item->card());
|
||||
alsa_alsa->setRivendellDevice(i,item->device());
|
||||
}
|
||||
}
|
||||
if(!alsa_alsa->save(alsa_filename)) {
|
||||
QMessageBox::warning(this,tr("RDAlsaConfig error"),
|
||||
tr(QString("Unable to save configuration to \"")+
|
||||
alsa_filename+"\""));
|
||||
return;
|
||||
}
|
||||
StartDaemons();
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::cancelData()
|
||||
{
|
||||
StartDaemons();
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
alsa_system_label->setGeometry(20,5,size().width()-20,20);
|
||||
alsa_system_list->
|
||||
setGeometry(10,25,size().width()-20,(size().height()-120)/2);
|
||||
alsa_up_button->setGeometry(size().width()-120,size().height()/2-28,50,30);
|
||||
alsa_down_button->setGeometry(size().width()-60,size().height()/2-28,50,30);
|
||||
alsa_config_label->setGeometry(20,size().height()/2-10,size().width()/2,20);
|
||||
alsa_config_list->setGeometry(10,size().height()/2+10,
|
||||
size().width()-20,(size().height()-120)/2);
|
||||
alsa_save_button->
|
||||
setGeometry(size().width()-120,size().height()-40,50,30);
|
||||
alsa_cancel_button->
|
||||
setGeometry(size().width()-60,size().height()-40,50,30);
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::closeEvent(QCloseEvent *e)
|
||||
{
|
||||
int r=QMessageBox::question(this,tr("RDAlsaConfig quit"),
|
||||
tr("Save configuration before exiting?"),
|
||||
QMessageBox::Yes,QMessageBox::No,
|
||||
QMessageBox::Cancel);
|
||||
switch(r) {
|
||||
case QMessageBox::Yes:
|
||||
saveData();
|
||||
break;
|
||||
|
||||
case QMessageBox::No:
|
||||
cancelData();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::LoadList(QListBox *system,QListBox *config)
|
||||
{
|
||||
for(unsigned i=0;i<alsa_alsa->cards();i++) {
|
||||
for(int j=0;j<alsa_alsa->pcmDevices(i);j++) {
|
||||
if(PcmUnused(i,j)) {
|
||||
AlsaItem *item=
|
||||
new AlsaItem(alsa_alsa->cardLongName(i)+" - "+
|
||||
alsa_alsa->pcmName(i,j));
|
||||
item->setCard(i);
|
||||
item->setDevice(j);
|
||||
system->insertItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
system->sort();
|
||||
|
||||
for(int i=0;i<RD_MAX_CARDS;i++) {
|
||||
if(alsa_alsa->rivendellCard(i)>=0) {
|
||||
AlsaItem *item=
|
||||
new AlsaItem(alsa_alsa->cardLongName(alsa_alsa->rivendellCard(i))+" - "+
|
||||
alsa_alsa->pcmName(alsa_alsa->rivendellCard(i),
|
||||
alsa_alsa->rivendellDevice(i)));
|
||||
item->setCard(alsa_alsa->rivendellCard(i));
|
||||
item->setDevice(alsa_alsa->rivendellDevice(i));
|
||||
config->insertItem(item);
|
||||
}
|
||||
}
|
||||
config->sort();
|
||||
}
|
||||
|
||||
|
||||
bool MainWidget::PcmUnused(int card,int device)
|
||||
{
|
||||
for(int i=0;i<RD_MAX_CARDS;i++) {
|
||||
if((card==alsa_alsa->rivendellCard(i))&&
|
||||
(device==alsa_alsa->rivendellDevice(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::MoveItem(QListBox *src,QListBox *dest)
|
||||
{
|
||||
AlsaItem *item=(AlsaItem *)src->selectedItem();
|
||||
if(item==NULL) {
|
||||
return;
|
||||
}
|
||||
dest->insertItem(new AlsaItem(*item)); // Force a deep copy
|
||||
dest->sort();
|
||||
delete item;
|
||||
}
|
||||
|
||||
|
||||
Autogen::Autogen(QObject *parent,const char *name)
|
||||
{
|
||||
StopDaemons();
|
||||
|
||||
//
|
||||
// Load Available Devices
|
||||
//
|
||||
RDAlsa *alsa=new RDAlsa();
|
||||
alsa->load(alsa_filename);
|
||||
|
||||
//
|
||||
// Build Configuration
|
||||
//
|
||||
int slot=0;
|
||||
for(unsigned i=0;i<alsa->cards();i++) {
|
||||
for(int j=0;j<alsa->pcmDevices(i);j++) {
|
||||
alsa->setRivendellCard(slot,i);
|
||||
alsa->setRivendellDevice(slot,j);
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Save Configuration
|
||||
//
|
||||
if(!alsa->save(alsa_filename)) {
|
||||
exit(256);
|
||||
}
|
||||
|
||||
StartDaemons();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
//
|
||||
// Load the command-line arguments
|
||||
//
|
||||
alsa_filename=RD_ASOUNDRC_FILE;
|
||||
RDCmdSwitch *cmd=new RDCmdSwitch(argc,argv,"rdalsaconfig",
|
||||
RDALSACONFIG_USAGE);
|
||||
for(unsigned i=0;i<cmd->keys();i++) {
|
||||
if(cmd->key(i)=="--asoundrc-file") {
|
||||
alsa_filename=cmd->value(i);
|
||||
}
|
||||
if(cmd->key(i)=="--autogen") {
|
||||
alsa_autogen=true;
|
||||
}
|
||||
if(cmd->key(i)=="--manage-daemons") {
|
||||
alsa_manage_daemons=true;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Autogenerate a full configuration
|
||||
//
|
||||
if(alsa_autogen) {
|
||||
QApplication a(argc,argv,false);
|
||||
new Autogen(NULL,"main");
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
//
|
||||
// Start GUI
|
||||
//
|
||||
QApplication a(argc,argv);
|
||||
MainWidget *w=new MainWidget(NULL,"main");
|
||||
a.setMainWidget(w);
|
||||
w->setGeometry(QRect(QPoint(0,0),w->sizeHint()));
|
||||
w->show();
|
||||
return a.exec();
|
||||
}
|
||||
84
utils/rdalsaconfig/rdalsaconfig.h
Normal file
84
utils/rdalsaconfig/rdalsaconfig.h
Normal file
@@ -0,0 +1,84 @@
|
||||
// rdalsaconfig.h
|
||||
//
|
||||
// A Qt-based application to display info about ALSA cards.
|
||||
//
|
||||
// (C) Copyright 2009 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// $Id: rdalsaconfig.h,v 1.3 2010/09/08 20:38:01 cvs Exp $
|
||||
//
|
||||
// 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 RDALSACONFIG_H
|
||||
#define RDALSACONFIG_H
|
||||
|
||||
#include <qwidget.h>
|
||||
#include <qlistbox.h>
|
||||
#include <qlabel.h>
|
||||
|
||||
#include <rdtransportbutton.h>
|
||||
|
||||
#include <rd.h>
|
||||
#include <rdalsa.h>
|
||||
|
||||
#define RDALSACONFIG_USAGE "[--asoundrc-file=<filename>] [--autogen] [--manage-daemons]\n\nGenerate an ALSA sound card configuration for Rivendell.\n\nThe following options are available:\n\n --asoundrc-file=<filename>\n Read and write configuration from <filename> (default value \n \"/etc/asound.conf\").\n\n --autogen\n Generate and save a configuration containing all available PCM devices\n and then exit.\n\n --manage-daemons\n Restart the Rivendell daemons as necessary to make configuration\n changes active (requires root permission).\n\n"
|
||||
|
||||
void StopDaemons();
|
||||
void StartDaemons();
|
||||
|
||||
class MainWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWidget(QWidget *parent=0,const char *name=0);
|
||||
~MainWidget();
|
||||
QSize sizeHint() const;
|
||||
QSizePolicy sizePolicy() const;
|
||||
|
||||
private slots:
|
||||
void upData();
|
||||
void downData();
|
||||
void saveData();
|
||||
void cancelData();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void closeEvent(QCloseEvent *e);
|
||||
|
||||
private:
|
||||
void LoadList(QListBox *system,QListBox *config);
|
||||
bool PcmUnused(int card,int device);
|
||||
void MoveItem(QListBox *src,QListBox *dest);
|
||||
QLabel *alsa_system_label;
|
||||
QListBox *alsa_system_list;
|
||||
QLabel *alsa_config_label;
|
||||
QListBox *alsa_config_list;
|
||||
RDTransportButton *alsa_up_button;
|
||||
RDTransportButton *alsa_down_button;
|
||||
QPushButton *alsa_save_button;
|
||||
QPushButton *alsa_cancel_button;
|
||||
RDAlsa *alsa_alsa;
|
||||
};
|
||||
|
||||
|
||||
class Autogen : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Autogen(QObject *parent=0,const char *name=0);
|
||||
};
|
||||
|
||||
|
||||
#endif // RDALSACONFIG_H
|
||||
0
utils/rdalsaconfig/rdalsaconfig.pro
Normal file
0
utils/rdalsaconfig/rdalsaconfig.pro
Normal file
Reference in New Issue
Block a user