mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-24 17:17:07 +01:00
Merge remote-tracking branch 'sec/commandline'
This commit is contained in:
35
main.cpp
35
main.cpp
@@ -1,4 +1,5 @@
|
||||
#include <QApplication>
|
||||
#include <QCommandLineParser>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
@@ -7,9 +8,35 @@ int main(int argc, char *argv[])
|
||||
QApplication a(argc, argv);
|
||||
a.setApplicationName("inspectrum");
|
||||
MainWindow mainWin;
|
||||
mainWin.show();
|
||||
if (argc > 1) {
|
||||
mainWin.openFile(QString::fromLatin1(argv[1]));
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("spectrum viewer");
|
||||
parser.addHelpOption();
|
||||
parser.addPositionalArgument("file", QCoreApplication::translate("main", "File to view."));
|
||||
|
||||
// Add options
|
||||
QCommandLineOption rateOption(QStringList() << "r" << "rate",
|
||||
QCoreApplication::translate("main", "Set sample rate."),
|
||||
QCoreApplication::translate("main", "Hz"));
|
||||
parser.addOption(rateOption);
|
||||
|
||||
// Process the actual command line
|
||||
parser.process(a);
|
||||
|
||||
if (parser.isSet(rateOption)){
|
||||
bool ok;
|
||||
int rate = parser.value(rateOption).toInt(&ok);
|
||||
if(!ok){
|
||||
fputs("ERROR: could not parse rate\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
mainWin.changeSampleRate(rate);
|
||||
}
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
if (args.size()>=1)
|
||||
mainWin.openFile(args.at(0));
|
||||
|
||||
mainWin.show();
|
||||
return a.exec();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,12 @@ void MainWindow::setSampleRate(QString rate)
|
||||
spectrogram.setSampleRate(rate.toInt());
|
||||
}
|
||||
|
||||
void MainWindow::changeSampleRate(int rate)
|
||||
{
|
||||
spectrogram.setSampleRate(rate);
|
||||
dock->sampleRate->setText(QString::number(rate));
|
||||
}
|
||||
|
||||
void MainWindow::setFFTSize(int size)
|
||||
{
|
||||
off_t sample = getCenterSample();
|
||||
|
||||
@@ -12,6 +12,7 @@ class MainWindow : public QMainWindow
|
||||
public:
|
||||
MainWindow();
|
||||
void openFile(QString fileName);
|
||||
void changeSampleRate(int rate);
|
||||
|
||||
public slots:
|
||||
void setSampleRate(QString rate);
|
||||
|
||||
Reference in New Issue
Block a user