Skip to content

Commit

Permalink
Add commandline options for padding, and data output. (#717)
Browse files Browse the repository at this point in the history
* Remove ellipsis from "Reload TBC" option

Ellipses mean there's a dialogue box, and in this case there isn't.

* Add commandline option --pad. Add param on commandline to specify data output.

These work in non-interactive mode, too.

* Refactor main window error dialogues into common method

This also means that error messages and warnings can be printed
but not displayed in a dialogue if nonInteractive==true.
  • Loading branch information
marnanel authored May 17, 2022
1 parent c9a9a6f commit f9b6be1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 20 deletions.
18 changes: 16 additions & 2 deletions tools/ld-process-efm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ int main(int argc, char *argv[])
QCoreApplication::translate("main", "Run in non-interactive mode"));
parser.addOption(nonInteractiveOption);

QCommandLineOption padOption(QStringList() << "p" << "pad",
QCoreApplication::translate("main", "Pad audio to initial disc time"));
parser.addOption(padOption);

// -- Positional arguments --

// Positional argument to specify input EFM file
Expand All @@ -69,6 +73,9 @@ int main(int argc, char *argv[])
// Positional argument to specify output audio file
parser.addPositionalArgument("output", QCoreApplication::translate("main", "Specify output audio file"));

// Positional argument to specify output data file
parser.addPositionalArgument("data", QCoreApplication::translate("main", "Specify output data file"));

// Process the command line options and arguments given by the user
parser.process(a);

Expand All @@ -77,12 +84,18 @@ int main(int argc, char *argv[])

// Get the options from the parser
bool isNonInteractiveOn = parser.isSet(nonInteractiveOption);
bool pad = parser.isSet(padOption);

// Get the arguments from the parser
QString inputEfmFilename;
QString outputAudioFilename;
QString outputDataFilename;
QStringList positionalArguments = parser.positionalArguments();
if (positionalArguments.count() == 2) {
if (positionalArguments.count() == 3) {
inputEfmFilename = positionalArguments.at(0);
outputAudioFilename = positionalArguments.at(1);
outputDataFilename = positionalArguments.at(2);
} else if (positionalArguments.count() == 2) {
inputEfmFilename = positionalArguments.at(0);
outputAudioFilename = positionalArguments.at(1);
} else if (positionalArguments.count() == 1) {
Expand All @@ -97,7 +110,8 @@ int main(int argc, char *argv[])
}

// Start the GUI application
MainWindow w(getDebugState(), isNonInteractiveOn, outputAudioFilename);
MainWindow w(getDebugState(), isNonInteractiveOn, outputAudioFilename,
outputDataFilename, pad);
if (!inputEfmFilename.isEmpty()) {
// Load the file to decode
if (!w.loadInputEfmFile(inputEfmFilename)) {
Expand Down
67 changes: 50 additions & 17 deletions tools/ld-process-efm/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(bool debugOn, bool _nonInteractive, QString _outputAudioFilename, QWidget *parent) :
MainWindow::MainWindow(bool debugOn, bool _nonInteractive, QString _outputAudioFilename,
QString _outputDataFilename, bool _pad, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
nonInteractive = _nonInteractive;
outputAudioFilename = _outputAudioFilename;
outputDataFilename = _outputDataFilename;
pad = _pad;

// Initialise the GUI
ui->setupUi(this);
Expand Down Expand Up @@ -64,6 +67,13 @@ MainWindow::MainWindow(bool debugOn, bool _nonInteractive, QString _outputAudioF
ui->debug_f1ToData_checkBox->setEnabled(true);
}

ui->audio_padSampleStart_checkBox->setChecked(pad);

if (outputDataFilename!=NULL) {
ui->options_decodeAsData_checkbox->setChecked(true);
ui->tabWidget->setTabEnabled(ui->tabWidget->indexOf(ui->dataTab), true);
}

// Select the Audio tab by default
ui->tabWidget->setCurrentWidget(ui->audioTab);

Expand Down Expand Up @@ -457,9 +467,8 @@ void MainWindow::on_actionSave_PCM_Audio_triggered()
if (!audioOutputTemporaryFileHandle.copy(audioFilename)) {
qDebug() << "MainWindow::on_actionSave_PCM_Audio_triggered(): Failed to save file as" << audioFilename;

QMessageBox messageBox;
messageBox.warning(this, "Warning", "Could not save PCM audio using the specified filename!");
messageBox.setFixedSize(500, 200);
this->showError("Could not save PCM audio using the specified filename!",
false);
}

// Update the configuration for the PNG directory
Expand Down Expand Up @@ -499,9 +508,8 @@ void MainWindow::on_actionSave_Sector_Data_triggered()
if (!dataOutputTemporaryFileHandle.copy(dataFilename)) {
qDebug() << "MainWindow::on_actionSave_Sector_Data_triggered(): Failed to save file as" << dataFilename;

QMessageBox messageBox;
messageBox.warning(this, "Warning", "Could not save sector data using the specified filename!");
messageBox.setFixedSize(500, 200);
this->showError("Could not save sector data using the specified filename!",
false);
}

// Update the configuration for the PNG directory
Expand Down Expand Up @@ -668,6 +676,19 @@ void MainWindow::processingCompleteSignalHandler(bool audioAvailable, bool dataA
if (dataAvailable) {
qDebug() << "MainWindow::processingCompleteSignalHandler(): Processing complete - data available";
ui->actionSave_Sector_Data->setEnabled(true);
// If in non-Interactive mode, autosave
if (nonInteractive) {
// Save the data
qInfo() << "Saving data as" << outputDataFilename;

// Check if filename exists (and remove the file if it does)
if (QFile::exists(outputDataFilename)) QFile::remove(outputDataFilename);

// Copy the data data from the temporary file to the destination
if (!dataOutputTemporaryFileHandle.copy(outputDataFilename)) {
qWarning() << "MainWindow::processingCompleteSignalHandler(): Failed to save file as" << outputDataFilename;
}
}
}

// Report the decode statistics to qInfo
Expand All @@ -692,6 +713,26 @@ void MainWindow::percentProcessedSignalHandler(qint32 percent)

// Miscellaneous methods ----------------------------------------------------------------------------------------------

// Show an error to the user
void MainWindow::showError(QString message, bool is_critical)
{
if (!nonInteractive) {
QMessageBox messageBox;
if (is_critical) {
messageBox.critical(this, "Error", message);
} else {
messageBox.warning(this, "Warning", message);
}
messageBox.setFixedSize(500, 200);
}

if (is_critical) {
qCritical() << message;
} else {
qWarning() << message;
}
}

// Load an EFM file
bool MainWindow::loadInputEfmFile(QString filename)
{
Expand All @@ -700,23 +741,15 @@ bool MainWindow::loadInputEfmFile(QString filename)
// Open input file for reading
QFile inputFileHandle((filename));
if (!inputFileHandle.open(QIODevice::ReadOnly)) {
// Show an error to the user
QMessageBox messageBox;
messageBox.critical(this, "Error", "Could not open the EFM input file!");
messageBox.setFixedSize(500, 200);
qWarning() << "Could not load input EFM file!";
this->showError("Could not open the EFM input file!", true);

guiNoEfmFileLoaded();
inputFileHandle.close();
return false;
}

if (inputFileHandle.bytesAvailable() == 0) {
// Show an error to the user
QMessageBox messageBox;
messageBox.critical(this, "Error", "Input EFM file is empty!");
messageBox.setFixedSize(500, 200);
qWarning() << "EFM input file is empty!";
this->showError("Input EFM file is empty!", true);

guiNoEfmFileLoaded();
inputFileHandle.close();
Expand Down
9 changes: 8 additions & 1 deletion tools/ld-process-efm/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class MainWindow : public QMainWindow
Q_OBJECT

public:
explicit MainWindow(bool debugOn, bool _nonInteractive, QString _outputAudioFilename, QWidget *parent = nullptr);
explicit MainWindow(bool debugOn, bool _nonInteractive,
QString _outputAudioFilename, QString _outputDataFilename,
bool pad,
QWidget *parent = nullptr);
~MainWindow();

bool loadInputEfmFile(QString filename);
Expand All @@ -73,6 +76,8 @@ private slots:
void on_actionSave_Sector_Data_triggered();

private:
void showError(QString message, bool is_critical);

Ui::MainWindow *ui;

// Dialogues
Expand All @@ -89,6 +94,8 @@ private slots:
QTimer statisticsUpdateTimer;
bool nonInteractive;
QString outputAudioFilename;
QString outputDataFilename;
bool pad;

// Method prototypes
void guiNoEfmFileLoaded();
Expand Down

0 comments on commit f9b6be1

Please sign in to comment.