svapp  1.9
SVFileReader.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam and QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _SV_FILE_READER_H_
00017 #define _SV_FILE_READER_H_
00018 
00019 #include "layer/LayerFactory.h"
00020 #include "transform/Transform.h"
00021 
00022 #include <QXmlDefaultHandler>
00023 
00024 #include <map>
00025 
00026 class Pane;
00027 class Model;
00028 class Document;
00029 class PlayParameters;
00030 
00031 class SVFileReaderPaneCallback
00032 {
00033 public:
00034     virtual ~SVFileReaderPaneCallback();
00035     virtual Pane *addPane() = 0;
00036     virtual void setWindowSize(int width, int height) = 0;
00037     virtual void addSelection(int start, int end) = 0;
00038 };
00039 
00164 class SVFileReader : public QObject, QXmlDefaultHandler
00165 {
00166     Q_OBJECT
00167 
00168 public:
00169     SVFileReader(Document *document,
00170                  SVFileReaderPaneCallback &callback,
00171                  QString location = ""); // for audio file locate mechanism
00172     virtual ~SVFileReader();
00173 
00174     void parse(const QString &xmlData);
00175     void parse(QXmlInputSource &source);
00176 
00177     bool isOK();
00178     QString getErrorString() const { return m_errorString; }
00179 
00180     // For loading a single layer onto an existing pane
00181     void setCurrentPane(Pane *pane) { m_currentPane = pane; }
00182     
00183     virtual bool startElement(const QString &namespaceURI,
00184                               const QString &localName,
00185                               const QString &qName,
00186                               const QXmlAttributes& atts);
00187 
00188     virtual bool characters(const QString &);
00189 
00190     virtual bool endElement(const QString &namespaceURI,
00191                             const QString &localName,
00192                             const QString &qName);
00193 
00194     bool error(const QXmlParseException &exception);
00195     bool fatalError(const QXmlParseException &exception);
00196 
00197     enum FileType
00198     {
00199         SVSessionFile,
00200         SVLayerFile,
00201         UnknownFileType
00202     };
00203 
00204     static FileType identifyXmlFile(QString path);
00205 
00206 signals:
00207     void modelRegenerationFailed(QString layerName, QString transformName,
00208                                  QString message);
00209     void modelRegenerationWarning(QString layerName, QString transformName,
00210                                   QString message);
00211 
00212 protected:
00213     bool readWindow(const QXmlAttributes &);
00214     bool readModel(const QXmlAttributes &);
00215     bool readView(const QXmlAttributes &);
00216     bool readLayer(const QXmlAttributes &);
00217     bool readDatasetStart(const QXmlAttributes &);
00218     bool addBinToDataset(const QXmlAttributes &);
00219     bool addPointToDataset(const QXmlAttributes &);
00220     bool addRowToDataset(const QXmlAttributes &);
00221     bool readRowData(const QString &);
00222     bool readDerivation(const QXmlAttributes &);
00223     bool readPlayParameters(const QXmlAttributes &);
00224     bool readPlugin(const QXmlAttributes &);
00225     bool readPluginForTransform(const QXmlAttributes &);
00226     bool readPluginForPlayback(const QXmlAttributes &);
00227     bool readTransform(const QXmlAttributes &);
00228     bool readParameter(const QXmlAttributes &);
00229     bool readSelection(const QXmlAttributes &);
00230     bool readMeasurement(const QXmlAttributes &);
00231     void addUnaddedModels();
00232 
00233     bool haveModel(int id) {
00234         return (m_models.find(id) != m_models.end()) && m_models[id];
00235     }
00236 
00237     Document *m_document;
00238     SVFileReaderPaneCallback &m_paneCallback;
00239     QString m_location;
00240     Pane *m_currentPane;
00241     std::map<int, Layer *> m_layers;
00242     std::map<int, Model *> m_models;
00243     std::set<Model *> m_addedModels;
00244     std::map<int, int> m_awaitingDatasets; // map dataset id -> model id
00245     Layer *m_currentLayer;
00246     Model *m_currentDataset;
00247     Model *m_currentDerivedModel;
00248     int m_currentDerivedModelId;
00249     PlayParameters *m_currentPlayParameters;
00250     Transform m_currentTransform;
00251     Model *m_currentTransformSource;
00252     int m_currentTransformChannel;
00253     bool m_currentTransformIsNewStyle;
00254     QString m_datasetSeparator;
00255     bool m_inRow;
00256     bool m_inLayer;
00257     bool m_inView;
00258     bool m_inData;
00259     bool m_inSelections;
00260     int m_rowNumber;
00261     QString m_errorString;
00262     bool m_ok;
00263 };
00264 
00265 #endif