Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Musicxml import logging #3330

Merged
merged 4 commits into from Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion mscore/CMakeLists.txt
Expand Up @@ -238,7 +238,7 @@ add_executable ( ${ExecutableName}
scoreview.cpp editharmony.cpp editfiguredbass.cpp events.cpp
editinstrument.cpp editstyle.cpp
icons.cpp importbww.cpp
importmxml.cpp importmxmlpass1.cpp importmxmlpass2.cpp
importmxml.cpp importmxmllogger.cpp importmxmlpass1.cpp importmxmlpass2.cpp
instrdialog.cpp instrwidget.cpp
debugger/debugger.cpp menus.cpp
musescore.cpp navigator.cpp pagesettings.cpp palette.cpp
Expand Down
9 changes: 7 additions & 2 deletions mscore/importmxml.cpp
Expand Up @@ -26,6 +26,7 @@
#include "libmscore/symbol.h"

#include "importmxml.h"
#include "importmxmllogger.h"
#include "importmxmlpass1.h"
#include "importmxmlpass2.h"
#include "preferences.h"
Expand All @@ -37,16 +38,20 @@ Score::FileError importMusicXMLfromBuffer(Score* score, const QString& /*name*/,
//qDebug("importMusicXMLfromBuffer(score %p, name '%s', dev %p)",
// score, qPrintable(name), dev);

MxmlLogger logger;
logger.setLoggingLevel(MxmlLogger::Level::INFO);
//logger.setLoggingLevel(MxmlLogger::Level::TRACE); // also include tracing

// pass 1
dev->seek(0);
MusicXMLParserPass1 pass1(score);
MusicXMLParserPass1 pass1(score, &logger);
Score::FileError res = pass1.parse(dev);
if (res != Score::FileError::FILE_NO_ERROR)
return res;

// pass 2
dev->seek(0);
MusicXMLParserPass2 pass2(score, pass1);
MusicXMLParserPass2 pass2(score, pass1, &logger);
return pass2.parse(dev);
}

Expand Down
97 changes: 97 additions & 0 deletions mscore/importmxmllogger.cpp
@@ -0,0 +1,97 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2017 Werner Schweer and others
//
// 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 published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================

#include "importmxmllogger.h"

namespace Ms {

//---------------------------------------------------------
// xmlLocation
//---------------------------------------------------------

static QString xmlLocation(const QXmlStreamReader* const xmlreader)
{
QString loc;
if (xmlreader) {
loc = QString(" at line %1 col %2").arg(xmlreader->lineNumber()).arg(xmlreader->columnNumber());
}
return loc;

}

//---------------------------------------------------------
// logDebugTrace
//---------------------------------------------------------

static void log(MxmlLogger::Level level, const QString& text, const QXmlStreamReader* const xmlreader)
{
QString str;
switch (level) {
case MxmlLogger::Level::TRACE: str = "Trace"; break;
case MxmlLogger::Level::INFO: str = "Info"; break;
case MxmlLogger::Level::ERROR: str = "Error"; break;
default: str = "Unknown"; break;
}

str += xmlLocation(xmlreader);
str += ": ";
str += text;

qDebug("%s", qPrintable(str));
}

//---------------------------------------------------------
// logDebugTrace
//---------------------------------------------------------

/**
Log debug (function) trace.
*/

void MxmlLogger::logDebugTrace(const QString& trace, const QXmlStreamReader* const xmlreader)
{
if (_level <= Level::TRACE) {
log(Level::TRACE, trace, xmlreader);
}
}

//---------------------------------------------------------
// logDebugInfo
//---------------------------------------------------------

/**
Log debug \a info (non-fatal events relevant for debugging).
*/

void MxmlLogger::logDebugInfo(const QString& info, const QXmlStreamReader* const xmlreader)
{
if (_level <= Level::INFO) {
log(Level::INFO, info, xmlreader);
}
}

//---------------------------------------------------------
// logError
//---------------------------------------------------------

/**
Log \a error (possibly non-fatal but to be reported to the user anyway).
*/

void MxmlLogger::logError(const QString& error, const QXmlStreamReader* const xmlreader)
{
if (_level <= Level::ERROR) {
log(Level::ERROR, error, xmlreader);
}
}

}
36 changes: 36 additions & 0 deletions mscore/importmxmllogger.h
@@ -0,0 +1,36 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2017 Werner Schweer and others
//
// 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 published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================

#ifndef __IMPORTMXMLLOGGER_H__
#define __IMPORTMXMLLOGGER_H__

class QXmlStreamReader;

namespace Ms {

class MxmlLogger {
public:
enum class Level : char {
TRACE, INFO, ERROR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFO and ERROR conflicts with something in a Windows specific header, so it doesn't build there, renaming to XINFO and XERROR fixes the build problem

};
MxmlLogger() {}
void logDebugTrace(const QString& trace, const QXmlStreamReader* const xmlreader = 0);
void logDebugInfo(const QString& info, const QXmlStreamReader* const xmlreader = 0);
void logError(const QString& error, const QXmlStreamReader* const xmlreader = 0);
void setLoggingLevel(const Level level) { _level = level; }
private:
Level _level = Level::INFO;
};

} // namespace Ms

#endif