mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2026-01-12 15:45:59 +01:00
2018-02-04 Fred Gleason <fredg@paravelsystems.com>
* Refactored the RDAudioExport class to use RDApplication.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Test the Rivendell file format exporter.
|
||||
//
|
||||
// (C) Copyright 2010,2016 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2010,2016-2018 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
|
||||
@@ -18,14 +18,15 @@
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <qapplication.h>
|
||||
|
||||
#include <rdapplication.h>
|
||||
#include <rddb.h>
|
||||
#include <rdcmd_switch.h>
|
||||
#include <rdaudioexport.h>
|
||||
#include <rdstation.h>
|
||||
|
||||
#include <audio_export_test.h>
|
||||
#include "audio_export_test.h"
|
||||
|
||||
MainObject::MainObject(QObject *parent)
|
||||
:QObject(parent)
|
||||
@@ -40,61 +41,67 @@ MainObject::MainObject(QObject *parent)
|
||||
bool ok=false;
|
||||
RDAudioConvert::ErrorCode audio_conv_err;
|
||||
RDAudioExport::ErrorCode conv_err;
|
||||
unsigned schema=0;
|
||||
QString err_msg;
|
||||
|
||||
//
|
||||
// Open the Database
|
||||
//
|
||||
rda=new RDApplication("audio_export_test","audio_export_test",AUDIO_EXPORT_TEST_USAGE,this);
|
||||
if(!rda->open(&err_msg)) {
|
||||
fprintf(stderr,"audio_export_test: %s\n",(const char *)err_msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//
|
||||
// Read Command Options
|
||||
//
|
||||
RDCmdSwitch *cmd=
|
||||
new RDCmdSwitch(qApp->argc(),qApp->argv(),"audio_export_test",
|
||||
AUDIO_EXPORT_TEST_USAGE);
|
||||
for(unsigned i=0;i<cmd->keys();i++) {
|
||||
if(cmd->key(i)=="--username") {
|
||||
username=cmd->value(i);
|
||||
cmd->setProcessed(i,true);
|
||||
for(unsigned i=0;i<rda->cmdSwitch()->keys();i++) {
|
||||
if(rda->cmdSwitch()->key(i)=="--username") {
|
||||
username=rda->cmdSwitch()->value(i);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--password") {
|
||||
password=cmd->value(i);
|
||||
cmd->setProcessed(i,true);
|
||||
if(rda->cmdSwitch()->key(i)=="--password") {
|
||||
password=rda->cmdSwitch()->value(i);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--cart-number") {
|
||||
cart_number=cmd->value(i).toUInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--cart-number") {
|
||||
cart_number=rda->cmdSwitch()->value(i).toUInt(&ok);
|
||||
if((!ok)||(cart_number>999999)) {
|
||||
fprintf(stderr,"audio_export_test: invalid cart number\n");
|
||||
exit(256);
|
||||
}
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--cut-number") {
|
||||
cut_number=cmd->value(i).toUInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--cut-number") {
|
||||
cut_number=rda->cmdSwitch()->value(i).toUInt(&ok);
|
||||
if((!ok)||(cut_number>999)) {
|
||||
fprintf(stderr,"audio_export_test: invalid cut number\n");
|
||||
exit(256);
|
||||
}
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--destination-file") {
|
||||
destination_filename=cmd->value(i);
|
||||
cmd->setProcessed(i,true);
|
||||
if(rda->cmdSwitch()->key(i)=="--destination-file") {
|
||||
destination_filename=rda->cmdSwitch()->value(i);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--start-point") {
|
||||
start_point=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--start-point") {
|
||||
start_point=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid start point\n");
|
||||
exit(256);
|
||||
}
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--end-point") {
|
||||
end_point=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--end-point") {
|
||||
end_point=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid end point\n");
|
||||
exit(256);
|
||||
}
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--destination-format") {
|
||||
RDSettings::Format format=(RDSettings::Format)cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--destination-format") {
|
||||
RDSettings::Format format=(RDSettings::Format)rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid destination format\n");
|
||||
exit(256);
|
||||
@@ -107,7 +114,7 @@ MainObject::MainObject(QObject *parent)
|
||||
case RDSettings::Flac:
|
||||
case RDSettings::OggVorbis:
|
||||
destination_settings->setFormat(format);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -116,52 +123,61 @@ MainObject::MainObject(QObject *parent)
|
||||
}
|
||||
destination_settings->setFormat(format);
|
||||
}
|
||||
if(cmd->key(i)=="--destination-channels") {
|
||||
unsigned channels=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--destination-channels") {
|
||||
unsigned channels=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid destination channels\n");
|
||||
exit(256);
|
||||
}
|
||||
destination_settings->setChannels(channels);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--destination-sample-rate") {
|
||||
unsigned sample_rate=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--destination-sample-rate") {
|
||||
unsigned sample_rate=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid destination sample rate\n");
|
||||
exit(256);
|
||||
}
|
||||
destination_settings->setSampleRate(sample_rate);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--destination-bit-rate") {
|
||||
unsigned bit_rate=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--destination-bit-rate") {
|
||||
unsigned bit_rate=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid destination bit rate\n");
|
||||
exit(256);
|
||||
}
|
||||
destination_settings->setBitRate(bit_rate);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--quality") {
|
||||
unsigned quality=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--quality") {
|
||||
unsigned quality=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid destination quality\n");
|
||||
exit(256);
|
||||
}
|
||||
destination_settings->setQuality(quality);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--normalization-level") {
|
||||
int normalization_level=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--normalization-level") {
|
||||
int normalization_level=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if((!ok)||(normalization_level>0)) {
|
||||
fprintf(stderr,"audio_export_test: invalid normalization level\n");
|
||||
exit(256);
|
||||
}
|
||||
destination_settings->setNormalizationLevel(normalization_level);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(!rda->cmdSwitch()->processed(i)) {
|
||||
fprintf(stderr,"audio_export_test: unknown command option \"%s\"\n",
|
||||
(const char *)rda->cmdSwitch()->key(i));
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Sanity Checks
|
||||
//
|
||||
if(cart_number==0) {
|
||||
fprintf(stderr,"audio_export_test: missing cart-number\n");
|
||||
exit(256);
|
||||
@@ -180,26 +196,7 @@ MainObject::MainObject(QObject *parent)
|
||||
exit(256);
|
||||
}
|
||||
|
||||
//
|
||||
// Read Configuration
|
||||
//
|
||||
rdconfig=new RDConfig();
|
||||
rdconfig->load();
|
||||
rdconfig->setModuleName("audio_export_test");
|
||||
|
||||
//
|
||||
// Open Database
|
||||
//
|
||||
QString err (tr("audio_export_test: "));
|
||||
QSqlDatabase *db=RDInitDb(&schema,&err);
|
||||
if(!db) {
|
||||
fprintf(stderr,err.ascii());
|
||||
delete cmd;
|
||||
exit(256);
|
||||
}
|
||||
|
||||
RDStation *station=new RDStation(rdconfig->stationName());
|
||||
RDAudioExport *conv=new RDAudioExport(station,rdconfig,this);
|
||||
RDAudioExport *conv=new RDAudioExport(this);
|
||||
conv->setCartNumber(cart_number);
|
||||
conv->setCutNumber(cut_number);
|
||||
conv->setDestinationFile(destination_filename);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Test the Rivendell file format converter.
|
||||
//
|
||||
// (C) Copyright 2010,2016 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2010,2016-2018 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
|
||||
@@ -24,20 +24,11 @@
|
||||
#include <list>
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qsqldatabase.h>
|
||||
|
||||
#include <rdconfig.h>
|
||||
#include <rdsettings.h>
|
||||
#include <rdcmd_switch.cpp>
|
||||
|
||||
#define AUDIO_EXPORT_TEST_USAGE "[options]\n\nTest the Rivendell audio exporter routines\n\nOptions are:\n--username=<username>\n\n--password=<password>\n\n--cart-number=<cartnum>\n\n--cut-number=<cutnum>\n\n--destination-file=<filename>\n\n--start-point=<msecs>\n\n--end-point=<msecs>\n\n--destination-format=<fmt>\n Supported formats are:\n 0 - PCM16 WAV\n 2 - MPEG Layer 2\n 3 - MPEG Layer 3\n 4 - FLAC\n 5 - OggVorbis\n 6 - MPEG Layer 2 WAV\n\n--destination-channels=<chans>\n\n--destination-sample-rate=<rate>\n\n--destination-bit-rate=<rate>\n\n--destination-quality=<qual>\n\n--normalization-level=<dbfs>\n\n"
|
||||
|
||||
//
|
||||
// Global Variables
|
||||
//
|
||||
RDConfig *rdconfig;
|
||||
|
||||
|
||||
class MainObject : public QObject
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user