2018-02-04 Fred Gleason <fredg@paravelsystems.com>

* Refactored the RDAudioImport class to use RDApplication.
This commit is contained in:
Fred Gleason
2018-02-04 07:11:12 -05:00
parent 69817c1941
commit 957772c5e6
13 changed files with 73 additions and 84 deletions

View File

@@ -2,7 +2,7 @@
//
// Test Rivendell file importing.
//
// (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,13 +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 <rdaudioimport.h>
#include <audio_import_test.h>
#include "audio_import_test.h"
MainObject::MainObject(QObject *parent)
:QObject(parent)
@@ -38,75 +40,91 @@ MainObject::MainObject(QObject *parent)
bool ok=false;
RDAudioConvert::ErrorCode audio_conv_err;
RDAudioImport::ErrorCode conv_err;
unsigned schema=0;
QString err_msg;
//
// Open the Database
//
rda=new RDApplication("audio_import_test","audio_import_test",
AUDIO_IMPORT_TEST_USAGE,this);
if(!rda->open(&err_msg)) {
fprintf(stderr,"audio_import_test: %s\n",(const char *)err_msg);
exit(1);
}
//
// Read Command Options
//
RDCmdSwitch *cmd=
new RDCmdSwitch(qApp->argc(),qApp->argv(),"audio_import_test",
AUDIO_IMPORT_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_import_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_import_test: invalid cut number\n");
exit(256);
}
cmd->setProcessed(i,true);
rda->cmdSwitch()->setProcessed(i,true);
}
if(cmd->key(i)=="--source-file") {
source_filename=cmd->value(i);
cmd->setProcessed(i,true);
if(rda->cmdSwitch()->key(i)=="--source-file") {
source_filename=rda->cmdSwitch()->value(i);
rda->cmdSwitch()->setProcessed(i,true);
}
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_import_test: invalid destination channels\n");
exit(256);
}
destination_settings->setChannels(channels);
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_import_test: invalid normalization level\n");
exit(256);
}
destination_settings->setNormalizationLevel(normalization_level);
cmd->setProcessed(i,true);
rda->cmdSwitch()->setProcessed(i,true);
}
if(cmd->key(i)=="--autotrim-level") {
int autotrim_level=cmd->value(i).toInt(&ok);
if(rda->cmdSwitch()->key(i)=="--autotrim-level") {
int autotrim_level=rda->cmdSwitch()->value(i).toInt(&ok);
if((!ok)||(autotrim_level>0)) {
fprintf(stderr,"audio_import_test: invalid autotrim level\n");
exit(256);
}
destination_settings->setAutotrimLevel(autotrim_level);
cmd->setProcessed(i,true);
rda->cmdSwitch()->setProcessed(i,true);
}
if(cmd->key(i)=="--use-metadata") {
if(rda->cmdSwitch()->key(i)=="--use-metadata") {
use_metadata=true;
cmd->setProcessed(i,true);
rda->cmdSwitch()->setProcessed(i,true);
}
if(!rda->cmdSwitch()->processed(i)) {
fprintf(stderr,"audio_import_test: unknown command option \"%s\"\n",
(const char *)rda->cmdSwitch()->key(i));
exit(2);
}
}
//
// Sanity Checks
//
if(cart_number==0) {
fprintf(stderr,"audio_import_test: missing cart-number\n");
exit(256);
@@ -121,25 +139,9 @@ MainObject::MainObject(QObject *parent)
}
//
// Read Configuration
// Run Test
//
rdconfig=new RDConfig();
rdconfig->load();
rdconfig->setModuleName("audio_import_test");
//
// Open Database
//
QString err (tr("audio_import_test: "));
QSqlDatabase *db=RDInitDb(&schema,&err);
if(!db) {
fprintf(stderr,err.ascii());
delete cmd;
exit(256);
}
RDStation *station=new RDStation(rdconfig->stationName());
RDAudioImport *conv=new RDAudioImport(station,rdconfig,this);
RDAudioImport *conv=new RDAudioImport(this);
conv->setCartNumber(cart_number);
conv->setCutNumber(cut_number);
conv->setSourceFile(source_filename);

View File

@@ -2,7 +2,7 @@
//
// Test Rivendell file importing
//
// (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_IMPORT_TEST_USAGE "[options]\n\nTest the Rivendell audio importer routines\n\nOptions are:\n--username=<username>\n\n--password=<password>\n\n--cart-number=<cartnum>\n\n--cut-number=<cutnum>\n\n--source-file=<filename>\n\n--destination-channels=<chans>\n\n--normalization-level=<dbfs>\n\n--autotrim-level=<dbfs>\n\n--use-metadata\n\n"
//
// Global Variables
//
RDConfig *rdconfig;
class MainObject : public QObject
{
public: