Chris@45: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@45: Chris@45: /* Chris@45: Sonic Visualiser Chris@45: An audio file viewer and annotation editor. Chris@45: Centre for Digital Music, Queen Mary, University of London. Chris@45: This file copyright 2006-2007 Chris Cannam and QMUL. Chris@45: Chris@45: This program is free software; you can redistribute it and/or Chris@45: modify it under the terms of the GNU General Public License as Chris@45: published by the Free Software Foundation; either version 2 of the Chris@45: License, or (at your option) any later version. See the file Chris@45: COPYING included with this distribution for more information. Chris@45: */ Chris@45: Chris@45: #include "MainWindowBase.h" Chris@46: #include "Document.h" Chris@45: Chris@45: Chris@45: #include "view/Pane.h" Chris@45: #include "view/PaneStack.h" Chris@45: #include "data/model/WaveFileModel.h" Chris@45: #include "data/model/SparseOneDimensionalModel.h" Chris@45: #include "data/model/NoteModel.h" Chris@45: #include "data/model/Labeller.h" Chris@124: #include "data/model/TabularModel.h" Chris@45: #include "view/ViewManager.h" Chris@45: Chris@45: #include "layer/WaveformLayer.h" Chris@45: #include "layer/TimeRulerLayer.h" Chris@45: #include "layer/TimeInstantLayer.h" Chris@45: #include "layer/TimeValueLayer.h" Chris@45: #include "layer/Colour3DPlotLayer.h" Chris@45: #include "layer/SliceLayer.h" Chris@45: #include "layer/SliceableLayer.h" Chris@45: #include "layer/ImageLayer.h" Chris@184: #include "layer/NoteLayer.h" Chris@184: #include "layer/RegionLayer.h" Chris@45: Chris@45: #include "widgets/ListInputDialog.h" Chris@105: #include "widgets/CommandHistory.h" Chris@109: #include "widgets/ProgressDialog.h" Chris@109: #include "widgets/MIDIFileImportDialog.h" Chris@109: #include "widgets/CSVFormatDialog.h" Chris@123: #include "widgets/ModelDataTableDialog.h" Chris@45: Chris@45: #include "audioio/AudioCallbackPlaySource.h" Chris@45: #include "audioio/AudioCallbackPlayTarget.h" Chris@45: #include "audioio/AudioTargetFactory.h" Chris@45: #include "audioio/PlaySpeedRangeMapper.h" Chris@45: #include "data/fileio/DataFileReaderFactory.h" Chris@45: #include "data/fileio/PlaylistFileReader.h" Chris@45: #include "data/fileio/WavFileWriter.h" Chris@45: #include "data/fileio/CSVFileWriter.h" Chris@45: #include "data/fileio/MIDIFileWriter.h" Chris@45: #include "data/fileio/BZipFileDevice.h" Chris@45: #include "data/fileio/FileSource.h" Chris@152: #include "data/fileio/AudioFileReaderFactory.h" Chris@134: #include "rdf/RDFImporter.h" Chris@45: Chris@45: #include "data/fft/FFTDataServer.h" Chris@45: Chris@45: #include "base/RecentFiles.h" Chris@45: Chris@45: #include "base/PlayParameterRepository.h" Chris@45: #include "base/XmlExportable.h" Chris@45: #include "base/Profiler.h" Chris@45: #include "base/Preferences.h" Chris@217: #include "base/TempWriteFile.h" Chris@217: #include "base/Exceptions.h" Chris@45: Chris@45: #include "data/osc/OSCQueue.h" Chris@157: #include "data/midi/MIDIInput.h" Chris@45: Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: #include Chris@168: #include Chris@45: Chris@45: #include Chris@45: #include Chris@45: #include Chris@45: Chris@45: using std::cerr; Chris@45: using std::endl; Chris@45: Chris@45: using std::vector; Chris@45: using std::map; Chris@45: using std::set; Chris@45: Chris@45: Chris@161: MainWindowBase::MainWindowBase(bool withAudioOutput, Chris@161: bool withOSCSupport, Chris@161: bool withMIDIInput) : Chris@45: m_document(0), Chris@45: m_paneStack(0), Chris@45: m_viewManager(0), Chris@45: m_timeRulerLayer(0), Chris@45: m_audioOutput(withAudioOutput), Chris@45: m_playSource(0), Chris@45: m_playTarget(0), Chris@113: m_oscQueue(0), Chris@113: m_oscQueueStarter(0), Chris@157: m_midiInput(0), Chris@45: m_recentFiles("RecentFiles", 20), Chris@54: m_recentTransforms("RecentTransforms", 20), Chris@45: m_documentModified(false), Chris@45: m_openingAudioFile(false), Chris@45: m_abandoning(false), Chris@121: m_labeller(0), Chris@121: m_lastPlayStatusSec(0) Chris@45: { Chris@113: Profiler profiler("MainWindowBase::MainWindowBase"); Chris@113: Chris@45: connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()), Chris@45: this, SLOT(documentModified())); Chris@45: connect(CommandHistory::getInstance(), SIGNAL(documentRestored()), Chris@45: this, SLOT(documentRestored())); Chris@45: Chris@45: m_viewManager = new ViewManager(); Chris@45: connect(m_viewManager, SIGNAL(selectionChanged()), Chris@45: this, SLOT(updateMenuStates())); Chris@45: connect(m_viewManager, SIGNAL(inProgressSelectionChanged()), Chris@45: this, SLOT(inProgressSelectionChanged())); Chris@45: Chris@105: // set a sensible default font size for views -- cannot do this Chris@105: // in Preferences, which is in base and not supposed to use QtGui Chris@105: int viewFontSize = QApplication::font().pointSize() * 0.9; Chris@105: QSettings settings; Chris@105: settings.beginGroup("Preferences"); Chris@105: viewFontSize = settings.value("view-font-size", viewFontSize).toInt(); Chris@105: settings.setValue("view-font-size", viewFontSize); Chris@105: settings.endGroup(); Chris@105: Chris@45: Preferences::BackgroundMode mode = Chris@45: Preferences::getInstance()->getBackgroundMode(); Chris@45: m_initialDarkBackground = m_viewManager->getGlobalDarkBackground(); Chris@45: if (mode != Preferences::BackgroundFromTheme) { Chris@45: m_viewManager->setGlobalDarkBackground Chris@45: (mode == Preferences::DarkBackground); Chris@45: } Chris@45: Chris@45: m_paneStack = new PaneStack(0, m_viewManager); Chris@45: connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)), Chris@45: this, SLOT(currentPaneChanged(Pane *))); Chris@45: connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)), Chris@45: this, SLOT(currentLayerChanged(Pane *, Layer *))); Chris@45: connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)), Chris@45: this, SLOT(rightButtonMenuRequested(Pane *, QPoint))); Chris@45: connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)), Chris@45: this, SLOT(contextHelpChanged(const QString &))); Chris@45: connect(m_paneStack, SIGNAL(paneAdded(Pane *)), Chris@45: this, SLOT(paneAdded(Pane *))); Chris@45: connect(m_paneStack, SIGNAL(paneHidden(Pane *)), Chris@45: this, SLOT(paneHidden(Pane *))); Chris@45: connect(m_paneStack, SIGNAL(paneAboutToBeDeleted(Pane *)), Chris@45: this, SLOT(paneAboutToBeDeleted(Pane *))); Chris@45: connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QStringList)), Chris@45: this, SLOT(paneDropAccepted(Pane *, QStringList))); Chris@45: connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QString)), Chris@45: this, SLOT(paneDropAccepted(Pane *, QString))); Chris@55: connect(m_paneStack, SIGNAL(paneDeleteButtonClicked(Pane *)), Chris@55: this, SLOT(paneDeleteButtonClicked(Pane *))); Chris@45: Chris@57: m_playSource = new AudioCallbackPlaySource(m_viewManager, Chris@57: QApplication::applicationName()); Chris@45: Chris@45: connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)), Chris@45: this, SLOT(sampleRateMismatch(size_t, size_t, bool))); Chris@45: connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()), Chris@45: this, SLOT(audioOverloadPluginDisabled())); Chris@130: connect(m_playSource, SIGNAL(audioTimeStretchMultiChannelDisabled()), Chris@130: this, SLOT(audioTimeStretchMultiChannelDisabled())); Chris@45: Chris@45: connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)), Chris@45: this, SLOT(outputLevelsChanged(float, float))); Chris@45: Chris@45: connect(m_viewManager, SIGNAL(playbackFrameChanged(unsigned long)), Chris@45: this, SLOT(playbackFrameChanged(unsigned long))); Chris@45: Chris@45: connect(m_viewManager, SIGNAL(globalCentreFrameChanged(unsigned long)), Chris@45: this, SLOT(globalCentreFrameChanged(unsigned long))); Chris@45: Chris@45: connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, unsigned long)), Chris@45: this, SLOT(viewCentreFrameChanged(View *, unsigned long))); Chris@45: Chris@45: connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, unsigned long, bool)), Chris@45: this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool))); Chris@45: Chris@45: connect(Preferences::getInstance(), Chris@45: SIGNAL(propertyChanged(PropertyContainer::PropertyName)), Chris@45: this, Chris@45: SLOT(preferenceChanged(PropertyContainer::PropertyName))); Chris@45: Chris@45: Labeller::ValueType labellerType = Labeller::ValueFromTwoLevelCounter; Chris@45: settings.beginGroup("MainWindow"); Chris@45: labellerType = (Labeller::ValueType) Chris@45: settings.value("labellertype", (int)labellerType).toInt(); Chris@45: int cycle = settings.value("labellercycle", 4).toInt(); Chris@45: settings.endGroup(); Chris@45: Chris@45: m_labeller = new Labeller(labellerType); Chris@45: m_labeller->setCounterCycleSize(cycle); Chris@113: Chris@161: if (withMIDIInput) { Chris@161: m_midiInput = new MIDIInput(QApplication::applicationName(), this); Chris@161: } Chris@157: Chris@113: if (withOSCSupport) { Chris@113: m_oscQueueStarter = new OSCQueueStarter(this); Chris@113: connect(m_oscQueueStarter, SIGNAL(finished()), this, SLOT(oscReady())); Chris@113: m_oscQueueStarter->start(); Chris@113: } Chris@45: } Chris@45: Chris@45: MainWindowBase::~MainWindowBase() Chris@45: { Chris@177: std::cerr << "MainWindowBase::~MainWindowBase" << std::endl; Chris@70: if (m_playTarget) m_playTarget->shutdown(); Chris@70: // delete m_playTarget; Chris@45: delete m_playSource; Chris@45: delete m_viewManager; Chris@45: delete m_oscQueue; Chris@157: delete m_midiInput; Chris@45: Profiles::getInstance()->dump(); Chris@45: } Chris@45: Chris@113: void Chris@168: MainWindowBase::resizeConstrained(QSize size) Chris@168: { Chris@168: QDesktopWidget *desktop = QApplication::desktop(); Chris@168: QRect available = desktop->availableGeometry(); Chris@168: QSize actual(std::min(size.width(), available.width()), Chris@168: std::min(size.height(), available.height())); Chris@168: resize(actual); Chris@168: } Chris@168: Chris@168: void Chris@113: MainWindowBase::oscReady() Chris@113: { Chris@113: if (m_oscQueue && m_oscQueue->isOK()) { Chris@113: connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC())); Chris@113: QTimer *oscTimer = new QTimer(this); Chris@113: connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC())); Chris@113: oscTimer->start(1000); Chris@113: std::cerr << "Finished setting up OSC interface" << std::endl; Chris@113: } Chris@113: } Chris@113: Chris@45: QString Chris@45: MainWindowBase::getOpenFileName(FileFinder::FileType type) Chris@45: { Chris@45: FileFinder *ff = FileFinder::getInstance(); Chris@45: switch (type) { Chris@45: case FileFinder::SessionFile: Chris@45: return ff->getOpenFileName(type, m_sessionFile); Chris@45: case FileFinder::AudioFile: Chris@45: return ff->getOpenFileName(type, m_audioFile); Chris@45: case FileFinder::LayerFile: Chris@45: return ff->getOpenFileName(type, m_sessionFile); Chris@45: case FileFinder::LayerFileNoMidi: Chris@45: return ff->getOpenFileName(type, m_sessionFile); Chris@45: case FileFinder::SessionOrAudioFile: Chris@45: return ff->getOpenFileName(type, m_sessionFile); Chris@45: case FileFinder::ImageFile: Chris@45: return ff->getOpenFileName(type, m_sessionFile); Chris@45: case FileFinder::AnyFile: Chris@45: if (getMainModel() != 0 && Chris@45: m_paneStack != 0 && Chris@45: m_paneStack->getCurrentPane() != 0) { // can import a layer Chris@45: return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile); Chris@45: } else { Chris@45: return ff->getOpenFileName(FileFinder::SessionOrAudioFile, Chris@45: m_sessionFile); Chris@45: } Chris@45: } Chris@45: return ""; Chris@45: } Chris@45: Chris@45: QString Chris@45: MainWindowBase::getSaveFileName(FileFinder::FileType type) Chris@45: { Chris@45: FileFinder *ff = FileFinder::getInstance(); Chris@45: switch (type) { Chris@45: case FileFinder::SessionFile: Chris@45: return ff->getSaveFileName(type, m_sessionFile); Chris@45: case FileFinder::AudioFile: Chris@45: return ff->getSaveFileName(type, m_audioFile); Chris@45: case FileFinder::LayerFile: Chris@45: return ff->getSaveFileName(type, m_sessionFile); Chris@45: case FileFinder::LayerFileNoMidi: Chris@45: return ff->getSaveFileName(type, m_sessionFile); Chris@45: case FileFinder::SessionOrAudioFile: Chris@45: return ff->getSaveFileName(type, m_sessionFile); Chris@45: case FileFinder::ImageFile: Chris@45: return ff->getSaveFileName(type, m_sessionFile); Chris@45: case FileFinder::AnyFile: Chris@45: return ff->getSaveFileName(type, m_sessionFile); Chris@45: } Chris@45: return ""; Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::registerLastOpenedFilePath(FileFinder::FileType type, QString path) Chris@45: { Chris@45: FileFinder *ff = FileFinder::getInstance(); Chris@45: ff->registerLastOpenedFilePath(type, path); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::updateMenuStates() Chris@45: { Chris@45: Pane *currentPane = 0; Chris@45: Layer *currentLayer = 0; Chris@45: Chris@45: if (m_paneStack) currentPane = m_paneStack->getCurrentPane(); Chris@45: if (currentPane) currentLayer = currentPane->getSelectedLayer(); Chris@45: Chris@73: bool havePrevPane = false, haveNextPane = false; Chris@73: bool havePrevLayer = false, haveNextLayer = false; Chris@73: Chris@73: if (currentPane) { Chris@73: for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { Chris@73: if (m_paneStack->getPane(i) == currentPane) { Chris@73: if (i > 0) havePrevPane = true; Chris@73: if (i < m_paneStack->getPaneCount()-1) haveNextPane = true; Chris@73: break; Chris@73: } Chris@73: } Chris@73: if (currentLayer) { Chris@73: for (int i = 0; i < currentPane->getLayerCount(); ++i) { Chris@73: if (currentPane->getLayer(i) == currentLayer) { Chris@73: if (i > 0) havePrevLayer = true; Chris@73: if (i < currentPane->getLayerCount()-1) haveNextLayer = true; Chris@73: break; Chris@73: } Chris@73: } Chris@73: } Chris@73: } Chris@73: Chris@45: bool haveCurrentPane = Chris@45: (currentPane != 0); Chris@45: bool haveCurrentLayer = Chris@45: (haveCurrentPane && Chris@45: (currentLayer != 0)); Chris@45: bool haveMainModel = Chris@45: (getMainModel() != 0); Chris@45: bool havePlayTarget = Chris@45: (m_playTarget != 0); Chris@45: bool haveSelection = Chris@45: (m_viewManager && Chris@45: !m_viewManager->getSelections().empty()); Chris@45: bool haveCurrentEditableLayer = Chris@45: (haveCurrentLayer && Chris@45: currentLayer->isLayerEditable()); Chris@45: bool haveCurrentTimeInstantsLayer = Chris@45: (haveCurrentLayer && Chris@45: dynamic_cast(currentLayer)); Chris@184: bool haveCurrentDurationLayer = Chris@184: (haveCurrentLayer && Chris@184: (dynamic_cast(currentLayer) || Chris@184: dynamic_cast(currentLayer))); Chris@45: bool haveCurrentColour3DPlot = Chris@45: (haveCurrentLayer && Chris@45: dynamic_cast(currentLayer)); Chris@45: bool haveClipboardContents = Chris@45: (m_viewManager && Chris@45: !m_viewManager->getClipboard().empty()); Chris@146: bool haveTabularLayer = Chris@146: (haveCurrentLayer && Chris@146: dynamic_cast(currentLayer->getModel())); Chris@45: Chris@45: emit canAddPane(haveMainModel); Chris@45: emit canDeleteCurrentPane(haveCurrentPane); Chris@45: emit canZoom(haveMainModel && haveCurrentPane); Chris@45: emit canScroll(haveMainModel && haveCurrentPane); Chris@45: emit canAddLayer(haveMainModel && haveCurrentPane); Chris@45: emit canImportMoreAudio(haveMainModel); Chris@45: emit canImportLayer(haveMainModel && haveCurrentPane); Chris@45: emit canExportAudio(haveMainModel); Chris@45: emit canExportLayer(haveMainModel && Chris@45: (haveCurrentEditableLayer || haveCurrentColour3DPlot)); Chris@45: emit canExportImage(haveMainModel && haveCurrentPane); Chris@45: emit canDeleteCurrentLayer(haveCurrentLayer); Chris@45: emit canRenameLayer(haveCurrentLayer); Chris@45: emit canEditLayer(haveCurrentEditableLayer); Chris@146: emit canEditLayerTabular(haveCurrentEditableLayer || haveTabularLayer); Chris@45: emit canMeasureLayer(haveCurrentLayer); Chris@45: emit canSelect(haveMainModel && haveCurrentPane); Chris@188: emit canPlay(haveMainModel && havePlayTarget); Chris@45: emit canFfwd(true); Chris@45: emit canRewind(true); Chris@87: emit canPaste(haveClipboardContents); Chris@45: emit canInsertInstant(haveCurrentPane); Chris@45: emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection); Chris@184: emit canInsertItemAtSelection(haveCurrentPane && haveSelection && haveCurrentDurationLayer); Chris@45: emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection); Chris@45: emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection); Chris@45: emit canClearSelection(haveSelection); Chris@45: emit canEditSelection(haveSelection && haveCurrentEditableLayer); Chris@45: emit canSave(m_sessionFile != "" && m_documentModified); Chris@73: emit canSelectPreviousPane(havePrevPane); Chris@73: emit canSelectNextPane(haveNextPane); Chris@73: emit canSelectPreviousLayer(havePrevLayer); Chris@73: emit canSelectNextLayer(haveNextLayer); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::documentModified() Chris@45: { Chris@45: // std::cerr << "MainWindowBase::documentModified" << std::endl; Chris@45: Chris@45: if (!m_documentModified) { Chris@45: //!!! this in subclass implementation? Chris@45: setWindowTitle(tr("%1 (modified)").arg(windowTitle())); Chris@45: } Chris@45: Chris@45: m_documentModified = true; Chris@45: updateMenuStates(); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::documentRestored() Chris@45: { Chris@45: // std::cerr << "MainWindowBase::documentRestored" << std::endl; Chris@45: Chris@45: if (m_documentModified) { Chris@45: //!!! this in subclass implementation? Chris@45: QString wt(windowTitle()); Chris@45: wt.replace(tr(" (modified)"), ""); Chris@45: setWindowTitle(wt); Chris@45: } Chris@45: Chris@45: m_documentModified = false; Chris@45: updateMenuStates(); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::playLoopToggled() Chris@45: { Chris@45: QAction *action = dynamic_cast(sender()); Chris@45: Chris@45: if (action) { Chris@45: m_viewManager->setPlayLoopMode(action->isChecked()); Chris@45: } else { Chris@45: m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode()); Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::playSelectionToggled() Chris@45: { Chris@45: QAction *action = dynamic_cast(sender()); Chris@45: Chris@45: if (action) { Chris@45: m_viewManager->setPlaySelectionMode(action->isChecked()); Chris@45: } else { Chris@45: m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode()); Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::playSoloToggled() Chris@45: { Chris@45: QAction *action = dynamic_cast(sender()); Chris@45: Chris@45: if (action) { Chris@45: m_viewManager->setPlaySoloMode(action->isChecked()); Chris@45: } else { Chris@45: m_viewManager->setPlaySoloMode(!m_viewManager->getPlaySoloMode()); Chris@45: } Chris@45: Chris@45: if (m_viewManager->getPlaySoloMode()) { Chris@45: currentPaneChanged(m_paneStack->getCurrentPane()); Chris@45: } else { Chris@45: m_viewManager->setPlaybackModel(0); Chris@45: if (m_playSource) { Chris@45: m_playSource->clearSoloModelSet(); Chris@45: } Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::currentPaneChanged(Pane *p) Chris@45: { Chris@45: updateMenuStates(); Chris@45: updateVisibleRangeDisplay(p); Chris@45: Chris@45: if (!p) return; Chris@45: Chris@45: if (!(m_viewManager && Chris@45: m_playSource && Chris@45: m_viewManager->getPlaySoloMode())) { Chris@45: if (m_viewManager) m_viewManager->setPlaybackModel(0); Chris@45: return; Chris@45: } Chris@45: Chris@45: Model *prevPlaybackModel = m_viewManager->getPlaybackModel(); Chris@60: Chris@93: // What we want here is not the currently playing frame (unless we Chris@93: // are about to clear out the audio playback buffers -- which may Chris@93: // or may not be possible, depending on the audio driver). What Chris@93: // we want is the frame that was last committed to the soundcard Chris@93: // buffers, as the audio driver will continue playing up to that Chris@93: // frame before switching to whichever one we decide we want to Chris@93: // switch to, regardless of our efforts. Chris@93: Chris@93: int frame = m_playSource->getCurrentBufferedFrame(); Chris@93: Chris@93: // std::cerr << "currentPaneChanged: current frame (in ref model) = " << frame << std::endl; Chris@45: Chris@45: View::ModelSet soloModels = p->getModels(); Chris@45: Chris@57: View::ModelSet sources; Chris@57: for (View::ModelSet::iterator mi = soloModels.begin(); Chris@57: mi != soloModels.end(); ++mi) { Chris@190: // If a model in this pane is derived from something else, Chris@190: // then we want to play that model as well -- if the model Chris@190: // that's derived from it is not something that is itself Chris@190: // individually playable (e.g. a waveform) Chris@190: if (*mi && Chris@190: !dynamic_cast(*mi) && Chris@190: (*mi)->getSourceModel()) { Chris@57: sources.insert((*mi)->getSourceModel()); Chris@57: } Chris@57: } Chris@57: for (View::ModelSet::iterator mi = sources.begin(); Chris@57: mi != sources.end(); ++mi) { Chris@57: soloModels.insert(*mi); Chris@57: } Chris@57: Chris@60: //!!! Need an "atomic" way of telling the play source that the Chris@60: //playback model has changed, and changing it on ViewManager -- Chris@60: //the play source should be making the setPlaybackModel call to Chris@60: //ViewManager Chris@60: Chris@45: for (View::ModelSet::iterator mi = soloModels.begin(); Chris@45: mi != soloModels.end(); ++mi) { Chris@45: if (dynamic_cast(*mi)) { Chris@45: m_viewManager->setPlaybackModel(*mi); Chris@45: } Chris@45: } Chris@45: Chris@45: RangeSummarisableTimeValueModel *a = Chris@45: dynamic_cast(prevPlaybackModel); Chris@45: RangeSummarisableTimeValueModel *b = Chris@45: dynamic_cast(m_viewManager-> Chris@45: getPlaybackModel()); Chris@45: Chris@45: m_playSource->setSoloModelSet(soloModels); Chris@45: Chris@45: if (a && b && (a != b)) { Chris@60: if (m_playSource->isPlaying()) m_playSource->play(frame); Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::currentLayerChanged(Pane *p, Layer *) Chris@45: { Chris@45: updateMenuStates(); Chris@45: updateVisibleRangeDisplay(p); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::selectAll() Chris@45: { Chris@45: if (!getMainModel()) return; Chris@45: m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(), Chris@45: getMainModel()->getEndFrame())); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::selectToStart() Chris@45: { Chris@45: if (!getMainModel()) return; Chris@45: m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(), Chris@45: m_viewManager->getGlobalCentreFrame())); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::selectToEnd() Chris@45: { Chris@45: if (!getMainModel()) return; Chris@45: m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(), Chris@45: getMainModel()->getEndFrame())); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::selectVisible() Chris@45: { Chris@45: Model *model = getMainModel(); Chris@45: if (!model) return; Chris@45: Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (!currentPane) return; Chris@45: Chris@45: size_t startFrame, endFrame; Chris@45: Chris@45: if (currentPane->getStartFrame() < 0) startFrame = 0; Chris@45: else startFrame = currentPane->getStartFrame(); Chris@45: Chris@45: if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame(); Chris@45: else endFrame = currentPane->getEndFrame(); Chris@45: Chris@45: m_viewManager->setSelection(Selection(startFrame, endFrame)); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::clearSelection() Chris@45: { Chris@45: m_viewManager->clearSelections(); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::cut() Chris@45: { Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (!currentPane) return; Chris@45: Chris@45: Layer *layer = currentPane->getSelectedLayer(); Chris@45: if (!layer) return; Chris@45: Chris@45: Clipboard &clipboard = m_viewManager->getClipboard(); Chris@45: clipboard.clear(); Chris@45: Chris@45: MultiSelection::SelectionList selections = m_viewManager->getSelections(); Chris@45: Chris@45: CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true); Chris@45: Chris@45: for (MultiSelection::SelectionList::iterator i = selections.begin(); Chris@45: i != selections.end(); ++i) { Chris@86: layer->copy(currentPane, *i, clipboard); Chris@45: layer->deleteSelection(*i); Chris@45: } Chris@45: Chris@45: CommandHistory::getInstance()->endCompoundOperation(); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::copy() Chris@45: { Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (!currentPane) return; Chris@45: Chris@45: Layer *layer = currentPane->getSelectedLayer(); Chris@45: if (!layer) return; Chris@45: Chris@45: Clipboard &clipboard = m_viewManager->getClipboard(); Chris@45: clipboard.clear(); Chris@45: Chris@45: MultiSelection::SelectionList selections = m_viewManager->getSelections(); Chris@45: Chris@45: for (MultiSelection::SelectionList::iterator i = selections.begin(); Chris@45: i != selections.end(); ++i) { Chris@86: layer->copy(currentPane, *i, clipboard); Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::paste() Chris@45: { Chris@215: pasteRelative(0); Chris@215: } Chris@215: Chris@215: void Chris@215: MainWindowBase::pasteAtPlaybackPosition() Chris@215: { Chris@215: unsigned long pos = getFrame(); Chris@215: Clipboard &clipboard = m_viewManager->getClipboard(); Chris@215: if (!clipboard.empty()) { Chris@215: long firstEventFrame = clipboard.getPoints()[0].getFrame(); Chris@215: long offset = 0; Chris@215: if (firstEventFrame < 0) { Chris@221: offset = (long)pos - firstEventFrame; Chris@215: } else if (firstEventFrame < pos) { Chris@221: offset = pos - (unsigned long)firstEventFrame; Chris@215: } else { Chris@221: offset = -((unsigned long)firstEventFrame - pos); Chris@215: } Chris@215: pasteRelative(offset); Chris@215: } Chris@215: } Chris@215: Chris@215: void Chris@215: MainWindowBase::pasteRelative(int offset) Chris@215: { Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (!currentPane) return; Chris@45: Chris@45: Layer *layer = currentPane->getSelectedLayer(); Chris@45: Chris@45: Clipboard &clipboard = m_viewManager->getClipboard(); Chris@87: Chris@98: bool inCompound = false; Chris@87: Chris@87: if (!layer || !layer->isLayerEditable()) { Chris@87: Chris@87: CommandHistory::getInstance()->startCompoundOperation Chris@87: (tr("Paste"), true); Chris@87: Chris@87: // no suitable current layer: create one of the most Chris@87: // appropriate sort Chris@87: LayerFactory::LayerType type = Chris@87: LayerFactory::getInstance()->getLayerTypeForClipboardContents(clipboard); Chris@87: layer = m_document->createEmptyLayer(type); Chris@87: Chris@87: if (!layer) { Chris@87: CommandHistory::getInstance()->endCompoundOperation(); Chris@87: return; Chris@45: } Chris@87: Chris@87: m_document->addLayerToView(currentPane, layer); Chris@87: m_paneStack->setCurrentLayer(currentPane, layer); Chris@87: Chris@87: inCompound = true; Chris@45: } Chris@45: Chris@215: layer->paste(currentPane, clipboard, offset, true); Chris@45: Chris@87: if (inCompound) CommandHistory::getInstance()->endCompoundOperation(); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::deleteSelected() Chris@45: { Chris@45: if (m_paneStack->getCurrentPane() && Chris@45: m_paneStack->getCurrentPane()->getSelectedLayer()) { Chris@45: Chris@45: Layer *layer = m_paneStack->getCurrentPane()->getSelectedLayer(); Chris@45: Chris@45: if (m_viewManager && Chris@45: (m_viewManager->getToolMode() == ViewManager::MeasureMode)) { Chris@45: Chris@45: layer->deleteCurrentMeasureRect(); Chris@45: Chris@45: } else { Chris@45: Chris@45: MultiSelection::SelectionList selections = Chris@45: m_viewManager->getSelections(); Chris@45: Chris@45: for (MultiSelection::SelectionList::iterator i = selections.begin(); Chris@45: i != selections.end(); ++i) { Chris@45: layer->deleteSelection(*i); Chris@45: } Chris@45: } Chris@45: } Chris@45: } Chris@45: Chris@161: // FrameTimer method Chris@161: Chris@161: unsigned long Chris@161: MainWindowBase::getFrame() const Chris@161: { Chris@161: if (m_playSource && m_playSource->isPlaying()) { Chris@161: return m_playSource->getCurrentPlayingFrame(); Chris@161: } else { Chris@161: return m_viewManager->getPlaybackFrame(); Chris@161: } Chris@161: } Chris@161: Chris@45: void Chris@45: MainWindowBase::insertInstant() Chris@45: { Chris@161: insertInstantAt(getFrame()); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::insertInstantsAtBoundaries() Chris@45: { Chris@45: MultiSelection::SelectionList selections = m_viewManager->getSelections(); Chris@45: for (MultiSelection::SelectionList::iterator i = selections.begin(); Chris@45: i != selections.end(); ++i) { Chris@45: size_t start = i->getStartFrame(); Chris@45: size_t end = i->getEndFrame(); Chris@45: if (start != end) { Chris@184: insertInstantAt(start); Chris@184: insertInstantAt(end); Chris@45: } Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::insertInstantAt(size_t frame) Chris@45: { Chris@45: Pane *pane = m_paneStack->getCurrentPane(); Chris@45: if (!pane) { Chris@45: return; Chris@45: } Chris@45: Chris@74: frame = pane->alignFromReference(frame); Chris@74: Chris@45: Layer *layer = dynamic_cast Chris@45: (pane->getSelectedLayer()); Chris@45: Chris@45: if (!layer) { Chris@45: for (int i = pane->getLayerCount(); i > 0; --i) { Chris@45: layer = dynamic_cast(pane->getLayer(i - 1)); Chris@45: if (layer) break; Chris@45: } Chris@45: Chris@45: if (!layer) { Chris@45: CommandHistory::getInstance()->startCompoundOperation Chris@45: (tr("Add Point"), true); Chris@45: layer = m_document->createEmptyLayer(LayerFactory::TimeInstants); Chris@45: if (layer) { Chris@45: m_document->addLayerToView(pane, layer); Chris@45: m_paneStack->setCurrentLayer(pane, layer); Chris@45: } Chris@45: CommandHistory::getInstance()->endCompoundOperation(); Chris@45: } Chris@45: } Chris@45: Chris@45: if (layer) { Chris@45: Chris@45: Model *model = layer->getModel(); Chris@45: SparseOneDimensionalModel *sodm = dynamic_cast Chris@45: (model); Chris@45: Chris@45: if (sodm) { Chris@45: SparseOneDimensionalModel::Point point(frame, ""); Chris@45: Chris@45: SparseOneDimensionalModel::Point prevPoint(0); Chris@45: bool havePrevPoint = false; Chris@45: Chris@45: SparseOneDimensionalModel::EditCommand *command = Chris@45: new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point")); Chris@45: Chris@74: if (m_labeller->requiresPrevPoint()) { Chris@45: Chris@45: SparseOneDimensionalModel::PointList prevPoints = Chris@45: sodm->getPreviousPoints(frame); Chris@45: Chris@45: if (!prevPoints.empty()) { Chris@45: prevPoint = *prevPoints.begin(); Chris@45: havePrevPoint = true; Chris@45: } Chris@45: } Chris@45: Chris@45: if (m_labeller) { Chris@45: Chris@45: m_labeller->setSampleRate(sodm->getSampleRate()); Chris@45: Chris@74: if (m_labeller->actingOnPrevPoint()) { Chris@45: command->deletePoint(prevPoint); Chris@45: } Chris@45: Chris@45: m_labeller->label Chris@45: (point, havePrevPoint ? &prevPoint : 0); Chris@45: Chris@74: if (m_labeller->actingOnPrevPoint()) { Chris@45: command->addPoint(prevPoint); Chris@45: } Chris@45: } Chris@45: Chris@45: command->addPoint(point); Chris@45: Chris@45: command->setName(tr("Add Point at %1 s") Chris@45: .arg(RealTime::frame2RealTime Chris@45: (frame, Chris@45: sodm->getSampleRate()) Chris@45: .toText(false).c_str())); Chris@45: Chris@108: Command *c = command->finish(); Chris@108: if (c) CommandHistory::getInstance()->addCommand(c, false); Chris@45: } Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@184: MainWindowBase::insertItemAtSelection() Chris@184: { Chris@184: MultiSelection::SelectionList selections = m_viewManager->getSelections(); Chris@184: for (MultiSelection::SelectionList::iterator i = selections.begin(); Chris@184: i != selections.end(); ++i) { Chris@184: size_t start = i->getStartFrame(); Chris@184: size_t end = i->getEndFrame(); Chris@184: if (start < end) { Chris@184: insertItemAt(start, end - start); Chris@184: } Chris@184: } Chris@184: } Chris@184: Chris@184: void Chris@184: MainWindowBase::insertItemAt(size_t frame, size_t duration) Chris@184: { Chris@184: Pane *pane = m_paneStack->getCurrentPane(); Chris@184: if (!pane) { Chris@184: return; Chris@184: } Chris@184: Chris@184: // ugh! Chris@184: Chris@184: size_t alignedStart = pane->alignFromReference(frame); Chris@184: size_t alignedEnd = pane->alignFromReference(frame + duration); Chris@184: if (alignedStart >= alignedEnd) return; Chris@184: size_t alignedDuration = alignedEnd - alignedStart; Chris@184: Chris@184: Command *c = 0; Chris@184: Chris@184: QString name = tr("Add Item at %1 s") Chris@184: .arg(RealTime::frame2RealTime Chris@184: (alignedStart, Chris@184: getMainModel()->getSampleRate()) Chris@184: .toText(false).c_str()); Chris@184: Chris@184: Layer *layer = pane->getSelectedLayer(); Chris@184: if (!layer) return; Chris@184: Chris@184: RegionModel *rm = dynamic_cast(layer->getModel()); Chris@184: if (rm) { Chris@184: RegionModel::Point point(alignedStart, Chris@185: rm->getValueMaximum() + 1, Chris@184: alignedDuration, Chris@184: ""); Chris@184: RegionModel::EditCommand *command = Chris@184: new RegionModel::EditCommand(rm, tr("Add Point")); Chris@184: command->addPoint(point); Chris@184: command->setName(name); Chris@184: c = command->finish(); Chris@184: } Chris@184: Chris@184: if (c) { Chris@184: CommandHistory::getInstance()->addCommand(c, false); Chris@184: return; Chris@184: } Chris@184: Chris@184: NoteModel *nm = dynamic_cast(layer->getModel()); Chris@184: if (nm) { Chris@184: NoteModel::Point point(alignedStart, Chris@184: rm->getValueMinimum(), Chris@184: alignedDuration, Chris@184: 1.f, Chris@184: ""); Chris@184: NoteModel::EditCommand *command = Chris@184: new NoteModel::EditCommand(nm, tr("Add Point")); Chris@184: command->addPoint(point); Chris@184: command->setName(name); Chris@184: c = command->finish(); Chris@184: } Chris@184: Chris@184: if (c) { Chris@184: CommandHistory::getInstance()->addCommand(c, false); Chris@184: return; Chris@184: } Chris@184: } Chris@184: Chris@184: void Chris@45: MainWindowBase::renumberInstants() Chris@45: { Chris@45: Pane *pane = m_paneStack->getCurrentPane(); Chris@45: if (!pane) return; Chris@45: Chris@45: Layer *layer = dynamic_cast(pane->getSelectedLayer()); Chris@45: if (!layer) return; Chris@45: Chris@45: MultiSelection ms(m_viewManager->getSelection()); Chris@45: Chris@45: Model *model = layer->getModel(); Chris@45: SparseOneDimensionalModel *sodm = dynamic_cast Chris@45: (model); Chris@45: if (!sodm) return; Chris@45: Chris@45: if (!m_labeller) return; Chris@45: Chris@45: Labeller labeller(*m_labeller); Chris@45: labeller.setSampleRate(sodm->getSampleRate()); Chris@45: Chris@45: // This uses a command Chris@45: Chris@45: labeller.labelAll(*sodm, &ms); Chris@45: } Chris@45: Chris@45: MainWindowBase::FileOpenStatus Chris@45: MainWindowBase::open(QString fileOrUrl, AudioFileOpenMode mode) Chris@45: { Chris@134: ProgressDialog dialog(tr("Opening file or URL..."), true, 2000, this); Chris@134: connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash())); Chris@109: return open(FileSource(fileOrUrl, &dialog), mode); Chris@45: } Chris@45: Chris@45: MainWindowBase::FileOpenStatus Chris@45: MainWindowBase::open(FileSource source, AudioFileOpenMode mode) Chris@45: { Chris@45: FileOpenStatus status; Chris@45: Chris@45: if (!source.isAvailable()) return FileOpenFailed; Chris@45: source.waitForData(); Chris@45: Chris@45: bool canImportLayer = (getMainModel() != 0 && Chris@45: m_paneStack != 0 && Chris@45: m_paneStack->getCurrentPane() != 0); Chris@45: Chris@152: bool rdf = (source.getExtension().toLower() == "rdf" || Chris@152: source.getExtension().toLower() == "n3" || Chris@152: source.getExtension().toLower() == "ttl"); Chris@152: Chris@152: bool audio = AudioFileReaderFactory::getKnownExtensions().contains Chris@152: (source.getExtension().toLower()); Chris@145: Chris@145: bool rdfSession = false; Chris@145: if (rdf) { Chris@145: RDFImporter::RDFDocumentType rdfType = Chris@145: RDFImporter::identifyDocumentType Chris@145: (QUrl::fromLocalFile(source.getLocalFilename()).toString()); Chris@148: // std::cerr << "RDF type: " << (int)rdfType << std::endl; Chris@145: if (rdfType == RDFImporter::AudioRefAndAnnotations || Chris@145: rdfType == RDFImporter::AudioRef) { Chris@145: rdfSession = true; Chris@145: } else if (rdfType == RDFImporter::NotRDF) { Chris@145: rdf = false; Chris@145: } Chris@145: } Chris@145: Chris@145: if (rdf) { Chris@145: if (rdfSession) { Chris@147: bool cancel = false; Chris@147: if (!canImportLayer || shouldCreateNewSessionForRDFAudio(&cancel)) { Chris@145: return openSession(source); Chris@147: } else if (cancel) { Chris@147: return FileOpenCancelled; Chris@145: } else { Chris@145: return openLayer(source); Chris@145: } Chris@145: } else { Chris@145: if ((status = openSession(source)) != FileOpenFailed) { Chris@145: return status; Chris@145: } else if (!canImportLayer) { Chris@145: return FileOpenWrongMode; Chris@145: } else if ((status = openLayer(source)) != FileOpenFailed) { Chris@145: return status; Chris@145: } else { Chris@145: return FileOpenFailed; Chris@145: } Chris@145: } Chris@145: } Chris@145: Chris@152: if (audio && (status = openAudio(source, mode)) != FileOpenFailed) { Chris@45: return status; Chris@45: } else if ((status = openSession(source)) != FileOpenFailed) { Chris@45: return status; Chris@45: } else if ((status = openPlaylist(source, mode)) != FileOpenFailed) { Chris@45: return status; Chris@45: } else if (!canImportLayer) { Chris@45: return FileOpenWrongMode; Chris@45: } else if ((status = openImage(source)) != FileOpenFailed) { Chris@45: return status; Chris@45: } else if ((status = openLayer(source)) != FileOpenFailed) { Chris@45: return status; Chris@45: } else { Chris@45: return FileOpenFailed; Chris@45: } Chris@45: } Chris@45: Chris@45: MainWindowBase::FileOpenStatus dan@210: MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode, QString templateName) Chris@45: { Chris@132: // std::cerr << "MainWindowBase::openAudio(" << source.getLocation().toStdString() << ")" << std::endl; Chris@45: Chris@220: if (templateName == "") templateName = "testtemplate"; Chris@220: Chris@45: if (!source.isAvailable()) return FileOpenFailed; Chris@45: source.waitForData(); Chris@45: Chris@45: m_openingAudioFile = true; Chris@45: Chris@45: size_t rate = 0; Chris@45: Chris@45: if (Preferences::getInstance()->getResampleOnLoad()) { Chris@45: rate = m_playSource->getSourceSampleRate(); Chris@45: } Chris@45: Chris@45: WaveFileModel *newModel = new WaveFileModel(source, rate); Chris@45: Chris@45: if (!newModel->isOK()) { Chris@45: delete newModel; Chris@45: m_openingAudioFile = false; Chris@45: return FileOpenFailed; Chris@45: } Chris@45: Chris@132: // std::cerr << "mode = " << mode << std::endl; Chris@45: Chris@45: if (mode == AskUser) { Chris@45: if (getMainModel()) { Chris@45: Chris@147: QSettings settings; Chris@147: settings.beginGroup("MainWindow"); Chris@221: int lastMode = settings.value("lastaudioopenmode", 0).toBool(); Chris@147: settings.endGroup(); Chris@221: int imode = 0; Chris@45: Chris@45: QStringList items; Chris@221: items << tr("Close the current session and start a new one") Chris@221: << tr("Replace the main audio file in this session") Chris@221: << tr("Add the audio file to this session"); Chris@45: Chris@45: bool ok = false; Chris@45: QString item = ListInputDialog::getItem Chris@45: (this, tr("Select target for import"), Chris@221: tr("Select a target for import

You already have an audio file loaded.
What would you like to do with the new audio file?"), Chris@221: items, lastMode, &ok); Chris@45: Chris@45: if (!ok || item.isEmpty()) { Chris@45: delete newModel; Chris@45: m_openingAudioFile = false; Chris@45: return FileOpenCancelled; Chris@45: } Chris@45: Chris@221: for (int i = 0; i < items.size(); ++i) { Chris@221: if (item == items[i]) imode = i; Chris@221: } Chris@221: Chris@147: settings.beginGroup("MainWindow"); Chris@221: settings.setValue("lastaudioopenmode", imode); Chris@147: settings.endGroup(); Chris@45: Chris@221: mode = (AudioFileOpenMode)imode; Chris@45: Chris@45: } else { Chris@221: // no main model: make a new session Chris@221: mode = ReplaceSession; Chris@45: } Chris@45: } Chris@45: Chris@45: if (mode == ReplaceCurrentPane) { Chris@45: Chris@45: Pane *pane = m_paneStack->getCurrentPane(); Chris@45: if (pane) { Chris@45: if (getMainModel()) { Chris@45: View::ModelSet models(pane->getModels()); Chris@45: if (models.find(getMainModel()) != models.end()) { Chris@221: // Current pane contains main model: replace that Chris@45: mode = ReplaceMainModel; Chris@45: } Chris@221: // Otherwise the current pane has a non-default model, Chris@221: // which we will deal with later Chris@45: } else { Chris@221: // We have no main model, so start a new session with Chris@221: // optional template Chris@221: mode = ReplaceSession; Chris@45: } Chris@45: } else { Chris@221: // We seem to have no current pane! Oh well Chris@45: mode = CreateAdditionalModel; Chris@45: } Chris@45: } Chris@45: Chris@45: if (mode == CreateAdditionalModel && !getMainModel()) { Chris@221: mode = ReplaceSession; Chris@221: } Chris@221: Chris@221: bool loadedTemplate = false; Chris@221: Chris@221: if (mode == ReplaceSession) { Chris@221: Chris@221: if (templateName.length() != 0) { Chris@221: QString tplPath = "file::templates/" + templateName + ".xml"; Chris@221: std::cerr << "SV looking for template " << tplPath.toStdString() << std::endl; Chris@221: FileOpenStatus tplStatus = openSessionFile(tplPath); Chris@221: if (tplStatus != FileOpenFailed) { Chris@221: loadedTemplate = true; Chris@221: } Chris@221: } Chris@221: Chris@221: if (!loadedTemplate) { Chris@221: closeSession(); Chris@221: createDocument(); Chris@221: } Chris@221: Chris@45: mode = ReplaceMainModel; Chris@45: } Chris@45: Chris@164: emit activity(tr("Import audio file \"%1\"").arg(source.getLocation())); Chris@164: Chris@45: if (mode == ReplaceMainModel) { Chris@45: Chris@45: Model *prevMain = getMainModel(); Chris@45: if (prevMain) { Chris@45: m_playSource->removeModel(prevMain); Chris@108: PlayParameterRepository::getInstance()->removePlayable(prevMain); Chris@45: } Chris@108: PlayParameterRepository::getInstance()->addPlayable(newModel); Chris@45: Chris@45: m_document->setMainModel(newModel); Chris@45: Chris@45: setupMenus(); Chris@45: dan@210: if (loadedTemplate || (m_sessionFile == "")) { Chris@45: //!!! shouldn't be dealing directly with title from here -- call a method Chris@57: setWindowTitle(tr("%1: %2") Chris@57: .arg(QApplication::applicationName()) Chris@45: .arg(source.getLocation())); Chris@45: CommandHistory::getInstance()->clear(); Chris@45: CommandHistory::getInstance()->documentSaved(); Chris@45: m_documentModified = false; Chris@45: } else { Chris@57: setWindowTitle(tr("%1: %2 [%3]") Chris@57: .arg(QApplication::applicationName()) Chris@45: .arg(QFileInfo(m_sessionFile).fileName()) Chris@45: .arg(source.getLocation())); Chris@45: if (m_documentModified) { Chris@45: m_documentModified = false; Chris@45: documentModified(); // so as to restore "(modified)" window title Chris@45: } Chris@45: } Chris@45: Chris@45: if (!source.isRemote()) m_audioFile = source.getLocalFilename(); Chris@45: Chris@45: } else if (mode == CreateAdditionalModel) { Chris@45: Chris@45: CommandHistory::getInstance()->startCompoundOperation Chris@219: (tr("Import \"%1\"").arg(source.getBasename()), true); Chris@45: Chris@45: m_document->addImportedModel(newModel); Chris@45: Chris@45: AddPaneCommand *command = new AddPaneCommand(this); Chris@45: CommandHistory::getInstance()->addCommand(command); Chris@45: Chris@45: Pane *pane = command->getPane(); Chris@45: Chris@47: if (m_timeRulerLayer) { Chris@47: m_document->addLayerToView(pane, m_timeRulerLayer); Chris@47: } Chris@45: Chris@45: Layer *newLayer = m_document->createImportedLayer(newModel); Chris@45: Chris@45: if (newLayer) { Chris@45: m_document->addLayerToView(pane, newLayer); Chris@45: } Chris@45: Chris@45: CommandHistory::getInstance()->endCompoundOperation(); Chris@45: Chris@45: } else if (mode == ReplaceCurrentPane) { Chris@45: Chris@45: // We know there is a current pane, otherwise we would have Chris@45: // reset the mode to CreateAdditionalModel above; and we know Chris@45: // the current pane does not contain the main model, otherwise Chris@45: // we would have reset it to ReplaceMainModel. But we don't Chris@45: // know whether the pane contains a waveform model at all. Chris@45: Chris@45: Pane *pane = m_paneStack->getCurrentPane(); Chris@45: Layer *replace = 0; Chris@45: Chris@45: for (int i = 0; i < pane->getLayerCount(); ++i) { Chris@45: Layer *layer = pane->getLayer(i); Chris@45: if (dynamic_cast(layer)) { Chris@45: replace = layer; Chris@45: break; Chris@45: } Chris@45: } Chris@45: Chris@45: CommandHistory::getInstance()->startCompoundOperation Chris@219: (tr("Import \"%1\"").arg(source.getBasename()), true); Chris@45: Chris@45: m_document->addImportedModel(newModel); Chris@45: Chris@45: if (replace) { Chris@45: m_document->removeLayerFromView(pane, replace); Chris@45: } Chris@45: Chris@45: Layer *newLayer = m_document->createImportedLayer(newModel); Chris@45: Chris@45: if (newLayer) { Chris@45: m_document->addLayerToView(pane, newLayer); Chris@45: } Chris@45: Chris@45: CommandHistory::getInstance()->endCompoundOperation(); Chris@45: } Chris@45: Chris@45: updateMenuStates(); Chris@45: m_recentFiles.addFile(source.getLocation()); Chris@45: if (!source.isRemote()) { Chris@45: // for file dialog Chris@45: registerLastOpenedFilePath(FileFinder::AudioFile, Chris@45: source.getLocalFilename()); Chris@45: } Chris@45: m_openingAudioFile = false; Chris@45: Chris@45: currentPaneChanged(m_paneStack->getCurrentPane()); Chris@45: Chris@45: return FileOpenSucceeded; Chris@45: } Chris@45: Chris@45: MainWindowBase::FileOpenStatus Chris@45: MainWindowBase::openPlaylist(FileSource source, AudioFileOpenMode mode) Chris@45: { Chris@135: std::cerr << "MainWindowBase::openPlaylist(" << source.getLocation().toStdString() << ")" << std::endl; Chris@135: Chris@45: std::set extensions; Chris@45: PlaylistFileReader::getSupportedExtensions(extensions); Chris@152: QString extension = source.getExtension().toLower(); Chris@45: if (extensions.find(extension) == extensions.end()) return FileOpenFailed; Chris@45: Chris@45: if (!source.isAvailable()) return FileOpenFailed; Chris@45: source.waitForData(); Chris@45: Chris@45: PlaylistFileReader reader(source.getLocalFilename()); Chris@45: if (!reader.isOK()) return FileOpenFailed; Chris@45: Chris@45: PlaylistFileReader::Playlist playlist = reader.load(); Chris@45: Chris@45: bool someSuccess = false; Chris@45: Chris@45: for (PlaylistFileReader::Playlist::const_iterator i = playlist.begin(); Chris@45: i != playlist.end(); ++i) { Chris@45: Chris@134: ProgressDialog dialog(tr("Opening playlist..."), true, 2000, this); Chris@134: connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash())); Chris@109: FileOpenStatus status = openAudio(FileSource(*i, &dialog), mode); Chris@45: Chris@45: if (status == FileOpenCancelled) { Chris@45: return FileOpenCancelled; Chris@45: } Chris@45: Chris@45: if (status == FileOpenSucceeded) { Chris@45: someSuccess = true; Chris@45: mode = CreateAdditionalModel; Chris@45: } Chris@45: } Chris@45: Chris@45: if (someSuccess) return FileOpenSucceeded; Chris@45: else return FileOpenFailed; Chris@45: } Chris@45: Chris@45: MainWindowBase::FileOpenStatus Chris@45: MainWindowBase::openLayer(FileSource source) Chris@45: { Chris@135: std::cerr << "MainWindowBase::openLayer(" << source.getLocation().toStdString() << ")" << std::endl; Chris@135: Chris@45: Pane *pane = m_paneStack->getCurrentPane(); Chris@45: Chris@45: if (!pane) { Chris@45: // shouldn't happen, as the menu action should have been disabled Chris@45: std::cerr << "WARNING: MainWindowBase::openLayer: no current pane" << std::endl; Chris@45: return FileOpenWrongMode; Chris@45: } Chris@45: Chris@45: if (!getMainModel()) { Chris@45: // shouldn't happen, as the menu action should have been disabled Chris@45: std::cerr << "WARNING: MainWindowBase::openLayer: No main model -- hence no default sample rate available" << std::endl; Chris@45: return FileOpenWrongMode; Chris@45: } Chris@45: Chris@45: if (!source.isAvailable()) return FileOpenFailed; Chris@45: source.waitForData(); Chris@45: Chris@45: QString path = source.getLocalFilename(); Chris@45: Chris@145: RDFImporter::RDFDocumentType rdfType = Chris@145: RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString()); Chris@145: Chris@148: // std::cerr << "RDF type: (in layer) " << (int) rdfType << std::endl; Chris@148: Chris@145: if (rdfType != RDFImporter::NotRDF) { Chris@145: Chris@145: return openLayersFromRDF(source); Chris@134: Chris@152: } else if (source.getExtension().toLower() == "svl" || Chris@152: (source.getExtension().toLower() == "xml" && Chris@140: (SVFileReader::identifyXmlFile(source.getLocalFilename()) Chris@140: == SVFileReader::SVLayerFile))) { Chris@45: Chris@45: PaneCallback callback(this); Chris@45: QFile file(path); Chris@45: Chris@45: if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { Chris@45: std::cerr << "ERROR: MainWindowBase::openLayer(" Chris@45: << source.getLocation().toStdString() Chris@45: << "): Failed to open file for reading" << std::endl; Chris@45: return FileOpenFailed; Chris@45: } Chris@45: Chris@45: SVFileReader reader(m_document, callback, source.getLocation()); Chris@79: connect Chris@79: (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)), Chris@79: this, SLOT(modelRegenerationFailed(QString, QString, QString))); Chris@79: connect Chris@79: (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)), Chris@79: this, SLOT(modelRegenerationWarning(QString, QString, QString))); Chris@45: reader.setCurrentPane(pane); Chris@45: Chris@45: QXmlInputSource inputSource(&file); Chris@45: reader.parse(inputSource); Chris@45: Chris@45: if (!reader.isOK()) { Chris@45: std::cerr << "ERROR: MainWindowBase::openLayer(" Chris@45: << source.getLocation().toStdString() Chris@45: << "): Failed to read XML file: " Chris@45: << reader.getErrorString().toStdString() << std::endl; Chris@45: return FileOpenFailed; Chris@45: } Chris@45: Chris@164: emit activity(tr("Import layer XML file \"%1\"").arg(source.getLocation())); Chris@164: Chris@45: m_recentFiles.addFile(source.getLocation()); Chris@45: Chris@45: if (!source.isRemote()) { Chris@45: registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog Chris@45: } Chris@45: Chris@75: return FileOpenSucceeded; Chris@75: Chris@45: } else { Chris@45: Chris@45: try { Chris@45: Chris@109: MIDIFileImportDialog midiDlg(this); Chris@109: Chris@109: Model *model = DataFileReaderFactory::loadNonCSV Chris@109: (path, &midiDlg, getMainModel()->getSampleRate()); Chris@45: Chris@109: if (!model) { Chris@196: CSVFormat format(path); Chris@196: format.setSampleRate(getMainModel()->getSampleRate()); Chris@196: CSVFormatDialog *dialog = new CSVFormatDialog(this, format); Chris@109: if (dialog->exec() == QDialog::Accepted) { Chris@109: model = DataFileReaderFactory::loadCSV Chris@109: (path, dialog->getFormat(), Chris@109: getMainModel()->getSampleRate()); Chris@109: } Chris@109: } Chris@109: Chris@45: if (model) { Chris@45: Chris@45: std::cerr << "MainWindowBase::openLayer: Have model" << std::endl; Chris@45: Chris@164: emit activity(tr("Import MIDI file \"%1\"").arg(source.getLocation())); Chris@164: Chris@45: Layer *newLayer = m_document->createImportedLayer(model); Chris@45: Chris@45: if (newLayer) { Chris@45: Chris@45: m_document->addLayerToView(pane, newLayer); Chris@88: m_paneStack->setCurrentLayer(pane, newLayer); Chris@88: Chris@45: m_recentFiles.addFile(source.getLocation()); Chris@45: Chris@45: if (!source.isRemote()) { Chris@45: registerLastOpenedFilePath Chris@45: (FileFinder::LayerFile, Chris@45: path); // for file dialog Chris@45: } Chris@88: Chris@45: return FileOpenSucceeded; Chris@45: } Chris@45: } Chris@45: } catch (DataFileReaderFactory::Exception e) { Chris@45: if (e == DataFileReaderFactory::ImportCancelled) { Chris@45: return FileOpenCancelled; Chris@45: } Chris@45: } Chris@45: } Chris@45: Chris@45: return FileOpenFailed; Chris@45: } Chris@45: Chris@45: MainWindowBase::FileOpenStatus Chris@45: MainWindowBase::openImage(FileSource source) Chris@45: { Chris@135: std::cerr << "MainWindowBase::openImage(" << source.getLocation().toStdString() << ")" << std::endl; Chris@135: Chris@45: Pane *pane = m_paneStack->getCurrentPane(); Chris@45: Chris@45: if (!pane) { Chris@45: // shouldn't happen, as the menu action should have been disabled Chris@45: std::cerr << "WARNING: MainWindowBase::openImage: no current pane" << std::endl; Chris@45: return FileOpenWrongMode; Chris@45: } Chris@45: Chris@45: if (!m_document->getMainModel()) { Chris@45: return FileOpenWrongMode; Chris@45: } Chris@45: Chris@45: bool newLayer = false; Chris@45: Chris@45: ImageLayer *il = dynamic_cast(pane->getSelectedLayer()); Chris@45: if (!il) { Chris@45: for (int i = pane->getLayerCount()-1; i >= 0; --i) { Chris@45: il = dynamic_cast(pane->getLayer(i)); Chris@45: if (il) break; Chris@45: } Chris@45: } Chris@45: if (!il) { Chris@45: il = dynamic_cast Chris@45: (m_document->createEmptyLayer(LayerFactory::Image)); Chris@45: if (!il) return FileOpenFailed; Chris@45: newLayer = true; Chris@45: } Chris@45: Chris@45: // We don't put the image file in Recent Files Chris@45: Chris@45: std::cerr << "openImage: trying location \"" << source.getLocation().toStdString() << "\" in image layer" << std::endl; Chris@45: Chris@45: if (!il->addImage(m_viewManager->getGlobalCentreFrame(), source.getLocation())) { Chris@45: if (newLayer) { Chris@52: m_document->deleteLayer(il); // also releases its model Chris@45: } Chris@45: return FileOpenFailed; Chris@45: } else { Chris@45: if (newLayer) { Chris@45: m_document->addLayerToView(pane, il); Chris@45: } Chris@45: m_paneStack->setCurrentLayer(pane, il); Chris@45: } Chris@45: Chris@45: return FileOpenSucceeded; Chris@45: } Chris@45: Chris@45: MainWindowBase::FileOpenStatus Chris@45: MainWindowBase::openSessionFile(QString fileOrUrl) Chris@45: { Chris@134: ProgressDialog dialog(tr("Opening session..."), true, 2000, this); Chris@134: connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash())); Chris@109: return openSession(FileSource(fileOrUrl, &dialog)); Chris@45: } Chris@45: Chris@45: MainWindowBase::FileOpenStatus Chris@45: MainWindowBase::openSession(FileSource source) Chris@45: { Chris@135: std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl; Chris@135: Chris@45: if (!source.isAvailable()) return FileOpenFailed; Chris@145: source.waitForData(); Chris@141: Chris@152: if (source.getExtension().toLower() != "sv") { Chris@145: Chris@145: RDFImporter::RDFDocumentType rdfType = Chris@145: RDFImporter::identifyDocumentType Chris@145: (QUrl::fromLocalFile(source.getLocalFilename()).toString()); Chris@145: Chris@148: // std::cerr << "RDF type: " << (int)rdfType << std::endl; Chris@148: Chris@145: if (rdfType == RDFImporter::AudioRefAndAnnotations || Chris@145: rdfType == RDFImporter::AudioRef) { Chris@145: return openSessionFromRDF(source); Chris@145: } else if (rdfType != RDFImporter::NotRDF) { Chris@145: return FileOpenFailed; Chris@145: } Chris@145: Chris@152: if (source.getExtension().toLower() == "xml") { Chris@140: if (SVFileReader::identifyXmlFile(source.getLocalFilename()) == Chris@140: SVFileReader::SVSessionFile) { Chris@140: std::cerr << "This XML file looks like a session file, attempting to open it as a session" << std::endl; Chris@140: } else { Chris@140: return FileOpenFailed; Chris@140: } Chris@140: } else { Chris@140: return FileOpenFailed; Chris@140: } Chris@140: } Chris@45: Chris@140: QXmlInputSource *inputSource = 0; Chris@140: BZipFileDevice *bzFile = 0; Chris@140: QFile *rawFile = 0; Chris@140: Chris@152: if (source.getExtension().toLower() == "sv") { Chris@140: bzFile = new BZipFileDevice(source.getLocalFilename()); Chris@140: if (!bzFile->open(QIODevice::ReadOnly)) { Chris@140: delete bzFile; Chris@140: return FileOpenFailed; Chris@140: } Chris@140: inputSource = new QXmlInputSource(bzFile); Chris@140: } else { Chris@140: rawFile = new QFile(source.getLocalFilename()); Chris@140: inputSource = new QXmlInputSource(rawFile); Chris@140: } Chris@140: Chris@140: if (!checkSaveModified()) { Chris@140: if (bzFile) bzFile->close(); Chris@140: delete inputSource; Chris@140: delete bzFile; Chris@140: delete rawFile; Chris@140: return FileOpenCancelled; Chris@140: } Chris@45: Chris@45: QString error; Chris@45: closeSession(); Chris@45: createDocument(); Chris@45: Chris@45: PaneCallback callback(this); Chris@45: m_viewManager->clearSelections(); Chris@45: Chris@45: SVFileReader reader(m_document, callback, source.getLocation()); Chris@79: connect Chris@79: (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)), Chris@79: this, SLOT(modelRegenerationFailed(QString, QString, QString))); Chris@79: connect Chris@79: (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)), Chris@79: this, SLOT(modelRegenerationWarning(QString, QString, QString))); Chris@140: Chris@140: reader.parse(*inputSource); Chris@45: Chris@45: if (!reader.isOK()) { Chris@45: error = tr("SV XML file read error:\n%1").arg(reader.getErrorString()); Chris@45: } Chris@45: Chris@140: if (bzFile) bzFile->close(); Chris@140: Chris@140: delete inputSource; Chris@140: delete bzFile; Chris@140: delete rawFile; Chris@45: Chris@45: bool ok = (error == ""); Chris@45: Chris@45: if (ok) { Chris@45: Chris@164: emit activity(tr("Import session file \"%1\"").arg(source.getLocation())); Chris@164: Chris@57: setWindowTitle(tr("%1: %2") Chris@57: .arg(QApplication::applicationName()) Chris@45: .arg(source.getLocation())); Chris@45: Chris@45: if (!source.isRemote()) m_sessionFile = source.getLocalFilename(); Chris@45: Chris@45: setupMenus(); Chris@45: Chris@45: CommandHistory::getInstance()->clear(); Chris@45: CommandHistory::getInstance()->documentSaved(); Chris@45: m_documentModified = false; Chris@45: updateMenuStates(); Chris@45: Chris@45: m_recentFiles.addFile(source.getLocation()); Chris@45: Chris@45: if (!source.isRemote()) { Chris@45: // for file dialog Chris@45: registerLastOpenedFilePath(FileFinder::SessionFile, Chris@45: source.getLocalFilename()); Chris@45: } Chris@45: Chris@45: } else { Chris@57: setWindowTitle(QApplication::applicationName()); Chris@45: } Chris@45: Chris@45: return ok ? FileOpenSucceeded : FileOpenFailed; Chris@45: } Chris@45: Chris@141: MainWindowBase::FileOpenStatus Chris@141: MainWindowBase::openSessionFromRDF(FileSource source) Chris@141: { Chris@141: std::cerr << "MainWindowBase::openSessionFromRDF(" << source.getLocation().toStdString() << ")" << std::endl; Chris@141: Chris@141: if (!source.isAvailable()) return FileOpenFailed; Chris@141: source.waitForData(); Chris@141: Chris@145: if (!checkSaveModified()) { Chris@145: return FileOpenCancelled; Chris@141: } Chris@143: Chris@145: closeSession(); Chris@145: createDocument(); Chris@145: Chris@145: FileOpenStatus status = openLayersFromRDF(source); Chris@141: Chris@141: setupMenus(); Chris@141: Chris@141: setWindowTitle(tr("%1: %2") Chris@141: .arg(QApplication::applicationName()) Chris@141: .arg(source.getLocation())); Chris@141: CommandHistory::getInstance()->clear(); Chris@141: CommandHistory::getInstance()->documentSaved(); Chris@141: m_documentModified = false; Chris@145: Chris@145: return status; Chris@145: } Chris@145: Chris@145: MainWindowBase::FileOpenStatus Chris@145: MainWindowBase::openLayersFromRDF(FileSource source) Chris@145: { Chris@145: size_t rate = 0; Chris@145: Chris@186: std::cerr << "MainWindowBase::openLayersFromRDF" << std::endl; Chris@186: Chris@145: ProgressDialog dialog(tr("Importing from RDF..."), true, 2000, this); Chris@145: connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash())); Chris@145: Chris@145: if (getMainModel()) { Chris@145: rate = getMainModel()->getSampleRate(); Chris@145: } else if (Preferences::getInstance()->getResampleOnLoad()) { Chris@145: rate = m_playSource->getSourceSampleRate(); Chris@145: } Chris@145: Chris@145: RDFImporter importer Chris@145: (QUrl::fromLocalFile(source.getLocalFilename()).toString(), rate); Chris@145: Chris@145: if (!importer.isOK()) { Chris@147: if (importer.getErrorString() != "") { Chris@147: QMessageBox::critical Chris@147: (this, tr("Failed to import RDF"), Chris@147: tr("Failed to import RDF

Importing data from RDF document at \"%1\" failed: %2

") Chris@147: .arg(source.getLocation()).arg(importer.getErrorString())); Chris@147: } Chris@145: return FileOpenFailed; Chris@145: } Chris@145: Chris@145: std::vector models = importer.getDataModels(&dialog); Chris@145: Chris@145: dialog.setMessage(tr("Importing from RDF...")); Chris@145: Chris@145: if (models.empty()) { Chris@186: QMessageBox::critical Chris@186: (this, tr("Failed to import RDF"), Chris@186: tr("Failed to import RDF

No suitable data models found for import from RDF document at \"%1\"

").arg(source.getLocation())); Chris@145: return FileOpenFailed; Chris@145: } Chris@145: Chris@164: emit activity(tr("Import RDF document \"%1\"").arg(source.getLocation())); Chris@164: Chris@145: std::set added; Chris@145: Chris@221: for (int i = 0; i < (int)models.size(); ++i) { Chris@145: Chris@145: Model *m = models[i]; Chris@145: WaveFileModel *w = dynamic_cast(m); Chris@145: Chris@145: if (w) { Chris@145: Chris@145: Pane *pane = addPaneToStack(); Chris@145: Layer *layer = 0; Chris@145: Chris@145: if (m_timeRulerLayer) { Chris@145: m_document->addLayerToView(pane, m_timeRulerLayer); Chris@145: } Chris@145: Chris@145: if (!getMainModel()) { Chris@145: m_document->setMainModel(w); Chris@145: layer = m_document->createMainModelLayer(LayerFactory::Waveform); Chris@145: } else { Chris@145: layer = m_document->createImportedLayer(w); Chris@145: } Chris@145: Chris@145: m_document->addLayerToView(pane, layer); Chris@145: Chris@145: added.insert(w); Chris@145: Chris@221: for (int j = 0; j < (int)models.size(); ++j) { Chris@145: Chris@145: Model *dm = models[j]; Chris@145: Chris@145: if (dm == m) continue; Chris@145: if (dm->getSourceModel() != m) continue; Chris@145: Chris@145: layer = m_document->createImportedLayer(dm); Chris@145: Chris@145: if (layer->isLayerOpaque() || Chris@145: dynamic_cast(layer)) { Chris@145: Chris@156: // these always go in a new pane, with nothing Chris@156: // else going in the same pane Chris@156: Chris@145: Pane *singleLayerPane = addPaneToStack(); Chris@145: if (m_timeRulerLayer) { Chris@145: m_document->addLayerToView(singleLayerPane, m_timeRulerLayer); Chris@145: } Chris@145: m_document->addLayerToView(singleLayerPane, layer); Chris@145: Chris@156: } else if (layer->getLayerColourSignificance() == Chris@156: Layer::ColourHasMeaningfulValue) { Chris@156: Chris@156: // these can go in a pane with something else, but Chris@156: // only if none of the something elses also have Chris@156: // this quality Chris@156: Chris@156: bool needNewPane = false; Chris@156: for (int i = 0; i < pane->getLayerCount(); ++i) { Chris@156: Layer *otherLayer = pane->getLayer(i); Chris@156: if (otherLayer && Chris@156: (otherLayer->getLayerColourSignificance() == Chris@156: Layer::ColourHasMeaningfulValue)) { Chris@156: needNewPane = true; Chris@156: break; Chris@156: } Chris@156: } Chris@156: if (needNewPane) { Chris@156: pane = addPaneToStack(); Chris@156: } Chris@156: Chris@156: m_document->addLayerToView(pane, layer); Chris@156: Chris@145: } else { Chris@145: Chris@145: if (pane->getLayerCount() > 4) { Chris@145: pane = addPaneToStack(); Chris@145: } Chris@145: Chris@145: m_document->addLayerToView(pane, layer); Chris@145: } Chris@145: Chris@145: added.insert(dm); Chris@145: } Chris@145: } Chris@145: } Chris@145: Chris@221: for (int i = 0; i < (int)models.size(); ++i) { Chris@145: Chris@145: Model *m = models[i]; Chris@145: Chris@145: if (added.find(m) == added.end()) { Chris@145: Chris@145: Layer *layer = m_document->createImportedLayer(m); Chris@145: if (!layer) return FileOpenFailed; Chris@145: Chris@145: Pane *singleLayerPane = addPaneToStack(); Chris@145: if (m_timeRulerLayer) { Chris@145: m_document->addLayerToView(singleLayerPane, m_timeRulerLayer); Chris@145: } Chris@145: m_document->addLayerToView(singleLayerPane, layer); Chris@145: } Chris@145: } Chris@145: Chris@145: m_recentFiles.addFile(source.getLocation()); Chris@145: return FileOpenSucceeded; Chris@141: } Chris@141: Chris@45: void Chris@45: MainWindowBase::createPlayTarget() Chris@45: { Chris@45: if (m_playTarget) return; Chris@45: Chris@126: QSettings settings; Chris@126: settings.beginGroup("Preferences"); Chris@126: QString targetName = settings.value("audio-target", "").toString(); Chris@126: settings.endGroup(); Chris@126: Chris@126: AudioTargetFactory *factory = AudioTargetFactory::getInstance(); Chris@126: Chris@126: factory->setDefaultCallbackTarget(targetName); Chris@126: m_playTarget = factory->createCallbackTarget(m_playSource); Chris@126: Chris@45: if (!m_playTarget) { Chris@104: emit hideSplash(); Chris@126: Chris@126: if (factory->isAutoCallbackTarget(targetName)) { Chris@128: QMessageBox::warning Chris@45: (this, tr("Couldn't open audio device"), Chris@126: tr("No audio available

Could not open an audio device for playback.

Automatic audio device detection failed. Audio playback will not be available during this session.

"), Chris@45: QMessageBox::Ok); Chris@126: } else { Chris@126: QMessageBox::warning Chris@126: (this, tr("Couldn't open audio device"), Chris@126: tr("No audio available

Failed to open your preferred audio device (\"%1\").

Audio playback will not be available during this session.

") Chris@126: .arg(factory->getCallbackTargetDescription(targetName)), Chris@126: QMessageBox::Ok); Chris@126: } Chris@45: } Chris@45: } Chris@45: Chris@45: WaveFileModel * Chris@45: MainWindowBase::getMainModel() Chris@45: { Chris@45: if (!m_document) return 0; Chris@45: return m_document->getMainModel(); Chris@45: } Chris@45: Chris@45: const WaveFileModel * Chris@45: MainWindowBase::getMainModel() const Chris@45: { Chris@45: if (!m_document) return 0; Chris@45: return m_document->getMainModel(); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::createDocument() Chris@45: { Chris@45: m_document = new Document; Chris@45: Chris@45: connect(m_document, SIGNAL(layerAdded(Layer *)), Chris@45: this, SLOT(layerAdded(Layer *))); Chris@45: connect(m_document, SIGNAL(layerRemoved(Layer *)), Chris@45: this, SLOT(layerRemoved(Layer *))); Chris@45: connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)), Chris@45: this, SLOT(layerAboutToBeDeleted(Layer *))); Chris@45: connect(m_document, SIGNAL(layerInAView(Layer *, bool)), Chris@45: this, SLOT(layerInAView(Layer *, bool))); Chris@45: Chris@45: connect(m_document, SIGNAL(modelAdded(Model *)), Chris@45: this, SLOT(modelAdded(Model *))); Chris@45: connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)), Chris@45: this, SLOT(mainModelChanged(WaveFileModel *))); Chris@45: connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)), Chris@45: this, SLOT(modelAboutToBeDeleted(Model *))); Chris@45: Chris@78: connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)), Chris@78: this, SLOT(modelGenerationFailed(QString, QString))); Chris@78: connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)), Chris@78: this, SLOT(modelRegenerationWarning(QString, QString, QString))); Chris@78: connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)), Chris@78: this, SLOT(modelGenerationFailed(QString, QString))); Chris@78: connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)), Chris@78: this, SLOT(modelRegenerationWarning(QString, QString, QString))); Chris@78: connect(m_document, SIGNAL(alignmentFailed(QString, QString)), Chris@78: this, SLOT(alignmentFailed(QString, QString))); Chris@160: Chris@160: emit replacedDocument(); Chris@45: } Chris@45: Chris@45: bool Chris@45: MainWindowBase::saveSessionFile(QString path) Chris@45: { Chris@217: try { Chris@217: Chris@217: TempWriteFile temp(path); Chris@217: Chris@217: BZipFileDevice bzFile(temp.getTemporaryFilename()); Chris@217: if (!bzFile.open(QIODevice::WriteOnly)) { Chris@217: std::cerr << "Failed to open session file \"" Chris@217: << temp.getTemporaryFilename().toStdString() Chris@217: << "\" for writing: " Chris@217: << bzFile.errorString().toStdString() << std::endl; Chris@217: return false; Chris@217: } Chris@217: Chris@217: QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); Chris@217: Chris@217: QTextStream out(&bzFile); Chris@217: toXml(out); Chris@217: out.flush(); Chris@217: Chris@217: QApplication::restoreOverrideCursor(); Chris@217: Chris@217: if (!bzFile.isOK()) { Chris@217: QMessageBox::critical(this, tr("Failed to write file"), Chris@217: tr("Save failed

Failed to write to file \"%1\": %2") Chris@217: .arg(path).arg(bzFile.errorString())); Chris@217: bzFile.close(); Chris@217: return false; Chris@217: } Chris@217: Chris@217: bzFile.close(); Chris@217: temp.moveToTarget(); Chris@217: return true; Chris@217: Chris@217: } catch (FileOperationFailed &f) { Chris@217: Chris@217: QMessageBox::critical(this, tr("Failed to write file"), Chris@217: tr("Save failed

Failed to write to file \"%1\": %2") Chris@217: .arg(path).arg(f.what())); Chris@45: return false; Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::toXml(QTextStream &out) Chris@45: { Chris@45: QString indent(" "); Chris@45: Chris@45: out << "\n"; Chris@45: out << "\n"; Chris@45: out << "\n"; Chris@45: Chris@45: m_document->toXml(out, "", ""); Chris@45: Chris@45: out << "\n"; Chris@45: Chris@45: out << QString(" \n") Chris@45: .arg(width()).arg(height()); Chris@45: Chris@45: for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { Chris@45: Chris@45: Pane *pane = m_paneStack->getPane(i); Chris@45: Chris@45: if (pane) { Chris@45: pane->toXml(out, indent); Chris@45: } Chris@45: } Chris@45: Chris@45: out << "\n"; Chris@45: Chris@45: m_viewManager->getSelection().toXml(out); Chris@45: Chris@45: out << "\n"; Chris@45: } Chris@45: Chris@45: Pane * Chris@45: MainWindowBase::addPaneToStack() Chris@45: { Chris@45: AddPaneCommand *command = new AddPaneCommand(this); Chris@45: CommandHistory::getInstance()->addCommand(command); Chris@57: Pane *pane = command->getPane(); Chris@57: return pane; Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::zoomIn() Chris@45: { Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (currentPane) currentPane->zoom(true); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::zoomOut() Chris@45: { Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (currentPane) currentPane->zoom(false); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::zoomToFit() Chris@45: { Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (!currentPane) return; Chris@45: Chris@45: Model *model = getMainModel(); Chris@45: if (!model) return; Chris@45: Chris@45: size_t start = model->getStartFrame(); Chris@45: size_t end = model->getEndFrame(); Chris@60: if (m_playSource) end = std::max(end, m_playSource->getPlayEndFrame()); Chris@45: size_t pixels = currentPane->width(); Chris@45: Chris@45: size_t sw = currentPane->getVerticalScaleWidth(); Chris@45: if (pixels > sw * 2) pixels -= sw * 2; Chris@45: else pixels = 1; Chris@45: if (pixels > 4) pixels -= 4; Chris@45: Chris@45: size_t zoomLevel = (end - start) / pixels; Chris@150: if (zoomLevel < 1) zoomLevel = 1; Chris@45: Chris@45: currentPane->setZoomLevel(zoomLevel); Chris@45: currentPane->setCentreFrame((start + end) / 2); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::zoomDefault() Chris@45: { Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (currentPane) currentPane->setZoomLevel(1024); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::scrollLeft() Chris@45: { Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (currentPane) currentPane->scroll(false, false); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::jumpLeft() Chris@45: { Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (currentPane) currentPane->scroll(false, true); Chris@45: } Chris@45: Chris@45: void Chris@162: MainWindowBase::peekLeft() Chris@162: { Chris@162: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@162: if (currentPane) currentPane->scroll(false, false, false); Chris@162: } Chris@162: Chris@162: void Chris@45: MainWindowBase::scrollRight() Chris@45: { Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (currentPane) currentPane->scroll(true, false); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::jumpRight() Chris@45: { Chris@45: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@45: if (currentPane) currentPane->scroll(true, true); Chris@45: } Chris@45: Chris@45: void Chris@162: MainWindowBase::peekRight() Chris@162: { Chris@162: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@162: if (currentPane) currentPane->scroll(true, false, false); Chris@162: } Chris@162: Chris@162: void Chris@45: MainWindowBase::showNoOverlays() Chris@45: { Chris@45: m_viewManager->setOverlayMode(ViewManager::NoOverlays); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::showMinimalOverlays() Chris@45: { Chris@45: m_viewManager->setOverlayMode(ViewManager::MinimalOverlays); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::showStandardOverlays() Chris@45: { Chris@45: m_viewManager->setOverlayMode(ViewManager::StandardOverlays); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::showAllOverlays() Chris@45: { Chris@45: m_viewManager->setOverlayMode(ViewManager::AllOverlays); Chris@45: } Chris@45: Chris@45: void Chris@211: MainWindowBase::toggleTimeRulers() Chris@211: { Chris@211: bool haveRulers = false; Chris@211: bool someHidden = false; Chris@211: Chris@211: for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { Chris@211: Chris@211: Pane *pane = m_paneStack->getPane(i); Chris@211: if (!pane) continue; Chris@211: Chris@211: for (int j = 0; j < pane->getLayerCount(); ++j) { Chris@211: Chris@211: Layer *layer = pane->getLayer(j); Chris@211: if (!dynamic_cast(layer)) continue; Chris@211: Chris@211: haveRulers = true; Chris@211: if (layer->isLayerDormant(pane)) someHidden = true; Chris@211: } Chris@211: } Chris@211: Chris@211: if (haveRulers) { Chris@211: Chris@211: bool show = someHidden; Chris@211: Chris@211: for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { Chris@211: Chris@211: Pane *pane = m_paneStack->getPane(i); Chris@211: if (!pane) continue; Chris@211: Chris@211: for (int j = 0; j < pane->getLayerCount(); ++j) { Chris@211: Chris@211: Layer *layer = pane->getLayer(j); Chris@211: if (!dynamic_cast(layer)) continue; Chris@211: Chris@211: layer->showLayer(pane, show); Chris@211: } Chris@211: } Chris@211: } Chris@211: } Chris@211: Chris@211: void Chris@45: MainWindowBase::toggleZoomWheels() Chris@45: { Chris@45: if (m_viewManager->getZoomWheelsEnabled()) { Chris@45: m_viewManager->setZoomWheelsEnabled(false); Chris@45: } else { Chris@45: m_viewManager->setZoomWheelsEnabled(true); Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::togglePropertyBoxes() Chris@45: { Chris@45: if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) { Chris@45: if (Preferences::getInstance()->getPropertyBoxLayout() == Chris@45: Preferences::VerticallyStacked) { Chris@45: m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout); Chris@45: } else { Chris@45: m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout); Chris@45: } Chris@45: } else { Chris@45: m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks); Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::toggleStatusBar() Chris@45: { Chris@45: QSettings settings; Chris@45: settings.beginGroup("MainWindow"); Chris@45: bool sb = settings.value("showstatusbar", true).toBool(); Chris@45: Chris@45: if (sb) { Chris@45: statusBar()->hide(); Chris@45: } else { Chris@45: statusBar()->show(); Chris@45: } Chris@45: Chris@45: settings.setValue("showstatusbar", !sb); Chris@45: Chris@45: settings.endGroup(); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::preferenceChanged(PropertyContainer::PropertyName name) Chris@45: { Chris@45: if (name == "Property Box Layout") { Chris@45: if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) { Chris@45: if (Preferences::getInstance()->getPropertyBoxLayout() == Chris@45: Preferences::VerticallyStacked) { Chris@45: m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout); Chris@45: } else { Chris@45: m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout); Chris@45: } Chris@45: } Chris@45: } else if (name == "Background Mode" && m_viewManager) { Chris@45: Preferences::BackgroundMode mode = Chris@45: Preferences::getInstance()->getBackgroundMode(); Chris@45: if (mode == Preferences::BackgroundFromTheme) { Chris@45: m_viewManager->setGlobalDarkBackground(m_initialDarkBackground); Chris@45: } else if (mode == Preferences::DarkBackground) { Chris@45: m_viewManager->setGlobalDarkBackground(true); Chris@45: } else { Chris@45: m_viewManager->setGlobalDarkBackground(false); Chris@45: } Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::play() Chris@45: { Chris@45: if (m_playSource->isPlaying()) { Chris@45: stop(); Chris@45: } else { Chris@45: playbackFrameChanged(m_viewManager->getPlaybackFrame()); Chris@45: m_playSource->play(m_viewManager->getPlaybackFrame()); Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::ffwd() Chris@45: { Chris@45: if (!getMainModel()) return; Chris@45: Chris@45: int frame = m_viewManager->getPlaybackFrame(); Chris@45: ++frame; Chris@45: Chris@85: Pane *pane = m_paneStack->getCurrentPane(); Chris@45: Layer *layer = getSnapLayer(); Chris@45: size_t sr = getMainModel()->getSampleRate(); Chris@45: Chris@45: if (!layer) { Chris@45: Chris@45: frame = RealTime::realTime2Frame Chris@45: (RealTime::frame2RealTime(frame, sr) + RealTime(2, 0), sr); Chris@45: if (frame > int(getMainModel()->getEndFrame())) { Chris@45: frame = getMainModel()->getEndFrame(); Chris@45: } Chris@45: Chris@45: } else { Chris@45: Chris@45: size_t resolution = 0; Chris@166: if (pane) frame = pane->alignFromReference(frame); Chris@85: if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(), Chris@85: frame, resolution, Layer::SnapRight)) { Chris@85: if (pane) frame = pane->alignToReference(frame); Chris@85: } else { Chris@45: frame = getMainModel()->getEndFrame(); Chris@45: } Chris@45: } Chris@45: Chris@45: if (frame < 0) frame = 0; Chris@45: Chris@45: if (m_viewManager->getPlaySelectionMode()) { Chris@45: frame = m_viewManager->constrainFrameToSelection(size_t(frame)); Chris@45: } Chris@45: Chris@45: m_viewManager->setPlaybackFrame(frame); Chris@166: Chris@166: if (frame == getMainModel()->getEndFrame() && Chris@166: m_playSource && Chris@166: m_playSource->isPlaying() && Chris@166: !m_viewManager->getPlayLoopMode()) { Chris@166: stop(); Chris@166: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::ffwdEnd() Chris@45: { Chris@45: if (!getMainModel()) return; Chris@45: Chris@139: if (m_playSource && Chris@139: m_playSource->isPlaying() && Chris@139: !m_viewManager->getPlayLoopMode()) { Chris@139: stop(); Chris@139: } Chris@139: Chris@45: size_t frame = getMainModel()->getEndFrame(); Chris@45: Chris@45: if (m_viewManager->getPlaySelectionMode()) { Chris@45: frame = m_viewManager->constrainFrameToSelection(frame); Chris@45: } Chris@45: Chris@45: m_viewManager->setPlaybackFrame(frame); Chris@45: } Chris@45: Chris@45: void Chris@166: MainWindowBase::ffwdSimilar() Chris@166: { Chris@166: if (!getMainModel()) return; Chris@166: Chris@166: Layer *layer = getSnapLayer(); Chris@166: if (!layer) { ffwd(); return; } Chris@166: Chris@166: Pane *pane = m_paneStack->getCurrentPane(); Chris@166: size_t sr = getMainModel()->getSampleRate(); Chris@166: Chris@166: int frame = m_viewManager->getPlaybackFrame(); Chris@166: Chris@166: size_t resolution = 0; Chris@166: if (pane) frame = pane->alignFromReference(frame); Chris@166: if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(), Chris@166: frame, resolution, Layer::SnapRight)) { Chris@166: if (pane) frame = pane->alignToReference(frame); Chris@166: } else { Chris@166: frame = getMainModel()->getEndFrame(); Chris@166: } Chris@166: Chris@166: if (frame < 0) frame = 0; Chris@166: Chris@166: if (m_viewManager->getPlaySelectionMode()) { Chris@166: frame = m_viewManager->constrainFrameToSelection(size_t(frame)); Chris@166: } Chris@166: Chris@166: m_viewManager->setPlaybackFrame(frame); Chris@166: Chris@166: if (frame == getMainModel()->getEndFrame() && Chris@166: m_playSource && Chris@166: m_playSource->isPlaying() && Chris@166: !m_viewManager->getPlayLoopMode()) { Chris@166: stop(); Chris@166: } Chris@166: } Chris@166: Chris@166: void Chris@45: MainWindowBase::rewind() Chris@45: { Chris@45: if (!getMainModel()) return; Chris@45: Chris@45: int frame = m_viewManager->getPlaybackFrame(); Chris@45: if (frame > 0) --frame; Chris@45: Chris@85: Pane *pane = m_paneStack->getCurrentPane(); Chris@45: Layer *layer = getSnapLayer(); Chris@45: size_t sr = getMainModel()->getSampleRate(); Chris@45: Chris@45: // when rewinding during playback, we want to allow a period Chris@45: // following a rewind target point at which the rewind will go to Chris@45: // the prior point instead of the immediately neighbouring one Chris@45: if (m_playSource && m_playSource->isPlaying()) { Chris@45: RealTime ct = RealTime::frame2RealTime(frame, sr); Chris@45: ct = ct - RealTime::fromSeconds(0.25); Chris@45: if (ct < RealTime::zeroTime) ct = RealTime::zeroTime; Chris@45: frame = RealTime::realTime2Frame(ct, sr); Chris@45: } Chris@45: Chris@45: if (!layer) { Chris@45: Chris@45: frame = RealTime::realTime2Frame Chris@45: (RealTime::frame2RealTime(frame, sr) - RealTime(2, 0), sr); Chris@45: if (frame < int(getMainModel()->getStartFrame())) { Chris@45: frame = getMainModel()->getStartFrame(); Chris@45: } Chris@45: Chris@45: } else { Chris@45: Chris@45: size_t resolution = 0; Chris@166: if (pane) frame = pane->alignFromReference(frame); Chris@85: if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(), Chris@85: frame, resolution, Layer::SnapLeft)) { Chris@85: if (pane) frame = pane->alignToReference(frame); Chris@85: } else { Chris@45: frame = getMainModel()->getStartFrame(); Chris@45: } Chris@45: } Chris@45: Chris@45: if (frame < 0) frame = 0; Chris@45: Chris@45: if (m_viewManager->getPlaySelectionMode()) { Chris@45: frame = m_viewManager->constrainFrameToSelection(size_t(frame)); Chris@45: } Chris@45: Chris@45: m_viewManager->setPlaybackFrame(frame); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::rewindStart() Chris@45: { Chris@45: if (!getMainModel()) return; Chris@45: Chris@45: size_t frame = getMainModel()->getStartFrame(); Chris@45: Chris@45: if (m_viewManager->getPlaySelectionMode()) { Chris@45: frame = m_viewManager->constrainFrameToSelection(frame); Chris@45: } Chris@45: Chris@45: m_viewManager->setPlaybackFrame(frame); Chris@45: } Chris@45: Chris@166: void Chris@166: MainWindowBase::rewindSimilar() Chris@166: { Chris@166: if (!getMainModel()) return; Chris@166: Chris@166: Layer *layer = getSnapLayer(); Chris@166: if (!layer) { rewind(); return; } Chris@166: Chris@166: Pane *pane = m_paneStack->getCurrentPane(); Chris@166: size_t sr = getMainModel()->getSampleRate(); Chris@166: Chris@166: int frame = m_viewManager->getPlaybackFrame(); Chris@166: Chris@166: size_t resolution = 0; Chris@166: if (pane) frame = pane->alignFromReference(frame); Chris@166: if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(), Chris@166: frame, resolution, Layer::SnapLeft)) { Chris@166: if (pane) frame = pane->alignToReference(frame); Chris@166: } else { Chris@166: frame = getMainModel()->getStartFrame(); Chris@166: } Chris@166: Chris@166: if (frame < 0) frame = 0; Chris@166: Chris@166: if (m_viewManager->getPlaySelectionMode()) { Chris@166: frame = m_viewManager->constrainFrameToSelection(size_t(frame)); Chris@166: } Chris@166: Chris@166: m_viewManager->setPlaybackFrame(frame); Chris@166: } Chris@166: Chris@45: Layer * Chris@45: MainWindowBase::getSnapLayer() const Chris@45: { Chris@45: Pane *pane = m_paneStack->getCurrentPane(); Chris@45: if (!pane) return 0; Chris@45: Chris@45: Layer *layer = pane->getSelectedLayer(); Chris@45: Chris@45: if (!dynamic_cast(layer) && Chris@45: !dynamic_cast(layer) && Chris@194: !dynamic_cast(layer) && Chris@45: !dynamic_cast(layer)) { Chris@45: Chris@45: layer = 0; Chris@45: Chris@45: for (int i = pane->getLayerCount(); i > 0; --i) { Chris@45: Layer *l = pane->getLayer(i-1); Chris@45: if (dynamic_cast(l)) { Chris@45: layer = l; Chris@45: break; Chris@45: } Chris@45: } Chris@45: } Chris@45: Chris@45: return layer; Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::stop() Chris@45: { Chris@45: m_playSource->stop(); Chris@45: Chris@45: if (m_paneStack && m_paneStack->getCurrentPane()) { Chris@45: updateVisibleRangeDisplay(m_paneStack->getCurrentPane()); Chris@45: } else { Chris@45: m_myStatusMessage = ""; Chris@45: statusBar()->showMessage(""); Chris@45: } Chris@45: } Chris@45: Chris@45: MainWindowBase::AddPaneCommand::AddPaneCommand(MainWindowBase *mw) : Chris@45: m_mw(mw), Chris@45: m_pane(0), Chris@45: m_prevCurrentPane(0), Chris@45: m_added(false) Chris@45: { Chris@45: } Chris@45: Chris@45: MainWindowBase::AddPaneCommand::~AddPaneCommand() Chris@45: { Chris@45: if (m_pane && !m_added) { Chris@45: m_mw->m_paneStack->deletePane(m_pane); Chris@45: } Chris@45: } Chris@45: Chris@45: QString Chris@45: MainWindowBase::AddPaneCommand::getName() const Chris@45: { Chris@45: return tr("Add Pane"); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::AddPaneCommand::execute() Chris@45: { Chris@45: if (!m_pane) { Chris@45: m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane(); Chris@45: m_pane = m_mw->m_paneStack->addPane(); Chris@45: Chris@45: connect(m_pane, SIGNAL(contextHelpChanged(const QString &)), Chris@45: m_mw, SLOT(contextHelpChanged(const QString &))); Chris@45: } else { Chris@45: m_mw->m_paneStack->showPane(m_pane); Chris@45: } Chris@45: Chris@45: m_mw->m_paneStack->setCurrentPane(m_pane); Chris@45: m_added = true; Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::AddPaneCommand::unexecute() Chris@45: { Chris@45: m_mw->m_paneStack->hidePane(m_pane); Chris@45: m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane); Chris@45: m_added = false; Chris@45: } Chris@45: Chris@45: MainWindowBase::RemovePaneCommand::RemovePaneCommand(MainWindowBase *mw, Pane *pane) : Chris@45: m_mw(mw), Chris@45: m_pane(pane), Chris@45: m_added(true) Chris@45: { Chris@45: } Chris@45: Chris@45: MainWindowBase::RemovePaneCommand::~RemovePaneCommand() Chris@45: { Chris@45: if (m_pane && !m_added) { Chris@45: m_mw->m_paneStack->deletePane(m_pane); Chris@45: } Chris@45: } Chris@45: Chris@45: QString Chris@45: MainWindowBase::RemovePaneCommand::getName() const Chris@45: { Chris@45: return tr("Remove Pane"); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::RemovePaneCommand::execute() Chris@45: { Chris@45: m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane(); Chris@45: m_mw->m_paneStack->hidePane(m_pane); Chris@45: m_added = false; Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::RemovePaneCommand::unexecute() Chris@45: { Chris@45: m_mw->m_paneStack->showPane(m_pane); Chris@45: m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane); Chris@45: m_added = true; Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::deleteCurrentPane() Chris@45: { Chris@45: CommandHistory::getInstance()->startCompoundOperation Chris@45: (tr("Delete Pane"), true); Chris@45: Chris@45: Pane *pane = m_paneStack->getCurrentPane(); Chris@45: if (pane) { Chris@45: while (pane->getLayerCount() > 0) { Chris@45: Layer *layer = pane->getLayer(0); Chris@45: if (layer) { Chris@45: m_document->removeLayerFromView(pane, layer); Chris@45: } else { Chris@45: break; Chris@45: } Chris@45: } Chris@45: Chris@45: RemovePaneCommand *command = new RemovePaneCommand(this, pane); Chris@45: CommandHistory::getInstance()->addCommand(command); Chris@45: } Chris@45: Chris@45: CommandHistory::getInstance()->endCompoundOperation(); Chris@45: Chris@45: updateMenuStates(); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::deleteCurrentLayer() Chris@45: { Chris@45: Pane *pane = m_paneStack->getCurrentPane(); Chris@45: if (pane) { Chris@45: Layer *layer = pane->getSelectedLayer(); Chris@45: if (layer) { Chris@45: m_document->removeLayerFromView(pane, layer); Chris@45: } Chris@45: } Chris@45: updateMenuStates(); Chris@45: } Chris@45: Chris@45: void Chris@123: MainWindowBase::editCurrentLayer() Chris@123: { Chris@123: Layer *layer = 0; Chris@123: Pane *pane = m_paneStack->getCurrentPane(); Chris@123: if (pane) layer = pane->getSelectedLayer(); Chris@123: if (!layer) return; Chris@123: Chris@123: Model *model = layer->getModel(); Chris@123: if (!model) return; Chris@123: Chris@124: TabularModel *tabular = dynamic_cast(model); Chris@124: if (!tabular) { Chris@124: //!!! how to prevent this function from being active if not Chris@124: //appropriate model type? or will we ultimately support Chris@124: //tabular display for all editable models? Chris@124: std::cerr << "NOTE: Not a tabular model" << std::endl; Chris@124: return; Chris@124: } Chris@124: Chris@123: if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) { Chris@126: if (!m_layerDataDialogMap[layer].isNull()) { Chris@126: m_layerDataDialogMap[layer]->show(); Chris@126: m_layerDataDialogMap[layer]->raise(); Chris@126: return; Chris@126: } Chris@123: } Chris@123: Chris@125: QString title = layer->getLayerPresentationName(); Chris@125: Chris@125: ModelDataTableDialog *dialog = new ModelDataTableDialog(tabular, title, this); Chris@128: dialog->setAttribute(Qt::WA_DeleteOnClose); Chris@128: Chris@128: connectLayerEditDialog(dialog); Chris@123: Chris@128: m_layerDataDialogMap[layer] = dialog; Chris@128: m_viewDataDialogMap[pane].insert(dialog); Chris@128: Chris@128: dialog->show(); Chris@128: } Chris@128: Chris@128: void Chris@128: MainWindowBase::connectLayerEditDialog(ModelDataTableDialog *dialog) Chris@128: { Chris@123: connect(m_viewManager, Chris@123: SIGNAL(globalCentreFrameChanged(unsigned long)), Chris@123: dialog, Chris@127: SLOT(userScrolledToFrame(unsigned long))); Chris@127: Chris@127: connect(m_viewManager, Chris@127: SIGNAL(playbackFrameChanged(unsigned long)), Chris@127: dialog, Chris@127: SLOT(playbackScrolledToFrame(unsigned long))); Chris@127: Chris@123: connect(dialog, Chris@123: SIGNAL(scrollToFrame(unsigned long)), Chris@123: m_viewManager, Chris@123: SLOT(setGlobalCentreFrame(unsigned long))); Chris@129: Chris@129: connect(dialog, Chris@129: SIGNAL(scrollToFrame(unsigned long)), Chris@129: m_viewManager, Chris@129: SLOT(setPlaybackFrame(unsigned long))); Chris@128: } Chris@123: Chris@123: void Chris@73: MainWindowBase::previousPane() Chris@73: { Chris@73: if (!m_paneStack) return; Chris@73: Chris@73: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@73: if (!currentPane) return; Chris@73: Chris@73: for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { Chris@73: if (m_paneStack->getPane(i) == currentPane) { Chris@73: if (i == 0) return; Chris@73: m_paneStack->setCurrentPane(m_paneStack->getPane(i-1)); Chris@73: updateMenuStates(); Chris@73: return; Chris@73: } Chris@73: } Chris@73: } Chris@73: Chris@73: void Chris@73: MainWindowBase::nextPane() Chris@73: { Chris@73: if (!m_paneStack) return; Chris@73: Chris@73: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@73: if (!currentPane) return; Chris@73: Chris@73: for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { Chris@73: if (m_paneStack->getPane(i) == currentPane) { Chris@73: if (i == m_paneStack->getPaneCount()-1) return; Chris@73: m_paneStack->setCurrentPane(m_paneStack->getPane(i+1)); Chris@73: updateMenuStates(); Chris@73: return; Chris@73: } Chris@73: } Chris@73: } Chris@73: Chris@73: void Chris@73: MainWindowBase::previousLayer() Chris@73: { Chris@73: //!!! Not right -- pane lists layers in stacking order Chris@73: Chris@73: if (!m_paneStack) return; Chris@73: Chris@73: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@73: if (!currentPane) return; Chris@73: Chris@73: Layer *currentLayer = currentPane->getSelectedLayer(); Chris@73: if (!currentLayer) return; Chris@73: Chris@73: for (int i = 0; i < currentPane->getLayerCount(); ++i) { Chris@73: if (currentPane->getLayer(i) == currentLayer) { Chris@73: if (i == 0) return; Chris@73: m_paneStack->setCurrentLayer(currentPane, Chris@73: currentPane->getLayer(i-1)); Chris@73: updateMenuStates(); Chris@73: return; Chris@73: } Chris@73: } Chris@73: } Chris@73: Chris@73: void Chris@73: MainWindowBase::nextLayer() Chris@73: { Chris@73: //!!! Not right -- pane lists layers in stacking order Chris@73: Chris@73: if (!m_paneStack) return; Chris@73: Chris@73: Pane *currentPane = m_paneStack->getCurrentPane(); Chris@73: if (!currentPane) return; Chris@73: Chris@73: Layer *currentLayer = currentPane->getSelectedLayer(); Chris@73: if (!currentLayer) return; Chris@73: Chris@73: for (int i = 0; i < currentPane->getLayerCount(); ++i) { Chris@73: if (currentPane->getLayer(i) == currentLayer) { Chris@73: if (i == currentPane->getLayerCount()-1) return; Chris@73: m_paneStack->setCurrentLayer(currentPane, Chris@73: currentPane->getLayer(i+1)); Chris@73: updateMenuStates(); Chris@73: return; Chris@73: } Chris@73: } Chris@73: } Chris@73: Chris@73: void Chris@45: MainWindowBase::playbackFrameChanged(unsigned long frame) Chris@45: { Chris@45: if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return; Chris@45: Chris@187: updatePositionStatusDisplays(); Chris@187: Chris@45: RealTime now = RealTime::frame2RealTime Chris@45: (frame, getMainModel()->getSampleRate()); Chris@45: Chris@45: if (now.sec == m_lastPlayStatusSec) return; Chris@45: Chris@45: RealTime then = RealTime::frame2RealTime Chris@45: (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate()); Chris@45: Chris@45: QString nowStr; Chris@45: QString thenStr; Chris@45: QString remainingStr; Chris@45: Chris@45: if (then.sec > 10) { Chris@45: nowStr = now.toSecText().c_str(); Chris@45: thenStr = then.toSecText().c_str(); Chris@45: remainingStr = (then - now).toSecText().c_str(); Chris@45: m_lastPlayStatusSec = now.sec; Chris@45: } else { Chris@45: nowStr = now.toText(true).c_str(); Chris@45: thenStr = then.toText(true).c_str(); Chris@45: remainingStr = (then - now).toText(true).c_str(); Chris@45: } Chris@45: Chris@45: m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)") Chris@45: .arg(nowStr).arg(thenStr).arg(remainingStr); Chris@45: Chris@45: statusBar()->showMessage(m_myStatusMessage); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::globalCentreFrameChanged(unsigned long ) Chris@45: { Chris@45: if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return; Chris@45: Pane *p = 0; Chris@45: if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return; Chris@45: if (!p->getFollowGlobalPan()) return; Chris@45: updateVisibleRangeDisplay(p); Chris@45: } Chris@45: Chris@45: void Chris@123: MainWindowBase::viewCentreFrameChanged(View *v, unsigned long frame) Chris@45: { Chris@130: // std::cerr << "MainWindowBase::viewCentreFrameChanged(" << v << "," << frame << ")" << std::endl; Chris@123: Chris@123: if (m_viewDataDialogMap.find(v) != m_viewDataDialogMap.end()) { Chris@123: for (DataDialogSet::iterator i = m_viewDataDialogMap[v].begin(); Chris@123: i != m_viewDataDialogMap[v].end(); ++i) { Chris@127: (*i)->userScrolledToFrame(frame); Chris@123: } Chris@123: } Chris@45: if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return; Chris@45: Pane *p = 0; Chris@45: if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return; Chris@45: if (v == p) updateVisibleRangeDisplay(p); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::viewZoomLevelChanged(View *v, unsigned long , bool ) Chris@45: { Chris@45: if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return; Chris@45: Pane *p = 0; Chris@45: if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return; Chris@45: if (v == p) updateVisibleRangeDisplay(p); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::layerAdded(Layer *) Chris@45: { Chris@45: // std::cerr << "MainWindowBase::layerAdded(" << layer << ")" << std::endl; Chris@45: updateMenuStates(); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::layerRemoved(Layer *) Chris@45: { Chris@45: // std::cerr << "MainWindowBase::layerRemoved(" << layer << ")" << std::endl; Chris@45: updateMenuStates(); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::layerAboutToBeDeleted(Layer *layer) Chris@45: { Chris@132: // std::cerr << "MainWindowBase::layerAboutToBeDeleted(" << layer << ")" << std::endl; Chris@123: Chris@128: removeLayerEditDialog(layer); Chris@123: Chris@47: if (m_timeRulerLayer && (layer == m_timeRulerLayer)) { Chris@45: // std::cerr << "(this is the time ruler layer)" << std::endl; Chris@45: m_timeRulerLayer = 0; Chris@45: } Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::layerInAView(Layer *layer, bool inAView) Chris@45: { Chris@132: // std::cerr << "MainWindowBase::layerInAView(" << layer << "," << inAView << ")" << std::endl; Chris@128: Chris@128: if (!inAView) removeLayerEditDialog(layer); Chris@45: Chris@45: // Check whether we need to add or remove model from play source Chris@45: Model *model = layer->getModel(); Chris@45: if (model) { Chris@45: if (inAView) { Chris@45: m_playSource->addModel(model); Chris@45: } else { Chris@45: bool found = false; Chris@45: for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { Chris@45: Pane *pane = m_paneStack->getPane(i); Chris@45: if (!pane) continue; Chris@45: for (int j = 0; j < pane->getLayerCount(); ++j) { Chris@45: Layer *pl = pane->getLayer(j); Chris@183: if (pl && Chris@183: !dynamic_cast(pl) && Chris@183: (pl->getModel() == model)) { Chris@45: found = true; Chris@45: break; Chris@45: } Chris@45: } Chris@45: if (found) break; Chris@45: } Chris@173: if (!found) { Chris@173: m_playSource->removeModel(model); Chris@173: } Chris@45: } Chris@45: } Chris@45: Chris@45: updateMenuStates(); Chris@45: } Chris@45: Chris@45: void Chris@128: MainWindowBase::removeLayerEditDialog(Layer *layer) Chris@128: { Chris@128: if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) { Chris@128: Chris@128: ModelDataTableDialog *dialog = m_layerDataDialogMap[layer]; Chris@128: Chris@128: for (ViewDataDialogMap::iterator vi = m_viewDataDialogMap.begin(); Chris@128: vi != m_viewDataDialogMap.end(); ++vi) { Chris@128: vi->second.erase(dialog); Chris@128: } Chris@128: Chris@128: m_layerDataDialogMap.erase(layer); Chris@128: delete dialog; Chris@128: } Chris@128: } Chris@128: Chris@128: void Chris@45: MainWindowBase::modelAdded(Model *model) Chris@45: { Chris@45: // std::cerr << "MainWindowBase::modelAdded(" << model << ")" << std::endl; Chris@45: m_playSource->addModel(model); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::mainModelChanged(WaveFileModel *model) Chris@45: { Chris@45: // std::cerr << "MainWindowBase::mainModelChanged(" << model << ")" << std::endl; Chris@45: updateDescriptionLabel(); Chris@45: if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate()); Chris@45: if (model && !m_playTarget && m_audioOutput) createPlayTarget(); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::modelAboutToBeDeleted(Model *model) Chris@45: { Chris@45: // std::cerr << "MainWindowBase::modelAboutToBeDeleted(" << model << ")" << std::endl; Chris@45: if (model == m_viewManager->getPlaybackModel()) { Chris@45: m_viewManager->setPlaybackModel(0); Chris@45: } Chris@45: m_playSource->removeModel(model); Chris@45: FFTDataServer::modelAboutToBeDeleted(model); Chris@45: } Chris@45: Chris@45: void Chris@55: MainWindowBase::paneDeleteButtonClicked(Pane *pane) Chris@55: { Chris@55: bool found = false; Chris@55: for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { Chris@55: if (m_paneStack->getPane(i) == pane) { Chris@55: found = true; Chris@55: break; Chris@55: } Chris@55: } Chris@55: if (!found) { Chris@55: std::cerr << "MainWindowBase::paneDeleteButtonClicked: Unknown pane " Chris@55: << pane << std::endl; Chris@55: return; Chris@55: } Chris@55: Chris@55: CommandHistory::getInstance()->startCompoundOperation Chris@55: (tr("Delete Pane"), true); Chris@55: Chris@55: while (pane->getLayerCount() > 0) { Chris@55: Layer *layer = pane->getLayer(0); Chris@55: if (layer) { Chris@55: m_document->removeLayerFromView(pane, layer); Chris@55: } else { Chris@55: break; Chris@55: } Chris@55: } Chris@55: Chris@55: RemovePaneCommand *command = new RemovePaneCommand(this, pane); Chris@55: CommandHistory::getInstance()->addCommand(command); Chris@55: Chris@55: CommandHistory::getInstance()->endCompoundOperation(); Chris@55: Chris@55: updateMenuStates(); Chris@55: } Chris@55: Chris@55: void Chris@45: MainWindowBase::pollOSC() Chris@45: { Chris@45: if (!m_oscQueue || m_oscQueue->isEmpty()) return; Chris@45: std::cerr << "MainWindowBase::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl; Chris@45: Chris@45: if (m_openingAudioFile) return; Chris@45: Chris@45: OSCMessage message = m_oscQueue->readMessage(); Chris@45: Chris@45: if (message.getTarget() != 0) { Chris@45: return; //!!! for now -- this class is target 0, others not handled yet Chris@45: } Chris@45: Chris@45: handleOSCMessage(message); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::inProgressSelectionChanged() Chris@45: { Chris@45: Pane *currentPane = 0; Chris@45: if (m_paneStack) currentPane = m_paneStack->getCurrentPane(); Chris@45: if (currentPane) updateVisibleRangeDisplay(currentPane); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::contextHelpChanged(const QString &s) Chris@45: { Chris@45: if (s == "" && m_myStatusMessage != "") { Chris@45: statusBar()->showMessage(m_myStatusMessage); Chris@45: return; Chris@45: } Chris@45: statusBar()->showMessage(s); Chris@45: } Chris@45: Chris@45: void Chris@45: MainWindowBase::openHelpUrl(QString url) Chris@45: { Chris@45: // This method mostly lifted from Qt Assistant source code Chris@45: Chris@45: QProcess *process = new QProcess(this); Chris@45: connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater())); Chris@45: Chris@45: QStringList args; Chris@45: Chris@45: #ifdef Q_OS_MAC Chris@45: args.append(url); Chris@45: process->start("open", args); Chris@45: #else Chris@45: #ifdef Q_OS_WIN32 Chris@45: Chris@45: QString pf(getenv("ProgramFiles")); Chris@45: QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE"); Chris@45: Chris@45: args.append(url); Chris@45: process->start(command, args); Chris@45: Chris@45: #else Chris@45: #ifdef Q_WS_X11 Chris@45: if (!qgetenv("KDE_FULL_SESSION").isEmpty()) { Chris@45: args.append("exec"); Chris@45: args.append(url); Chris@45: process->start("kfmclient", args); Chris@45: } else if (!qgetenv("BROWSER").isEmpty()) { Chris@45: args.append(url); Chris@45: process->start(qgetenv("BROWSER"), args); Chris@45: } else { Chris@45: args.append(url); Chris@45: process->start("firefox", args); Chris@45: } Chris@45: #endif Chris@45: #endif Chris@45: #endif Chris@45: } Chris@45: Chris@180: