comparison layer/LayerFactory.cpp @ 30:ea6fe8cfcdd5

* Add the Note layer for pianoroll-type display of note-type data * Complete the MIDI file importer (well, nearly -- it would be nice to be able to import the non-note data as other sorts of models, and that's not done yet). * Minor refactoring in RealTime etc
author Chris Cannam
date Fri, 10 Feb 2006 17:51:36 +0000
parents 0183ebb725ca
children 10ba9276a315
comparison
equal deleted inserted replaced
29:9f55af9676b4 30:ea6fe8cfcdd5
12 #include "WaveformLayer.h" 12 #include "WaveformLayer.h"
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 "Colour3DPlotLayer.h" 18 #include "Colour3DPlotLayer.h"
18 19
19 #include "model/RangeSummarisableTimeValueModel.h" 20 #include "model/RangeSummarisableTimeValueModel.h"
20 #include "model/DenseTimeValueModel.h" 21 #include "model/DenseTimeValueModel.h"
21 #include "model/SparseOneDimensionalModel.h" 22 #include "model/SparseOneDimensionalModel.h"
22 #include "model/SparseTimeValueModel.h" 23 #include "model/SparseTimeValueModel.h"
24 #include "model/NoteModel.h"
23 #include "model/DenseThreeDimensionalModel.h" 25 #include "model/DenseThreeDimensionalModel.h"
24 26
25 LayerFactory * 27 LayerFactory *
26 LayerFactory::m_instance = new LayerFactory; 28 LayerFactory::m_instance = new LayerFactory;
27 29
42 case Waveform: return Layer::tr("Waveform"); 44 case Waveform: return Layer::tr("Waveform");
43 case Spectrogram: return Layer::tr("Spectrogram"); 45 case Spectrogram: return Layer::tr("Spectrogram");
44 case TimeRuler: return Layer::tr("Ruler"); 46 case TimeRuler: return Layer::tr("Ruler");
45 case TimeInstants: return Layer::tr("Time Instants"); 47 case TimeInstants: return Layer::tr("Time Instants");
46 case TimeValues: return Layer::tr("Time Values"); 48 case TimeValues: return Layer::tr("Time Values");
49 case Notes: return Layer::tr("Notes");
47 case Colour3DPlot: return Layer::tr("Colour 3D Plot"); 50 case Colour3DPlot: return Layer::tr("Colour 3D Plot");
48 51
49 case MelodicRangeSpectrogram: 52 case MelodicRangeSpectrogram:
50 // The user can change all the parameters of this after the 53 // The user can change all the parameters of this after the
51 // fact -- there's nothing permanently melodic-range about it 54 // fact -- there's nothing permanently melodic-range about it
82 85
83 if (dynamic_cast<SparseTimeValueModel *>(model)) { 86 if (dynamic_cast<SparseTimeValueModel *>(model)) {
84 types.insert(TimeValues); 87 types.insert(TimeValues);
85 } 88 }
86 89
90 if (dynamic_cast<NoteModel *>(model)) {
91 types.insert(Notes);
92 }
93
87 // We don't count TimeRuler here as it doesn't actually display 94 // We don't count TimeRuler here as it doesn't actually display
88 // the data, although it can be backed by any model 95 // the data, although it can be backed by any model
89 96
90 return types; 97 return types;
91 } 98 }
94 LayerFactory::getValidEmptyLayerTypes() 101 LayerFactory::getValidEmptyLayerTypes()
95 { 102 {
96 LayerTypeSet types; 103 LayerTypeSet types;
97 types.insert(TimeInstants); 104 types.insert(TimeInstants);
98 types.insert(TimeValues); 105 types.insert(TimeValues);
106 types.insert(Notes);
99 //!!! and in principle Colour3DPlot -- now that's a challenge 107 //!!! and in principle Colour3DPlot -- now that's a challenge
100 return types; 108 return types;
101 } 109 }
102 110
103 LayerFactory::LayerType 111 LayerFactory::LayerType
106 if (dynamic_cast<const WaveformLayer *>(layer)) return Waveform; 114 if (dynamic_cast<const WaveformLayer *>(layer)) return Waveform;
107 if (dynamic_cast<const SpectrogramLayer *>(layer)) return Spectrogram; 115 if (dynamic_cast<const SpectrogramLayer *>(layer)) return Spectrogram;
108 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler; 116 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler;
109 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants; 117 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants;
110 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues; 118 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues;
119 if (dynamic_cast<const NoteLayer *>(layer)) return Notes;
111 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot; 120 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot;
112 return UnknownLayer; 121 return UnknownLayer;
113 } 122 }
114 123
115 QString 124 QString
119 case Waveform: return "waveform"; 128 case Waveform: return "waveform";
120 case Spectrogram: return "spectrogram"; 129 case Spectrogram: return "spectrogram";
121 case TimeRuler: return "timeruler"; 130 case TimeRuler: return "timeruler";
122 case TimeInstants: return "instants"; 131 case TimeInstants: return "instants";
123 case TimeValues: return "values"; 132 case TimeValues: return "values";
133 case Notes: return "notes";
124 case Colour3DPlot: return "colour3d"; 134 case Colour3DPlot: return "colour3d";
125 default: return "unknown"; 135 default: return "unknown";
126 } 136 }
127 } 137 }
128 138
133 case Waveform: return "waveform"; 143 case Waveform: return "waveform";
134 case Spectrogram: return "spectrogram"; 144 case Spectrogram: return "spectrogram";
135 case TimeRuler: return "timeruler"; 145 case TimeRuler: return "timeruler";
136 case TimeInstants: return "timeinstants"; 146 case TimeInstants: return "timeinstants";
137 case TimeValues: return "timevalues"; 147 case TimeValues: return "timevalues";
148 case Notes: return "notes";
138 case Colour3DPlot: return "colour3dplot"; 149 case Colour3DPlot: return "colour3dplot";
139 default: return "unknown"; 150 default: return "unknown";
140 } 151 }
141 } 152 }
142 153
146 if (name == "waveform") return Waveform; 157 if (name == "waveform") return Waveform;
147 if (name == "spectrogram") return Spectrogram; 158 if (name == "spectrogram") return Spectrogram;
148 if (name == "timeruler") return TimeRuler; 159 if (name == "timeruler") return TimeRuler;
149 if (name == "timeinstants") return TimeInstants; 160 if (name == "timeinstants") return TimeInstants;
150 if (name == "timevalues") return TimeValues; 161 if (name == "timevalues") return TimeValues;
162 if (name == "notes") return Notes;
151 if (name == "colour3dplot") return Colour3DPlot; 163 if (name == "colour3dplot") return Colour3DPlot;
152 return UnknownLayer; 164 return UnknownLayer;
153 } 165 }
154 166
155 void 167 void
166 178
167 if (trySetModel<TimeInstantLayer, SparseOneDimensionalModel>(layer, model)) 179 if (trySetModel<TimeInstantLayer, SparseOneDimensionalModel>(layer, model))
168 return; 180 return;
169 181
170 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model)) 182 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model))
183 return;
184
185 if (trySetModel<NoteLayer, NoteModel>(layer, model))
171 return; 186 return;
172 187
173 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model)) 188 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model))
174 return; 189 return;
175 190
183 if (layerType == TimeInstants) { 198 if (layerType == TimeInstants) {
184 return new SparseOneDimensionalModel(baseModel->getSampleRate(), 1); 199 return new SparseOneDimensionalModel(baseModel->getSampleRate(), 1);
185 } else if (layerType == TimeValues) { 200 } else if (layerType == TimeValues) {
186 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, 201 return new SparseTimeValueModel(baseModel->getSampleRate(), 1,
187 0.0, 0.0, true); 202 0.0, 0.0, true);
203 } else if (layerType == Notes) {
204 return new NoteModel(baseModel->getSampleRate(), 1,
205 0.0, 0.0, true);
188 } else { 206 } else {
189 return 0; 207 return 0;
190 } 208 }
191 } 209 }
192 210
216 layer = new TimeInstantLayer(view); 234 layer = new TimeInstantLayer(view);
217 break; 235 break;
218 236
219 case TimeValues: 237 case TimeValues:
220 layer = new TimeValueLayer(view); 238 layer = new TimeValueLayer(view);
239 break;
240
241 case Notes:
242 layer = new NoteLayer(view);
221 break; 243 break;
222 244
223 case Colour3DPlot: 245 case Colour3DPlot:
224 layer = new Colour3DPlotLayer(view); 246 layer = new Colour3DPlotLayer(view);
225 break; 247 break;