Chris@58
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@59
|
4 Sonic Visualiser
|
Chris@59
|
5 An audio file viewer and annotation editor.
|
Chris@59
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@59
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@59
|
9 This program is free software; you can redistribute it and/or
|
Chris@59
|
10 modify it under the terms of the GNU General Public License as
|
Chris@59
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@59
|
12 License, or (at your option) any later version. See the file
|
Chris@59
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include "LayerFactory.h"
|
Chris@0
|
17
|
Chris@0
|
18 #include "WaveformLayer.h"
|
Chris@0
|
19 #include "SpectrogramLayer.h"
|
Chris@0
|
20 #include "TimeRulerLayer.h"
|
Chris@0
|
21 #include "TimeInstantLayer.h"
|
Chris@0
|
22 #include "TimeValueLayer.h"
|
Chris@30
|
23 #include "NoteLayer.h"
|
Chris@35
|
24 #include "TextLayer.h"
|
Chris@0
|
25 #include "Colour3DPlotLayer.h"
|
Chris@0
|
26
|
Chris@128
|
27 #include "data/model/RangeSummarisableTimeValueModel.h"
|
Chris@128
|
28 #include "data/model/DenseTimeValueModel.h"
|
Chris@128
|
29 #include "data/model/SparseOneDimensionalModel.h"
|
Chris@128
|
30 #include "data/model/SparseTimeValueModel.h"
|
Chris@128
|
31 #include "data/model/NoteModel.h"
|
Chris@128
|
32 #include "data/model/TextModel.h"
|
Chris@128
|
33 #include "data/model/DenseThreeDimensionalModel.h"
|
Chris@0
|
34
|
Chris@0
|
35 LayerFactory *
|
Chris@0
|
36 LayerFactory::m_instance = new LayerFactory;
|
Chris@0
|
37
|
Chris@0
|
38 LayerFactory *
|
Chris@125
|
39 LayerFactory::getInstance()
|
Chris@0
|
40 {
|
Chris@0
|
41 return m_instance;
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 LayerFactory::~LayerFactory()
|
Chris@0
|
45 {
|
Chris@0
|
46 }
|
Chris@0
|
47
|
Chris@0
|
48 QString
|
Chris@0
|
49 LayerFactory::getLayerPresentationName(LayerType type)
|
Chris@0
|
50 {
|
Chris@0
|
51 switch (type) {
|
Chris@0
|
52 case Waveform: return Layer::tr("Waveform");
|
Chris@0
|
53 case Spectrogram: return Layer::tr("Spectrogram");
|
Chris@0
|
54 case TimeRuler: return Layer::tr("Ruler");
|
Chris@0
|
55 case TimeInstants: return Layer::tr("Time Instants");
|
Chris@0
|
56 case TimeValues: return Layer::tr("Time Values");
|
Chris@30
|
57 case Notes: return Layer::tr("Notes");
|
Chris@35
|
58 case Text: return Layer::tr("Text");
|
Chris@0
|
59 case Colour3DPlot: return Layer::tr("Colour 3D Plot");
|
Chris@0
|
60
|
Chris@0
|
61 case MelodicRangeSpectrogram:
|
Chris@0
|
62 // The user can change all the parameters of this after the
|
Chris@0
|
63 // fact -- there's nothing permanently melodic-range about it
|
Chris@0
|
64 // that should be encoded in its name
|
Chris@0
|
65 return Layer::tr("Spectrogram");
|
Chris@11
|
66
|
Chris@37
|
67 case PeakFrequencySpectrogram:
|
Chris@37
|
68 // likewise
|
Chris@37
|
69 return Layer::tr("Spectrogram");
|
Chris@37
|
70
|
Chris@11
|
71 default: break;
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 return Layer::tr("Layer");
|
Chris@0
|
75 }
|
Chris@0
|
76
|
Chris@0
|
77 LayerFactory::LayerTypeSet
|
Chris@0
|
78 LayerFactory::getValidLayerTypes(Model *model)
|
Chris@0
|
79 {
|
Chris@0
|
80 LayerTypeSet types;
|
Chris@0
|
81
|
Chris@0
|
82 if (dynamic_cast<DenseThreeDimensionalModel *>(model)) {
|
Chris@0
|
83 types.insert(Colour3DPlot);
|
Chris@0
|
84 }
|
Chris@0
|
85
|
Chris@0
|
86 if (dynamic_cast<DenseTimeValueModel *>(model)) {
|
Chris@0
|
87 types.insert(Spectrogram);
|
Chris@0
|
88 types.insert(MelodicRangeSpectrogram);
|
Chris@37
|
89 types.insert(PeakFrequencySpectrogram);
|
Chris@0
|
90 }
|
Chris@0
|
91
|
Chris@0
|
92 if (dynamic_cast<RangeSummarisableTimeValueModel *>(model)) {
|
Chris@0
|
93 types.insert(Waveform);
|
Chris@0
|
94 }
|
Chris@0
|
95
|
Chris@0
|
96 if (dynamic_cast<SparseOneDimensionalModel *>(model)) {
|
Chris@0
|
97 types.insert(TimeInstants);
|
Chris@0
|
98 }
|
Chris@0
|
99
|
Chris@0
|
100 if (dynamic_cast<SparseTimeValueModel *>(model)) {
|
Chris@0
|
101 types.insert(TimeValues);
|
Chris@35
|
102
|
Chris@35
|
103 }
|
Chris@35
|
104 if (dynamic_cast<NoteModel *>(model)) {
|
Chris@35
|
105 types.insert(Notes);
|
Chris@0
|
106 }
|
Chris@0
|
107
|
Chris@35
|
108 if (dynamic_cast<TextModel *>(model)) {
|
Chris@35
|
109 types.insert(Text);
|
Chris@30
|
110 }
|
Chris@30
|
111
|
Chris@0
|
112 // We don't count TimeRuler here as it doesn't actually display
|
Chris@0
|
113 // the data, although it can be backed by any model
|
Chris@0
|
114
|
Chris@0
|
115 return types;
|
Chris@0
|
116 }
|
Chris@0
|
117
|
Chris@17
|
118 LayerFactory::LayerTypeSet
|
Chris@17
|
119 LayerFactory::getValidEmptyLayerTypes()
|
Chris@17
|
120 {
|
Chris@17
|
121 LayerTypeSet types;
|
Chris@17
|
122 types.insert(TimeInstants);
|
Chris@17
|
123 types.insert(TimeValues);
|
Chris@30
|
124 types.insert(Notes);
|
Chris@35
|
125 types.insert(Text);
|
Chris@17
|
126 //!!! and in principle Colour3DPlot -- now that's a challenge
|
Chris@17
|
127 return types;
|
Chris@17
|
128 }
|
Chris@17
|
129
|
Chris@0
|
130 LayerFactory::LayerType
|
Chris@6
|
131 LayerFactory::getLayerType(const Layer *layer)
|
Chris@0
|
132 {
|
Chris@6
|
133 if (dynamic_cast<const WaveformLayer *>(layer)) return Waveform;
|
Chris@6
|
134 if (dynamic_cast<const SpectrogramLayer *>(layer)) return Spectrogram;
|
Chris@6
|
135 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler;
|
Chris@6
|
136 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants;
|
Chris@6
|
137 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues;
|
Chris@30
|
138 if (dynamic_cast<const NoteLayer *>(layer)) return Notes;
|
Chris@35
|
139 if (dynamic_cast<const TextLayer *>(layer)) return Text;
|
Chris@6
|
140 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot;
|
Chris@6
|
141 return UnknownLayer;
|
Chris@6
|
142 }
|
Chris@6
|
143
|
Chris@6
|
144 QString
|
Chris@17
|
145 LayerFactory::getLayerIconName(LayerType type)
|
Chris@17
|
146 {
|
Chris@17
|
147 switch (type) {
|
Chris@17
|
148 case Waveform: return "waveform";
|
Chris@17
|
149 case Spectrogram: return "spectrogram";
|
Chris@17
|
150 case TimeRuler: return "timeruler";
|
Chris@17
|
151 case TimeInstants: return "instants";
|
Chris@17
|
152 case TimeValues: return "values";
|
Chris@30
|
153 case Notes: return "notes";
|
Chris@35
|
154 case Text: return "text";
|
Chris@17
|
155 case Colour3DPlot: return "colour3d";
|
Chris@17
|
156 default: return "unknown";
|
Chris@17
|
157 }
|
Chris@17
|
158 }
|
Chris@17
|
159
|
Chris@17
|
160 QString
|
Chris@6
|
161 LayerFactory::getLayerTypeName(LayerType type)
|
Chris@6
|
162 {
|
Chris@6
|
163 switch (type) {
|
Chris@6
|
164 case Waveform: return "waveform";
|
Chris@6
|
165 case Spectrogram: return "spectrogram";
|
Chris@6
|
166 case TimeRuler: return "timeruler";
|
Chris@6
|
167 case TimeInstants: return "timeinstants";
|
Chris@6
|
168 case TimeValues: return "timevalues";
|
Chris@30
|
169 case Notes: return "notes";
|
Chris@35
|
170 case Text: return "text";
|
Chris@6
|
171 case Colour3DPlot: return "colour3dplot";
|
Chris@6
|
172 default: return "unknown";
|
Chris@6
|
173 }
|
Chris@6
|
174 }
|
Chris@6
|
175
|
Chris@6
|
176 LayerFactory::LayerType
|
Chris@6
|
177 LayerFactory::getLayerTypeForName(QString name)
|
Chris@6
|
178 {
|
Chris@6
|
179 if (name == "waveform") return Waveform;
|
Chris@6
|
180 if (name == "spectrogram") return Spectrogram;
|
Chris@6
|
181 if (name == "timeruler") return TimeRuler;
|
Chris@6
|
182 if (name == "timeinstants") return TimeInstants;
|
Chris@6
|
183 if (name == "timevalues") return TimeValues;
|
Chris@30
|
184 if (name == "notes") return Notes;
|
Chris@35
|
185 if (name == "text") return Text;
|
Chris@6
|
186 if (name == "colour3dplot") return Colour3DPlot;
|
Chris@0
|
187 return UnknownLayer;
|
Chris@0
|
188 }
|
Chris@0
|
189
|
Chris@0
|
190 void
|
Chris@0
|
191 LayerFactory::setModel(Layer *layer, Model *model)
|
Chris@0
|
192 {
|
Chris@0
|
193 if (trySetModel<WaveformLayer, RangeSummarisableTimeValueModel>(layer, model))
|
Chris@0
|
194 return;
|
Chris@0
|
195
|
Chris@0
|
196 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
|
Chris@0
|
197 return;
|
Chris@0
|
198
|
Chris@0
|
199 if (trySetModel<TimeRulerLayer, Model>(layer, model))
|
Chris@0
|
200 return;
|
Chris@0
|
201
|
Chris@0
|
202 if (trySetModel<TimeInstantLayer, SparseOneDimensionalModel>(layer, model))
|
Chris@0
|
203 return;
|
Chris@0
|
204
|
Chris@0
|
205 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model))
|
Chris@0
|
206 return;
|
Chris@0
|
207
|
Chris@30
|
208 if (trySetModel<NoteLayer, NoteModel>(layer, model))
|
Chris@30
|
209 return;
|
Chris@30
|
210
|
Chris@35
|
211 if (trySetModel<TextLayer, TextModel>(layer, model))
|
Chris@35
|
212 return;
|
Chris@35
|
213
|
Chris@0
|
214 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model))
|
Chris@0
|
215 return;
|
Chris@0
|
216
|
Chris@0
|
217 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
|
Chris@0
|
218 return;
|
Chris@0
|
219 }
|
Chris@0
|
220
|
Chris@17
|
221 Model *
|
Chris@17
|
222 LayerFactory::createEmptyModel(LayerType layerType, Model *baseModel)
|
Chris@17
|
223 {
|
Chris@17
|
224 if (layerType == TimeInstants) {
|
Chris@17
|
225 return new SparseOneDimensionalModel(baseModel->getSampleRate(), 1);
|
Chris@17
|
226 } else if (layerType == TimeValues) {
|
Chris@17
|
227 return new SparseTimeValueModel(baseModel->getSampleRate(), 1,
|
Chris@17
|
228 0.0, 0.0, true);
|
Chris@30
|
229 } else if (layerType == Notes) {
|
Chris@30
|
230 return new NoteModel(baseModel->getSampleRate(), 1,
|
Chris@30
|
231 0.0, 0.0, true);
|
Chris@35
|
232 } else if (layerType == Text) {
|
Chris@35
|
233 return new TextModel(baseModel->getSampleRate(), 1, true);
|
Chris@17
|
234 } else {
|
Chris@17
|
235 return 0;
|
Chris@17
|
236 }
|
Chris@17
|
237 }
|
Chris@17
|
238
|
Chris@53
|
239 int
|
Chris@53
|
240 LayerFactory::getChannel(Layer *layer)
|
Chris@53
|
241 {
|
Chris@53
|
242 if (dynamic_cast<WaveformLayer *>(layer)) {
|
Chris@53
|
243 return dynamic_cast<WaveformLayer *>(layer)->getChannel();
|
Chris@53
|
244 }
|
Chris@53
|
245 if (dynamic_cast<SpectrogramLayer *>(layer)) {
|
Chris@53
|
246 return dynamic_cast<SpectrogramLayer *>(layer)->getChannel();
|
Chris@53
|
247 }
|
Chris@53
|
248 return -1;
|
Chris@53
|
249 }
|
Chris@53
|
250
|
Chris@53
|
251 void
|
Chris@53
|
252 LayerFactory::setChannel(Layer *layer, int channel)
|
Chris@53
|
253 {
|
Chris@53
|
254 if (dynamic_cast<WaveformLayer *>(layer)) {
|
Chris@53
|
255 dynamic_cast<WaveformLayer *>(layer)->setChannel(channel);
|
Chris@53
|
256 return;
|
Chris@53
|
257 }
|
Chris@53
|
258 if (dynamic_cast<SpectrogramLayer *>(layer)) {
|
Chris@53
|
259 dynamic_cast<SpectrogramLayer *>(layer)->setChannel(channel);
|
Chris@53
|
260 return;
|
Chris@53
|
261 }
|
Chris@53
|
262 }
|
Chris@53
|
263
|
Chris@0
|
264 Layer *
|
Chris@53
|
265 LayerFactory::createLayer(LayerType type)
|
Chris@0
|
266 {
|
Chris@0
|
267 Layer *layer = 0;
|
Chris@0
|
268
|
Chris@0
|
269 switch (type) {
|
Chris@0
|
270
|
Chris@0
|
271 case Waveform:
|
Chris@44
|
272 layer = new WaveformLayer;
|
Chris@0
|
273 break;
|
Chris@0
|
274
|
Chris@0
|
275 case Spectrogram:
|
Chris@44
|
276 layer = new SpectrogramLayer;
|
Chris@0
|
277 break;
|
Chris@0
|
278
|
Chris@0
|
279 case TimeRuler:
|
Chris@44
|
280 layer = new TimeRulerLayer;
|
Chris@0
|
281 break;
|
Chris@0
|
282
|
Chris@0
|
283 case TimeInstants:
|
Chris@44
|
284 layer = new TimeInstantLayer;
|
Chris@0
|
285 break;
|
Chris@0
|
286
|
Chris@0
|
287 case TimeValues:
|
Chris@44
|
288 layer = new TimeValueLayer;
|
Chris@0
|
289 break;
|
Chris@0
|
290
|
Chris@30
|
291 case Notes:
|
Chris@44
|
292 layer = new NoteLayer;
|
Chris@30
|
293 break;
|
Chris@30
|
294
|
Chris@35
|
295 case Text:
|
Chris@44
|
296 layer = new TextLayer;
|
Chris@35
|
297 break;
|
Chris@35
|
298
|
Chris@0
|
299 case Colour3DPlot:
|
Chris@44
|
300 layer = new Colour3DPlotLayer;
|
Chris@0
|
301 break;
|
Chris@0
|
302
|
Chris@0
|
303 case MelodicRangeSpectrogram:
|
Chris@44
|
304 layer = new SpectrogramLayer(SpectrogramLayer::MelodicRange);
|
Chris@0
|
305 break;
|
Chris@11
|
306
|
Chris@37
|
307 case PeakFrequencySpectrogram:
|
Chris@44
|
308 layer = new SpectrogramLayer(SpectrogramLayer::MelodicPeaks);
|
Chris@37
|
309 break;
|
Chris@37
|
310
|
Chris@11
|
311 default: break;
|
Chris@0
|
312 }
|
Chris@0
|
313
|
Chris@0
|
314 if (!layer) {
|
Chris@0
|
315 std::cerr << "LayerFactory::createLayer: Unknown layer type "
|
Chris@0
|
316 << type << std::endl;
|
Chris@0
|
317 } else {
|
Chris@101
|
318 // std::cerr << "LayerFactory::createLayer: Setting object name "
|
Chris@101
|
319 // << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl;
|
Chris@0
|
320 layer->setObjectName(getLayerPresentationName(type));
|
Chris@0
|
321 }
|
Chris@0
|
322
|
Chris@0
|
323 return layer;
|
Chris@0
|
324 }
|
Chris@0
|
325
|