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