comparison layer/LayerFactory.cpp @ 35:10ba9276a315

* Add TextModel and TextLayer types * Make View refresh work better when editing a model (previously edits might not be refreshed if their visible changed area extended beyond the strict frame range that was being modified in the model) * Add phase-adjusted instantaneous frequency display to spectrogram layer (still a work in progress) * Pull maths aliases out into a separate header in dsp/maths so MathUtilities can be included without introducing them
author Chris Cannam
date Mon, 20 Feb 2006 13:33:36 +0000
parents ea6fe8cfcdd5
children 21d061e66177
comparison
equal deleted inserted replaced
34:c43f2c4f66f2 35:10ba9276a315
13 #include "SpectrogramLayer.h" 13 #include "SpectrogramLayer.h"
14 #include "TimeRulerLayer.h" 14 #include "TimeRulerLayer.h"
15 #include "TimeInstantLayer.h" 15 #include "TimeInstantLayer.h"
16 #include "TimeValueLayer.h" 16 #include "TimeValueLayer.h"
17 #include "NoteLayer.h" 17 #include "NoteLayer.h"
18 #include "TextLayer.h"
18 #include "Colour3DPlotLayer.h" 19 #include "Colour3DPlotLayer.h"
19 20
20 #include "model/RangeSummarisableTimeValueModel.h" 21 #include "model/RangeSummarisableTimeValueModel.h"
21 #include "model/DenseTimeValueModel.h" 22 #include "model/DenseTimeValueModel.h"
22 #include "model/SparseOneDimensionalModel.h" 23 #include "model/SparseOneDimensionalModel.h"
23 #include "model/SparseTimeValueModel.h" 24 #include "model/SparseTimeValueModel.h"
24 #include "model/NoteModel.h" 25 #include "model/NoteModel.h"
26 #include "model/TextModel.h"
25 #include "model/DenseThreeDimensionalModel.h" 27 #include "model/DenseThreeDimensionalModel.h"
26 28
27 LayerFactory * 29 LayerFactory *
28 LayerFactory::m_instance = new LayerFactory; 30 LayerFactory::m_instance = new LayerFactory;
29 31
45 case Spectrogram: return Layer::tr("Spectrogram"); 47 case Spectrogram: return Layer::tr("Spectrogram");
46 case TimeRuler: return Layer::tr("Ruler"); 48 case TimeRuler: return Layer::tr("Ruler");
47 case TimeInstants: return Layer::tr("Time Instants"); 49 case TimeInstants: return Layer::tr("Time Instants");
48 case TimeValues: return Layer::tr("Time Values"); 50 case TimeValues: return Layer::tr("Time Values");
49 case Notes: return Layer::tr("Notes"); 51 case Notes: return Layer::tr("Notes");
52 case Text: return Layer::tr("Text");
50 case Colour3DPlot: return Layer::tr("Colour 3D Plot"); 53 case Colour3DPlot: return Layer::tr("Colour 3D Plot");
51 54
52 case MelodicRangeSpectrogram: 55 case MelodicRangeSpectrogram:
53 // The user can change all the parameters of this after the 56 // The user can change all the parameters of this after the
54 // fact -- there's nothing permanently melodic-range about it 57 // fact -- there's nothing permanently melodic-range about it
83 types.insert(TimeInstants); 86 types.insert(TimeInstants);
84 } 87 }
85 88
86 if (dynamic_cast<SparseTimeValueModel *>(model)) { 89 if (dynamic_cast<SparseTimeValueModel *>(model)) {
87 types.insert(TimeValues); 90 types.insert(TimeValues);
88 } 91
89 92 }
90 if (dynamic_cast<NoteModel *>(model)) { 93 if (dynamic_cast<NoteModel *>(model)) {
91 types.insert(Notes); 94 types.insert(Notes);
95 }
96
97 if (dynamic_cast<TextModel *>(model)) {
98 types.insert(Text);
92 } 99 }
93 100
94 // We don't count TimeRuler here as it doesn't actually display 101 // We don't count TimeRuler here as it doesn't actually display
95 // the data, although it can be backed by any model 102 // the data, although it can be backed by any model
96 103
102 { 109 {
103 LayerTypeSet types; 110 LayerTypeSet types;
104 types.insert(TimeInstants); 111 types.insert(TimeInstants);
105 types.insert(TimeValues); 112 types.insert(TimeValues);
106 types.insert(Notes); 113 types.insert(Notes);
114 types.insert(Text);
107 //!!! and in principle Colour3DPlot -- now that's a challenge 115 //!!! and in principle Colour3DPlot -- now that's a challenge
108 return types; 116 return types;
109 } 117 }
110 118
111 LayerFactory::LayerType 119 LayerFactory::LayerType
115 if (dynamic_cast<const SpectrogramLayer *>(layer)) return Spectrogram; 123 if (dynamic_cast<const SpectrogramLayer *>(layer)) return Spectrogram;
116 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler; 124 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler;
117 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants; 125 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants;
118 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues; 126 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues;
119 if (dynamic_cast<const NoteLayer *>(layer)) return Notes; 127 if (dynamic_cast<const NoteLayer *>(layer)) return Notes;
128 if (dynamic_cast<const TextLayer *>(layer)) return Text;
120 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot; 129 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot;
121 return UnknownLayer; 130 return UnknownLayer;
122 } 131 }
123 132
124 QString 133 QString
129 case Spectrogram: return "spectrogram"; 138 case Spectrogram: return "spectrogram";
130 case TimeRuler: return "timeruler"; 139 case TimeRuler: return "timeruler";
131 case TimeInstants: return "instants"; 140 case TimeInstants: return "instants";
132 case TimeValues: return "values"; 141 case TimeValues: return "values";
133 case Notes: return "notes"; 142 case Notes: return "notes";
143 case Text: return "text";
134 case Colour3DPlot: return "colour3d"; 144 case Colour3DPlot: return "colour3d";
135 default: return "unknown"; 145 default: return "unknown";
136 } 146 }
137 } 147 }
138 148
144 case Spectrogram: return "spectrogram"; 154 case Spectrogram: return "spectrogram";
145 case TimeRuler: return "timeruler"; 155 case TimeRuler: return "timeruler";
146 case TimeInstants: return "timeinstants"; 156 case TimeInstants: return "timeinstants";
147 case TimeValues: return "timevalues"; 157 case TimeValues: return "timevalues";
148 case Notes: return "notes"; 158 case Notes: return "notes";
159 case Text: return "text";
149 case Colour3DPlot: return "colour3dplot"; 160 case Colour3DPlot: return "colour3dplot";
150 default: return "unknown"; 161 default: return "unknown";
151 } 162 }
152 } 163 }
153 164
158 if (name == "spectrogram") return Spectrogram; 169 if (name == "spectrogram") return Spectrogram;
159 if (name == "timeruler") return TimeRuler; 170 if (name == "timeruler") return TimeRuler;
160 if (name == "timeinstants") return TimeInstants; 171 if (name == "timeinstants") return TimeInstants;
161 if (name == "timevalues") return TimeValues; 172 if (name == "timevalues") return TimeValues;
162 if (name == "notes") return Notes; 173 if (name == "notes") return Notes;
174 if (name == "text") return Text;
163 if (name == "colour3dplot") return Colour3DPlot; 175 if (name == "colour3dplot") return Colour3DPlot;
164 return UnknownLayer; 176 return UnknownLayer;
165 } 177 }
166 178
167 void 179 void
181 193
182 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model)) 194 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model))
183 return; 195 return;
184 196
185 if (trySetModel<NoteLayer, NoteModel>(layer, model)) 197 if (trySetModel<NoteLayer, NoteModel>(layer, model))
198 return;
199
200 if (trySetModel<TextLayer, TextModel>(layer, model))
186 return; 201 return;
187 202
188 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model)) 203 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model))
189 return; 204 return;
190 205
201 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, 216 return new SparseTimeValueModel(baseModel->getSampleRate(), 1,
202 0.0, 0.0, true); 217 0.0, 0.0, true);
203 } else if (layerType == Notes) { 218 } else if (layerType == Notes) {
204 return new NoteModel(baseModel->getSampleRate(), 1, 219 return new NoteModel(baseModel->getSampleRate(), 1,
205 0.0, 0.0, true); 220 0.0, 0.0, true);
221 } else if (layerType == Text) {
222 return new TextModel(baseModel->getSampleRate(), 1, true);
206 } else { 223 } else {
207 return 0; 224 return 0;
208 } 225 }
209 } 226 }
210 227
238 layer = new TimeValueLayer(view); 255 layer = new TimeValueLayer(view);
239 break; 256 break;
240 257
241 case Notes: 258 case Notes:
242 layer = new NoteLayer(view); 259 layer = new NoteLayer(view);
260 break;
261
262 case Text:
263 layer = new TextLayer(view);
243 break; 264 break;
244 265
245 case Colour3DPlot: 266 case Colour3DPlot:
246 layer = new Colour3DPlotLayer(view); 267 layer = new Colour3DPlotLayer(view);
247 break; 268 break;