Chris@0
|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 A waveform viewer and audio annotation editor.
|
Chris@5
|
5 Chris Cannam, Queen Mary University of London, 2005-2006
|
Chris@0
|
6
|
Chris@0
|
7 This is experimental software. Not for distribution.
|
Chris@0
|
8 */
|
Chris@0
|
9
|
Chris@0
|
10 #include "LayerFactory.h"
|
Chris@0
|
11
|
Chris@0
|
12 #include "WaveformLayer.h"
|
Chris@0
|
13 #include "SpectrogramLayer.h"
|
Chris@0
|
14 #include "TimeRulerLayer.h"
|
Chris@0
|
15 #include "TimeInstantLayer.h"
|
Chris@0
|
16 #include "TimeValueLayer.h"
|
Chris@0
|
17 #include "Colour3DPlotLayer.h"
|
Chris@0
|
18
|
Chris@0
|
19 #include "model/RangeSummarisableTimeValueModel.h"
|
Chris@0
|
20 #include "model/DenseTimeValueModel.h"
|
Chris@0
|
21 #include "model/SparseOneDimensionalModel.h"
|
Chris@0
|
22 #include "model/SparseTimeValueModel.h"
|
Chris@0
|
23 #include "model/DenseThreeDimensionalModel.h"
|
Chris@0
|
24
|
Chris@0
|
25 LayerFactory *
|
Chris@0
|
26 LayerFactory::m_instance = new LayerFactory;
|
Chris@0
|
27
|
Chris@0
|
28 LayerFactory *
|
Chris@0
|
29 LayerFactory::instance()
|
Chris@0
|
30 {
|
Chris@0
|
31 return m_instance;
|
Chris@0
|
32 }
|
Chris@0
|
33
|
Chris@0
|
34 LayerFactory::~LayerFactory()
|
Chris@0
|
35 {
|
Chris@0
|
36 }
|
Chris@0
|
37
|
Chris@0
|
38 QString
|
Chris@0
|
39 LayerFactory::getLayerPresentationName(LayerType type)
|
Chris@0
|
40 {
|
Chris@0
|
41 switch (type) {
|
Chris@0
|
42 case Waveform: return Layer::tr("Waveform");
|
Chris@0
|
43 case Spectrogram: return Layer::tr("Spectrogram");
|
Chris@0
|
44 case TimeRuler: return Layer::tr("Ruler");
|
Chris@0
|
45 case TimeInstants: return Layer::tr("Time Instants");
|
Chris@0
|
46 case TimeValues: return Layer::tr("Time Values");
|
Chris@0
|
47 case Colour3DPlot: return Layer::tr("Colour 3D Plot");
|
Chris@0
|
48
|
Chris@0
|
49 case MelodicRangeSpectrogram:
|
Chris@0
|
50 // The user can change all the parameters of this after the
|
Chris@0
|
51 // fact -- there's nothing permanently melodic-range about it
|
Chris@0
|
52 // that should be encoded in its name
|
Chris@0
|
53 return Layer::tr("Spectrogram");
|
Chris@0
|
54 }
|
Chris@0
|
55
|
Chris@0
|
56 return Layer::tr("Layer");
|
Chris@0
|
57 }
|
Chris@0
|
58
|
Chris@0
|
59 LayerFactory::LayerTypeSet
|
Chris@0
|
60 LayerFactory::getValidLayerTypes(Model *model)
|
Chris@0
|
61 {
|
Chris@0
|
62 LayerTypeSet types;
|
Chris@0
|
63
|
Chris@0
|
64 if (dynamic_cast<DenseThreeDimensionalModel *>(model)) {
|
Chris@0
|
65 types.insert(Colour3DPlot);
|
Chris@0
|
66 }
|
Chris@0
|
67
|
Chris@0
|
68 if (dynamic_cast<DenseTimeValueModel *>(model)) {
|
Chris@0
|
69 types.insert(Spectrogram);
|
Chris@0
|
70 types.insert(MelodicRangeSpectrogram);
|
Chris@0
|
71 }
|
Chris@0
|
72
|
Chris@0
|
73 if (dynamic_cast<RangeSummarisableTimeValueModel *>(model)) {
|
Chris@0
|
74 types.insert(Waveform);
|
Chris@0
|
75 }
|
Chris@0
|
76
|
Chris@0
|
77 if (dynamic_cast<SparseOneDimensionalModel *>(model)) {
|
Chris@0
|
78 types.insert(TimeInstants);
|
Chris@0
|
79 }
|
Chris@0
|
80
|
Chris@0
|
81 if (dynamic_cast<SparseTimeValueModel *>(model)) {
|
Chris@0
|
82 types.insert(TimeValues);
|
Chris@0
|
83 }
|
Chris@0
|
84
|
Chris@0
|
85 // We don't count TimeRuler here as it doesn't actually display
|
Chris@0
|
86 // the data, although it can be backed by any model
|
Chris@0
|
87
|
Chris@0
|
88 return types;
|
Chris@0
|
89 }
|
Chris@0
|
90
|
Chris@0
|
91 LayerFactory::LayerType
|
Chris@6
|
92 LayerFactory::getLayerType(const Layer *layer)
|
Chris@0
|
93 {
|
Chris@6
|
94 if (dynamic_cast<const WaveformLayer *>(layer)) return Waveform;
|
Chris@6
|
95 if (dynamic_cast<const SpectrogramLayer *>(layer)) return Spectrogram;
|
Chris@6
|
96 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler;
|
Chris@6
|
97 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants;
|
Chris@6
|
98 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues;
|
Chris@6
|
99 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot;
|
Chris@6
|
100 return UnknownLayer;
|
Chris@6
|
101 }
|
Chris@6
|
102
|
Chris@6
|
103 QString
|
Chris@6
|
104 LayerFactory::getLayerTypeName(LayerType type)
|
Chris@6
|
105 {
|
Chris@6
|
106 switch (type) {
|
Chris@6
|
107 case Waveform: return "waveform";
|
Chris@6
|
108 case Spectrogram: return "spectrogram";
|
Chris@6
|
109 case TimeRuler: return "timeruler";
|
Chris@6
|
110 case TimeInstants: return "timeinstants";
|
Chris@6
|
111 case TimeValues: return "timevalues";
|
Chris@6
|
112 case Colour3DPlot: return "colour3dplot";
|
Chris@6
|
113 default: return "unknown";
|
Chris@6
|
114 }
|
Chris@6
|
115 }
|
Chris@6
|
116
|
Chris@6
|
117 LayerFactory::LayerType
|
Chris@6
|
118 LayerFactory::getLayerTypeForName(QString name)
|
Chris@6
|
119 {
|
Chris@6
|
120 if (name == "waveform") return Waveform;
|
Chris@6
|
121 if (name == "spectrogram") return Spectrogram;
|
Chris@6
|
122 if (name == "timeruler") return TimeRuler;
|
Chris@6
|
123 if (name == "timeinstants") return TimeInstants;
|
Chris@6
|
124 if (name == "timevalues") return TimeValues;
|
Chris@6
|
125 if (name == "colour3dplot") return Colour3DPlot;
|
Chris@0
|
126 return UnknownLayer;
|
Chris@0
|
127 }
|
Chris@0
|
128
|
Chris@0
|
129 void
|
Chris@0
|
130 LayerFactory::setModel(Layer *layer, Model *model)
|
Chris@0
|
131 {
|
Chris@0
|
132 if (trySetModel<WaveformLayer, RangeSummarisableTimeValueModel>(layer, model))
|
Chris@0
|
133 return;
|
Chris@0
|
134
|
Chris@0
|
135 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
|
Chris@0
|
136 return;
|
Chris@0
|
137
|
Chris@0
|
138 if (trySetModel<TimeRulerLayer, Model>(layer, model))
|
Chris@0
|
139 return;
|
Chris@0
|
140
|
Chris@0
|
141 if (trySetModel<TimeInstantLayer, SparseOneDimensionalModel>(layer, model))
|
Chris@0
|
142 return;
|
Chris@0
|
143
|
Chris@0
|
144 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model))
|
Chris@0
|
145 return;
|
Chris@0
|
146
|
Chris@0
|
147 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model))
|
Chris@0
|
148 return;
|
Chris@0
|
149
|
Chris@0
|
150 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
|
Chris@0
|
151 return;
|
Chris@0
|
152 }
|
Chris@0
|
153
|
Chris@0
|
154 Layer *
|
Chris@0
|
155 LayerFactory::createLayer(LayerType type, View *view,
|
Chris@0
|
156 Model *model, int channel)
|
Chris@0
|
157 {
|
Chris@0
|
158 Layer *layer = 0;
|
Chris@0
|
159
|
Chris@0
|
160 switch (type) {
|
Chris@0
|
161
|
Chris@0
|
162 case Waveform:
|
Chris@0
|
163 layer = new WaveformLayer(view);
|
Chris@0
|
164 static_cast<WaveformLayer *>(layer)->setChannel(channel);
|
Chris@0
|
165 break;
|
Chris@0
|
166
|
Chris@0
|
167 case Spectrogram:
|
Chris@0
|
168 layer = new SpectrogramLayer(view);
|
Chris@0
|
169 static_cast<SpectrogramLayer *>(layer)->setChannel(channel);
|
Chris@0
|
170 break;
|
Chris@0
|
171
|
Chris@0
|
172 case TimeRuler:
|
Chris@0
|
173 layer = new TimeRulerLayer(view);
|
Chris@0
|
174 break;
|
Chris@0
|
175
|
Chris@0
|
176 case TimeInstants:
|
Chris@0
|
177 layer = new TimeInstantLayer(view);
|
Chris@0
|
178 break;
|
Chris@0
|
179
|
Chris@0
|
180 case TimeValues:
|
Chris@0
|
181 layer = new TimeValueLayer(view);
|
Chris@0
|
182 break;
|
Chris@0
|
183
|
Chris@0
|
184 case Colour3DPlot:
|
Chris@0
|
185 layer = new Colour3DPlotLayer(view);
|
Chris@0
|
186 break;
|
Chris@0
|
187
|
Chris@0
|
188 case MelodicRangeSpectrogram:
|
Chris@0
|
189 layer = new SpectrogramLayer(view, SpectrogramLayer::MelodicRange);
|
Chris@0
|
190 static_cast<SpectrogramLayer *>(layer)->setChannel(channel);
|
Chris@0
|
191 break;
|
Chris@0
|
192 }
|
Chris@0
|
193
|
Chris@0
|
194 if (!layer) {
|
Chris@0
|
195 std::cerr << "LayerFactory::createLayer: Unknown layer type "
|
Chris@0
|
196 << type << std::endl;
|
Chris@0
|
197 } else {
|
Chris@0
|
198 setModel(layer, model);
|
Chris@0
|
199 std::cerr << "LayerFactory::createLayer: Setting object name "
|
Chris@0
|
200 << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl;
|
Chris@0
|
201 layer->setObjectName(getLayerPresentationName(type));
|
Chris@0
|
202 }
|
Chris@0
|
203
|
Chris@0
|
204 return layer;
|
Chris@0
|
205 }
|
Chris@0
|
206
|