comparison src/Analyser.cpp @ 260:46d59edfd18a

Much fiddling toward getting sessions and individual audio files to load cleanly when they need quite different handling after load
author Chris Cannam
date Wed, 02 Apr 2014 21:25:56 +0100
parents f99fae5fe89c
children df9861755e33
comparison
equal deleted inserted replaced
259:fa329ca6d75e 260:46d59edfd18a
87 // waveform or what have you). It could be hidden if we don't want 87 // waveform or what have you). It could be hidden if we don't want
88 // to see it but it must exist. 88 // to see it but it must exist.
89 89
90 QString warning, error; 90 QString warning, error;
91 91
92 cerr << "Analyser::newFileLoaded: about to check visualisations etc" << endl;
93
92 // This isn't fatal -- we can proceed without 94 // This isn't fatal -- we can proceed without
93 // visualisations. Other failures are fatal though. 95 // visualisations. Other failures are fatal though.
94 warning = addVisualisations(); 96 warning = addVisualisations();
95 97
96 error = addWaveform(); 98 error = addWaveform();
101 103
102 loadState(Audio); 104 loadState(Audio);
103 loadState(PitchTrack); 105 loadState(PitchTrack);
104 loadState(Notes); 106 loadState(Notes);
105 loadState(Spectrogram); 107 loadState(Spectrogram);
108
109 stackLayers();
106 110
107 emit layersChanged(); 111 emit layersChanged();
108 112
109 return warning; 113 return warning;
110 } 114 }
162 (m_document->createDerivedLayer(transform, m_fileModel)); 166 (m_document->createDerivedLayer(transform, m_fileModel));
163 167
164 if (!spectrogram) return tr("Transform \"%1\" did not run correctly (no layer or wrong layer type returned)").arg(base + out); 168 if (!spectrogram) return tr("Transform \"%1\" did not run correctly (no layer or wrong layer type returned)").arg(base + out);
165 */ 169 */
166 170
171 // As with all the visualisation layers, if we already have one in
172 // the pane we do not create another, just record its
173 // existence. (We create a new one when loading a new audio file,
174 // but just note the existing one when loading a complete session.)
175
176 for (int i = 0; i < m_pane->getLayerCount(); ++i) {
177 SpectrogramLayer *existing = qobject_cast<SpectrogramLayer *>
178 (m_pane->getLayer(i));
179 if (existing) {
180 cerr << "recording existing spectrogram layer" << endl;
181 m_layers[Spectrogram] = existing;
182 return "";
183 }
184 }
185
167 SpectrogramLayer *spectrogram = qobject_cast<SpectrogramLayer *> 186 SpectrogramLayer *spectrogram = qobject_cast<SpectrogramLayer *>
168 (m_document->createMainModelLayer(LayerFactory::MelodicRangeSpectrogram)); 187 (m_document->createMainModelLayer(LayerFactory::MelodicRangeSpectrogram));
169 188
170 spectrogram->setColourMap((int)ColourMapper::BlackOnWhite); 189 spectrogram->setColourMap((int)ColourMapper::BlackOnWhite);
171 spectrogram->setNormalizeHybrid(true); 190 spectrogram->setNormalizeHybrid(true);
180 199
181 QString 200 QString
182 Analyser::addWaveform() 201 Analyser::addWaveform()
183 { 202 {
184 // Our waveform layer is just a shadow, light grey and taking up 203 // Our waveform layer is just a shadow, light grey and taking up
185 // little space at the bottom 204 // little space at the bottom.
205
206 // As with the spectrogram above, if one exists already we just
207 // use it
208 for (int i = 0; i < m_pane->getLayerCount(); ++i) {
209 WaveformLayer *existing = qobject_cast<WaveformLayer *>
210 (m_pane->getLayer(i));
211 if (existing) {
212 cerr << "recording existing waveform layer" << endl;
213 m_layers[Audio] = existing;
214 return "";
215 }
216 }
186 217
187 WaveformLayer *waveform = qobject_cast<WaveformLayer *> 218 WaveformLayer *waveform = qobject_cast<WaveformLayer *>
188 (m_document->createMainModelLayer(LayerFactory::Waveform)); 219 (m_document->createMainModelLayer(LayerFactory::Waveform));
189 220
190 waveform->setMiddleLineHeight(0.9); 221 waveform->setMiddleLineHeight(0.9);
201 } 232 }
202 233
203 QString 234 QString
204 Analyser::addAnalyses() 235 Analyser::addAnalyses()
205 { 236 {
237 // As with the spectrogram above, if these layers exist we use
238 // them
239 TimeValueLayer *existingPitch = 0;
240 FlexiNoteLayer *existingNotes = 0;
241 for (int i = 0; i < m_pane->getLayerCount(); ++i) {
242 if (!existingPitch) {
243 existingPitch = qobject_cast<TimeValueLayer *>(m_pane->getLayer(i));
244 }
245 if (!existingNotes) {
246 existingNotes = qobject_cast<FlexiNoteLayer *>(m_pane->getLayer(i));
247 }
248 }
249 if (existingPitch && existingNotes) {
250 cerr << "recording existing pitch and notes layers" << endl;
251 m_layers[PitchTrack] = existingPitch;
252 m_layers[Notes] = existingNotes;
253 return "";
254 } else if (existingPitch || existingNotes) {
255 return "One (but not both) of pitch and note track found in session";
256 }
257
206 TransformFactory *tf = TransformFactory::getInstance(); 258 TransformFactory *tf = TransformFactory::getInstance();
207 259
208 QString plugname = "pYIN"; 260 QString plugname = "pYIN";
209 QString base = "vamp:pyin:pyin:"; 261 QString base = "vamp:pyin:pyin:";
210 QString f0out = "smoothedpitchtrack"; 262 QString f0out = "smoothedpitchtrack";
482 534
483 Clipboard clip; 535 Clipboard clip;
484 pitchTrack->deleteSelection(sel); 536 pitchTrack->deleteSelection(sel);
485 m_reAnalysisCandidates[m_currentCandidate]->copy(m_pane, sel, clip); 537 m_reAnalysisCandidates[m_currentCandidate]->copy(m_pane, sel, clip);
486 pitchTrack->paste(m_pane, clip, 0, false); 538 pitchTrack->paste(m_pane, clip, 0, false);
487 539 }
540
541 void
542 Analyser::stackLayers()
543 {
488 // raise the pitch track, then notes on top (if present) 544 // raise the pitch track, then notes on top (if present)
489 m_paneStack->setCurrentLayer(m_pane, m_layers[PitchTrack]); 545 if (m_layers[PitchTrack]) {
546 m_paneStack->setCurrentLayer(m_pane, m_layers[PitchTrack]);
547 }
490 if (m_layers[Notes] && !m_layers[Notes]->isLayerDormant(m_pane)) { 548 if (m_layers[Notes] && !m_layers[Notes]->isLayerDormant(m_pane)) {
491 m_paneStack->setCurrentLayer(m_pane, m_layers[Notes]); 549 m_paneStack->setCurrentLayer(m_pane, m_layers[Notes]);
492 } 550 }
493 } 551 }
494 552