spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 68989c8b6fd6ccda53ccd14766de5dee78663ead
parent 0b121ec1c5ce99535d35a6a54c9252bd9f552a7d
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Sun, 19 Aug 2012 13:09:09 -0700

Fix return status code

Diffstat:
Msrc/spek-spectrogram.cc | 1+
Msrc/spek.cc | 60++++++++++++++++++++++++++++++++----------------------------
2 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/src/spek-spectrogram.cc b/src/spek-spectrogram.cc @@ -123,6 +123,7 @@ void SpekSpectrogram::on_have_sample(SpekHaveSampleEvent& event) int sample = event.get_sample(); const float *values = event.get_values(); + // TODO: check image size, quit if wrong. for (int y = 0; y < bands; y++) { double level = log10(1.0 - THRESHOLD + values[y]) / log10_threshold; if (level > 1.0) level = 1.0; diff --git a/src/spek.cc b/src/spek.cc @@ -27,13 +27,16 @@ class Spek: public wxApp { +public: + Spek() : wxApp(), quit(false) {} + protected: virtual bool OnInit(); - virtual void OnInitCmdLine(wxCmdLineParser& parser); - virtual bool OnCmdLineParsed(wxCmdLineParser& parser); + virtual int OnRun(); private: wxString path; + bool quit; }; IMPLEMENT_APP(Spek) @@ -46,19 +49,7 @@ bool Spek::OnInit() SpekPreferences::get().init(); spek_audio_init(); - if (!wxApp::OnInit()) { - return false; - } - - SpekWindow *window = new SpekWindow(this->path); - window->Show(true); - SetTopWindow(window); - return true; -} - -void Spek::OnInitCmdLine(wxCmdLineParser& parser) -{ - wxCmdLineEntryDesc desc[] = {{ + static const wxCmdLineEntryDesc desc[] = {{ wxCMD_LINE_SWITCH, wxT_2("h"), wxT_2("help"), @@ -77,27 +68,40 @@ void Spek::OnInitCmdLine(wxCmdLineParser& parser) wxT_2("FILE"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL - }, { - wxCMD_LINE_NONE - } + }, + wxCMD_LINE_DESC_END }; - parser.SetDesc(desc); -} - -bool Spek::OnCmdLineParsed(wxCmdLineParser& parser) -{ - if (!wxApp::OnCmdLineParsed(parser)) { + wxCmdLineParser parser(desc, argc, argv); + int ret = parser.Parse(true); + if (ret == 1) { return false; } - + if (ret == -1) { + this->quit = true; + return true; + } if (parser.Found(wxT("version"))) { // TRANSLATORS: first %s is the package name, second %s is the package version. wxPrintf(_("%s version %s\n"), wxT(PACKAGE_NAME), wxT(PACKAGE_VERSION)); - return false; + this->quit = true; + return true; + } + if (parser.GetParamCount()) { + this->path = parser.GetParam(); } - this->path = parser.GetParam(); - + SpekWindow *window = new SpekWindow(this->path); + window->Show(true); + SetTopWindow(window); return true; } + +int Spek::OnRun() +{ + if (quit) { + return 0; + } + + return wxApp::OnRun(); +}