Mercurial > hg > tony
changeset 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 | fa329ca6d75e |
children | 0265b8df0427 |
files | .hgsubstate src/Analyser.cpp src/Analyser.h src/MainWindow.cpp src/MainWindow.h |
diffstat | 5 files changed, 88 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgsubstate Wed Apr 02 18:22:41 2014 +0100 +++ b/.hgsubstate Wed Apr 02 21:25:56 2014 +0100 @@ -2,6 +2,6 @@ 236814e07bd07473958c1ff89103124536a0c3c8 dataquay e291f3657872db892f6ee525b36e98472a5ccd26 pyin 27d4e7152c954bf3c4387319db088fb3cd02436b sv-dependency-builds -93cf23bfa1cba443d912716dcf6c20448b0b868d svapp +4eccff14b4d8766b461d126b5bad88e435483677 svapp 8db820ad2b8f4f15b80e103d681f5a66c90983de svcore d0fd7630d32f38e816a9147acf7295f812bee1e1 svgui
--- a/src/Analyser.cpp Wed Apr 02 18:22:41 2014 +0100 +++ b/src/Analyser.cpp Wed Apr 02 21:25:56 2014 +0100 @@ -89,6 +89,8 @@ QString warning, error; + cerr << "Analyser::newFileLoaded: about to check visualisations etc" << endl; + // This isn't fatal -- we can proceed without // visualisations. Other failures are fatal though. warning = addVisualisations(); @@ -104,6 +106,8 @@ loadState(Notes); loadState(Spectrogram); + stackLayers(); + emit layersChanged(); return warning; @@ -164,6 +168,21 @@ if (!spectrogram) return tr("Transform \"%1\" did not run correctly (no layer or wrong layer type returned)").arg(base + out); */ + // As with all the visualisation layers, if we already have one in + // the pane we do not create another, just record its + // existence. (We create a new one when loading a new audio file, + // but just note the existing one when loading a complete session.) + + for (int i = 0; i < m_pane->getLayerCount(); ++i) { + SpectrogramLayer *existing = qobject_cast<SpectrogramLayer *> + (m_pane->getLayer(i)); + if (existing) { + cerr << "recording existing spectrogram layer" << endl; + m_layers[Spectrogram] = existing; + return ""; + } + } + SpectrogramLayer *spectrogram = qobject_cast<SpectrogramLayer *> (m_document->createMainModelLayer(LayerFactory::MelodicRangeSpectrogram)); @@ -182,7 +201,19 @@ Analyser::addWaveform() { // Our waveform layer is just a shadow, light grey and taking up - // little space at the bottom + // little space at the bottom. + + // As with the spectrogram above, if one exists already we just + // use it + for (int i = 0; i < m_pane->getLayerCount(); ++i) { + WaveformLayer *existing = qobject_cast<WaveformLayer *> + (m_pane->getLayer(i)); + if (existing) { + cerr << "recording existing waveform layer" << endl; + m_layers[Audio] = existing; + return ""; + } + } WaveformLayer *waveform = qobject_cast<WaveformLayer *> (m_document->createMainModelLayer(LayerFactory::Waveform)); @@ -203,6 +234,27 @@ QString Analyser::addAnalyses() { + // As with the spectrogram above, if these layers exist we use + // them + TimeValueLayer *existingPitch = 0; + FlexiNoteLayer *existingNotes = 0; + for (int i = 0; i < m_pane->getLayerCount(); ++i) { + if (!existingPitch) { + existingPitch = qobject_cast<TimeValueLayer *>(m_pane->getLayer(i)); + } + if (!existingNotes) { + existingNotes = qobject_cast<FlexiNoteLayer *>(m_pane->getLayer(i)); + } + } + if (existingPitch && existingNotes) { + cerr << "recording existing pitch and notes layers" << endl; + m_layers[PitchTrack] = existingPitch; + m_layers[Notes] = existingNotes; + return ""; + } else if (existingPitch || existingNotes) { + return "One (but not both) of pitch and note track found in session"; + } + TransformFactory *tf = TransformFactory::getInstance(); QString plugname = "pYIN"; @@ -484,9 +536,15 @@ pitchTrack->deleteSelection(sel); m_reAnalysisCandidates[m_currentCandidate]->copy(m_pane, sel, clip); pitchTrack->paste(m_pane, clip, 0, false); +} +void +Analyser::stackLayers() +{ // raise the pitch track, then notes on top (if present) - m_paneStack->setCurrentLayer(m_pane, m_layers[PitchTrack]); + if (m_layers[PitchTrack]) { + m_paneStack->setCurrentLayer(m_pane, m_layers[PitchTrack]); + } if (m_layers[Notes] && !m_layers[Notes]->isLayerDormant(m_pane)) { m_paneStack->setCurrentLayer(m_pane, m_layers[Notes]); }
--- a/src/Analyser.h Wed Apr 02 18:22:41 2014 +0100 +++ b/src/Analyser.h Wed Apr 02 21:25:56 2014 +0100 @@ -83,6 +83,10 @@ } } + WaveFileModel *getMainModel() const { + return m_fileModel; + } + float getGain(Component c) const; void setGain(Component c, float gain); @@ -214,6 +218,8 @@ QString addAnalyses(); void discardPitchCandidates(); + + void stackLayers(); // Document::LayerCreationHandler method void layersCreated(std::vector<Layer *>, std::vector<Layer *>);
--- a/src/MainWindow.cpp Wed Apr 02 18:22:41 2014 +0100 +++ b/src/MainWindow.cpp Wed Apr 02 21:25:56 2014 +0100 @@ -366,6 +366,8 @@ connect(this, SIGNAL(activity(QString)), m_activityLog, SLOT(activityHappened(QString))); connect(this, SIGNAL(replacedDocument()), this, SLOT(documentReplaced())); + connect(this, SIGNAL(sessionLoaded()), this, SLOT(analyseNewMainModel())); + connect(this, SIGNAL(audioFileLoaded()), this, SLOT(analyseNewMainModel())); m_activityLog->hide(); newSession(); @@ -2597,12 +2599,6 @@ .arg(startStr).arg(endStr).arg(durationStr); } - // scale Y axis - FlexiNoteLayer *fnl = dynamic_cast<FlexiNoteLayer *>(p->getLayer(2)); - if (fnl) { - fnl->setVerticalRangeToNoteRange(p); - } - statusBar()->showMessage(m_myStatusMessage); } @@ -2685,36 +2681,43 @@ connect(m_fader, SIGNAL(valueChanged(float)), m_playTarget, SLOT(setOutputGain(float))); } - - analyseNewMainModel(); } void MainWindow::analyseNewMainModel() { WaveFileModel *model = getMainModel(); + + cerr << "MainWindow::analyseNewMainModel: main model is " << model << endl; + + cerr << "(document is " << m_document << ", it says main model is " << m_document->getMainModel() << ")" << endl; if (model) { + cerr << "pane stack is " << m_paneStack << " with " << m_paneStack->getPaneCount() << " panes" << endl; + if (m_paneStack) { int pc = m_paneStack->getPaneCount(); Pane *pane = 0; - - if (pc < 1) { + Pane *selectionStrip = 0; + + if (pc < 2) { pane = m_paneStack->addPane(); - - Pane *selectionStrip = m_paneStack->addPane(); - selectionStrip->setFixedHeight(26); + selectionStrip = m_paneStack->addPane(); m_document->addLayerToView (selectionStrip, m_document->createMainModelLayer(LayerFactory::TimeRuler)); + } else { + pane = m_paneStack->getPane(0); + selectionStrip = m_paneStack->getPane(1); + } + + if (selectionStrip) { + selectionStrip->setFixedHeight(26); m_paneStack->sizePanesEqually(); - m_viewManager->clearToolModeOverrides(); m_viewManager->setToolModeFor(selectionStrip, ViewManager::SelectMode); - } else { - pane = m_paneStack->getPane(0); } if (pane) {
--- a/src/MainWindow.h Wed Apr 02 18:22:41 2014 +0100 +++ b/src/MainWindow.h Wed Apr 02 21:25:56 2014 +0100 @@ -170,6 +170,8 @@ virtual void selectionChangedByUser(); virtual void regionOutlined(QRect); + virtual void analyseNewMainModel(); + protected: Analyser *m_analyser; @@ -235,8 +237,6 @@ virtual void closeEvent(QCloseEvent *e); bool checkSaveModified(); - void analyseNewMainModel(); - virtual void updateVisibleRangeDisplay(Pane *p) const; virtual void updatePositionStatusDisplays() const; };