annotate framework/SVFileReader.h @ 45:9ea770d93fae

* document -> framework (will not compile, path fixes not in yet)
author Chris Cannam
date Wed, 24 Oct 2007 16:37:58 +0000
parents
children de2b3c6479c8
rev   line source
Chris@45 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@45 2
Chris@45 3 /*
Chris@45 4 Sonic Visualiser
Chris@45 5 An audio file viewer and annotation editor.
Chris@45 6 Centre for Digital Music, Queen Mary, University of London.
Chris@45 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@45 8
Chris@45 9 This program is free software; you can redistribute it and/or
Chris@45 10 modify it under the terms of the GNU General Public License as
Chris@45 11 published by the Free Software Foundation; either version 2 of the
Chris@45 12 License, or (at your option) any later version. See the file
Chris@45 13 COPYING included with this distribution for more information.
Chris@45 14 */
Chris@45 15
Chris@45 16 #ifndef _SV_FILE_READER_H_
Chris@45 17 #define _SV_FILE_READER_H_
Chris@45 18
Chris@45 19 #include "layer/LayerFactory.h"
Chris@45 20 #include "plugin/transform/Transform.h"
Chris@45 21 #include "plugin/transform/PluginTransform.h"
Chris@45 22
Chris@45 23 #include <QXmlDefaultHandler>
Chris@45 24
Chris@45 25 #include <map>
Chris@45 26
Chris@45 27 class Pane;
Chris@45 28 class Model;
Chris@45 29 class Document;
Chris@45 30 class PlayParameters;
Chris@45 31
Chris@45 32 class SVFileReaderPaneCallback
Chris@45 33 {
Chris@45 34 public:
Chris@45 35 virtual ~SVFileReaderPaneCallback();
Chris@45 36 virtual Pane *addPane() = 0;
Chris@45 37 virtual void setWindowSize(int width, int height) = 0;
Chris@45 38 virtual void addSelection(int start, int end) = 0;
Chris@45 39 };
Chris@45 40
Chris@45 41 /**
Chris@45 42 SVFileReader loads Sonic Visualiser XML files. (The SV file
Chris@45 43 format is bzipped XML.)
Chris@45 44
Chris@45 45 Some notes about the SV XML format follow. We're very lazy with
Chris@45 46 our XML: there's no schema or DTD, and we depend heavily on
Chris@45 47 elements being in a particular order.
Chris@45 48
Chris@45 49 \verbatim
Chris@45 50
Chris@45 51 <sv>
Chris@45 52
Chris@45 53 <data>
Chris@45 54
Chris@45 55 <!-- The data section contains definitions of both models and
Chris@45 56 visual layers. Layers are considered data in the document;
Chris@45 57 the structure of views that displays the layers is not. -->
Chris@45 58
Chris@45 59 <!-- id numbers are unique within the data type (i.e. no two
Chris@45 60 models can have the same id, but a model can have the same
Chris@45 61 id as a layer, etc). SV generates its id numbers just for
Chris@45 62 the purpose of cross-referencing within the current file;
Chris@45 63 they don't necessarily have any meaning once the file has
Chris@45 64 been loaded. -->
Chris@45 65
Chris@45 66 <model id="0" name="..." type="..." ... />
Chris@45 67 <model id="1" name="..." type="..." ... />
Chris@45 68
Chris@45 69 <!-- Models that have data associated with them store it
Chris@45 70 in a neighbouring dataset element. The dataset must follow
Chris@45 71 the model and precede any derivation or layer elements that
Chris@45 72 refer to the model. -->
Chris@45 73
Chris@45 74 <model id="2" name="..." type="..." dataset="0" ... />
Chris@45 75
Chris@45 76 <dataset id="0" type="...">
Chris@45 77 <point frame="..." value="..." ... />
Chris@45 78 </dataset>
Chris@45 79
Chris@45 80 <!-- Where one model is derived from another via a transform,
Chris@45 81 it has an associated derivation element. This must follow
Chris@45 82 both the source and target model elements. The source and
Chris@45 83 model attributes give the source model id and target model
Chris@45 84 id respectively. A model can have both dataset and
Chris@45 85 derivation elements; if it does, dataset must appear first.
Chris@45 86 If the model's data are not stored, but instead the model
Chris@45 87 is to be regenerated completely from the transform when
Chris@45 88 the session is reloaded, then the model should have _only_
Chris@45 89 a derivation element, and no model element should appear
Chris@45 90 for it at all. -->
Chris@45 91
Chris@45 92 <derivation source="0" model="2" transform="..." ...>
Chris@45 93 <plugin id="..." ... />
Chris@45 94 </derivation>
Chris@45 95
Chris@45 96 <!-- The playparameters element lists playback settings for
Chris@45 97 a model. -->
Chris@45 98
Chris@45 99 <playparameters mute="false" pan="0" gain="1" model="1" ... />
Chris@45 100
Chris@45 101 <!-- Layer elements. The models must have already been defined.
Chris@45 102 The same model may appear in more than one layer (of more
Chris@45 103 than one type). -->
Chris@45 104
Chris@45 105 <layer id="1" type="..." name="..." model="0" ... />
Chris@45 106 <layer id="2" type="..." name="..." model="1" ... />
Chris@45 107
Chris@45 108 </data>
Chris@45 109
Chris@45 110
Chris@45 111 <display>
Chris@45 112
Chris@45 113 <!-- The display element contains visual structure for the
Chris@45 114 layers. It's simpler than the data section. -->
Chris@45 115
Chris@45 116 <!-- Overall preferred window size for this session. -->
Chris@45 117
Chris@45 118 <window width="..." height="..."/>
Chris@45 119
Chris@45 120 <!-- List of view elements to stack up. Each one contains
Chris@45 121 a list of layers in stacking order, back to front. -->
Chris@45 122
Chris@45 123 <view type="pane" ...>
Chris@45 124 <layer id="1"/>
Chris@45 125 <layer id="2"/>
Chris@45 126 </view>
Chris@45 127
Chris@45 128 <!-- The layer elements just refer to layers defined in the
Chris@45 129 data section, so they don't have to have any attributes
Chris@45 130 other than the id. For sort-of-historical reasons SV
Chris@45 131 actually does repeat the other attributes here, but
Chris@45 132 it doesn't need to. -->
Chris@45 133
Chris@45 134 <view type="pane" ...>
Chris@45 135 <layer id="2"/>
Chris@45 136 <view>
Chris@45 137
Chris@45 138 </display>
Chris@45 139
Chris@45 140
Chris@45 141 <!-- List of selected regions by audio frame extents. -->
Chris@45 142
Chris@45 143 <selections>
Chris@45 144 <selection start="..." end="..."/>
Chris@45 145 </selections>
Chris@45 146
Chris@45 147
Chris@45 148 </sv>
Chris@45 149
Chris@45 150 \endverbatim
Chris@45 151 */
Chris@45 152
Chris@45 153
Chris@45 154 class SVFileReader : public QXmlDefaultHandler
Chris@45 155 {
Chris@45 156 public:
Chris@45 157 SVFileReader(Document *document,
Chris@45 158 SVFileReaderPaneCallback &callback,
Chris@45 159 QString location = ""); // for audio file locate mechanism
Chris@45 160 virtual ~SVFileReader();
Chris@45 161
Chris@45 162 void parse(const QString &xmlData);
Chris@45 163 void parse(QXmlInputSource &source);
Chris@45 164
Chris@45 165 bool isOK();
Chris@45 166 QString getErrorString() const { return m_errorString; }
Chris@45 167
Chris@45 168 // For loading a single layer onto an existing pane
Chris@45 169 void setCurrentPane(Pane *pane) { m_currentPane = pane; }
Chris@45 170
Chris@45 171 virtual bool startElement(const QString &namespaceURI,
Chris@45 172 const QString &localName,
Chris@45 173 const QString &qName,
Chris@45 174 const QXmlAttributes& atts);
Chris@45 175
Chris@45 176 virtual bool characters(const QString &);
Chris@45 177
Chris@45 178 virtual bool endElement(const QString &namespaceURI,
Chris@45 179 const QString &localName,
Chris@45 180 const QString &qName);
Chris@45 181
Chris@45 182 bool error(const QXmlParseException &exception);
Chris@45 183 bool fatalError(const QXmlParseException &exception);
Chris@45 184
Chris@45 185 protected:
Chris@45 186 bool readWindow(const QXmlAttributes &);
Chris@45 187 bool readModel(const QXmlAttributes &);
Chris@45 188 bool readView(const QXmlAttributes &);
Chris@45 189 bool readLayer(const QXmlAttributes &);
Chris@45 190 bool readDatasetStart(const QXmlAttributes &);
Chris@45 191 bool addBinToDataset(const QXmlAttributes &);
Chris@45 192 bool addPointToDataset(const QXmlAttributes &);
Chris@45 193 bool addRowToDataset(const QXmlAttributes &);
Chris@45 194 bool readRowData(const QString &);
Chris@45 195 bool readDerivation(const QXmlAttributes &);
Chris@45 196 bool readPlayParameters(const QXmlAttributes &);
Chris@45 197 bool readPlugin(const QXmlAttributes &);
Chris@45 198 bool readSelection(const QXmlAttributes &);
Chris@45 199 bool readMeasurement(const QXmlAttributes &);
Chris@45 200 void addUnaddedModels();
Chris@45 201
Chris@45 202 bool haveModel(int id) {
Chris@45 203 return (m_models.find(id) != m_models.end()) && m_models[id];
Chris@45 204 }
Chris@45 205
Chris@45 206 Document *m_document;
Chris@45 207 SVFileReaderPaneCallback &m_paneCallback;
Chris@45 208 QString m_location;
Chris@45 209 Pane *m_currentPane;
Chris@45 210 std::map<int, Layer *> m_layers;
Chris@45 211 std::map<int, Model *> m_models;
Chris@45 212 std::set<Model *> m_addedModels;
Chris@45 213 std::map<int, int> m_awaitingDatasets; // map dataset id -> model id
Chris@45 214 Layer *m_currentLayer;
Chris@45 215 Model *m_currentDataset;
Chris@45 216 Model *m_currentDerivedModel;
Chris@45 217 int m_currentDerivedModelId;
Chris@45 218 PlayParameters *m_currentPlayParameters;
Chris@45 219 QString m_currentTransform;
Chris@45 220 Model *m_currentTransformSource;
Chris@45 221 PluginTransform::ExecutionContext m_currentTransformContext;
Chris@45 222 QString m_currentTransformConfiguration;
Chris@45 223 QString m_datasetSeparator;
Chris@45 224 bool m_inRow;
Chris@45 225 bool m_inLayer;
Chris@45 226 bool m_inView;
Chris@45 227 bool m_inData;
Chris@45 228 bool m_inSelections;
Chris@45 229 int m_rowNumber;
Chris@45 230 QString m_errorString;
Chris@45 231 bool m_ok;
Chris@45 232 };
Chris@45 233
Chris@45 234 #endif