| Chris@0 | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */ | 
| Chris@0 | 2 | 
| Chris@0 | 3 /* | 
| Chris@0 | 4     Sonic Visualiser | 
| Chris@0 | 5     An audio file viewer and annotation editor. | 
| Chris@0 | 6     Centre for Digital Music, Queen Mary, University of London. | 
| Chris@77 | 7     This file copyright 2006 Chris Cannam and QMUL. | 
| Chris@0 | 8 | 
| Chris@0 | 9     This program is free software; you can redistribute it and/or | 
| Chris@0 | 10     modify it under the terms of the GNU General Public License as | 
| Chris@0 | 11     published by the Free Software Foundation; either version 2 of the | 
| Chris@0 | 12     License, or (at your option) any later version.  See the file | 
| Chris@0 | 13     COPYING included with this distribution for more information. | 
| Chris@0 | 14 */ | 
| Chris@0 | 15 | 
| Chris@1 | 16 #include "version.h" | 
| Chris@0 | 17 | 
| Chris@0 | 18 #include "MainWindow.h" | 
| Chris@1 | 19 #include "document/Document.h" | 
| Chris@0 | 20 #include "PreferencesDialog.h" | 
| Chris@0 | 21 | 
| Chris@1 | 22 #include "view/Pane.h" | 
| Chris@1 | 23 #include "view/PaneStack.h" | 
| Chris@1 | 24 #include "data/model/WaveFileModel.h" | 
| Chris@1 | 25 #include "data/model/SparseOneDimensionalModel.h" | 
| Chris@1 | 26 #include "view/ViewManager.h" | 
| Chris@0 | 27 #include "base/Preferences.h" | 
| Chris@0 | 28 #include "layer/WaveformLayer.h" | 
| Chris@0 | 29 #include "layer/TimeRulerLayer.h" | 
| Chris@0 | 30 #include "layer/TimeInstantLayer.h" | 
| Chris@0 | 31 #include "layer/TimeValueLayer.h" | 
| Chris@0 | 32 #include "layer/Colour3DPlotLayer.h" | 
| Chris@95 | 33 #include "layer/SliceLayer.h" | 
| Chris@95 | 34 #include "layer/SliceableLayer.h" | 
| Chris@0 | 35 #include "widgets/Fader.h" | 
| Chris@65 | 36 #include "view/Overview.h" | 
| Chris@0 | 37 #include "widgets/PropertyBox.h" | 
| Chris@0 | 38 #include "widgets/PropertyStack.h" | 
| Chris@0 | 39 #include "widgets/AudioDial.h" | 
| Chris@0 | 40 #include "widgets/LayerTree.h" | 
| Chris@0 | 41 #include "widgets/ListInputDialog.h" | 
| Chris@36 | 42 #include "widgets/SubdividingMenu.h" | 
| Chris@90 | 43 #include "widgets/NotifyingPushButton.h" | 
| Chris@0 | 44 #include "audioio/AudioCallbackPlaySource.h" | 
| Chris@0 | 45 #include "audioio/AudioCallbackPlayTarget.h" | 
| Chris@0 | 46 #include "audioio/AudioTargetFactory.h" | 
| Chris@59 | 47 #include "audioio/PlaySpeedRangeMapper.h" | 
| Chris@1 | 48 #include "data/fileio/AudioFileReaderFactory.h" | 
| Chris@1 | 49 #include "data/fileio/DataFileReaderFactory.h" | 
| Chris@1 | 50 #include "data/fileio/WavFileWriter.h" | 
| Chris@1 | 51 #include "data/fileio/CSVFileWriter.h" | 
| Chris@1 | 52 #include "data/fileio/BZipFileDevice.h" | 
| Chris@85 | 53 #include "data/fileio/RemoteFile.h" | 
| Chris@91 | 54 #include "data/fft/FFTDataServer.h" | 
| Chris@1 | 55 #include "base/RecentFiles.h" | 
| Chris@0 | 56 #include "transform/TransformFactory.h" | 
| Chris@0 | 57 #include "base/PlayParameterRepository.h" | 
| Chris@0 | 58 #include "base/XmlExportable.h" | 
| Chris@0 | 59 #include "base/CommandHistory.h" | 
| Chris@0 | 60 #include "base/Profiler.h" | 
| Chris@0 | 61 #include "base/Clipboard.h" | 
| Chris@69 | 62 #include "osc/OSCQueue.h" | 
| Chris@0 | 63 | 
| Chris@0 | 64 // For version information | 
| Chris@0 | 65 #include "vamp/vamp.h" | 
| Chris@0 | 66 #include "vamp-sdk/PluginBase.h" | 
| Chris@0 | 67 #include "plugin/api/ladspa.h" | 
| Chris@0 | 68 #include "plugin/api/dssi.h" | 
| Chris@0 | 69 | 
| Chris@0 | 70 #include <QApplication> | 
| Chris@0 | 71 #include <QMessageBox> | 
| Chris@0 | 72 #include <QGridLayout> | 
| Chris@0 | 73 #include <QLabel> | 
| Chris@0 | 74 #include <QAction> | 
| Chris@0 | 75 #include <QMenuBar> | 
| Chris@0 | 76 #include <QToolBar> | 
| Chris@0 | 77 #include <QInputDialog> | 
| Chris@0 | 78 #include <QStatusBar> | 
| Chris@0 | 79 #include <QTreeView> | 
| Chris@0 | 80 #include <QFile> | 
| Chris@88 | 81 #include <QFileInfo> | 
| Chris@88 | 82 #include <QDir> | 
| Chris@0 | 83 #include <QTextStream> | 
| Chris@0 | 84 #include <QProcess> | 
| Chris@7 | 85 #include <QShortcut> | 
| Chris@5 | 86 #include <QSettings> | 
| Chris@11 | 87 #include <QDateTime> | 
| Chris@11 | 88 #include <QProcess> | 
| Chris@16 | 89 #include <QCheckBox> | 
| Chris@55 | 90 #include <QRegExp> | 
| Chris@0 | 91 | 
| Chris@0 | 92 #include <iostream> | 
| Chris@0 | 93 #include <cstdio> | 
| Chris@0 | 94 #include <errno.h> | 
| Chris@0 | 95 | 
| Chris@0 | 96 using std::cerr; | 
| Chris@0 | 97 using std::endl; | 
| Chris@0 | 98 | 
| Chris@33 | 99 using std::vector; | 
| Chris@33 | 100 using std::map; | 
| Chris@33 | 101 using std::set; | 
| Chris@33 | 102 | 
| Chris@0 | 103 | 
| Chris@70 | 104 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) : | 
| Chris@0 | 105     m_document(0), | 
| Chris@0 | 106     m_paneStack(0), | 
| Chris@0 | 107     m_viewManager(0), | 
| Chris@65 | 108     m_overview(0), | 
| Chris@0 | 109     m_timeRulerLayer(0), | 
| Chris@46 | 110     m_audioOutput(withAudioOutput), | 
| Chris@0 | 111     m_playSource(0), | 
| Chris@0 | 112     m_playTarget(0), | 
| Chris@70 | 113     m_oscQueue(withOSCSupport ? new OSCQueue() : 0), | 
| Chris@81 | 114     m_recentFiles("RecentFiles", 20), | 
| Chris@49 | 115     m_recentTransforms("RecentTransforms", 20), | 
| Chris@0 | 116     m_mainMenusCreated(false), | 
| Chris@0 | 117     m_paneMenu(0), | 
| Chris@0 | 118     m_layerMenu(0), | 
| Chris@34 | 119     m_transformsMenu(0), | 
| Chris@0 | 120     m_existingLayersMenu(0), | 
| Chris@95 | 121     m_sliceMenu(0), | 
| Chris@34 | 122     m_recentFilesMenu(0), | 
| Chris@34 | 123     m_recentTransformsMenu(0), | 
| Chris@0 | 124     m_rightButtonMenu(0), | 
| Chris@0 | 125     m_rightButtonLayerMenu(0), | 
| Chris@34 | 126     m_rightButtonTransformsMenu(0), | 
| Chris@0 | 127     m_documentModified(false), | 
| Chris@70 | 128     m_openingAudioFile(false), | 
| Chris@70 | 129     m_abandoning(false), | 
| Chris@0 | 130     m_preferencesDialog(0) | 
| Chris@0 | 131 { | 
| Chris@0 | 132     setWindowTitle(tr("Sonic Visualiser")); | 
| Chris@0 | 133 | 
| Chris@0 | 134     UnitDatabase::getInstance()->registerUnit("Hz"); | 
| Chris@0 | 135     UnitDatabase::getInstance()->registerUnit("dB"); | 
| Chris@0 | 136 | 
| Chris@0 | 137     connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()), | 
| Chris@0 | 138 	    this, SLOT(documentModified())); | 
| Chris@0 | 139     connect(CommandHistory::getInstance(), SIGNAL(documentRestored()), | 
| Chris@0 | 140 	    this, SLOT(documentRestored())); | 
| Chris@0 | 141 | 
| Chris@0 | 142     QFrame *frame = new QFrame; | 
| Chris@0 | 143     setCentralWidget(frame); | 
| Chris@0 | 144 | 
| Chris@0 | 145     QGridLayout *layout = new QGridLayout; | 
| Chris@0 | 146 | 
| Chris@0 | 147     m_viewManager = new ViewManager(); | 
| Chris@0 | 148     connect(m_viewManager, SIGNAL(selectionChanged()), | 
| Chris@0 | 149 	    this, SLOT(updateMenuStates())); | 
| Chris@117 | 150     connect(m_viewManager, SIGNAL(inProgressSelectionChanged()), | 
| Chris@117 | 151 	    this, SLOT(inProgressSelectionChanged())); | 
| Chris@0 | 152 | 
| Chris@0 | 153     m_descriptionLabel = new QLabel; | 
| Chris@0 | 154 | 
| Chris@0 | 155     m_paneStack = new PaneStack(frame, m_viewManager); | 
| Chris@0 | 156     connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)), | 
| Chris@0 | 157 	    this, SLOT(currentPaneChanged(Pane *))); | 
| Chris@0 | 158     connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)), | 
| Chris@0 | 159 	    this, SLOT(currentLayerChanged(Pane *, Layer *))); | 
| Chris@0 | 160     connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)), | 
| Chris@0 | 161             this, SLOT(rightButtonMenuRequested(Pane *, QPoint))); | 
| Chris@73 | 162     connect(m_paneStack, SIGNAL(propertyStacksResized()), | 
| Chris@73 | 163             this, SLOT(propertyStacksResized())); | 
| Chris@90 | 164     connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)), | 
| Chris@116 | 165             this, SLOT(contextHelpChanged(const QString &))); | 
| Chris@0 | 166 | 
| Chris@65 | 167     m_overview = new Overview(frame); | 
| Chris@65 | 168     m_overview->setViewManager(m_viewManager); | 
| Chris@65 | 169     m_overview->setFixedHeight(40); | 
| Chris@90 | 170     connect(m_overview, SIGNAL(contextHelpChanged(const QString &)), | 
| Chris@116 | 171             this, SLOT(contextHelpChanged(const QString &))); | 
| Chris@0 | 172 | 
| Chris@0 | 173     m_panLayer = new WaveformLayer; | 
| Chris@0 | 174     m_panLayer->setChannelMode(WaveformLayer::MergeChannels); | 
| Chris@0 | 175 //    m_panLayer->setScale(WaveformLayer::MeterScale); | 
| Chris@39 | 176 //    m_panLayer->setAutoNormalize(true); | 
| Chris@0 | 177     m_panLayer->setBaseColour(Qt::darkGreen); | 
| Chris@0 | 178     m_panLayer->setAggressiveCacheing(true); | 
| Chris@65 | 179     m_overview->addLayer(m_panLayer); | 
| Chris@0 | 180 | 
| Chris@0 | 181     m_playSource = new AudioCallbackPlaySource(m_viewManager); | 
| Chris@0 | 182 | 
| Chris@0 | 183     connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)), | 
| Chris@0 | 184 	    this,           SLOT(sampleRateMismatch(size_t, size_t, bool))); | 
| Chris@42 | 185     connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()), | 
| Chris@42 | 186             this,           SLOT(audioOverloadPluginDisabled())); | 
| Chris@0 | 187 | 
| Chris@0 | 188     m_fader = new Fader(frame, false); | 
| Chris@90 | 189     connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); | 
| Chris@90 | 190     connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); | 
| Chris@0 | 191 | 
| Chris@0 | 192     m_playSpeed = new AudioDial(frame); | 
| Chris@12 | 193     m_playSpeed->setMinimum(0); | 
| Chris@48 | 194     m_playSpeed->setMaximum(200); | 
| Chris@25 | 195     m_playSpeed->setValue(100); | 
| Chris@0 | 196     m_playSpeed->setFixedWidth(24); | 
| Chris@0 | 197     m_playSpeed->setFixedHeight(24); | 
| Chris@0 | 198     m_playSpeed->setNotchesVisible(true); | 
| Chris@25 | 199     m_playSpeed->setPageStep(10); | 
| Chris@60 | 200     m_playSpeed->setObjectName(tr("Playback Speedup")); | 
| Chris@25 | 201     m_playSpeed->setDefaultValue(100); | 
| Chris@59 | 202     m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200)); | 
| Chris@60 | 203     m_playSpeed->setShowToolTip(true); | 
| Chris@0 | 204     connect(m_playSpeed, SIGNAL(valueChanged(int)), | 
| Chris@0 | 205 	    this, SLOT(playSpeedChanged(int))); | 
| Chris@90 | 206     connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); | 
| Chris@90 | 207     connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); | 
| Chris@90 | 208 | 
| Chris@90 | 209     m_playSharpen = new NotifyingPushButton(frame); | 
| Chris@17 | 210     m_playSharpen->setToolTip(tr("Sharpen percussive transients")); | 
| Chris@26 | 211     m_playSharpen->setFixedSize(20, 20); | 
| Chris@26 | 212 //    m_playSharpen->setFlat(true); | 
| Chris@16 | 213     m_playSharpen->setEnabled(false); | 
| Chris@26 | 214     m_playSharpen->setCheckable(true); | 
| Chris@26 | 215     m_playSharpen->setChecked(false); | 
| Chris@26 | 216     m_playSharpen->setIcon(QIcon(":icons/sharpen.png")); | 
| Chris@26 | 217     connect(m_playSharpen, SIGNAL(clicked()), this, SLOT(playSharpenToggled())); | 
| Chris@90 | 218     connect(m_playSharpen, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); | 
| Chris@90 | 219     connect(m_playSharpen, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); | 
| Chris@90 | 220 | 
| Chris@90 | 221     m_playMono = new NotifyingPushButton(frame); | 
| Chris@26 | 222     m_playMono->setToolTip(tr("Run time stretcher in mono only")); | 
| Chris@26 | 223     m_playMono->setFixedSize(20, 20); | 
| Chris@26 | 224 //    m_playMono->setFlat(true); | 
| Chris@26 | 225     m_playMono->setEnabled(false); | 
| Chris@26 | 226     m_playMono->setCheckable(true); | 
| Chris@26 | 227     m_playMono->setChecked(false); | 
| Chris@26 | 228     m_playMono->setIcon(QIcon(":icons/mono.png")); | 
| Chris@26 | 229     connect(m_playMono, SIGNAL(clicked()), this, SLOT(playMonoToggled())); | 
| Chris@90 | 230     connect(m_playMono, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); | 
| Chris@90 | 231     connect(m_playMono, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); | 
| Chris@21 | 232 | 
| Chris@21 | 233     QSettings settings; | 
| Chris@21 | 234     settings.beginGroup("MainWindow"); | 
| Chris@24 | 235     m_playSharpen->setChecked(settings.value("playsharpen", true).toBool()); | 
| Chris@26 | 236     m_playMono->setChecked(settings.value("playmono", false).toBool()); | 
| Chris@21 | 237     settings.endGroup(); | 
| Chris@21 | 238 | 
| Chris@26 | 239     layout->addWidget(m_paneStack, 0, 0, 1, 5); | 
| Chris@65 | 240     layout->addWidget(m_overview, 1, 0); | 
| Chris@0 | 241     layout->addWidget(m_fader, 1, 1); | 
| Chris@0 | 242     layout->addWidget(m_playSpeed, 1, 2); | 
| Chris@16 | 243     layout->addWidget(m_playSharpen, 1, 3); | 
| Chris@26 | 244     layout->addWidget(m_playMono, 1, 4); | 
| Chris@16 | 245 | 
| Chris@16 | 246     layout->setColumnStretch(0, 10); | 
| Chris@16 | 247 | 
| Chris@0 | 248     frame->setLayout(layout); | 
| Chris@0 | 249 | 
| Chris@0 | 250     connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)), | 
| Chris@0 | 251 	    this, SLOT(outputLevelsChanged(float, float))); | 
| Chris@0 | 252 | 
| Chris@116 | 253     connect(m_viewManager, SIGNAL(playbackFrameChanged(unsigned long)), | 
| Chris@116 | 254             this, SLOT(playbackFrameChanged(unsigned long))); | 
| Chris@116 | 255 | 
| Chris@116 | 256     connect(m_viewManager, SIGNAL(globalCentreFrameChanged(unsigned long)), | 
| Chris@116 | 257             this, SLOT(globalCentreFrameChanged(unsigned long))); | 
| Chris@116 | 258 | 
| Chris@116 | 259     connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, unsigned long)), | 
| Chris@116 | 260             this, SLOT(viewCentreFrameChanged(View *, unsigned long))); | 
| Chris@116 | 261 | 
| Chris@116 | 262     connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, unsigned long, bool)), | 
| Chris@116 | 263             this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool))); | 
| Chris@116 | 264 | 
| Chris@0 | 265     connect(Preferences::getInstance(), | 
| Chris@0 | 266             SIGNAL(propertyChanged(PropertyContainer::PropertyName)), | 
| Chris@0 | 267             this, | 
| Chris@0 | 268             SLOT(preferenceChanged(PropertyContainer::PropertyName))); | 
| Chris@0 | 269 | 
| Chris@98 | 270 //    preferenceChanged("Property Box Layout"); | 
| Chris@98 | 271 | 
| Chris@70 | 272     if (m_oscQueue && m_oscQueue->isOK()) { | 
| Chris@69 | 273         connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC())); | 
| Chris@69 | 274         QTimer *oscTimer = new QTimer(this); | 
| Chris@69 | 275         connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC())); | 
| Chris@69 | 276         oscTimer->start(1000); | 
| Chris@69 | 277     } | 
| Chris@69 | 278 | 
| Chris@0 | 279     setupMenus(); | 
| Chris@0 | 280     setupToolbars(); | 
| Chris@0 | 281 | 
| Chris@90 | 282     statusBar(); | 
| Chris@0 | 283 | 
| Chris@0 | 284     newSession(); | 
| Chris@0 | 285 } | 
| Chris@0 | 286 | 
| Chris@0 | 287 MainWindow::~MainWindow() | 
| Chris@0 | 288 { | 
| Chris@70 | 289     if (!m_abandoning) { | 
| Chris@70 | 290         closeSession(); | 
| Chris@70 | 291     } | 
| Chris@0 | 292     delete m_playTarget; | 
| Chris@0 | 293     delete m_playSource; | 
| Chris@0 | 294     delete m_viewManager; | 
| Chris@69 | 295     delete m_oscQueue; | 
| Chris@0 | 296     Profiles::getInstance()->dump(); | 
| Chris@0 | 297 } | 
| Chris@0 | 298 | 
| Chris@81 | 299 QString | 
| Chris@88 | 300 MainWindow::getOpenFileName(FileFinder::FileType type) | 
| Chris@81 | 301 { | 
| Chris@88 | 302     FileFinder *ff = FileFinder::getInstance(); | 
| Chris@81 | 303     switch (type) { | 
| Chris@88 | 304     case FileFinder::SessionFile: | 
| Chris@88 | 305         return ff->getOpenFileName(type, m_sessionFile); | 
| Chris@88 | 306     case FileFinder::AudioFile: | 
| Chris@88 | 307         return ff->getOpenFileName(type, m_audioFile); | 
| Chris@88 | 308     case FileFinder::LayerFile: | 
| Chris@88 | 309         return ff->getOpenFileName(type, m_sessionFile); | 
| Chris@88 | 310     case FileFinder::SessionOrAudioFile: | 
| Chris@88 | 311         return ff->getOpenFileName(type, m_sessionFile); | 
| Chris@88 | 312     case FileFinder::AnyFile: | 
| Chris@88 | 313         if (getMainModel() != 0 && | 
| Chris@88 | 314             m_paneStack != 0 && | 
| Chris@88 | 315             m_paneStack->getCurrentPane() != 0) { // can import a layer | 
| Chris@88 | 316             return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile); | 
| Chris@81 | 317         } else { | 
| Chris@88 | 318             return ff->getOpenFileName(FileFinder::SessionOrAudioFile, | 
| Chris@88 | 319                                        m_sessionFile); | 
| Chris@81 | 320         } | 
| Chris@81 | 321     } | 
| Chris@88 | 322     return ""; | 
| Chris@88 | 323 } | 
| Chris@88 | 324 | 
| Chris@88 | 325 QString | 
| Chris@88 | 326 MainWindow::getSaveFileName(FileFinder::FileType type) | 
| Chris@88 | 327 { | 
| Chris@88 | 328     FileFinder *ff = FileFinder::getInstance(); | 
| Chris@88 | 329     switch (type) { | 
| Chris@88 | 330     case FileFinder::SessionFile: | 
| Chris@88 | 331         return ff->getSaveFileName(type, m_sessionFile); | 
| Chris@88 | 332     case FileFinder::AudioFile: | 
| Chris@88 | 333         return ff->getSaveFileName(type, m_audioFile); | 
| Chris@88 | 334     case FileFinder::LayerFile: | 
| Chris@88 | 335         return ff->getSaveFileName(type, m_sessionFile); | 
| Chris@88 | 336     case FileFinder::SessionOrAudioFile: | 
| Chris@88 | 337         return ff->getSaveFileName(type, m_sessionFile); | 
| Chris@88 | 338     case FileFinder::AnyFile: | 
| Chris@88 | 339         return ff->getSaveFileName(type, m_sessionFile); | 
| Chris@81 | 340     } | 
| Chris@88 | 341     return ""; | 
| Chris@81 | 342 } | 
| Chris@81 | 343 | 
| Chris@88 | 344 void | 
| Chris@88 | 345 MainWindow::registerLastOpenedFilePath(FileFinder::FileType type, QString path) | 
| Chris@81 | 346 { | 
| Chris@88 | 347     FileFinder *ff = FileFinder::getInstance(); | 
| Chris@88 | 348     ff->registerLastOpenedFilePath(type, path); | 
| Chris@81 | 349 } | 
| Chris@81 | 350 | 
| Chris@81 | 351 void | 
| Chris@0 | 352 MainWindow::setupMenus() | 
| Chris@0 | 353 { | 
| Chris@0 | 354     if (!m_mainMenusCreated) { | 
| Chris@0 | 355         m_rightButtonMenu = new QMenu(); | 
| Chris@104 | 356 | 
| Chris@104 | 357         // No -- we don't want tear-off enabled on the right-button | 
| Chris@104 | 358         // menu.  If it is enabled, then simply right-clicking and | 
| Chris@104 | 359         // releasing will pop up the menu, activate the tear-off, and | 
| Chris@104 | 360         // leave the torn-off menu window in front of the main window. | 
| Chris@104 | 361         // That isn't desirable.  I'm not sure it ever would be, in a | 
| Chris@104 | 362         // context menu -- perhaps technically a Qt bug? | 
| Chris@104 | 363 //        m_rightButtonMenu->setTearOffEnabled(true); | 
| Chris@0 | 364     } | 
| Chris@0 | 365 | 
| Chris@0 | 366     if (m_rightButtonLayerMenu) { | 
| Chris@0 | 367         m_rightButtonLayerMenu->clear(); | 
| Chris@0 | 368     } else { | 
| Chris@0 | 369         m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer")); | 
| Chris@97 | 370         m_rightButtonLayerMenu->setTearOffEnabled(true); | 
| Chris@0 | 371         m_rightButtonMenu->addSeparator(); | 
| Chris@0 | 372     } | 
| Chris@0 | 373 | 
| Chris@34 | 374     if (m_rightButtonTransformsMenu) { | 
| Chris@34 | 375         m_rightButtonTransformsMenu->clear(); | 
| Chris@34 | 376     } else { | 
| Chris@34 | 377         m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform")); | 
| Chris@97 | 378         m_rightButtonTransformsMenu->setTearOffEnabled(true); | 
| Chris@34 | 379         m_rightButtonMenu->addSeparator(); | 
| Chris@34 | 380     } | 
| Chris@34 | 381 | 
| Chris@0 | 382     if (!m_mainMenusCreated) { | 
| Chris@0 | 383         CommandHistory::getInstance()->registerMenu(m_rightButtonMenu); | 
| Chris@0 | 384         m_rightButtonMenu->addSeparator(); | 
| Chris@66 | 385     } | 
| Chris@66 | 386 | 
| Chris@66 | 387     setupFileMenu(); | 
| Chris@66 | 388     setupEditMenu(); | 
| Chris@66 | 389     setupViewMenu(); | 
| Chris@66 | 390     setupPaneAndLayerMenus(); | 
| Chris@66 | 391     setupTransformsMenu(); | 
| Chris@66 | 392     setupHelpMenu(); | 
| Chris@66 | 393 | 
| Chris@66 | 394     m_mainMenusCreated = true; | 
| Chris@66 | 395 } | 
| Chris@66 | 396 | 
| Chris@66 | 397 void | 
| Chris@66 | 398 MainWindow::setupFileMenu() | 
| Chris@66 | 399 { | 
| Chris@66 | 400     if (m_mainMenusCreated) return; | 
| Chris@66 | 401 | 
| Chris@66 | 402     QMenu *menu = menuBar()->addMenu(tr("&File")); | 
| Chris@97 | 403     menu->setTearOffEnabled(true); | 
| Chris@66 | 404     QToolBar *toolbar = addToolBar(tr("File Toolbar")); | 
| Chris@66 | 405 | 
| Chris@66 | 406     QIcon icon(":icons/filenew.png"); | 
| Chris@66 | 407     icon.addFile(":icons/filenew-22.png"); | 
| Chris@66 | 408     QAction *action = new QAction(icon, tr("&New Session"), this); | 
| Chris@66 | 409     action->setShortcut(tr("Ctrl+N")); | 
| Chris@90 | 410     action->setStatusTip(tr("Abandon the current Sonic Visualiser session and start a new one")); | 
| Chris@66 | 411     connect(action, SIGNAL(triggered()), this, SLOT(newSession())); | 
| Chris@66 | 412     menu->addAction(action); | 
| Chris@66 | 413     toolbar->addAction(action); | 
| Chris@0 | 414 | 
| Chris@66 | 415     icon = QIcon(":icons/fileopen.png"); | 
| Chris@66 | 416     icon.addFile(":icons/fileopen-22.png"); | 
| Chris@66 | 417 | 
| Chris@66 | 418     action = new QAction(icon, tr("&Open Session..."), this); | 
| Chris@66 | 419     action->setShortcut(tr("Ctrl+O")); | 
| Chris@66 | 420     action->setStatusTip(tr("Open a previously saved Sonic Visualiser session file")); | 
| Chris@66 | 421     connect(action, SIGNAL(triggered()), this, SLOT(openSession())); | 
| Chris@66 | 422     menu->addAction(action); | 
| Chris@66 | 423 | 
| Chris@66 | 424     action = new QAction(icon, tr("&Open..."), this); | 
| Chris@66 | 425     action->setStatusTip(tr("Open a session file, audio file, or layer")); | 
| Chris@66 | 426     connect(action, SIGNAL(triggered()), this, SLOT(openSomething())); | 
| Chris@66 | 427     toolbar->addAction(action); | 
| Chris@66 | 428 | 
| Chris@66 | 429     icon = QIcon(":icons/filesave.png"); | 
| Chris@66 | 430     icon.addFile(":icons/filesave-22.png"); | 
| Chris@66 | 431     action = new QAction(icon, tr("&Save Session"), this); | 
| Chris@66 | 432     action->setShortcut(tr("Ctrl+S")); | 
| Chris@66 | 433     action->setStatusTip(tr("Save the current session into a Sonic Visualiser session file")); | 
| Chris@66 | 434     connect(action, SIGNAL(triggered()), this, SLOT(saveSession())); | 
| Chris@66 | 435     connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 436     menu->addAction(action); | 
| Chris@66 | 437     toolbar->addAction(action); | 
| Chris@0 | 438 | 
| Chris@66 | 439     icon = QIcon(":icons/filesaveas.png"); | 
| Chris@66 | 440     icon.addFile(":icons/filesaveas-22.png"); | 
| Chris@66 | 441     action = new QAction(icon, tr("Save Session &As..."), this); | 
| Chris@66 | 442     action->setStatusTip(tr("Save the current session into a new Sonic Visualiser session file")); | 
| Chris@66 | 443     connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs())); | 
| Chris@66 | 444     menu->addAction(action); | 
| Chris@66 | 445     toolbar->addAction(action); | 
| Chris@66 | 446 | 
| Chris@66 | 447     menu->addSeparator(); | 
| Chris@66 | 448 | 
| Chris@66 | 449     action = new QAction(tr("&Import Audio File..."), this); | 
| Chris@66 | 450     action->setShortcut(tr("Ctrl+I")); | 
| Chris@66 | 451     action->setStatusTip(tr("Import an existing audio file")); | 
| Chris@66 | 452     connect(action, SIGNAL(triggered()), this, SLOT(importAudio())); | 
| Chris@66 | 453     menu->addAction(action); | 
| Chris@66 | 454 | 
| Chris@66 | 455     action = new QAction(tr("Import Secondary Audio File..."), this); | 
| Chris@66 | 456     action->setShortcut(tr("Ctrl+Shift+I")); | 
| Chris@66 | 457     action->setStatusTip(tr("Import an extra audio file as a separate layer")); | 
| Chris@66 | 458     connect(action, SIGNAL(triggered()), this, SLOT(importMoreAudio())); | 
| Chris@66 | 459     connect(this, SIGNAL(canImportMoreAudio(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 460     menu->addAction(action); | 
| Chris@66 | 461 | 
| Chris@66 | 462     action = new QAction(tr("&Export Audio File..."), this); | 
| Chris@66 | 463     action->setStatusTip(tr("Export selection as an audio file")); | 
| Chris@66 | 464     connect(action, SIGNAL(triggered()), this, SLOT(exportAudio())); | 
| Chris@66 | 465     connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 466     menu->addAction(action); | 
| Chris@66 | 467 | 
| Chris@66 | 468     menu->addSeparator(); | 
| Chris@66 | 469 | 
| Chris@66 | 470     action = new QAction(tr("Import Annotation &Layer..."), this); | 
| Chris@66 | 471     action->setShortcut(tr("Ctrl+L")); | 
| Chris@66 | 472     action->setStatusTip(tr("Import layer data from an existing file")); | 
| Chris@66 | 473     connect(action, SIGNAL(triggered()), this, SLOT(importLayer())); | 
| Chris@66 | 474     connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 475     menu->addAction(action); | 
| Chris@66 | 476 | 
| Chris@66 | 477     action = new QAction(tr("Export Annotation Layer..."), this); | 
| Chris@66 | 478     action->setStatusTip(tr("Export layer data to a file")); | 
| Chris@66 | 479     connect(action, SIGNAL(triggered()), this, SLOT(exportLayer())); | 
| Chris@66 | 480     connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 481     menu->addAction(action); | 
| Chris@66 | 482 | 
| Chris@66 | 483     menu->addSeparator(); | 
| Chris@86 | 484 | 
| Chris@86 | 485     action = new QAction(tr("Open Lo&cation..."), this); | 
| Chris@86 | 486     action->setShortcut(tr("Ctrl+Shift+O")); | 
| Chris@86 | 487     action->setStatusTip(tr("Open or import a file from a remote URL")); | 
| Chris@86 | 488     connect(action, SIGNAL(triggered()), this, SLOT(openLocation())); | 
| Chris@86 | 489     menu->addAction(action); | 
| Chris@86 | 490 | 
| Chris@86 | 491     menu->addSeparator(); | 
| Chris@86 | 492 | 
| Chris@66 | 493     m_recentFilesMenu = menu->addMenu(tr("&Recent Files")); | 
| Chris@97 | 494     m_recentFilesMenu->setTearOffEnabled(true); | 
| Chris@66 | 495     setupRecentFilesMenu(); | 
| Chris@66 | 496     connect(&m_recentFiles, SIGNAL(recentChanged()), | 
| Chris@66 | 497             this, SLOT(setupRecentFilesMenu())); | 
| Chris@66 | 498 | 
| Chris@66 | 499     menu->addSeparator(); | 
| Chris@66 | 500     action = new QAction(tr("&Preferences..."), this); | 
| Chris@66 | 501     action->setStatusTip(tr("Adjust the application preferences")); | 
| Chris@66 | 502     connect(action, SIGNAL(triggered()), this, SLOT(preferences())); | 
| Chris@66 | 503     menu->addAction(action); | 
| Chris@0 | 504 | 
| Chris@66 | 505     /*!!! | 
| Chris@66 | 506       menu->addSeparator(); | 
| Chris@0 | 507 | 
| Chris@66 | 508       action = new QAction(tr("Play / Pause"), this); | 
| Chris@66 | 509       action->setShortcut(tr("Space")); | 
| Chris@66 | 510       action->setStatusTip(tr("Start or stop playback from the current position")); | 
| Chris@66 | 511       connect(action, SIGNAL(triggered()), this, SLOT(play())); | 
| Chris@66 | 512       menu->addAction(action); | 
| Chris@66 | 513     */ | 
| Chris@66 | 514 | 
| Chris@66 | 515     menu->addSeparator(); | 
| Chris@66 | 516     action = new QAction(QIcon(":/icons/exit.png"), | 
| Chris@66 | 517                          tr("&Quit"), this); | 
| Chris@66 | 518     action->setShortcut(tr("Ctrl+Q")); | 
| Chris@90 | 519     action->setStatusTip(tr("Exit Sonic Visualiser")); | 
| Chris@66 | 520     connect(action, SIGNAL(triggered()), this, SLOT(close())); | 
| Chris@66 | 521     menu->addAction(action); | 
| Chris@66 | 522 } | 
| Chris@66 | 523 | 
| Chris@66 | 524 void | 
| Chris@66 | 525 MainWindow::setupEditMenu() | 
| Chris@66 | 526 { | 
| Chris@66 | 527     if (m_mainMenusCreated) return; | 
| Chris@66 | 528 | 
| Chris@66 | 529     QMenu *menu = menuBar()->addMenu(tr("&Edit")); | 
| Chris@97 | 530     menu->setTearOffEnabled(true); | 
| Chris@66 | 531     CommandHistory::getInstance()->registerMenu(menu); | 
| Chris@66 | 532 | 
| Chris@66 | 533     menu->addSeparator(); | 
| Chris@66 | 534 | 
| Chris@66 | 535     QAction *action = new QAction(QIcon(":/icons/editcut.png"), | 
| Chris@66 | 536                                   tr("Cu&t"), this); | 
| Chris@66 | 537     action->setShortcut(tr("Ctrl+X")); | 
| Chris@90 | 538     action->setStatusTip(tr("Cut the selection from the current layer to the clipboard")); | 
| Chris@66 | 539     connect(action, SIGNAL(triggered()), this, SLOT(cut())); | 
| Chris@66 | 540     connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 541     menu->addAction(action); | 
| Chris@66 | 542     m_rightButtonMenu->addAction(action); | 
| Chris@66 | 543 | 
| Chris@66 | 544     action = new QAction(QIcon(":/icons/editcopy.png"), | 
| Chris@66 | 545                          tr("&Copy"), this); | 
| Chris@66 | 546     action->setShortcut(tr("Ctrl+C")); | 
| Chris@90 | 547     action->setStatusTip(tr("Copy the selection from the current layer to the clipboard")); | 
| Chris@66 | 548     connect(action, SIGNAL(triggered()), this, SLOT(copy())); | 
| Chris@66 | 549     connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 550     menu->addAction(action); | 
| Chris@66 | 551     m_rightButtonMenu->addAction(action); | 
| Chris@66 | 552 | 
| Chris@66 | 553     action = new QAction(QIcon(":/icons/editpaste.png"), | 
| Chris@66 | 554                          tr("&Paste"), this); | 
| Chris@66 | 555     action->setShortcut(tr("Ctrl+V")); | 
| Chris@90 | 556     action->setStatusTip(tr("Paste from the clipboard to the current layer")); | 
| Chris@66 | 557     connect(action, SIGNAL(triggered()), this, SLOT(paste())); | 
| Chris@66 | 558     connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 559     menu->addAction(action); | 
| Chris@66 | 560     m_rightButtonMenu->addAction(action); | 
| Chris@66 | 561 | 
| Chris@66 | 562     action = new QAction(tr("&Delete Selected Items"), this); | 
| Chris@66 | 563     action->setShortcut(tr("Del")); | 
| Chris@90 | 564     action->setStatusTip(tr("Delete the selection from the current layer")); | 
| Chris@66 | 565     connect(action, SIGNAL(triggered()), this, SLOT(deleteSelected())); | 
| Chris@66 | 566     connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 567     menu->addAction(action); | 
| Chris@66 | 568     m_rightButtonMenu->addAction(action); | 
| Chris@66 | 569 | 
| Chris@66 | 570     menu->addSeparator(); | 
| Chris@66 | 571     m_rightButtonMenu->addSeparator(); | 
| Chris@0 | 572 | 
| Chris@66 | 573     action = new QAction(tr("Select &All"), this); | 
| Chris@66 | 574     action->setShortcut(tr("Ctrl+A")); | 
| Chris@90 | 575     action->setStatusTip(tr("Select the whole duration of the current session")); | 
| Chris@66 | 576     connect(action, SIGNAL(triggered()), this, SLOT(selectAll())); | 
| Chris@66 | 577     connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 578     menu->addAction(action); | 
| Chris@66 | 579     m_rightButtonMenu->addAction(action); | 
| Chris@0 | 580 | 
| Chris@66 | 581     action = new QAction(tr("Select &Visible Range"), this); | 
| Chris@66 | 582     action->setShortcut(tr("Ctrl+Shift+A")); | 
| Chris@90 | 583     action->setStatusTip(tr("Select the time range corresponding to the current window width")); | 
| Chris@66 | 584     connect(action, SIGNAL(triggered()), this, SLOT(selectVisible())); | 
| Chris@66 | 585     connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 586     menu->addAction(action); | 
| Chris@0 | 587 | 
| Chris@66 | 588     action = new QAction(tr("Select to &Start"), this); | 
| Chris@66 | 589     action->setShortcut(tr("Shift+Left")); | 
| Chris@90 | 590     action->setStatusTip(tr("Select from the start of the session to the current playback position")); | 
| Chris@66 | 591     connect(action, SIGNAL(triggered()), this, SLOT(selectToStart())); | 
| Chris@66 | 592     connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 593     menu->addAction(action); | 
| Chris@0 | 594 | 
| Chris@66 | 595     action = new QAction(tr("Select to &End"), this); | 
| Chris@66 | 596     action->setShortcut(tr("Shift+Right")); | 
| Chris@90 | 597     action->setStatusTip(tr("Select from the current playback position to the end of the session")); | 
| Chris@66 | 598     connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd())); | 
| Chris@66 | 599     connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 600     menu->addAction(action); | 
| Chris@66 | 601 | 
| Chris@66 | 602     action = new QAction(tr("C&lear Selection"), this); | 
| Chris@66 | 603     action->setShortcut(tr("Esc")); | 
| Chris@90 | 604     action->setStatusTip(tr("Clear the selection")); | 
| Chris@66 | 605     connect(action, SIGNAL(triggered()), this, SLOT(clearSelection())); | 
| Chris@66 | 606     connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 607     menu->addAction(action); | 
| Chris@66 | 608     m_rightButtonMenu->addAction(action); | 
| Chris@66 | 609 | 
| Chris@66 | 610     menu->addSeparator(); | 
| Chris@66 | 611 | 
| Chris@66 | 612     action = new QAction(tr("&Insert Instant at Playback Position"), this); | 
| Chris@66 | 613     action->setShortcut(tr("Enter")); | 
| Chris@90 | 614     action->setStatusTip(tr("Insert a new time instant at the current playback position, in a new layer if necessary")); | 
| Chris@66 | 615     connect(action, SIGNAL(triggered()), this, SLOT(insertInstant())); | 
| Chris@66 | 616     connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 617     menu->addAction(action); | 
| Chris@66 | 618 | 
| Chris@81 | 619     action = new QAction(tr("Insert Instants at Selection &Boundaries"), this); | 
| Chris@81 | 620     action->setShortcut(tr("Shift+Enter")); | 
| Chris@90 | 621     action->setStatusTip(tr("Insert new time instants at the start and end of the current selection, in a new layer if necessary")); | 
| Chris@81 | 622     connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries())); | 
| Chris@81 | 623     connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@81 | 624     menu->addAction(action); | 
| Chris@81 | 625 | 
| Chris@66 | 626     // Laptop shortcut (no keypad Enter key) | 
| Chris@66 | 627     connect(new QShortcut(tr(";"), this), SIGNAL(activated()), | 
| Chris@66 | 628             this, SLOT(insertInstant())); | 
| Chris@66 | 629 } | 
| Chris@66 | 630 | 
| Chris@66 | 631 void | 
| Chris@66 | 632 MainWindow::setupViewMenu() | 
| Chris@66 | 633 { | 
| Chris@66 | 634     if (m_mainMenusCreated) return; | 
| Chris@66 | 635 | 
| Chris@90 | 636     QAction *action = 0; | 
| Chris@90 | 637 | 
| Chris@66 | 638     QMenu *menu = menuBar()->addMenu(tr("&View")); | 
| Chris@97 | 639     menu->setTearOffEnabled(true); | 
| Chris@66 | 640     action = new QAction(tr("Scroll &Left"), this); | 
| Chris@66 | 641     action->setShortcut(tr("Left")); | 
| Chris@66 | 642     action->setStatusTip(tr("Scroll the current pane to the left")); | 
| Chris@66 | 643     connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft())); | 
| Chris@66 | 644     connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 645     menu->addAction(action); | 
| Chris@0 | 646 | 
| Chris@66 | 647     action = new QAction(tr("Scroll &Right"), this); | 
| Chris@66 | 648     action->setShortcut(tr("Right")); | 
| Chris@66 | 649     action->setStatusTip(tr("Scroll the current pane to the right")); | 
| Chris@66 | 650     connect(action, SIGNAL(triggered()), this, SLOT(scrollRight())); | 
| Chris@66 | 651     connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 652     menu->addAction(action); | 
| Chris@0 | 653 | 
| Chris@90 | 654     action = new QAction(tr("&Jump Left"), this); | 
| Chris@66 | 655     action->setShortcut(tr("Ctrl+Left")); | 
| Chris@66 | 656     action->setStatusTip(tr("Scroll the current pane a big step to the left")); | 
| Chris@66 | 657     connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft())); | 
| Chris@66 | 658     connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 659     menu->addAction(action); | 
| Chris@0 | 660 | 
| Chris@90 | 661     action = new QAction(tr("J&ump Right"), this); | 
| Chris@66 | 662     action->setShortcut(tr("Ctrl+Right")); | 
| Chris@66 | 663     action->setStatusTip(tr("Scroll the current pane a big step to the right")); | 
| Chris@66 | 664     connect(action, SIGNAL(triggered()), this, SLOT(jumpRight())); | 
| Chris@66 | 665     connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 666     menu->addAction(action); | 
| Chris@66 | 667 | 
| Chris@66 | 668     menu->addSeparator(); | 
| Chris@66 | 669 | 
| Chris@66 | 670     action = new QAction(QIcon(":/icons/zoom-in.png"), | 
| Chris@66 | 671                          tr("Zoom &In"), this); | 
| Chris@66 | 672     action->setShortcut(tr("Up")); | 
| Chris@66 | 673     action->setStatusTip(tr("Increase the zoom level")); | 
| Chris@66 | 674     connect(action, SIGNAL(triggered()), this, SLOT(zoomIn())); | 
| Chris@66 | 675     connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 676     menu->addAction(action); | 
| Chris@0 | 677 | 
| Chris@66 | 678     action = new QAction(QIcon(":/icons/zoom-out.png"), | 
| Chris@66 | 679                          tr("Zoom &Out"), this); | 
| Chris@66 | 680     action->setShortcut(tr("Down")); | 
| Chris@66 | 681     action->setStatusTip(tr("Decrease the zoom level")); | 
| Chris@66 | 682     connect(action, SIGNAL(triggered()), this, SLOT(zoomOut())); | 
| Chris@66 | 683     connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 684     menu->addAction(action); | 
| Chris@0 | 685 | 
| Chris@66 | 686     action = new QAction(tr("Restore &Default Zoom"), this); | 
| Chris@90 | 687     action->setStatusTip(tr("Restore the zoom level to the default")); | 
| Chris@66 | 688     connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault())); | 
| Chris@66 | 689     connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 690     menu->addAction(action); | 
| Chris@66 | 691 | 
| Chris@66 | 692     action = new QAction(tr("Zoom to &Fit"), this); | 
| Chris@66 | 693     action->setStatusTip(tr("Zoom to show the whole file")); | 
| Chris@66 | 694     connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit())); | 
| Chris@66 | 695     connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 696     menu->addAction(action); | 
| Chris@90 | 697 | 
| Chris@90 | 698     menu->addSeparator(); | 
| Chris@90 | 699 | 
| Chris@90 | 700     QActionGroup *overlayGroup = new QActionGroup(this); | 
| Chris@90 | 701 | 
| Chris@90 | 702     action = new QAction(tr("Show &No Overlays"), this); | 
| Chris@90 | 703     action->setShortcut(tr("0")); | 
| Chris@90 | 704     action->setStatusTip(tr("Hide centre indicator, frame times, layer names and scale")); | 
| Chris@90 | 705     connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays())); | 
| Chris@90 | 706     action->setCheckable(true); | 
| Chris@90 | 707     action->setChecked(false); | 
| Chris@90 | 708     overlayGroup->addAction(action); | 
| Chris@90 | 709     menu->addAction(action); | 
| Chris@90 | 710 | 
| Chris@90 | 711     action = new QAction(tr("Show &Minimal Overlays"), this); | 
| Chris@90 | 712     action->setShortcut(tr("9")); | 
| Chris@90 | 713     action->setStatusTip(tr("Show centre indicator only")); | 
| Chris@90 | 714     connect(action, SIGNAL(triggered()), this, SLOT(showMinimalOverlays())); | 
| Chris@90 | 715     action->setCheckable(true); | 
| Chris@90 | 716     action->setChecked(false); | 
| Chris@90 | 717     overlayGroup->addAction(action); | 
| Chris@90 | 718     menu->addAction(action); | 
| Chris@90 | 719 | 
| Chris@90 | 720     action = new QAction(tr("Show &Standard Overlays"), this); | 
| Chris@90 | 721     action->setShortcut(tr("8")); | 
| Chris@90 | 722     action->setStatusTip(tr("Show centre indicator, frame times and scale")); | 
| Chris@90 | 723     connect(action, SIGNAL(triggered()), this, SLOT(showStandardOverlays())); | 
| Chris@90 | 724     action->setCheckable(true); | 
| Chris@90 | 725     action->setChecked(true); | 
| Chris@90 | 726     overlayGroup->addAction(action); | 
| Chris@90 | 727     menu->addAction(action); | 
| Chris@90 | 728 | 
| Chris@90 | 729     action = new QAction(tr("Show &All Overlays"), this); | 
| Chris@90 | 730     action->setShortcut(tr("7")); | 
| Chris@90 | 731     action->setStatusTip(tr("Show all texts and scale")); | 
| Chris@90 | 732     connect(action, SIGNAL(triggered()), this, SLOT(showAllOverlays())); | 
| Chris@90 | 733     action->setCheckable(true); | 
| Chris@90 | 734     action->setChecked(false); | 
| Chris@90 | 735     overlayGroup->addAction(action); | 
| Chris@90 | 736     menu->addAction(action); | 
| Chris@7 | 737 | 
| Chris@72 | 738     menu->addSeparator(); | 
| Chris@72 | 739 | 
| Chris@66 | 740     action = new QAction(tr("Show &Zoom Wheels"), this); | 
| Chris@66 | 741     action->setShortcut(tr("Z")); | 
| Chris@66 | 742     action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically")); | 
| Chris@66 | 743     connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels())); | 
| Chris@66 | 744     action->setCheckable(true); | 
| Chris@66 | 745     action->setChecked(m_viewManager->getZoomWheelsEnabled()); | 
| Chris@66 | 746     menu->addAction(action); | 
| Chris@72 | 747 | 
| Chris@72 | 748     action = new QAction(tr("Show Property Bo&xes"), this); | 
| Chris@72 | 749     action->setShortcut(tr("X")); | 
| Chris@72 | 750     action->setStatusTip(tr("Show the layer property boxes at the side of the main window")); | 
| Chris@72 | 751     connect(action, SIGNAL(triggered()), this, SLOT(togglePropertyBoxes())); | 
| Chris@72 | 752     action->setCheckable(true); | 
| Chris@72 | 753     action->setChecked(true); | 
| Chris@72 | 754     menu->addAction(action); | 
| Chris@0 | 755 | 
| Chris@90 | 756     action = new QAction(tr("Show Status &Bar"), this); | 
| Chris@90 | 757     action->setStatusTip(tr("Show context help information in the status bar at the bottom of the window")); | 
| Chris@90 | 758     connect(action, SIGNAL(triggered()), this, SLOT(toggleStatusBar())); | 
| Chris@90 | 759     action->setCheckable(true); | 
| Chris@90 | 760     action->setChecked(true); | 
| Chris@90 | 761     menu->addAction(action); | 
| Chris@90 | 762 | 
| Chris@90 | 763     QSettings settings; | 
| Chris@90 | 764     settings.beginGroup("MainWindow"); | 
| Chris@90 | 765     bool sb = settings.value("showstatusbar", true).toBool(); | 
| Chris@90 | 766     if (!sb) { | 
| Chris@90 | 767         action->setChecked(false); | 
| Chris@90 | 768         statusBar()->hide(); | 
| Chris@90 | 769     } | 
| Chris@90 | 770     settings.endGroup(); | 
| Chris@90 | 771 | 
| Chris@0 | 772 /*!!! This one doesn't work properly yet | 
| Chris@90 | 773 | 
| Chris@66 | 774     menu->addSeparator(); | 
| Chris@66 | 775 | 
| Chris@90 | 776     action = new QAction(tr("Show La&yer Hierarchy"), this); | 
| Chris@66 | 777     action->setShortcut(tr("Alt+L")); | 
| Chris@90 | 778     action->setStatusTip(tr("Open a window displaying the hierarchy of panes and layers in this session")); | 
| Chris@66 | 779     connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree())); | 
| Chris@66 | 780     menu->addAction(action); | 
| Chris@90 | 781  */ | 
| Chris@66 | 782 } | 
| Chris@66 | 783 | 
| Chris@66 | 784 void | 
| Chris@66 | 785 MainWindow::setupPaneAndLayerMenus() | 
| Chris@66 | 786 { | 
| Chris@0 | 787     if (m_paneMenu) { | 
| Chris@0 | 788 	m_paneActions.clear(); | 
| Chris@0 | 789 	m_paneMenu->clear(); | 
| Chris@0 | 790     } else { | 
| Chris@0 | 791 	m_paneMenu = menuBar()->addMenu(tr("&Pane")); | 
| Chris@97 | 792         m_paneMenu->setTearOffEnabled(true); | 
| Chris@0 | 793     } | 
| Chris@0 | 794 | 
| Chris@0 | 795     if (m_layerMenu) { | 
| Chris@0 | 796 	m_layerActions.clear(); | 
| Chris@0 | 797 	m_layerMenu->clear(); | 
| Chris@0 | 798     } else { | 
| Chris@0 | 799 	m_layerMenu = menuBar()->addMenu(tr("&Layer")); | 
| Chris@97 | 800         m_layerMenu->setTearOffEnabled(true); | 
| Chris@0 | 801     } | 
| Chris@0 | 802 | 
| Chris@66 | 803     QMenu *menu = m_paneMenu; | 
| Chris@66 | 804 | 
| Chris@66 | 805     QAction *action = new QAction(QIcon(":/icons/pane.png"), tr("Add &New Pane"), this); | 
| Chris@66 | 806     action->setShortcut(tr("Alt+N")); | 
| Chris@66 | 807     action->setStatusTip(tr("Add a new pane containing only a time ruler")); | 
| Chris@66 | 808     connect(action, SIGNAL(triggered()), this, SLOT(addPane())); | 
| Chris@66 | 809     connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 810     m_paneActions[action] = PaneConfiguration(LayerFactory::TimeRuler); | 
| Chris@66 | 811     menu->addAction(action); | 
| Chris@66 | 812 | 
| Chris@66 | 813     menu->addSeparator(); | 
| Chris@66 | 814 | 
| Chris@66 | 815     menu = m_layerMenu; | 
| Chris@66 | 816 | 
| Chris@66 | 817 //    menu->addSeparator(); | 
| Chris@66 | 818 | 
| Chris@66 | 819     LayerFactory::LayerTypeSet emptyLayerTypes = | 
| Chris@66 | 820 	LayerFactory::getInstance()->getValidEmptyLayerTypes(); | 
| Chris@66 | 821 | 
| Chris@66 | 822     for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin(); | 
| Chris@66 | 823 	 i != emptyLayerTypes.end(); ++i) { | 
| Chris@66 | 824 | 
| Chris@66 | 825 	QIcon icon; | 
| Chris@66 | 826 	QString mainText, tipText, channelText; | 
| Chris@66 | 827 	LayerFactory::LayerType type = *i; | 
| Chris@66 | 828 	QString name = LayerFactory::getInstance()->getLayerPresentationName(type); | 
| Chris@66 | 829 | 
| Chris@66 | 830 	icon = QIcon(QString(":/icons/%1.png") | 
| Chris@66 | 831 		     .arg(LayerFactory::getInstance()->getLayerIconName(type))); | 
| Chris@66 | 832 | 
| Chris@66 | 833 	mainText = tr("Add New %1 Layer").arg(name); | 
| Chris@66 | 834 	tipText = tr("Add a new empty layer of type %1").arg(name); | 
| Chris@66 | 835 | 
| Chris@66 | 836 	action = new QAction(icon, mainText, this); | 
| Chris@66 | 837 	action->setStatusTip(tipText); | 
| Chris@66 | 838 | 
| Chris@66 | 839 	if (type == LayerFactory::Text) { | 
| Chris@66 | 840 	    action->setShortcut(tr("Alt+T")); | 
| Chris@66 | 841 	} | 
| Chris@66 | 842 | 
| Chris@66 | 843 	connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 
| Chris@66 | 844 	connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 845 	m_layerActions[action] = type; | 
| Chris@66 | 846 	menu->addAction(action); | 
| Chris@66 | 847         m_rightButtonLayerMenu->addAction(action); | 
| Chris@66 | 848     } | 
| Chris@66 | 849 | 
| Chris@66 | 850     m_rightButtonLayerMenu->addSeparator(); | 
| Chris@66 | 851     menu->addSeparator(); | 
| Chris@66 | 852 | 
| Chris@66 | 853     LayerFactory::LayerType backgroundTypes[] = { | 
| Chris@66 | 854 	LayerFactory::Waveform, | 
| Chris@66 | 855 	LayerFactory::Spectrogram, | 
| Chris@66 | 856 	LayerFactory::MelodicRangeSpectrogram, | 
| Chris@66 | 857 	LayerFactory::PeakFrequencySpectrogram, | 
| Chris@66 | 858         LayerFactory::Spectrum | 
| Chris@66 | 859     }; | 
| Chris@66 | 860 | 
| Chris@66 | 861     std::vector<Model *> models; | 
| Chris@66 | 862     if (m_document) models = m_document->getTransformInputModels(); //!!! not well named for this! | 
| Chris@66 | 863     bool plural = (models.size() > 1); | 
| Chris@66 | 864     if (models.empty()) { | 
| Chris@67 | 865         models.push_back(getMainModel()); // probably 0 | 
| Chris@66 | 866     } | 
| Chris@66 | 867 | 
| Chris@66 | 868     for (unsigned int i = 0; | 
| Chris@66 | 869 	 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) { | 
| Chris@66 | 870 | 
| Chris@66 | 871 	for (int menuType = 0; menuType <= 1; ++menuType) { // pane, layer | 
| Chris@66 | 872 | 
| Chris@66 | 873 	    if (menuType == 0) menu = m_paneMenu; | 
| Chris@66 | 874 	    else menu = m_layerMenu; | 
| Chris@66 | 875 | 
| Chris@66 | 876 	    QMenu *submenu = 0; | 
| Chris@66 | 877 | 
| Chris@66 | 878             QIcon icon; | 
| Chris@66 | 879             QString mainText, shortcutText, tipText, channelText; | 
| Chris@66 | 880             LayerFactory::LayerType type = backgroundTypes[i]; | 
| Chris@66 | 881             bool mono = true; | 
| Chris@66 | 882 | 
| Chris@66 | 883             switch (type) { | 
| Chris@66 | 884 | 
| Chris@66 | 885             case LayerFactory::Waveform: | 
| Chris@66 | 886                 icon = QIcon(":/icons/waveform.png"); | 
| Chris@66 | 887                 mainText = tr("Add &Waveform"); | 
| Chris@66 | 888                 if (menuType == 0) { | 
| Chris@66 | 889                     shortcutText = tr("Alt+W"); | 
| Chris@66 | 890                     tipText = tr("Add a new pane showing a waveform view"); | 
| Chris@66 | 891                 } else { | 
| Chris@66 | 892                     tipText = tr("Add a new layer showing a waveform view"); | 
| Chris@66 | 893                 } | 
| Chris@66 | 894                 mono = false; | 
| Chris@66 | 895                 break; | 
| Chris@66 | 896 | 
| Chris@66 | 897             case LayerFactory::Spectrogram: | 
| Chris@67 | 898                 icon = QIcon(":/icons/spectrogram.png"); | 
| Chris@66 | 899                 mainText = tr("Add &Spectrogram"); | 
| Chris@66 | 900                 if (menuType == 0) { | 
| Chris@66 | 901                     shortcutText = tr("Alt+S"); | 
| Chris@90 | 902                     tipText = tr("Add a new pane showing a spectrogram"); | 
| Chris@66 | 903                 } else { | 
| Chris@90 | 904                     tipText = tr("Add a new layer showing a spectrogram"); | 
| Chris@66 | 905                 } | 
| Chris@66 | 906                 break; | 
| Chris@66 | 907 | 
| Chris@66 | 908             case LayerFactory::MelodicRangeSpectrogram: | 
| Chris@67 | 909                 icon = QIcon(":/icons/spectrogram.png"); | 
| Chris@66 | 910                 mainText = tr("Add &Melodic Range Spectrogram"); | 
| Chris@66 | 911                 if (menuType == 0) { | 
| Chris@66 | 912                     shortcutText = tr("Alt+M"); | 
| Chris@90 | 913                     tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches"); | 
| Chris@66 | 914                 } else { | 
| Chris@90 | 915                     tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches"); | 
| Chris@66 | 916                 } | 
| Chris@66 | 917                 break; | 
| Chris@66 | 918 | 
| Chris@66 | 919             case LayerFactory::PeakFrequencySpectrogram: | 
| Chris@67 | 920                 icon = QIcon(":/icons/spectrogram.png"); | 
| Chris@66 | 921                 mainText = tr("Add &Peak Frequency Spectrogram"); | 
| Chris@66 | 922                 if (menuType == 0) { | 
| Chris@66 | 923                     shortcutText = tr("Alt+P"); | 
| Chris@66 | 924                     tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies"); | 
| Chris@66 | 925                 } else { | 
| Chris@66 | 926                     tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies"); | 
| Chris@66 | 927                 } | 
| Chris@66 | 928                 break; | 
| Chris@66 | 929 | 
| Chris@66 | 930             case LayerFactory::Spectrum: | 
| Chris@67 | 931                 icon = QIcon(":/icons/spectrum.png"); | 
| Chris@66 | 932                 mainText = tr("Add Spectr&um"); | 
| Chris@66 | 933                 if (menuType == 0) { | 
| Chris@66 | 934                     shortcutText = tr("Alt+U"); | 
| Chris@66 | 935                     tipText = tr("Add a new pane showing a frequency spectrum"); | 
| Chris@66 | 936                 } else { | 
| Chris@66 | 937                     tipText = tr("Add a new layer showing a frequency spectrum"); | 
| Chris@66 | 938                 } | 
| Chris@66 | 939                 break; | 
| Chris@66 | 940 | 
| Chris@66 | 941             default: break; | 
| Chris@66 | 942             } | 
| Chris@66 | 943 | 
| Chris@66 | 944             std::vector<Model *> candidateModels; | 
| Chris@66 | 945             if (menuType == 0) { | 
| Chris@66 | 946                 candidateModels = models; | 
| Chris@66 | 947             } else { | 
| Chris@66 | 948                 candidateModels.push_back(0); | 
| Chris@66 | 949             } | 
| Chris@66 | 950 | 
| Chris@66 | 951             for (std::vector<Model *>::iterator mi = | 
| Chris@66 | 952                      candidateModels.begin(); | 
| Chris@66 | 953                  mi != candidateModels.end(); ++mi) { | 
| Chris@66 | 954 | 
| Chris@66 | 955                 Model *model = *mi; | 
| Chris@66 | 956 | 
| Chris@66 | 957                 int channels = 0; | 
| Chris@66 | 958                 if (model) { | 
| Chris@66 | 959                     DenseTimeValueModel *dtvm = | 
| Chris@66 | 960                         dynamic_cast<DenseTimeValueModel *>(model); | 
| Chris@66 | 961                     if (dtvm) channels = dtvm->getChannelCount(); | 
| Chris@66 | 962                 } | 
| Chris@66 | 963                 if (channels < 1 && getMainModel()) { | 
| Chris@66 | 964                     channels = getMainModel()->getChannelCount(); | 
| Chris@66 | 965                 } | 
| Chris@66 | 966                 if (channels < 1) channels = 1; | 
| Chris@66 | 967 | 
| Chris@66 | 968                 for (int c = 0; c <= channels; ++c) { | 
| Chris@66 | 969 | 
| Chris@66 | 970                     if (c == 1 && channels == 1) continue; | 
| Chris@66 | 971                     bool isDefault = (c == 0); | 
| Chris@66 | 972                     bool isOnly = (isDefault && (channels == 1)); | 
| Chris@66 | 973 | 
| Chris@66 | 974                     if (menuType == 1) { | 
| Chris@66 | 975                         if (isDefault) isOnly = true; | 
| Chris@66 | 976                         else continue; | 
| Chris@66 | 977                     } | 
| Chris@66 | 978 | 
| Chris@66 | 979                     if (isOnly && (!plural || menuType == 1)) { | 
| Chris@66 | 980 | 
| Chris@67 | 981                         if (type != LayerFactory::Waveform) { | 
| Chris@67 | 982                             action = new QAction(mainText, this); | 
| Chris@67 | 983                         } else { | 
| Chris@67 | 984                             action = new QAction(icon, mainText, this); | 
| Chris@67 | 985                         } | 
| Chris@67 | 986 | 
| Chris@66 | 987                         action->setShortcut(shortcutText); | 
| Chris@66 | 988                         action->setStatusTip(tipText); | 
| Chris@66 | 989                         if (menuType == 0) { | 
| Chris@66 | 990                             connect(action, SIGNAL(triggered()), | 
| Chris@66 | 991                                     this, SLOT(addPane())); | 
| Chris@66 | 992                             connect(this, SIGNAL(canAddPane(bool)), | 
| Chris@66 | 993                                     action, SLOT(setEnabled(bool))); | 
| Chris@66 | 994                             m_paneActions[action] = PaneConfiguration(type); | 
| Chris@66 | 995                         } else { | 
| Chris@66 | 996                             connect(action, SIGNAL(triggered()), | 
| Chris@66 | 997                                     this, SLOT(addLayer())); | 
| Chris@66 | 998                             connect(this, SIGNAL(canAddLayer(bool)), | 
| Chris@66 | 999                                     action, SLOT(setEnabled(bool))); | 
| Chris@66 | 1000                             m_layerActions[action] = type; | 
| Chris@66 | 1001                         } | 
| Chris@66 | 1002                         menu->addAction(action); | 
| Chris@66 | 1003 | 
| Chris@66 | 1004                     } else { | 
| Chris@66 | 1005 | 
| Chris@66 | 1006                         if (!submenu) { | 
| Chris@66 | 1007                             submenu = menu->addMenu(mainText); | 
| Chris@97 | 1008                             submenu->setTearOffEnabled(true); | 
| Chris@67 | 1009                         } else if (isDefault) { | 
| Chris@67 | 1010                             submenu->addSeparator(); | 
| Chris@66 | 1011                         } | 
| Chris@66 | 1012 | 
| Chris@66 | 1013                         QString actionText; | 
| Chris@66 | 1014                         if (c == 0) { | 
| Chris@66 | 1015                             if (mono) { | 
| Chris@66 | 1016                                 actionText = tr("&All Channels Mixed"); | 
| Chris@66 | 1017                             } else { | 
| Chris@66 | 1018                                 actionText = tr("&All Channels"); | 
| Chris@66 | 1019                             } | 
| Chris@66 | 1020                         } else { | 
| Chris@66 | 1021                             actionText = tr("Channel &%1").arg(c); | 
| Chris@66 | 1022                         } | 
| Chris@66 | 1023 | 
| Chris@66 | 1024                         if (model) { | 
| Chris@66 | 1025                             actionText = tr("%1: %2") | 
| Chris@66 | 1026                                 .arg(model->objectName()) | 
| Chris@66 | 1027                                 .arg(actionText); | 
| Chris@66 | 1028                         } | 
| Chris@67 | 1029 | 
| Chris@67 | 1030                         if (isDefault) { | 
| Chris@67 | 1031                             action = new QAction(icon, actionText, this); | 
| Chris@67 | 1032                             if (!model || model == getMainModel()) { | 
| Chris@67 | 1033                                 action->setShortcut(shortcutText); | 
| Chris@67 | 1034                             } | 
| Chris@67 | 1035                         } else { | 
| Chris@67 | 1036                             action = new QAction(actionText, this); | 
| Chris@67 | 1037                         } | 
| Chris@67 | 1038 | 
| Chris@66 | 1039                         action->setStatusTip(tipText); | 
| Chris@66 | 1040 | 
| Chris@66 | 1041                         if (menuType == 0) { | 
| Chris@66 | 1042                             connect(action, SIGNAL(triggered()), | 
| Chris@66 | 1043                                     this, SLOT(addPane())); | 
| Chris@66 | 1044                             connect(this, SIGNAL(canAddPane(bool)), | 
| Chris@66 | 1045                                     action, SLOT(setEnabled(bool))); | 
| Chris@66 | 1046                             m_paneActions[action] = | 
| Chris@66 | 1047                                 PaneConfiguration(type, model, c - 1); | 
| Chris@66 | 1048                         } else { | 
| Chris@66 | 1049                             connect(action, SIGNAL(triggered()), | 
| Chris@66 | 1050                                     this, SLOT(addLayer())); | 
| Chris@66 | 1051                             connect(this, SIGNAL(canAddLayer(bool)), | 
| Chris@66 | 1052                                     action, SLOT(setEnabled(bool))); | 
| Chris@66 | 1053                             m_layerActions[action] = type; | 
| Chris@66 | 1054                         } | 
| Chris@66 | 1055 | 
| Chris@66 | 1056                         submenu->addAction(action); | 
| Chris@66 | 1057                     } | 
| Chris@66 | 1058 		} | 
| Chris@66 | 1059 	    } | 
| Chris@66 | 1060 	} | 
| Chris@66 | 1061     } | 
| Chris@66 | 1062 | 
| Chris@66 | 1063     menu = m_paneMenu; | 
| Chris@66 | 1064 | 
| Chris@66 | 1065     menu->addSeparator(); | 
| Chris@66 | 1066 | 
| Chris@66 | 1067     action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Pane"), this); | 
| Chris@66 | 1068     action->setShortcut(tr("Alt+D")); | 
| Chris@90 | 1069     action->setStatusTip(tr("Delete the currently active pane")); | 
| Chris@66 | 1070     connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane())); | 
| Chris@66 | 1071     connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 1072     menu->addAction(action); | 
| Chris@66 | 1073 | 
| Chris@66 | 1074     menu = m_layerMenu; | 
| Chris@66 | 1075 | 
| Chris@66 | 1076     action = new QAction(QIcon(":/icons/timeruler.png"), tr("Add &Time Ruler"), this); | 
| Chris@66 | 1077     action->setStatusTip(tr("Add a new layer showing a time ruler")); | 
| Chris@66 | 1078     connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 
| Chris@66 | 1079     connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 1080     m_layerActions[action] = LayerFactory::TimeRuler; | 
| Chris@66 | 1081     menu->addAction(action); | 
| Chris@66 | 1082 | 
| Chris@66 | 1083     menu->addSeparator(); | 
| Chris@66 | 1084 | 
| Chris@66 | 1085     m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer")); | 
| Chris@97 | 1086     m_existingLayersMenu->setTearOffEnabled(true); | 
| Chris@66 | 1087     m_rightButtonLayerMenu->addMenu(m_existingLayersMenu); | 
| Chris@95 | 1088 | 
| Chris@95 | 1089     m_sliceMenu = menu->addMenu(tr("Add S&lice of Layer")); | 
| Chris@97 | 1090     m_sliceMenu->setTearOffEnabled(true); | 
| Chris@95 | 1091     m_rightButtonLayerMenu->addMenu(m_sliceMenu); | 
| Chris@95 | 1092 | 
| Chris@95 | 1093     setupExistingLayersMenus(); | 
| Chris@66 | 1094 | 
| Chris@66 | 1095     m_rightButtonLayerMenu->addSeparator(); | 
| Chris@66 | 1096     menu->addSeparator(); | 
| Chris@66 | 1097 | 
| Chris@66 | 1098     action = new QAction(tr("&Rename Layer..."), this); | 
| Chris@66 | 1099     action->setShortcut(tr("Alt+R")); | 
| Chris@66 | 1100     action->setStatusTip(tr("Rename the currently active layer")); | 
| Chris@66 | 1101     connect(action, SIGNAL(triggered()), this, SLOT(renameCurrentLayer())); | 
| Chris@66 | 1102     connect(this, SIGNAL(canRenameLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 1103     menu->addAction(action); | 
| Chris@66 | 1104     m_rightButtonLayerMenu->addAction(action); | 
| Chris@66 | 1105 | 
| Chris@66 | 1106     action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Layer"), this); | 
| Chris@66 | 1107     action->setShortcut(tr("Alt+Shift+D")); | 
| Chris@66 | 1108     action->setStatusTip(tr("Delete the currently active layer")); | 
| Chris@66 | 1109     connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer())); | 
| Chris@66 | 1110     connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@66 | 1111     menu->addAction(action); | 
| Chris@66 | 1112     m_rightButtonLayerMenu->addAction(action); | 
| Chris@66 | 1113 } | 
| Chris@66 | 1114 | 
| Chris@66 | 1115 void | 
| Chris@66 | 1116 MainWindow::setupTransformsMenu() | 
| Chris@66 | 1117 { | 
| Chris@34 | 1118     if (m_transformsMenu) { | 
| Chris@34 | 1119         m_transformActions.clear(); | 
| Chris@34 | 1120         m_transformActionsReverse.clear(); | 
| Chris@34 | 1121         m_transformsMenu->clear(); | 
| Chris@34 | 1122     } else { | 
| Chris@97 | 1123 	m_transformsMenu = menuBar()->addMenu(tr("&Transform")); | 
| Chris@97 | 1124         m_transformsMenu->setTearOffEnabled(true); | 
| Chris@97 | 1125    } | 
| Chris@34 | 1126 | 
| Chris@0 | 1127     TransformFactory::TransformList transforms = | 
| Chris@0 | 1128 	TransformFactory::getInstance()->getAllTransforms(); | 
| Chris@0 | 1129 | 
| Chris@33 | 1130     vector<QString> types = | 
| Chris@0 | 1131         TransformFactory::getInstance()->getAllTransformTypes(); | 
| Chris@0 | 1132 | 
| Chris@37 | 1133     map<QString, map<QString, SubdividingMenu *> > categoryMenus; | 
| Chris@37 | 1134     map<QString, map<QString, SubdividingMenu *> > makerMenus; | 
| Chris@33 | 1135 | 
| Chris@36 | 1136     map<QString, SubdividingMenu *> byPluginNameMenus; | 
| Chris@33 | 1137     map<QString, map<QString, QMenu *> > pluginNameMenus; | 
| Chris@33 | 1138 | 
| Chris@37 | 1139     set<SubdividingMenu *> pendingMenus; | 
| Chris@37 | 1140 | 
| Chris@34 | 1141     m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms")); | 
| Chris@97 | 1142     m_recentTransformsMenu->setTearOffEnabled(true); | 
| Chris@34 | 1143     m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu); | 
| Chris@34 | 1144     connect(&m_recentTransforms, SIGNAL(recentChanged()), | 
| Chris@34 | 1145             this, SLOT(setupRecentTransformsMenu())); | 
| Chris@34 | 1146 | 
| Chris@34 | 1147     m_transformsMenu->addSeparator(); | 
| Chris@34 | 1148     m_rightButtonTransformsMenu->addSeparator(); | 
| Chris@34 | 1149 | 
| Chris@33 | 1150     for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) { | 
| Chris@33 | 1151 | 
| Chris@33 | 1152         if (i != types.begin()) { | 
| Chris@34 | 1153             m_transformsMenu->addSeparator(); | 
| Chris@34 | 1154             m_rightButtonTransformsMenu->addSeparator(); | 
| Chris@33 | 1155         } | 
| Chris@33 | 1156 | 
| Chris@33 | 1157         QString byCategoryLabel = tr("%1 by Category").arg(*i); | 
| Chris@37 | 1158         SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel, | 
| Chris@37 | 1159                                                               20, 40); | 
| Chris@97 | 1160         byCategoryMenu->setTearOffEnabled(true); | 
| Chris@37 | 1161         m_transformsMenu->addMenu(byCategoryMenu); | 
| Chris@34 | 1162         m_rightButtonTransformsMenu->addMenu(byCategoryMenu); | 
| Chris@37 | 1163         pendingMenus.insert(byCategoryMenu); | 
| Chris@33 | 1164 | 
| Chris@33 | 1165         vector<QString> categories = | 
| Chris@33 | 1166             TransformFactory::getInstance()->getTransformCategories(*i); | 
| Chris@33 | 1167 | 
| Chris@33 | 1168         for (vector<QString>::iterator j = categories.begin(); | 
| Chris@33 | 1169              j != categories.end(); ++j) { | 
| Chris@33 | 1170 | 
| Chris@33 | 1171             QString category = *j; | 
| Chris@33 | 1172             if (category == "") category = tr("Unclassified"); | 
| Chris@33 | 1173 | 
| Chris@33 | 1174             if (categories.size() < 2) { | 
| Chris@33 | 1175                 categoryMenus[*i][category] = byCategoryMenu; | 
| Chris@33 | 1176                 continue; | 
| Chris@33 | 1177             } | 
| Chris@33 | 1178 | 
| Chris@33 | 1179             QStringList components = category.split(" > "); | 
| Chris@33 | 1180             QString key; | 
| Chris@33 | 1181 | 
| Chris@33 | 1182             for (QStringList::iterator k = components.begin(); | 
| Chris@33 | 1183                  k != components.end(); ++k) { | 
| Chris@33 | 1184 | 
| Chris@33 | 1185                 QString parentKey = key; | 
| Chris@33 | 1186                 if (key != "") key += " > "; | 
| Chris@33 | 1187                 key += *k; | 
| Chris@33 | 1188 | 
| Chris@33 | 1189                 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) { | 
| Chris@37 | 1190                     SubdividingMenu *m = new SubdividingMenu(*k, 20, 40); | 
| Chris@97 | 1191                     m->setTearOffEnabled(true); | 
| Chris@37 | 1192                     pendingMenus.insert(m); | 
| Chris@37 | 1193                     categoryMenus[*i][key] = m; | 
| Chris@33 | 1194                     if (parentKey == "") { | 
| Chris@37 | 1195                         byCategoryMenu->addMenu(m); | 
| Chris@33 | 1196                     } else { | 
| Chris@37 | 1197                         categoryMenus[*i][parentKey]->addMenu(m); | 
| Chris@33 | 1198                     } | 
| Chris@33 | 1199                 } | 
| Chris@33 | 1200             } | 
| Chris@33 | 1201         } | 
| Chris@33 | 1202 | 
| Chris@34 | 1203         QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i); | 
| Chris@36 | 1204         byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel); | 
| Chris@97 | 1205         byPluginNameMenus[*i]->setTearOffEnabled(true); | 
| Chris@36 | 1206         m_transformsMenu->addMenu(byPluginNameMenus[*i]); | 
| Chris@34 | 1207         m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]); | 
| Chris@37 | 1208         pendingMenus.insert(byPluginNameMenus[*i]); | 
| Chris@34 | 1209 | 
| Chris@33 | 1210         QString byMakerLabel = tr("%1 by Maker").arg(*i); | 
| Chris@37 | 1211         SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40); | 
| Chris@97 | 1212         byMakerMenu->setTearOffEnabled(true); | 
| Chris@37 | 1213         m_transformsMenu->addMenu(byMakerMenu); | 
| Chris@34 | 1214         m_rightButtonTransformsMenu->addMenu(byMakerMenu); | 
| Chris@37 | 1215         pendingMenus.insert(byMakerMenu); | 
| Chris@33 | 1216 | 
| Chris@33 | 1217         vector<QString> makers = | 
| Chris@33 | 1218             TransformFactory::getInstance()->getTransformMakers(*i); | 
| Chris@37 | 1219 | 
| Chris@33 | 1220         for (vector<QString>::iterator j = makers.begin(); | 
| Chris@33 | 1221              j != makers.end(); ++j) { | 
| Chris@33 | 1222 | 
| Chris@33 | 1223             QString maker = *j; | 
| Chris@33 | 1224             if (maker == "") maker = tr("Unknown"); | 
| Chris@55 | 1225             maker.replace(QRegExp(tr(" [\\(<].*$")), ""); | 
| Chris@55 | 1226 | 
| Chris@37 | 1227             makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40); | 
| Chris@97 | 1228             makerMenus[*i][maker]->setTearOffEnabled(true); | 
| Chris@37 | 1229             byMakerMenu->addMenu(makerMenus[*i][maker]); | 
| Chris@37 | 1230             pendingMenus.insert(makerMenus[*i][maker]); | 
| Chris@33 | 1231         } | 
| Chris@0 | 1232     } | 
| Chris@0 | 1233 | 
| Chris@0 | 1234     for (unsigned int i = 0; i < transforms.size(); ++i) { | 
| Chris@0 | 1235 | 
| Chris@107 | 1236 	QString name = transforms[i].name; | 
| Chris@107 | 1237 	if (name == "") name = transforms[i].identifier; | 
| Chris@107 | 1238 | 
| Chris@107 | 1239 //        std::cerr << "Plugin Name: " << name.toStdString() << std::endl; | 
| Chris@80 | 1240 | 
| Chris@33 | 1241         QString type = transforms[i].type; | 
| Chris@33 | 1242 | 
| Chris@33 | 1243         QString category = transforms[i].category; | 
| Chris@33 | 1244         if (category == "") category = tr("Unclassified"); | 
| Chris@33 | 1245 | 
| Chris@33 | 1246         QString maker = transforms[i].maker; | 
| Chris@33 | 1247         if (maker == "") maker = tr("Unknown"); | 
| Chris@55 | 1248         maker.replace(QRegExp(tr(" [\\(<].*$")), ""); | 
| Chris@33 | 1249 | 
| Chris@107 | 1250         QString pluginName = name.section(": ", 0, 0); | 
| Chris@107 | 1251         QString output = name.section(": ", 1); | 
| Chris@107 | 1252 | 
| Chris@107 | 1253 	QAction *action = new QAction(tr("%1...").arg(name), this); | 
| Chris@0 | 1254 	connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 
| Chris@107 | 1255 	m_transformActions[action] = transforms[i].identifier; | 
| Chris@107 | 1256         m_transformActionsReverse[transforms[i].identifier] = action; | 
| Chris@0 | 1257 	connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@33 | 1258 | 
| Chris@108 | 1259         action->setStatusTip(transforms[i].description); | 
| Chris@90 | 1260 | 
| Chris@33 | 1261         if (categoryMenus[type].find(category) == categoryMenus[type].end()) { | 
| Chris@33 | 1262             std::cerr << "WARNING: MainWindow::setupMenus: Internal error: " | 
| Chris@33 | 1263                       << "No category menu for transform \"" | 
| Chris@107 | 1264                       << name.toStdString() << "\" (category = \"" | 
| Chris@33 | 1265                       << category.toStdString() << "\")" << std::endl; | 
| Chris@33 | 1266         } else { | 
| Chris@33 | 1267             categoryMenus[type][category]->addAction(action); | 
| Chris@33 | 1268         } | 
| Chris@33 | 1269 | 
| Chris@33 | 1270         if (makerMenus[type].find(maker) == makerMenus[type].end()) { | 
| Chris@33 | 1271             std::cerr << "WARNING: MainWindow::setupMenus: Internal error: " | 
| Chris@33 | 1272                       << "No maker menu for transform \"" | 
| Chris@107 | 1273                       << name.toStdString() << "\" (maker = \"" | 
| Chris@33 | 1274                       << maker.toStdString() << "\")" << std::endl; | 
| Chris@33 | 1275         } else { | 
| Chris@80 | 1276             makerMenus[type][maker]->addAction(action); | 
| Chris@33 | 1277         } | 
| Chris@33 | 1278 | 
| Chris@33 | 1279         action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this); | 
| Chris@33 | 1280         connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 
| Chris@107 | 1281         m_transformActions[action] = transforms[i].identifier; | 
| Chris@33 | 1282         connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@108 | 1283         action->setStatusTip(transforms[i].description); | 
| Chris@33 | 1284 | 
| Chris@34 | 1285 //        cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl; | 
| Chris@34 | 1286 | 
| Chris@33 | 1287         if (pluginNameMenus[type].find(pluginName) == | 
| Chris@33 | 1288             pluginNameMenus[type].end()) { | 
| Chris@33 | 1289 | 
| Chris@36 | 1290             SubdividingMenu *parentMenu = byPluginNameMenus[type]; | 
| Chris@97 | 1291             parentMenu->setTearOffEnabled(true); | 
| Chris@34 | 1292 | 
| Chris@33 | 1293             if (output == "") { | 
| Chris@36 | 1294                 parentMenu->addAction(pluginName, action); | 
| Chris@33 | 1295             } else { | 
| Chris@34 | 1296                 pluginNameMenus[type][pluginName] = | 
| Chris@34 | 1297                     parentMenu->addMenu(pluginName); | 
| Chris@33 | 1298                 connect(this, SIGNAL(canAddLayer(bool)), | 
| Chris@33 | 1299                         pluginNameMenus[type][pluginName], | 
| Chris@33 | 1300                         SLOT(setEnabled(bool))); | 
| Chris@33 | 1301             } | 
| Chris@33 | 1302         } | 
| Chris@33 | 1303 | 
| Chris@33 | 1304         if (pluginNameMenus[type].find(pluginName) != | 
| Chris@33 | 1305             pluginNameMenus[type].end()) { | 
| Chris@33 | 1306             pluginNameMenus[type][pluginName]->addAction(action); | 
| Chris@33 | 1307         } | 
| Chris@0 | 1308     } | 
| Chris@0 | 1309 | 
| Chris@37 | 1310     for (set<SubdividingMenu *>::iterator i = pendingMenus.begin(); | 
| Chris@37 | 1311          i != pendingMenus.end(); ++i) { | 
| Chris@37 | 1312         (*i)->entriesAdded(); | 
| Chris@37 | 1313     } | 
| Chris@37 | 1314 | 
| Chris@34 | 1315     setupRecentTransformsMenu(); | 
| Chris@66 | 1316 } | 
| Chris@66 | 1317 | 
| Chris@66 | 1318 void | 
| Chris@66 | 1319 MainWindow::setupHelpMenu() | 
| Chris@66 | 1320 { | 
| Chris@66 | 1321     if (m_mainMenusCreated) return; | 
| Chris@66 | 1322 | 
| Chris@66 | 1323     QMenu *menu = menuBar()->addMenu(tr("&Help")); | 
| Chris@97 | 1324     menu->setTearOffEnabled(true); | 
| Chris@66 | 1325 | 
| Chris@66 | 1326     QAction *action = new QAction(tr("&Help Reference"), this); | 
| Chris@66 | 1327     action->setStatusTip(tr("Open the Sonic Visualiser reference manual")); | 
| Chris@66 | 1328     connect(action, SIGNAL(triggered()), this, SLOT(help())); | 
| Chris@0 | 1329     menu->addAction(action); | 
| Chris@0 | 1330 | 
| Chris@66 | 1331     action = new QAction(tr("Sonic Visualiser on the &Web"), this); | 
| Chris@66 | 1332     action->setStatusTip(tr("Open the Sonic Visualiser website")); | 
| Chris@66 | 1333     connect(action, SIGNAL(triggered()), this, SLOT(website())); | 
| Chris@0 | 1334     menu->addAction(action); | 
| Chris@66 | 1335 | 
| Chris@66 | 1336     action = new QAction(tr("&About Sonic Visualiser"), this); | 
| Chris@66 | 1337     action->setStatusTip(tr("Show information about Sonic Visualiser")); | 
| Chris@66 | 1338     connect(action, SIGNAL(triggered()), this, SLOT(about())); | 
| Chris@0 | 1339     menu->addAction(action); | 
| Chris@0 | 1340 } | 
| Chris@0 | 1341 | 
| Chris@0 | 1342 void | 
| Chris@0 | 1343 MainWindow::setupRecentFilesMenu() | 
| Chris@0 | 1344 { | 
| Chris@0 | 1345     m_recentFilesMenu->clear(); | 
| Chris@34 | 1346     vector<QString> files = m_recentFiles.getRecent(); | 
| Chris@0 | 1347     for (size_t i = 0; i < files.size(); ++i) { | 
| Chris@0 | 1348 	QAction *action = new QAction(files[i], this); | 
| Chris@0 | 1349 	connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile())); | 
| Chris@0 | 1350 	m_recentFilesMenu->addAction(action); | 
| Chris@0 | 1351     } | 
| Chris@0 | 1352 } | 
| Chris@0 | 1353 | 
| Chris@0 | 1354 void | 
| Chris@34 | 1355 MainWindow::setupRecentTransformsMenu() | 
| Chris@34 | 1356 { | 
| Chris@34 | 1357     m_recentTransformsMenu->clear(); | 
| Chris@34 | 1358     vector<QString> transforms = m_recentTransforms.getRecent(); | 
| Chris@34 | 1359     for (size_t i = 0; i < transforms.size(); ++i) { | 
| Chris@34 | 1360         TransformActionReverseMap::iterator ti = | 
| Chris@34 | 1361             m_transformActionsReverse.find(transforms[i]); | 
| Chris@34 | 1362         if (ti == m_transformActionsReverse.end()) { | 
| Chris@34 | 1363             std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: " | 
| Chris@34 | 1364                       << "Unknown transform \"" << transforms[i].toStdString() | 
| Chris@34 | 1365                       << "\" in recent transforms list" << std::endl; | 
| Chris@34 | 1366             continue; | 
| Chris@34 | 1367         } | 
| Chris@34 | 1368 	m_recentTransformsMenu->addAction(ti->second); | 
| Chris@34 | 1369     } | 
| Chris@34 | 1370 } | 
| Chris@34 | 1371 | 
| Chris@34 | 1372 void | 
| Chris@95 | 1373 MainWindow::setupExistingLayersMenus() | 
| Chris@0 | 1374 { | 
| Chris@0 | 1375     if (!m_existingLayersMenu) return; // should have been created by setupMenus | 
| Chris@0 | 1376 | 
| Chris@0 | 1377 //    std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl; | 
| Chris@0 | 1378 | 
| Chris@0 | 1379     m_existingLayersMenu->clear(); | 
| Chris@0 | 1380     m_existingLayerActions.clear(); | 
| Chris@0 | 1381 | 
| Chris@95 | 1382     m_sliceMenu->clear(); | 
| Chris@95 | 1383     m_sliceActions.clear(); | 
| Chris@95 | 1384 | 
| Chris@33 | 1385     vector<Layer *> orderedLayers; | 
| Chris@33 | 1386     set<Layer *> observedLayers; | 
| Chris@95 | 1387     set<Layer *> sliceableLayers; | 
| Chris@95 | 1388 | 
| Chris@95 | 1389     LayerFactory *factory = LayerFactory::getInstance(); | 
| Chris@0 | 1390 | 
| Chris@0 | 1391     for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { | 
| Chris@0 | 1392 | 
| Chris@0 | 1393 	Pane *pane = m_paneStack->getPane(i); | 
| Chris@0 | 1394 	if (!pane) continue; | 
| Chris@0 | 1395 | 
| Chris@0 | 1396 	for (int j = 0; j < pane->getLayerCount(); ++j) { | 
| Chris@0 | 1397 | 
| Chris@0 | 1398 	    Layer *layer = pane->getLayer(j); | 
| Chris@0 | 1399 	    if (!layer) continue; | 
| Chris@0 | 1400 	    if (observedLayers.find(layer) != observedLayers.end()) { | 
| Chris@0 | 1401 		std::cerr << "found duplicate layer " << layer << std::endl; | 
| Chris@0 | 1402 		continue; | 
| Chris@0 | 1403 	    } | 
| Chris@0 | 1404 | 
| Chris@0 | 1405 //	    std::cerr << "found new layer " << layer << " (name = " | 
| Chris@0 | 1406 //		      << layer->getLayerPresentationName().toStdString() << ")" << std::endl; | 
| Chris@0 | 1407 | 
| Chris@0 | 1408 	    orderedLayers.push_back(layer); | 
| Chris@0 | 1409 	    observedLayers.insert(layer); | 
| Chris@95 | 1410 | 
| Chris@95 | 1411             if (factory->isLayerSliceable(layer)) { | 
| Chris@95 | 1412                 sliceableLayers.insert(layer); | 
| Chris@95 | 1413             } | 
| Chris@0 | 1414 	} | 
| Chris@0 | 1415     } | 
| Chris@0 | 1416 | 
| Chris@33 | 1417     map<QString, int> observedNames; | 
| Chris@0 | 1418 | 
| Chris@0 | 1419     for (int i = 0; i < orderedLayers.size(); ++i) { | 
| Chris@0 | 1420 | 
| Chris@95 | 1421         Layer *layer = orderedLayers[i]; | 
| Chris@95 | 1422 | 
| Chris@95 | 1423 	QString name = layer->getLayerPresentationName(); | 
| Chris@0 | 1424 	int n = ++observedNames[name]; | 
| Chris@0 | 1425 	if (n > 1) name = QString("%1 <%2>").arg(name).arg(n); | 
| Chris@0 | 1426 | 
| Chris@95 | 1427 	QIcon icon = QIcon(QString(":/icons/%1.png") | 
| Chris@95 | 1428                            .arg(factory->getLayerIconName | 
| Chris@95 | 1429                                 (factory->getLayerType(layer)))); | 
| Chris@95 | 1430 | 
| Chris@95 | 1431 	QAction *action = new QAction(icon, name, this); | 
| Chris@0 | 1432 	connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 
| Chris@0 | 1433 	connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@95 | 1434 	m_existingLayerActions[action] = layer; | 
| Chris@0 | 1435 | 
| Chris@0 | 1436 	m_existingLayersMenu->addAction(action); | 
| Chris@95 | 1437 | 
| Chris@95 | 1438         if (sliceableLayers.find(layer) != sliceableLayers.end()) { | 
| Chris@95 | 1439             action = new QAction(icon, name, this); | 
| Chris@95 | 1440             connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 
| Chris@95 | 1441             connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@95 | 1442             m_sliceActions[action] = layer; | 
| Chris@95 | 1443             m_sliceMenu->addAction(action); | 
| Chris@95 | 1444         } | 
| Chris@0 | 1445     } | 
| Chris@95 | 1446 | 
| Chris@95 | 1447     m_sliceMenu->setEnabled(!m_sliceActions.empty()); | 
| Chris@0 | 1448 } | 
| Chris@0 | 1449 | 
| Chris@0 | 1450 void | 
| Chris@0 | 1451 MainWindow::setupToolbars() | 
| Chris@0 | 1452 { | 
| Chris@0 | 1453     QToolBar *toolbar = addToolBar(tr("Transport Toolbar")); | 
| Chris@0 | 1454 | 
| Chris@0 | 1455     QAction *action = toolbar->addAction(QIcon(":/icons/rewind-start.png"), | 
| Chris@0 | 1456 					 tr("Rewind to Start")); | 
| Chris@0 | 1457     action->setShortcut(tr("Home")); | 
| Chris@0 | 1458     action->setStatusTip(tr("Rewind to the start")); | 
| Chris@0 | 1459     connect(action, SIGNAL(triggered()), this, SLOT(rewindStart())); | 
| Chris@0 | 1460     connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@0 | 1461 | 
| Chris@0 | 1462     action = toolbar->addAction(QIcon(":/icons/rewind.png"), | 
| Chris@0 | 1463 				tr("Rewind")); | 
| Chris@0 | 1464     action->setShortcut(tr("PageUp")); | 
| Chris@0 | 1465     action->setStatusTip(tr("Rewind to the previous time instant in the current layer")); | 
| Chris@0 | 1466     connect(action, SIGNAL(triggered()), this, SLOT(rewind())); | 
| Chris@0 | 1467     connect(this, SIGNAL(canRewind(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@0 | 1468 | 
| Chris@0 | 1469     action = toolbar->addAction(QIcon(":/icons/playpause.png"), | 
| Chris@0 | 1470 				tr("Play / Pause")); | 
| Chris@0 | 1471     action->setCheckable(true); | 
| Chris@0 | 1472     action->setShortcut(tr("Space")); | 
| Chris@0 | 1473     action->setStatusTip(tr("Start or stop playback from the current position")); | 
| Chris@0 | 1474     connect(action, SIGNAL(triggered()), this, SLOT(play())); | 
| Chris@0 | 1475     connect(m_playSource, SIGNAL(playStatusChanged(bool)), | 
| Chris@0 | 1476 	    action, SLOT(setChecked(bool))); | 
| Chris@0 | 1477     connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@0 | 1478 | 
| Chris@0 | 1479     action = toolbar->addAction(QIcon(":/icons/ffwd.png"), | 
| Chris@0 | 1480 				tr("Fast Forward")); | 
| Chris@0 | 1481     action->setShortcut(tr("PageDown")); | 
| Chris@0 | 1482     action->setStatusTip(tr("Fast forward to the next time instant in the current layer")); | 
| Chris@0 | 1483     connect(action, SIGNAL(triggered()), this, SLOT(ffwd())); | 
| Chris@0 | 1484     connect(this, SIGNAL(canFfwd(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@0 | 1485 | 
| Chris@0 | 1486     action = toolbar->addAction(QIcon(":/icons/ffwd-end.png"), | 
| Chris@0 | 1487 				tr("Fast Forward to End")); | 
| Chris@0 | 1488     action->setShortcut(tr("End")); | 
| Chris@0 | 1489     action->setStatusTip(tr("Fast-forward to the end")); | 
| Chris@0 | 1490     connect(action, SIGNAL(triggered()), this, SLOT(ffwdEnd())); | 
| Chris@0 | 1491     connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@0 | 1492 | 
| Chris@0 | 1493     toolbar = addToolBar(tr("Play Mode Toolbar")); | 
| Chris@0 | 1494 | 
| Chris@0 | 1495     action = toolbar->addAction(QIcon(":/icons/playselection.png"), | 
| Chris@0 | 1496 				tr("Constrain Playback to Selection")); | 
| Chris@0 | 1497     action->setCheckable(true); | 
| Chris@0 | 1498     action->setChecked(m_viewManager->getPlaySelectionMode()); | 
| Chris@0 | 1499     action->setShortcut(tr("s")); | 
| Chris@0 | 1500     action->setStatusTip(tr("Constrain playback to the selected area")); | 
| Chris@69 | 1501     connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)), | 
| Chris@69 | 1502             action, SLOT(setChecked(bool))); | 
| Chris@0 | 1503     connect(action, SIGNAL(triggered()), this, SLOT(playSelectionToggled())); | 
| Chris@0 | 1504     connect(this, SIGNAL(canPlaySelection(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@0 | 1505 | 
| Chris@0 | 1506     action = toolbar->addAction(QIcon(":/icons/playloop.png"), | 
| Chris@0 | 1507 				tr("Loop Playback")); | 
| Chris@0 | 1508     action->setCheckable(true); | 
| Chris@0 | 1509     action->setChecked(m_viewManager->getPlayLoopMode()); | 
| Chris@0 | 1510     action->setShortcut(tr("l")); | 
| Chris@0 | 1511     action->setStatusTip(tr("Loop playback")); | 
| Chris@69 | 1512     connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)), | 
| Chris@69 | 1513             action, SLOT(setChecked(bool))); | 
| Chris@0 | 1514     connect(action, SIGNAL(triggered()), this, SLOT(playLoopToggled())); | 
| Chris@0 | 1515     connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@0 | 1516 | 
| Chris@0 | 1517     toolbar = addToolBar(tr("Edit Toolbar")); | 
| Chris@0 | 1518     CommandHistory::getInstance()->registerToolbar(toolbar); | 
| Chris@0 | 1519 | 
| Chris@0 | 1520     toolbar = addToolBar(tr("Tools Toolbar")); | 
| Chris@0 | 1521     QActionGroup *group = new QActionGroup(this); | 
| Chris@0 | 1522 | 
| Chris@0 | 1523     action = toolbar->addAction(QIcon(":/icons/navigate.png"), | 
| Chris@0 | 1524 				tr("Navigate")); | 
| Chris@0 | 1525     action->setCheckable(true); | 
| Chris@0 | 1526     action->setChecked(true); | 
| Chris@0 | 1527     action->setShortcut(tr("1")); | 
| Chris@90 | 1528     action->setStatusTip(tr("Navigate")); | 
| Chris@0 | 1529     connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected())); | 
| Chris@0 | 1530     group->addAction(action); | 
| Chris@0 | 1531     m_toolActions[ViewManager::NavigateMode] = action; | 
| Chris@0 | 1532 | 
| Chris@0 | 1533     action = toolbar->addAction(QIcon(":/icons/select.png"), | 
| Chris@0 | 1534 				tr("Select")); | 
| Chris@0 | 1535     action->setCheckable(true); | 
| Chris@0 | 1536     action->setShortcut(tr("2")); | 
| Chris@90 | 1537     action->setStatusTip(tr("Select ranges")); | 
| Chris@0 | 1538     connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected())); | 
| Chris@0 | 1539     group->addAction(action); | 
| Chris@0 | 1540     m_toolActions[ViewManager::SelectMode] = action; | 
| Chris@0 | 1541 | 
| Chris@0 | 1542     action = toolbar->addAction(QIcon(":/icons/move.png"), | 
| Chris@0 | 1543 				tr("Edit")); | 
| Chris@0 | 1544     action->setCheckable(true); | 
| Chris@0 | 1545     action->setShortcut(tr("3")); | 
| Chris@90 | 1546     action->setStatusTip(tr("Edit items in layer")); | 
| Chris@0 | 1547     connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected())); | 
| Chris@0 | 1548     connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@0 | 1549     group->addAction(action); | 
| Chris@0 | 1550     m_toolActions[ViewManager::EditMode] = action; | 
| Chris@0 | 1551 | 
| Chris@0 | 1552     action = toolbar->addAction(QIcon(":/icons/draw.png"), | 
| Chris@0 | 1553 				tr("Draw")); | 
| Chris@0 | 1554     action->setCheckable(true); | 
| Chris@0 | 1555     action->setShortcut(tr("4")); | 
| Chris@90 | 1556     action->setStatusTip(tr("Draw new items in layer")); | 
| Chris@0 | 1557     connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected())); | 
| Chris@0 | 1558     connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool))); | 
| Chris@0 | 1559     group->addAction(action); | 
| Chris@0 | 1560     m_toolActions[ViewManager::DrawMode] = action; | 
| Chris@0 | 1561 | 
| Chris@0 | 1562 //    action = toolbar->addAction(QIcon(":/icons/text.png"), | 
| Chris@0 | 1563 //				tr("Text")); | 
| Chris@0 | 1564 //    action->setCheckable(true); | 
| Chris@0 | 1565 //    action->setShortcut(tr("5")); | 
| Chris@0 | 1566 //    connect(action, SIGNAL(triggered()), this, SLOT(toolTextSelected())); | 
| Chris@0 | 1567 //    group->addAction(action); | 
| Chris@0 | 1568 //    m_toolActions[ViewManager::TextMode] = action; | 
| Chris@0 | 1569 | 
| Chris@0 | 1570     toolNavigateSelected(); | 
| Chris@0 | 1571 } | 
| Chris@0 | 1572 | 
| Chris@0 | 1573 void | 
| Chris@0 | 1574 MainWindow::updateMenuStates() | 
| Chris@0 | 1575 { | 
| Chris@117 | 1576     Pane *currentPane = 0; | 
| Chris@117 | 1577     Layer *currentLayer = 0; | 
| Chris@117 | 1578 | 
| Chris@117 | 1579     if (m_paneStack) currentPane = m_paneStack->getCurrentPane(); | 
| Chris@117 | 1580     if (currentPane) currentLayer = currentPane->getSelectedLayer(); | 
| Chris@117 | 1581 | 
| Chris@0 | 1582     bool haveCurrentPane = | 
| Chris@117 | 1583         (currentPane != 0); | 
| Chris@0 | 1584     bool haveCurrentLayer = | 
| Chris@117 | 1585         (haveCurrentPane && | 
| Chris@117 | 1586          (currentLayer != 0)); | 
| Chris@0 | 1587     bool haveMainModel = | 
| Chris@0 | 1588 	(getMainModel() != 0); | 
| Chris@0 | 1589     bool havePlayTarget = | 
| Chris@0 | 1590 	(m_playTarget != 0); | 
| Chris@0 | 1591     bool haveSelection = | 
| Chris@0 | 1592 	(m_viewManager && | 
| Chris@0 | 1593 	 !m_viewManager->getSelections().empty()); | 
| Chris@0 | 1594     bool haveCurrentEditableLayer = | 
| Chris@0 | 1595 	(haveCurrentLayer && | 
| Chris@117 | 1596 	 currentLayer->isLayerEditable()); | 
| Chris@0 | 1597     bool haveCurrentTimeInstantsLayer = | 
| Chris@0 | 1598 	(haveCurrentLayer && | 
| Chris@117 | 1599 	 dynamic_cast<TimeInstantLayer *>(currentLayer)); | 
| Chris@0 | 1600     bool haveCurrentTimeValueLayer = | 
| Chris@0 | 1601 	(haveCurrentLayer && | 
| Chris@117 | 1602 	 dynamic_cast<TimeValueLayer *>(currentLayer)); | 
| Chris@0 | 1603     bool haveCurrentColour3DPlot = | 
| Chris@0 | 1604         (haveCurrentLayer && | 
| Chris@117 | 1605          dynamic_cast<Colour3DPlotLayer *>(currentLayer)); | 
| Chris@0 | 1606     bool haveClipboardContents = | 
| Chris@0 | 1607         (m_viewManager && | 
| Chris@0 | 1608          !m_viewManager->getClipboard().empty()); | 
| Chris@0 | 1609 | 
| Chris@0 | 1610     emit canAddPane(haveMainModel); | 
| Chris@0 | 1611     emit canDeleteCurrentPane(haveCurrentPane); | 
| Chris@0 | 1612     emit canZoom(haveMainModel && haveCurrentPane); | 
| Chris@0 | 1613     emit canScroll(haveMainModel && haveCurrentPane); | 
| Chris@0 | 1614     emit canAddLayer(haveMainModel && haveCurrentPane); | 
| Chris@0 | 1615     emit canImportMoreAudio(haveMainModel); | 
| Chris@0 | 1616     emit canImportLayer(haveMainModel && haveCurrentPane); | 
| Chris@0 | 1617     emit canExportAudio(haveMainModel); | 
| Chris@0 | 1618     emit canExportLayer(haveMainModel && | 
| Chris@0 | 1619                         (haveCurrentEditableLayer || haveCurrentColour3DPlot)); | 
| Chris@0 | 1620     emit canDeleteCurrentLayer(haveCurrentLayer); | 
| Chris@0 | 1621     emit canRenameLayer(haveCurrentLayer); | 
| Chris@0 | 1622     emit canEditLayer(haveCurrentEditableLayer); | 
| Chris@0 | 1623     emit canSelect(haveMainModel && haveCurrentPane); | 
| Chris@0 | 1624     emit canPlay(/*!!! haveMainModel && */ havePlayTarget); | 
| Chris@0 | 1625     emit canFfwd(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer); | 
| Chris@0 | 1626     emit canRewind(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer); | 
| Chris@0 | 1627     emit canPaste(haveCurrentEditableLayer && haveClipboardContents); | 
| Chris@0 | 1628     emit canInsertInstant(haveCurrentPane); | 
| Chris@81 | 1629     emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection); | 
| Chris@0 | 1630     emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection); | 
| Chris@0 | 1631     emit canClearSelection(haveSelection); | 
| Chris@0 | 1632     emit canEditSelection(haveSelection && haveCurrentEditableLayer); | 
| Chris@0 | 1633     emit canSave(m_sessionFile != "" && m_documentModified); | 
| Chris@0 | 1634 } | 
| Chris@0 | 1635 | 
| Chris@0 | 1636 void | 
| Chris@0 | 1637 MainWindow::updateDescriptionLabel() | 
| Chris@0 | 1638 { | 
| Chris@0 | 1639     if (!getMainModel()) { | 
| Chris@0 | 1640 	m_descriptionLabel->setText(tr("No audio file loaded.")); | 
| Chris@0 | 1641 	return; | 
| Chris@0 | 1642     } | 
| Chris@0 | 1643 | 
| Chris@0 | 1644     QString description; | 
| Chris@0 | 1645 | 
| Chris@0 | 1646     size_t ssr = getMainModel()->getSampleRate(); | 
| Chris@0 | 1647     size_t tsr = ssr; | 
| Chris@0 | 1648     if (m_playSource) tsr = m_playSource->getTargetSampleRate(); | 
| Chris@0 | 1649 | 
| Chris@0 | 1650     if (ssr != tsr) { | 
| Chris@0 | 1651 	description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr); | 
| Chris@0 | 1652     } else { | 
| Chris@0 | 1653 	description = QString("%1Hz").arg(ssr); | 
| Chris@0 | 1654     } | 
| Chris@0 | 1655 | 
| Chris@0 | 1656     description = QString("%1 - %2") | 
| Chris@0 | 1657 	.arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr) | 
| Chris@0 | 1658 	     .toText(false).c_str()) | 
| Chris@0 | 1659 	.arg(description); | 
| Chris@0 | 1660 | 
| Chris@0 | 1661     m_descriptionLabel->setText(description); | 
| Chris@0 | 1662 } | 
| Chris@0 | 1663 | 
| Chris@0 | 1664 void | 
| Chris@0 | 1665 MainWindow::documentModified() | 
| Chris@0 | 1666 { | 
| Chris@0 | 1667 //    std::cerr << "MainWindow::documentModified" << std::endl; | 
| Chris@0 | 1668 | 
| Chris@0 | 1669     if (!m_documentModified) { | 
| Chris@0 | 1670 	setWindowTitle(tr("%1 (modified)").arg(windowTitle())); | 
| Chris@0 | 1671     } | 
| Chris@0 | 1672 | 
| Chris@0 | 1673     m_documentModified = true; | 
| Chris@0 | 1674     updateMenuStates(); | 
| Chris@0 | 1675 } | 
| Chris@0 | 1676 | 
| Chris@0 | 1677 void | 
| Chris@0 | 1678 MainWindow::documentRestored() | 
| Chris@0 | 1679 { | 
| Chris@0 | 1680 //    std::cerr << "MainWindow::documentRestored" << std::endl; | 
| Chris@0 | 1681 | 
| Chris@0 | 1682     if (m_documentModified) { | 
| Chris@0 | 1683 	QString wt(windowTitle()); | 
| Chris@0 | 1684 	wt.replace(tr(" (modified)"), ""); | 
| Chris@0 | 1685 	setWindowTitle(wt); | 
| Chris@0 | 1686     } | 
| Chris@0 | 1687 | 
| Chris@0 | 1688     m_documentModified = false; | 
| Chris@0 | 1689     updateMenuStates(); | 
| Chris@0 | 1690 } | 
| Chris@0 | 1691 | 
| Chris@0 | 1692 void | 
| Chris@0 | 1693 MainWindow::playLoopToggled() | 
| Chris@0 | 1694 { | 
| Chris@0 | 1695     QAction *action = dynamic_cast<QAction *>(sender()); | 
| Chris@0 | 1696 | 
| Chris@0 | 1697     if (action) { | 
| Chris@0 | 1698 	m_viewManager->setPlayLoopMode(action->isChecked()); | 
| Chris@0 | 1699     } else { | 
| Chris@0 | 1700 	m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode()); | 
| Chris@0 | 1701     } | 
| Chris@0 | 1702 } | 
| Chris@0 | 1703 | 
| Chris@0 | 1704 void | 
| Chris@0 | 1705 MainWindow::playSelectionToggled() | 
| Chris@0 | 1706 { | 
| Chris@0 | 1707     QAction *action = dynamic_cast<QAction *>(sender()); | 
| Chris@0 | 1708 | 
| Chris@0 | 1709     if (action) { | 
| Chris@0 | 1710 	m_viewManager->setPlaySelectionMode(action->isChecked()); | 
| Chris@0 | 1711     } else { | 
| Chris@0 | 1712 	m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode()); | 
| Chris@0 | 1713     } | 
| Chris@0 | 1714 } | 
| Chris@0 | 1715 | 
| Chris@0 | 1716 void | 
| Chris@116 | 1717 MainWindow::currentPaneChanged(Pane *p) | 
| Chris@0 | 1718 { | 
| Chris@0 | 1719     updateMenuStates(); | 
| Chris@116 | 1720     updateVisibleRangeDisplay(p); | 
| Chris@0 | 1721 } | 
| Chris@0 | 1722 | 
| Chris@0 | 1723 void | 
| Chris@116 | 1724 MainWindow::currentLayerChanged(Pane *p, Layer *) | 
| Chris@0 | 1725 { | 
| Chris@0 | 1726     updateMenuStates(); | 
| Chris@116 | 1727     updateVisibleRangeDisplay(p); | 
| Chris@0 | 1728 } | 
| Chris@0 | 1729 | 
| Chris@0 | 1730 void | 
| Chris@0 | 1731 MainWindow::toolNavigateSelected() | 
| Chris@0 | 1732 { | 
| Chris@0 | 1733     m_viewManager->setToolMode(ViewManager::NavigateMode); | 
| Chris@0 | 1734 } | 
| Chris@0 | 1735 | 
| Chris@0 | 1736 void | 
| Chris@0 | 1737 MainWindow::toolSelectSelected() | 
| Chris@0 | 1738 { | 
| Chris@0 | 1739     m_viewManager->setToolMode(ViewManager::SelectMode); | 
| Chris@0 | 1740 } | 
| Chris@0 | 1741 | 
| Chris@0 | 1742 void | 
| Chris@0 | 1743 MainWindow::toolEditSelected() | 
| Chris@0 | 1744 { | 
| Chris@0 | 1745     m_viewManager->setToolMode(ViewManager::EditMode); | 
| Chris@0 | 1746 } | 
| Chris@0 | 1747 | 
| Chris@0 | 1748 void | 
| Chris@0 | 1749 MainWindow::toolDrawSelected() | 
| Chris@0 | 1750 { | 
| Chris@0 | 1751     m_viewManager->setToolMode(ViewManager::DrawMode); | 
| Chris@0 | 1752 } | 
| Chris@0 | 1753 | 
| Chris@0 | 1754 //void | 
| Chris@0 | 1755 //MainWindow::toolTextSelected() | 
| Chris@0 | 1756 //{ | 
| Chris@0 | 1757 //    m_viewManager->setToolMode(ViewManager::TextMode); | 
| Chris@0 | 1758 //} | 
| Chris@0 | 1759 | 
| Chris@0 | 1760 void | 
| Chris@0 | 1761 MainWindow::selectAll() | 
| Chris@0 | 1762 { | 
| Chris@0 | 1763     if (!getMainModel()) return; | 
| Chris@0 | 1764     m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(), | 
| Chris@0 | 1765 					  getMainModel()->getEndFrame())); | 
| Chris@0 | 1766 } | 
| Chris@0 | 1767 | 
| Chris@0 | 1768 void | 
| Chris@0 | 1769 MainWindow::selectToStart() | 
| Chris@0 | 1770 { | 
| Chris@0 | 1771     if (!getMainModel()) return; | 
| Chris@0 | 1772     m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(), | 
| Chris@0 | 1773 					  m_viewManager->getGlobalCentreFrame())); | 
| Chris@0 | 1774 } | 
| Chris@0 | 1775 | 
| Chris@0 | 1776 void | 
| Chris@0 | 1777 MainWindow::selectToEnd() | 
| Chris@0 | 1778 { | 
| Chris@0 | 1779     if (!getMainModel()) return; | 
| Chris@0 | 1780     m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(), | 
| Chris@0 | 1781 					  getMainModel()->getEndFrame())); | 
| Chris@0 | 1782 } | 
| Chris@0 | 1783 | 
| Chris@0 | 1784 void | 
| Chris@0 | 1785 MainWindow::selectVisible() | 
| Chris@0 | 1786 { | 
| Chris@0 | 1787     Model *model = getMainModel(); | 
| Chris@0 | 1788     if (!model) return; | 
| Chris@0 | 1789 | 
| Chris@0 | 1790     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 1791     if (!currentPane) return; | 
| Chris@0 | 1792 | 
| Chris@0 | 1793     size_t startFrame, endFrame; | 
| Chris@0 | 1794 | 
| Chris@0 | 1795     if (currentPane->getStartFrame() < 0) startFrame = 0; | 
| Chris@0 | 1796     else startFrame = currentPane->getStartFrame(); | 
| Chris@0 | 1797 | 
| Chris@0 | 1798     if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame(); | 
| Chris@0 | 1799     else endFrame = currentPane->getEndFrame(); | 
| Chris@0 | 1800 | 
| Chris@0 | 1801     m_viewManager->setSelection(Selection(startFrame, endFrame)); | 
| Chris@0 | 1802 } | 
| Chris@0 | 1803 | 
| Chris@0 | 1804 void | 
| Chris@0 | 1805 MainWindow::clearSelection() | 
| Chris@0 | 1806 { | 
| Chris@0 | 1807     m_viewManager->clearSelections(); | 
| Chris@0 | 1808 } | 
| Chris@0 | 1809 | 
| Chris@0 | 1810 void | 
| Chris@0 | 1811 MainWindow::cut() | 
| Chris@0 | 1812 { | 
| Chris@0 | 1813     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 1814     if (!currentPane) return; | 
| Chris@0 | 1815 | 
| Chris@0 | 1816     Layer *layer = currentPane->getSelectedLayer(); | 
| Chris@0 | 1817     if (!layer) return; | 
| Chris@0 | 1818 | 
| Chris@0 | 1819     Clipboard &clipboard = m_viewManager->getClipboard(); | 
| Chris@0 | 1820     clipboard.clear(); | 
| Chris@0 | 1821 | 
| Chris@0 | 1822     MultiSelection::SelectionList selections = m_viewManager->getSelections(); | 
| Chris@0 | 1823 | 
| Chris@0 | 1824     CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true); | 
| Chris@0 | 1825 | 
| Chris@0 | 1826     for (MultiSelection::SelectionList::iterator i = selections.begin(); | 
| Chris@0 | 1827          i != selections.end(); ++i) { | 
| Chris@0 | 1828         layer->copy(*i, clipboard); | 
| Chris@0 | 1829         layer->deleteSelection(*i); | 
| Chris@0 | 1830     } | 
| Chris@0 | 1831 | 
| Chris@0 | 1832     CommandHistory::getInstance()->endCompoundOperation(); | 
| Chris@0 | 1833 } | 
| Chris@0 | 1834 | 
| Chris@0 | 1835 void | 
| Chris@0 | 1836 MainWindow::copy() | 
| Chris@0 | 1837 { | 
| Chris@0 | 1838     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 1839     if (!currentPane) return; | 
| Chris@0 | 1840 | 
| Chris@0 | 1841     Layer *layer = currentPane->getSelectedLayer(); | 
| Chris@0 | 1842     if (!layer) return; | 
| Chris@0 | 1843 | 
| Chris@0 | 1844     Clipboard &clipboard = m_viewManager->getClipboard(); | 
| Chris@0 | 1845     clipboard.clear(); | 
| Chris@0 | 1846 | 
| Chris@0 | 1847     MultiSelection::SelectionList selections = m_viewManager->getSelections(); | 
| Chris@0 | 1848 | 
| Chris@0 | 1849     for (MultiSelection::SelectionList::iterator i = selections.begin(); | 
| Chris@0 | 1850          i != selections.end(); ++i) { | 
| Chris@0 | 1851         layer->copy(*i, clipboard); | 
| Chris@0 | 1852     } | 
| Chris@0 | 1853 } | 
| Chris@0 | 1854 | 
| Chris@0 | 1855 void | 
| Chris@0 | 1856 MainWindow::paste() | 
| Chris@0 | 1857 { | 
| Chris@0 | 1858     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 1859     if (!currentPane) return; | 
| Chris@0 | 1860 | 
| Chris@0 | 1861     //!!! if we have no current layer, we should create one of the most | 
| Chris@0 | 1862     // appropriate type | 
| Chris@0 | 1863 | 
| Chris@0 | 1864     Layer *layer = currentPane->getSelectedLayer(); | 
| Chris@0 | 1865     if (!layer) return; | 
| Chris@0 | 1866 | 
| Chris@0 | 1867     Clipboard &clipboard = m_viewManager->getClipboard(); | 
| Chris@0 | 1868     Clipboard::PointList contents = clipboard.getPoints(); | 
| Chris@0 | 1869 /* | 
| Chris@0 | 1870     long minFrame = 0; | 
| Chris@0 | 1871     bool have = false; | 
| Chris@0 | 1872     for (int i = 0; i < contents.size(); ++i) { | 
| Chris@0 | 1873         if (!contents[i].haveFrame()) continue; | 
| Chris@0 | 1874         if (!have || contents[i].getFrame() < minFrame) { | 
| Chris@0 | 1875             minFrame = contents[i].getFrame(); | 
| Chris@0 | 1876             have = true; | 
| Chris@0 | 1877         } | 
| Chris@0 | 1878     } | 
| Chris@0 | 1879 | 
| Chris@0 | 1880     long frameOffset = long(m_viewManager->getGlobalCentreFrame()) - minFrame; | 
| Chris@0 | 1881 | 
| Chris@0 | 1882     layer->paste(clipboard, frameOffset); | 
| Chris@0 | 1883 */ | 
| Chris@0 | 1884     layer->paste(clipboard, 0, true); | 
| Chris@0 | 1885 } | 
| Chris@0 | 1886 | 
| Chris@0 | 1887 void | 
| Chris@0 | 1888 MainWindow::deleteSelected() | 
| Chris@0 | 1889 { | 
| Chris@0 | 1890     if (m_paneStack->getCurrentPane() && | 
| Chris@0 | 1891 	m_paneStack->getCurrentPane()->getSelectedLayer()) { | 
| Chris@0 | 1892 | 
| Chris@0 | 1893 	MultiSelection::SelectionList selections = | 
| Chris@0 | 1894 	    m_viewManager->getSelections(); | 
| Chris@0 | 1895 | 
| Chris@0 | 1896 	for (MultiSelection::SelectionList::iterator i = selections.begin(); | 
| Chris@0 | 1897 	     i != selections.end(); ++i) { | 
| Chris@0 | 1898 | 
| Chris@0 | 1899 	    m_paneStack->getCurrentPane()->getSelectedLayer()->deleteSelection(*i); | 
| Chris@0 | 1900 	} | 
| Chris@0 | 1901     } | 
| Chris@0 | 1902 } | 
| Chris@0 | 1903 | 
| Chris@0 | 1904 void | 
| Chris@0 | 1905 MainWindow::insertInstant() | 
| Chris@0 | 1906 { | 
| Chris@0 | 1907     int frame = m_viewManager->getPlaybackFrame(); | 
| Chris@81 | 1908     insertInstantAt(frame); | 
| Chris@81 | 1909 } | 
| Chris@81 | 1910 | 
| Chris@81 | 1911 void | 
| Chris@81 | 1912 MainWindow::insertInstantsAtBoundaries() | 
| Chris@81 | 1913 { | 
| Chris@81 | 1914     MultiSelection::SelectionList selections = m_viewManager->getSelections(); | 
| Chris@81 | 1915     for (MultiSelection::SelectionList::iterator i = selections.begin(); | 
| Chris@81 | 1916          i != selections.end(); ++i) { | 
| Chris@81 | 1917         size_t start = i->getStartFrame(); | 
| Chris@81 | 1918         size_t end = i->getEndFrame(); | 
| Chris@81 | 1919         if (start != end) { | 
| Chris@81 | 1920             insertInstantAt(i->getStartFrame()); | 
| Chris@81 | 1921             insertInstantAt(i->getEndFrame()); | 
| Chris@81 | 1922         } | 
| Chris@81 | 1923     } | 
| Chris@81 | 1924 } | 
| Chris@81 | 1925 | 
| Chris@81 | 1926 void | 
| Chris@81 | 1927 MainWindow::insertInstantAt(size_t frame) | 
| Chris@81 | 1928 { | 
| Chris@0 | 1929     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 1930     if (!pane) { | 
| Chris@0 | 1931         return; | 
| Chris@0 | 1932     } | 
| Chris@0 | 1933 | 
| Chris@0 | 1934     Layer *layer = dynamic_cast<TimeInstantLayer *> | 
| Chris@0 | 1935         (pane->getSelectedLayer()); | 
| Chris@0 | 1936 | 
| Chris@0 | 1937     if (!layer) { | 
| Chris@0 | 1938         for (int i = pane->getLayerCount(); i > 0; --i) { | 
| Chris@0 | 1939             layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1)); | 
| Chris@0 | 1940             if (layer) break; | 
| Chris@0 | 1941         } | 
| Chris@0 | 1942 | 
| Chris@0 | 1943         if (!layer) { | 
| Chris@0 | 1944             CommandHistory::getInstance()->startCompoundOperation | 
| Chris@0 | 1945                 (tr("Add Point"), true); | 
| Chris@0 | 1946             layer = m_document->createEmptyLayer(LayerFactory::TimeInstants); | 
| Chris@0 | 1947             if (layer) { | 
| Chris@0 | 1948                 m_document->addLayerToView(pane, layer); | 
| Chris@0 | 1949                 m_paneStack->setCurrentLayer(pane, layer); | 
| Chris@0 | 1950             } | 
| Chris@0 | 1951             CommandHistory::getInstance()->endCompoundOperation(); | 
| Chris@0 | 1952         } | 
| Chris@0 | 1953     } | 
| Chris@0 | 1954 | 
| Chris@0 | 1955     if (layer) { | 
| Chris@0 | 1956 | 
| Chris@0 | 1957         Model *model = layer->getModel(); | 
| Chris@0 | 1958         SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *> | 
| Chris@0 | 1959             (model); | 
| Chris@0 | 1960 | 
| Chris@0 | 1961         if (sodm) { | 
| Chris@0 | 1962             SparseOneDimensionalModel::Point point | 
| Chris@0 | 1963                 (frame, QString("%1").arg(sodm->getPointCount() + 1)); | 
| Chris@0 | 1964             CommandHistory::getInstance()->addCommand | 
| Chris@0 | 1965                 (new SparseOneDimensionalModel::AddPointCommand(sodm, point, | 
| Chris@0 | 1966                                                                 tr("Add Points")), | 
| Chris@0 | 1967                  true, true); // bundled | 
| Chris@0 | 1968         } | 
| Chris@0 | 1969     } | 
| Chris@0 | 1970 } | 
| Chris@0 | 1971 | 
| Chris@0 | 1972 void | 
| Chris@0 | 1973 MainWindow::importAudio() | 
| Chris@0 | 1974 { | 
| Chris@88 | 1975     QString path = getOpenFileName(FileFinder::AudioFile); | 
| Chris@0 | 1976 | 
| Chris@0 | 1977     if (path != "") { | 
| Chris@82 | 1978 	if (openAudioFile(path, ReplaceMainModel) == FileOpenFailed) { | 
| Chris@0 | 1979 	    QMessageBox::critical(this, tr("Failed to open file"), | 
| Chris@0 | 1980 				  tr("Audio file \"%1\" could not be opened").arg(path)); | 
| Chris@0 | 1981 	} | 
| Chris@0 | 1982     } | 
| Chris@0 | 1983 } | 
| Chris@0 | 1984 | 
| Chris@0 | 1985 void | 
| Chris@0 | 1986 MainWindow::importMoreAudio() | 
| Chris@0 | 1987 { | 
| Chris@88 | 1988     QString path = getOpenFileName(FileFinder::AudioFile); | 
| Chris@0 | 1989 | 
| Chris@0 | 1990     if (path != "") { | 
| Chris@82 | 1991 	if (openAudioFile(path, CreateAdditionalModel) == FileOpenFailed) { | 
| Chris@0 | 1992 	    QMessageBox::critical(this, tr("Failed to open file"), | 
| Chris@0 | 1993 				  tr("Audio file \"%1\" could not be opened").arg(path)); | 
| Chris@0 | 1994 	} | 
| Chris@0 | 1995     } | 
| Chris@0 | 1996 } | 
| Chris@0 | 1997 | 
| Chris@0 | 1998 void | 
| Chris@0 | 1999 MainWindow::exportAudio() | 
| Chris@0 | 2000 { | 
| Chris@0 | 2001     if (!getMainModel()) return; | 
| Chris@0 | 2002 | 
| Chris@88 | 2003     QString path = getSaveFileName(FileFinder::AudioFile); | 
| Chris@0 | 2004 | 
| Chris@0 | 2005     if (path == "") return; | 
| Chris@0 | 2006 | 
| Chris@0 | 2007     bool ok = false; | 
| Chris@0 | 2008     QString error; | 
| Chris@0 | 2009 | 
| Chris@0 | 2010     MultiSelection ms = m_viewManager->getSelection(); | 
| Chris@0 | 2011     MultiSelection::SelectionList selections = m_viewManager->getSelections(); | 
| Chris@0 | 2012 | 
| Chris@0 | 2013     bool multiple = false; | 
| Chris@0 | 2014 | 
| Chris@38 | 2015     MultiSelection *selectionToWrite = 0; | 
| Chris@38 | 2016 | 
| Chris@38 | 2017     if (selections.size() == 1) { | 
| Chris@0 | 2018 | 
| Chris@0 | 2019 	QStringList items; | 
| Chris@0 | 2020 	items << tr("Export the selected region only") | 
| Chris@0 | 2021 	      << tr("Export the whole audio file"); | 
| Chris@0 | 2022 | 
| Chris@0 | 2023 	bool ok = false; | 
| Chris@0 | 2024 	QString item = ListInputDialog::getItem | 
| Chris@0 | 2025 	    (this, tr("Select region to export"), | 
| Chris@0 | 2026 	     tr("Which region from the original audio file do you want to export?"), | 
| Chris@0 | 2027 	     items, 0, &ok); | 
| Chris@0 | 2028 | 
| Chris@0 | 2029 	if (!ok || item.isEmpty()) return; | 
| Chris@0 | 2030 | 
| Chris@38 | 2031 	if (item == items[0]) selectionToWrite = &ms; | 
| Chris@38 | 2032 | 
| Chris@38 | 2033     } else if (selections.size() > 1) { | 
| Chris@0 | 2034 | 
| Chris@0 | 2035 	QStringList items; | 
| Chris@0 | 2036 	items << tr("Export the selected regions into a single audio file") | 
| Chris@0 | 2037 	      << tr("Export the selected regions into separate files") | 
| Chris@0 | 2038 	      << tr("Export the whole audio file"); | 
| Chris@0 | 2039 | 
| Chris@0 | 2040 	QString item = ListInputDialog::getItem | 
| Chris@0 | 2041 	    (this, tr("Select region to export"), | 
| Chris@0 | 2042 	     tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"), | 
| Chris@0 | 2043 	     items, 0, &ok); | 
| Chris@0 | 2044 | 
| Chris@0 | 2045 	if (!ok || item.isEmpty()) return; | 
| Chris@0 | 2046 | 
| Chris@0 | 2047 	if (item == items[0]) { | 
| Chris@0 | 2048 | 
| Chris@38 | 2049             selectionToWrite = &ms; | 
| Chris@38 | 2050 | 
| Chris@38 | 2051         } else if (item == items[1]) { | 
| Chris@0 | 2052 | 
| Chris@0 | 2053             multiple = true; | 
| Chris@0 | 2054 | 
| Chris@0 | 2055 	    int n = 1; | 
| Chris@0 | 2056 	    QString base = path; | 
| Chris@0 | 2057 	    base.replace(".wav", ""); | 
| Chris@0 | 2058 | 
| Chris@0 | 2059 	    for (MultiSelection::SelectionList::iterator i = selections.begin(); | 
| Chris@0 | 2060 		 i != selections.end(); ++i) { | 
| Chris@0 | 2061 | 
| Chris@0 | 2062 		MultiSelection subms; | 
| Chris@0 | 2063 		subms.setSelection(*i); | 
| Chris@0 | 2064 | 
| Chris@0 | 2065 		QString subpath = QString("%1.%2.wav").arg(base).arg(n); | 
| Chris@0 | 2066 		++n; | 
| Chris@0 | 2067 | 
| Chris@0 | 2068 		if (QFileInfo(subpath).exists()) { | 
| Chris@0 | 2069 		    error = tr("Fragment file %1 already exists, aborting").arg(subpath); | 
| Chris@0 | 2070 		    break; | 
| Chris@0 | 2071 		} | 
| Chris@0 | 2072 | 
| Chris@38 | 2073 		WavFileWriter subwriter(subpath, | 
| Chris@38 | 2074                                         getMainModel()->getSampleRate(), | 
| Chris@38 | 2075                                         getMainModel()->getChannelCount()); | 
| Chris@38 | 2076                 subwriter.writeModel(getMainModel(), &subms); | 
| Chris@0 | 2077 		ok = subwriter.isOK(); | 
| Chris@0 | 2078 | 
| Chris@0 | 2079 		if (!ok) { | 
| Chris@0 | 2080 		    error = subwriter.getError(); | 
| Chris@0 | 2081 		    break; | 
| Chris@0 | 2082 		} | 
| Chris@0 | 2083 	    } | 
| Chris@0 | 2084 	} | 
| Chris@0 | 2085     } | 
| Chris@0 | 2086 | 
| Chris@38 | 2087     if (!multiple) { | 
| Chris@38 | 2088         WavFileWriter writer(path, | 
| Chris@38 | 2089                              getMainModel()->getSampleRate(), | 
| Chris@38 | 2090                              getMainModel()->getChannelCount()); | 
| Chris@38 | 2091         writer.writeModel(getMainModel(), selectionToWrite); | 
| Chris@38 | 2092 	ok = writer.isOK(); | 
| Chris@38 | 2093 	error = writer.getError(); | 
| Chris@0 | 2094     } | 
| Chris@0 | 2095 | 
| Chris@0 | 2096     if (ok) { | 
| Chris@0 | 2097         if (!multiple) { | 
| Chris@34 | 2098             m_recentFiles.addFile(path); | 
| Chris@0 | 2099         } | 
| Chris@0 | 2100     } else { | 
| Chris@0 | 2101 	QMessageBox::critical(this, tr("Failed to write file"), error); | 
| Chris@0 | 2102     } | 
| Chris@0 | 2103 } | 
| Chris@0 | 2104 | 
| Chris@0 | 2105 void | 
| Chris@0 | 2106 MainWindow::importLayer() | 
| Chris@0 | 2107 { | 
| Chris@0 | 2108     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 2109 | 
| Chris@0 | 2110     if (!pane) { | 
| Chris@0 | 2111 	// shouldn't happen, as the menu action should have been disabled | 
| Chris@0 | 2112 	std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl; | 
| Chris@0 | 2113 	return; | 
| Chris@0 | 2114     } | 
| Chris@0 | 2115 | 
| Chris@0 | 2116     if (!getMainModel()) { | 
| Chris@0 | 2117 	// shouldn't happen, as the menu action should have been disabled | 
| Chris@0 | 2118 	std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl; | 
| Chris@0 | 2119 	return; | 
| Chris@0 | 2120     } | 
| Chris@0 | 2121 | 
| Chris@88 | 2122     QString path = getOpenFileName(FileFinder::LayerFile); | 
| Chris@0 | 2123 | 
| Chris@0 | 2124     if (path != "") { | 
| Chris@0 | 2125 | 
| Chris@82 | 2126         if (openLayerFile(path) == FileOpenFailed) { | 
| Chris@0 | 2127             QMessageBox::critical(this, tr("Failed to open file"), | 
| Chris@0 | 2128                                   tr("File %1 could not be opened.").arg(path)); | 
| Chris@0 | 2129             return; | 
| Chris@0 | 2130         } | 
| Chris@0 | 2131     } | 
| Chris@0 | 2132 } | 
| Chris@0 | 2133 | 
| Chris@82 | 2134 MainWindow::FileOpenStatus | 
| Chris@0 | 2135 MainWindow::openLayerFile(QString path) | 
| Chris@0 | 2136 { | 
| Chris@86 | 2137     return openLayerFile(path, path); | 
| Chris@86 | 2138 } | 
| Chris@86 | 2139 | 
| Chris@86 | 2140 MainWindow::FileOpenStatus | 
| Chris@86 | 2141 MainWindow::openLayerFile(QString path, QString location) | 
| Chris@86 | 2142 { | 
| Chris@0 | 2143     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 2144 | 
| Chris@0 | 2145     if (!pane) { | 
| Chris@0 | 2146 	// shouldn't happen, as the menu action should have been disabled | 
| Chris@0 | 2147 	std::cerr << "WARNING: MainWindow::openLayerFile: no current pane" << std::endl; | 
| Chris@82 | 2148 	return FileOpenFailed; | 
| Chris@0 | 2149     } | 
| Chris@0 | 2150 | 
| Chris@0 | 2151     if (!getMainModel()) { | 
| Chris@0 | 2152 	// shouldn't happen, as the menu action should have been disabled | 
| Chris@0 | 2153 	std::cerr << "WARNING: MainWindow::openLayerFile: No main model -- hence no default sample rate available" << std::endl; | 
| Chris@82 | 2154 	return FileOpenFailed; | 
| Chris@0 | 2155     } | 
| Chris@0 | 2156 | 
| Chris@86 | 2157     bool realFile = (location == path); | 
| Chris@86 | 2158 | 
| Chris@0 | 2159     if (path.endsWith(".svl") || path.endsWith(".xml")) { | 
| Chris@0 | 2160 | 
| Chris@0 | 2161         PaneCallback callback(this); | 
| Chris@0 | 2162         QFile file(path); | 
| Chris@0 | 2163 | 
| Chris@0 | 2164         if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { | 
| Chris@0 | 2165             std::cerr << "ERROR: MainWindow::openLayerFile(" | 
| Chris@86 | 2166                       << location.toStdString() | 
| Chris@0 | 2167                       << "): Failed to open file for reading" << std::endl; | 
| Chris@82 | 2168             return FileOpenFailed; | 
| Chris@0 | 2169         } | 
| Chris@0 | 2170 | 
| Chris@87 | 2171         SVFileReader reader(m_document, callback, location); | 
| Chris@0 | 2172         reader.setCurrentPane(pane); | 
| Chris@0 | 2173 | 
| Chris@0 | 2174         QXmlInputSource inputSource(&file); | 
| Chris@0 | 2175         reader.parse(inputSource); | 
| Chris@0 | 2176 | 
| Chris@0 | 2177         if (!reader.isOK()) { | 
| Chris@0 | 2178             std::cerr << "ERROR: MainWindow::openLayerFile(" | 
| Chris@86 | 2179                       << location.toStdString() | 
| Chris@0 | 2180                       << "): Failed to read XML file: " | 
| Chris@0 | 2181                       << reader.getErrorString().toStdString() << std::endl; | 
| Chris@82 | 2182             return FileOpenFailed; | 
| Chris@0 | 2183         } | 
| Chris@0 | 2184 | 
| Chris@86 | 2185         m_recentFiles.addFile(location); | 
| Chris@86 | 2186 | 
| Chris@86 | 2187         if (realFile) { | 
| Chris@88 | 2188             registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog | 
| Chris@86 | 2189         } | 
| Chris@86 | 2190 | 
| Chris@82 | 2191         return FileOpenSucceeded; | 
| Chris@0 | 2192 | 
| Chris@0 | 2193     } else { | 
| Chris@0 | 2194 | 
| Chris@0 | 2195         Model *model = DataFileReaderFactory::load(path, getMainModel()->getSampleRate()); | 
| Chris@0 | 2196 | 
| Chris@0 | 2197         if (model) { | 
| Chris@86 | 2198 | 
| Chris@0 | 2199             Layer *newLayer = m_document->createImportedLayer(model); | 
| Chris@86 | 2200 | 
| Chris@0 | 2201             if (newLayer) { | 
| Chris@86 | 2202 | 
| Chris@0 | 2203                 m_document->addLayerToView(pane, newLayer); | 
| Chris@86 | 2204                 m_recentFiles.addFile(location); | 
| Chris@86 | 2205 | 
| Chris@86 | 2206                 if (realFile) { | 
| Chris@88 | 2207                     registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog | 
| Chris@86 | 2208                 } | 
| Chris@86 | 2209 | 
| Chris@82 | 2210                 return FileOpenSucceeded; | 
| Chris@0 | 2211             } | 
| Chris@0 | 2212         } | 
| Chris@0 | 2213     } | 
| Chris@0 | 2214 | 
| Chris@82 | 2215     return FileOpenFailed; | 
| Chris@0 | 2216 } | 
| Chris@0 | 2217 | 
| Chris@0 | 2218 void | 
| Chris@0 | 2219 MainWindow::exportLayer() | 
| Chris@0 | 2220 { | 
| Chris@0 | 2221     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 2222     if (!pane) return; | 
| Chris@0 | 2223 | 
| Chris@0 | 2224     Layer *layer = pane->getSelectedLayer(); | 
| Chris@0 | 2225     if (!layer) return; | 
| Chris@0 | 2226 | 
| Chris@0 | 2227     Model *model = layer->getModel(); | 
| Chris@0 | 2228     if (!model) return; | 
| Chris@0 | 2229 | 
| Chris@88 | 2230     QString path = getSaveFileName(FileFinder::LayerFile); | 
| Chris@0 | 2231 | 
| Chris@0 | 2232     if (path == "") return; | 
| Chris@0 | 2233 | 
| Chris@0 | 2234     if (QFileInfo(path).suffix() == "") path += ".svl"; | 
| Chris@0 | 2235 | 
| Chris@0 | 2236     QString error; | 
| Chris@0 | 2237 | 
| Chris@0 | 2238     if (path.endsWith(".xml") || path.endsWith(".svl")) { | 
| Chris@0 | 2239 | 
| Chris@0 | 2240         QFile file(path); | 
| Chris@0 | 2241         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { | 
| Chris@0 | 2242             error = tr("Failed to open file %1 for writing").arg(path); | 
| Chris@0 | 2243         } else { | 
| Chris@0 | 2244             QTextStream out(&file); | 
| Chris@0 | 2245             out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | 
| Chris@0 | 2246                 << "<!DOCTYPE sonic-visualiser>\n" | 
| Chris@0 | 2247                 << "<sv>\n" | 
| Chris@0 | 2248                 << "  <data>\n"; | 
| Chris@0 | 2249 | 
| Chris@0 | 2250             model->toXml(out, "    "); | 
| Chris@0 | 2251 | 
| Chris@0 | 2252             out << "  </data>\n" | 
| Chris@0 | 2253                 << "  <display>\n"; | 
| Chris@0 | 2254 | 
| Chris@0 | 2255             layer->toXml(out, "    "); | 
| Chris@0 | 2256 | 
| Chris@0 | 2257             out << "  </display>\n" | 
| Chris@0 | 2258                 << "</sv>\n"; | 
| Chris@0 | 2259         } | 
| Chris@0 | 2260 | 
| Chris@0 | 2261     } else { | 
| Chris@0 | 2262 | 
| Chris@0 | 2263         CSVFileWriter writer(path, model, | 
| Chris@0 | 2264                              (path.endsWith(".csv") ? "," : "\t")); | 
| Chris@0 | 2265         writer.write(); | 
| Chris@0 | 2266 | 
| Chris@0 | 2267         if (!writer.isOK()) { | 
| Chris@0 | 2268             error = writer.getError(); | 
| Chris@0 | 2269         } | 
| Chris@0 | 2270     } | 
| Chris@0 | 2271 | 
| Chris@0 | 2272     if (error != "") { | 
| Chris@0 | 2273         QMessageBox::critical(this, tr("Failed to write file"), error); | 
| Chris@0 | 2274     } else { | 
| Chris@34 | 2275         m_recentFiles.addFile(path); | 
| Chris@0 | 2276     } | 
| Chris@0 | 2277 } | 
| Chris@0 | 2278 | 
| Chris@82 | 2279 MainWindow::FileOpenStatus | 
| Chris@0 | 2280 MainWindow::openAudioFile(QString path, AudioFileOpenMode mode) | 
| Chris@0 | 2281 { | 
| Chris@86 | 2282     return openAudioFile(path, path, mode); | 
| Chris@86 | 2283 } | 
| Chris@86 | 2284 | 
| Chris@86 | 2285 MainWindow::FileOpenStatus | 
| Chris@86 | 2286 MainWindow::openAudioFile(QString path, QString location, AudioFileOpenMode mode) | 
| Chris@86 | 2287 { | 
| Chris@0 | 2288     if (!(QFileInfo(path).exists() && | 
| Chris@0 | 2289 	  QFileInfo(path).isFile() && | 
| Chris@0 | 2290 	  QFileInfo(path).isReadable())) { | 
| Chris@82 | 2291 	return FileOpenFailed; | 
| Chris@0 | 2292     } | 
| Chris@0 | 2293 | 
| Chris@70 | 2294     m_openingAudioFile = true; | 
| Chris@70 | 2295 | 
| Chris@88 | 2296     WaveFileModel *newModel = new WaveFileModel(path, location); | 
| Chris@0 | 2297 | 
| Chris@0 | 2298     if (!newModel->isOK()) { | 
| Chris@0 | 2299 	delete newModel; | 
| Chris@70 | 2300         m_openingAudioFile = false; | 
| Chris@82 | 2301 	return FileOpenFailed; | 
| Chris@0 | 2302     } | 
| Chris@0 | 2303 | 
| Chris@0 | 2304     bool setAsMain = true; | 
| Chris@0 | 2305     static bool prevSetAsMain = true; | 
| Chris@0 | 2306 | 
| Chris@86 | 2307     bool realFile = (location == path); | 
| Chris@86 | 2308 | 
| Chris@0 | 2309     if (mode == CreateAdditionalModel) setAsMain = false; | 
| Chris@0 | 2310     else if (mode == AskUser) { | 
| Chris@0 | 2311         if (m_document->getMainModel()) { | 
| Chris@0 | 2312 | 
| Chris@0 | 2313             QStringList items; | 
| Chris@0 | 2314             items << tr("Replace the existing main waveform") | 
| Chris@0 | 2315                   << tr("Load this file into a new waveform pane"); | 
| Chris@0 | 2316 | 
| Chris@0 | 2317             bool ok = false; | 
| Chris@0 | 2318             QString item = ListInputDialog::getItem | 
| Chris@0 | 2319                 (this, tr("Select target for import"), | 
| Chris@0 | 2320                  tr("You already have an audio waveform loaded.\nWhat would you like to do with the new audio file?"), | 
| Chris@0 | 2321                  items, prevSetAsMain ? 0 : 1, &ok); | 
| Chris@0 | 2322 | 
| Chris@0 | 2323             if (!ok || item.isEmpty()) { | 
| Chris@0 | 2324                 delete newModel; | 
| Chris@70 | 2325                 m_openingAudioFile = false; | 
| Chris@82 | 2326                 return FileOpenCancelled; | 
| Chris@0 | 2327             } | 
| Chris@0 | 2328 | 
| Chris@0 | 2329             setAsMain = (item == items[0]); | 
| Chris@0 | 2330             prevSetAsMain = setAsMain; | 
| Chris@0 | 2331         } | 
| Chris@0 | 2332     } | 
| Chris@0 | 2333 | 
| Chris@0 | 2334     if (setAsMain) { | 
| Chris@0 | 2335 | 
| Chris@0 | 2336         Model *prevMain = getMainModel(); | 
| Chris@0 | 2337         if (prevMain) m_playSource->removeModel(prevMain); | 
| Chris@0 | 2338 | 
| Chris@0 | 2339 	PlayParameterRepository::getInstance()->clear(); | 
| Chris@0 | 2340 | 
| Chris@0 | 2341 	// The clear() call will have removed the parameters for the | 
| Chris@0 | 2342 	// main model.  Re-add them with the new one. | 
| Chris@0 | 2343 	PlayParameterRepository::getInstance()->addModel(newModel); | 
| Chris@0 | 2344 | 
| Chris@0 | 2345 	m_document->setMainModel(newModel); | 
| Chris@0 | 2346 	setupMenus(); | 
| Chris@0 | 2347 | 
| Chris@0 | 2348 	if (m_sessionFile == "") { | 
| Chris@0 | 2349 	    setWindowTitle(tr("Sonic Visualiser: %1") | 
| Chris@86 | 2350 			   .arg(QFileInfo(location).fileName())); | 
| Chris@0 | 2351 	    CommandHistory::getInstance()->clear(); | 
| Chris@0 | 2352 	    CommandHistory::getInstance()->documentSaved(); | 
| Chris@0 | 2353 	    m_documentModified = false; | 
| Chris@0 | 2354 	} else { | 
| Chris@0 | 2355 	    setWindowTitle(tr("Sonic Visualiser: %1 [%2]") | 
| Chris@0 | 2356 			   .arg(QFileInfo(m_sessionFile).fileName()) | 
| Chris@86 | 2357 			   .arg(QFileInfo(location).fileName())); | 
| Chris@0 | 2358 	    if (m_documentModified) { | 
| Chris@0 | 2359 		m_documentModified = false; | 
| Chris@0 | 2360 		documentModified(); // so as to restore "(modified)" window title | 
| Chris@0 | 2361 	    } | 
| Chris@0 | 2362 	} | 
| Chris@0 | 2363 | 
| Chris@86 | 2364         if (realFile) m_audioFile = path; | 
| Chris@0 | 2365 | 
| Chris@0 | 2366     } else { // !setAsMain | 
| Chris@0 | 2367 | 
| Chris@0 | 2368 	CommandHistory::getInstance()->startCompoundOperation | 
| Chris@86 | 2369 	    (tr("Import \"%1\"").arg(QFileInfo(location).fileName()), true); | 
| Chris@0 | 2370 | 
| Chris@0 | 2371 	m_document->addImportedModel(newModel); | 
| Chris@0 | 2372 | 
| Chris@0 | 2373 	AddPaneCommand *command = new AddPaneCommand(this); | 
| Chris@0 | 2374 	CommandHistory::getInstance()->addCommand(command); | 
| Chris@0 | 2375 | 
| Chris@0 | 2376 	Pane *pane = command->getPane(); | 
| Chris@0 | 2377 | 
| Chris@0 | 2378 	if (!m_timeRulerLayer) { | 
| Chris@0 | 2379 	    m_timeRulerLayer = m_document->createMainModelLayer | 
| Chris@0 | 2380 		(LayerFactory::TimeRuler); | 
| Chris@0 | 2381 	} | 
| Chris@0 | 2382 | 
| Chris@0 | 2383 	m_document->addLayerToView(pane, m_timeRulerLayer); | 
| Chris@0 | 2384 | 
| Chris@0 | 2385 	Layer *newLayer = m_document->createImportedLayer(newModel); | 
| Chris@0 | 2386 | 
| Chris@0 | 2387 	if (newLayer) { | 
| Chris@0 | 2388 	    m_document->addLayerToView(pane, newLayer); | 
| Chris@0 | 2389 	} | 
| Chris@0 | 2390 | 
| Chris@0 | 2391 	CommandHistory::getInstance()->endCompoundOperation(); | 
| Chris@0 | 2392     } | 
| Chris@0 | 2393 | 
| Chris@0 | 2394     updateMenuStates(); | 
| Chris@86 | 2395     m_recentFiles.addFile(location); | 
| Chris@86 | 2396     if (realFile) { | 
| Chris@88 | 2397         registerLastOpenedFilePath(FileFinder::AudioFile, path); // for file dialog | 
| Chris@86 | 2398     } | 
| Chris@70 | 2399     m_openingAudioFile = false; | 
| Chris@0 | 2400 | 
| Chris@82 | 2401     return FileOpenSucceeded; | 
| Chris@0 | 2402 } | 
| Chris@0 | 2403 | 
| Chris@0 | 2404 void | 
| Chris@0 | 2405 MainWindow::createPlayTarget() | 
| Chris@0 | 2406 { | 
| Chris@0 | 2407     if (m_playTarget) return; | 
| Chris@0 | 2408 | 
| Chris@0 | 2409     m_playTarget = AudioTargetFactory::createCallbackTarget(m_playSource); | 
| Chris@0 | 2410     if (!m_playTarget) { | 
| Chris@0 | 2411 	QMessageBox::warning | 
| Chris@0 | 2412 	    (this, tr("Couldn't open audio device"), | 
| Chris@0 | 2413 	     tr("Could not open an audio device for playback.\nAudio playback will not be available during this session.\n"), | 
| Chris@0 | 2414 	     QMessageBox::Ok, 0); | 
| Chris@0 | 2415     } | 
| Chris@0 | 2416     connect(m_fader, SIGNAL(valueChanged(float)), | 
| Chris@0 | 2417 	    m_playTarget, SLOT(setOutputGain(float))); | 
| Chris@0 | 2418 } | 
| Chris@0 | 2419 | 
| Chris@0 | 2420 WaveFileModel * | 
| Chris@0 | 2421 MainWindow::getMainModel() | 
| Chris@0 | 2422 { | 
| Chris@0 | 2423     if (!m_document) return 0; | 
| Chris@0 | 2424     return m_document->getMainModel(); | 
| Chris@0 | 2425 } | 
| Chris@0 | 2426 | 
| Chris@116 | 2427 const WaveFileModel * | 
| Chris@116 | 2428 MainWindow::getMainModel() const | 
| Chris@116 | 2429 { | 
| Chris@116 | 2430     if (!m_document) return 0; | 
| Chris@116 | 2431     return m_document->getMainModel(); | 
| Chris@116 | 2432 } | 
| Chris@116 | 2433 | 
| Chris@0 | 2434 void | 
| Chris@0 | 2435 MainWindow::newSession() | 
| Chris@0 | 2436 { | 
| Chris@0 | 2437     if (!checkSaveModified()) return; | 
| Chris@0 | 2438 | 
| Chris@0 | 2439     closeSession(); | 
| Chris@0 | 2440     createDocument(); | 
| Chris@0 | 2441 | 
| Chris@0 | 2442     Pane *pane = m_paneStack->addPane(); | 
| Chris@0 | 2443 | 
| Chris@90 | 2444     connect(pane, SIGNAL(contextHelpChanged(const QString &)), | 
| Chris@116 | 2445             this, SLOT(contextHelpChanged(const QString &))); | 
| Chris@90 | 2446 | 
| Chris@0 | 2447     if (!m_timeRulerLayer) { | 
| Chris@0 | 2448 	m_timeRulerLayer = m_document->createMainModelLayer | 
| Chris@0 | 2449 	    (LayerFactory::TimeRuler); | 
| Chris@0 | 2450     } | 
| Chris@0 | 2451 | 
| Chris@0 | 2452     m_document->addLayerToView(pane, m_timeRulerLayer); | 
| Chris@0 | 2453 | 
| Chris@0 | 2454     Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform); | 
| Chris@0 | 2455     m_document->addLayerToView(pane, waveform); | 
| Chris@0 | 2456 | 
| Chris@65 | 2457     m_overview->registerView(pane); | 
| Chris@0 | 2458 | 
| Chris@0 | 2459     CommandHistory::getInstance()->clear(); | 
| Chris@0 | 2460     CommandHistory::getInstance()->documentSaved(); | 
| Chris@0 | 2461     documentRestored(); | 
| Chris@0 | 2462     updateMenuStates(); | 
| Chris@0 | 2463 } | 
| Chris@0 | 2464 | 
| Chris@0 | 2465 void | 
| Chris@0 | 2466 MainWindow::createDocument() | 
| Chris@0 | 2467 { | 
| Chris@0 | 2468     m_document = new Document; | 
| Chris@0 | 2469 | 
| Chris@0 | 2470     connect(m_document, SIGNAL(layerAdded(Layer *)), | 
| Chris@0 | 2471 	    this, SLOT(layerAdded(Layer *))); | 
| Chris@0 | 2472     connect(m_document, SIGNAL(layerRemoved(Layer *)), | 
| Chris@0 | 2473 	    this, SLOT(layerRemoved(Layer *))); | 
| Chris@0 | 2474     connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)), | 
| Chris@0 | 2475 	    this, SLOT(layerAboutToBeDeleted(Layer *))); | 
| Chris@0 | 2476     connect(m_document, SIGNAL(layerInAView(Layer *, bool)), | 
| Chris@0 | 2477 	    this, SLOT(layerInAView(Layer *, bool))); | 
| Chris@0 | 2478 | 
| Chris@0 | 2479     connect(m_document, SIGNAL(modelAdded(Model *)), | 
| Chris@0 | 2480 	    this, SLOT(modelAdded(Model *))); | 
| Chris@0 | 2481     connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)), | 
| Chris@0 | 2482 	    this, SLOT(mainModelChanged(WaveFileModel *))); | 
| Chris@0 | 2483     connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)), | 
| Chris@0 | 2484 	    this, SLOT(modelAboutToBeDeleted(Model *))); | 
| Chris@0 | 2485 | 
| Chris@0 | 2486     connect(m_document, SIGNAL(modelGenerationFailed(QString)), | 
| Chris@0 | 2487             this, SLOT(modelGenerationFailed(QString))); | 
| Chris@63 | 2488     connect(m_document, SIGNAL(modelRegenerationFailed(QString, QString)), | 
| Chris@63 | 2489             this, SLOT(modelRegenerationFailed(QString, QString))); | 
| Chris@0 | 2490 } | 
| Chris@0 | 2491 | 
| Chris@0 | 2492 void | 
| Chris@0 | 2493 MainWindow::closeSession() | 
| Chris@0 | 2494 { | 
| Chris@0 | 2495     if (!checkSaveModified()) return; | 
| Chris@0 | 2496 | 
| Chris@0 | 2497     while (m_paneStack->getPaneCount() > 0) { | 
| Chris@0 | 2498 | 
| Chris@0 | 2499 	Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1); | 
| Chris@0 | 2500 | 
| Chris@0 | 2501 	while (pane->getLayerCount() > 0) { | 
| Chris@0 | 2502 	    m_document->removeLayerFromView | 
| Chris@0 | 2503 		(pane, pane->getLayer(pane->getLayerCount() - 1)); | 
| Chris@0 | 2504 	} | 
| Chris@0 | 2505 | 
| Chris@65 | 2506 	m_overview->unregisterView(pane); | 
| Chris@0 | 2507 	m_paneStack->deletePane(pane); | 
| Chris@0 | 2508     } | 
| Chris@0 | 2509 | 
| Chris@0 | 2510     while (m_paneStack->getHiddenPaneCount() > 0) { | 
| Chris@0 | 2511 | 
| Chris@0 | 2512 	Pane *pane = m_paneStack->getHiddenPane | 
| Chris@0 | 2513 	    (m_paneStack->getHiddenPaneCount() - 1); | 
| Chris@0 | 2514 | 
| Chris@0 | 2515 	while (pane->getLayerCount() > 0) { | 
| Chris@0 | 2516 	    m_document->removeLayerFromView | 
| Chris@0 | 2517 		(pane, pane->getLayer(pane->getLayerCount() - 1)); | 
| Chris@0 | 2518 	} | 
| Chris@0 | 2519 | 
| Chris@65 | 2520 	m_overview->unregisterView(pane); | 
| Chris@0 | 2521 	m_paneStack->deletePane(pane); | 
| Chris@0 | 2522     } | 
| Chris@0 | 2523 | 
| Chris@0 | 2524     delete m_document; | 
| Chris@0 | 2525     m_document = 0; | 
| Chris@0 | 2526     m_viewManager->clearSelections(); | 
| Chris@0 | 2527     m_timeRulerLayer = 0; // document owned this | 
| Chris@0 | 2528 | 
| Chris@0 | 2529     m_sessionFile = ""; | 
| Chris@0 | 2530     setWindowTitle(tr("Sonic Visualiser")); | 
| Chris@0 | 2531 | 
| Chris@0 | 2532     CommandHistory::getInstance()->clear(); | 
| Chris@0 | 2533     CommandHistory::getInstance()->documentSaved(); | 
| Chris@0 | 2534     documentRestored(); | 
| Chris@0 | 2535 } | 
| Chris@0 | 2536 | 
| Chris@0 | 2537 void | 
| Chris@0 | 2538 MainWindow::openSession() | 
| Chris@0 | 2539 { | 
| Chris@0 | 2540     if (!checkSaveModified()) return; | 
| Chris@0 | 2541 | 
| Chris@0 | 2542     QString orig = m_audioFile; | 
| Chris@0 | 2543     if (orig == "") orig = "."; | 
| Chris@0 | 2544     else orig = QFileInfo(orig).absoluteDir().canonicalPath(); | 
| Chris@0 | 2545 | 
| Chris@88 | 2546     QString path = getOpenFileName(FileFinder::SessionFile); | 
| Chris@0 | 2547 | 
| Chris@0 | 2548     if (path.isEmpty()) return; | 
| Chris@0 | 2549 | 
| Chris@82 | 2550     if (openSessionFile(path) == FileOpenFailed) { | 
| Chris@0 | 2551 	QMessageBox::critical(this, tr("Failed to open file"), | 
| Chris@0 | 2552 			      tr("Session file \"%1\" could not be opened").arg(path)); | 
| Chris@0 | 2553     } | 
| Chris@0 | 2554 } | 
| Chris@0 | 2555 | 
| Chris@0 | 2556 void | 
| Chris@0 | 2557 MainWindow::openSomething() | 
| Chris@0 | 2558 { | 
| Chris@0 | 2559     QString orig = m_audioFile; | 
| Chris@0 | 2560     if (orig == "") orig = "."; | 
| Chris@0 | 2561     else orig = QFileInfo(orig).absoluteDir().canonicalPath(); | 
| Chris@0 | 2562 | 
| Chris@0 | 2563     bool canImportLayer = (getMainModel() != 0 && | 
| Chris@0 | 2564                            m_paneStack != 0 && | 
| Chris@0 | 2565                            m_paneStack->getCurrentPane() != 0); | 
| Chris@0 | 2566 | 
| Chris@88 | 2567     QString path = getOpenFileName(FileFinder::AnyFile); | 
| Chris@0 | 2568 | 
| Chris@0 | 2569     if (path.isEmpty()) return; | 
| Chris@0 | 2570 | 
| Chris@0 | 2571     if (path.endsWith(".sv")) { | 
| Chris@0 | 2572 | 
| Chris@0 | 2573         if (!checkSaveModified()) return; | 
| Chris@0 | 2574 | 
| Chris@82 | 2575         if (openSessionFile(path) == FileOpenFailed) { | 
| Chris@0 | 2576             QMessageBox::critical(this, tr("Failed to open file"), | 
| Chris@0 | 2577                                   tr("Session file \"%1\" could not be opened").arg(path)); | 
| Chris@0 | 2578         } | 
| Chris@0 | 2579 | 
| Chris@0 | 2580     } else { | 
| Chris@0 | 2581 | 
| Chris@82 | 2582         if (openAudioFile(path, AskUser) == FileOpenFailed) { | 
| Chris@82 | 2583 | 
| Chris@82 | 2584             if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) { | 
| Chris@0 | 2585 | 
| Chris@0 | 2586                 QMessageBox::critical(this, tr("Failed to open file"), | 
| Chris@0 | 2587                                       tr("File \"%1\" could not be opened").arg(path)); | 
| Chris@0 | 2588             } | 
| Chris@0 | 2589         } | 
| Chris@0 | 2590     } | 
| Chris@0 | 2591 } | 
| Chris@0 | 2592 | 
| Chris@0 | 2593 void | 
| Chris@86 | 2594 MainWindow::openLocation() | 
| Chris@86 | 2595 { | 
| Chris@103 | 2596     QSettings settings; | 
| Chris@103 | 2597     settings.beginGroup("MainWindow"); | 
| Chris@103 | 2598     QString lastLocation = settings.value("lastremote", "").toString(); | 
| Chris@103 | 2599 | 
| Chris@86 | 2600     bool ok = false; | 
| Chris@86 | 2601     QString text = QInputDialog::getText | 
| Chris@86 | 2602         (this, tr("Open Location"), | 
| Chris@86 | 2603          tr("Please enter the URL of the location to open:"), | 
| Chris@103 | 2604          QLineEdit::Normal, lastLocation, &ok); | 
| Chris@103 | 2605 | 
| Chris@103 | 2606     if (!ok) return; | 
| Chris@103 | 2607 | 
| Chris@103 | 2608     settings.setValue("lastremote", text); | 
| Chris@103 | 2609 | 
| Chris@103 | 2610     if (text.isEmpty()) return; | 
| Chris@86 | 2611 | 
| Chris@86 | 2612     if (openURL(QUrl(text)) == FileOpenFailed) { | 
| Chris@86 | 2613         QMessageBox::critical(this, tr("Failed to open location"), | 
| Chris@86 | 2614                               tr("URL \"%1\" could not be opened").arg(text)); | 
| Chris@86 | 2615     } | 
| Chris@86 | 2616 } | 
| Chris@86 | 2617 | 
| Chris@86 | 2618 void | 
| Chris@0 | 2619 MainWindow::openRecentFile() | 
| Chris@0 | 2620 { | 
| Chris@0 | 2621     QObject *obj = sender(); | 
| Chris@0 | 2622     QAction *action = dynamic_cast<QAction *>(obj); | 
| Chris@0 | 2623 | 
| Chris@0 | 2624     if (!action) { | 
| Chris@0 | 2625 	std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action" | 
| Chris@0 | 2626 		  << std::endl; | 
| Chris@0 | 2627 	return; | 
| Chris@0 | 2628     } | 
| Chris@0 | 2629 | 
| Chris@0 | 2630     QString path = action->text(); | 
| Chris@0 | 2631     if (path == "") return; | 
| Chris@0 | 2632 | 
| Chris@86 | 2633     QUrl url(path); | 
| Chris@86 | 2634     if (RemoteFile::canHandleScheme(url)) { | 
| Chris@86 | 2635         openURL(url); | 
| Chris@86 | 2636         return; | 
| Chris@86 | 2637     } | 
| Chris@86 | 2638 | 
| Chris@0 | 2639     if (path.endsWith("sv")) { | 
| Chris@0 | 2640 | 
| Chris@103 | 2641         if (!checkSaveModified()) return; | 
| Chris@0 | 2642 | 
| Chris@82 | 2643         if (openSessionFile(path) == FileOpenFailed) { | 
| Chris@0 | 2644             QMessageBox::critical(this, tr("Failed to open file"), | 
| Chris@0 | 2645                                   tr("Session file \"%1\" could not be opened").arg(path)); | 
| Chris@0 | 2646         } | 
| Chris@0 | 2647 | 
| Chris@0 | 2648     } else { | 
| Chris@0 | 2649 | 
| Chris@82 | 2650         if (openAudioFile(path, AskUser) == FileOpenFailed) { | 
| Chris@0 | 2651 | 
| Chris@0 | 2652             bool canImportLayer = (getMainModel() != 0 && | 
| Chris@0 | 2653                                    m_paneStack != 0 && | 
| Chris@0 | 2654                                    m_paneStack->getCurrentPane() != 0); | 
| Chris@0 | 2655 | 
| Chris@82 | 2656             if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) { | 
| Chris@0 | 2657 | 
| Chris@0 | 2658                 QMessageBox::critical(this, tr("Failed to open file"), | 
| Chris@0 | 2659                                       tr("File \"%1\" could not be opened").arg(path)); | 
| Chris@0 | 2660             } | 
| Chris@0 | 2661         } | 
| Chris@0 | 2662     } | 
| Chris@0 | 2663 } | 
| Chris@0 | 2664 | 
| Chris@82 | 2665 MainWindow::FileOpenStatus | 
| Chris@85 | 2666 MainWindow::openURL(QUrl url) | 
| Chris@85 | 2667 { | 
| Chris@85 | 2668     if (url.scheme().toLower() == "file") { | 
| Chris@85 | 2669         return openSomeFile(url.toLocalFile()); | 
| Chris@86 | 2670     } else if (!RemoteFile::canHandleScheme(url)) { | 
| Chris@85 | 2671         QMessageBox::critical(this, tr("Unsupported scheme in URL"), | 
| Chris@85 | 2672                               tr("The URL scheme \"%1\" is not supported") | 
| Chris@85 | 2673                               .arg(url.scheme())); | 
| Chris@85 | 2674         return FileOpenFailed; | 
| Chris@85 | 2675     } else { | 
| Chris@85 | 2676         RemoteFile rf(url); | 
| Chris@85 | 2677         rf.wait(); | 
| Chris@85 | 2678         if (!rf.isOK()) { | 
| Chris@85 | 2679             QMessageBox::critical(this, tr("File download failed"), | 
| Chris@85 | 2680                                   tr("Failed to download URL \"%1\": %2") | 
| Chris@85 | 2681                                   .arg(url.toString()).arg(rf.getErrorString())); | 
| Chris@85 | 2682             return FileOpenFailed; | 
| Chris@85 | 2683         } | 
| Chris@88 | 2684         FileOpenStatus status; | 
| Chris@88 | 2685         if ((status = openSomeFile(rf.getLocalFilename(), url.toString())) != | 
| Chris@88 | 2686             FileOpenSucceeded) { | 
| Chris@88 | 2687             rf.deleteLocalFile(); | 
| Chris@88 | 2688         } | 
| Chris@88 | 2689         return status; | 
| Chris@85 | 2690     } | 
| Chris@85 | 2691 } | 
| Chris@85 | 2692 | 
| Chris@85 | 2693 MainWindow::FileOpenStatus | 
| Chris@54 | 2694 MainWindow::openSomeFile(QString path, AudioFileOpenMode mode) | 
| Chris@0 | 2695 { | 
| Chris@86 | 2696     return openSomeFile(path, path, mode); | 
| Chris@86 | 2697 } | 
| Chris@86 | 2698 | 
| Chris@86 | 2699 MainWindow::FileOpenStatus | 
| Chris@86 | 2700 MainWindow::openSomeFile(QString path, QString location, | 
| Chris@86 | 2701                          AudioFileOpenMode mode) | 
| Chris@86 | 2702 { | 
| Chris@82 | 2703     FileOpenStatus status; | 
| Chris@82 | 2704 | 
| Chris@85 | 2705     bool canImportLayer = (getMainModel() != 0 && | 
| Chris@85 | 2706                            m_paneStack != 0 && | 
| Chris@85 | 2707                            m_paneStack->getCurrentPane() != 0); | 
| Chris@85 | 2708 | 
| Chris@86 | 2709     if ((status = openAudioFile(path, location, mode)) != FileOpenFailed) { | 
| Chris@82 | 2710         return status; | 
| Chris@86 | 2711     } else if ((status = openSessionFile(path, location)) != FileOpenFailed) { | 
| Chris@82 | 2712 	return status; | 
| Chris@85 | 2713     } else if (!canImportLayer) { | 
| Chris@85 | 2714         return FileOpenFailed; | 
| Chris@86 | 2715     } else if ((status = openLayerFile(path, location)) != FileOpenFailed) { | 
| Chris@85 | 2716         return status; | 
| Chris@0 | 2717     } else { | 
| Chris@82 | 2718 	return FileOpenFailed; | 
| Chris@0 | 2719     } | 
| Chris@0 | 2720 } | 
| Chris@0 | 2721 | 
| Chris@82 | 2722 MainWindow::FileOpenStatus | 
| Chris@0 | 2723 MainWindow::openSessionFile(QString path) | 
| Chris@0 | 2724 { | 
| Chris@86 | 2725     return openSessionFile(path, path); | 
| Chris@86 | 2726 } | 
| Chris@86 | 2727 | 
| Chris@86 | 2728 MainWindow::FileOpenStatus | 
| Chris@86 | 2729 MainWindow::openSessionFile(QString path, QString location) | 
| Chris@86 | 2730 { | 
| Chris@0 | 2731     BZipFileDevice bzFile(path); | 
| Chris@0 | 2732     if (!bzFile.open(QIODevice::ReadOnly)) { | 
| Chris@86 | 2733         std::cerr << "Failed to open session file \"" << location.toStdString() | 
| Chris@0 | 2734                   << "\": " << bzFile.errorString().toStdString() << std::endl; | 
| Chris@82 | 2735         return FileOpenFailed; | 
| Chris@0 | 2736     } | 
| Chris@0 | 2737 | 
| Chris@103 | 2738     if (!checkSaveModified()) return FileOpenCancelled; | 
| Chris@103 | 2739 | 
| Chris@0 | 2740     QString error; | 
| Chris@0 | 2741     closeSession(); | 
| Chris@0 | 2742     createDocument(); | 
| Chris@0 | 2743 | 
| Chris@0 | 2744     PaneCallback callback(this); | 
| Chris@0 | 2745     m_viewManager->clearSelections(); | 
| Chris@0 | 2746 | 
| Chris@87 | 2747     SVFileReader reader(m_document, callback, location); | 
| Chris@0 | 2748     QXmlInputSource inputSource(&bzFile); | 
| Chris@0 | 2749     reader.parse(inputSource); | 
| Chris@0 | 2750 | 
| Chris@0 | 2751     if (!reader.isOK()) { | 
| Chris@0 | 2752         error = tr("SV XML file read error:\n%1").arg(reader.getErrorString()); | 
| Chris@0 | 2753     } | 
| Chris@0 | 2754 | 
| Chris@0 | 2755     bzFile.close(); | 
| Chris@0 | 2756 | 
| Chris@0 | 2757     bool ok = (error == ""); | 
| Chris@86 | 2758 | 
| Chris@86 | 2759     bool realFile = (location == path); | 
| Chris@0 | 2760 | 
| Chris@0 | 2761     if (ok) { | 
| Chris@86 | 2762 | 
| Chris@0 | 2763 	setWindowTitle(tr("Sonic Visualiser: %1") | 
| Chris@86 | 2764 		       .arg(QFileInfo(location).fileName())); | 
| Chris@86 | 2765 | 
| Chris@86 | 2766 	if (realFile) m_sessionFile = path; | 
| Chris@86 | 2767 | 
| Chris@0 | 2768 	setupMenus(); | 
| Chris@0 | 2769 	CommandHistory::getInstance()->clear(); | 
| Chris@0 | 2770 	CommandHistory::getInstance()->documentSaved(); | 
| Chris@0 | 2771 	m_documentModified = false; | 
| Chris@0 | 2772 	updateMenuStates(); | 
| Chris@86 | 2773 | 
| Chris@86 | 2774         m_recentFiles.addFile(location); | 
| Chris@86 | 2775 | 
| Chris@86 | 2776         if (realFile) { | 
| Chris@88 | 2777             registerLastOpenedFilePath(FileFinder::SessionFile, path); // for file dialog | 
| Chris@86 | 2778         } | 
| Chris@86 | 2779 | 
| Chris@0 | 2780     } else { | 
| Chris@0 | 2781 	setWindowTitle(tr("Sonic Visualiser")); | 
| Chris@0 | 2782     } | 
| Chris@0 | 2783 | 
| Chris@82 | 2784     return ok ? FileOpenSucceeded : FileOpenFailed; | 
| Chris@0 | 2785 } | 
| Chris@0 | 2786 | 
| Chris@0 | 2787 void | 
| Chris@0 | 2788 MainWindow::closeEvent(QCloseEvent *e) | 
| Chris@0 | 2789 { | 
| Chris@70 | 2790     if (!m_abandoning && !checkSaveModified()) { | 
| Chris@0 | 2791 	e->ignore(); | 
| Chris@0 | 2792 	return; | 
| Chris@0 | 2793     } | 
| Chris@0 | 2794 | 
| Chris@5 | 2795     QSettings settings; | 
| Chris@5 | 2796     settings.beginGroup("MainWindow"); | 
| Chris@5 | 2797     settings.setValue("size", size()); | 
| Chris@5 | 2798     settings.setValue("position", pos()); | 
| Chris@5 | 2799     settings.endGroup(); | 
| Chris@5 | 2800 | 
| Chris@0 | 2801     e->accept(); | 
| Chris@0 | 2802     return; | 
| Chris@0 | 2803 } | 
| Chris@0 | 2804 | 
| Chris@0 | 2805 bool | 
| Chris@11 | 2806 MainWindow::commitData(bool mayAskUser) | 
| Chris@11 | 2807 { | 
| Chris@11 | 2808     if (mayAskUser) { | 
| Chris@11 | 2809         return checkSaveModified(); | 
| Chris@11 | 2810     } else { | 
| Chris@11 | 2811         if (!m_documentModified) return true; | 
| Chris@11 | 2812 | 
| Chris@11 | 2813         // If we can't check with the user first, then we can't save | 
| Chris@11 | 2814         // to the original session file (even if we have it) -- have | 
| Chris@11 | 2815         // to use a temporary file | 
| Chris@11 | 2816 | 
| Chris@11 | 2817         QString svDirBase = ".sv1"; | 
| Chris@11 | 2818         QString svDir = QDir::home().filePath(svDirBase); | 
| Chris@11 | 2819 | 
| Chris@11 | 2820         if (!QFileInfo(svDir).exists()) { | 
| Chris@11 | 2821             if (!QDir::home().mkdir(svDirBase)) return false; | 
| Chris@11 | 2822         } else { | 
| Chris@11 | 2823             if (!QFileInfo(svDir).isDir()) return false; | 
| Chris@11 | 2824         } | 
| Chris@11 | 2825 | 
| Chris@11 | 2826         // This name doesn't have to be unguessable | 
| Chris@93 | 2827 #ifndef _WIN32 | 
| Chris@11 | 2828         QString fname = QString("tmp-%1-%2.sv") | 
| Chris@11 | 2829             .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz")) | 
| Chris@11 | 2830             .arg(QProcess().pid()); | 
| Chris@93 | 2831 #else | 
| Chris@93 | 2832         QString fname = QString("tmp-%1.sv") | 
| Chris@93 | 2833             .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz")); | 
| Chris@93 | 2834 #endif | 
| Chris@11 | 2835         QString fpath = QDir(svDir).filePath(fname); | 
| Chris@11 | 2836         if (saveSessionFile(fpath)) { | 
| Chris@34 | 2837             m_recentFiles.addFile(fpath); | 
| Chris@11 | 2838             return true; | 
| Chris@11 | 2839         } else { | 
| Chris@11 | 2840             return false; | 
| Chris@11 | 2841         } | 
| Chris@11 | 2842     } | 
| Chris@11 | 2843 } | 
| Chris@11 | 2844 | 
| Chris@11 | 2845 bool | 
| Chris@0 | 2846 MainWindow::checkSaveModified() | 
| Chris@0 | 2847 { | 
| Chris@0 | 2848     // Called before some destructive operation (e.g. new session, | 
| Chris@0 | 2849     // exit program).  Return true if we can safely proceed, false to | 
| Chris@0 | 2850     // cancel. | 
| Chris@0 | 2851 | 
| Chris@0 | 2852     if (!m_documentModified) return true; | 
| Chris@0 | 2853 | 
| Chris@0 | 2854     int button = | 
| Chris@0 | 2855 	QMessageBox::warning(this, | 
| Chris@0 | 2856 			     tr("Session modified"), | 
| Chris@0 | 2857 			     tr("The current session has been modified.\nDo you want to save it?"), | 
| Chris@0 | 2858 			     QMessageBox::Yes, | 
| Chris@0 | 2859 			     QMessageBox::No, | 
| Chris@0 | 2860 			     QMessageBox::Cancel); | 
| Chris@0 | 2861 | 
| Chris@0 | 2862     if (button == QMessageBox::Yes) { | 
| Chris@0 | 2863 	saveSession(); | 
| Chris@0 | 2864 	if (m_documentModified) { // save failed -- don't proceed! | 
| Chris@0 | 2865 	    return false; | 
| Chris@0 | 2866 	} else { | 
| Chris@0 | 2867             return true; // saved, so it's safe to continue now | 
| Chris@0 | 2868         } | 
| Chris@0 | 2869     } else if (button == QMessageBox::No) { | 
| Chris@0 | 2870 	m_documentModified = false; // so we know to abandon it | 
| Chris@0 | 2871 	return true; | 
| Chris@0 | 2872     } | 
| Chris@0 | 2873 | 
| Chris@0 | 2874     // else cancel | 
| Chris@0 | 2875     return false; | 
| Chris@0 | 2876 } | 
| Chris@0 | 2877 | 
| Chris@0 | 2878 void | 
| Chris@0 | 2879 MainWindow::saveSession() | 
| Chris@0 | 2880 { | 
| Chris@0 | 2881     if (m_sessionFile != "") { | 
| Chris@0 | 2882 	if (!saveSessionFile(m_sessionFile)) { | 
| Chris@0 | 2883 	    QMessageBox::critical(this, tr("Failed to save file"), | 
| Chris@0 | 2884 				  tr("Session file \"%1\" could not be saved.").arg(m_sessionFile)); | 
| Chris@0 | 2885 	} else { | 
| Chris@0 | 2886 	    CommandHistory::getInstance()->documentSaved(); | 
| Chris@0 | 2887 	    documentRestored(); | 
| Chris@0 | 2888 	} | 
| Chris@0 | 2889     } else { | 
| Chris@0 | 2890 	saveSessionAs(); | 
| Chris@0 | 2891     } | 
| Chris@0 | 2892 } | 
| Chris@0 | 2893 | 
| Chris@0 | 2894 void | 
| Chris@0 | 2895 MainWindow::saveSessionAs() | 
| Chris@0 | 2896 { | 
| Chris@0 | 2897     QString orig = m_audioFile; | 
| Chris@0 | 2898     if (orig == "") orig = "."; | 
| Chris@0 | 2899     else orig = QFileInfo(orig).absoluteDir().canonicalPath(); | 
| Chris@0 | 2900 | 
| Chris@88 | 2901     QString path = getSaveFileName(FileFinder::SessionFile); | 
| Chris@81 | 2902 | 
| Chris@81 | 2903     if (path == "") return; | 
| Chris@0 | 2904 | 
| Chris@0 | 2905     if (!saveSessionFile(path)) { | 
| Chris@0 | 2906 	QMessageBox::critical(this, tr("Failed to save file"), | 
| Chris@79 | 2907 			      tr("Session file \"%1\" could not be saved.").arg(path)); | 
| Chris@0 | 2908     } else { | 
| Chris@0 | 2909 	setWindowTitle(tr("Sonic Visualiser: %1") | 
| Chris@0 | 2910 		       .arg(QFileInfo(path).fileName())); | 
| Chris@0 | 2911 	m_sessionFile = path; | 
| Chris@0 | 2912 	CommandHistory::getInstance()->documentSaved(); | 
| Chris@0 | 2913 	documentRestored(); | 
| Chris@34 | 2914         m_recentFiles.addFile(path); | 
| Chris@0 | 2915     } | 
| Chris@0 | 2916 } | 
| Chris@0 | 2917 | 
| Chris@0 | 2918 bool | 
| Chris@0 | 2919 MainWindow::saveSessionFile(QString path) | 
| Chris@0 | 2920 { | 
| Chris@0 | 2921     BZipFileDevice bzFile(path); | 
| Chris@0 | 2922     if (!bzFile.open(QIODevice::WriteOnly)) { | 
| Chris@0 | 2923         std::cerr << "Failed to open session file \"" << path.toStdString() | 
| Chris@0 | 2924                   << "\" for writing: " | 
| Chris@0 | 2925                   << bzFile.errorString().toStdString() << std::endl; | 
| Chris@0 | 2926         return false; | 
| Chris@0 | 2927     } | 
| Chris@0 | 2928 | 
| Chris@0 | 2929     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); | 
| Chris@0 | 2930 | 
| Chris@0 | 2931     QTextStream out(&bzFile); | 
| Chris@0 | 2932     toXml(out); | 
| Chris@0 | 2933     out.flush(); | 
| Chris@0 | 2934 | 
| Chris@0 | 2935     QApplication::restoreOverrideCursor(); | 
| Chris@0 | 2936 | 
| Chris@84 | 2937     if (!bzFile.isOK()) { | 
| Chris@0 | 2938 	QMessageBox::critical(this, tr("Failed to write file"), | 
| Chris@0 | 2939 			      tr("Failed to write to file \"%1\": %2") | 
| Chris@0 | 2940 			      .arg(path).arg(bzFile.errorString())); | 
| Chris@0 | 2941         bzFile.close(); | 
| Chris@0 | 2942 	return false; | 
| Chris@0 | 2943     } | 
| Chris@0 | 2944 | 
| Chris@0 | 2945     bzFile.close(); | 
| Chris@0 | 2946     return true; | 
| Chris@0 | 2947 } | 
| Chris@0 | 2948 | 
| Chris@0 | 2949 void | 
| Chris@0 | 2950 MainWindow::toXml(QTextStream &out) | 
| Chris@0 | 2951 { | 
| Chris@0 | 2952     QString indent("  "); | 
| Chris@0 | 2953 | 
| Chris@0 | 2954     out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | 
| Chris@0 | 2955     out << "<!DOCTYPE sonic-visualiser>\n"; | 
| Chris@0 | 2956     out << "<sv>\n"; | 
| Chris@0 | 2957 | 
| Chris@0 | 2958     m_document->toXml(out, "", ""); | 
| Chris@0 | 2959 | 
| Chris@0 | 2960     out << "<display>\n"; | 
| Chris@0 | 2961 | 
| Chris@0 | 2962     out << QString("  <window width=\"%1\" height=\"%2\"/>\n") | 
| Chris@0 | 2963 	.arg(width()).arg(height()); | 
| Chris@0 | 2964 | 
| Chris@0 | 2965     for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { | 
| Chris@0 | 2966 | 
| Chris@0 | 2967 	Pane *pane = m_paneStack->getPane(i); | 
| Chris@0 | 2968 | 
| Chris@0 | 2969 	if (pane) { | 
| Chris@0 | 2970             pane->toXml(out, indent); | 
| Chris@0 | 2971 	} | 
| Chris@0 | 2972     } | 
| Chris@0 | 2973 | 
| Chris@0 | 2974     out << "</display>\n"; | 
| Chris@0 | 2975 | 
| Chris@0 | 2976     m_viewManager->getSelection().toXml(out); | 
| Chris@0 | 2977 | 
| Chris@0 | 2978     out << "</sv>\n"; | 
| Chris@0 | 2979 } | 
| Chris@0 | 2980 | 
| Chris@0 | 2981 Pane * | 
| Chris@0 | 2982 MainWindow::addPaneToStack() | 
| Chris@0 | 2983 { | 
| Chris@0 | 2984     AddPaneCommand *command = new AddPaneCommand(this); | 
| Chris@0 | 2985     CommandHistory::getInstance()->addCommand(command); | 
| Chris@0 | 2986     return command->getPane(); | 
| Chris@0 | 2987 } | 
| Chris@0 | 2988 | 
| Chris@0 | 2989 void | 
| Chris@0 | 2990 MainWindow::zoomIn() | 
| Chris@0 | 2991 { | 
| Chris@0 | 2992     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 2993     if (currentPane) currentPane->zoom(true); | 
| Chris@0 | 2994 } | 
| Chris@0 | 2995 | 
| Chris@0 | 2996 void | 
| Chris@0 | 2997 MainWindow::zoomOut() | 
| Chris@0 | 2998 { | 
| Chris@0 | 2999     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3000     if (currentPane) currentPane->zoom(false); | 
| Chris@0 | 3001 } | 
| Chris@0 | 3002 | 
| Chris@0 | 3003 void | 
| Chris@0 | 3004 MainWindow::zoomToFit() | 
| Chris@0 | 3005 { | 
| Chris@0 | 3006     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3007     if (!currentPane) return; | 
| Chris@0 | 3008 | 
| Chris@0 | 3009     Model *model = getMainModel(); | 
| Chris@0 | 3010     if (!model) return; | 
| Chris@0 | 3011 | 
| Chris@0 | 3012     size_t start = model->getStartFrame(); | 
| Chris@0 | 3013     size_t end = model->getEndFrame(); | 
| Chris@0 | 3014     size_t pixels = currentPane->width(); | 
| Chris@0 | 3015     size_t zoomLevel = (end - start) / pixels; | 
| Chris@0 | 3016 | 
| Chris@0 | 3017     currentPane->setZoomLevel(zoomLevel); | 
| Chris@0 | 3018     currentPane->setStartFrame(start); | 
| Chris@0 | 3019 } | 
| Chris@0 | 3020 | 
| Chris@0 | 3021 void | 
| Chris@0 | 3022 MainWindow::zoomDefault() | 
| Chris@0 | 3023 { | 
| Chris@0 | 3024     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3025     if (currentPane) currentPane->setZoomLevel(1024); | 
| Chris@0 | 3026 } | 
| Chris@0 | 3027 | 
| Chris@0 | 3028 void | 
| Chris@0 | 3029 MainWindow::scrollLeft() | 
| Chris@0 | 3030 { | 
| Chris@0 | 3031     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3032     if (currentPane) currentPane->scroll(false, false); | 
| Chris@0 | 3033 } | 
| Chris@0 | 3034 | 
| Chris@0 | 3035 void | 
| Chris@0 | 3036 MainWindow::jumpLeft() | 
| Chris@0 | 3037 { | 
| Chris@0 | 3038     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3039     if (currentPane) currentPane->scroll(false, true); | 
| Chris@0 | 3040 } | 
| Chris@0 | 3041 | 
| Chris@0 | 3042 void | 
| Chris@0 | 3043 MainWindow::scrollRight() | 
| Chris@0 | 3044 { | 
| Chris@0 | 3045     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3046     if (currentPane) currentPane->scroll(true, false); | 
| Chris@0 | 3047 } | 
| Chris@0 | 3048 | 
| Chris@0 | 3049 void | 
| Chris@0 | 3050 MainWindow::jumpRight() | 
| Chris@0 | 3051 { | 
| Chris@0 | 3052     Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3053     if (currentPane) currentPane->scroll(true, true); | 
| Chris@0 | 3054 } | 
| Chris@0 | 3055 | 
| Chris@0 | 3056 void | 
| Chris@0 | 3057 MainWindow::showNoOverlays() | 
| Chris@0 | 3058 { | 
| Chris@0 | 3059     m_viewManager->setOverlayMode(ViewManager::NoOverlays); | 
| Chris@0 | 3060 } | 
| Chris@0 | 3061 | 
| Chris@0 | 3062 void | 
| Chris@90 | 3063 MainWindow::showMinimalOverlays() | 
| Chris@0 | 3064 { | 
| Chris@90 | 3065     m_viewManager->setOverlayMode(ViewManager::MinimalOverlays); | 
| Chris@0 | 3066 } | 
| Chris@0 | 3067 | 
| Chris@0 | 3068 void | 
| Chris@90 | 3069 MainWindow::showStandardOverlays() | 
| Chris@90 | 3070 { | 
| Chris@90 | 3071     m_viewManager->setOverlayMode(ViewManager::StandardOverlays); | 
| Chris@90 | 3072 } | 
| Chris@90 | 3073 | 
| Chris@90 | 3074 void | 
| Chris@90 | 3075 MainWindow::showAllOverlays() | 
| Chris@0 | 3076 { | 
| Chris@0 | 3077     m_viewManager->setOverlayMode(ViewManager::AllOverlays); | 
| Chris@0 | 3078 } | 
| Chris@0 | 3079 | 
| Chris@0 | 3080 void | 
| Chris@7 | 3081 MainWindow::toggleZoomWheels() | 
| Chris@7 | 3082 { | 
| Chris@7 | 3083     if (m_viewManager->getZoomWheelsEnabled()) { | 
| Chris@7 | 3084         m_viewManager->setZoomWheelsEnabled(false); | 
| Chris@7 | 3085     } else { | 
| Chris@7 | 3086         m_viewManager->setZoomWheelsEnabled(true); | 
| Chris@7 | 3087     } | 
| Chris@7 | 3088 } | 
| Chris@7 | 3089 | 
| Chris@7 | 3090 void | 
| Chris@72 | 3091 MainWindow::togglePropertyBoxes() | 
| Chris@72 | 3092 { | 
| Chris@72 | 3093     if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) { | 
| Chris@72 | 3094         if (Preferences::getInstance()->getPropertyBoxLayout() == | 
| Chris@72 | 3095             Preferences::VerticallyStacked) { | 
| Chris@72 | 3096             m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout); | 
| Chris@72 | 3097         } else { | 
| Chris@72 | 3098             m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout); | 
| Chris@72 | 3099         } | 
| Chris@72 | 3100     } else { | 
| Chris@72 | 3101         m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks); | 
| Chris@72 | 3102     } | 
| Chris@72 | 3103 } | 
| Chris@72 | 3104 | 
| Chris@72 | 3105 void | 
| Chris@90 | 3106 MainWindow::toggleStatusBar() | 
| Chris@90 | 3107 { | 
| Chris@90 | 3108     QSettings settings; | 
| Chris@90 | 3109     settings.beginGroup("MainWindow"); | 
| Chris@90 | 3110     bool sb = settings.value("showstatusbar", true).toBool(); | 
| Chris@90 | 3111 | 
| Chris@90 | 3112     if (sb) { | 
| Chris@90 | 3113         statusBar()->hide(); | 
| Chris@90 | 3114     } else { | 
| Chris@90 | 3115         statusBar()->show(); | 
| Chris@90 | 3116     } | 
| Chris@90 | 3117 | 
| Chris@90 | 3118     settings.setValue("showstatusbar", !sb); | 
| Chris@90 | 3119 | 
| Chris@90 | 3120     settings.endGroup(); | 
| Chris@90 | 3121 } | 
| Chris@90 | 3122 | 
| Chris@90 | 3123 void | 
| Chris@72 | 3124 MainWindow::preferenceChanged(PropertyContainer::PropertyName name) | 
| Chris@72 | 3125 { | 
| Chris@72 | 3126     if (name == "Property Box Layout") { | 
| Chris@72 | 3127         if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) { | 
| Chris@72 | 3128             if (Preferences::getInstance()->getPropertyBoxLayout() == | 
| Chris@72 | 3129                 Preferences::VerticallyStacked) { | 
| Chris@72 | 3130                 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout); | 
| Chris@72 | 3131             } else { | 
| Chris@72 | 3132                 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout); | 
| Chris@72 | 3133             } | 
| Chris@72 | 3134         } | 
| Chris@72 | 3135     } | 
| Chris@72 | 3136 } | 
| Chris@72 | 3137 | 
| Chris@72 | 3138 void | 
| Chris@0 | 3139 MainWindow::play() | 
| Chris@0 | 3140 { | 
| Chris@0 | 3141     if (m_playSource->isPlaying()) { | 
| Chris@116 | 3142         stop(); | 
| Chris@0 | 3143     } else { | 
| Chris@116 | 3144         playbackFrameChanged(m_viewManager->getPlaybackFrame()); | 
| Chris@0 | 3145 	m_playSource->play(m_viewManager->getPlaybackFrame()); | 
| Chris@0 | 3146     } | 
| Chris@0 | 3147 } | 
| Chris@0 | 3148 | 
| Chris@0 | 3149 void | 
| Chris@0 | 3150 MainWindow::ffwd() | 
| Chris@0 | 3151 { | 
| Chris@0 | 3152     if (!getMainModel()) return; | 
| Chris@0 | 3153 | 
| Chris@0 | 3154     int frame = m_viewManager->getPlaybackFrame(); | 
| Chris@0 | 3155     ++frame; | 
| Chris@0 | 3156 | 
| Chris@0 | 3157     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3158     if (!pane) return; | 
| Chris@0 | 3159 | 
| Chris@0 | 3160     Layer *layer = pane->getSelectedLayer(); | 
| Chris@0 | 3161 | 
| Chris@0 | 3162     if (!dynamic_cast<TimeInstantLayer *>(layer) && | 
| Chris@0 | 3163         !dynamic_cast<TimeValueLayer *>(layer)) return; | 
| Chris@0 | 3164 | 
| Chris@0 | 3165     size_t resolution = 0; | 
| Chris@0 | 3166     if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapRight)) { | 
| Chris@0 | 3167         frame = getMainModel()->getEndFrame(); | 
| Chris@0 | 3168     } | 
| Chris@0 | 3169 | 
| Chris@0 | 3170     m_viewManager->setPlaybackFrame(frame); | 
| Chris@0 | 3171 } | 
| Chris@0 | 3172 | 
| Chris@0 | 3173 void | 
| Chris@0 | 3174 MainWindow::ffwdEnd() | 
| Chris@0 | 3175 { | 
| Chris@0 | 3176     if (!getMainModel()) return; | 
| Chris@0 | 3177     m_viewManager->setPlaybackFrame(getMainModel()->getEndFrame()); | 
| Chris@0 | 3178 } | 
| Chris@0 | 3179 | 
| Chris@0 | 3180 void | 
| Chris@0 | 3181 MainWindow::rewind() | 
| Chris@0 | 3182 { | 
| Chris@0 | 3183     if (!getMainModel()) return; | 
| Chris@0 | 3184 | 
| Chris@0 | 3185     int frame = m_viewManager->getPlaybackFrame(); | 
| Chris@0 | 3186     if (frame > 0) --frame; | 
| Chris@0 | 3187 | 
| Chris@0 | 3188     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3189     if (!pane) return; | 
| Chris@0 | 3190 | 
| Chris@0 | 3191     Layer *layer = pane->getSelectedLayer(); | 
| Chris@0 | 3192 | 
| Chris@0 | 3193     if (!dynamic_cast<TimeInstantLayer *>(layer) && | 
| Chris@0 | 3194         !dynamic_cast<TimeValueLayer *>(layer)) return; | 
| Chris@0 | 3195 | 
| Chris@0 | 3196     size_t resolution = 0; | 
| Chris@0 | 3197     if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapLeft)) { | 
| Chris@0 | 3198         frame = getMainModel()->getEndFrame(); | 
| Chris@0 | 3199     } | 
| Chris@0 | 3200 | 
| Chris@0 | 3201     m_viewManager->setPlaybackFrame(frame); | 
| Chris@0 | 3202 } | 
| Chris@0 | 3203 | 
| Chris@0 | 3204 void | 
| Chris@0 | 3205 MainWindow::rewindStart() | 
| Chris@0 | 3206 { | 
| Chris@0 | 3207     if (!getMainModel()) return; | 
| Chris@0 | 3208     m_viewManager->setPlaybackFrame(getMainModel()->getStartFrame()); | 
| Chris@0 | 3209 } | 
| Chris@0 | 3210 | 
| Chris@0 | 3211 void | 
| Chris@0 | 3212 MainWindow::stop() | 
| Chris@0 | 3213 { | 
| Chris@0 | 3214     m_playSource->stop(); | 
| Chris@116 | 3215 | 
| Chris@116 | 3216     if (m_paneStack && m_paneStack->getCurrentPane()) { | 
| Chris@116 | 3217         updateVisibleRangeDisplay(m_paneStack->getCurrentPane()); | 
| Chris@116 | 3218     } else { | 
| Chris@116 | 3219         m_myStatusMessage = ""; | 
| Chris@116 | 3220         statusBar()->showMessage(""); | 
| Chris@116 | 3221     } | 
| Chris@0 | 3222 } | 
| Chris@0 | 3223 | 
| Chris@0 | 3224 void | 
| Chris@0 | 3225 MainWindow::addPane() | 
| Chris@0 | 3226 { | 
| Chris@0 | 3227     QObject *s = sender(); | 
| Chris@0 | 3228     QAction *action = dynamic_cast<QAction *>(s); | 
| Chris@0 | 3229 | 
| Chris@0 | 3230     if (!action) { | 
| Chris@0 | 3231 	std::cerr << "WARNING: MainWindow::addPane: sender is not an action" | 
| Chris@0 | 3232 		  << std::endl; | 
| Chris@0 | 3233 	return; | 
| Chris@0 | 3234     } | 
| Chris@0 | 3235 | 
| Chris@0 | 3236     PaneActionMap::iterator i = m_paneActions.find(action); | 
| Chris@0 | 3237 | 
| Chris@0 | 3238     if (i == m_paneActions.end()) { | 
| Chris@0 | 3239 	std::cerr << "WARNING: MainWindow::addPane: unknown action " | 
| Chris@0 | 3240 		  << action->objectName().toStdString() << std::endl; | 
| Chris@0 | 3241 	return; | 
| Chris@0 | 3242     } | 
| Chris@0 | 3243 | 
| Chris@69 | 3244     addPane(i->second, action->text()); | 
| Chris@69 | 3245 } | 
| Chris@69 | 3246 | 
| Chris@69 | 3247 void | 
| Chris@69 | 3248 MainWindow::addPane(const PaneConfiguration &configuration, QString text) | 
| Chris@69 | 3249 { | 
| Chris@69 | 3250     CommandHistory::getInstance()->startCompoundOperation(text, true); | 
| Chris@0 | 3251 | 
| Chris@0 | 3252     AddPaneCommand *command = new AddPaneCommand(this); | 
| Chris@0 | 3253     CommandHistory::getInstance()->addCommand(command); | 
| Chris@0 | 3254 | 
| Chris@0 | 3255     Pane *pane = command->getPane(); | 
| Chris@0 | 3256 | 
| Chris@69 | 3257     if (configuration.layer == LayerFactory::Spectrum) { | 
| Chris@109 | 3258         pane->setPlaybackFollow(PlaybackScrollContinuous); | 
| Chris@110 | 3259         pane->setFollowGlobalZoom(false); | 
| Chris@112 | 3260         pane->setZoomLevel(512); | 
| Chris@7 | 3261     } | 
| Chris@7 | 3262 | 
| Chris@69 | 3263     if (configuration.layer != LayerFactory::TimeRuler && | 
| Chris@69 | 3264         configuration.layer != LayerFactory::Spectrum) { | 
| Chris@8 | 3265 | 
| Chris@0 | 3266 	if (!m_timeRulerLayer) { | 
| Chris@0 | 3267 //	    std::cerr << "no time ruler layer, creating one" << std::endl; | 
| Chris@0 | 3268 	    m_timeRulerLayer = m_document->createMainModelLayer | 
| Chris@0 | 3269 		(LayerFactory::TimeRuler); | 
| Chris@0 | 3270 	} | 
| Chris@0 | 3271 | 
| Chris@0 | 3272 //	std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl; | 
| Chris@0 | 3273 | 
| Chris@0 | 3274 	m_document->addLayerToView(pane, m_timeRulerLayer); | 
| Chris@0 | 3275     } | 
| Chris@0 | 3276 | 
| Chris@69 | 3277     Layer *newLayer = m_document->createLayer(configuration.layer); | 
| Chris@69 | 3278 | 
| Chris@69 | 3279     Model *suggestedModel = configuration.sourceModel; | 
| Chris@66 | 3280     Model *model = 0; | 
| Chris@66 | 3281 | 
| Chris@66 | 3282     if (suggestedModel) { | 
| Chris@66 | 3283 | 
| Chris@66 | 3284         // check its validity | 
| Chris@66 | 3285         std::vector<Model *> inputModels = m_document->getTransformInputModels(); | 
| Chris@66 | 3286         for (size_t j = 0; j < inputModels.size(); ++j) { | 
| Chris@66 | 3287             if (inputModels[j] == suggestedModel) { | 
| Chris@66 | 3288                 model = suggestedModel; | 
| Chris@66 | 3289                 break; | 
| Chris@66 | 3290             } | 
| Chris@66 | 3291         } | 
| Chris@66 | 3292 | 
| Chris@66 | 3293         if (!model) { | 
| Chris@66 | 3294             std::cerr << "WARNING: Model " << (void *)suggestedModel | 
| Chris@66 | 3295                       << " appears in pane action map, but is not reported " | 
| Chris@66 | 3296                       << "by document as a valid transform source" << std::endl; | 
| Chris@66 | 3297         } | 
| Chris@66 | 3298     } | 
| Chris@66 | 3299 | 
| Chris@66 | 3300     if (!model) model = m_document->getMainModel(); | 
| Chris@66 | 3301 | 
| Chris@66 | 3302     m_document->setModel(newLayer, model); | 
| Chris@66 | 3303 | 
| Chris@69 | 3304     m_document->setChannel(newLayer, configuration.channel); | 
| Chris@0 | 3305     m_document->addLayerToView(pane, newLayer); | 
| Chris@0 | 3306 | 
| Chris@0 | 3307     m_paneStack->setCurrentPane(pane); | 
| Chris@70 | 3308     m_paneStack->setCurrentLayer(pane, newLayer); | 
| Chris@0 | 3309 | 
| Chris@73 | 3310     std::cerr << "MainWindow::addPane: global centre frame is " | 
| Chris@73 | 3311               << m_viewManager->getGlobalCentreFrame() << std::endl; | 
| Chris@73 | 3312     pane->setCentreFrame(m_viewManager->getGlobalCentreFrame()); | 
| Chris@73 | 3313 | 
| Chris@0 | 3314     CommandHistory::getInstance()->endCompoundOperation(); | 
| Chris@0 | 3315 | 
| Chris@0 | 3316     updateMenuStates(); | 
| Chris@0 | 3317 } | 
| Chris@0 | 3318 | 
| Chris@0 | 3319 MainWindow::AddPaneCommand::AddPaneCommand(MainWindow *mw) : | 
| Chris@0 | 3320     m_mw(mw), | 
| Chris@0 | 3321     m_pane(0), | 
| Chris@0 | 3322     m_prevCurrentPane(0), | 
| Chris@0 | 3323     m_added(false) | 
| Chris@0 | 3324 { | 
| Chris@0 | 3325 } | 
| Chris@0 | 3326 | 
| Chris@0 | 3327 MainWindow::AddPaneCommand::~AddPaneCommand() | 
| Chris@0 | 3328 { | 
| Chris@0 | 3329     if (m_pane && !m_added) { | 
| Chris@0 | 3330 	m_mw->m_paneStack->deletePane(m_pane); | 
| Chris@0 | 3331     } | 
| Chris@0 | 3332 } | 
| Chris@0 | 3333 | 
| Chris@0 | 3334 QString | 
| Chris@0 | 3335 MainWindow::AddPaneCommand::getName() const | 
| Chris@0 | 3336 { | 
| Chris@0 | 3337     return tr("Add Pane"); | 
| Chris@0 | 3338 } | 
| Chris@0 | 3339 | 
| Chris@0 | 3340 void | 
| Chris@0 | 3341 MainWindow::AddPaneCommand::execute() | 
| Chris@0 | 3342 { | 
| Chris@0 | 3343     if (!m_pane) { | 
| Chris@0 | 3344 	m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane(); | 
| Chris@0 | 3345 	m_pane = m_mw->m_paneStack->addPane(); | 
| Chris@90 | 3346 | 
| Chris@90 | 3347         connect(m_pane, SIGNAL(contextHelpChanged(const QString &)), | 
| Chris@116 | 3348                 m_mw, SLOT(contextHelpChanged(const QString &))); | 
| Chris@0 | 3349     } else { | 
| Chris@0 | 3350 	m_mw->m_paneStack->showPane(m_pane); | 
| Chris@0 | 3351     } | 
| Chris@0 | 3352 | 
| Chris@0 | 3353     m_mw->m_paneStack->setCurrentPane(m_pane); | 
| Chris@65 | 3354     m_mw->m_overview->registerView(m_pane); | 
| Chris@0 | 3355     m_added = true; | 
| Chris@0 | 3356 } | 
| Chris@0 | 3357 | 
| Chris@0 | 3358 void | 
| Chris@0 | 3359 MainWindow::AddPaneCommand::unexecute() | 
| Chris@0 | 3360 { | 
| Chris@0 | 3361     m_mw->m_paneStack->hidePane(m_pane); | 
| Chris@0 | 3362     m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane); | 
| Chris@65 | 3363     m_mw->m_overview->unregisterView(m_pane); | 
| Chris@0 | 3364     m_added = false; | 
| Chris@0 | 3365 } | 
| Chris@0 | 3366 | 
| Chris@0 | 3367 MainWindow::RemovePaneCommand::RemovePaneCommand(MainWindow *mw, Pane *pane) : | 
| Chris@0 | 3368     m_mw(mw), | 
| Chris@0 | 3369     m_pane(pane), | 
| Chris@0 | 3370     m_added(true) | 
| Chris@0 | 3371 { | 
| Chris@0 | 3372 } | 
| Chris@0 | 3373 | 
| Chris@0 | 3374 MainWindow::RemovePaneCommand::~RemovePaneCommand() | 
| Chris@0 | 3375 { | 
| Chris@0 | 3376     if (m_pane && !m_added) { | 
| Chris@0 | 3377 	m_mw->m_paneStack->deletePane(m_pane); | 
| Chris@0 | 3378     } | 
| Chris@0 | 3379 } | 
| Chris@0 | 3380 | 
| Chris@0 | 3381 QString | 
| Chris@0 | 3382 MainWindow::RemovePaneCommand::getName() const | 
| Chris@0 | 3383 { | 
| Chris@0 | 3384     return tr("Remove Pane"); | 
| Chris@0 | 3385 } | 
| Chris@0 | 3386 | 
| Chris@0 | 3387 void | 
| Chris@0 | 3388 MainWindow::RemovePaneCommand::execute() | 
| Chris@0 | 3389 { | 
| Chris@0 | 3390     m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane(); | 
| Chris@0 | 3391     m_mw->m_paneStack->hidePane(m_pane); | 
| Chris@65 | 3392     m_mw->m_overview->unregisterView(m_pane); | 
| Chris@0 | 3393     m_added = false; | 
| Chris@0 | 3394 } | 
| Chris@0 | 3395 | 
| Chris@0 | 3396 void | 
| Chris@0 | 3397 MainWindow::RemovePaneCommand::unexecute() | 
| Chris@0 | 3398 { | 
| Chris@0 | 3399     m_mw->m_paneStack->showPane(m_pane); | 
| Chris@0 | 3400     m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane); | 
| Chris@65 | 3401     m_mw->m_overview->registerView(m_pane); | 
| Chris@0 | 3402     m_added = true; | 
| Chris@0 | 3403 } | 
| Chris@0 | 3404 | 
| Chris@0 | 3405 void | 
| Chris@0 | 3406 MainWindow::addLayer() | 
| Chris@0 | 3407 { | 
| Chris@0 | 3408     QObject *s = sender(); | 
| Chris@0 | 3409     QAction *action = dynamic_cast<QAction *>(s); | 
| Chris@0 | 3410 | 
| Chris@0 | 3411     if (!action) { | 
| Chris@0 | 3412 	std::cerr << "WARNING: MainWindow::addLayer: sender is not an action" | 
| Chris@0 | 3413 		  << std::endl; | 
| Chris@0 | 3414 	return; | 
| Chris@0 | 3415     } | 
| Chris@0 | 3416 | 
| Chris@0 | 3417     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3418 | 
| Chris@0 | 3419     if (!pane) { | 
| Chris@0 | 3420 	std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl; | 
| Chris@0 | 3421 	return; | 
| Chris@0 | 3422     } | 
| Chris@0 | 3423 | 
| Chris@0 | 3424     ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action); | 
| Chris@0 | 3425 | 
| Chris@0 | 3426     if (ei != m_existingLayerActions.end()) { | 
| Chris@0 | 3427 	Layer *newLayer = ei->second; | 
| Chris@0 | 3428 	m_document->addLayerToView(pane, newLayer); | 
| Chris@0 | 3429 	m_paneStack->setCurrentLayer(pane, newLayer); | 
| Chris@0 | 3430 	return; | 
| Chris@0 | 3431     } | 
| Chris@0 | 3432 | 
| Chris@95 | 3433     ei = m_sliceActions.find(action); | 
| Chris@95 | 3434 | 
| Chris@95 | 3435     if (ei != m_sliceActions.end()) { | 
| Chris@95 | 3436         Layer *newLayer = m_document->createLayer(LayerFactory::Slice); | 
| Chris@95 | 3437 //        document->setModel(newLayer, ei->second->getModel()); | 
| Chris@95 | 3438         SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second); | 
| Chris@95 | 3439         SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer); | 
| Chris@95 | 3440         if (source && dest) { | 
| Chris@95 | 3441             dest->setSliceableModel(source->getSliceableModel()); | 
| Chris@95 | 3442             connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)), | 
| Chris@95 | 3443                     dest, SLOT(sliceableModelReplaced(const Model *, const Model *))); | 
| Chris@95 | 3444             connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)), | 
| Chris@95 | 3445                     dest, SLOT(modelAboutToBeDeleted(Model *))); | 
| Chris@95 | 3446         } | 
| Chris@95 | 3447 	m_document->addLayerToView(pane, newLayer); | 
| Chris@95 | 3448 	m_paneStack->setCurrentLayer(pane, newLayer); | 
| Chris@95 | 3449 	return; | 
| Chris@95 | 3450     } | 
| Chris@95 | 3451 | 
| Chris@34 | 3452     TransformActionMap::iterator i = m_transformActions.find(action); | 
| Chris@34 | 3453 | 
| Chris@34 | 3454     if (i == m_transformActions.end()) { | 
| Chris@0 | 3455 | 
| Chris@0 | 3456 	LayerActionMap::iterator i = m_layerActions.find(action); | 
| Chris@0 | 3457 | 
| Chris@0 | 3458 	if (i == m_layerActions.end()) { | 
| Chris@0 | 3459 	    std::cerr << "WARNING: MainWindow::addLayer: unknown action " | 
| Chris@0 | 3460 		      << action->objectName().toStdString() << std::endl; | 
| Chris@0 | 3461 	    return; | 
| Chris@0 | 3462 	} | 
| Chris@0 | 3463 | 
| Chris@0 | 3464 	LayerFactory::LayerType type = i->second; | 
| Chris@0 | 3465 | 
| Chris@0 | 3466 	LayerFactory::LayerTypeSet emptyTypes = | 
| Chris@0 | 3467 	    LayerFactory::getInstance()->getValidEmptyLayerTypes(); | 
| Chris@0 | 3468 | 
| Chris@0 | 3469 	Layer *newLayer; | 
| Chris@0 | 3470 | 
| Chris@0 | 3471 	if (emptyTypes.find(type) != emptyTypes.end()) { | 
| Chris@0 | 3472 | 
| Chris@0 | 3473 	    newLayer = m_document->createEmptyLayer(type); | 
| Chris@0 | 3474 	    m_toolActions[ViewManager::DrawMode]->trigger(); | 
| Chris@0 | 3475 | 
| Chris@0 | 3476 	} else { | 
| Chris@0 | 3477 | 
| Chris@0 | 3478 	    newLayer = m_document->createMainModelLayer(type); | 
| Chris@0 | 3479 	} | 
| Chris@0 | 3480 | 
| Chris@0 | 3481 	m_document->addLayerToView(pane, newLayer); | 
| Chris@0 | 3482 	m_paneStack->setCurrentLayer(pane, newLayer); | 
| Chris@0 | 3483 | 
| Chris@0 | 3484 	return; | 
| Chris@0 | 3485     } | 
| Chris@0 | 3486 | 
| Chris@107 | 3487     TransformId transform = i->second; | 
| Chris@0 | 3488     TransformFactory *factory = TransformFactory::getInstance(); | 
| Chris@0 | 3489 | 
| Chris@0 | 3490     QString configurationXml; | 
| Chris@0 | 3491 | 
| Chris@0 | 3492     int channel = -1; | 
| Chris@0 | 3493     // pick up the default channel from any existing layers on the same pane | 
| Chris@0 | 3494     for (int j = 0; j < pane->getLayerCount(); ++j) { | 
| Chris@0 | 3495 	int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j)); | 
| Chris@0 | 3496 	if (c != -1) { | 
| Chris@0 | 3497 	    channel = c; | 
| Chris@0 | 3498 	    break; | 
| Chris@0 | 3499 	} | 
| Chris@0 | 3500     } | 
| Chris@0 | 3501 | 
| Chris@33 | 3502     // We always ask for configuration, even if the plugin isn't | 
| Chris@33 | 3503     // supposed to be configurable, because we need to let the user | 
| Chris@33 | 3504     // change the execution context (block size etc). | 
| Chris@0 | 3505 | 
| Chris@27 | 3506     PluginTransform::ExecutionContext context(channel); | 
| Chris@27 | 3507 | 
| Chris@66 | 3508     std::vector<Model *> candidateInputModels = | 
| Chris@66 | 3509         m_document->getTransformInputModels(); | 
| Chris@53 | 3510 | 
| Chris@54 | 3511     Model *inputModel = factory->getConfigurationForTransform(transform, | 
| Chris@54 | 3512                                                               candidateInputModels, | 
| Chris@54 | 3513                                                               context, | 
| Chris@54 | 3514                                                               configurationXml, | 
| Chris@54 | 3515                                                               m_playSource); | 
| Chris@54 | 3516     if (!inputModel) return; | 
| Chris@54 | 3517 | 
| Chris@54 | 3518     std::cerr << "Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << std::endl; | 
| Chris@0 | 3519 | 
| Chris@0 | 3520     Layer *newLayer = m_document->createDerivedLayer(transform, | 
| Chris@54 | 3521                                                      inputModel, | 
| Chris@27 | 3522                                                      context, | 
| Chris@0 | 3523                                                      configurationXml); | 
| Chris@0 | 3524 | 
| Chris@0 | 3525     if (newLayer) { | 
| Chris@0 | 3526         m_document->addLayerToView(pane, newLayer); | 
| Chris@27 | 3527         m_document->setChannel(newLayer, context.channel); | 
| Chris@34 | 3528         m_recentTransforms.add(transform); | 
| Chris@70 | 3529         m_paneStack->setCurrentLayer(pane, newLayer); | 
| Chris@0 | 3530     } | 
| Chris@0 | 3531 | 
| Chris@0 | 3532     updateMenuStates(); | 
| Chris@0 | 3533 } | 
| Chris@0 | 3534 | 
| Chris@0 | 3535 void | 
| Chris@0 | 3536 MainWindow::deleteCurrentPane() | 
| Chris@0 | 3537 { | 
| Chris@0 | 3538     CommandHistory::getInstance()->startCompoundOperation | 
| Chris@0 | 3539 	(tr("Delete Pane"), true); | 
| Chris@0 | 3540 | 
| Chris@0 | 3541     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3542     if (pane) { | 
| Chris@0 | 3543 	while (pane->getLayerCount() > 0) { | 
| Chris@0 | 3544 	    Layer *layer = pane->getLayer(0); | 
| Chris@0 | 3545 	    if (layer) { | 
| Chris@0 | 3546 		m_document->removeLayerFromView(pane, layer); | 
| Chris@0 | 3547 	    } else { | 
| Chris@0 | 3548 		break; | 
| Chris@0 | 3549 	    } | 
| Chris@0 | 3550 	} | 
| Chris@0 | 3551 | 
| Chris@0 | 3552 	RemovePaneCommand *command = new RemovePaneCommand(this, pane); | 
| Chris@0 | 3553 	CommandHistory::getInstance()->addCommand(command); | 
| Chris@0 | 3554     } | 
| Chris@0 | 3555 | 
| Chris@0 | 3556     CommandHistory::getInstance()->endCompoundOperation(); | 
| Chris@0 | 3557 | 
| Chris@0 | 3558     updateMenuStates(); | 
| Chris@0 | 3559 } | 
| Chris@0 | 3560 | 
| Chris@0 | 3561 void | 
| Chris@0 | 3562 MainWindow::deleteCurrentLayer() | 
| Chris@0 | 3563 { | 
| Chris@0 | 3564     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3565     if (pane) { | 
| Chris@0 | 3566 	Layer *layer = pane->getSelectedLayer(); | 
| Chris@0 | 3567 	if (layer) { | 
| Chris@0 | 3568 	    m_document->removeLayerFromView(pane, layer); | 
| Chris@0 | 3569 	} | 
| Chris@0 | 3570     } | 
| Chris@0 | 3571     updateMenuStates(); | 
| Chris@0 | 3572 } | 
| Chris@0 | 3573 | 
| Chris@0 | 3574 void | 
| Chris@0 | 3575 MainWindow::renameCurrentLayer() | 
| Chris@0 | 3576 { | 
| Chris@0 | 3577     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@0 | 3578     if (pane) { | 
| Chris@0 | 3579 	Layer *layer = pane->getSelectedLayer(); | 
| Chris@0 | 3580 	if (layer) { | 
| Chris@0 | 3581 	    bool ok = false; | 
| Chris@0 | 3582 	    QString newName = QInputDialog::getText | 
| Chris@0 | 3583 		(this, tr("Rename Layer"), | 
| Chris@0 | 3584 		 tr("New name for this layer:"), | 
| Chris@0 | 3585 		 QLineEdit::Normal, layer->objectName(), &ok); | 
| Chris@0 | 3586 	    if (ok) { | 
| Chris@0 | 3587 		layer->setObjectName(newName); | 
| Chris@95 | 3588 		setupExistingLayersMenus(); | 
| Chris@0 | 3589 	    } | 
| Chris@0 | 3590 	} | 
| Chris@0 | 3591     } | 
| Chris@0 | 3592 } | 
| Chris@0 | 3593 | 
| Chris@0 | 3594 void | 
| Chris@59 | 3595 MainWindow::playSpeedChanged(int position) | 
| Chris@0 | 3596 { | 
| Chris@59 | 3597     PlaySpeedRangeMapper mapper(0, 200); | 
| Chris@60 | 3598 | 
| Chris@60 | 3599     float percent = m_playSpeed->mappedValue(); | 
| Chris@60 | 3600 | 
| Chris@60 | 3601     float factor = mapper.getFactorForValue(percent); | 
| Chris@60 | 3602 | 
| Chris@60 | 3603 //    float factor = mapper.getFactorForPosition(position); | 
| Chris@60 | 3604 //    float percent = mapper.getValueForPosition(position); | 
| Chris@60 | 3605 | 
| Chris@60 | 3606     std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl; | 
| Chris@60 | 3607 | 
| Chris@60 | 3608 //!!!    bool slow = (position < 100); | 
| Chris@59 | 3609     bool something = (position != 100); | 
| Chris@60 | 3610 /*!!! | 
| Chris@59 | 3611     int pc = lrintf(percent); | 
| Chris@21 | 3612 | 
| Chris@21 | 3613     m_playSpeed->setToolTip(tr("Playback speed: %1%2%") | 
| Chris@60 | 3614                             .arg(!slow ? "+" : "") | 
| Chris@21 | 3615 			    .arg(pc)); | 
| Chris@60 | 3616 */ | 
| Chris@25 | 3617     m_playSharpen->setEnabled(something); | 
| Chris@26 | 3618     m_playMono->setEnabled(something); | 
| Chris@25 | 3619     bool sharpen = (something && m_playSharpen->isChecked()); | 
| Chris@26 | 3620     bool mono = (something && m_playMono->isChecked()); | 
| Chris@26 | 3621     m_playSource->setTimeStretch(factor, sharpen, mono); | 
| Chris@16 | 3622 } | 
| Chris@16 | 3623 | 
| Chris@16 | 3624 void | 
| Chris@16 | 3625 MainWindow::playSharpenToggled() | 
| Chris@16 | 3626 { | 
| Chris@21 | 3627     QSettings settings; | 
| Chris@21 | 3628     settings.beginGroup("MainWindow"); | 
| Chris@21 | 3629     settings.setValue("playsharpen", m_playSharpen->isChecked()); | 
| Chris@21 | 3630     settings.endGroup(); | 
| Chris@21 | 3631 | 
| Chris@16 | 3632     playSpeedChanged(m_playSpeed->value()); | 
| Chris@0 | 3633 } | 
| Chris@0 | 3634 | 
| Chris@0 | 3635 void | 
| Chris@26 | 3636 MainWindow::playMonoToggled() | 
| Chris@26 | 3637 { | 
| Chris@26 | 3638     QSettings settings; | 
| Chris@26 | 3639     settings.beginGroup("MainWindow"); | 
| Chris@26 | 3640     settings.setValue("playmono", m_playMono->isChecked()); | 
| Chris@26 | 3641     settings.endGroup(); | 
| Chris@26 | 3642 | 
| Chris@26 | 3643     playSpeedChanged(m_playSpeed->value()); | 
| Chris@26 | 3644 } | 
| Chris@26 | 3645 | 
| Chris@26 | 3646 void | 
| Chris@116 | 3647 MainWindow::playbackFrameChanged(unsigned long frame) | 
| Chris@116 | 3648 { | 
| Chris@116 | 3649     if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return; | 
| Chris@116 | 3650 | 
| Chris@116 | 3651     RealTime now = RealTime::frame2RealTime | 
| Chris@116 | 3652         (frame, getMainModel()->getSampleRate()); | 
| Chris@116 | 3653 | 
| Chris@116 | 3654     if (now.sec == m_lastPlayStatusSec) return; | 
| Chris@116 | 3655 | 
| Chris@116 | 3656     RealTime then = RealTime::frame2RealTime | 
| Chris@116 | 3657         (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate()); | 
| Chris@116 | 3658 | 
| Chris@116 | 3659     QString nowStr; | 
| Chris@116 | 3660     QString thenStr; | 
| Chris@116 | 3661     QString remainingStr; | 
| Chris@116 | 3662 | 
| Chris@116 | 3663     if (then.sec > 10) { | 
| Chris@116 | 3664         nowStr = now.toSecText().c_str(); | 
| Chris@116 | 3665         thenStr = then.toSecText().c_str(); | 
| Chris@116 | 3666         remainingStr = (then - now).toSecText().c_str(); | 
| Chris@116 | 3667         m_lastPlayStatusSec = now.sec; | 
| Chris@116 | 3668     } else { | 
| Chris@116 | 3669         nowStr = now.toText(true).c_str(); | 
| Chris@116 | 3670         thenStr = then.toText(true).c_str(); | 
| Chris@116 | 3671         remainingStr = (then - now).toText(true).c_str(); | 
| Chris@116 | 3672     } | 
| Chris@116 | 3673 | 
| Chris@116 | 3674     m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)") | 
| Chris@116 | 3675         .arg(nowStr).arg(thenStr).arg(remainingStr); | 
| Chris@116 | 3676 | 
| Chris@116 | 3677     statusBar()->showMessage(m_myStatusMessage); | 
| Chris@116 | 3678 } | 
| Chris@116 | 3679 | 
| Chris@116 | 3680 void | 
| Chris@116 | 3681 MainWindow::globalCentreFrameChanged(unsigned long frame) | 
| Chris@116 | 3682 { | 
| Chris@116 | 3683     if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return; | 
| Chris@116 | 3684     Pane *p = 0; | 
| Chris@116 | 3685     if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return; | 
| Chris@116 | 3686     if (!p->getFollowGlobalPan()) return; | 
| Chris@116 | 3687     updateVisibleRangeDisplay(p); | 
| Chris@116 | 3688 } | 
| Chris@116 | 3689 | 
| Chris@116 | 3690 void | 
| Chris@116 | 3691 MainWindow::viewCentreFrameChanged(View *v, unsigned long frame) | 
| Chris@116 | 3692 { | 
| Chris@116 | 3693     if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return; | 
| Chris@116 | 3694     Pane *p = 0; | 
| Chris@116 | 3695     if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return; | 
| Chris@116 | 3696     if (v == p) updateVisibleRangeDisplay(p); | 
| Chris@116 | 3697 } | 
| Chris@116 | 3698 | 
| Chris@116 | 3699 void | 
| Chris@116 | 3700 MainWindow::viewZoomLevelChanged(View *v, unsigned long zoom, bool locked) | 
| Chris@116 | 3701 { | 
| Chris@116 | 3702     if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return; | 
| Chris@116 | 3703     Pane *p = 0; | 
| Chris@116 | 3704     if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return; | 
| Chris@116 | 3705     if (v == p) updateVisibleRangeDisplay(p); | 
| Chris@116 | 3706 } | 
| Chris@116 | 3707 | 
| Chris@116 | 3708 void | 
| Chris@116 | 3709 MainWindow::updateVisibleRangeDisplay(Pane *p) const | 
| Chris@116 | 3710 { | 
| Chris@116 | 3711     if (!getMainModel() || !p) { | 
| Chris@116 | 3712         return; | 
| Chris@116 | 3713     } | 
| Chris@116 | 3714 | 
| Chris@117 | 3715     bool haveSelection = false; | 
| Chris@117 | 3716     size_t startFrame = 0, endFrame = 0; | 
| Chris@117 | 3717 | 
| Chris@117 | 3718     if (m_viewManager && m_viewManager->haveInProgressSelection()) { | 
| Chris@117 | 3719 | 
| Chris@117 | 3720         bool exclusive = false; | 
| Chris@117 | 3721         Selection s = m_viewManager->getInProgressSelection(exclusive); | 
| Chris@117 | 3722 | 
| Chris@117 | 3723         if (!s.isEmpty()) { | 
| Chris@117 | 3724             haveSelection = true; | 
| Chris@117 | 3725             startFrame = s.getStartFrame(); | 
| Chris@117 | 3726             endFrame = s.getEndFrame(); | 
| Chris@117 | 3727         } | 
| Chris@117 | 3728     } | 
| Chris@117 | 3729 | 
| Chris@117 | 3730     if (!haveSelection) { | 
| Chris@117 | 3731         startFrame = p->getFirstVisibleFrame(); | 
| Chris@117 | 3732         endFrame = p->getLastVisibleFrame(); | 
| Chris@117 | 3733     } | 
| Chris@117 | 3734 | 
| Chris@116 | 3735     RealTime start = RealTime::frame2RealTime | 
| Chris@117 | 3736         (startFrame, getMainModel()->getSampleRate()); | 
| Chris@116 | 3737 | 
| Chris@116 | 3738     RealTime end = RealTime::frame2RealTime | 
| Chris@117 | 3739         (endFrame, getMainModel()->getSampleRate()); | 
| Chris@116 | 3740 | 
| Chris@116 | 3741     RealTime duration = end - start; | 
| Chris@116 | 3742 | 
| Chris@116 | 3743     QString startStr, endStr, durationStr; | 
| Chris@116 | 3744     startStr = start.toText(true).c_str(); | 
| Chris@116 | 3745     endStr = end.toText(true).c_str(); | 
| Chris@116 | 3746     durationStr = duration.toText(true).c_str(); | 
| Chris@116 | 3747 | 
| Chris@117 | 3748     if (haveSelection) { | 
| Chris@117 | 3749         m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)") | 
| Chris@117 | 3750             .arg(startStr).arg(endStr).arg(durationStr); | 
| Chris@117 | 3751     } else { | 
| Chris@117 | 3752         m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)") | 
| Chris@117 | 3753             .arg(startStr).arg(endStr).arg(durationStr); | 
| Chris@117 | 3754     } | 
| Chris@116 | 3755 | 
| Chris@116 | 3756     statusBar()->showMessage(m_myStatusMessage); | 
| Chris@116 | 3757 } | 
| Chris@116 | 3758 | 
| Chris@116 | 3759 void | 
| Chris@0 | 3760 MainWindow::outputLevelsChanged(float left, float right) | 
| Chris@0 | 3761 { | 
| Chris@0 | 3762     m_fader->setPeakLeft(left); | 
| Chris@0 | 3763     m_fader->setPeakRight(right); | 
| Chris@0 | 3764 } | 
| Chris@0 | 3765 | 
| Chris@0 | 3766 void | 
| Chris@0 | 3767 MainWindow::sampleRateMismatch(size_t requested, size_t actual, | 
| Chris@0 | 3768                                bool willResample) | 
| Chris@0 | 3769 { | 
| Chris@0 | 3770     if (!willResample) { | 
| Chris@0 | 3771         //!!! more helpful message needed | 
| Chris@0 | 3772         QMessageBox::information | 
| Chris@0 | 3773             (this, tr("Sample rate mismatch"), | 
| Chris@0 | 3774              tr("The sample rate of this audio file (%1 Hz) does not match\nthe current playback rate (%2 Hz).\n\nThe file will play at the wrong speed.") | 
| Chris@0 | 3775              .arg(requested).arg(actual)); | 
| Chris@0 | 3776     } | 
| Chris@0 | 3777 | 
| Chris@0 | 3778 /*!!! Let's not do this for now, and see how we go -- now that we're putting | 
| Chris@0 | 3779       sample rate information in the status bar | 
| Chris@0 | 3780 | 
| Chris@0 | 3781     QMessageBox::information | 
| Chris@0 | 3782 	(this, tr("Sample rate mismatch"), | 
| Chris@0 | 3783 	 tr("The sample rate of this audio file (%1 Hz) does not match\nthat of the output audio device (%2 Hz).\n\nThe file will be resampled automatically during playback.") | 
| Chris@0 | 3784 	 .arg(requested).arg(actual)); | 
| Chris@0 | 3785 */ | 
| Chris@0 | 3786 | 
| Chris@0 | 3787     updateDescriptionLabel(); | 
| Chris@0 | 3788 } | 
| Chris@0 | 3789 | 
| Chris@0 | 3790 void | 
| Chris@42 | 3791 MainWindow::audioOverloadPluginDisabled() | 
| Chris@42 | 3792 { | 
| Chris@42 | 3793     QMessageBox::information | 
| Chris@42 | 3794         (this, tr("Audio processing overload"), | 
| Chris@42 | 3795          tr("Audio effects plugin auditioning has been disabled\ndue to a processing overload.")); | 
| Chris@42 | 3796 } | 
| Chris@42 | 3797 | 
| Chris@42 | 3798 void | 
| Chris@0 | 3799 MainWindow::layerAdded(Layer *layer) | 
| Chris@0 | 3800 { | 
| Chris@0 | 3801 //    std::cerr << "MainWindow::layerAdded(" << layer << ")" << std::endl; | 
| Chris@0 | 3802 //    setupExistingLayersMenu(); | 
| Chris@0 | 3803     updateMenuStates(); | 
| Chris@0 | 3804 } | 
| Chris@0 | 3805 | 
| Chris@0 | 3806 void | 
| Chris@0 | 3807 MainWindow::layerRemoved(Layer *layer) | 
| Chris@0 | 3808 { | 
| Chris@0 | 3809 //    std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl; | 
| Chris@95 | 3810     setupExistingLayersMenus(); | 
| Chris@0 | 3811     updateMenuStates(); | 
| Chris@0 | 3812 } | 
| Chris@0 | 3813 | 
| Chris@0 | 3814 void | 
| Chris@0 | 3815 MainWindow::layerAboutToBeDeleted(Layer *layer) | 
| Chris@0 | 3816 { | 
| Chris@0 | 3817 //    std::cerr << "MainWindow::layerAboutToBeDeleted(" << layer << ")" << std::endl; | 
| Chris@0 | 3818     if (layer == m_timeRulerLayer) { | 
| Chris@0 | 3819 //	std::cerr << "(this is the time ruler layer)" << std::endl; | 
| Chris@0 | 3820 	m_timeRulerLayer = 0; | 
| Chris@0 | 3821     } | 
| Chris@0 | 3822 } | 
| Chris@0 | 3823 | 
| Chris@0 | 3824 void | 
| Chris@0 | 3825 MainWindow::layerInAView(Layer *layer, bool inAView) | 
| Chris@0 | 3826 { | 
| Chris@0 | 3827 //    std::cerr << "MainWindow::layerInAView(" << layer << "," << inAView << ")" << std::endl; | 
| Chris@0 | 3828 | 
| Chris@0 | 3829     // Check whether we need to add or remove model from play source | 
| Chris@0 | 3830     Model *model = layer->getModel(); | 
| Chris@0 | 3831     if (model) { | 
| Chris@0 | 3832         if (inAView) { | 
| Chris@0 | 3833             m_playSource->addModel(model); | 
| Chris@0 | 3834         } else { | 
| Chris@0 | 3835             bool found = false; | 
| Chris@0 | 3836             for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { | 
| Chris@0 | 3837                 Pane *pane = m_paneStack->getPane(i); | 
| Chris@0 | 3838                 if (!pane) continue; | 
| Chris@0 | 3839                 for (int j = 0; j < pane->getLayerCount(); ++j) { | 
| Chris@0 | 3840                     Layer *pl = pane->getLayer(j); | 
| Chris@0 | 3841                     if (pl && pl->getModel() == model) { | 
| Chris@0 | 3842                         found = true; | 
| Chris@0 | 3843                         break; | 
| Chris@0 | 3844                     } | 
| Chris@0 | 3845                 } | 
| Chris@0 | 3846                 if (found) break; | 
| Chris@0 | 3847             } | 
| Chris@0 | 3848             if (!found) m_playSource->removeModel(model); | 
| Chris@0 | 3849         } | 
| Chris@0 | 3850     } | 
| Chris@0 | 3851 | 
| Chris@95 | 3852     setupExistingLayersMenus(); | 
| Chris@0 | 3853     updateMenuStates(); | 
| Chris@0 | 3854 } | 
| Chris@0 | 3855 | 
| Chris@0 | 3856 void | 
| Chris@0 | 3857 MainWindow::modelAdded(Model *model) | 
| Chris@0 | 3858 { | 
| Chris@0 | 3859 //    std::cerr << "MainWindow::modelAdded(" << model << ")" << std::endl; | 
| Chris@0 | 3860     m_playSource->addModel(model); | 
| Chris@66 | 3861     if (dynamic_cast<DenseTimeValueModel *>(model)) { | 
| Chris@66 | 3862         setupPaneAndLayerMenus(); | 
| Chris@66 | 3863     } | 
| Chris@0 | 3864 } | 
| Chris@0 | 3865 | 
| Chris@0 | 3866 void | 
| Chris@0 | 3867 MainWindow::mainModelChanged(WaveFileModel *model) | 
| Chris@0 | 3868 { | 
| Chris@0 | 3869 //    std::cerr << "MainWindow::mainModelChanged(" << model << ")" << std::endl; | 
| Chris@0 | 3870     updateDescriptionLabel(); | 
| Chris@0 | 3871     m_panLayer->setModel(model); | 
| Chris@0 | 3872     if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate()); | 
| Chris@46 | 3873     if (model && !m_playTarget && m_audioOutput) createPlayTarget(); | 
| Chris@0 | 3874 } | 
| Chris@0 | 3875 | 
| Chris@0 | 3876 void | 
| Chris@0 | 3877 MainWindow::modelAboutToBeDeleted(Model *model) | 
| Chris@0 | 3878 { | 
| Chris@0 | 3879 //    std::cerr << "MainWindow::modelAboutToBeDeleted(" << model << ")" << std::endl; | 
| Chris@0 | 3880     m_playSource->removeModel(model); | 
| Chris@91 | 3881     FFTDataServer::modelAboutToBeDeleted(model); | 
| Chris@0 | 3882 } | 
| Chris@0 | 3883 | 
| Chris@0 | 3884 void | 
| Chris@0 | 3885 MainWindow::modelGenerationFailed(QString transformName) | 
| Chris@0 | 3886 { | 
| Chris@0 | 3887     QMessageBox::warning | 
| Chris@0 | 3888         (this, | 
| Chris@0 | 3889          tr("Failed to generate layer"), | 
| Chris@34 | 3890          tr("Failed to generate a derived layer.\n\nThe layer transform \"%1\" failed.\n\nThis probably means that a plugin failed to initialise, perhaps because it\nrejected the processing block size that was requested.") | 
| Chris@0 | 3891          .arg(transformName), | 
| Chris@0 | 3892          QMessageBox::Ok, 0); | 
| Chris@0 | 3893 } | 
| Chris@0 | 3894 | 
| Chris@0 | 3895 void | 
| Chris@0 | 3896 MainWindow::modelRegenerationFailed(QString layerName, QString transformName) | 
| Chris@0 | 3897 { | 
| Chris@0 | 3898     QMessageBox::warning | 
| Chris@0 | 3899         (this, | 
| Chris@0 | 3900          tr("Failed to regenerate layer"), | 
| Chris@34 | 3901          tr("Failed to regenerate derived layer \"%1\".\n\nThe layer transform \"%2\" failed to run.\n\nThis probably means the layer used a plugin that is not currently available.") | 
| Chris@0 | 3902          .arg(layerName).arg(transformName), | 
| Chris@0 | 3903          QMessageBox::Ok, 0); | 
| Chris@0 | 3904 } | 
| Chris@0 | 3905 | 
| Chris@0 | 3906 void | 
| Chris@0 | 3907 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position) | 
| Chris@0 | 3908 { | 
| Chris@0 | 3909 //    std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl; | 
| Chris@0 | 3910     m_paneStack->setCurrentPane(pane); | 
| Chris@0 | 3911     m_rightButtonMenu->popup(position); | 
| Chris@0 | 3912 } | 
| Chris@0 | 3913 | 
| Chris@0 | 3914 void | 
| Chris@73 | 3915 MainWindow::propertyStacksResized() | 
| Chris@73 | 3916 { | 
| Chris@73 | 3917 /* | 
| Chris@73 | 3918     std::cerr << "MainWindow::propertyStacksResized" << std::endl; | 
| Chris@73 | 3919     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@73 | 3920     if (pane && m_overview) { | 
| Chris@73 | 3921         std::cerr << "Fixed width: "  << pane->width() << std::endl; | 
| Chris@73 | 3922         m_overview->setFixedWidth(pane->width()); | 
| Chris@73 | 3923     } | 
| Chris@73 | 3924 */ | 
| Chris@73 | 3925 } | 
| Chris@73 | 3926 | 
| Chris@73 | 3927 void | 
| Chris@0 | 3928 MainWindow::showLayerTree() | 
| Chris@0 | 3929 { | 
| Chris@0 | 3930     QTreeView *view = new QTreeView(); | 
| Chris@0 | 3931     LayerTreeModel *tree = new LayerTreeModel(m_paneStack); | 
| Chris@0 | 3932     view->expand(tree->index(0, 0, QModelIndex())); | 
| Chris@0 | 3933     view->setModel(tree); | 
| Chris@0 | 3934     view->show(); | 
| Chris@0 | 3935 } | 
| Chris@0 | 3936 | 
| Chris@0 | 3937 void | 
| Chris@69 | 3938 MainWindow::pollOSC() | 
| Chris@69 | 3939 { | 
| Chris@70 | 3940     if (!m_oscQueue || m_oscQueue->isEmpty()) return; | 
| Chris@69 | 3941     std::cerr << "MainWindow::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl; | 
| Chris@69 | 3942 | 
| Chris@70 | 3943     if (m_openingAudioFile) return; | 
| Chris@70 | 3944 | 
| Chris@69 | 3945     OSCMessage message = m_oscQueue->readMessage(); | 
| Chris@69 | 3946 | 
| Chris@69 | 3947     if (message.getTarget() != 0) { | 
| Chris@69 | 3948         return; //!!! for now -- this class is target 0, others not handled yet | 
| Chris@69 | 3949     } | 
| Chris@69 | 3950 | 
| Chris@69 | 3951     handleOSCMessage(message); | 
| Chris@69 | 3952 } | 
| Chris@69 | 3953 | 
| Chris@69 | 3954 void | 
| Chris@69 | 3955 MainWindow::handleOSCMessage(const OSCMessage &message) | 
| Chris@69 | 3956 { | 
| Chris@70 | 3957     std::cerr << "MainWindow::handleOSCMessage: thread id = " | 
| Chris@70 | 3958               << QThread::currentThreadId() << std::endl; | 
| Chris@70 | 3959 | 
| Chris@69 | 3960     // This large function should really be abstracted out. | 
| Chris@69 | 3961 | 
| Chris@69 | 3962     if (message.getMethod() == "open") { | 
| Chris@69 | 3963 | 
| Chris@69 | 3964         if (message.getArgCount() == 1 && | 
| Chris@69 | 3965             message.getArg(0).canConvert(QVariant::String)) { | 
| Chris@69 | 3966             QString path = message.getArg(0).toString(); | 
| Chris@82 | 3967             if (openSomeFile(path, ReplaceMainModel) != FileOpenSucceeded) { | 
| Chris@69 | 3968                 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \"" | 
| Chris@69 | 3969                           << path.toStdString() << "\"" << std::endl; | 
| Chris@69 | 3970             } | 
| Chris@69 | 3971             //!!! we really need to spin here and not return until the | 
| Chris@69 | 3972             // file has been completely decoded... | 
| Chris@69 | 3973         } | 
| Chris@69 | 3974 | 
| Chris@69 | 3975     } else if (message.getMethod() == "openadditional") { | 
| Chris@69 | 3976 | 
| Chris@69 | 3977         if (message.getArgCount() == 1 && | 
| Chris@69 | 3978             message.getArg(0).canConvert(QVariant::String)) { | 
| Chris@69 | 3979             QString path = message.getArg(0).toString(); | 
| Chris@82 | 3980             if (openSomeFile(path, CreateAdditionalModel) != FileOpenSucceeded) { | 
| Chris@69 | 3981                 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \"" | 
| Chris@69 | 3982                           << path.toStdString() << "\"" << std::endl; | 
| Chris@69 | 3983             } | 
| Chris@69 | 3984         } | 
| Chris@69 | 3985 | 
| Chris@69 | 3986     } else if (message.getMethod() == "recent" || | 
| Chris@69 | 3987                message.getMethod() == "last") { | 
| Chris@69 | 3988 | 
| Chris@69 | 3989         int n = 0; | 
| Chris@69 | 3990         if (message.getMethod() == "recent" && | 
| Chris@69 | 3991             message.getArgCount() == 1 && | 
| Chris@69 | 3992             message.getArg(0).canConvert(QVariant::Int)) { | 
| Chris@69 | 3993             n = message.getArg(0).toInt() - 1; | 
| Chris@69 | 3994         } | 
| Chris@69 | 3995         std::vector<QString> recent = m_recentFiles.getRecent(); | 
| Chris@69 | 3996         if (n >= 0 && n < recent.size()) { | 
| Chris@82 | 3997             if (openSomeFile(recent[n], ReplaceMainModel) != FileOpenSucceeded) { | 
| Chris@69 | 3998                 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \"" | 
| Chris@69 | 3999                           << recent[n].toStdString() << "\"" << std::endl; | 
| Chris@69 | 4000             } | 
| Chris@69 | 4001         } | 
| Chris@69 | 4002 | 
| Chris@69 | 4003     } else if (message.getMethod() == "save") { | 
| Chris@69 | 4004 | 
| Chris@69 | 4005         QString path; | 
| Chris@69 | 4006         if (message.getArgCount() == 1 && | 
| Chris@69 | 4007             message.getArg(0).canConvert(QVariant::String)) { | 
| Chris@69 | 4008             path = message.getArg(0).toString(); | 
| Chris@69 | 4009             if (QFileInfo(path).exists()) { | 
| Chris@69 | 4010                 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in save" << std::endl; | 
| Chris@69 | 4011             } else { | 
| Chris@69 | 4012                 saveSessionFile(path); | 
| Chris@69 | 4013             } | 
| Chris@69 | 4014         } | 
| Chris@69 | 4015 | 
| Chris@69 | 4016     } else if (message.getMethod() == "export") { | 
| Chris@69 | 4017 | 
| Chris@69 | 4018         QString path; | 
| Chris@69 | 4019         if (getMainModel()) { | 
| Chris@69 | 4020             if (message.getArgCount() == 1 && | 
| Chris@69 | 4021                 message.getArg(0).canConvert(QVariant::String)) { | 
| Chris@69 | 4022                 path = message.getArg(0).toString(); | 
| Chris@69 | 4023                 if (QFileInfo(path).exists()) { | 
| Chris@69 | 4024                     std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in export" << std::endl; | 
| Chris@69 | 4025                 } else { | 
| Chris@69 | 4026                     WavFileWriter writer(path, | 
| Chris@69 | 4027                                          getMainModel()->getSampleRate(), | 
| Chris@69 | 4028                                          getMainModel()->getChannelCount()); | 
| Chris@69 | 4029                     MultiSelection ms = m_viewManager->getSelection(); | 
| Chris@69 | 4030                     if (!ms.getSelections().empty()) { | 
| Chris@69 | 4031                         writer.writeModel(getMainModel(), &ms); | 
| Chris@69 | 4032                     } else { | 
| Chris@69 | 4033                         writer.writeModel(getMainModel()); | 
| Chris@69 | 4034                     } | 
| Chris@69 | 4035                 } | 
| Chris@69 | 4036             } | 
| Chris@69 | 4037         } | 
| Chris@69 | 4038 | 
| Chris@69 | 4039     } else if (message.getMethod() == "jump" || | 
| Chris@69 | 4040                message.getMethod() == "play") { | 
| Chris@69 | 4041 | 
| Chris@69 | 4042         if (getMainModel()) { | 
| Chris@69 | 4043 | 
| Chris@69 | 4044             unsigned long frame = m_viewManager->getPlaybackFrame(); | 
| Chris@69 | 4045             bool selection = false; | 
| Chris@69 | 4046             bool play = (message.getMethod() == "play"); | 
| Chris@69 | 4047 | 
| Chris@69 | 4048             if (message.getArgCount() == 1) { | 
| Chris@69 | 4049 | 
| Chris@69 | 4050                 if (message.getArg(0).canConvert(QVariant::String) && | 
| Chris@69 | 4051                     message.getArg(0).toString() == "selection") { | 
| Chris@69 | 4052 | 
| Chris@69 | 4053                     selection = true; | 
| Chris@69 | 4054 | 
| Chris@69 | 4055                 } else if (message.getArg(0).canConvert(QVariant::String) && | 
| Chris@69 | 4056                            message.getArg(0).toString() == "end") { | 
| Chris@69 | 4057 | 
| Chris@69 | 4058                     frame = getMainModel()->getEndFrame(); | 
| Chris@69 | 4059 | 
| Chris@69 | 4060                 } else if (message.getArg(0).canConvert(QVariant::Double)) { | 
| Chris@69 | 4061 | 
| Chris@69 | 4062                     double time = message.getArg(0).toDouble(); | 
| Chris@69 | 4063                     if (time < 0.0) time = 0.0; | 
| Chris@69 | 4064 | 
| Chris@69 | 4065                     frame = lrint(time * getMainModel()->getSampleRate()); | 
| Chris@69 | 4066                 } | 
| Chris@69 | 4067             } | 
| Chris@69 | 4068 | 
| Chris@69 | 4069             if (frame > getMainModel()->getEndFrame()) { | 
| Chris@69 | 4070                 frame = getMainModel()->getEndFrame(); | 
| Chris@69 | 4071             } | 
| Chris@69 | 4072 | 
| Chris@69 | 4073             if (play) { | 
| Chris@69 | 4074                 m_viewManager->setPlaySelectionMode(selection); | 
| Chris@69 | 4075             } | 
| Chris@69 | 4076 | 
| Chris@69 | 4077             if (selection) { | 
| Chris@69 | 4078                 MultiSelection::SelectionList sl = m_viewManager->getSelections(); | 
| Chris@69 | 4079                 if (!sl.empty()) { | 
| Chris@69 | 4080                     frame = sl.begin()->getStartFrame(); | 
| Chris@69 | 4081                 } | 
| Chris@69 | 4082             } | 
| Chris@69 | 4083 | 
| Chris@69 | 4084             m_viewManager->setPlaybackFrame(frame); | 
| Chris@69 | 4085 | 
| Chris@69 | 4086             if (play && !m_playSource->isPlaying()) { | 
| Chris@69 | 4087                 m_playSource->play(frame); | 
| Chris@69 | 4088             } | 
| Chris@69 | 4089         } | 
| Chris@69 | 4090 | 
| Chris@69 | 4091     } else if (message.getMethod() == "stop") { | 
| Chris@69 | 4092 | 
| Chris@69 | 4093         if (m_playSource->isPlaying()) m_playSource->stop(); | 
| Chris@69 | 4094 | 
| Chris@69 | 4095     } else if (message.getMethod() == "loop") { | 
| Chris@69 | 4096 | 
| Chris@69 | 4097         if (message.getArgCount() == 1 && | 
| Chris@69 | 4098             message.getArg(0).canConvert(QVariant::String)) { | 
| Chris@69 | 4099 | 
| Chris@69 | 4100             QString str = message.getArg(0).toString(); | 
| Chris@69 | 4101             if (str == "on") { | 
| Chris@69 | 4102                 m_viewManager->setPlayLoopMode(true); | 
| Chris@69 | 4103             } else if (str == "off") { | 
| Chris@69 | 4104                 m_viewManager->setPlayLoopMode(false); | 
| Chris@69 | 4105             } | 
| Chris@69 | 4106         } | 
| Chris@69 | 4107 | 
| Chris@69 | 4108     } else if (message.getMethod() == "select" || | 
| Chris@69 | 4109                message.getMethod() == "addselect") { | 
| Chris@69 | 4110 | 
| Chris@69 | 4111         if (getMainModel()) { | 
| Chris@69 | 4112 | 
| Chris@73 | 4113             int f0 = getMainModel()->getStartFrame(); | 
| Chris@73 | 4114             int f1 = getMainModel()->getEndFrame(); | 
| Chris@69 | 4115 | 
| Chris@69 | 4116             bool done = false; | 
| Chris@69 | 4117 | 
| Chris@69 | 4118             if (message.getArgCount() == 2 && | 
| Chris@69 | 4119                 message.getArg(0).canConvert(QVariant::Double) && | 
| Chris@69 | 4120                 message.getArg(1).canConvert(QVariant::Double)) { | 
| Chris@69 | 4121 | 
| Chris@69 | 4122                 double t0 = message.getArg(0).toDouble(); | 
| Chris@69 | 4123                 double t1 = message.getArg(1).toDouble(); | 
| Chris@69 | 4124                 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; } | 
| Chris@69 | 4125                 if (t0 < 0.0) t0 = 0.0; | 
| Chris@69 | 4126                 if (t1 < 0.0) t1 = 0.0; | 
| Chris@69 | 4127 | 
| Chris@69 | 4128                 f0 = lrint(t0 * getMainModel()->getSampleRate()); | 
| Chris@69 | 4129                 f1 = lrint(t1 * getMainModel()->getSampleRate()); | 
| Chris@73 | 4130 | 
| Chris@73 | 4131                 Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@73 | 4132                 Layer *layer = 0; | 
| Chris@73 | 4133                 if (pane) layer = pane->getSelectedLayer(); | 
| Chris@73 | 4134                 if (layer) { | 
| Chris@73 | 4135                     size_t resolution; | 
| Chris@73 | 4136                     layer->snapToFeatureFrame(pane, f0, resolution, | 
| Chris@73 | 4137                                               Layer::SnapLeft); | 
| Chris@73 | 4138                     layer->snapToFeatureFrame(pane, f1, resolution, | 
| Chris@73 | 4139                                               Layer::SnapRight); | 
| Chris@73 | 4140                 } | 
| Chris@69 | 4141 | 
| Chris@69 | 4142             } else if (message.getArgCount() == 1 && | 
| Chris@69 | 4143                        message.getArg(0).canConvert(QVariant::String)) { | 
| Chris@69 | 4144 | 
| Chris@69 | 4145                 QString str = message.getArg(0).toString(); | 
| Chris@69 | 4146                 if (str == "none") { | 
| Chris@69 | 4147                     m_viewManager->clearSelections(); | 
| Chris@69 | 4148                     done = true; | 
| Chris@69 | 4149                 } | 
| Chris@69 | 4150             } | 
| Chris@69 | 4151 | 
| Chris@69 | 4152             if (!done) { | 
| Chris@69 | 4153                 if (message.getMethod() == "select") { | 
| Chris@69 | 4154                     m_viewManager->setSelection(Selection(f0, f1)); | 
| Chris@69 | 4155                 } else { | 
| Chris@69 | 4156                     m_viewManager->addSelection(Selection(f0, f1)); | 
| Chris@69 | 4157                 } | 
| Chris@69 | 4158             } | 
| Chris@69 | 4159         } | 
| Chris@69 | 4160 | 
| Chris@69 | 4161     } else if (message.getMethod() == "add") { | 
| Chris@69 | 4162 | 
| Chris@69 | 4163         if (getMainModel()) { | 
| Chris@69 | 4164 | 
| Chris@69 | 4165             if (message.getArgCount() >= 1 && | 
| Chris@69 | 4166                 message.getArg(0).canConvert(QVariant::String)) { | 
| Chris@69 | 4167 | 
| Chris@69 | 4168                 int channel = -1; | 
| Chris@69 | 4169                 if (message.getArgCount() == 2 && | 
| Chris@69 | 4170                     message.getArg(0).canConvert(QVariant::Int)) { | 
| Chris@69 | 4171                     channel = message.getArg(0).toInt(); | 
| Chris@69 | 4172                     if (channel < -1 || | 
| Chris@69 | 4173                         channel > getMainModel()->getChannelCount()) { | 
| Chris@69 | 4174                         std::cerr << "WARNING: MainWindow::handleOSCMessage: channel " | 
| Chris@69 | 4175                                   << channel << " out of range" << std::endl; | 
| Chris@69 | 4176                         channel = -1; | 
| Chris@69 | 4177                     } | 
| Chris@69 | 4178                 } | 
| Chris@69 | 4179 | 
| Chris@69 | 4180                 QString str = message.getArg(0).toString(); | 
| Chris@69 | 4181 | 
| Chris@69 | 4182                 LayerFactory::LayerType type = | 
| Chris@69 | 4183                     LayerFactory::getInstance()->getLayerTypeForName(str); | 
| Chris@69 | 4184 | 
| Chris@69 | 4185                 if (type == LayerFactory::UnknownLayer) { | 
| Chris@69 | 4186                     std::cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer " | 
| Chris@69 | 4187                               << "type " << str.toStdString() << std::endl; | 
| Chris@69 | 4188                 } else { | 
| Chris@69 | 4189 | 
| Chris@69 | 4190                     PaneConfiguration configuration(type, | 
| Chris@69 | 4191                                                     getMainModel(), | 
| Chris@69 | 4192                                                     channel); | 
| Chris@69 | 4193 | 
| Chris@69 | 4194                     addPane(configuration, | 
| Chris@69 | 4195                             tr("Add %1 Pane") | 
| Chris@69 | 4196                             .arg(LayerFactory::getInstance()-> | 
| Chris@69 | 4197                                  getLayerPresentationName(type))); | 
| Chris@69 | 4198                 } | 
| Chris@69 | 4199             } | 
| Chris@69 | 4200         } | 
| Chris@69 | 4201 | 
| Chris@69 | 4202     } else if (message.getMethod() == "undo") { | 
| Chris@69 | 4203 | 
| Chris@69 | 4204         CommandHistory::getInstance()->undo(); | 
| Chris@69 | 4205 | 
| Chris@69 | 4206     } else if (message.getMethod() == "redo") { | 
| Chris@69 | 4207 | 
| Chris@69 | 4208         CommandHistory::getInstance()->redo(); | 
| Chris@69 | 4209 | 
| Chris@69 | 4210     } else if (message.getMethod() == "set") { | 
| Chris@69 | 4211 | 
| Chris@70 | 4212         if (message.getArgCount() == 2 && | 
| Chris@69 | 4213             message.getArg(0).canConvert(QVariant::String) && | 
| Chris@69 | 4214             message.getArg(1).canConvert(QVariant::Double)) { | 
| Chris@69 | 4215 | 
| Chris@69 | 4216             QString property = message.getArg(0).toString(); | 
| Chris@69 | 4217             float value = (float)message.getArg(1).toDouble(); | 
| Chris@69 | 4218 | 
| Chris@69 | 4219             if (property == "gain") { | 
| Chris@69 | 4220                 if (value < 0.0) value = 0.0; | 
| Chris@69 | 4221                 m_fader->setValue(value); | 
| Chris@69 | 4222                 if (m_playTarget) m_playTarget->setOutputGain(value); | 
| Chris@69 | 4223             } else if (property == "speedup") { | 
| Chris@69 | 4224                 m_playSpeed->setMappedValue(value); | 
| Chris@69 | 4225             } else if (property == "overlays") { | 
| Chris@69 | 4226                 if (value < 0.5) { | 
| Chris@69 | 4227                     m_viewManager->setOverlayMode(ViewManager::NoOverlays); | 
| Chris@69 | 4228                 } else if (value < 1.5) { | 
| Chris@90 | 4229                     m_viewManager->setOverlayMode(ViewManager::MinimalOverlays); | 
| Chris@90 | 4230                 } else if (value < 2.5) { | 
| Chris@90 | 4231                     m_viewManager->setOverlayMode(ViewManager::StandardOverlays); | 
| Chris@69 | 4232                 } else { | 
| Chris@69 | 4233                     m_viewManager->setOverlayMode(ViewManager::AllOverlays); | 
| Chris@69 | 4234                 } | 
| Chris@70 | 4235             } else if (property == "zoomwheels") { | 
| Chris@70 | 4236                 m_viewManager->setZoomWheelsEnabled(value > 0.5); | 
| Chris@72 | 4237             } else if (property == "propertyboxes") { | 
| Chris@72 | 4238                 bool toggle = ((value < 0.5) != | 
| Chris@72 | 4239                                (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks)); | 
| Chris@72 | 4240                 if (toggle) togglePropertyBoxes(); | 
| Chris@70 | 4241             } | 
| Chris@70 | 4242 | 
| Chris@70 | 4243         } else { | 
| Chris@70 | 4244             PropertyContainer *container = 0; | 
| Chris@70 | 4245             Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@70 | 4246             if (pane && | 
| Chris@70 | 4247                 message.getArgCount() == 3 && | 
| Chris@70 | 4248                 message.getArg(0).canConvert(QVariant::String) && | 
| Chris@70 | 4249                 message.getArg(1).canConvert(QVariant::String) && | 
| Chris@70 | 4250                 message.getArg(2).canConvert(QVariant::String)) { | 
| Chris@70 | 4251                 if (message.getArg(0).toString() == "pane") { | 
| Chris@70 | 4252                     container = pane->getPropertyContainer(0); | 
| Chris@70 | 4253                 } else if (message.getArg(0).toString() == "layer") { | 
| Chris@70 | 4254                     container = pane->getSelectedLayer(); | 
| Chris@70 | 4255                 } | 
| Chris@70 | 4256             } | 
| Chris@70 | 4257             if (container) { | 
| Chris@70 | 4258                 QString nameString = message.getArg(1).toString(); | 
| Chris@70 | 4259                 QString valueString = message.getArg(2).toString(); | 
| Chris@70 | 4260                 container->setPropertyWithCommand(nameString, valueString); | 
| Chris@69 | 4261             } | 
| Chris@69 | 4262         } | 
| Chris@69 | 4263 | 
| Chris@69 | 4264     } else if (message.getMethod() == "setcurrent") { | 
| Chris@69 | 4265 | 
| Chris@69 | 4266         int paneIndex = -1, layerIndex = -1; | 
| Chris@69 | 4267         bool wantLayer = false; | 
| Chris@69 | 4268 | 
| Chris@69 | 4269         if (message.getArgCount() >= 1 && | 
| Chris@69 | 4270             message.getArg(0).canConvert(QVariant::Int)) { | 
| Chris@69 | 4271 | 
| Chris@69 | 4272             paneIndex = message.getArg(0).toInt() - 1; | 
| Chris@69 | 4273 | 
| Chris@69 | 4274             if (message.getArgCount() >= 2 && | 
| Chris@69 | 4275                 message.getArg(1).canConvert(QVariant::Int)) { | 
| Chris@69 | 4276                 wantLayer = true; | 
| Chris@69 | 4277                 layerIndex = message.getArg(1).toInt() - 1; | 
| Chris@69 | 4278             } | 
| Chris@69 | 4279         } | 
| Chris@69 | 4280 | 
| Chris@69 | 4281         if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) { | 
| Chris@69 | 4282             Pane *pane = m_paneStack->getPane(paneIndex); | 
| Chris@70 | 4283             m_paneStack->setCurrentPane(pane); | 
| Chris@69 | 4284             if (layerIndex >= 0 && layerIndex < pane->getLayerCount()) { | 
| Chris@69 | 4285                 Layer *layer = pane->getLayer(layerIndex); | 
| Chris@69 | 4286                 m_paneStack->setCurrentLayer(pane, layer); | 
| Chris@69 | 4287             } else if (wantLayer && layerIndex == -1) { | 
| Chris@69 | 4288                 m_paneStack->setCurrentLayer(pane, 0); | 
| Chris@69 | 4289             } | 
| Chris@69 | 4290         } | 
| Chris@69 | 4291 | 
| Chris@69 | 4292     } else if (message.getMethod() == "delete") { | 
| Chris@69 | 4293 | 
| Chris@69 | 4294         if (message.getArgCount() == 1 && | 
| Chris@69 | 4295             message.getArg(0).canConvert(QVariant::String)) { | 
| Chris@69 | 4296 | 
| Chris@69 | 4297             QString target = message.getArg(0).toString(); | 
| Chris@69 | 4298 | 
| Chris@69 | 4299             if (target == "pane") { | 
| Chris@69 | 4300 | 
| Chris@69 | 4301                 deleteCurrentPane(); | 
| Chris@69 | 4302 | 
| Chris@69 | 4303             } else if (target == "layer") { | 
| Chris@69 | 4304 | 
| Chris@69 | 4305                 deleteCurrentLayer(); | 
| Chris@69 | 4306 | 
| Chris@69 | 4307             } else { | 
| Chris@69 | 4308 | 
| Chris@69 | 4309                 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target.toStdString() << std::endl; | 
| Chris@69 | 4310             } | 
| Chris@69 | 4311         } | 
| Chris@69 | 4312 | 
| Chris@69 | 4313     } else if (message.getMethod() == "zoom") { | 
| Chris@69 | 4314 | 
| Chris@69 | 4315         if (message.getArgCount() == 1) { | 
| Chris@69 | 4316             if (message.getArg(0).canConvert(QVariant::String) && | 
| Chris@69 | 4317                 message.getArg(0).toString() == "in") { | 
| Chris@69 | 4318                 zoomIn(); | 
| Chris@69 | 4319             } else if (message.getArg(0).canConvert(QVariant::String) && | 
| Chris@69 | 4320                        message.getArg(0).toString() == "out") { | 
| Chris@69 | 4321                 zoomOut(); | 
| Chris@69 | 4322             } else if (message.getArg(0).canConvert(QVariant::String) && | 
| Chris@69 | 4323                        message.getArg(0).toString() == "default") { | 
| Chris@69 | 4324                 zoomDefault(); | 
| Chris@69 | 4325             } else if (message.getArg(0).canConvert(QVariant::Double)) { | 
| Chris@69 | 4326                 double level = message.getArg(0).toDouble(); | 
| Chris@69 | 4327                 Pane *currentPane = m_paneStack->getCurrentPane(); | 
| Chris@69 | 4328                 if (level < 1.0) level = 1.0; | 
| Chris@69 | 4329                 if (currentPane) currentPane->setZoomLevel(lrint(level)); | 
| Chris@69 | 4330             } | 
| Chris@69 | 4331         } | 
| Chris@69 | 4332 | 
| Chris@73 | 4333     } else if (message.getMethod() == "zoomvertical") { | 
| Chris@73 | 4334 | 
| Chris@73 | 4335         Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@73 | 4336         Layer *layer = 0; | 
| Chris@73 | 4337         if (pane && pane->getLayerCount() > 0) { | 
| Chris@73 | 4338             layer = pane->getLayer(pane->getLayerCount() - 1); | 
| Chris@73 | 4339         } | 
| Chris@73 | 4340         int defaultStep = 0; | 
| Chris@73 | 4341         int steps = 0; | 
| Chris@73 | 4342         if (layer) { | 
| Chris@73 | 4343             steps = layer->getVerticalZoomSteps(defaultStep); | 
| Chris@73 | 4344             if (message.getArgCount() == 1 && steps > 0) { | 
| Chris@73 | 4345                 if (message.getArg(0).canConvert(QVariant::String) && | 
| Chris@73 | 4346                     message.getArg(0).toString() == "in") { | 
| Chris@73 | 4347                     int step = layer->getCurrentVerticalZoomStep() + 1; | 
| Chris@73 | 4348                     if (step < steps) layer->setVerticalZoomStep(step); | 
| Chris@73 | 4349                 } else if (message.getArg(0).canConvert(QVariant::String) && | 
| Chris@73 | 4350                            message.getArg(0).toString() == "out") { | 
| Chris@73 | 4351                     int step = layer->getCurrentVerticalZoomStep() - 1; | 
| Chris@73 | 4352                     if (step >= 0) layer->setVerticalZoomStep(step); | 
| Chris@73 | 4353                 } else if (message.getArg(0).canConvert(QVariant::String) && | 
| Chris@73 | 4354                            message.getArg(0).toString() == "default") { | 
| Chris@73 | 4355                     layer->setVerticalZoomStep(defaultStep); | 
| Chris@73 | 4356                 } | 
| Chris@73 | 4357             } else if (message.getArgCount() == 2) { | 
| Chris@73 | 4358                 if (message.getArg(0).canConvert(QVariant::Double) && | 
| Chris@73 | 4359                     message.getArg(1).canConvert(QVariant::Double)) { | 
| Chris@73 | 4360                     double min = message.getArg(0).toDouble(); | 
| Chris@73 | 4361                     double max = message.getArg(1).toDouble(); | 
| Chris@73 | 4362                     layer->setDisplayExtents(min, max); | 
| Chris@73 | 4363                 } | 
| Chris@73 | 4364             } | 
| Chris@73 | 4365         } | 
| Chris@73 | 4366 | 
| Chris@70 | 4367     } else if (message.getMethod() == "quit") { | 
| Chris@70 | 4368 | 
| Chris@70 | 4369         m_abandoning = true; | 
| Chris@70 | 4370         close(); | 
| Chris@70 | 4371 | 
| Chris@70 | 4372     } else if (message.getMethod() == "resize") { | 
| Chris@70 | 4373 | 
| Chris@70 | 4374         if (message.getArgCount() == 2) { | 
| Chris@70 | 4375 | 
| Chris@70 | 4376             int width = 0, height = 0; | 
| Chris@70 | 4377 | 
| Chris@70 | 4378             if (message.getArg(1).canConvert(QVariant::Int)) { | 
| Chris@70 | 4379 | 
| Chris@70 | 4380                 height = message.getArg(1).toInt(); | 
| Chris@70 | 4381 | 
| Chris@70 | 4382                 if (message.getArg(0).canConvert(QVariant::String) && | 
| Chris@70 | 4383                     message.getArg(0).toString() == "pane") { | 
| Chris@70 | 4384 | 
| Chris@70 | 4385                     Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@70 | 4386                     if (pane) pane->resize(pane->width(), height); | 
| Chris@70 | 4387 | 
| Chris@70 | 4388                 } else if (message.getArg(0).canConvert(QVariant::Int)) { | 
| Chris@70 | 4389 | 
| Chris@70 | 4390                     width = message.getArg(0).toInt(); | 
| Chris@70 | 4391                     resize(width, height); | 
| Chris@70 | 4392                 } | 
| Chris@70 | 4393             } | 
| Chris@70 | 4394         } | 
| Chris@70 | 4395 | 
| Chris@70 | 4396     } else if (message.getMethod() == "transform") { | 
| Chris@70 | 4397 | 
| Chris@70 | 4398         Pane *pane = m_paneStack->getCurrentPane(); | 
| Chris@70 | 4399 | 
| Chris@70 | 4400         if (getMainModel() && | 
| Chris@70 | 4401             pane && | 
| Chris@70 | 4402             message.getArgCount() == 1 && | 
| Chris@70 | 4403             message.getArg(0).canConvert(QVariant::String)) { | 
| Chris@70 | 4404 | 
| Chris@107 | 4405             TransformId transform = message.getArg(0).toString(); | 
| Chris@70 | 4406 | 
| Chris@70 | 4407             Layer *newLayer = m_document->createDerivedLayer | 
| Chris@70 | 4408                 (transform, | 
| Chris@70 | 4409                  getMainModel(), | 
| Chris@73 | 4410                  TransformFactory::getInstance()->getDefaultContextForTransform | 
| Chris@73 | 4411                  (transform, getMainModel()), | 
| Chris@70 | 4412                  ""); | 
| Chris@70 | 4413 | 
| Chris@70 | 4414             if (newLayer) { | 
| Chris@70 | 4415                 m_document->addLayerToView(pane, newLayer); | 
| Chris@70 | 4416                 m_recentTransforms.add(transform); | 
| Chris@70 | 4417                 m_paneStack->setCurrentLayer(pane, newLayer); | 
| Chris@70 | 4418             } | 
| Chris@70 | 4419         } | 
| Chris@70 | 4420 | 
| Chris@69 | 4421     } else { | 
| Chris@69 | 4422         std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported " | 
| Chris@69 | 4423                   << "method \"" << message.getMethod().toStdString() | 
| Chris@69 | 4424                   << "\"" << std::endl; | 
| Chris@69 | 4425     } | 
| Chris@69 | 4426 | 
| Chris@69 | 4427 } | 
| Chris@69 | 4428 | 
| Chris@69 | 4429 void | 
| Chris@0 | 4430 MainWindow::preferences() | 
| Chris@0 | 4431 { | 
| Chris@0 | 4432     if (!m_preferencesDialog.isNull()) { | 
| Chris@0 | 4433         m_preferencesDialog->show(); | 
| Chris@0 | 4434         m_preferencesDialog->raise(); | 
| Chris@0 | 4435         return; | 
| Chris@0 | 4436     } | 
| Chris@0 | 4437 | 
| Chris@0 | 4438     m_preferencesDialog = new PreferencesDialog(this); | 
| Chris@0 | 4439 | 
| Chris@0 | 4440     // DeleteOnClose is safe here, because m_preferencesDialog is a | 
| Chris@0 | 4441     // QPointer that will be zeroed when the dialog is deleted.  We | 
| Chris@0 | 4442     // use it in preference to leaving the dialog lying around because | 
| Chris@0 | 4443     // if you Cancel the dialog, it resets the preferences state | 
| Chris@0 | 4444     // without resetting its own widgets, so its state will be | 
| Chris@0 | 4445     // incorrect when next shown unless we construct it afresh | 
| Chris@0 | 4446     m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose); | 
| Chris@0 | 4447 | 
| Chris@0 | 4448     m_preferencesDialog->show(); | 
| Chris@0 | 4449 } | 
| Chris@0 | 4450 | 
| Chris@0 | 4451 void | 
| Chris@90 | 4452 MainWindow::mouseEnteredWidget() | 
| Chris@90 | 4453 { | 
| Chris@90 | 4454     QWidget *w = dynamic_cast<QWidget *>(sender()); | 
| Chris@90 | 4455     if (!w) return; | 
| Chris@90 | 4456 | 
| Chris@90 | 4457     if (w == m_fader) { | 
| Chris@116 | 4458         contextHelpChanged(tr("Adjust the master playback level")); | 
| Chris@90 | 4459     } else if (w == m_playSpeed) { | 
| Chris@116 | 4460         contextHelpChanged(tr("Adjust the master playback speed")); | 
| Chris@90 | 4461     } else if (w == m_playSharpen && w->isEnabled()) { | 
| Chris@116 | 4462         contextHelpChanged(tr("Toggle transient sharpening for playback time scaling")); | 
| Chris@90 | 4463     } else if (w == m_playMono && w->isEnabled()) { | 
| Chris@116 | 4464         contextHelpChanged(tr("Toggle mono mode for playback time scaling")); | 
| Chris@90 | 4465     } | 
| Chris@90 | 4466 } | 
| Chris@90 | 4467 | 
| Chris@90 | 4468 void | 
| Chris@90 | 4469 MainWindow::mouseLeftWidget() | 
| Chris@90 | 4470 { | 
| Chris@116 | 4471     contextHelpChanged(""); | 
| Chris@116 | 4472 } | 
| Chris@116 | 4473 | 
| Chris@116 | 4474 void | 
| Chris@117 | 4475 MainWindow::inProgressSelectionChanged() | 
| Chris@117 | 4476 { | 
| Chris@117 | 4477     Pane *currentPane = 0; | 
| Chris@117 | 4478     if (m_paneStack) currentPane = m_paneStack->getCurrentPane(); | 
| Chris@117 | 4479     if (currentPane) updateVisibleRangeDisplay(currentPane); | 
| Chris@117 | 4480 } | 
| Chris@117 | 4481 | 
| Chris@117 | 4482 void | 
| Chris@116 | 4483 MainWindow::contextHelpChanged(const QString &s) | 
| Chris@116 | 4484 { | 
| Chris@116 | 4485     if (s == "" && m_myStatusMessage != "") { | 
| Chris@116 | 4486         statusBar()->showMessage(m_myStatusMessage); | 
| Chris@116 | 4487         return; | 
| Chris@116 | 4488     } | 
| Chris@116 | 4489     statusBar()->showMessage(s); | 
| Chris@90 | 4490 } | 
| Chris@90 | 4491 | 
| Chris@90 | 4492 void | 
| Chris@0 | 4493 MainWindow::website() | 
| Chris@0 | 4494 { | 
| Chris@0 | 4495     openHelpUrl(tr("http://www.sonicvisualiser.org/")); | 
| Chris@0 | 4496 } | 
| Chris@0 | 4497 | 
| Chris@0 | 4498 void | 
| Chris@0 | 4499 MainWindow::help() | 
| Chris@0 | 4500 { | 
| Chris@0 | 4501     openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/en/")); | 
| Chris@0 | 4502 } | 
| Chris@0 | 4503 | 
| Chris@0 | 4504 void | 
| Chris@0 | 4505 MainWindow::openHelpUrl(QString url) | 
| Chris@0 | 4506 { | 
| Chris@0 | 4507     // This method mostly lifted from Qt Assistant source code | 
| Chris@0 | 4508 | 
| Chris@0 | 4509     QProcess *process = new QProcess(this); | 
| Chris@0 | 4510     connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater())); | 
| Chris@0 | 4511 | 
| Chris@0 | 4512     QStringList args; | 
| Chris@0 | 4513 | 
| Chris@0 | 4514 #ifdef Q_OS_MAC | 
| Chris@0 | 4515     args.append(url); | 
| Chris@0 | 4516     process->start("open", args); | 
| Chris@0 | 4517 #else | 
| Chris@0 | 4518 #ifdef Q_OS_WIN32 | 
| Chris@0 | 4519 | 
| Chris@0 | 4520 	QString pf(getenv("ProgramFiles")); | 
| Chris@0 | 4521 	QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE"); | 
| Chris@0 | 4522 | 
| Chris@0 | 4523 	args.append(url); | 
| Chris@0 | 4524 	process->start(command, args); | 
| Chris@0 | 4525 | 
| Chris@0 | 4526 #else | 
| Chris@0 | 4527 #ifdef Q_WS_X11 | 
| Chris@0 | 4528     if (!qgetenv("KDE_FULL_SESSION").isEmpty()) { | 
| Chris@0 | 4529         args.append("exec"); | 
| Chris@0 | 4530         args.append(url); | 
| Chris@0 | 4531         process->start("kfmclient", args); | 
| Chris@0 | 4532     } else if (!qgetenv("BROWSER").isEmpty()) { | 
| Chris@0 | 4533         args.append(url); | 
| Chris@0 | 4534         process->start(qgetenv("BROWSER"), args); | 
| Chris@0 | 4535     } else { | 
| Chris@0 | 4536         args.append(url); | 
| Chris@0 | 4537         process->start("firefox", args); | 
| Chris@0 | 4538     } | 
| Chris@0 | 4539 #endif | 
| Chris@0 | 4540 #endif | 
| Chris@0 | 4541 #endif | 
| Chris@0 | 4542 } | 
| Chris@0 | 4543 | 
| Chris@0 | 4544 void | 
| Chris@0 | 4545 MainWindow::about() | 
| Chris@0 | 4546 { | 
| Chris@0 | 4547     bool debug = false; | 
| Chris@0 | 4548     QString version = "(unknown version)"; | 
| Chris@0 | 4549 | 
| Chris@0 | 4550 #ifdef BUILD_DEBUG | 
| Chris@0 | 4551     debug = true; | 
| Chris@0 | 4552 #endif | 
| Chris@0 | 4553 #ifdef SV_VERSION | 
| Chris@0 | 4554 #ifdef SVNREV | 
| Chris@0 | 4555     version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV); | 
| Chris@0 | 4556 #else | 
| Chris@0 | 4557     version = tr("Release %1").arg(SV_VERSION); | 
| Chris@0 | 4558 #endif | 
| Chris@0 | 4559 #else | 
| Chris@0 | 4560 #ifdef SVNREV | 
| Chris@0 | 4561     version = tr("Unreleased : Revision %1").arg(SVNREV); | 
| Chris@0 | 4562 #endif | 
| Chris@0 | 4563 #endif | 
| Chris@0 | 4564 | 
| Chris@0 | 4565     QString aboutText; | 
| Chris@0 | 4566 | 
| Chris@0 | 4567     aboutText += tr("<h3>About Sonic Visualiser</h3>"); | 
| Chris@90 | 4568     aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for<br>semantic music analysis and annotation.</p>"); | 
| Chris@111 | 4569     aboutText += tr("<p>%1 : %2 configuration</p>") | 
| Chris@0 | 4570         .arg(version) | 
| Chris@0 | 4571         .arg(debug ? tr("Debug") : tr("Release")); | 
| Chris@0 | 4572 | 
| Chris@0 | 4573 #ifdef BUILD_STATIC | 
| Chris@0 | 4574     aboutText += tr("<p>Statically linked"); | 
| Chris@0 | 4575 #ifndef QT_SHARED | 
| Chris@0 | 4576     aboutText += tr("<br>With Qt (v%1) © Trolltech AS").arg(QT_VERSION_STR); | 
| Chris@0 | 4577 #endif | 
| Chris@0 | 4578 #ifdef HAVE_JACK | 
| Chris@93 | 4579 #ifdef JACK_VERSION | 
| Chris@0 | 4580     aboutText += tr("<br>With JACK audio output (v%1) © Paul Davis and Jack O'Quin").arg(JACK_VERSION); | 
| Chris@93 | 4581 #else | 
| Chris@93 | 4582     aboutText += tr("<br>With JACK audio output © Paul Davis and Jack O'Quin"); | 
| Chris@93 | 4583 #endif | 
| Chris@0 | 4584 #endif | 
| Chris@0 | 4585 #ifdef HAVE_PORTAUDIO | 
| Chris@0 | 4586     aboutText += tr("<br>With PortAudio audio output © Ross Bencina and Phil Burk"); | 
| Chris@0 | 4587 #endif | 
| Chris@0 | 4588 #ifdef HAVE_OGGZ | 
| Chris@93 | 4589 #ifdef OGGZ_VERSION | 
| Chris@0 | 4590     aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) © CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION); | 
| Chris@93 | 4591 #else | 
| Chris@93 | 4592     aboutText += tr("<br>With Ogg file decoder © CSIRO Australia"); | 
| Chris@93 | 4593 #endif | 
| Chris@0 | 4594 #endif | 
| Chris@0 | 4595 #ifdef HAVE_MAD | 
| Chris@93 | 4596 #ifdef MAD_VERSION | 
| Chris@0 | 4597     aboutText += tr("<br>With MAD mp3 decoder (v%1) © Underbit Technologies Inc").arg(MAD_VERSION); | 
| Chris@93 | 4598 #else | 
| Chris@93 | 4599     aboutText += tr("<br>With MAD mp3 decoder © Underbit Technologies Inc"); | 
| Chris@93 | 4600 #endif | 
| Chris@0 | 4601 #endif | 
| Chris@0 | 4602 #ifdef HAVE_SAMPLERATE | 
| Chris@93 | 4603 #ifdef SAMPLERATE_VERSION | 
| Chris@0 | 4604     aboutText += tr("<br>With libsamplerate (v%1) © Erik de Castro Lopo").arg(SAMPLERATE_VERSION); | 
| Chris@93 | 4605 #else | 
| Chris@93 | 4606     aboutText += tr("<br>With libsamplerate © Erik de Castro Lopo"); | 
| Chris@93 | 4607 #endif | 
| Chris@0 | 4608 #endif | 
| Chris@0 | 4609 #ifdef HAVE_SNDFILE | 
| Chris@93 | 4610 #ifdef SNDFILE_VERSION | 
| Chris@0 | 4611     aboutText += tr("<br>With libsndfile (v%1) © Erik de Castro Lopo").arg(SNDFILE_VERSION); | 
| Chris@93 | 4612 #else | 
| Chris@93 | 4613     aboutText += tr("<br>With libsndfile © Erik de Castro Lopo"); | 
| Chris@93 | 4614 #endif | 
| Chris@0 | 4615 #endif | 
| Chris@0 | 4616 #ifdef HAVE_FFTW3 | 
| Chris@93 | 4617 #ifdef FFTW3_VERSION | 
| Chris@0 | 4618     aboutText += tr("<br>With FFTW3 (v%1) © Matteo Frigo and MIT").arg(FFTW3_VERSION); | 
| Chris@93 | 4619 #else | 
| Chris@93 | 4620     aboutText += tr("<br>With FFTW3 © Matteo Frigo and MIT"); | 
| Chris@93 | 4621 #endif | 
| Chris@0 | 4622 #endif | 
| Chris@0 | 4623 #ifdef HAVE_VAMP | 
| Chris@114 | 4624     aboutText += tr("<br>With Vamp plugin support (API v%1, host SDK v%2) © Chris Cannam").arg(VAMP_API_VERSION).arg(VAMP_SDK_VERSION); | 
| Chris@0 | 4625 #endif | 
| Chris@0 | 4626     aboutText += tr("<br>With LADSPA plugin support (API v%1) © Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION); | 
| Chris@0 | 4627     aboutText += tr("<br>With DSSI plugin support (API v%1) © Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION); | 
| Chris@69 | 4628 #ifdef HAVE_LIBLO | 
| Chris@93 | 4629 #ifdef LIBLO_VERSION | 
| Chris@69 | 4630     aboutText += tr("<br>With liblo Lite OSC library (v%1) © Steve Harris").arg(LIBLO_VERSION); | 
| Chris@93 | 4631 #else | 
| Chris@93 | 4632     aboutText += tr("<br>With liblo Lite OSC library © Steve Harris").arg(LIBLO_VERSION); | 
| Chris@93 | 4633 #endif | 
| Chris@70 | 4634     if (m_oscQueue && m_oscQueue->isOK()) { | 
| Chris@69 | 4635         aboutText += tr("<p>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL()); | 
| Chris@69 | 4636     } | 
| Chris@69 | 4637 #endif | 
| Chris@0 | 4638     aboutText += "</p>"; | 
| Chris@0 | 4639 #endif | 
| Chris@0 | 4640 | 
| Chris@0 | 4641     aboutText += | 
| Chris@90 | 4642         "<p>Sonic Visualiser Copyright © 2005 - 2007 Chris Cannam and<br>" | 
| Chris@90 | 4643         "Queen Mary, University of London.</p>" | 
| Chris@0 | 4644         "<p>This program is free software; you can redistribute it and/or<br>" | 
| Chris@0 | 4645         "modify it under the terms of the GNU General Public License as<br>" | 
| Chris@0 | 4646         "published by the Free Software Foundation; either version 2 of the<br>" | 
| Chris@0 | 4647         "License, or (at your option) any later version.<br>See the file " | 
| Chris@0 | 4648         "COPYING included with this distribution for more information.</p>"; | 
| Chris@0 | 4649 | 
| Chris@0 | 4650     QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText); | 
| Chris@0 | 4651 } | 
| Chris@0 | 4652 |