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@0
|
5 Chris Cannam, Queen Mary University of London, 2005
|
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@0
|
92 LayerFactory::getLayerType(Layer *layer)
|
Chris@0
|
93 {
|
Chris@0
|
94 if (dynamic_cast<WaveformLayer *>(layer)) return Waveform;
|
Chris@0
|
95 if (dynamic_cast<SpectrogramLayer *>(layer)) return Spectrogram;
|
Chris@0
|
96 if (dynamic_cast<TimeRulerLayer *>(layer)) return TimeRuler;
|
Chris@0
|
97 if (dynamic_cast<TimeInstantLayer *>(layer)) return TimeInstants;
|
Chris@0
|
98 if (dynamic_cast<TimeValueLayer *>(layer)) return TimeValues;
|
Chris@0
|
99 if (dynamic_cast<Colour3DPlotLayer *>(layer)) return Colour3DPlot;
|
Chris@0
|
100 return UnknownLayer;
|
Chris@0
|
101 }
|
Chris@0
|
102
|
Chris@0
|
103 void
|
Chris@0
|
104 LayerFactory::setModel(Layer *layer, Model *model)
|
Chris@0
|
105 {
|
Chris@0
|
106 if (trySetModel<WaveformLayer, RangeSummarisableTimeValueModel>(layer, model))
|
Chris@0
|
107 return;
|
Chris@0
|
108
|
Chris@0
|
109 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
|
Chris@0
|
110 return;
|
Chris@0
|
111
|
Chris@0
|
112 if (trySetModel<TimeRulerLayer, Model>(layer, model))
|
Chris@0
|
113 return;
|
Chris@0
|
114
|
Chris@0
|
115 if (trySetModel<TimeInstantLayer, SparseOneDimensionalModel>(layer, model))
|
Chris@0
|
116 return;
|
Chris@0
|
117
|
Chris@0
|
118 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model))
|
Chris@0
|
119 return;
|
Chris@0
|
120
|
Chris@0
|
121 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model))
|
Chris@0
|
122 return;
|
Chris@0
|
123
|
Chris@0
|
124 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
|
Chris@0
|
125 return;
|
Chris@0
|
126 }
|
Chris@0
|
127
|
Chris@0
|
128 Layer *
|
Chris@0
|
129 LayerFactory::createLayer(LayerType type, View *view,
|
Chris@0
|
130 Model *model, int channel)
|
Chris@0
|
131 {
|
Chris@0
|
132 Layer *layer = 0;
|
Chris@0
|
133
|
Chris@0
|
134 switch (type) {
|
Chris@0
|
135
|
Chris@0
|
136 case Waveform:
|
Chris@0
|
137 layer = new WaveformLayer(view);
|
Chris@0
|
138 static_cast<WaveformLayer *>(layer)->setChannel(channel);
|
Chris@0
|
139 break;
|
Chris@0
|
140
|
Chris@0
|
141 case Spectrogram:
|
Chris@0
|
142 layer = new SpectrogramLayer(view);
|
Chris@0
|
143 static_cast<SpectrogramLayer *>(layer)->setChannel(channel);
|
Chris@0
|
144 break;
|
Chris@0
|
145
|
Chris@0
|
146 case TimeRuler:
|
Chris@0
|
147 layer = new TimeRulerLayer(view);
|
Chris@0
|
148 break;
|
Chris@0
|
149
|
Chris@0
|
150 case TimeInstants:
|
Chris@0
|
151 layer = new TimeInstantLayer(view);
|
Chris@0
|
152 break;
|
Chris@0
|
153
|
Chris@0
|
154 case TimeValues:
|
Chris@0
|
155 layer = new TimeValueLayer(view);
|
Chris@0
|
156 break;
|
Chris@0
|
157
|
Chris@0
|
158 case Colour3DPlot:
|
Chris@0
|
159 layer = new Colour3DPlotLayer(view);
|
Chris@0
|
160 break;
|
Chris@0
|
161
|
Chris@0
|
162 case MelodicRangeSpectrogram:
|
Chris@0
|
163 layer = new SpectrogramLayer(view, SpectrogramLayer::MelodicRange);
|
Chris@0
|
164 static_cast<SpectrogramLayer *>(layer)->setChannel(channel);
|
Chris@0
|
165 break;
|
Chris@0
|
166 }
|
Chris@0
|
167
|
Chris@0
|
168 if (!layer) {
|
Chris@0
|
169 std::cerr << "LayerFactory::createLayer: Unknown layer type "
|
Chris@0
|
170 << type << std::endl;
|
Chris@0
|
171 } else {
|
Chris@0
|
172 setModel(layer, model);
|
Chris@0
|
173 std::cerr << "LayerFactory::createLayer: Setting object name "
|
Chris@0
|
174 << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl;
|
Chris@0
|
175 layer->setObjectName(getLayerPresentationName(type));
|
Chris@0
|
176 }
|
Chris@0
|
177
|
Chris@0
|
178 return layer;
|
Chris@0
|
179 }
|
Chris@0
|
180
|