From bc4f29f1ee59d17a480a6d18bf010eb61c212e77 Mon Sep 17 00:00:00 2001 From: louisjb Date: Fri, 9 Jul 2010 13:04:48 +0000 Subject: [PATCH] added --log --midi-input-dump formark. git-svn-id: https://svn.code.sf.net/p/pianobooster/code/trunk@141 ba081f5d-443b-49a7-ac4b-446c3f91f371 --- PianoBooster/src/Cfg.cpp | 2 + PianoBooster/src/Cfg.h | 2 + PianoBooster/src/MidiDeviceBase.h | 4 +- PianoBooster/src/MidiDeviceRt.cpp | 9 ++++ PianoBooster/src/MidiTrack.cpp | 2 +- PianoBooster/src/QtWindow.cpp | 8 +++ PianoBooster/src/Util.cpp | 87 ++++++++++++++++++++++--------- 7 files changed, 86 insertions(+), 28 deletions(-) diff --git a/PianoBooster/src/Cfg.cpp b/PianoBooster/src/Cfg.cpp index 269f058..622a566 100644 --- a/PianoBooster/src/Cfg.cpp +++ b/PianoBooster/src/Cfg.cpp @@ -40,6 +40,8 @@ int Cfg::m_appWidth; int Cfg::m_appHeight; bool Cfg::experimentalTempo = false; bool Cfg::experimentalNoteLength = false; +bool Cfg::useLogFile = false; +bool Cfg::midiInputDump = false; int Cfg::experimentalSwapInterval = -1; diff --git a/PianoBooster/src/Cfg.h b/PianoBooster/src/Cfg.h index c16c4d4..6efdc78 100644 --- a/PianoBooster/src/Cfg.h +++ b/PianoBooster/src/Cfg.h @@ -132,6 +132,8 @@ public: static bool experimentalTempo; static bool experimentalNoteLength; static int experimentalSwapInterval; + static bool useLogFile; + static bool midiInputDump; private: static float m_staveEndX; diff --git a/PianoBooster/src/MidiDeviceBase.h b/PianoBooster/src/MidiDeviceBase.h index 052d80b..5617f73 100755 --- a/PianoBooster/src/MidiDeviceBase.h +++ b/PianoBooster/src/MidiDeviceBase.h @@ -31,6 +31,8 @@ #include #include "Util.h" +#include "Cfg.h" + /*! * @brief xxxxx. */ @@ -52,7 +54,7 @@ public: virtual bool openMidiPort(midiType_t type, QString portName) = 0; virtual void closeMidiPort(midiType_t type, int index) = 0; - + // based on the fluid synth settings virtual int midiSettingsSetStr(QString name, QString str) = 0; virtual int midiSettingsSetNum(QString name, double val) = 0; diff --git a/PianoBooster/src/MidiDeviceRt.cpp b/PianoBooster/src/MidiDeviceRt.cpp index 2698369..0ddad02 100755 --- a/PianoBooster/src/MidiDeviceRt.cpp +++ b/PianoBooster/src/MidiDeviceRt.cpp @@ -212,6 +212,15 @@ CMidiEvent CMidiDeviceRt::readMidiInput() unsigned int channel; + if (Cfg::midiInputDump) + { + QString str; + + for (unsigned int i = 0; i < m_inputMessage.size(); i++) + str += " 0x" + QString::number(m_inputMessage[i], 16) + ','; + ppLogInfo("midi input %s", qPrintable(str)); + } + channel = m_inputMessage[0] & 0x0f; switch (m_inputMessage[0] & 0xf0 ) { diff --git a/PianoBooster/src/MidiTrack.cpp b/PianoBooster/src/MidiTrack.cpp index f50526e..6908909 100644 --- a/PianoBooster/src/MidiTrack.cpp +++ b/PianoBooster/src/MidiTrack.cpp @@ -400,7 +400,7 @@ void CMidiTrack::noteOffEvent(CMidiEvent &event, int deltaTime, int channel, int m_noteOnEventPtr[channel][pitch] = 0; int duration = m_currentTime - noteOnEventPtr->getDuration(); - ppLogDebug ("NOTE OFF chan %d pitch %d currentTime %d Duration %d", channel + 1, pitch, m_currentTime, duration); + //ppLogDebug ("NOTE OFF chan %d pitch %d currentTime %d Duration %d", channel + 1, pitch, m_currentTime, duration); noteOnEventPtr->setDuration(duration); diff --git a/PianoBooster/src/QtWindow.cpp b/PianoBooster/src/QtWindow.cpp index 9c14ffa..5ffa366 100644 --- a/PianoBooster/src/QtWindow.cpp +++ b/PianoBooster/src/QtWindow.cpp @@ -176,6 +176,9 @@ void QtWindow::displayUsage() fprintf(stderr, " -L: Displays the note length (experimental)\n"); fprintf(stderr, " -h: --help: Displays this help message\n"); fprintf(stderr, " -v: Displays version number and then exits\n"); + fprintf(stderr, " --log: write debug info to the \"pb.log\" log file\n"); + fprintf(stderr, " --midi-input-dump: Displays the midi input in hex\n"); + } int QtWindow::decodeIntegerParam(QString arg, int defaultParam) @@ -252,6 +255,11 @@ void QtWindow::decodeCommandLine() Cfg::quickStart = true; else if (arg.startsWith("-L")) Cfg::experimentalNoteLength = true; + else if (arg.startsWith("--log")) + Cfg::useLogFile = true; + else if (arg.startsWith("--midi-input-dump")) + Cfg::midiInputDump = true; + else if (arg.startsWith("-X1")) Cfg::experimentalTempo = true; else if (arg.startsWith("-Xswap")) diff --git a/PianoBooster/src/Util.cpp b/PianoBooster/src/Util.cpp index 2fd5ca0..14581c3 100644 --- a/PianoBooster/src/Util.cpp +++ b/PianoBooster/src/Util.cpp @@ -39,15 +39,40 @@ static QTime s_realtime; +static FILE * logInfoFile = 0; +static FILE * logErrorFile = 0; + +static void openLogFile() { + if (logInfoFile != 0) + return; + + if (Cfg::useLogFile) + { + logInfoFile = fopen ("bp.log","w"); + logErrorFile = logInfoFile; + if (logErrorFile == 0) + { + fputs("FATAL: cannot open the logfile", stderr); + exit(EXIT_FAILURE); + } + } + else + { + logInfoFile = stdout; + logErrorFile = stderr; + } +} + /* prints an error message to stderr, and dies */ void fatal(const char *msg, ...) { va_list ap; - + openLogFile(); + fputs("FATAL: ", logErrorFile); va_start(ap, msg); - vfprintf(stderr, msg, ap); + vfprintf(logErrorFile, msg, ap); va_end(ap); - fputc('\n', stderr); + fputc('\n', logErrorFile); exit(EXIT_FAILURE); } @@ -57,11 +82,13 @@ void ppLog(logLevel_t level, const char *msg, ...) if (Cfg::logLevel < level) return; + openLogFile(); va_start(ap, msg); - vfprintf(stdout, msg, ap); + vfprintf(logInfoFile, msg, ap); va_end(ap); - fputc('\n', stdout); + fputc('\n', logInfoFile); } + void ppLogInfo(const char *msg, ...) { va_list ap; @@ -70,12 +97,13 @@ void ppLogInfo(const char *msg, ...) if (Cfg::logLevel < 1) return; - fputs("Info: ", stdout); + openLogFile(); + fputs("Info: ", logInfoFile); va_start(ap, msg); - vfprintf(stdout, msg, ap); + vfprintf(logInfoFile, msg, ap); va_end(ap); - fputc('\n', stdout); + fputc('\n', logInfoFile); } void ppLogWarn(const char *msg, ...) @@ -85,24 +113,26 @@ void ppLogWarn(const char *msg, ...) if (Cfg::logLevel < 2) return; - fputs("Warn: ", stdout); + openLogFile(); + fputs("Warn: ", logInfoFile); va_start(ap, msg); - vfprintf(stdout, msg, ap); + vfprintf(logInfoFile, msg, ap); va_end(ap); - fputc('\n', stdout); + fputc('\n', logInfoFile); } void ppLogTrace(const char *msg, ...) { va_list ap; - fputs("Trace: ", stdout); + openLogFile(); + fputs("Trace: ", logInfoFile); va_start(ap, msg); - vfprintf(stdout, msg, ap); + vfprintf(logInfoFile, msg, ap); va_end(ap); - fputc('\n', stdout); + fputc('\n', logInfoFile); } @@ -113,33 +143,36 @@ void ppLogDebug( const char *msg, ...) if (Cfg::logLevel < 2) return; - fputs("Debug: ", stdout); + openLogFile(); + fputs("Debug: ", logInfoFile); va_start(ap, msg); - vfprintf(stdout, msg, ap); + vfprintf(logInfoFile, msg, ap); va_end(ap); - fputc('\n', stdout); + fputc('\n', logInfoFile); } void ppLogError(const char *msg, ...) { va_list ap; - fputs("ERROR: ", stdout); + openLogFile(); + fputs("ERROR: ", logErrorFile); va_start(ap, msg); - vfprintf(stdout, msg, ap); + vfprintf(logErrorFile, msg, ap); va_end(ap); - fputc('\n', stdout); + fputc('\n', logErrorFile); } void ppTiming(const char *msg, ...) { va_list ap; + openLogFile(); va_start(ap, msg); - fprintf(stdout, "T %4d " , s_realtime.restart() ); - vfprintf(stdout, msg, ap); + fprintf(logInfoFile, "T %4d " , s_realtime.restart() ); + vfprintf(logInfoFile, msg, ap); va_end(ap); - fputc('\n', stdout); + fputc('\n', logInfoFile); } ////////////////////// BENCH MARK ////////////////////// @@ -213,11 +246,13 @@ void printResult(int i, benchData_t *pBench) { if (pBench->deltaCount == 0) return; + + openLogFile(); if (i>=0) - fprintf(stdout, "Bench%2d: ", i); + fprintf(logInfoFile, "Bench%2d: ", i); else - fputs("Bench : ", stdout); - fprintf(stdout, "ct %4d, min %2d, avg %4.3f, max %2d frame %4.3f %s\n", pBench->deltaCount, pBench->minDelta, + fputs("Bench : ", logInfoFile); + fprintf(logInfoFile, "ct %4d, min %2d, avg %4.3f, max %2d frame %4.3f %s\n", pBench->deltaCount, pBench->minDelta, static_cast(pBench->deltaTotal)/pBench->deltaCount, pBench->maxDelta, (static_cast(pBench->frameRateCurrent - pBench->frameRatePrevious))/pBench->deltaCount,