Chris@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@0: Sonic Visualiser Chris@0: An audio file viewer and annotation editor. Chris@0: Centre for Digital Music, Queen Mary, University of London. Chris@77: This file copyright 2006 Chris Cannam and QMUL. Chris@0: Chris@0: This program is free software; you can redistribute it and/or Chris@0: modify it under the terms of the GNU General Public License as Chris@0: published by the Free Software Foundation; either version 2 of the Chris@0: License, or (at your option) any later version. See the file Chris@0: COPYING included with this distribution for more information. Chris@0: */ Chris@0: Chris@0: #ifndef _SV_FILE_READER_H_ Chris@0: #define _SV_FILE_READER_H_ Chris@0: Chris@0: #include "layer/LayerFactory.h" Chris@0: #include "transform/Transform.h" Chris@30: #include "transform/PluginTransform.h" Chris@0: Chris@0: #include Chris@0: Chris@0: #include Chris@0: Chris@0: class Pane; Chris@0: class Model; Chris@0: class Document; Chris@0: class PlayParameters; Chris@0: Chris@0: class SVFileReaderPaneCallback Chris@0: { Chris@0: public: Chris@137: virtual ~SVFileReaderPaneCallback(); Chris@0: virtual Pane *addPane() = 0; Chris@0: virtual void setWindowSize(int width, int height) = 0; Chris@0: virtual void addSelection(int start, int end) = 0; Chris@0: }; Chris@0: Chris@127: /** Chris@127: SVFileReader loads Sonic Visualiser XML files. (The SV file Chris@127: format is bzipped XML.) Chris@127: Chris@127: Some notes about the SV XML format follow. We're very lazy with Chris@127: our XML: there's no schema or DTD, and we depend heavily on Chris@127: elements being in a particular order. Chris@127: Chris@127: \verbatim Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: Chris@127: \endverbatim Chris@127: */ Chris@127: Chris@127: Chris@0: class SVFileReader : public QXmlDefaultHandler Chris@0: { Chris@0: public: Chris@0: SVFileReader(Document *document, Chris@87: SVFileReaderPaneCallback &callback, Chris@87: QString location = ""); // for audio file locate mechanism Chris@0: virtual ~SVFileReader(); Chris@0: Chris@0: void parse(const QString &xmlData); Chris@0: void parse(QXmlInputSource &source); Chris@0: Chris@0: bool isOK(); Chris@0: QString getErrorString() const { return m_errorString; } Chris@0: Chris@0: // For loading a single layer onto an existing pane Chris@0: void setCurrentPane(Pane *pane) { m_currentPane = pane; } Chris@0: Chris@0: virtual bool startElement(const QString &namespaceURI, Chris@0: const QString &localName, Chris@0: const QString &qName, Chris@0: const QXmlAttributes& atts); Chris@0: Chris@0: virtual bool characters(const QString &); Chris@0: Chris@0: virtual bool endElement(const QString &namespaceURI, Chris@0: const QString &localName, Chris@0: const QString &qName); Chris@0: Chris@0: bool error(const QXmlParseException &exception); Chris@0: bool fatalError(const QXmlParseException &exception); Chris@0: Chris@0: protected: Chris@0: bool readWindow(const QXmlAttributes &); Chris@0: bool readModel(const QXmlAttributes &); Chris@0: bool readView(const QXmlAttributes &); Chris@0: bool readLayer(const QXmlAttributes &); Chris@0: bool readDatasetStart(const QXmlAttributes &); Chris@0: bool addBinToDataset(const QXmlAttributes &); Chris@0: bool addPointToDataset(const QXmlAttributes &); Chris@0: bool addRowToDataset(const QXmlAttributes &); Chris@0: bool readRowData(const QString &); Chris@0: bool readDerivation(const QXmlAttributes &); Chris@0: bool readPlayParameters(const QXmlAttributes &); Chris@0: bool readPlugin(const QXmlAttributes &); Chris@0: bool readSelection(const QXmlAttributes &); Chris@0: void addUnaddedModels(); Chris@0: Chris@0: Document *m_document; Chris@0: SVFileReaderPaneCallback &m_paneCallback; Chris@87: QString m_location; Chris@0: Pane *m_currentPane; Chris@0: std::map m_layers; Chris@0: std::map m_models; Chris@0: std::set m_addedModels; Chris@0: std::map m_awaitingDatasets; // map dataset id -> model id Chris@0: Model *m_currentDataset; Chris@0: Model *m_currentDerivedModel; Chris@55: int m_currentDerivedModelId; Chris@0: PlayParameters *m_currentPlayParameters; Chris@0: QString m_currentTransform; Chris@55: Model *m_currentTransformSource; Chris@30: PluginTransform::ExecutionContext m_currentTransformContext; Chris@0: QString m_currentTransformConfiguration; Chris@0: QString m_datasetSeparator; Chris@0: bool m_inRow; Chris@0: bool m_inView; Chris@0: bool m_inData; Chris@0: bool m_inSelections; Chris@0: int m_rowNumber; Chris@0: QString m_errorString; Chris@0: bool m_ok; Chris@0: }; Chris@0: Chris@0: #endif