00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "../version.h"
00017
00018 #include "MainWindow.h"
00019 #include "PreferencesDialog.h"
00020
00021 #include "view/Pane.h"
00022 #include "view/PaneStack.h"
00023 #include "data/model/WaveFileModel.h"
00024 #include "data/model/SparseOneDimensionalModel.h"
00025 #include "data/model/NoteModel.h"
00026 #include "data/model/Labeller.h"
00027 #include "data/osc/OSCQueue.h"
00028 #include "framework/Document.h"
00029 #include "view/ViewManager.h"
00030 #include "base/Preferences.h"
00031 #include "layer/WaveformLayer.h"
00032 #include "layer/TimeRulerLayer.h"
00033 #include "layer/TimeInstantLayer.h"
00034 #include "layer/TimeValueLayer.h"
00035 #include "layer/Colour3DPlotLayer.h"
00036 #include "layer/SliceLayer.h"
00037 #include "layer/SliceableLayer.h"
00038 #include "layer/ImageLayer.h"
00039 #include "widgets/Fader.h"
00040 #include "view/Overview.h"
00041 #include "widgets/PropertyBox.h"
00042 #include "widgets/PropertyStack.h"
00043 #include "widgets/AudioDial.h"
00044 #include "widgets/IconLoader.h"
00045 #include "widgets/LayerTreeDialog.h"
00046 #include "widgets/ListInputDialog.h"
00047 #include "widgets/SubdividingMenu.h"
00048 #include "widgets/NotifyingPushButton.h"
00049 #include "widgets/KeyReference.h"
00050 #include "widgets/LabelCounterInputDialog.h"
00051 #include "audioio/AudioCallbackPlaySource.h"
00052 #include "audioio/AudioCallbackPlayTarget.h"
00053 #include "audioio/AudioTargetFactory.h"
00054 #include "audioio/PlaySpeedRangeMapper.h"
00055 #include "data/fileio/DataFileReaderFactory.h"
00056 #include "data/fileio/PlaylistFileReader.h"
00057 #include "data/fileio/WavFileWriter.h"
00058 #include "data/fileio/CSVFileWriter.h"
00059 #include "data/fileio/MIDIFileWriter.h"
00060 #include "data/fileio/BZipFileDevice.h"
00061 #include "data/fileio/FileSource.h"
00062 #include "data/fft/FFTDataServer.h"
00063 #include "base/RecentFiles.h"
00064 #include "plugin/transform/TransformFactory.h"
00065 #include "plugin/transform/ModelTransformerFactory.h"
00066 #include "base/PlayParameterRepository.h"
00067 #include "base/XmlExportable.h"
00068 #include "base/CommandHistory.h"
00069 #include "base/Profiler.h"
00070 #include "base/Clipboard.h"
00071 #include "base/UnitDatabase.h"
00072 #include "base/ColourDatabase.h"
00073
00074
00075 #include "vamp/vamp.h"
00076 #include "vamp-sdk/PluginBase.h"
00077 #include "plugin/api/ladspa.h"
00078 #include "plugin/api/dssi.h"
00079
00080 #include <QApplication>
00081 #include <QMessageBox>
00082 #include <QGridLayout>
00083 #include <QLabel>
00084 #include <QAction>
00085 #include <QMenuBar>
00086 #include <QToolBar>
00087 #include <QInputDialog>
00088 #include <QStatusBar>
00089 #include <QTreeView>
00090 #include <QFile>
00091 #include <QFileInfo>
00092 #include <QDir>
00093 #include <QTextStream>
00094 #include <QProcess>
00095 #include <QShortcut>
00096 #include <QSettings>
00097 #include <QDateTime>
00098 #include <QProcess>
00099 #include <QCheckBox>
00100 #include <QRegExp>
00101 #include <QScrollArea>
00102
00103 #include <iostream>
00104 #include <cstdio>
00105 #include <errno.h>
00106
00107 using std::cerr;
00108 using std::endl;
00109
00110 using std::vector;
00111 using std::map;
00112 using std::set;
00113
00114
00115 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) :
00116 MainWindowBase(withAudioOutput, withOSCSupport),
00117 m_overview(0),
00118 m_mainMenusCreated(false),
00119 m_paneMenu(0),
00120 m_layerMenu(0),
00121 m_transformsMenu(0),
00122 m_playbackMenu(0),
00123 m_existingLayersMenu(0),
00124 m_sliceMenu(0),
00125 m_recentFilesMenu(0),
00126 m_recentTransformsMenu(0),
00127 m_rightButtonMenu(0),
00128 m_rightButtonLayerMenu(0),
00129 m_rightButtonTransformsMenu(0),
00130 m_rightButtonPlaybackMenu(0),
00131 m_soloAction(0),
00132 m_soloModified(false),
00133 m_prevSolo(false),
00134 m_ffwdAction(0),
00135 m_rwdAction(0),
00136 m_playControlsSpacer(0),
00137 m_playControlsWidth(0),
00138 m_preferencesDialog(0),
00139 m_layerTreeDialog(0),
00140 m_keyReference(new KeyReference())
00141 {
00142 setWindowTitle(tr("Sonic Visualiser"));
00143
00144 UnitDatabase *udb = UnitDatabase::getInstance();
00145 udb->registerUnit("Hz");
00146 udb->registerUnit("dB");
00147 udb->registerUnit("s");
00148
00149 ColourDatabase *cdb = ColourDatabase::getInstance();
00150 cdb->addColour(Qt::black, tr("Black"));
00151 cdb->addColour(Qt::darkRed, tr("Red"));
00152 cdb->addColour(Qt::darkBlue, tr("Blue"));
00153 cdb->addColour(Qt::darkGreen, tr("Green"));
00154 cdb->addColour(QColor(200, 50, 255), tr("Purple"));
00155 cdb->addColour(QColor(255, 150, 50), tr("Orange"));
00156 cdb->setUseDarkBackground(cdb->addColour(Qt::white, tr("White")), true);
00157 cdb->setUseDarkBackground(cdb->addColour(Qt::red, tr("Bright Red")), true);
00158 cdb->setUseDarkBackground(cdb->addColour(QColor(30, 150, 255), tr("Bright Blue")), true);
00159 cdb->setUseDarkBackground(cdb->addColour(Qt::green, tr("Bright Green")), true);
00160 cdb->setUseDarkBackground(cdb->addColour(QColor(225, 74, 255), tr("Bright Purple")), true);
00161 cdb->setUseDarkBackground(cdb->addColour(QColor(255, 188, 80), tr("Bright Orange")), true);
00162
00163 QFrame *frame = new QFrame;
00164 setCentralWidget(frame);
00165
00166 QGridLayout *layout = new QGridLayout;
00167
00168 m_descriptionLabel = new QLabel;
00169
00170 QScrollArea *scroll = new QScrollArea(frame);
00171 scroll->setWidgetResizable(true);
00172 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00173 scroll->setFrameShape(QFrame::NoFrame);
00174
00175 scroll->setWidget(m_paneStack);
00176
00177 m_overview = new Overview(frame);
00178 m_overview->setViewManager(m_viewManager);
00179 m_overview->setFixedHeight(40);
00180 #ifndef _WIN32
00181
00182
00183
00184 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00185 #endif
00186 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
00187 this, SLOT(contextHelpChanged(const QString &)));
00188
00189 m_panLayer = new WaveformLayer;
00190 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
00191 m_panLayer->setAggressiveCacheing(true);
00192 m_overview->addLayer(m_panLayer);
00193
00194 if (m_viewManager->getGlobalDarkBackground()) {
00195 m_panLayer->setBaseColour
00196 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
00197 } else {
00198 m_panLayer->setBaseColour
00199 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
00200 }
00201
00202 m_fader = new Fader(frame, false);
00203 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
00204 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
00205
00206 m_playSpeed = new AudioDial(frame);
00207 m_playSpeed->setMinimum(0);
00208 m_playSpeed->setMaximum(200);
00209 m_playSpeed->setValue(100);
00210 m_playSpeed->setFixedWidth(24);
00211 m_playSpeed->setFixedHeight(24);
00212 m_playSpeed->setNotchesVisible(true);
00213 m_playSpeed->setPageStep(10);
00214 m_playSpeed->setObjectName(tr("Playback Speedup"));
00215 m_playSpeed->setDefaultValue(100);
00216 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
00217 m_playSpeed->setShowToolTip(true);
00218 connect(m_playSpeed, SIGNAL(valueChanged(int)),
00219 this, SLOT(playSpeedChanged(int)));
00220 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
00221 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
00222
00223 IconLoader il;
00224
00225 QSettings settings;
00226 settings.beginGroup("MainWindow");
00227 settings.endGroup();
00228
00229 m_playControlsSpacer = new QFrame;
00230
00231 layout->setSpacing(4);
00232 layout->addWidget(scroll, 0, 0, 1, 5);
00233 layout->addWidget(m_overview, 1, 1);
00234 layout->addWidget(m_playControlsSpacer, 1, 2);
00235 layout->addWidget(m_playSpeed, 1, 3);
00236 layout->addWidget(m_fader, 1, 4);
00237
00238 m_playControlsWidth =
00239 m_fader->width() + m_playSpeed->width() + layout->spacing() * 2;
00240
00241 layout->setColumnMinimumWidth(0, 14);
00242 layout->setColumnStretch(0, 0);
00243
00244 m_paneStack->setPropertyStackMinWidth(m_playControlsWidth
00245 + 2 + layout->spacing());
00246 m_playControlsSpacer->setFixedSize(QSize(2, 2));
00247
00248 layout->setColumnStretch(1, 10);
00249
00250 connect(m_paneStack, SIGNAL(propertyStacksResized(int)),
00251 this, SLOT(propertyStacksResized(int)));
00252
00253 frame->setLayout(layout);
00254
00255 setupMenus();
00256 setupToolbars();
00257 setupHelpMenu();
00258
00259 statusBar();
00260
00261 newSession();
00262 }
00263
00264 MainWindow::~MainWindow()
00265 {
00266 delete m_keyReference;
00267 delete m_preferencesDialog;
00268 delete m_layerTreeDialog;
00269 Profiles::getInstance()->dump();
00270 }
00271
00272 void
00273 MainWindow::setupMenus()
00274 {
00275 if (!m_mainMenusCreated) {
00276 m_rightButtonMenu = new QMenu();
00277
00278
00279
00280
00281
00282
00283
00284
00285 }
00286
00287 if (m_rightButtonLayerMenu) {
00288 m_rightButtonLayerMenu->clear();
00289 } else {
00290 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
00291 m_rightButtonLayerMenu->setTearOffEnabled(true);
00292 m_rightButtonMenu->addSeparator();
00293 }
00294
00295 if (m_rightButtonTransformsMenu) {
00296 m_rightButtonTransformsMenu->clear();
00297 } else {
00298 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
00299 m_rightButtonTransformsMenu->setTearOffEnabled(true);
00300 m_rightButtonMenu->addSeparator();
00301 }
00302
00303 if (!m_mainMenusCreated) {
00304 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
00305 m_rightButtonMenu->addSeparator();
00306 }
00307
00308 setupFileMenu();
00309 setupEditMenu();
00310 setupViewMenu();
00311 setupPaneAndLayerMenus();
00312 setupTransformsMenu();
00313
00314 m_mainMenusCreated = true;
00315 }
00316
00317 void
00318 MainWindow::setupFileMenu()
00319 {
00320 if (m_mainMenusCreated) return;
00321
00322 QMenu *menu = menuBar()->addMenu(tr("&File"));
00323 menu->setTearOffEnabled(true);
00324 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
00325
00326 m_keyReference->setCategory(tr("File and Session Management"));
00327
00328 IconLoader il;
00329
00330 QIcon icon = il.load("filenew");
00331 icon.addPixmap(il.loadPixmap("filenew-22"));
00332 QAction *action = new QAction(icon, tr("&New Session"), this);
00333 action->setShortcut(tr("Ctrl+N"));
00334 action->setStatusTip(tr("Abandon the current Sonic Visualiser session and start a new one"));
00335 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
00336 m_keyReference->registerShortcut(action);
00337 menu->addAction(action);
00338 toolbar->addAction(action);
00339
00340 icon = il.load("fileopensession");
00341 action = new QAction(icon, tr("&Open Session..."), this);
00342 action->setShortcut(tr("Ctrl+O"));
00343 action->setStatusTip(tr("Open a previously saved Sonic Visualiser session file"));
00344 connect(action, SIGNAL(triggered()), this, SLOT(openSession()));
00345 m_keyReference->registerShortcut(action);
00346 menu->addAction(action);
00347
00348 icon = il.load("fileopen");
00349 icon.addPixmap(il.loadPixmap("fileopen-22"));
00350
00351 action = new QAction(icon, tr("&Open..."), this);
00352 action->setStatusTip(tr("Open a session file, audio file, or layer"));
00353 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
00354 toolbar->addAction(action);
00355
00356 icon = il.load("filesave");
00357 icon.addPixmap(il.loadPixmap("filesave-22"));
00358 action = new QAction(icon, tr("&Save Session"), this);
00359 action->setShortcut(tr("Ctrl+S"));
00360 action->setStatusTip(tr("Save the current session into a Sonic Visualiser session file"));
00361 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
00362 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
00363 m_keyReference->registerShortcut(action);
00364 menu->addAction(action);
00365 toolbar->addAction(action);
00366
00367 icon = il.load("filesaveas");
00368 icon.addPixmap(il.loadPixmap("filesaveas-22"));
00369 action = new QAction(icon, tr("Save Session &As..."), this);
00370 action->setStatusTip(tr("Save the current session into a new Sonic Visualiser session file"));
00371 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
00372 menu->addAction(action);
00373 toolbar->addAction(action);
00374
00375 menu->addSeparator();
00376
00377 icon = il.load("fileopenaudio");
00378 action = new QAction(icon, tr("&Import Audio File..."), this);
00379 action->setShortcut(tr("Ctrl+I"));
00380 action->setStatusTip(tr("Import an existing audio file"));
00381 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
00382 m_keyReference->registerShortcut(action);
00383 menu->addAction(action);
00384
00385 action = new QAction(tr("Import Secondary Audio File..."), this);
00386 action->setShortcut(tr("Ctrl+Shift+I"));
00387 action->setStatusTip(tr("Import an extra audio file as a separate layer"));
00388 connect(action, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
00389 connect(this, SIGNAL(canImportMoreAudio(bool)), action, SLOT(setEnabled(bool)));
00390 m_keyReference->registerShortcut(action);
00391 menu->addAction(action);
00392
00393 action = new QAction(tr("&Export Audio File..."), this);
00394 action->setStatusTip(tr("Export selection as an audio file"));
00395 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
00396 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
00397 menu->addAction(action);
00398
00399 menu->addSeparator();
00400
00401 action = new QAction(tr("Import Annotation &Layer..."), this);
00402 action->setShortcut(tr("Ctrl+L"));
00403 action->setStatusTip(tr("Import layer data from an existing file"));
00404 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
00405 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
00406 m_keyReference->registerShortcut(action);
00407 menu->addAction(action);
00408
00409 action = new QAction(tr("Export Annotation Layer..."), this);
00410 action->setStatusTip(tr("Export layer data to a file"));
00411 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
00412 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
00413 menu->addAction(action);
00414
00415 menu->addSeparator();
00416
00417 action = new QAction(tr("Export Image File..."), this);
00418 action->setStatusTip(tr("Export a single pane to an image file"));
00419 connect(action, SIGNAL(triggered()), this, SLOT(exportImage()));
00420 connect(this, SIGNAL(canExportImage(bool)), action, SLOT(setEnabled(bool)));
00421 menu->addAction(action);
00422
00423 menu->addSeparator();
00424
00425 action = new QAction(tr("Open Lo&cation..."), this);
00426 action->setShortcut(tr("Ctrl+Shift+O"));
00427 action->setStatusTip(tr("Open or import a file from a remote URL"));
00428 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
00429 m_keyReference->registerShortcut(action);
00430 menu->addAction(action);
00431
00432 menu->addSeparator();
00433
00434 m_recentFilesMenu = menu->addMenu(tr("&Recent Files"));
00435 m_recentFilesMenu->setTearOffEnabled(true);
00436 setupRecentFilesMenu();
00437 connect(&m_recentFiles, SIGNAL(recentChanged()),
00438 this, SLOT(setupRecentFilesMenu()));
00439
00440 menu->addSeparator();
00441 action = new QAction(tr("&Preferences..."), this);
00442 action->setStatusTip(tr("Adjust the application preferences"));
00443 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
00444 menu->addAction(action);
00445
00446 menu->addSeparator();
00447 action = new QAction(il.load("exit"),
00448 tr("&Quit"), this);
00449 action->setShortcut(tr("Ctrl+Q"));
00450 action->setStatusTip(tr("Exit Sonic Visualiser"));
00451 connect(action, SIGNAL(triggered()), this, SLOT(close()));
00452 m_keyReference->registerShortcut(action);
00453 menu->addAction(action);
00454 }
00455
00456 void
00457 MainWindow::setupEditMenu()
00458 {
00459 if (m_mainMenusCreated) return;
00460
00461 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
00462 menu->setTearOffEnabled(true);
00463 CommandHistory::getInstance()->registerMenu(menu);
00464
00465 m_keyReference->setCategory(tr("Editing"));
00466
00467 menu->addSeparator();
00468
00469 IconLoader il;
00470
00471 QAction *action = new QAction(il.load("editcut"),
00472 tr("Cu&t"), this);
00473 action->setShortcut(tr("Ctrl+X"));
00474 action->setStatusTip(tr("Cut the selection from the current layer to the clipboard"));
00475 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
00476 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
00477 m_keyReference->registerShortcut(action);
00478 menu->addAction(action);
00479 m_rightButtonMenu->addAction(action);
00480
00481 action = new QAction(il.load("editcopy"),
00482 tr("&Copy"), this);
00483 action->setShortcut(tr("Ctrl+C"));
00484 action->setStatusTip(tr("Copy the selection from the current layer to the clipboard"));
00485 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
00486 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
00487 m_keyReference->registerShortcut(action);
00488 menu->addAction(action);
00489 m_rightButtonMenu->addAction(action);
00490
00491 action = new QAction(il.load("editpaste"),
00492 tr("&Paste"), this);
00493 action->setShortcut(tr("Ctrl+V"));
00494 action->setStatusTip(tr("Paste from the clipboard to the current layer"));
00495 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
00496 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
00497 m_keyReference->registerShortcut(action);
00498 menu->addAction(action);
00499 m_rightButtonMenu->addAction(action);
00500
00501 m_deleteSelectedAction = new QAction(tr("&Delete Selected Items"), this);
00502 m_deleteSelectedAction->setShortcut(tr("Del"));
00503 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
00504 connect(m_deleteSelectedAction, SIGNAL(triggered()), this, SLOT(deleteSelected()));
00505 connect(this, SIGNAL(canDeleteSelection(bool)), m_deleteSelectedAction, SLOT(setEnabled(bool)));
00506 m_keyReference->registerShortcut(m_deleteSelectedAction);
00507 menu->addAction(m_deleteSelectedAction);
00508 m_rightButtonMenu->addAction(m_deleteSelectedAction);
00509
00510 menu->addSeparator();
00511 m_rightButtonMenu->addSeparator();
00512
00513 m_keyReference->setCategory(tr("Selection"));
00514
00515 action = new QAction(tr("Select &All"), this);
00516 action->setShortcut(tr("Ctrl+A"));
00517 action->setStatusTip(tr("Select the whole duration of the current session"));
00518 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
00519 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
00520 m_keyReference->registerShortcut(action);
00521 menu->addAction(action);
00522 m_rightButtonMenu->addAction(action);
00523
00524 action = new QAction(tr("Select &Visible Range"), this);
00525 action->setShortcut(tr("Ctrl+Shift+A"));
00526 action->setStatusTip(tr("Select the time range corresponding to the current window width"));
00527 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
00528 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
00529 m_keyReference->registerShortcut(action);
00530 menu->addAction(action);
00531
00532 action = new QAction(tr("Select to &Start"), this);
00533 action->setShortcut(tr("Shift+Left"));
00534 action->setStatusTip(tr("Select from the start of the session to the current playback position"));
00535 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
00536 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
00537 m_keyReference->registerShortcut(action);
00538 menu->addAction(action);
00539
00540 action = new QAction(tr("Select to &End"), this);
00541 action->setShortcut(tr("Shift+Right"));
00542 action->setStatusTip(tr("Select from the current playback position to the end of the session"));
00543 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
00544 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
00545 m_keyReference->registerShortcut(action);
00546 menu->addAction(action);
00547
00548 action = new QAction(tr("C&lear Selection"), this);
00549 action->setShortcut(tr("Esc"));
00550 action->setStatusTip(tr("Clear the selection"));
00551 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
00552 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
00553 m_keyReference->registerShortcut(action);
00554 menu->addAction(action);
00555 m_rightButtonMenu->addAction(action);
00556
00557 menu->addSeparator();
00558
00559 m_keyReference->setCategory(tr("Tapping Time Instants"));
00560
00561 action = new QAction(tr("&Insert Instant at Playback Position"), this);
00562 action->setShortcut(tr("Enter"));
00563 action->setStatusTip(tr("Insert a new time instant at the current playback position, in a new layer if necessary"));
00564 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
00565 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
00566 m_keyReference->registerShortcut(action);
00567 menu->addAction(action);
00568
00569
00570 QString shortcut(tr(";"));
00571 connect(new QShortcut(shortcut, this), SIGNAL(activated()),
00572 this, SLOT(insertInstant()));
00573 m_keyReference->registerAlternativeShortcut(action, shortcut);
00574
00575 action = new QAction(tr("Insert Instants at Selection &Boundaries"), this);
00576 action->setShortcut(tr("Shift+Enter"));
00577 action->setStatusTip(tr("Insert new time instants at the start and end of the current selected regions, in a new layer if necessary"));
00578 connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries()));
00579 connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool)));
00580 m_keyReference->registerShortcut(action);
00581 menu->addAction(action);
00582
00583 QMenu *numberingMenu = menu->addMenu(tr("Number New Instants with"));
00584 numberingMenu->setTearOffEnabled(true);
00585 QActionGroup *numberingGroup = new QActionGroup(this);
00586
00587 Labeller::TypeNameMap types = m_labeller->getTypeNames();
00588 for (Labeller::TypeNameMap::iterator i = types.begin(); i != types.end(); ++i) {
00589
00590 if (i->first == Labeller::ValueFromLabel ||
00591 i->first == Labeller::ValueFromExistingNeighbour) continue;
00592
00593 action = new QAction(i->second, this);
00594 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsNumbering()));
00595 action->setCheckable(true);
00596 action->setChecked(m_labeller->getType() == i->first);
00597 numberingGroup->addAction(action);
00598 numberingMenu->addAction(action);
00599 m_numberingActions[action] = (int)i->first;
00600
00601 if (i->first == Labeller::ValueFromTwoLevelCounter) {
00602
00603 QMenu *cycleMenu = numberingMenu->addMenu(tr("Cycle size"));
00604 QActionGroup *cycleGroup = new QActionGroup(this);
00605
00606 int cycles[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16 };
00607 for (int i = 0; i < int(sizeof(cycles)/sizeof(cycles[0])); ++i) {
00608 action = new QAction(QString("%1").arg(cycles[i]), this);
00609 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsCounterCycle()));
00610 action->setCheckable(true);
00611 action->setChecked(cycles[i] == m_labeller->getCounterCycleSize());
00612 cycleGroup->addAction(action);
00613 cycleMenu->addAction(action);
00614 }
00615 }
00616
00617 if (i->first == Labeller::ValueNone ||
00618 i->first == Labeller::ValueFromTwoLevelCounter ||
00619 i->first == Labeller::ValueFromRealTime) {
00620 numberingMenu->addSeparator();
00621 }
00622 }
00623
00624 action = new QAction(tr("Set Numbering Counters..."), this);
00625 action->setStatusTip(tr("Set the counters used for counter-based labelling"));
00626 connect(action, SIGNAL(triggered()), this, SLOT(resetInstantsCounters()));
00627 menu->addAction(action);
00628
00629 action = new QAction(tr("Renumber Selected Instants"), this);
00630 action->setStatusTip(tr("Renumber the selected instants using the current labelling scheme"));
00631 connect(action, SIGNAL(triggered()), this, SLOT(renumberInstants()));
00632 connect(this, SIGNAL(canRenumberInstants(bool)), action, SLOT(setEnabled(bool)));
00633
00634 menu->addAction(action);
00635 }
00636
00637 void
00638 MainWindow::setupViewMenu()
00639 {
00640 if (m_mainMenusCreated) return;
00641
00642 IconLoader il;
00643
00644 QAction *action = 0;
00645
00646 m_keyReference->setCategory(tr("Panning and Navigation"));
00647
00648 QMenu *menu = menuBar()->addMenu(tr("&View"));
00649 menu->setTearOffEnabled(true);
00650 action = new QAction(tr("Scroll &Left"), this);
00651 action->setShortcut(tr("Left"));
00652 action->setStatusTip(tr("Scroll the current pane to the left"));
00653 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
00654 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
00655 m_keyReference->registerShortcut(action);
00656 menu->addAction(action);
00657
00658 action = new QAction(tr("Scroll &Right"), this);
00659 action->setShortcut(tr("Right"));
00660 action->setStatusTip(tr("Scroll the current pane to the right"));
00661 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
00662 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
00663 m_keyReference->registerShortcut(action);
00664 menu->addAction(action);
00665
00666 action = new QAction(tr("&Jump Left"), this);
00667 action->setShortcut(tr("Ctrl+Left"));
00668 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
00669 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
00670 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
00671 m_keyReference->registerShortcut(action);
00672 menu->addAction(action);
00673
00674 action = new QAction(tr("J&ump Right"), this);
00675 action->setShortcut(tr("Ctrl+Right"));
00676 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
00677 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
00678 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
00679 m_keyReference->registerShortcut(action);
00680 menu->addAction(action);
00681
00682 menu->addSeparator();
00683
00684 m_keyReference->setCategory(tr("Zoom"));
00685
00686 action = new QAction(il.load("zoom-in"),
00687 tr("Zoom &In"), this);
00688 action->setShortcut(tr("Up"));
00689 action->setStatusTip(tr("Increase the zoom level"));
00690 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
00691 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
00692 m_keyReference->registerShortcut(action);
00693 menu->addAction(action);
00694
00695 action = new QAction(il.load("zoom-out"),
00696 tr("Zoom &Out"), this);
00697 action->setShortcut(tr("Down"));
00698 action->setStatusTip(tr("Decrease the zoom level"));
00699 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
00700 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
00701 m_keyReference->registerShortcut(action);
00702 menu->addAction(action);
00703
00704 action = new QAction(tr("Restore &Default Zoom"), this);
00705 action->setStatusTip(tr("Restore the zoom level to the default"));
00706 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
00707 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
00708 menu->addAction(action);
00709
00710 action = new QAction(il.load("zoom-fit"),
00711 tr("Zoom to &Fit"), this);
00712 action->setShortcut(tr("F"));
00713 action->setStatusTip(tr("Zoom to show the whole file"));
00714 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
00715 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
00716 m_keyReference->registerShortcut(action);
00717 menu->addAction(action);
00718
00719 menu->addSeparator();
00720
00721 m_keyReference->setCategory(tr("Display Features"));
00722
00723 QActionGroup *overlayGroup = new QActionGroup(this);
00724
00725 action = new QAction(tr("Show &No Overlays"), this);
00726 action->setShortcut(tr("0"));
00727 action->setStatusTip(tr("Hide centre indicator, frame times, layer names and scale"));
00728 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
00729 action->setCheckable(true);
00730 action->setChecked(false);
00731 overlayGroup->addAction(action);
00732 m_keyReference->registerShortcut(action);
00733 menu->addAction(action);
00734
00735 action = new QAction(tr("Show &Minimal Overlays"), this);
00736 action->setShortcut(tr("9"));
00737 action->setStatusTip(tr("Show centre indicator only"));
00738 connect(action, SIGNAL(triggered()), this, SLOT(showMinimalOverlays()));
00739 action->setCheckable(true);
00740 action->setChecked(false);
00741 overlayGroup->addAction(action);
00742 m_keyReference->registerShortcut(action);
00743 menu->addAction(action);
00744
00745 action = new QAction(tr("Show &Standard Overlays"), this);
00746 action->setShortcut(tr("8"));
00747 action->setStatusTip(tr("Show centre indicator, frame times and scale"));
00748 connect(action, SIGNAL(triggered()), this, SLOT(showStandardOverlays()));
00749 action->setCheckable(true);
00750 action->setChecked(true);
00751 overlayGroup->addAction(action);
00752 m_keyReference->registerShortcut(action);
00753 menu->addAction(action);
00754
00755 action = new QAction(tr("Show &All Overlays"), this);
00756 action->setShortcut(tr("7"));
00757 action->setStatusTip(tr("Show all texts and scale"));
00758 connect(action, SIGNAL(triggered()), this, SLOT(showAllOverlays()));
00759 action->setCheckable(true);
00760 action->setChecked(false);
00761 overlayGroup->addAction(action);
00762 m_keyReference->registerShortcut(action);
00763 menu->addAction(action);
00764
00765 menu->addSeparator();
00766
00767 action = new QAction(tr("Show &Zoom Wheels"), this);
00768 action->setShortcut(tr("Z"));
00769 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
00770 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
00771 action->setCheckable(true);
00772 action->setChecked(m_viewManager->getZoomWheelsEnabled());
00773 m_keyReference->registerShortcut(action);
00774 menu->addAction(action);
00775
00776 action = new QAction(tr("Show Property Bo&xes"), this);
00777 action->setShortcut(tr("X"));
00778 action->setStatusTip(tr("Show the layer property boxes at the side of the main window"));
00779 connect(action, SIGNAL(triggered()), this, SLOT(togglePropertyBoxes()));
00780 action->setCheckable(true);
00781 action->setChecked(true);
00782 m_keyReference->registerShortcut(action);
00783 menu->addAction(action);
00784
00785 action = new QAction(tr("Show Status &Bar"), this);
00786 action->setStatusTip(tr("Show context help information in the status bar at the bottom of the window"));
00787 connect(action, SIGNAL(triggered()), this, SLOT(toggleStatusBar()));
00788 action->setCheckable(true);
00789 action->setChecked(true);
00790 menu->addAction(action);
00791
00792 QSettings settings;
00793 settings.beginGroup("MainWindow");
00794 bool sb = settings.value("showstatusbar", true).toBool();
00795 if (!sb) {
00796 action->setChecked(false);
00797 statusBar()->hide();
00798 }
00799 settings.endGroup();
00800
00801 menu->addSeparator();
00802
00803 action = new QAction(tr("Show La&yer Summary"), this);
00804 action->setShortcut(tr("Y"));
00805 action->setStatusTip(tr("Open a window displaying the hierarchy of panes and layers in this session"));
00806 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
00807 m_keyReference->registerShortcut(action);
00808 menu->addAction(action);
00809 }
00810
00811 void
00812 MainWindow::setupPaneAndLayerMenus()
00813 {
00814 if (m_paneMenu) {
00815 m_paneActions.clear();
00816 m_paneMenu->clear();
00817 } else {
00818 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
00819 m_paneMenu->setTearOffEnabled(true);
00820 }
00821
00822 if (m_layerMenu) {
00823 m_layerActions.clear();
00824 m_layerMenu->clear();
00825 } else {
00826 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
00827 m_layerMenu->setTearOffEnabled(true);
00828 }
00829
00830 QMenu *menu = m_paneMenu;
00831
00832 IconLoader il;
00833
00834 m_keyReference->setCategory(tr("Managing Panes and Layers"));
00835
00836 QAction *action = new QAction(il.load("pane"), tr("Add &New Pane"), this);
00837 action->setShortcut(tr("N"));
00838 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
00839 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
00840 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
00841 m_paneActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
00842 m_keyReference->registerShortcut(action);
00843 menu->addAction(action);
00844
00845 menu->addSeparator();
00846
00847 menu = m_layerMenu;
00848
00849
00850
00851 LayerFactory::LayerTypeSet emptyLayerTypes =
00852 LayerFactory::getInstance()->getValidEmptyLayerTypes();
00853
00854 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
00855 i != emptyLayerTypes.end(); ++i) {
00856
00857 QIcon icon;
00858 QString mainText, tipText, channelText;
00859 LayerFactory::LayerType type = *i;
00860 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
00861
00862 icon = il.load(LayerFactory::getInstance()->getLayerIconName(type));
00863
00864 mainText = tr("Add New %1 Layer").arg(name);
00865 tipText = tr("Add a new empty layer of type %1").arg(name);
00866
00867 action = new QAction(icon, mainText, this);
00868 action->setStatusTip(tipText);
00869
00870 if (type == LayerFactory::Text) {
00871 action->setShortcut(tr("T"));
00872 m_keyReference->registerShortcut(action);
00873 }
00874
00875 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
00876 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
00877 m_layerActions[action] = LayerConfiguration(type);
00878 menu->addAction(action);
00879 m_rightButtonLayerMenu->addAction(action);
00880 }
00881
00882 m_rightButtonLayerMenu->addSeparator();
00883 menu->addSeparator();
00884
00885 LayerFactory::LayerType backgroundTypes[] = {
00886 LayerFactory::Waveform,
00887 LayerFactory::Spectrogram,
00888 LayerFactory::MelodicRangeSpectrogram,
00889 LayerFactory::PeakFrequencySpectrogram,
00890 LayerFactory::Spectrum
00891 };
00892
00893 std::vector<Model *> models;
00894 if (m_document) models = m_document->getTransformInputModels();
00895 bool plural = (models.size() > 1);
00896 if (models.empty()) {
00897 models.push_back(getMainModel());
00898 }
00899
00900 for (unsigned int i = 0;
00901 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
00902
00903 const int paneMenuType = 0, layerMenuType = 1;
00904
00905 for (int menuType = paneMenuType; menuType <= layerMenuType; ++menuType) {
00906
00907 if (menuType == paneMenuType) menu = m_paneMenu;
00908 else menu = m_layerMenu;
00909
00910 QMenu *submenu = 0;
00911
00912 QIcon icon;
00913 QString mainText, shortcutText, tipText, channelText;
00914 LayerFactory::LayerType type = backgroundTypes[i];
00915 bool mono = true;
00916
00917 switch (type) {
00918
00919 case LayerFactory::Waveform:
00920 icon = il.load("waveform");
00921 mainText = tr("Add &Waveform");
00922 if (menuType == paneMenuType) {
00923 shortcutText = tr("W");
00924 tipText = tr("Add a new pane showing a waveform view");
00925 } else {
00926 tipText = tr("Add a new layer showing a waveform view");
00927 }
00928 mono = false;
00929 break;
00930
00931 case LayerFactory::Spectrogram:
00932 icon = il.load("spectrogram");
00933 mainText = tr("Add Spectro&gram");
00934 if (menuType == paneMenuType) {
00935 shortcutText = tr("G");
00936 tipText = tr("Add a new pane showing a spectrogram");
00937 } else {
00938 tipText = tr("Add a new layer showing a spectrogram");
00939 }
00940 break;
00941
00942 case LayerFactory::MelodicRangeSpectrogram:
00943 icon = il.load("spectrogram");
00944 mainText = tr("Add &Melodic Range Spectrogram");
00945 if (menuType == paneMenuType) {
00946 shortcutText = tr("M");
00947 tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches");
00948 } else {
00949 tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches");
00950 }
00951 break;
00952
00953 case LayerFactory::PeakFrequencySpectrogram:
00954 icon = il.load("spectrogram");
00955 mainText = tr("Add Pea&k Frequency Spectrogram");
00956 if (menuType == paneMenuType) {
00957 shortcutText = tr("K");
00958 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
00959 } else {
00960 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
00961 }
00962 break;
00963
00964 case LayerFactory::Spectrum:
00965 icon = il.load("spectrum");
00966 mainText = tr("Add Spectr&um");
00967 if (menuType == paneMenuType) {
00968 shortcutText = tr("U");
00969 tipText = tr("Add a new pane showing a frequency spectrum");
00970 } else {
00971 tipText = tr("Add a new layer showing a frequency spectrum");
00972 }
00973 break;
00974
00975 default: break;
00976 }
00977
00978 std::vector<Model *> candidateModels;
00979
00980 candidateModels = models;
00981
00982
00983
00984
00985 for (std::vector<Model *>::iterator mi =
00986 candidateModels.begin();
00987 mi != candidateModels.end(); ++mi) {
00988
00989 Model *model = *mi;
00990
00991 int channels = 0;
00992 if (model) {
00993 DenseTimeValueModel *dtvm =
00994 dynamic_cast<DenseTimeValueModel *>(model);
00995 if (dtvm) channels = dtvm->getChannelCount();
00996 }
00997 if (channels < 1 && getMainModel()) {
00998 channels = getMainModel()->getChannelCount();
00999 }
01000 if (channels < 1) channels = 1;
01001
01002 for (int c = 0; c <= channels; ++c) {
01003
01004 if (c == 1 && channels == 1) continue;
01005 bool isDefault = (c == 0);
01006 bool isOnly = (isDefault && (channels == 1));
01007
01008
01009
01010
01011
01012
01013 if (isOnly && (!plural )) {
01014
01015
01016
01017
01018 action = new QAction(icon, mainText, this);
01019
01020
01021 action->setShortcut(shortcutText);
01022 action->setStatusTip(tipText);
01023 if (menuType == paneMenuType) {
01024 connect(action, SIGNAL(triggered()),
01025 this, SLOT(addPane()));
01026 connect(this, SIGNAL(canAddPane(bool)),
01027 action, SLOT(setEnabled(bool)));
01028 m_paneActions[action] = LayerConfiguration(type);
01029 } else {
01030 connect(action, SIGNAL(triggered()),
01031 this, SLOT(addLayer()));
01032 connect(this, SIGNAL(canAddLayer(bool)),
01033 action, SLOT(setEnabled(bool)));
01034 m_layerActions[action] = LayerConfiguration(type);
01035 }
01036 if (shortcutText != "") {
01037 m_keyReference->registerShortcut(action);
01038 }
01039 menu->addAction(action);
01040
01041 } else {
01042
01043 if (!submenu) {
01044 submenu = menu->addMenu(mainText);
01045 submenu->setTearOffEnabled(true);
01046 } else if (isDefault) {
01047 submenu->addSeparator();
01048 }
01049
01050 QString actionText;
01051 if (c == 0) {
01052 if (mono) {
01053 actionText = tr("&All Channels Mixed");
01054 } else {
01055 actionText = tr("&All Channels");
01056 }
01057 } else {
01058 actionText = tr("Channel &%1").arg(c);
01059 }
01060
01061 if (model) {
01062 actionText = tr("%1: %2")
01063 .arg(model->objectName())
01064 .arg(actionText);
01065 }
01066
01067 if (isDefault) {
01068 action = new QAction(icon, actionText, this);
01069 if (!model || model == getMainModel()) {
01070 action->setShortcut(shortcutText);
01071 }
01072 } else {
01073 action = new QAction(actionText, this);
01074 }
01075
01076 action->setStatusTip(tipText);
01077
01078 if (menuType == paneMenuType) {
01079 connect(action, SIGNAL(triggered()),
01080 this, SLOT(addPane()));
01081 connect(this, SIGNAL(canAddPane(bool)),
01082 action, SLOT(setEnabled(bool)));
01083 m_paneActions[action] =
01084 LayerConfiguration(type, model, c - 1);
01085 } else {
01086 connect(action, SIGNAL(triggered()),
01087 this, SLOT(addLayer()));
01088 connect(this, SIGNAL(canAddLayer(bool)),
01089 action, SLOT(setEnabled(bool)));
01090 m_layerActions[action] =
01091 LayerConfiguration(type, model, c - 1);
01092 }
01093
01094 submenu->addAction(action);
01095 }
01096 }
01097 }
01098 }
01099 }
01100
01101 menu = m_paneMenu;
01102 menu->addSeparator();
01103
01104 action = new QAction(tr("Switch to Previous Pane"), this);
01105 action->setShortcut(tr("["));
01106 action->setStatusTip(tr("Make the next pane up in the pane stack current"));
01107 connect(action, SIGNAL(triggered()), this, SLOT(previousPane()));
01108 connect(this, SIGNAL(canSelectPreviousPane(bool)), action, SLOT(setEnabled(bool)));
01109 m_keyReference->registerShortcut(action);
01110 menu->addAction(action);
01111
01112 action = new QAction(tr("Switch to Next Pane"), this);
01113 action->setShortcut(tr("]"));
01114 action->setStatusTip(tr("Make the next pane down in the pane stack current"));
01115 connect(action, SIGNAL(triggered()), this, SLOT(nextPane()));
01116 connect(this, SIGNAL(canSelectNextPane(bool)), action, SLOT(setEnabled(bool)));
01117 m_keyReference->registerShortcut(action);
01118 menu->addAction(action);
01119
01120 menu->addSeparator();
01121
01122 action = new QAction(il.load("editdelete"), tr("&Delete Pane"), this);
01123 action->setShortcut(tr("Ctrl+Shift+D"));
01124 action->setStatusTip(tr("Delete the currently active pane"));
01125 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
01126 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
01127 m_keyReference->registerShortcut(action);
01128 menu->addAction(action);
01129
01130 menu = m_layerMenu;
01131
01132 action = new QAction(il.load("timeruler"), tr("Add &Time Ruler"), this);
01133 action->setStatusTip(tr("Add a new layer showing a time ruler"));
01134 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
01135 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
01136 m_layerActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
01137 menu->addAction(action);
01138
01139 menu->addSeparator();
01140
01141 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
01142 m_existingLayersMenu->setTearOffEnabled(true);
01143 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
01144
01145 m_sliceMenu = menu->addMenu(tr("Add S&lice of Layer"));
01146 m_sliceMenu->setTearOffEnabled(true);
01147 m_rightButtonLayerMenu->addMenu(m_sliceMenu);
01148
01149 setupExistingLayersMenus();
01150
01170 m_rightButtonLayerMenu->addSeparator();
01171 menu->addSeparator();
01172
01173 QAction *raction = new QAction(tr("&Rename Layer..."), this);
01174 raction->setShortcut(tr("R"));
01175 raction->setStatusTip(tr("Rename the currently active layer"));
01176 connect(raction, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
01177 connect(this, SIGNAL(canRenameLayer(bool)), raction, SLOT(setEnabled(bool)));
01178 menu->addAction(raction);
01179 m_rightButtonLayerMenu->addAction(raction);
01180
01181 action = new QAction(il.load("editdelete"), tr("&Delete Layer"), this);
01182 action->setShortcut(tr("Ctrl+D"));
01183 action->setStatusTip(tr("Delete the currently active layer"));
01184 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
01185 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
01186 m_keyReference->registerShortcut(action);
01187 menu->addAction(action);
01188 m_rightButtonLayerMenu->addAction(action);
01189
01190 m_keyReference->registerShortcut(raction);
01191 }
01192
01193 void
01194 MainWindow::setupTransformsMenu()
01195 {
01196 if (m_transformsMenu) {
01197 m_transformActions.clear();
01198 m_transformActionsReverse.clear();
01199 m_transformsMenu->clear();
01200 } else {
01201 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
01202 m_transformsMenu->setTearOffEnabled(true);
01203 }
01204
01205 TransformList transforms =
01206 TransformFactory::getInstance()->getAllTransformDescriptions();
01207
01208 vector<QString> types =
01209 TransformFactory::getInstance()->getAllTransformTypes();
01210
01211 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
01212 map<QString, map<QString, SubdividingMenu *> > makerMenus;
01213
01214 map<QString, SubdividingMenu *> byPluginNameMenus;
01215 map<QString, map<QString, QMenu *> > pluginNameMenus;
01216
01217 set<SubdividingMenu *> pendingMenus;
01218
01219 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
01220 m_recentTransformsMenu->setTearOffEnabled(true);
01221 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
01222 connect(&m_recentTransforms, SIGNAL(recentChanged()),
01223 this, SLOT(setupRecentTransformsMenu()));
01224
01225 m_transformsMenu->addSeparator();
01226 m_rightButtonTransformsMenu->addSeparator();
01227
01228 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
01229
01230 if (i != types.begin()) {
01231 m_transformsMenu->addSeparator();
01232 m_rightButtonTransformsMenu->addSeparator();
01233 }
01234
01235 QString byCategoryLabel = tr("%1 by Category").arg(*i);
01236 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
01237 20, 40);
01238 byCategoryMenu->setTearOffEnabled(true);
01239 m_transformsMenu->addMenu(byCategoryMenu);
01240 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
01241 pendingMenus.insert(byCategoryMenu);
01242
01243 vector<QString> categories =
01244 TransformFactory::getInstance()->getTransformCategories(*i);
01245
01246 for (vector<QString>::iterator j = categories.begin();
01247 j != categories.end(); ++j) {
01248
01249 QString category = *j;
01250 if (category == "") category = tr("Unclassified");
01251
01252 if (categories.size() < 2) {
01253 categoryMenus[*i][category] = byCategoryMenu;
01254 continue;
01255 }
01256
01257 QStringList components = category.split(" > ");
01258 QString key;
01259
01260 for (QStringList::iterator k = components.begin();
01261 k != components.end(); ++k) {
01262
01263 QString parentKey = key;
01264 if (key != "") key += " > ";
01265 key += *k;
01266
01267 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
01268 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
01269 m->setTearOffEnabled(true);
01270 pendingMenus.insert(m);
01271 categoryMenus[*i][key] = m;
01272 if (parentKey == "") {
01273 byCategoryMenu->addMenu(m);
01274 } else {
01275 categoryMenus[*i][parentKey]->addMenu(m);
01276 }
01277 }
01278 }
01279 }
01280
01281 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
01282 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
01283 byPluginNameMenus[*i]->setTearOffEnabled(true);
01284 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
01285 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
01286 pendingMenus.insert(byPluginNameMenus[*i]);
01287
01288 QString byMakerLabel = tr("%1 by Maker").arg(*i);
01289 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
01290 byMakerMenu->setTearOffEnabled(true);
01291 m_transformsMenu->addMenu(byMakerMenu);
01292 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
01293 pendingMenus.insert(byMakerMenu);
01294
01295 vector<QString> makers =
01296 TransformFactory::getInstance()->getTransformMakers(*i);
01297
01298 for (vector<QString>::iterator j = makers.begin();
01299 j != makers.end(); ++j) {
01300
01301 QString maker = *j;
01302 if (maker == "") maker = tr("Unknown");
01303 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
01304
01305 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
01306 makerMenus[*i][maker]->setTearOffEnabled(true);
01307 byMakerMenu->addMenu(makerMenus[*i][maker]);
01308 pendingMenus.insert(makerMenus[*i][maker]);
01309 }
01310 }
01311
01312
01313
01314
01315 std::map<QString, QString> idNameSonameMap;
01316 std::set<QString> seenNames, duplicateNames;
01317 for (unsigned int i = 0; i < transforms.size(); ++i) {
01318 QString name = transforms[i].name;
01319 if (seenNames.find(name) != seenNames.end()) {
01320 duplicateNames.insert(name);
01321 } else {
01322 seenNames.insert(name);
01323 }
01324 }
01325
01326 for (unsigned int i = 0; i < transforms.size(); ++i) {
01327
01328 QString name = transforms[i].name;
01329 if (name == "") name = transforms[i].identifier;
01330
01331
01332
01333 QString type = transforms[i].type;
01334
01335 QString category = transforms[i].category;
01336 if (category == "") category = tr("Unclassified");
01337
01338 QString maker = transforms[i].maker;
01339 if (maker == "") maker = tr("Unknown");
01340 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
01341
01342 QString pluginName = name.section(": ", 0, 0);
01343 QString output = name.section(": ", 1);
01344
01345 if (duplicateNames.find(pluginName) != duplicateNames.end()) {
01346 pluginName = QString("%1 <%2>")
01347 .arg(pluginName)
01348 .arg(transforms[i].identifier.section(':', 1, 1));
01349 if (output == "") name = pluginName;
01350 else name = QString("%1: %2")
01351 .arg(pluginName)
01352 .arg(output);
01353 }
01354
01355 QAction *action = new QAction(tr("%1...").arg(name), this);
01356 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
01357 m_transformActions[action] = transforms[i].identifier;
01358 m_transformActionsReverse[transforms[i].identifier] = action;
01359 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
01360
01361 action->setStatusTip(transforms[i].description);
01362
01363 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
01364 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
01365 << "No category menu for transform \""
01366 << name.toStdString() << "\" (category = \""
01367 << category.toStdString() << "\")" << std::endl;
01368 } else {
01369 categoryMenus[type][category]->addAction(action);
01370 }
01371
01372 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
01373 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
01374 << "No maker menu for transform \""
01375 << name.toStdString() << "\" (maker = \""
01376 << maker.toStdString() << "\")" << std::endl;
01377 } else {
01378 makerMenus[type][maker]->addAction(action);
01379 }
01380
01381 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
01382 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
01383 m_transformActions[action] = transforms[i].identifier;
01384 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
01385 action->setStatusTip(transforms[i].description);
01386
01387
01388
01389 if (pluginNameMenus[type].find(pluginName) ==
01390 pluginNameMenus[type].end()) {
01391
01392 SubdividingMenu *parentMenu = byPluginNameMenus[type];
01393 parentMenu->setTearOffEnabled(true);
01394
01395 if (output == "") {
01396 parentMenu->addAction(pluginName, action);
01397 } else {
01398 pluginNameMenus[type][pluginName] =
01399 parentMenu->addMenu(pluginName);
01400 connect(this, SIGNAL(canAddLayer(bool)),
01401 pluginNameMenus[type][pluginName],
01402 SLOT(setEnabled(bool)));
01403 }
01404 }
01405
01406 if (pluginNameMenus[type].find(pluginName) !=
01407 pluginNameMenus[type].end()) {
01408 pluginNameMenus[type][pluginName]->addAction(action);
01409 }
01410 }
01411
01412 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
01413 i != pendingMenus.end(); ++i) {
01414 (*i)->entriesAdded();
01415 }
01416
01417 setupRecentTransformsMenu();
01418 }
01419
01420 void
01421 MainWindow::setupHelpMenu()
01422 {
01423 QMenu *menu = menuBar()->addMenu(tr("&Help"));
01424 menu->setTearOffEnabled(true);
01425
01426 m_keyReference->setCategory(tr("Help"));
01427
01428 IconLoader il;
01429
01430 QAction *action = new QAction(il.load("help"),
01431 tr("&Help Reference"), this);
01432 action->setShortcut(tr("F1"));
01433 action->setStatusTip(tr("Open the Sonic Visualiser reference manual"));
01434 connect(action, SIGNAL(triggered()), this, SLOT(help()));
01435 m_keyReference->registerShortcut(action);
01436 menu->addAction(action);
01437
01438 action = new QAction(tr("&Key and Mouse Reference"), this);
01439 action->setShortcut(tr("F2"));
01440 action->setStatusTip(tr("Open a window showing the keystrokes you can use in Sonic Visualiser"));
01441 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
01442 m_keyReference->registerShortcut(action);
01443 menu->addAction(action);
01444
01445 action = new QAction(tr("Sonic Visualiser on the &Web"), this);
01446 action->setStatusTip(tr("Open the Sonic Visualiser website"));
01447 connect(action, SIGNAL(triggered()), this, SLOT(website()));
01448 menu->addAction(action);
01449
01450 action = new QAction(tr("&About Sonic Visualiser"), this);
01451 action->setStatusTip(tr("Show information about Sonic Visualiser"));
01452 connect(action, SIGNAL(triggered()), this, SLOT(about()));
01453 menu->addAction(action);
01454 }
01455
01456 void
01457 MainWindow::setupRecentFilesMenu()
01458 {
01459 m_recentFilesMenu->clear();
01460 vector<QString> files = m_recentFiles.getRecent();
01461 for (size_t i = 0; i < files.size(); ++i) {
01462 QAction *action = new QAction(files[i], this);
01463 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
01464 if (i == 0) {
01465 action->setShortcut(tr("Ctrl+R"));
01466 m_keyReference->registerShortcut
01467 (tr("Re-open"),
01468 action->shortcut(),
01469 tr("Re-open the current or most recently opened file"));
01470 }
01471 m_recentFilesMenu->addAction(action);
01472 }
01473 }
01474
01475 void
01476 MainWindow::setupRecentTransformsMenu()
01477 {
01478 m_recentTransformsMenu->clear();
01479 vector<QString> transforms = m_recentTransforms.getRecent();
01480 for (size_t i = 0; i < transforms.size(); ++i) {
01481 TransformActionReverseMap::iterator ti =
01482 m_transformActionsReverse.find(transforms[i]);
01483 if (ti == m_transformActionsReverse.end()) {
01484 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
01485 << "Unknown transform \"" << transforms[i].toStdString()
01486 << "\" in recent transforms list" << std::endl;
01487 continue;
01488 }
01489 if (i == 0) {
01490 ti->second->setShortcut(tr("Ctrl+T"));
01491 m_keyReference->registerShortcut
01492 (tr("Repeat Transform"),
01493 ti->second->shortcut(),
01494 tr("Re-select the most recently run transform"));
01495 } else {
01496 ti->second->setShortcut(QString(""));
01497 }
01498 m_recentTransformsMenu->addAction(ti->second);
01499 }
01500 }
01501
01502 void
01503 MainWindow::setupExistingLayersMenus()
01504 {
01505 if (!m_existingLayersMenu) return;
01506
01507
01508
01509 m_existingLayersMenu->clear();
01510 m_existingLayerActions.clear();
01511
01512 m_sliceMenu->clear();
01513 m_sliceActions.clear();
01514
01515 IconLoader il;
01516
01517 vector<Layer *> orderedLayers;
01518 set<Layer *> observedLayers;
01519 set<Layer *> sliceableLayers;
01520
01521 LayerFactory *factory = LayerFactory::getInstance();
01522
01523 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
01524
01525 Pane *pane = m_paneStack->getPane(i);
01526 if (!pane) continue;
01527
01528 for (int j = 0; j < pane->getLayerCount(); ++j) {
01529
01530 Layer *layer = pane->getLayer(j);
01531 if (!layer) continue;
01532 if (observedLayers.find(layer) != observedLayers.end()) {
01533
01534 continue;
01535 }
01536
01537
01538
01539
01540 orderedLayers.push_back(layer);
01541 observedLayers.insert(layer);
01542
01543 if (factory->isLayerSliceable(layer)) {
01544 sliceableLayers.insert(layer);
01545 }
01546 }
01547 }
01548
01549 map<QString, int> observedNames;
01550
01551 for (size_t i = 0; i < orderedLayers.size(); ++i) {
01552
01553 Layer *layer = orderedLayers[i];
01554
01555 QString name = layer->getLayerPresentationName();
01556 int n = ++observedNames[name];
01557 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
01558
01559 QIcon icon = il.load(factory->getLayerIconName
01560 (factory->getLayerType(layer)));
01561
01562 QAction *action = new QAction(icon, name, this);
01563 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
01564 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
01565 m_existingLayerActions[action] = layer;
01566
01567 m_existingLayersMenu->addAction(action);
01568
01569 if (sliceableLayers.find(layer) != sliceableLayers.end()) {
01570 action = new QAction(icon, name, this);
01571 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
01572 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
01573 m_sliceActions[action] = layer;
01574 m_sliceMenu->addAction(action);
01575 }
01576 }
01577
01578 m_sliceMenu->setEnabled(!m_sliceActions.empty());
01579 }
01580
01581 void
01582 MainWindow::setupToolbars()
01583 {
01584 m_keyReference->setCategory(tr("Playback and Transport Controls"));
01585
01586 IconLoader il;
01587
01588 QMenu *menu = m_playbackMenu = menuBar()->addMenu(tr("Play&back"));
01589 menu->setTearOffEnabled(true);
01590 m_rightButtonMenu->addSeparator();
01591 m_rightButtonPlaybackMenu = m_rightButtonMenu->addMenu(tr("Playback"));
01592
01593 QToolBar *toolbar = addToolBar(tr("Playback Toolbar"));
01594
01595 QAction *rwdStartAction = toolbar->addAction(il.load("rewind-start"),
01596 tr("Rewind to Start"));
01597 rwdStartAction->setShortcut(tr("Home"));
01598 rwdStartAction->setStatusTip(tr("Rewind to the start"));
01599 connect(rwdStartAction, SIGNAL(triggered()), this, SLOT(rewindStart()));
01600 connect(this, SIGNAL(canPlay(bool)), rwdStartAction, SLOT(setEnabled(bool)));
01601
01602 QAction *m_rwdAction = toolbar->addAction(il.load("rewind"),
01603 tr("Rewind"));
01604 m_rwdAction->setShortcut(tr("PgUp"));
01605 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant or time ruler notch"));
01606 connect(m_rwdAction, SIGNAL(triggered()), this, SLOT(rewind()));
01607 connect(this, SIGNAL(canRewind(bool)), m_rwdAction, SLOT(setEnabled(bool)));
01608
01609 QAction *playAction = toolbar->addAction(il.load("playpause"),
01610 tr("Play / Pause"));
01611 playAction->setCheckable(true);
01612 playAction->setShortcut(tr("Space"));
01613 playAction->setStatusTip(tr("Start or stop playback from the current position"));
01614 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
01615 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
01616 playAction, SLOT(setChecked(bool)));
01617 connect(this, SIGNAL(canPlay(bool)), playAction, SLOT(setEnabled(bool)));
01618
01619 m_ffwdAction = toolbar->addAction(il.load("ffwd"),
01620 tr("Fast Forward"));
01621 m_ffwdAction->setShortcut(tr("PgDown"));
01622 m_ffwdAction->setStatusTip(tr("Fast-forward to the next time instant or time ruler notch"));
01623 connect(m_ffwdAction, SIGNAL(triggered()), this, SLOT(ffwd()));
01624 connect(this, SIGNAL(canFfwd(bool)), m_ffwdAction, SLOT(setEnabled(bool)));
01625
01626 QAction *ffwdEndAction = toolbar->addAction(il.load("ffwd-end"),
01627 tr("Fast Forward to End"));
01628 ffwdEndAction->setShortcut(tr("End"));
01629 ffwdEndAction->setStatusTip(tr("Fast-forward to the end"));
01630 connect(ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
01631 connect(this, SIGNAL(canPlay(bool)), ffwdEndAction, SLOT(setEnabled(bool)));
01632
01633 toolbar = addToolBar(tr("Play Mode Toolbar"));
01634
01635 QAction *psAction = toolbar->addAction(il.load("playselection"),
01636 tr("Constrain Playback to Selection"));
01637 psAction->setCheckable(true);
01638 psAction->setChecked(m_viewManager->getPlaySelectionMode());
01639 psAction->setShortcut(tr("s"));
01640 psAction->setStatusTip(tr("Constrain playback to the selected regions"));
01641 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
01642 psAction, SLOT(setChecked(bool)));
01643 connect(psAction, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
01644 connect(this, SIGNAL(canPlaySelection(bool)), psAction, SLOT(setEnabled(bool)));
01645
01646 QAction *plAction = toolbar->addAction(il.load("playloop"),
01647 tr("Loop Playback"));
01648 plAction->setCheckable(true);
01649 plAction->setChecked(m_viewManager->getPlayLoopMode());
01650 plAction->setShortcut(tr("l"));
01651 plAction->setStatusTip(tr("Loop playback"));
01652 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
01653 plAction, SLOT(setChecked(bool)));
01654 connect(plAction, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
01655 connect(this, SIGNAL(canPlay(bool)), plAction, SLOT(setEnabled(bool)));
01656
01657 m_soloAction = toolbar->addAction(il.load("solo"),
01658 tr("Solo Current Pane"));
01659 m_soloAction->setCheckable(true);
01660 m_soloAction->setChecked(m_viewManager->getPlaySoloMode());
01661 m_prevSolo = m_viewManager->getPlaySoloMode();
01662 m_soloAction->setShortcut(tr("o"));
01663 m_soloAction->setStatusTip(tr("Solo the current pane during playback"));
01664 connect(m_viewManager, SIGNAL(playSoloModeChanged(bool)),
01665 m_soloAction, SLOT(setChecked(bool)));
01666 connect(m_soloAction, SIGNAL(triggered()), this, SLOT(playSoloToggled()));
01667 connect(this, SIGNAL(canChangeSolo(bool)), m_soloAction, SLOT(setEnabled(bool)));
01668
01669 QAction *alAction = 0;
01670 if (Document::canAlign()) {
01671 alAction = toolbar->addAction(il.load("align"),
01672 tr("Align File Timelines"));
01673 alAction->setCheckable(true);
01674 alAction->setChecked(m_viewManager->getAlignMode());
01675 alAction->setStatusTip(tr("Treat multiple audio files as versions of the same work, and align their timelines"));
01676 connect(m_viewManager, SIGNAL(alignModeChanged(bool)),
01677 alAction, SLOT(setChecked(bool)));
01678 connect(alAction, SIGNAL(triggered()), this, SLOT(alignToggled()));
01679 connect(this, SIGNAL(canAlign(bool)), alAction, SLOT(setEnabled(bool)));
01680 }
01681
01682 m_keyReference->registerShortcut(playAction);
01683 m_keyReference->registerShortcut(psAction);
01684 m_keyReference->registerShortcut(plAction);
01685 m_keyReference->registerShortcut(m_soloAction);
01686 if (alAction) m_keyReference->registerShortcut(alAction);
01687 m_keyReference->registerShortcut(m_rwdAction);
01688 m_keyReference->registerShortcut(m_ffwdAction);
01689 m_keyReference->registerShortcut(rwdStartAction);
01690 m_keyReference->registerShortcut(ffwdEndAction);
01691
01692 menu->addAction(playAction);
01693 menu->addAction(psAction);
01694 menu->addAction(plAction);
01695 menu->addAction(m_soloAction);
01696 if (alAction) menu->addAction(alAction);
01697 menu->addSeparator();
01698 menu->addAction(m_rwdAction);
01699 menu->addAction(m_ffwdAction);
01700 menu->addSeparator();
01701 menu->addAction(rwdStartAction);
01702 menu->addAction(ffwdEndAction);
01703 menu->addSeparator();
01704
01705 m_rightButtonPlaybackMenu->addAction(playAction);
01706 m_rightButtonPlaybackMenu->addAction(psAction);
01707 m_rightButtonPlaybackMenu->addAction(plAction);
01708 m_rightButtonPlaybackMenu->addAction(m_soloAction);
01709 if (alAction) m_rightButtonPlaybackMenu->addAction(alAction);
01710 m_rightButtonPlaybackMenu->addSeparator();
01711 m_rightButtonPlaybackMenu->addAction(m_rwdAction);
01712 m_rightButtonPlaybackMenu->addAction(m_ffwdAction);
01713 m_rightButtonPlaybackMenu->addSeparator();
01714 m_rightButtonPlaybackMenu->addAction(rwdStartAction);
01715 m_rightButtonPlaybackMenu->addAction(ffwdEndAction);
01716 m_rightButtonPlaybackMenu->addSeparator();
01717
01718 QAction *fastAction = menu->addAction(tr("Speed Up"));
01719 fastAction->setShortcut(tr("Ctrl+PgUp"));
01720 fastAction->setStatusTip(tr("Time-stretch playback to speed it up without changing pitch"));
01721 connect(fastAction, SIGNAL(triggered()), this, SLOT(speedUpPlayback()));
01722 connect(this, SIGNAL(canSpeedUpPlayback(bool)), fastAction, SLOT(setEnabled(bool)));
01723
01724 QAction *slowAction = menu->addAction(tr("Slow Down"));
01725 slowAction->setShortcut(tr("Ctrl+PgDown"));
01726 slowAction->setStatusTip(tr("Time-stretch playback to slow it down without changing pitch"));
01727 connect(slowAction, SIGNAL(triggered()), this, SLOT(slowDownPlayback()));
01728 connect(this, SIGNAL(canSlowDownPlayback(bool)), slowAction, SLOT(setEnabled(bool)));
01729
01730 QAction *normalAction = menu->addAction(tr("Restore Normal Speed"));
01731 normalAction->setShortcut(tr("Ctrl+Home"));
01732 normalAction->setStatusTip(tr("Restore non-time-stretched playback"));
01733 connect(normalAction, SIGNAL(triggered()), this, SLOT(restoreNormalPlayback()));
01734 connect(this, SIGNAL(canChangePlaybackSpeed(bool)), normalAction, SLOT(setEnabled(bool)));
01735
01736 m_keyReference->registerShortcut(fastAction);
01737 m_keyReference->registerShortcut(slowAction);
01738 m_keyReference->registerShortcut(normalAction);
01739
01740 m_rightButtonPlaybackMenu->addAction(fastAction);
01741 m_rightButtonPlaybackMenu->addAction(slowAction);
01742 m_rightButtonPlaybackMenu->addAction(normalAction);
01743
01744 toolbar = addToolBar(tr("Edit Toolbar"));
01745 CommandHistory::getInstance()->registerToolbar(toolbar);
01746
01747 m_keyReference->setCategory(tr("Tool Selection"));
01748
01749 toolbar = addToolBar(tr("Tools Toolbar"));
01750 QActionGroup *group = new QActionGroup(this);
01751
01752 QAction *action = toolbar->addAction(il.load("navigate"),
01753 tr("Navigate"));
01754 action->setCheckable(true);
01755 action->setChecked(true);
01756 action->setShortcut(tr("1"));
01757 action->setStatusTip(tr("Navigate"));
01758 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
01759 group->addAction(action);
01760 m_keyReference->registerShortcut(action);
01761 m_toolActions[ViewManager::NavigateMode] = action;
01762
01763 action = toolbar->addAction(il.load("select"),
01764 tr("Select"));
01765 action->setCheckable(true);
01766 action->setShortcut(tr("2"));
01767 action->setStatusTip(tr("Select ranges"));
01768 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
01769 group->addAction(action);
01770 m_keyReference->registerShortcut(action);
01771 m_toolActions[ViewManager::SelectMode] = action;
01772
01773 action = toolbar->addAction(il.load("move"),
01774 tr("Edit"));
01775 action->setCheckable(true);
01776 action->setShortcut(tr("3"));
01777 action->setStatusTip(tr("Edit items in layer"));
01778 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
01779 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
01780 group->addAction(action);
01781 m_keyReference->registerShortcut(action);
01782 m_toolActions[ViewManager::EditMode] = action;
01783
01784 action = toolbar->addAction(il.load("draw"),
01785 tr("Draw"));
01786 action->setCheckable(true);
01787 action->setShortcut(tr("4"));
01788 action->setStatusTip(tr("Draw new items in layer"));
01789 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
01790 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
01791 group->addAction(action);
01792 m_keyReference->registerShortcut(action);
01793 m_toolActions[ViewManager::DrawMode] = action;
01794
01795 action = toolbar->addAction(il.load("erase"),
01796 tr("Erase"));
01797 action->setCheckable(true);
01798 action->setShortcut(tr("5"));
01799 action->setStatusTip(tr("Erase items from layer"));
01800 connect(action, SIGNAL(triggered()), this, SLOT(toolEraseSelected()));
01801 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
01802 group->addAction(action);
01803 m_keyReference->registerShortcut(action);
01804 m_toolActions[ViewManager::EraseMode] = action;
01805
01806 action = toolbar->addAction(il.load("measure"),
01807 tr("Measure"));
01808 action->setCheckable(true);
01809 action->setShortcut(tr("6"));
01810 action->setStatusTip(tr("Make measurements in layer"));
01811 connect(action, SIGNAL(triggered()), this, SLOT(toolMeasureSelected()));
01812 connect(this, SIGNAL(canMeasureLayer(bool)), action, SLOT(setEnabled(bool)));
01813 group->addAction(action);
01814 m_keyReference->registerShortcut(action);
01815 m_toolActions[ViewManager::MeasureMode] = action;
01816
01817 toolNavigateSelected();
01818
01819 Pane::registerShortcuts(*m_keyReference);
01820 }
01821
01822 void
01823 MainWindow::updateMenuStates()
01824 {
01825 MainWindowBase::updateMenuStates();
01826
01827 Pane *currentPane = 0;
01828 Layer *currentLayer = 0;
01829
01830 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
01831 if (currentPane) currentLayer = currentPane->getSelectedLayer();
01832
01833 bool haveCurrentPane =
01834 (currentPane != 0);
01835 bool haveCurrentLayer =
01836 (haveCurrentPane &&
01837 (currentLayer != 0));
01838 bool havePlayTarget =
01839 (m_playTarget != 0);
01840 bool haveSelection =
01841 (m_viewManager &&
01842 !m_viewManager->getSelections().empty());
01843 bool haveCurrentEditableLayer =
01844 (haveCurrentLayer &&
01845 currentLayer->isLayerEditable());
01846 bool haveCurrentTimeInstantsLayer =
01847 (haveCurrentLayer &&
01848 dynamic_cast<TimeInstantLayer *>(currentLayer));
01849 bool haveCurrentTimeValueLayer =
01850 (haveCurrentLayer &&
01851 dynamic_cast<TimeValueLayer *>(currentLayer));
01852
01853 emit canChangeSolo(havePlayTarget);
01854 emit canAlign(havePlayTarget && m_document && m_document->canAlign());
01855
01856 emit canChangePlaybackSpeed(true);
01857 int v = m_playSpeed->value();
01858 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
01859 emit canSlowDownPlayback(v > m_playSpeed->minimum());
01860
01861 if (m_viewManager &&
01862 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
01863 emit canDeleteSelection(haveCurrentLayer);
01864 m_deleteSelectedAction->setText(tr("&Delete Current Measurement"));
01865 m_deleteSelectedAction->setStatusTip(tr("Delete the measurement currently under the mouse pointer"));
01866 } else {
01867 emit canDeleteSelection(haveSelection && haveCurrentEditableLayer);
01868 m_deleteSelectedAction->setText(tr("&Delete Selected Items"));
01869 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
01870 }
01871
01872 if (m_ffwdAction && m_rwdAction) {
01873 if (haveCurrentTimeInstantsLayer) {
01874 m_ffwdAction->setText(tr("Fast Forward to Next Instant"));
01875 m_ffwdAction->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
01876 m_rwdAction->setText(tr("Rewind to Previous Instant"));
01877 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
01878 } else if (haveCurrentTimeValueLayer) {
01879 m_ffwdAction->setText(tr("Fast Forward to Next Point"));
01880 m_ffwdAction->setStatusTip(tr("Fast forward to the next point in the current layer"));
01881 m_rwdAction->setText(tr("Rewind to Previous Point"));
01882 m_rwdAction->setStatusTip(tr("Rewind to the previous point in the current layer"));
01883 } else {
01884 m_ffwdAction->setText(tr("Fast Forward"));
01885 m_ffwdAction->setStatusTip(tr("Fast forward"));
01886 m_rwdAction->setText(tr("Rewind"));
01887 m_rwdAction->setStatusTip(tr("Rewind"));
01888 }
01889 }
01890 }
01891
01892 void
01893 MainWindow::updateDescriptionLabel()
01894 {
01895 if (!getMainModel()) {
01896 m_descriptionLabel->setText(tr("No audio file loaded."));
01897 return;
01898 }
01899
01900 QString description;
01901
01902 size_t ssr = getMainModel()->getSampleRate();
01903 size_t tsr = ssr;
01904 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
01905
01906 if (ssr != tsr) {
01907 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
01908 } else {
01909 description = QString("%1Hz").arg(ssr);
01910 }
01911
01912 description = QString("%1 - %2")
01913 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
01914 .toText(false).c_str())
01915 .arg(description);
01916
01917 m_descriptionLabel->setText(description);
01918 }
01919
01920 void
01921 MainWindow::documentModified()
01922 {
01924 MainWindowBase::documentModified();
01925 }
01926
01927 void
01928 MainWindow::documentRestored()
01929 {
01931 MainWindowBase::documentRestored();
01932 }
01933
01934 void
01935 MainWindow::toolNavigateSelected()
01936 {
01937 m_viewManager->setToolMode(ViewManager::NavigateMode);
01938 }
01939
01940 void
01941 MainWindow::toolSelectSelected()
01942 {
01943 m_viewManager->setToolMode(ViewManager::SelectMode);
01944 }
01945
01946 void
01947 MainWindow::toolEditSelected()
01948 {
01949 m_viewManager->setToolMode(ViewManager::EditMode);
01950 }
01951
01952 void
01953 MainWindow::toolDrawSelected()
01954 {
01955 m_viewManager->setToolMode(ViewManager::DrawMode);
01956 }
01957
01958 void
01959 MainWindow::toolEraseSelected()
01960 {
01961 m_viewManager->setToolMode(ViewManager::EraseMode);
01962 }
01963
01964 void
01965 MainWindow::toolMeasureSelected()
01966 {
01967 m_viewManager->setToolMode(ViewManager::MeasureMode);
01968 }
01969
01970 void
01971 MainWindow::importAudio()
01972 {
01973 QString path = getOpenFileName(FileFinder::AudioFile);
01974
01975 if (path != "") {
01976 if (openAudio(path, ReplaceMainModel) == FileOpenFailed) {
01977 QMessageBox::critical(this, tr("Failed to open file"),
01978 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
01979 }
01980 }
01981 }
01982
01983 void
01984 MainWindow::importMoreAudio()
01985 {
01986 QString path = getOpenFileName(FileFinder::AudioFile);
01987
01988 if (path != "") {
01989 if (openAudio(path, CreateAdditionalModel) == FileOpenFailed) {
01990 QMessageBox::critical(this, tr("Failed to open file"),
01991 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
01992 }
01993 }
01994 }
01995
01996 void
01997 MainWindow::exportAudio()
01998 {
01999 if (!getMainModel()) return;
02000
02001 QString path = getSaveFileName(FileFinder::AudioFile);
02002
02003 if (path == "") return;
02004
02005 bool ok = false;
02006 QString error;
02007
02008 MultiSelection ms = m_viewManager->getSelection();
02009 MultiSelection::SelectionList selections = m_viewManager->getSelections();
02010
02011 bool multiple = false;
02012
02013 MultiSelection *selectionToWrite = 0;
02014
02015 if (selections.size() == 1) {
02016
02017 QStringList items;
02018 items << tr("Export the selected region only")
02019 << tr("Export the whole audio file");
02020
02021 bool ok = false;
02022 QString item = ListInputDialog::getItem
02023 (this, tr("Select region to export"),
02024 tr("Which region from the original audio file do you want to export?"),
02025 items, 0, &ok);
02026
02027 if (!ok || item.isEmpty()) return;
02028
02029 if (item == items[0]) selectionToWrite = &ms;
02030
02031 } else if (selections.size() > 1) {
02032
02033 QStringList items;
02034 items << tr("Export the selected regions into a single audio file")
02035 << tr("Export the selected regions into separate files")
02036 << tr("Export the whole audio file");
02037
02038 QString item = ListInputDialog::getItem
02039 (this, tr("Select region to export"),
02040 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
02041 items, 0, &ok);
02042
02043 if (!ok || item.isEmpty()) return;
02044
02045 if (item == items[0]) {
02046
02047 selectionToWrite = &ms;
02048
02049 } else if (item == items[1]) {
02050
02051 multiple = true;
02052
02053 int n = 1;
02054 QString base = path;
02055 base.replace(".wav", "");
02056
02057 for (MultiSelection::SelectionList::iterator i = selections.begin();
02058 i != selections.end(); ++i) {
02059
02060 MultiSelection subms;
02061 subms.setSelection(*i);
02062
02063 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
02064 ++n;
02065
02066 if (QFileInfo(subpath).exists()) {
02067 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
02068 break;
02069 }
02070
02071 WavFileWriter subwriter(subpath,
02072 getMainModel()->getSampleRate(),
02073 getMainModel()->getChannelCount());
02074 subwriter.writeModel(getMainModel(), &subms);
02075 ok = subwriter.isOK();
02076
02077 if (!ok) {
02078 error = subwriter.getError();
02079 break;
02080 }
02081 }
02082 }
02083 }
02084
02085 if (!multiple) {
02086 WavFileWriter writer(path,
02087 getMainModel()->getSampleRate(),
02088 getMainModel()->getChannelCount());
02089 writer.writeModel(getMainModel(), selectionToWrite);
02090 ok = writer.isOK();
02091 error = writer.getError();
02092 }
02093
02094 if (ok) {
02095 if (!multiple) {
02096 m_recentFiles.addFile(path);
02097 }
02098 } else {
02099 QMessageBox::critical(this, tr("Failed to write file"), error);
02100 }
02101 }
02102
02103 void
02104 MainWindow::importLayer()
02105 {
02106 Pane *pane = m_paneStack->getCurrentPane();
02107
02108 if (!pane) {
02109
02110 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
02111 return;
02112 }
02113
02114 if (!getMainModel()) {
02115
02116 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
02117 return;
02118 }
02119
02120 QString path = getOpenFileName(FileFinder::LayerFile);
02121
02122 if (path != "") {
02123
02124 FileOpenStatus status = openLayer(path);
02125
02126 if (status == FileOpenFailed) {
02127 QMessageBox::critical(this, tr("Failed to open file"),
02128 tr("<b>File open failed</b><p>Layer file %1 could not be opened.").arg(path));
02129 return;
02130 } else if (status == FileOpenWrongMode) {
02131 QMessageBox::critical(this, tr("Failed to open file"),
02132 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
02133 }
02134 }
02135 }
02136
02137 void
02138 MainWindow::exportLayer()
02139 {
02140 Pane *pane = m_paneStack->getCurrentPane();
02141 if (!pane) return;
02142
02143 Layer *layer = pane->getSelectedLayer();
02144 if (!layer) return;
02145
02146 Model *model = layer->getModel();
02147 if (!model) return;
02148
02149 FileFinder::FileType type = FileFinder::LayerFileNoMidi;
02150
02151 if (dynamic_cast<NoteModel *>(model)) type = FileFinder::LayerFile;
02152
02153 QString path = getSaveFileName(type);
02154
02155 if (path == "") return;
02156
02157 if (QFileInfo(path).suffix() == "") path += ".svl";
02158
02159 QString suffix = QFileInfo(path).suffix().toLower();
02160
02161 QString error;
02162
02163 if (suffix == "xml" || suffix == "svl") {
02164
02165 QFile file(path);
02166 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
02167 error = tr("Failed to open file %1 for writing").arg(path);
02168 } else {
02169 QTextStream out(&file);
02170 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
02171 << "<!DOCTYPE sonic-visualiser>\n"
02172 << "<sv>\n"
02173 << " <data>\n";
02174
02175 model->toXml(out, " ");
02176
02177 out << " </data>\n"
02178 << " <display>\n";
02179
02180 layer->toXml(out, " ");
02181
02182 out << " </display>\n"
02183 << "</sv>\n";
02184 }
02185
02186 } else if (suffix == "mid" || suffix == "midi") {
02187
02188 NoteModel *nm = dynamic_cast<NoteModel *>(model);
02189
02190 if (!nm) {
02191 error = tr("Can't export non-note layers to MIDI");
02192 } else {
02193 MIDIFileWriter writer(path, nm);
02194 writer.write();
02195 if (!writer.isOK()) {
02196 error = writer.getError();
02197 }
02198 }
02199
02200 } else {
02201
02202 CSVFileWriter writer(path, model,
02203 ((suffix == "csv") ? "," : "\t"));
02204 writer.write();
02205
02206 if (!writer.isOK()) {
02207 error = writer.getError();
02208 }
02209 }
02210
02211 if (error != "") {
02212 QMessageBox::critical(this, tr("Failed to write file"), error);
02213 } else {
02214 m_recentFiles.addFile(path);
02215 }
02216 }
02217
02218 void
02219 MainWindow::exportImage()
02220 {
02221 Pane *pane = m_paneStack->getCurrentPane();
02222 if (!pane) return;
02223
02224 QString path = getSaveFileName(FileFinder::ImageFile);
02225
02226 if (path == "") return;
02227
02228 if (QFileInfo(path).suffix() == "") path += ".png";
02229
02230 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty();
02231
02232 QSize total, visible, selected;
02233 total = pane->getImageSize();
02234 visible = pane->getImageSize(pane->getFirstVisibleFrame(),
02235 pane->getLastVisibleFrame());
02236
02237 size_t sf0 = 0, sf1 = 0;
02238
02239 if (haveSelection) {
02240 MultiSelection::SelectionList selections = m_viewManager->getSelections();
02241 sf0 = selections.begin()->getStartFrame();
02242 MultiSelection::SelectionList::iterator e = selections.end();
02243 --e;
02244 sf1 = e->getEndFrame();
02245 selected = pane->getImageSize(sf0, sf1);
02246 }
02247
02248 QStringList items;
02249 items << tr("Export the whole pane (%1x%2 pixels)")
02250 .arg(total.width()).arg(total.height());
02251 items << tr("Export the visible area only (%1x%2 pixels)")
02252 .arg(visible.width()).arg(visible.height());
02253 if (haveSelection) {
02254 items << tr("Export the selection extent (%1x%2 pixels)")
02255 .arg(selected.width()).arg(selected.height());
02256 } else {
02257 items << tr("Export the selection extent");
02258 }
02259
02260 QSettings settings;
02261 settings.beginGroup("MainWindow");
02262 int deflt = settings.value("lastimageexportregion", 0).toInt();
02263 if (deflt == 2 && !haveSelection) deflt = 1;
02264 if (deflt == 0 && total.width() > 32767) deflt = 1;
02265
02266 ListInputDialog *lid = new ListInputDialog
02267 (this, tr("Select region to export"),
02268 tr("Which region of the current pane do you want to export as an image?"),
02269 items, deflt);
02270
02271 if (!haveSelection) {
02272 lid->setItemAvailability(2, false);
02273 }
02274 if (total.width() > 32767) {
02275 lid->setItemAvailability(0, false);
02276 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image."));
02277 }
02278
02279 bool ok = lid->exec();
02280 QString item = lid->getCurrentString();
02281 delete lid;
02282
02283 if (!ok || item.isEmpty()) return;
02284
02285 settings.setValue("lastimageexportregion", deflt);
02286
02287 QImage *image = 0;
02288
02289 if (item == items[0]) {
02290 image = pane->toNewImage();
02291 } else if (item == items[1]) {
02292 image = pane->toNewImage(pane->getFirstVisibleFrame(),
02293 pane->getLastVisibleFrame());
02294 } else if (haveSelection) {
02295 image = pane->toNewImage(sf0, sf1);
02296 }
02297
02298 if (!image) return;
02299
02300 if (!image->save(path, "PNG")) {
02301 QMessageBox::critical(this, tr("Failed to save image file"),
02302 tr("Failed to save image file %1").arg(path));
02303 }
02304
02305 delete image;
02306 }
02307
02308 void
02309 MainWindow::newSession()
02310 {
02311 if (!checkSaveModified()) return;
02312
02313 closeSession();
02314 createDocument();
02315
02316 Pane *pane = m_paneStack->addPane();
02317
02318 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
02319 this, SLOT(contextHelpChanged(const QString &)));
02320
02321 if (!m_timeRulerLayer) {
02322 m_timeRulerLayer = m_document->createMainModelLayer
02323 (LayerFactory::TimeRuler);
02324 }
02325
02326 m_document->addLayerToView(pane, m_timeRulerLayer);
02327
02328 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
02329 m_document->addLayerToView(pane, waveform);
02330
02331 m_overview->registerView(pane);
02332
02333 CommandHistory::getInstance()->clear();
02334 CommandHistory::getInstance()->documentSaved();
02335 documentRestored();
02336 updateMenuStates();
02337 }
02338
02339 void
02340 MainWindow::closeSession()
02341 {
02342 if (!checkSaveModified()) return;
02343
02344 while (m_paneStack->getPaneCount() > 0) {
02345
02346 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
02347
02348 while (pane->getLayerCount() > 0) {
02349 m_document->removeLayerFromView
02350 (pane, pane->getLayer(pane->getLayerCount() - 1));
02351 }
02352
02353 m_overview->unregisterView(pane);
02354 m_paneStack->deletePane(pane);
02355 }
02356
02357 while (m_paneStack->getHiddenPaneCount() > 0) {
02358
02359 Pane *pane = m_paneStack->getHiddenPane
02360 (m_paneStack->getHiddenPaneCount() - 1);
02361
02362 while (pane->getLayerCount() > 0) {
02363 m_document->removeLayerFromView
02364 (pane, pane->getLayer(pane->getLayerCount() - 1));
02365 }
02366
02367 m_overview->unregisterView(pane);
02368 m_paneStack->deletePane(pane);
02369 }
02370
02371 delete m_document;
02372 m_document = 0;
02373 m_viewManager->clearSelections();
02374 m_timeRulerLayer = 0;
02375
02376 m_sessionFile = "";
02377 setWindowTitle(tr("Sonic Visualiser"));
02378
02379 CommandHistory::getInstance()->clear();
02380 CommandHistory::getInstance()->documentSaved();
02381 documentRestored();
02382 }
02383
02384 void
02385 MainWindow::openSession()
02386 {
02387 if (!checkSaveModified()) return;
02388
02389 QString orig = m_audioFile;
02390 if (orig == "") orig = ".";
02391 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
02392
02393 QString path = getOpenFileName(FileFinder::SessionFile);
02394
02395 if (path.isEmpty()) return;
02396
02397 if (openSessionFile(path) == FileOpenFailed) {
02398 QMessageBox::critical(this, tr("Failed to open file"),
02399 tr("<b>File open failed</b><p>Session file \"%1\" could not be opened").arg(path));
02400 }
02401 }
02402
02403 void
02404 MainWindow::openSomething()
02405 {
02406 QString orig = m_audioFile;
02407 if (orig == "") orig = ".";
02408 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
02409
02410 QString path = getOpenFileName(FileFinder::AnyFile);
02411
02412 if (path.isEmpty()) return;
02413
02414 FileOpenStatus status = open(path, AskUser);
02415
02416 if (status == FileOpenFailed) {
02417 QMessageBox::critical(this, tr("Failed to open file"),
02418 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path));
02419 } else if (status == FileOpenWrongMode) {
02420 QMessageBox::critical(this, tr("Failed to open file"),
02421 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
02422 }
02423 }
02424
02425 void
02426 MainWindow::openLocation()
02427 {
02428 QSettings settings;
02429 settings.beginGroup("MainWindow");
02430 QString lastLocation = settings.value("lastremote", "").toString();
02431
02432 bool ok = false;
02433 QString text = QInputDialog::getText
02434 (this, tr("Open Location"),
02435 tr("Please enter the URL of the location to open:"),
02436 QLineEdit::Normal, lastLocation, &ok);
02437
02438 if (!ok) return;
02439
02440 settings.setValue("lastremote", text);
02441
02442 if (text.isEmpty()) return;
02443
02444 FileOpenStatus status = open(text);
02445
02446 if (status == FileOpenFailed) {
02447 QMessageBox::critical(this, tr("Failed to open location"),
02448 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text));
02449 } else if (status == FileOpenWrongMode) {
02450 QMessageBox::critical(this, tr("Failed to open location"),
02451 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
02452 }
02453 }
02454
02455 void
02456 MainWindow::openRecentFile()
02457 {
02458 QObject *obj = sender();
02459 QAction *action = dynamic_cast<QAction *>(obj);
02460
02461 if (!action) {
02462 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
02463 << std::endl;
02464 return;
02465 }
02466
02467 QString path = action->text();
02468 if (path == "") return;
02469
02470 FileOpenStatus status = open(path);
02471
02472 if (status == FileOpenFailed) {
02473 QMessageBox::critical(this, tr("Failed to open location"),
02474 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path));
02475 } else if (status == FileOpenWrongMode) {
02476 QMessageBox::critical(this, tr("Failed to open location"),
02477 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
02478 }
02479 }
02480
02481 void
02482 MainWindow::paneAdded(Pane *pane)
02483 {
02484 if (m_overview) m_overview->registerView(pane);
02485 }
02486
02487 void
02488 MainWindow::paneHidden(Pane *pane)
02489 {
02490 if (m_overview) m_overview->unregisterView(pane);
02491 }
02492
02493 void
02494 MainWindow::paneAboutToBeDeleted(Pane *pane)
02495 {
02496 if (m_overview) m_overview->unregisterView(pane);
02497 }
02498
02499 void
02500 MainWindow::paneDropAccepted(Pane *pane, QStringList uriList)
02501 {
02502 if (pane) m_paneStack->setCurrentPane(pane);
02503
02504 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) {
02505
02506 FileOpenStatus status = open(*i, ReplaceCurrentPane);
02507
02508 if (status == FileOpenFailed) {
02509 QMessageBox::critical(this, tr("Failed to open dropped URL"),
02510 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i));
02511 } else if (status == FileOpenWrongMode) {
02512 QMessageBox::critical(this, tr("Failed to open dropped URL"),
02513 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
02514 }
02515 }
02516 }
02517
02518 void
02519 MainWindow::paneDropAccepted(Pane *pane, QString text)
02520 {
02521 if (pane) m_paneStack->setCurrentPane(pane);
02522
02523 QUrl testUrl(text);
02524 if (testUrl.scheme() == "file" ||
02525 testUrl.scheme() == "http" ||
02526 testUrl.scheme() == "ftp") {
02527 QStringList list;
02528 list.push_back(text);
02529 paneDropAccepted(pane, list);
02530 return;
02531 }
02532
02534
02535 }
02536
02537 void
02538 MainWindow::closeEvent(QCloseEvent *e)
02539 {
02540
02541
02542 if (m_openingAudioFile) {
02543
02544 e->ignore();
02545 return;
02546 }
02547
02548 if (!m_abandoning && !checkSaveModified()) {
02549
02550 e->ignore();
02551 return;
02552 }
02553
02554 QSettings settings;
02555 settings.beginGroup("MainWindow");
02556 settings.setValue("size", size());
02557 settings.setValue("position", pos());
02558 settings.endGroup();
02559
02560 delete m_keyReference;
02561 m_keyReference = 0;
02562
02563 if (m_preferencesDialog &&
02564 m_preferencesDialog->isVisible()) {
02565 closeSession();
02566 m_preferencesDialog->applicationClosing(false);
02567 }
02568
02569 closeSession();
02570
02571 e->accept();
02572 return;
02573 }
02574
02575 bool
02576 MainWindow::commitData(bool mayAskUser)
02577 {
02578 if (mayAskUser) {
02579 bool rv = checkSaveModified();
02580 if (rv) {
02581 if (m_preferencesDialog &&
02582 m_preferencesDialog->isVisible()) {
02583 m_preferencesDialog->applicationClosing(false);
02584 }
02585 }
02586 return rv;
02587 } else {
02588 if (m_preferencesDialog &&
02589 m_preferencesDialog->isVisible()) {
02590 m_preferencesDialog->applicationClosing(true);
02591 }
02592 if (!m_documentModified) return true;
02593
02594
02595
02596
02597
02598 QString svDirBase = ".sv1";
02599 QString svDir = QDir::home().filePath(svDirBase);
02600
02601 if (!QFileInfo(svDir).exists()) {
02602 if (!QDir::home().mkdir(svDirBase)) return false;
02603 } else {
02604 if (!QFileInfo(svDir).isDir()) return false;
02605 }
02606
02607
02608 #ifndef _WIN32
02609 QString fname = QString("tmp-%1-%2.sv")
02610 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
02611 .arg(QProcess().pid());
02612 #else
02613 QString fname = QString("tmp-%1.sv")
02614 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
02615 #endif
02616 QString fpath = QDir(svDir).filePath(fname);
02617 if (saveSessionFile(fpath)) {
02618 m_recentFiles.addFile(fpath);
02619 return true;
02620 } else {
02621 return false;
02622 }
02623 }
02624 }
02625
02626 bool
02627 MainWindow::checkSaveModified()
02628 {
02629
02630
02631
02632
02633 if (!m_documentModified) return true;
02634
02635 int button =
02636 QMessageBox::warning(this,
02637 tr("Session modified"),
02638 tr("<b>Session modified</b><p>The current session has been modified.<br>Do you want to save it?"),
02639 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
02640 QMessageBox::Yes);
02641
02642 if (button == QMessageBox::Yes) {
02643 saveSession();
02644 if (m_documentModified) {
02645 return false;
02646 } else {
02647 return true;
02648 }
02649 } else if (button == QMessageBox::No) {
02650 m_documentModified = false;
02651 return true;
02652 }
02653
02654
02655 return false;
02656 }
02657
02658 void
02659 MainWindow::saveSession()
02660 {
02661 if (m_sessionFile != "") {
02662 if (!saveSessionFile(m_sessionFile)) {
02663 QMessageBox::critical(this, tr("Failed to save file"),
02664 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(m_sessionFile));
02665 } else {
02666 CommandHistory::getInstance()->documentSaved();
02667 documentRestored();
02668 }
02669 } else {
02670 saveSessionAs();
02671 }
02672 }
02673
02674 void
02675 MainWindow::saveSessionAs()
02676 {
02677 QString orig = m_audioFile;
02678 if (orig == "") orig = ".";
02679 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
02680
02681 QString path = getSaveFileName(FileFinder::SessionFile);
02682
02683 if (path == "") return;
02684
02685 if (!saveSessionFile(path)) {
02686 QMessageBox::critical(this, tr("Failed to save file"),
02687 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(path));
02688 } else {
02689 setWindowTitle(tr("Sonic Visualiser: %1")
02690 .arg(QFileInfo(path).fileName()));
02691 m_sessionFile = path;
02692 CommandHistory::getInstance()->documentSaved();
02693 documentRestored();
02694 m_recentFiles.addFile(path);
02695 }
02696 }
02697
02698 void
02699 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
02700 {
02701 MainWindowBase::preferenceChanged(name);
02702
02703 if (name == "Background Mode" && m_viewManager) {
02704 if (m_viewManager->getGlobalDarkBackground()) {
02705 m_panLayer->setBaseColour
02706 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
02707 } else {
02708 m_panLayer->setBaseColour
02709 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
02710 }
02711 }
02712 }
02713
02714 void
02715 MainWindow::propertyStacksResized(int width)
02716 {
02717 std::cerr << "MainWindow::propertyStacksResized(" << width << ")" << std::endl;
02718
02719 if (!m_playControlsSpacer) return;
02720
02721 int spacerWidth = width - m_playControlsWidth - 4;
02722
02723 std::cerr << "resizing spacer from " << m_playControlsSpacer->width() << " to " << spacerWidth << std::endl;
02724
02725 m_playControlsSpacer->setFixedSize(QSize(spacerWidth, 2));
02726 }
02727
02728 void
02729 MainWindow::addPane()
02730 {
02731 QObject *s = sender();
02732 QAction *action = dynamic_cast<QAction *>(s);
02733
02734 if (!action) {
02735 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
02736 << std::endl;
02737 return;
02738 }
02739
02740 PaneActionMap::iterator i = m_paneActions.find(action);
02741
02742 if (i == m_paneActions.end()) {
02743 std::cerr << "WARNING: MainWindow::addPane: unknown action "
02744 << action->objectName().toStdString() << std::endl;
02745 return;
02746 }
02747
02748 addPane(i->second, action->text());
02749 }
02750
02751 void
02752 MainWindow::addPane(const LayerConfiguration &configuration, QString text)
02753 {
02754 CommandHistory::getInstance()->startCompoundOperation(text, true);
02755
02756 AddPaneCommand *command = new AddPaneCommand(this);
02757 CommandHistory::getInstance()->addCommand(command);
02758
02759 Pane *pane = command->getPane();
02760
02761 if (configuration.layer == LayerFactory::Spectrum) {
02762 pane->setPlaybackFollow(PlaybackScrollContinuous);
02763 pane->setFollowGlobalZoom(false);
02764 pane->setZoomLevel(512);
02765 }
02766
02767 if (configuration.layer != LayerFactory::TimeRuler &&
02768 configuration.layer != LayerFactory::Spectrum) {
02769
02770 if (!m_timeRulerLayer) {
02771
02772 m_timeRulerLayer = m_document->createMainModelLayer
02773 (LayerFactory::TimeRuler);
02774 }
02775
02776
02777
02778 m_document->addLayerToView(pane, m_timeRulerLayer);
02779 }
02780
02781 Layer *newLayer = m_document->createLayer(configuration.layer);
02782
02783 Model *suggestedModel = configuration.sourceModel;
02784 Model *model = 0;
02785
02786 if (suggestedModel) {
02787
02788
02789 std::vector<Model *> inputModels = m_document->getTransformInputModels();
02790 for (size_t j = 0; j < inputModels.size(); ++j) {
02791 if (inputModels[j] == suggestedModel) {
02792 model = suggestedModel;
02793 break;
02794 }
02795 }
02796
02797 if (!model) {
02798 std::cerr << "WARNING: Model " << (void *)suggestedModel
02799 << " appears in pane action map, but is not reported "
02800 << "by document as a valid transform source" << std::endl;
02801 }
02802 }
02803
02804 if (!model) model = m_document->getMainModel();
02805
02806 m_document->setModel(newLayer, model);
02807
02808 m_document->setChannel(newLayer, configuration.channel);
02809 m_document->addLayerToView(pane, newLayer);
02810
02811 m_paneStack->setCurrentPane(pane);
02812 m_paneStack->setCurrentLayer(pane, newLayer);
02813
02814
02815
02816
02817
02818 CommandHistory::getInstance()->endCompoundOperation();
02819
02820 updateMenuStates();
02821 }
02822
02823 void
02824 MainWindow::addLayer()
02825 {
02826 QObject *s = sender();
02827 QAction *action = dynamic_cast<QAction *>(s);
02828
02829 if (!action) {
02830 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
02831 << std::endl;
02832 return;
02833 }
02834
02835 Pane *pane = m_paneStack->getCurrentPane();
02836
02837 if (!pane) {
02838 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
02839 return;
02840 }
02841
02842 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
02843
02844 if (ei != m_existingLayerActions.end()) {
02845 Layer *newLayer = ei->second;
02846 m_document->addLayerToView(pane, newLayer);
02847 m_paneStack->setCurrentLayer(pane, newLayer);
02848 return;
02849 }
02850
02851 ei = m_sliceActions.find(action);
02852
02853 if (ei != m_sliceActions.end()) {
02854 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
02855
02856 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
02857 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
02858 if (source && dest) {
02860 dest->setSliceableModel(source->getSliceableModel());
02861 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
02862 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
02863 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
02864 dest, SLOT(modelAboutToBeDeleted(Model *)));
02865 }
02866 m_document->addLayerToView(pane, newLayer);
02867 m_paneStack->setCurrentLayer(pane, newLayer);
02868 return;
02869 }
02870
02871 TransformActionMap::iterator i = m_transformActions.find(action);
02872
02873 if (i == m_transformActions.end()) {
02874
02875 LayerActionMap::iterator i = m_layerActions.find(action);
02876
02877 if (i == m_layerActions.end()) {
02878 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
02879 << action->objectName().toStdString() << std::endl;
02880 return;
02881 }
02882
02883 LayerFactory::LayerType type = i->second.layer;
02884
02885 LayerFactory::LayerTypeSet emptyTypes =
02886 LayerFactory::getInstance()->getValidEmptyLayerTypes();
02887
02888 Layer *newLayer;
02889
02890 if (emptyTypes.find(type) != emptyTypes.end()) {
02891
02892 newLayer = m_document->createEmptyLayer(type);
02893 if (newLayer) {
02894 m_toolActions[ViewManager::DrawMode]->trigger();
02895 }
02896
02897 } else {
02898
02899 if (!i->second.sourceModel) {
02900
02901 newLayer = m_document->createMainModelLayer(type);
02902 } else {
02903 newLayer = m_document->createLayer(type);
02904 if (m_document->isKnownModel(i->second.sourceModel)) {
02905 m_document->setChannel(newLayer, i->second.channel);
02906 m_document->setModel(newLayer, i->second.sourceModel);
02907 } else {
02908 std::cerr << "WARNING: MainWindow::addLayer: unknown model "
02909 << i->second.sourceModel
02910 << " (\""
02911 << (i->second.sourceModel ? i->second.sourceModel->objectName().toStdString() : "")
02912 << "\") in layer action map"
02913 << std::endl;
02914 }
02915 }
02916 }
02917
02918 if (newLayer) {
02919 m_document->addLayerToView(pane, newLayer);
02920 m_paneStack->setCurrentLayer(pane, newLayer);
02921 }
02922
02923 return;
02924 }
02925
02927
02928
02929
02930
02931
02932
02933
02934
02935
02936
02937
02938
02939
02940
02941
02942
02943
02944 QString transformId = i->second;
02945 Transform transform = TransformFactory::getInstance()->
02946 getDefaultTransformFor(transformId);
02947
02948 std::vector<Model *> candidateInputModels =
02949 m_document->getTransformInputModels();
02950
02951 Model *defaultInputModel = 0;
02952 for (int j = 0; j < pane->getLayerCount(); ++j) {
02953 Layer *layer = pane->getLayer(j);
02954 if (!layer) continue;
02955 if (LayerFactory::getInstance()->getLayerType(layer) !=
02956 LayerFactory::Waveform &&
02957 !layer->isLayerOpaque()) continue;
02958 Model *model = layer->getModel();
02959 if (!model) continue;
02960 for (size_t k = 0; k < candidateInputModels.size(); ++k) {
02961 if (candidateInputModels[k] == model) {
02962 defaultInputModel = model;
02963 break;
02964 }
02965 }
02966 if (defaultInputModel) break;
02967 }
02968
02969 size_t startFrame = 0, duration = 0;
02970 size_t endFrame = 0;
02971 m_viewManager->getSelection().getExtents(startFrame, endFrame);
02972 if (endFrame > startFrame) duration = endFrame - startFrame;
02973 else startFrame = 0;
02974
02975 ModelTransformer::Input input = ModelTransformerFactory::getInstance()->
02976 getConfigurationForTransform
02977 (transform,
02978 candidateInputModels,
02979 defaultInputModel,
02980 m_playSource,
02981 startFrame,
02982 duration);
02983
02984 if (!input.getModel()) return;
02985
02986
02987
02988 Layer *newLayer = m_document->createDerivedLayer(transform, input);
02989
02990 if (newLayer) {
02991 m_document->addLayerToView(pane, newLayer);
02992 m_document->setChannel(newLayer, input.getChannel());
02993 m_recentTransforms.add(transformId);
02994 m_paneStack->setCurrentLayer(pane, newLayer);
02995 }
02996
02997 updateMenuStates();
02998 }
02999
03000 void
03001 MainWindow::renameCurrentLayer()
03002 {
03003 Pane *pane = m_paneStack->getCurrentPane();
03004 if (pane) {
03005 Layer *layer = pane->getSelectedLayer();
03006 if (layer) {
03007 bool ok = false;
03008 QString newName = QInputDialog::getText
03009 (this, tr("Rename Layer"),
03010 tr("New name for this layer:"),
03011 QLineEdit::Normal, layer->objectName(), &ok);
03012 if (ok) {
03013 layer->setPresentationName(newName);
03014 setupExistingLayersMenus();
03015 }
03016 }
03017 }
03018 }
03019
03020 void
03021 MainWindow::playSoloToggled()
03022 {
03023 MainWindowBase::playSoloToggled();
03024 m_soloModified = true;
03025 }
03026
03027 void
03028 MainWindow::alignToggled()
03029 {
03030 QAction *action = dynamic_cast<QAction *>(sender());
03031
03032 if (!m_viewManager) return;
03033
03034 if (action) {
03035 m_viewManager->setAlignMode(action->isChecked());
03036 } else {
03037 m_viewManager->setAlignMode(!m_viewManager->getAlignMode());
03038 }
03039
03040 if (m_viewManager->getAlignMode()) {
03041 m_prevSolo = m_soloAction->isChecked();
03042 if (!m_soloAction->isChecked()) {
03043 m_soloAction->setChecked(true);
03044 MainWindowBase::playSoloToggled();
03045 }
03046 m_soloModified = false;
03047 emit canChangeSolo(false);
03048 m_document->alignModels();
03049 m_document->setAutoAlignment(true);
03050 } else {
03051 if (!m_soloModified) {
03052 if (m_soloAction->isChecked() != m_prevSolo) {
03053 m_soloAction->setChecked(m_prevSolo);
03054 MainWindowBase::playSoloToggled();
03055 }
03056 }
03057 emit canChangeSolo(true);
03058 m_document->setAutoAlignment(false);
03059 }
03060
03061 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
03062
03063 Pane *pane = m_paneStack->getPane(i);
03064 if (!pane) continue;
03065
03066 pane->update();
03067 }
03068 }
03069
03070 void
03071 MainWindow::playSpeedChanged(int position)
03072 {
03073 PlaySpeedRangeMapper mapper(0, 200);
03074
03075 float percent = m_playSpeed->mappedValue();
03076 float factor = mapper.getFactorForValue(percent);
03077
03078 std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
03079
03080 bool something = (position != 100);
03081
03082 int pc = lrintf(percent);
03083
03084 if (!something) {
03085 contextHelpChanged(tr("Playback speed: Normal"));
03086 } else {
03087 contextHelpChanged(tr("Playback speed: %1%2%")
03088 .arg(position > 100 ? "+" : "")
03089 .arg(pc));
03090 }
03091
03092 m_playSource->setTimeStretch(factor);
03093
03094 updateMenuStates();
03095 }
03096
03097 void
03098 MainWindow::speedUpPlayback()
03099 {
03100 int value = m_playSpeed->value();
03101 value = value + m_playSpeed->pageStep();
03102 if (value > m_playSpeed->maximum()) value = m_playSpeed->maximum();
03103 m_playSpeed->setValue(value);
03104 }
03105
03106 void
03107 MainWindow::slowDownPlayback()
03108 {
03109 int value = m_playSpeed->value();
03110 value = value - m_playSpeed->pageStep();
03111 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
03112 m_playSpeed->setValue(value);
03113 }
03114
03115 void
03116 MainWindow::restoreNormalPlayback()
03117 {
03118 m_playSpeed->setValue(m_playSpeed->defaultValue());
03119 }
03120
03121 void
03122 MainWindow::currentPaneChanged(Pane *pane)
03123 {
03124 MainWindowBase::currentPaneChanged(pane);
03125
03126 if (!pane || !m_panLayer) return;
03127 for (int i = pane->getLayerCount(); i > 0; ) {
03128 --i;
03129 Layer *layer = pane->getLayer(i);
03130 if (LayerFactory::getInstance()->getLayerType(layer) ==
03131 LayerFactory::Waveform) {
03132 RangeSummarisableTimeValueModel *tvm =
03133 dynamic_cast<RangeSummarisableTimeValueModel *>(layer->getModel());
03134 if (tvm) {
03135 m_panLayer->setModel(tvm);
03136 return;
03137 }
03138 }
03139 }
03140 }
03141
03142 void
03143 MainWindow::updateVisibleRangeDisplay(Pane *p) const
03144 {
03145 if (!getMainModel() || !p) {
03146 return;
03147 }
03148
03149 bool haveSelection = false;
03150 size_t startFrame = 0, endFrame = 0;
03151
03152 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
03153
03154 bool exclusive = false;
03155 Selection s = m_viewManager->getInProgressSelection(exclusive);
03156
03157 if (!s.isEmpty()) {
03158 haveSelection = true;
03159 startFrame = s.getStartFrame();
03160 endFrame = s.getEndFrame();
03161 }
03162 }
03163
03164 if (!haveSelection) {
03165 startFrame = p->getFirstVisibleFrame();
03166 endFrame = p->getLastVisibleFrame();
03167 }
03168
03169 RealTime start = RealTime::frame2RealTime
03170 (startFrame, getMainModel()->getSampleRate());
03171
03172 RealTime end = RealTime::frame2RealTime
03173 (endFrame, getMainModel()->getSampleRate());
03174
03175 RealTime duration = end - start;
03176
03177 QString startStr, endStr, durationStr;
03178 startStr = start.toText(true).c_str();
03179 endStr = end.toText(true).c_str();
03180 durationStr = duration.toText(true).c_str();
03181
03182 if (haveSelection) {
03183 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
03184 .arg(startStr).arg(endStr).arg(durationStr);
03185 } else {
03186 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
03187 .arg(startStr).arg(endStr).arg(durationStr);
03188 }
03189
03190 statusBar()->showMessage(m_myStatusMessage);
03191 }
03192
03193 void
03194 MainWindow::outputLevelsChanged(float left, float right)
03195 {
03196 m_fader->setPeakLeft(left);
03197 m_fader->setPeakRight(right);
03198 }
03199
03200 void
03201 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
03202 bool willResample)
03203 {
03204 if (!willResample) {
03205 QMessageBox::information
03206 (this, tr("Sample rate mismatch"),
03207 tr("<b>Wrong sample rate</b><p>The sample rate of this audio file (%1 Hz) does not match\nthe current playback rate (%2 Hz).<p>The file will play at the wrong speed and pitch.<p>Change the <i>Resample mismatching files on import</i> option under <i>File</i> -> <i>Preferences</i> if you want to alter this behaviour.")
03208 .arg(requested).arg(actual));
03209 }
03210
03211 updateDescriptionLabel();
03212 }
03213
03214 void
03215 MainWindow::audioOverloadPluginDisabled()
03216 {
03217 QMessageBox::information
03218 (this, tr("Audio processing overload"),
03219 tr("<b>Overloaded</b><p>Audio effects plugin auditioning has been disabled due to a processing overload."));
03220 }
03221
03222 void
03223 MainWindow::layerRemoved(Layer *layer)
03224 {
03225 setupExistingLayersMenus();
03226 MainWindowBase::layerRemoved(layer);
03227 }
03228
03229 void
03230 MainWindow::layerInAView(Layer *layer, bool inAView)
03231 {
03232 setupExistingLayersMenus();
03233 MainWindowBase::layerInAView(layer, inAView);
03234 }
03235
03236 void
03237 MainWindow::modelAdded(Model *model)
03238 {
03239 MainWindowBase::modelAdded(model);
03240 if (dynamic_cast<DenseTimeValueModel *>(model)) {
03241 setupPaneAndLayerMenus();
03242 }
03243 }
03244
03245 void
03246 MainWindow::mainModelChanged(WaveFileModel *model)
03247 {
03248 m_panLayer->setModel(model);
03249
03250 MainWindowBase::mainModelChanged(model);
03251
03252 if (m_playTarget) {
03253 connect(m_fader, SIGNAL(valueChanged(float)),
03254 m_playTarget, SLOT(setOutputGain(float)));
03255 }
03256 }
03257
03258 void
03259 MainWindow::setInstantsNumbering()
03260 {
03261 QAction *a = dynamic_cast<QAction *>(sender());
03262 if (!a) return;
03263
03264 int type = m_numberingActions[a];
03265
03266 if (m_labeller) m_labeller->setType(Labeller::ValueType(type));
03267
03268 QSettings settings;
03269 settings.beginGroup("MainWindow");
03270 settings.setValue("labellertype", type);
03271 settings.endGroup();
03272 }
03273
03274 void
03275 MainWindow::setInstantsCounterCycle()
03276 {
03277 QAction *a = dynamic_cast<QAction *>(sender());
03278 if (!a) return;
03279
03280 int cycle = a->text().toInt();
03281 if (cycle == 0) return;
03282
03283 if (m_labeller) m_labeller->setCounterCycleSize(cycle);
03284
03285 QSettings settings;
03286 settings.beginGroup("MainWindow");
03287 settings.setValue("labellercycle", cycle);
03288 settings.endGroup();
03289 }
03290
03291 void
03292 MainWindow::resetInstantsCounters()
03293 {
03294 LabelCounterInputDialog dialog(m_labeller, this);
03295 dialog.setWindowTitle(tr("Reset Counters"));
03296 dialog.exec();
03297 }
03298
03299 void
03300 MainWindow::modelGenerationFailed(QString transformName, QString message)
03301 {
03302 if (message != "") {
03303
03304 QMessageBox::warning
03305 (this,
03306 tr("Failed to generate layer"),
03307 tr("<b>Layer generation failed</b><p>Failed to generate derived layer.<p>The layer transform \"%1\" failed:<p>%2")
03308 .arg(transformName).arg(message),
03309 QMessageBox::Ok);
03310 } else {
03311 QMessageBox::warning
03312 (this,
03313 tr("Failed to generate layer"),
03314 tr("<b>Layer generation failed</b><p>Failed to generate a derived layer.<p>The layer transform \"%1\" failed.<p>No error information is available.")
03315 .arg(transformName),
03316 QMessageBox::Ok);
03317 }
03318 }
03319
03320 void
03321 MainWindow::modelGenerationWarning(QString transformName, QString message)
03322 {
03323 QMessageBox::warning
03324 (this, tr("Warning"), message, QMessageBox::Ok);
03325 }
03326
03327 void
03328 MainWindow::modelRegenerationFailed(QString layerName,
03329 QString transformName, QString message)
03330 {
03331 if (message != "") {
03332
03333 QMessageBox::warning
03334 (this,
03335 tr("Failed to regenerate layer"),
03336 tr("<b>Layer generation failed</b><p>Failed to regenerate derived layer \"%1\" using new data model as input.<p>The layer transform \"%2\" failed:<p>%3")
03337 .arg(layerName).arg(transformName).arg(message),
03338 QMessageBox::Ok);
03339 } else {
03340 QMessageBox::warning
03341 (this,
03342 tr("Failed to regenerate layer"),
03343 tr("<b>Layer generation failed</b><p>Failed to regenerate derived layer \"%1\" using new data model as input.<p>The layer transform \"%2\" failed.<p>No error information is available.")
03344 .arg(layerName).arg(transformName),
03345 QMessageBox::Ok);
03346 }
03347 }
03348
03349 void
03350 MainWindow::modelRegenerationWarning(QString layerName,
03351 QString transformName, QString message)
03352 {
03353 QMessageBox::warning
03354 (this, tr("Warning"), tr("<b>Warning when regenerating layer</b><p>When regenerating the derived layer \"%1\" using new data model as input:<p>%2").arg(layerName).arg(message), QMessageBox::Ok);
03355 }
03356
03357 void
03358 MainWindow::alignmentFailed(QString transformName, QString message)
03359 {
03360 QMessageBox::warning
03361 (this,
03362 tr("Failed to calculate alignment"),
03363 tr("<b>Alignment calculation failed</b><p>Failed to calculate an audio alignment using transform \"%1\":<p>%2")
03364 .arg(transformName).arg(message),
03365 QMessageBox::Ok);
03366 }
03367
03368 void
03369 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
03370 {
03371
03372 m_paneStack->setCurrentPane(pane);
03373 m_rightButtonMenu->popup(position);
03374 }
03375
03376 void
03377 MainWindow::showLayerTree()
03378 {
03379 if (!m_layerTreeDialog.isNull()) {
03380 m_layerTreeDialog->show();
03381 m_layerTreeDialog->raise();
03382 return;
03383 }
03384
03385 m_layerTreeDialog = new LayerTreeDialog(m_paneStack);
03386 m_layerTreeDialog->setAttribute(Qt::WA_DeleteOnClose);
03387 m_layerTreeDialog->show();
03388 }
03389
03390 void
03391 MainWindow::preferences()
03392 {
03393 if (!m_preferencesDialog.isNull()) {
03394 m_preferencesDialog->show();
03395 m_preferencesDialog->raise();
03396 return;
03397 }
03398
03399 m_preferencesDialog = new PreferencesDialog(this);
03400
03401
03402
03403
03404
03405
03406
03407 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
03408
03409 m_preferencesDialog->show();
03410 }
03411
03412 void
03413 MainWindow::mouseEnteredWidget()
03414 {
03415 QWidget *w = dynamic_cast<QWidget *>(sender());
03416 if (!w) return;
03417
03418 if (w == m_fader) {
03419 contextHelpChanged(tr("Adjust the master playback level"));
03420 } else if (w == m_playSpeed) {
03421 contextHelpChanged(tr("Adjust the master playback speed"));
03422 }
03423 }
03424
03425 void
03426 MainWindow::mouseLeftWidget()
03427 {
03428 contextHelpChanged("");
03429 }
03430
03431 void
03432 MainWindow::website()
03433 {
03434 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
03435 }
03436
03437 void
03438 MainWindow::help()
03439 {
03440 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/1.2/en/"));
03441 }
03442
03443 void
03444 MainWindow::about()
03445 {
03446 bool debug = false;
03447 QString version = "(unknown version)";
03448
03449 #ifdef BUILD_DEBUG
03450 debug = true;
03451 #endif
03452 #ifdef SV_VERSION
03453 #ifdef SVNREV
03454 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
03455 #else
03456 version = tr("Release %1").arg(SV_VERSION);
03457 #endif
03458 #else
03459 #ifdef SVNREV
03460 version = tr("Unreleased : Revision %1").arg(SVNREV);
03461 #endif
03462 #endif
03463
03464 QString aboutText;
03465
03466 aboutText += tr("<h3>About Sonic Visualiser</h3>");
03467 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for semantic music analysis and annotation.</p>");
03468 aboutText += tr("<p>%1 : %2 configuration</p>")
03469 .arg(version)
03470 .arg(debug ? tr("Debug") : tr("Release"));
03471
03472 #ifndef BUILD_STATIC
03473 aboutText += tr("<br>Using Qt v%1 © Trolltech AS").arg(QT_VERSION_STR);
03474 #else
03475 #ifdef QT_SHARED
03476 aboutText += tr("<br>Using Qt v%1 © Trolltech AS").arg(QT_VERSION_STR);
03477 #endif
03478 #endif
03479
03480 #ifdef BUILD_STATIC
03481 aboutText += tr("<p>Statically linked");
03482 #ifndef QT_SHARED
03483 aboutText += tr("<br>With Qt (v%1) © Trolltech AS").arg(QT_VERSION_STR);
03484 #endif
03485 #ifdef HAVE_JACK
03486 #ifdef JACK_VERSION
03487 aboutText += tr("<br>With JACK audio output (v%1) © Paul Davis and Jack O'Quin").arg(JACK_VERSION);
03488 #else
03489 aboutText += tr("<br>With JACK audio output © Paul Davis and Jack O'Quin");
03490 #endif
03491 #endif
03492 #ifdef HAVE_PORTAUDIO
03493 aboutText += tr("<br>With PortAudio audio output © Ross Bencina and Phil Burk");
03494 #endif
03495 #ifdef HAVE_OGGZ
03496 #ifdef OGGZ_VERSION
03497 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) © CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
03498 #else
03499 aboutText += tr("<br>With Ogg file decoder © CSIRO Australia");
03500 #endif
03501 #endif
03502 #ifdef HAVE_MAD
03503 #ifdef MAD_VERSION
03504 aboutText += tr("<br>With MAD mp3 decoder (v%1) © Underbit Technologies Inc").arg(MAD_VERSION);
03505 #else
03506 aboutText += tr("<br>With MAD mp3 decoder © Underbit Technologies Inc");
03507 #endif
03508 #endif
03509 #ifdef HAVE_SAMPLERATE
03510 #ifdef SAMPLERATE_VERSION
03511 aboutText += tr("<br>With libsamplerate (v%1) © Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
03512 #else
03513 aboutText += tr("<br>With libsamplerate © Erik de Castro Lopo");
03514 #endif
03515 #endif
03516 #ifdef HAVE_SNDFILE
03517 #ifdef SNDFILE_VERSION
03518 aboutText += tr("<br>With libsndfile (v%1) © Erik de Castro Lopo").arg(SNDFILE_VERSION);
03519 #else
03520 aboutText += tr("<br>With libsndfile © Erik de Castro Lopo");
03521 #endif
03522 #endif
03523 #ifdef HAVE_FFTW3F
03524 #ifdef FFTW3_VERSION
03525 aboutText += tr("<br>With FFTW3 (v%1) © Matteo Frigo and MIT").arg(FFTW3_VERSION);
03526 #else
03527 aboutText += tr("<br>With FFTW3 © Matteo Frigo and MIT");
03528 #endif
03529 #endif
03530 #ifdef HAVE_VAMP
03531 aboutText += tr("<br>With Vamp plugin support (API v%1, host SDK v%2) © Chris Cannam").arg(VAMP_API_VERSION).arg(VAMP_SDK_VERSION);
03532 #endif
03533 aboutText += tr("<br>With LADSPA plugin support (API v%1) © Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
03534 aboutText += tr("<br>With DSSI plugin support (API v%1) © Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
03535 #ifdef HAVE_LIBLO
03536 #ifdef LIBLO_VERSION
03537 aboutText += tr("<br>With liblo Lite OSC library (v%1) © Steve Harris").arg(LIBLO_VERSION);
03538 #else
03539 aboutText += tr("<br>With liblo Lite OSC library © Steve Harris").arg(LIBLO_VERSION);
03540 #endif
03541 if (m_oscQueue && m_oscQueue->isOK()) {
03542 aboutText += tr("<p>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
03543 }
03544 #endif
03545 aboutText += "</p>";
03546 #endif
03547
03548 aboutText +=
03549 "<p>Sonic Visualiser Copyright © 2005 - 2008 Chris Cannam and "
03550 "Queen Mary, University of London.</p>"
03551 "<p>This program is free software; you can redistribute it and/or "
03552 "modify it under the terms of the GNU General Public License as "
03553 "published by the Free Software Foundation; either version 2 of the "
03554 "License, or (at your option) any later version.<br>See the file "
03555 "COPYING included with this distribution for more information.</p>";
03556
03557 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
03558 }
03559
03560 void
03561 MainWindow::keyReference()
03562 {
03563 m_keyReference->show();
03564 }
03565