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