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