diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 18:37:05 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 18:37:05 +0000 |
commit | 145364a8af6a1fec06556221e66d4b724a62fc9a (patch) | |
tree | 53bd71a544008c518034f208d64c932dc2883f50 /src/gui/editors/guitar/ChordXmlHandler.cpp | |
download | rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.tar.gz rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.zip |
Added old abandoned KDE3 version of the RoseGarden MIDI tool
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/rosegarden@1097595 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/gui/editors/guitar/ChordXmlHandler.cpp')
-rw-r--r-- | src/gui/editors/guitar/ChordXmlHandler.cpp | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/src/gui/editors/guitar/ChordXmlHandler.cpp b/src/gui/editors/guitar/ChordXmlHandler.cpp new file mode 100644 index 0000000..701c43c --- /dev/null +++ b/src/gui/editors/guitar/ChordXmlHandler.cpp @@ -0,0 +1,154 @@ +// -*- c-basic-offset: 4 -*- + +/* + Rosegarden + A sequencer and musical notation editor. + + This program is Copyright 2000-2008 + Guillaume Laurent <[email protected]>, + Chris Cannam <[email protected]>, + Richard Bown <[email protected]> + + The moral right of the authors to claim authorship of this work + has been asserted. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "ChordXmlHandler.h" +#include "misc/Debug.h" + +namespace Rosegarden +{ + +ChordXmlHandler::ChordXmlHandler(Guitar::ChordMap& map) + : ProgressReporter(0), + m_chordMap(map) +{ +} + +ChordXmlHandler::~ChordXmlHandler() +{ +} + +bool ChordXmlHandler::startDocument() +{ + // nothing to do ? + return true; +} + +bool ChordXmlHandler::startElement(const QString& namespaceURI, + const QString& localName, + const QString& qName, + const QXmlAttributes& atts) +{ + QString lcName = qName.lower(); + + if (lcName == "chordset") { + // start new chord set + m_currentRoot = atts.value("root").stripWhiteSpace(); + + } else if (lcName == "chord") { + + m_currentChord = Guitar::Chord(m_currentRoot); + + if (atts.index("ext") >= 0) + m_currentChord.setExt(atts.value("ext").stripWhiteSpace()); + + if (atts.index("user") >= 0) { + QString userVal = atts.value("user").stripWhiteSpace().lower(); + bool res = (userVal == "yes" || userVal == "1" || userVal == "true"); + m_currentChord.setUserChord(res); + } else { + m_currentChord.setUserChord(false); + } + + } else if (lcName == "fingering") { + m_inFingering = true; + } + + return true; +} + +bool ChordXmlHandler::endElement(const QString& namespaceURI, + const QString& localName, + const QString& qName) +{ + QString lcName = qName.lower(); + + if (lcName == "fingering") { + + m_inFingering = false; + m_chordMap.insert(m_currentChord); + NOTATION_DEBUG << "ChordXmlHandler::endElement (fingering) : adding chord " << m_currentChord << endl; + + } else if (lcName == "chord") { + + // adding is done after each parsing of fingering + // +// m_chordMap.insert(m_currentChord); + + } + + return true; +} + +bool ChordXmlHandler::characters(const QString& ch) +{ + QString ch2 = ch.simplifyWhiteSpace(); + + if (!ch2.isEmpty() && m_inFingering) { + if (!parseFingering(ch2)) + return false; + } + + return true; +} + +bool ChordXmlHandler::endDocument() +{ + return true; +} + +bool ChordXmlHandler::parseFingering(const QString& ch) { + + QString errString; + + Guitar::Fingering fingering = Guitar::Fingering::parseFingering(ch, errString); + + if (m_errorString.isEmpty()) { + NOTATION_DEBUG << "ChordXmlHandler::parseFingering : fingering " << ch << endl; + m_currentChord.setFingering(fingering); + return true; + } else { + m_errorString = errString; + return false; + } +} + +bool +ChordXmlHandler::error(const QXmlParseException& exception) +{ + m_errorString = QString("%1 at line %2, column %3") + .arg(exception.message()) + .arg(exception.lineNumber()) + .arg(exception.columnNumber()); + return QXmlDefaultHandler::error( exception ); +} + +bool +ChordXmlHandler::fatalError(const QXmlParseException& exception) +{ + m_errorString = QString("%1 at line %2, column %3") + .arg(exception.message()) + .arg(exception.lineNumber()) + .arg(exception.columnNumber()); + return QXmlDefaultHandler::fatalError( exception ); +} + + +} |