annotate main/MainWindow.cpp @ 66:cf27fc7feb7a

* Add Pane menu entries for generating spectrogram etc from non-main models * Some restructuring of MainWindow menu setup code
author Chris Cannam
date Fri, 20 Oct 2006 16:47:13 +0000
parents 77c083741589
children 0229bec2d2dc
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 Sonic Visualiser
Chris@0 5 An audio file viewer and annotation editor.
Chris@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@0 9 This program is free software; you can redistribute it and/or
Chris@0 10 modify it under the terms of the GNU General Public License as
Chris@0 11 published by the Free Software Foundation; either version 2 of the
Chris@0 12 License, or (at your option) any later version. See the file
Chris@0 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@1 16 #include "version.h"
Chris@0 17
Chris@0 18 #include "MainWindow.h"
Chris@1 19 #include "document/Document.h"
Chris@0 20 #include "PreferencesDialog.h"
Chris@0 21
Chris@1 22 #include "view/Pane.h"
Chris@1 23 #include "view/PaneStack.h"
Chris@1 24 #include "data/model/WaveFileModel.h"
Chris@1 25 #include "data/model/SparseOneDimensionalModel.h"
Chris@1 26 #include "view/ViewManager.h"
Chris@0 27 #include "base/Preferences.h"
Chris@0 28 #include "layer/WaveformLayer.h"
Chris@0 29 #include "layer/TimeRulerLayer.h"
Chris@0 30 #include "layer/TimeInstantLayer.h"
Chris@0 31 #include "layer/TimeValueLayer.h"
Chris@0 32 #include "layer/Colour3DPlotLayer.h"
Chris@0 33 #include "widgets/Fader.h"
Chris@65 34 #include "view/Overview.h"
Chris@0 35 #include "widgets/PropertyBox.h"
Chris@0 36 #include "widgets/PropertyStack.h"
Chris@0 37 #include "widgets/AudioDial.h"
Chris@0 38 #include "widgets/LayerTree.h"
Chris@0 39 #include "widgets/ListInputDialog.h"
Chris@36 40 #include "widgets/SubdividingMenu.h"
Chris@0 41 #include "audioio/AudioCallbackPlaySource.h"
Chris@0 42 #include "audioio/AudioCallbackPlayTarget.h"
Chris@0 43 #include "audioio/AudioTargetFactory.h"
Chris@59 44 #include "audioio/PlaySpeedRangeMapper.h"
Chris@1 45 #include "data/fileio/AudioFileReaderFactory.h"
Chris@1 46 #include "data/fileio/DataFileReaderFactory.h"
Chris@1 47 #include "data/fileio/WavFileWriter.h"
Chris@1 48 #include "data/fileio/CSVFileWriter.h"
Chris@1 49 #include "data/fileio/BZipFileDevice.h"
Chris@1 50 #include "base/RecentFiles.h"
Chris@0 51 #include "transform/TransformFactory.h"
Chris@0 52 #include "base/PlayParameterRepository.h"
Chris@0 53 #include "base/XmlExportable.h"
Chris@0 54 #include "base/CommandHistory.h"
Chris@0 55 #include "base/Profiler.h"
Chris@0 56 #include "base/Clipboard.h"
Chris@0 57
Chris@0 58 // For version information
Chris@0 59 #include "vamp/vamp.h"
Chris@0 60 #include "vamp-sdk/PluginBase.h"
Chris@0 61 #include "plugin/api/ladspa.h"
Chris@0 62 #include "plugin/api/dssi.h"
Chris@0 63
Chris@0 64 #include <QApplication>
Chris@0 65 #include <QPushButton>
Chris@0 66 #include <QFileDialog>
Chris@0 67 #include <QMessageBox>
Chris@0 68 #include <QGridLayout>
Chris@0 69 #include <QLabel>
Chris@0 70 #include <QAction>
Chris@0 71 #include <QMenuBar>
Chris@0 72 #include <QToolBar>
Chris@0 73 #include <QInputDialog>
Chris@0 74 #include <QStatusBar>
Chris@0 75 #include <QTreeView>
Chris@0 76 #include <QFile>
Chris@0 77 #include <QTextStream>
Chris@0 78 #include <QProcess>
Chris@7 79 #include <QShortcut>
Chris@5 80 #include <QSettings>
Chris@11 81 #include <QDateTime>
Chris@11 82 #include <QProcess>
Chris@16 83 #include <QCheckBox>
Chris@55 84 #include <QRegExp>
Chris@0 85
Chris@0 86 #include <iostream>
Chris@0 87 #include <cstdio>
Chris@0 88 #include <errno.h>
Chris@0 89
Chris@0 90 using std::cerr;
Chris@0 91 using std::endl;
Chris@0 92
Chris@33 93 using std::vector;
Chris@33 94 using std::map;
Chris@33 95 using std::set;
Chris@33 96
Chris@0 97
Chris@46 98 MainWindow::MainWindow(bool withAudioOutput) :
Chris@0 99 m_document(0),
Chris@0 100 m_paneStack(0),
Chris@0 101 m_viewManager(0),
Chris@65 102 m_overview(0),
Chris@0 103 m_timeRulerLayer(0),
Chris@46 104 m_audioOutput(withAudioOutput),
Chris@0 105 m_playSource(0),
Chris@0 106 m_playTarget(0),
Chris@34 107 m_recentFiles("RecentFiles"),
Chris@49 108 m_recentTransforms("RecentTransforms", 20),
Chris@0 109 m_mainMenusCreated(false),
Chris@0 110 m_paneMenu(0),
Chris@0 111 m_layerMenu(0),
Chris@34 112 m_transformsMenu(0),
Chris@0 113 m_existingLayersMenu(0),
Chris@34 114 m_recentFilesMenu(0),
Chris@34 115 m_recentTransformsMenu(0),
Chris@0 116 m_rightButtonMenu(0),
Chris@0 117 m_rightButtonLayerMenu(0),
Chris@34 118 m_rightButtonTransformsMenu(0),
Chris@0 119 m_documentModified(false),
Chris@0 120 m_preferencesDialog(0)
Chris@0 121 {
Chris@0 122 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 123
Chris@0 124 UnitDatabase::getInstance()->registerUnit("Hz");
Chris@0 125 UnitDatabase::getInstance()->registerUnit("dB");
Chris@0 126
Chris@0 127 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
Chris@0 128 this, SLOT(documentModified()));
Chris@0 129 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
Chris@0 130 this, SLOT(documentRestored()));
Chris@0 131
Chris@0 132 QFrame *frame = new QFrame;
Chris@0 133 setCentralWidget(frame);
Chris@0 134
Chris@0 135 QGridLayout *layout = new QGridLayout;
Chris@0 136
Chris@0 137 m_viewManager = new ViewManager();
Chris@0 138 connect(m_viewManager, SIGNAL(selectionChanged()),
Chris@0 139 this, SLOT(updateMenuStates()));
Chris@0 140
Chris@0 141 m_descriptionLabel = new QLabel;
Chris@0 142
Chris@0 143 m_paneStack = new PaneStack(frame, m_viewManager);
Chris@0 144 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
Chris@0 145 this, SLOT(currentPaneChanged(Pane *)));
Chris@0 146 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
Chris@0 147 this, SLOT(currentLayerChanged(Pane *, Layer *)));
Chris@0 148 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
Chris@0 149 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
Chris@0 150
Chris@65 151 m_overview = new Overview(frame);
Chris@65 152 m_overview->setViewManager(m_viewManager);
Chris@65 153 m_overview->setFixedHeight(40);
Chris@0 154
Chris@0 155 m_panLayer = new WaveformLayer;
Chris@0 156 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
Chris@0 157 // m_panLayer->setScale(WaveformLayer::MeterScale);
Chris@39 158 // m_panLayer->setAutoNormalize(true);
Chris@0 159 m_panLayer->setBaseColour(Qt::darkGreen);
Chris@0 160 m_panLayer->setAggressiveCacheing(true);
Chris@65 161 m_overview->addLayer(m_panLayer);
Chris@0 162
Chris@0 163 m_playSource = new AudioCallbackPlaySource(m_viewManager);
Chris@0 164
Chris@0 165 connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)),
Chris@0 166 this, SLOT(sampleRateMismatch(size_t, size_t, bool)));
Chris@42 167 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
Chris@42 168 this, SLOT(audioOverloadPluginDisabled()));
Chris@0 169
Chris@0 170 m_fader = new Fader(frame, false);
Chris@0 171
Chris@0 172 m_playSpeed = new AudioDial(frame);
Chris@12 173 m_playSpeed->setMinimum(0);
Chris@48 174 m_playSpeed->setMaximum(200);
Chris@25 175 m_playSpeed->setValue(100);
Chris@0 176 m_playSpeed->setFixedWidth(24);
Chris@0 177 m_playSpeed->setFixedHeight(24);
Chris@0 178 m_playSpeed->setNotchesVisible(true);
Chris@25 179 m_playSpeed->setPageStep(10);
Chris@60 180 m_playSpeed->setObjectName(tr("Playback Speedup"));
Chris@25 181 m_playSpeed->setDefaultValue(100);
Chris@59 182 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
Chris@60 183 m_playSpeed->setShowToolTip(true);
Chris@0 184 connect(m_playSpeed, SIGNAL(valueChanged(int)),
Chris@0 185 this, SLOT(playSpeedChanged(int)));
Chris@0 186
Chris@26 187 m_playSharpen = new QPushButton(frame);
Chris@17 188 m_playSharpen->setToolTip(tr("Sharpen percussive transients"));
Chris@26 189 m_playSharpen->setFixedSize(20, 20);
Chris@26 190 // m_playSharpen->setFlat(true);
Chris@16 191 m_playSharpen->setEnabled(false);
Chris@26 192 m_playSharpen->setCheckable(true);
Chris@26 193 m_playSharpen->setChecked(false);
Chris@26 194 m_playSharpen->setIcon(QIcon(":icons/sharpen.png"));
Chris@26 195 connect(m_playSharpen, SIGNAL(clicked()), this, SLOT(playSharpenToggled()));
Chris@26 196
Chris@26 197 m_playMono = new QPushButton(frame);
Chris@26 198 m_playMono->setToolTip(tr("Run time stretcher in mono only"));
Chris@26 199 m_playMono->setFixedSize(20, 20);
Chris@26 200 // m_playMono->setFlat(true);
Chris@26 201 m_playMono->setEnabled(false);
Chris@26 202 m_playMono->setCheckable(true);
Chris@26 203 m_playMono->setChecked(false);
Chris@26 204 m_playMono->setIcon(QIcon(":icons/mono.png"));
Chris@26 205 connect(m_playMono, SIGNAL(clicked()), this, SLOT(playMonoToggled()));
Chris@21 206
Chris@21 207 QSettings settings;
Chris@21 208 settings.beginGroup("MainWindow");
Chris@24 209 m_playSharpen->setChecked(settings.value("playsharpen", true).toBool());
Chris@26 210 m_playMono->setChecked(settings.value("playmono", false).toBool());
Chris@21 211 settings.endGroup();
Chris@21 212
Chris@26 213 layout->addWidget(m_paneStack, 0, 0, 1, 5);
Chris@65 214 layout->addWidget(m_overview, 1, 0);
Chris@0 215 layout->addWidget(m_fader, 1, 1);
Chris@0 216 layout->addWidget(m_playSpeed, 1, 2);
Chris@16 217 layout->addWidget(m_playSharpen, 1, 3);
Chris@26 218 layout->addWidget(m_playMono, 1, 4);
Chris@16 219
Chris@16 220 layout->setColumnStretch(0, 10);
Chris@16 221
Chris@0 222 frame->setLayout(layout);
Chris@0 223
Chris@0 224 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
Chris@0 225 this, SLOT(outputLevelsChanged(float, float)));
Chris@0 226
Chris@0 227 connect(Preferences::getInstance(),
Chris@0 228 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
Chris@0 229 this,
Chris@0 230 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
Chris@0 231
Chris@0 232 setupMenus();
Chris@0 233 setupToolbars();
Chris@0 234
Chris@47 235 // statusBar()->addWidget(m_descriptionLabel);
Chris@0 236
Chris@0 237 newSession();
Chris@0 238 }
Chris@0 239
Chris@0 240 MainWindow::~MainWindow()
Chris@0 241 {
Chris@0 242 closeSession();
Chris@0 243 delete m_playTarget;
Chris@0 244 delete m_playSource;
Chris@0 245 delete m_viewManager;
Chris@0 246 Profiles::getInstance()->dump();
Chris@0 247 }
Chris@0 248
Chris@0 249 void
Chris@0 250 MainWindow::setupMenus()
Chris@0 251 {
Chris@0 252 if (!m_mainMenusCreated) {
Chris@0 253 m_rightButtonMenu = new QMenu();
Chris@0 254 }
Chris@0 255
Chris@0 256 if (m_rightButtonLayerMenu) {
Chris@0 257 m_rightButtonLayerMenu->clear();
Chris@0 258 } else {
Chris@0 259 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
Chris@0 260 m_rightButtonMenu->addSeparator();
Chris@0 261 }
Chris@0 262
Chris@34 263 if (m_rightButtonTransformsMenu) {
Chris@34 264 m_rightButtonTransformsMenu->clear();
Chris@34 265 } else {
Chris@34 266 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
Chris@34 267 m_rightButtonMenu->addSeparator();
Chris@34 268 }
Chris@34 269
Chris@0 270 if (!m_mainMenusCreated) {
Chris@0 271 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
Chris@0 272 m_rightButtonMenu->addSeparator();
Chris@66 273 }
Chris@66 274
Chris@66 275 setupFileMenu();
Chris@66 276 setupEditMenu();
Chris@66 277 setupViewMenu();
Chris@66 278 setupPaneAndLayerMenus();
Chris@66 279 setupTransformsMenu();
Chris@66 280 setupHelpMenu();
Chris@66 281
Chris@66 282 m_mainMenusCreated = true;
Chris@66 283 }
Chris@66 284
Chris@66 285 void
Chris@66 286 MainWindow::setupFileMenu()
Chris@66 287 {
Chris@66 288 if (m_mainMenusCreated) return;
Chris@66 289
Chris@66 290 QMenu *menu = menuBar()->addMenu(tr("&File"));
Chris@66 291 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
Chris@66 292
Chris@66 293 QIcon icon(":icons/filenew.png");
Chris@66 294 icon.addFile(":icons/filenew-22.png");
Chris@66 295 QAction *action = new QAction(icon, tr("&New Session"), this);
Chris@66 296 action->setShortcut(tr("Ctrl+N"));
Chris@66 297 action->setStatusTip(tr("Clear the current Sonic Visualiser session and start a new one"));
Chris@66 298 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
Chris@66 299 menu->addAction(action);
Chris@66 300 toolbar->addAction(action);
Chris@0 301
Chris@66 302 icon = QIcon(":icons/fileopen.png");
Chris@66 303 icon.addFile(":icons/fileopen-22.png");
Chris@66 304
Chris@66 305 action = new QAction(icon, tr("&Open Session..."), this);
Chris@66 306 action->setShortcut(tr("Ctrl+O"));
Chris@66 307 action->setStatusTip(tr("Open a previously saved Sonic Visualiser session file"));
Chris@66 308 connect(action, SIGNAL(triggered()), this, SLOT(openSession()));
Chris@66 309 menu->addAction(action);
Chris@66 310
Chris@66 311 action = new QAction(icon, tr("&Open..."), this);
Chris@66 312 action->setStatusTip(tr("Open a session file, audio file, or layer"));
Chris@66 313 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
Chris@66 314 toolbar->addAction(action);
Chris@66 315
Chris@66 316 icon = QIcon(":icons/filesave.png");
Chris@66 317 icon.addFile(":icons/filesave-22.png");
Chris@66 318 action = new QAction(icon, tr("&Save Session"), this);
Chris@66 319 action->setShortcut(tr("Ctrl+S"));
Chris@66 320 action->setStatusTip(tr("Save the current session into a Sonic Visualiser session file"));
Chris@66 321 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
Chris@66 322 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
Chris@66 323 menu->addAction(action);
Chris@66 324 toolbar->addAction(action);
Chris@0 325
Chris@66 326 icon = QIcon(":icons/filesaveas.png");
Chris@66 327 icon.addFile(":icons/filesaveas-22.png");
Chris@66 328 action = new QAction(icon, tr("Save Session &As..."), this);
Chris@66 329 action->setStatusTip(tr("Save the current session into a new Sonic Visualiser session file"));
Chris@66 330 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
Chris@66 331 menu->addAction(action);
Chris@66 332 toolbar->addAction(action);
Chris@66 333
Chris@66 334 menu->addSeparator();
Chris@66 335
Chris@66 336 action = new QAction(tr("&Import Audio File..."), this);
Chris@66 337 action->setShortcut(tr("Ctrl+I"));
Chris@66 338 action->setStatusTip(tr("Import an existing audio file"));
Chris@66 339 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
Chris@66 340 menu->addAction(action);
Chris@66 341
Chris@66 342 action = new QAction(tr("Import Secondary Audio File..."), this);
Chris@66 343 action->setShortcut(tr("Ctrl+Shift+I"));
Chris@66 344 action->setStatusTip(tr("Import an extra audio file as a separate layer"));
Chris@66 345 connect(action, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
Chris@66 346 connect(this, SIGNAL(canImportMoreAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@66 347 menu->addAction(action);
Chris@66 348
Chris@66 349 action = new QAction(tr("&Export Audio File..."), this);
Chris@66 350 action->setStatusTip(tr("Export selection as an audio file"));
Chris@66 351 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
Chris@66 352 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@66 353 menu->addAction(action);
Chris@66 354
Chris@66 355 menu->addSeparator();
Chris@66 356
Chris@66 357 action = new QAction(tr("Import Annotation &Layer..."), this);
Chris@66 358 action->setShortcut(tr("Ctrl+L"));
Chris@66 359 action->setStatusTip(tr("Import layer data from an existing file"));
Chris@66 360 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
Chris@66 361 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 362 menu->addAction(action);
Chris@66 363
Chris@66 364 action = new QAction(tr("Export Annotation Layer..."), this);
Chris@66 365 action->setStatusTip(tr("Export layer data to a file"));
Chris@66 366 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
Chris@66 367 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 368 menu->addAction(action);
Chris@66 369
Chris@66 370 menu->addSeparator();
Chris@66 371 m_recentFilesMenu = menu->addMenu(tr("&Recent Files"));
Chris@66 372 setupRecentFilesMenu();
Chris@66 373 connect(&m_recentFiles, SIGNAL(recentChanged()),
Chris@66 374 this, SLOT(setupRecentFilesMenu()));
Chris@66 375
Chris@66 376 menu->addSeparator();
Chris@66 377 action = new QAction(tr("&Preferences..."), this);
Chris@66 378 action->setStatusTip(tr("Adjust the application preferences"));
Chris@66 379 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
Chris@66 380 menu->addAction(action);
Chris@0 381
Chris@66 382 /*!!!
Chris@66 383 menu->addSeparator();
Chris@0 384
Chris@66 385 action = new QAction(tr("Play / Pause"), this);
Chris@66 386 action->setShortcut(tr("Space"));
Chris@66 387 action->setStatusTip(tr("Start or stop playback from the current position"));
Chris@66 388 connect(action, SIGNAL(triggered()), this, SLOT(play()));
Chris@66 389 menu->addAction(action);
Chris@66 390 */
Chris@66 391
Chris@66 392 menu->addSeparator();
Chris@66 393 action = new QAction(QIcon(":/icons/exit.png"),
Chris@66 394 tr("&Quit"), this);
Chris@66 395 action->setShortcut(tr("Ctrl+Q"));
Chris@66 396 connect(action, SIGNAL(triggered()), this, SLOT(close()));
Chris@66 397 menu->addAction(action);
Chris@66 398 }
Chris@66 399
Chris@66 400 void
Chris@66 401 MainWindow::setupEditMenu()
Chris@66 402 {
Chris@66 403 if (m_mainMenusCreated) return;
Chris@66 404
Chris@66 405 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
Chris@66 406 CommandHistory::getInstance()->registerMenu(menu);
Chris@66 407
Chris@66 408 menu->addSeparator();
Chris@66 409
Chris@66 410 QAction *action = new QAction(QIcon(":/icons/editcut.png"),
Chris@66 411 tr("Cu&t"), this);
Chris@66 412 action->setShortcut(tr("Ctrl+X"));
Chris@66 413 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
Chris@66 414 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@66 415 menu->addAction(action);
Chris@66 416 m_rightButtonMenu->addAction(action);
Chris@66 417
Chris@66 418 action = new QAction(QIcon(":/icons/editcopy.png"),
Chris@66 419 tr("&Copy"), this);
Chris@66 420 action->setShortcut(tr("Ctrl+C"));
Chris@66 421 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
Chris@66 422 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@66 423 menu->addAction(action);
Chris@66 424 m_rightButtonMenu->addAction(action);
Chris@66 425
Chris@66 426 action = new QAction(QIcon(":/icons/editpaste.png"),
Chris@66 427 tr("&Paste"), this);
Chris@66 428 action->setShortcut(tr("Ctrl+V"));
Chris@66 429 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
Chris@66 430 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
Chris@66 431 menu->addAction(action);
Chris@66 432 m_rightButtonMenu->addAction(action);
Chris@66 433
Chris@66 434 action = new QAction(tr("&Delete Selected Items"), this);
Chris@66 435 action->setShortcut(tr("Del"));
Chris@66 436 connect(action, SIGNAL(triggered()), this, SLOT(deleteSelected()));
Chris@66 437 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@66 438 menu->addAction(action);
Chris@66 439 m_rightButtonMenu->addAction(action);
Chris@66 440
Chris@66 441 menu->addSeparator();
Chris@66 442 m_rightButtonMenu->addSeparator();
Chris@0 443
Chris@66 444 action = new QAction(tr("Select &All"), this);
Chris@66 445 action->setShortcut(tr("Ctrl+A"));
Chris@66 446 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
Chris@66 447 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@66 448 menu->addAction(action);
Chris@66 449 m_rightButtonMenu->addAction(action);
Chris@0 450
Chris@66 451 action = new QAction(tr("Select &Visible Range"), this);
Chris@66 452 action->setShortcut(tr("Ctrl+Shift+A"));
Chris@66 453 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
Chris@66 454 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@66 455 menu->addAction(action);
Chris@0 456
Chris@66 457 action = new QAction(tr("Select to &Start"), this);
Chris@66 458 action->setShortcut(tr("Shift+Left"));
Chris@66 459 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
Chris@66 460 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@66 461 menu->addAction(action);
Chris@0 462
Chris@66 463 action = new QAction(tr("Select to &End"), this);
Chris@66 464 action->setShortcut(tr("Shift+Right"));
Chris@66 465 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
Chris@66 466 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@66 467 menu->addAction(action);
Chris@66 468
Chris@66 469 action = new QAction(tr("C&lear Selection"), this);
Chris@66 470 action->setShortcut(tr("Esc"));
Chris@66 471 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
Chris@66 472 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@66 473 menu->addAction(action);
Chris@66 474 m_rightButtonMenu->addAction(action);
Chris@66 475
Chris@66 476 menu->addSeparator();
Chris@66 477
Chris@66 478 action = new QAction(tr("&Insert Instant at Playback Position"), this);
Chris@66 479 action->setShortcut(tr("Enter"));
Chris@66 480 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
Chris@66 481 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
Chris@66 482 menu->addAction(action);
Chris@66 483
Chris@66 484 // Laptop shortcut (no keypad Enter key)
Chris@66 485 connect(new QShortcut(tr(";"), this), SIGNAL(activated()),
Chris@66 486 this, SLOT(insertInstant()));
Chris@66 487 }
Chris@66 488
Chris@66 489 void
Chris@66 490 MainWindow::setupViewMenu()
Chris@66 491 {
Chris@66 492 if (m_mainMenusCreated) return;
Chris@66 493
Chris@66 494 QMenu *menu = menuBar()->addMenu(tr("&View"));
Chris@66 495
Chris@66 496 QActionGroup *overlayGroup = new QActionGroup(this);
Chris@0 497
Chris@66 498 QAction *action = new QAction(tr("&No Text Overlays"), this);
Chris@66 499 action->setShortcut(tr("0"));
Chris@66 500 action->setStatusTip(tr("Show no texts for frame times, layer names etc"));
Chris@66 501 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
Chris@66 502 action->setCheckable(true);
Chris@66 503 action->setChecked(false);
Chris@66 504 overlayGroup->addAction(action);
Chris@66 505 menu->addAction(action);
Chris@0 506
Chris@66 507 action = new QAction(tr("Basic &Text Overlays"), this);
Chris@66 508 action->setShortcut(tr("9"));
Chris@66 509 action->setStatusTip(tr("Show texts for frame times etc, but not layer names etc"));
Chris@66 510 connect(action, SIGNAL(triggered()), this, SLOT(showBasicOverlays()));
Chris@66 511 action->setCheckable(true);
Chris@66 512 action->setChecked(true);
Chris@66 513 overlayGroup->addAction(action);
Chris@66 514 menu->addAction(action);
Chris@0 515
Chris@66 516 action = new QAction(tr("&All Text Overlays"), this);
Chris@66 517 action->setShortcut(tr("8"));
Chris@66 518 action->setStatusTip(tr("Show texts for frame times, layer names etc"));
Chris@66 519 connect(action, SIGNAL(triggered()), this, SLOT(showAllTextOverlays()));
Chris@66 520 action->setCheckable(true);
Chris@66 521 action->setChecked(false);
Chris@66 522 overlayGroup->addAction(action);
Chris@66 523 menu->addAction(action);
Chris@66 524
Chris@66 525 menu->addSeparator();
Chris@0 526
Chris@66 527 action = new QAction(tr("Scroll &Left"), this);
Chris@66 528 action->setShortcut(tr("Left"));
Chris@66 529 action->setStatusTip(tr("Scroll the current pane to the left"));
Chris@66 530 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
Chris@66 531 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@66 532 menu->addAction(action);
Chris@0 533
Chris@66 534 action = new QAction(tr("Scroll &Right"), this);
Chris@66 535 action->setShortcut(tr("Right"));
Chris@66 536 action->setStatusTip(tr("Scroll the current pane to the right"));
Chris@66 537 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
Chris@66 538 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@66 539 menu->addAction(action);
Chris@0 540
Chris@66 541 action = new QAction(tr("Jump Left"), this);
Chris@66 542 action->setShortcut(tr("Ctrl+Left"));
Chris@66 543 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
Chris@66 544 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
Chris@66 545 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@66 546 menu->addAction(action);
Chris@0 547
Chris@66 548 action = new QAction(tr("Jump Right"), this);
Chris@66 549 action->setShortcut(tr("Ctrl+Right"));
Chris@66 550 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
Chris@66 551 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
Chris@66 552 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@66 553 menu->addAction(action);
Chris@66 554
Chris@66 555 menu->addSeparator();
Chris@66 556
Chris@66 557 action = new QAction(QIcon(":/icons/zoom-in.png"),
Chris@66 558 tr("Zoom &In"), this);
Chris@66 559 action->setShortcut(tr("Up"));
Chris@66 560 action->setStatusTip(tr("Increase the zoom level"));
Chris@66 561 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
Chris@66 562 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 563 menu->addAction(action);
Chris@0 564
Chris@66 565 action = new QAction(QIcon(":/icons/zoom-out.png"),
Chris@66 566 tr("Zoom &Out"), this);
Chris@66 567 action->setShortcut(tr("Down"));
Chris@66 568 action->setStatusTip(tr("Decrease the zoom level"));
Chris@66 569 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
Chris@66 570 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 571 menu->addAction(action);
Chris@0 572
Chris@66 573 action = new QAction(tr("Restore &Default Zoom"), this);
Chris@66 574 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
Chris@66 575 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 576 menu->addAction(action);
Chris@66 577
Chris@66 578 action = new QAction(tr("Zoom to &Fit"), this);
Chris@66 579 action->setStatusTip(tr("Zoom to show the whole file"));
Chris@66 580 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
Chris@66 581 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 582 menu->addAction(action);
Chris@7 583
Chris@66 584 action = new QAction(tr("Show &Zoom Wheels"), this);
Chris@66 585 action->setShortcut(tr("Z"));
Chris@66 586 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
Chris@66 587 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
Chris@66 588 action->setCheckable(true);
Chris@66 589 action->setChecked(m_viewManager->getZoomWheelsEnabled());
Chris@66 590 menu->addAction(action);
Chris@0 591
Chris@0 592 /*!!! This one doesn't work properly yet
Chris@62 593 */
Chris@66 594 menu->addSeparator();
Chris@66 595
Chris@66 596 action = new QAction(tr("Show &Layer Hierarchy"), this);
Chris@66 597 action->setShortcut(tr("Alt+L"));
Chris@66 598 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
Chris@66 599 menu->addAction(action);
Chris@62 600 /* */
Chris@66 601 }
Chris@66 602
Chris@66 603 void
Chris@66 604 MainWindow::setupPaneAndLayerMenus()
Chris@66 605 {
Chris@0 606 if (m_paneMenu) {
Chris@0 607 m_paneActions.clear();
Chris@0 608 m_paneMenu->clear();
Chris@0 609 } else {
Chris@0 610 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
Chris@0 611 }
Chris@0 612
Chris@0 613 if (m_layerMenu) {
Chris@0 614 m_layerActions.clear();
Chris@0 615 m_layerMenu->clear();
Chris@0 616 } else {
Chris@0 617 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
Chris@0 618 }
Chris@0 619
Chris@66 620 QMenu *menu = m_paneMenu;
Chris@66 621
Chris@66 622 QAction *action = new QAction(QIcon(":/icons/pane.png"), tr("Add &New Pane"), this);
Chris@66 623 action->setShortcut(tr("Alt+N"));
Chris@66 624 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
Chris@66 625 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
Chris@66 626 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
Chris@66 627 m_paneActions[action] = PaneConfiguration(LayerFactory::TimeRuler);
Chris@66 628 menu->addAction(action);
Chris@66 629
Chris@66 630 menu->addSeparator();
Chris@66 631
Chris@66 632 menu = m_layerMenu;
Chris@66 633
Chris@66 634 // menu->addSeparator();
Chris@66 635
Chris@66 636 LayerFactory::LayerTypeSet emptyLayerTypes =
Chris@66 637 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@66 638
Chris@66 639 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
Chris@66 640 i != emptyLayerTypes.end(); ++i) {
Chris@66 641
Chris@66 642 QIcon icon;
Chris@66 643 QString mainText, tipText, channelText;
Chris@66 644 LayerFactory::LayerType type = *i;
Chris@66 645 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
Chris@66 646
Chris@66 647 icon = QIcon(QString(":/icons/%1.png")
Chris@66 648 .arg(LayerFactory::getInstance()->getLayerIconName(type)));
Chris@66 649
Chris@66 650 mainText = tr("Add New %1 Layer").arg(name);
Chris@66 651 tipText = tr("Add a new empty layer of type %1").arg(name);
Chris@66 652
Chris@66 653 action = new QAction(icon, mainText, this);
Chris@66 654 action->setStatusTip(tipText);
Chris@66 655
Chris@66 656 if (type == LayerFactory::Text) {
Chris@66 657 action->setShortcut(tr("Alt+T"));
Chris@66 658 }
Chris@66 659
Chris@66 660 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@66 661 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 662 m_layerActions[action] = type;
Chris@66 663 menu->addAction(action);
Chris@66 664 m_rightButtonLayerMenu->addAction(action);
Chris@66 665 }
Chris@66 666
Chris@66 667 m_rightButtonLayerMenu->addSeparator();
Chris@66 668 menu->addSeparator();
Chris@66 669
Chris@66 670 LayerFactory::LayerType backgroundTypes[] = {
Chris@66 671 LayerFactory::Waveform,
Chris@66 672 LayerFactory::Spectrogram,
Chris@66 673 LayerFactory::MelodicRangeSpectrogram,
Chris@66 674 LayerFactory::PeakFrequencySpectrogram,
Chris@66 675 LayerFactory::Spectrum
Chris@66 676 };
Chris@66 677
Chris@66 678 std::vector<Model *> models;
Chris@66 679 if (m_document) models = m_document->getTransformInputModels(); //!!! not well named for this!
Chris@66 680 bool plural = (models.size() > 1);
Chris@66 681 if (models.empty()) {
Chris@66 682 if (m_document) {
Chris@66 683 models.push_back(m_document->getMainModel()); // probably 0
Chris@66 684 } else {
Chris@66 685 models.push_back(0);
Chris@66 686 }
Chris@66 687 }
Chris@66 688
Chris@66 689 for (unsigned int i = 0;
Chris@66 690 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
Chris@66 691
Chris@66 692 for (int menuType = 0; menuType <= 1; ++menuType) { // pane, layer
Chris@66 693
Chris@66 694 if (menuType == 0) menu = m_paneMenu;
Chris@66 695 else menu = m_layerMenu;
Chris@66 696
Chris@66 697 QMenu *submenu = 0;
Chris@66 698
Chris@66 699 QIcon icon;
Chris@66 700 QString mainText, shortcutText, tipText, channelText;
Chris@66 701 LayerFactory::LayerType type = backgroundTypes[i];
Chris@66 702 bool mono = true;
Chris@66 703
Chris@66 704 switch (type) {
Chris@66 705
Chris@66 706 case LayerFactory::Waveform:
Chris@66 707 icon = QIcon(":/icons/waveform.png");
Chris@66 708 mainText = tr("Add &Waveform");
Chris@66 709 if (menuType == 0) {
Chris@66 710 shortcutText = tr("Alt+W");
Chris@66 711 tipText = tr("Add a new pane showing a waveform view");
Chris@66 712 } else {
Chris@66 713 tipText = tr("Add a new layer showing a waveform view");
Chris@66 714 }
Chris@66 715 mono = false;
Chris@66 716 break;
Chris@66 717
Chris@66 718 case LayerFactory::Spectrogram:
Chris@66 719 mainText = tr("Add &Spectrogram");
Chris@66 720 if (menuType == 0) {
Chris@66 721 shortcutText = tr("Alt+S");
Chris@66 722 tipText = tr("Add a new pane showing a dB spectrogram");
Chris@66 723 } else {
Chris@66 724 tipText = tr("Add a new layer showing a dB spectrogram");
Chris@66 725 }
Chris@66 726 break;
Chris@66 727
Chris@66 728 case LayerFactory::MelodicRangeSpectrogram:
Chris@66 729 mainText = tr("Add &Melodic Range Spectrogram");
Chris@66 730 if (menuType == 0) {
Chris@66 731 shortcutText = tr("Alt+M");
Chris@66 732 tipText = tr("Add a new pane showing a spectrogram set up for a pitch overview");
Chris@66 733 } else {
Chris@66 734 tipText = tr("Add a new layer showing a spectrogram set up for a pitch overview");
Chris@66 735 }
Chris@66 736 break;
Chris@66 737
Chris@66 738 case LayerFactory::PeakFrequencySpectrogram:
Chris@66 739 mainText = tr("Add &Peak Frequency Spectrogram");
Chris@66 740 if (menuType == 0) {
Chris@66 741 shortcutText = tr("Alt+P");
Chris@66 742 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
Chris@66 743 } else {
Chris@66 744 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
Chris@66 745 }
Chris@66 746 break;
Chris@66 747
Chris@66 748 case LayerFactory::Spectrum:
Chris@66 749 mainText = tr("Add Spectr&um");
Chris@66 750 if (menuType == 0) {
Chris@66 751 shortcutText = tr("Alt+U");
Chris@66 752 tipText = tr("Add a new pane showing a frequency spectrum");
Chris@66 753 } else {
Chris@66 754 tipText = tr("Add a new layer showing a frequency spectrum");
Chris@66 755 }
Chris@66 756 break;
Chris@66 757
Chris@66 758 default: break;
Chris@66 759 }
Chris@66 760
Chris@66 761 std::vector<Model *> candidateModels;
Chris@66 762 if (menuType == 0) {
Chris@66 763 candidateModels = models;
Chris@66 764 } else {
Chris@66 765 candidateModels.push_back(0);
Chris@66 766 }
Chris@66 767
Chris@66 768 for (std::vector<Model *>::iterator mi =
Chris@66 769 candidateModels.begin();
Chris@66 770 mi != candidateModels.end(); ++mi) {
Chris@66 771
Chris@66 772 Model *model = *mi;
Chris@66 773
Chris@66 774 int channels = 0;
Chris@66 775 if (model) {
Chris@66 776 DenseTimeValueModel *dtvm =
Chris@66 777 dynamic_cast<DenseTimeValueModel *>(model);
Chris@66 778 if (dtvm) channels = dtvm->getChannelCount();
Chris@66 779 }
Chris@66 780 if (channels < 1 && getMainModel()) {
Chris@66 781 channels = getMainModel()->getChannelCount();
Chris@66 782 }
Chris@66 783 if (channels < 1) channels = 1;
Chris@66 784
Chris@66 785 for (int c = 0; c <= channels; ++c) {
Chris@66 786
Chris@66 787 if (c == 1 && channels == 1) continue;
Chris@66 788 bool isDefault = (c == 0);
Chris@66 789 bool isOnly = (isDefault && (channels == 1));
Chris@66 790
Chris@66 791 if (menuType == 1) {
Chris@66 792 if (isDefault) isOnly = true;
Chris@66 793 else continue;
Chris@66 794 }
Chris@66 795
Chris@66 796 if (isOnly && (!plural || menuType == 1)) {
Chris@66 797
Chris@66 798 action = new QAction(icon, mainText, this);
Chris@66 799 action->setShortcut(shortcutText);
Chris@66 800 action->setStatusTip(tipText);
Chris@66 801 if (menuType == 0) {
Chris@66 802 connect(action, SIGNAL(triggered()),
Chris@66 803 this, SLOT(addPane()));
Chris@66 804 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 805 action, SLOT(setEnabled(bool)));
Chris@66 806 m_paneActions[action] = PaneConfiguration(type);
Chris@66 807 } else {
Chris@66 808 connect(action, SIGNAL(triggered()),
Chris@66 809 this, SLOT(addLayer()));
Chris@66 810 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 811 action, SLOT(setEnabled(bool)));
Chris@66 812 m_layerActions[action] = type;
Chris@66 813 }
Chris@66 814 menu->addAction(action);
Chris@66 815
Chris@66 816 } else {
Chris@66 817
Chris@66 818 if (!submenu) {
Chris@66 819 submenu = menu->addMenu(mainText);
Chris@66 820 }
Chris@66 821
Chris@66 822 QString actionText;
Chris@66 823 if (c == 0) {
Chris@66 824 if (mono) {
Chris@66 825 actionText = tr("&All Channels Mixed");
Chris@66 826 } else {
Chris@66 827 actionText = tr("&All Channels");
Chris@66 828 }
Chris@66 829 } else {
Chris@66 830 actionText = tr("Channel &%1").arg(c);
Chris@66 831 }
Chris@66 832
Chris@66 833 if (model) {
Chris@66 834 actionText = tr("%1: %2")
Chris@66 835 .arg(model->objectName())
Chris@66 836 .arg(actionText);
Chris@66 837 }
Chris@66 838
Chris@66 839 action = new QAction(icon, actionText, this);
Chris@66 840 if (isDefault) action->setShortcut(shortcutText);
Chris@66 841 action->setStatusTip(tipText);
Chris@66 842
Chris@66 843 if (menuType == 0) {
Chris@66 844 connect(action, SIGNAL(triggered()),
Chris@66 845 this, SLOT(addPane()));
Chris@66 846 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 847 action, SLOT(setEnabled(bool)));
Chris@66 848 m_paneActions[action] =
Chris@66 849 PaneConfiguration(type, model, c - 1);
Chris@66 850 } else {
Chris@66 851 connect(action, SIGNAL(triggered()),
Chris@66 852 this, SLOT(addLayer()));
Chris@66 853 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 854 action, SLOT(setEnabled(bool)));
Chris@66 855 m_layerActions[action] = type;
Chris@66 856 }
Chris@66 857
Chris@66 858 submenu->addAction(action);
Chris@66 859 }
Chris@66 860 }
Chris@66 861 }
Chris@66 862 }
Chris@66 863 }
Chris@66 864
Chris@66 865 menu = m_paneMenu;
Chris@66 866
Chris@66 867 menu->addSeparator();
Chris@66 868
Chris@66 869 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Pane"), this);
Chris@66 870 action->setShortcut(tr("Alt+D"));
Chris@66 871 action->setStatusTip(tr("Delete the currently selected pane"));
Chris@66 872 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
Chris@66 873 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
Chris@66 874 menu->addAction(action);
Chris@66 875
Chris@66 876 menu = m_layerMenu;
Chris@66 877
Chris@66 878 action = new QAction(QIcon(":/icons/timeruler.png"), tr("Add &Time Ruler"), this);
Chris@66 879 action->setStatusTip(tr("Add a new layer showing a time ruler"));
Chris@66 880 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@66 881 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 882 m_layerActions[action] = LayerFactory::TimeRuler;
Chris@66 883 menu->addAction(action);
Chris@66 884
Chris@66 885 menu->addSeparator();
Chris@66 886
Chris@66 887 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
Chris@66 888 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
Chris@66 889 setupExistingLayersMenu();
Chris@66 890
Chris@66 891 m_rightButtonLayerMenu->addSeparator();
Chris@66 892 menu->addSeparator();
Chris@66 893
Chris@66 894 action = new QAction(tr("&Rename Layer..."), this);
Chris@66 895 action->setShortcut(tr("Alt+R"));
Chris@66 896 action->setStatusTip(tr("Rename the currently active layer"));
Chris@66 897 connect(action, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
Chris@66 898 connect(this, SIGNAL(canRenameLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 899 menu->addAction(action);
Chris@66 900 m_rightButtonLayerMenu->addAction(action);
Chris@66 901
Chris@66 902 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Layer"), this);
Chris@66 903 action->setShortcut(tr("Alt+Shift+D"));
Chris@66 904 action->setStatusTip(tr("Delete the currently active layer"));
Chris@66 905 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
Chris@66 906 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 907 menu->addAction(action);
Chris@66 908 m_rightButtonLayerMenu->addAction(action);
Chris@66 909 }
Chris@66 910
Chris@66 911 void
Chris@66 912 MainWindow::setupTransformsMenu()
Chris@66 913 {
Chris@34 914 if (m_transformsMenu) {
Chris@34 915 m_transformActions.clear();
Chris@34 916 m_transformActionsReverse.clear();
Chris@34 917 m_transformsMenu->clear();
Chris@34 918 } else {
Chris@34 919 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
Chris@34 920 }
Chris@34 921
Chris@0 922 TransformFactory::TransformList transforms =
Chris@0 923 TransformFactory::getInstance()->getAllTransforms();
Chris@0 924
Chris@33 925 vector<QString> types =
Chris@0 926 TransformFactory::getInstance()->getAllTransformTypes();
Chris@0 927
Chris@37 928 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
Chris@37 929 map<QString, map<QString, SubdividingMenu *> > makerMenus;
Chris@33 930
Chris@36 931 map<QString, SubdividingMenu *> byPluginNameMenus;
Chris@33 932 map<QString, map<QString, QMenu *> > pluginNameMenus;
Chris@33 933
Chris@37 934 set<SubdividingMenu *> pendingMenus;
Chris@37 935
Chris@34 936 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
Chris@34 937 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
Chris@34 938 connect(&m_recentTransforms, SIGNAL(recentChanged()),
Chris@34 939 this, SLOT(setupRecentTransformsMenu()));
Chris@34 940
Chris@34 941 m_transformsMenu->addSeparator();
Chris@34 942 m_rightButtonTransformsMenu->addSeparator();
Chris@34 943
Chris@33 944 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
Chris@33 945
Chris@33 946 if (i != types.begin()) {
Chris@34 947 m_transformsMenu->addSeparator();
Chris@34 948 m_rightButtonTransformsMenu->addSeparator();
Chris@33 949 }
Chris@33 950
Chris@33 951 QString byCategoryLabel = tr("%1 by Category").arg(*i);
Chris@37 952 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
Chris@37 953 20, 40);
Chris@37 954 m_transformsMenu->addMenu(byCategoryMenu);
Chris@34 955 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
Chris@37 956 pendingMenus.insert(byCategoryMenu);
Chris@33 957
Chris@33 958 vector<QString> categories =
Chris@33 959 TransformFactory::getInstance()->getTransformCategories(*i);
Chris@33 960
Chris@33 961 for (vector<QString>::iterator j = categories.begin();
Chris@33 962 j != categories.end(); ++j) {
Chris@33 963
Chris@33 964 QString category = *j;
Chris@33 965 if (category == "") category = tr("Unclassified");
Chris@33 966
Chris@33 967 if (categories.size() < 2) {
Chris@33 968 categoryMenus[*i][category] = byCategoryMenu;
Chris@33 969 continue;
Chris@33 970 }
Chris@33 971
Chris@33 972 QStringList components = category.split(" > ");
Chris@33 973 QString key;
Chris@33 974
Chris@33 975 for (QStringList::iterator k = components.begin();
Chris@33 976 k != components.end(); ++k) {
Chris@33 977
Chris@33 978 QString parentKey = key;
Chris@33 979 if (key != "") key += " > ";
Chris@33 980 key += *k;
Chris@33 981
Chris@33 982 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
Chris@37 983 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
Chris@37 984 pendingMenus.insert(m);
Chris@37 985 categoryMenus[*i][key] = m;
Chris@33 986 if (parentKey == "") {
Chris@37 987 byCategoryMenu->addMenu(m);
Chris@33 988 } else {
Chris@37 989 categoryMenus[*i][parentKey]->addMenu(m);
Chris@33 990 }
Chris@33 991 }
Chris@33 992 }
Chris@33 993 }
Chris@33 994
Chris@34 995 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
Chris@36 996 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
Chris@36 997 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@34 998 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@37 999 pendingMenus.insert(byPluginNameMenus[*i]);
Chris@34 1000
Chris@33 1001 QString byMakerLabel = tr("%1 by Maker").arg(*i);
Chris@37 1002 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
Chris@37 1003 m_transformsMenu->addMenu(byMakerMenu);
Chris@34 1004 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
Chris@37 1005 pendingMenus.insert(byMakerMenu);
Chris@33 1006
Chris@33 1007 vector<QString> makers =
Chris@33 1008 TransformFactory::getInstance()->getTransformMakers(*i);
Chris@37 1009
Chris@33 1010 for (vector<QString>::iterator j = makers.begin();
Chris@33 1011 j != makers.end(); ++j) {
Chris@33 1012
Chris@33 1013 QString maker = *j;
Chris@33 1014 if (maker == "") maker = tr("Unknown");
Chris@55 1015 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@55 1016
Chris@37 1017 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
Chris@37 1018 byMakerMenu->addMenu(makerMenus[*i][maker]);
Chris@37 1019 pendingMenus.insert(makerMenus[*i][maker]);
Chris@33 1020 }
Chris@0 1021 }
Chris@0 1022
Chris@0 1023 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@0 1024
Chris@0 1025 QString description = transforms[i].description;
Chris@0 1026 if (description == "") description = transforms[i].name;
Chris@0 1027
Chris@33 1028 QString type = transforms[i].type;
Chris@33 1029
Chris@33 1030 QString category = transforms[i].category;
Chris@33 1031 if (category == "") category = tr("Unclassified");
Chris@33 1032
Chris@33 1033 QString maker = transforms[i].maker;
Chris@33 1034 if (maker == "") maker = tr("Unknown");
Chris@55 1035 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@33 1036
Chris@33 1037 QString pluginName = description.section(": ", 0, 0);
Chris@33 1038 QString output = description.section(": ", 1);
Chris@33 1039
Chris@66 1040 QAction *action = new QAction(tr("%1...").arg(description), this);
Chris@0 1041 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@34 1042 m_transformActions[action] = transforms[i].name;
Chris@34 1043 m_transformActionsReverse[transforms[i].name] = action;
Chris@0 1044 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@33 1045
Chris@33 1046 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
Chris@33 1047 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1048 << "No category menu for transform \""
Chris@33 1049 << description.toStdString() << "\" (category = \""
Chris@33 1050 << category.toStdString() << "\")" << std::endl;
Chris@33 1051 } else {
Chris@33 1052 categoryMenus[type][category]->addAction(action);
Chris@33 1053 }
Chris@33 1054
Chris@33 1055 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
Chris@33 1056 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1057 << "No maker menu for transform \""
Chris@33 1058 << description.toStdString() << "\" (maker = \""
Chris@33 1059 << maker.toStdString() << "\")" << std::endl;
Chris@33 1060 } else {
Chris@37 1061 makerMenus[type][maker]->addAction(pluginName, action);
Chris@33 1062 }
Chris@33 1063
Chris@33 1064 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
Chris@33 1065 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@34 1066 m_transformActions[action] = transforms[i].name;
Chris@33 1067 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@33 1068
Chris@34 1069 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
Chris@34 1070
Chris@33 1071 if (pluginNameMenus[type].find(pluginName) ==
Chris@33 1072 pluginNameMenus[type].end()) {
Chris@33 1073
Chris@36 1074 SubdividingMenu *parentMenu = byPluginNameMenus[type];
Chris@34 1075
Chris@33 1076 if (output == "") {
Chris@36 1077 parentMenu->addAction(pluginName, action);
Chris@33 1078 } else {
Chris@34 1079 pluginNameMenus[type][pluginName] =
Chris@34 1080 parentMenu->addMenu(pluginName);
Chris@33 1081 connect(this, SIGNAL(canAddLayer(bool)),
Chris@33 1082 pluginNameMenus[type][pluginName],
Chris@33 1083 SLOT(setEnabled(bool)));
Chris@33 1084 }
Chris@33 1085 }
Chris@33 1086
Chris@33 1087 if (pluginNameMenus[type].find(pluginName) !=
Chris@33 1088 pluginNameMenus[type].end()) {
Chris@33 1089 pluginNameMenus[type][pluginName]->addAction(action);
Chris@33 1090 }
Chris@0 1091 }
Chris@0 1092
Chris@37 1093 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
Chris@37 1094 i != pendingMenus.end(); ++i) {
Chris@37 1095 (*i)->entriesAdded();
Chris@37 1096 }
Chris@37 1097
Chris@34 1098 setupRecentTransformsMenu();
Chris@66 1099 }
Chris@66 1100
Chris@66 1101 void
Chris@66 1102 MainWindow::setupHelpMenu()
Chris@66 1103 {
Chris@66 1104 if (m_mainMenusCreated) return;
Chris@66 1105
Chris@66 1106 QMenu *menu = menuBar()->addMenu(tr("&Help"));
Chris@66 1107
Chris@66 1108 QAction *action = new QAction(tr("&Help Reference"), this);
Chris@66 1109 action->setStatusTip(tr("Open the Sonic Visualiser reference manual"));
Chris@66 1110 connect(action, SIGNAL(triggered()), this, SLOT(help()));
Chris@0 1111 menu->addAction(action);
Chris@0 1112
Chris@66 1113 action = new QAction(tr("Sonic Visualiser on the &Web"), this);
Chris@66 1114 action->setStatusTip(tr("Open the Sonic Visualiser website"));
Chris@66 1115 connect(action, SIGNAL(triggered()), this, SLOT(website()));
Chris@0 1116 menu->addAction(action);
Chris@66 1117
Chris@66 1118 action = new QAction(tr("&About Sonic Visualiser"), this);
Chris@66 1119 action->setStatusTip(tr("Show information about Sonic Visualiser"));
Chris@66 1120 connect(action, SIGNAL(triggered()), this, SLOT(about()));
Chris@0 1121 menu->addAction(action);
Chris@0 1122 }
Chris@0 1123
Chris@0 1124 void
Chris@0 1125 MainWindow::setupRecentFilesMenu()
Chris@0 1126 {
Chris@0 1127 m_recentFilesMenu->clear();
Chris@34 1128 vector<QString> files = m_recentFiles.getRecent();
Chris@0 1129 for (size_t i = 0; i < files.size(); ++i) {
Chris@0 1130 QAction *action = new QAction(files[i], this);
Chris@0 1131 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
Chris@0 1132 m_recentFilesMenu->addAction(action);
Chris@0 1133 }
Chris@0 1134 }
Chris@0 1135
Chris@0 1136 void
Chris@34 1137 MainWindow::setupRecentTransformsMenu()
Chris@34 1138 {
Chris@34 1139 m_recentTransformsMenu->clear();
Chris@34 1140 vector<QString> transforms = m_recentTransforms.getRecent();
Chris@34 1141 for (size_t i = 0; i < transforms.size(); ++i) {
Chris@34 1142 TransformActionReverseMap::iterator ti =
Chris@34 1143 m_transformActionsReverse.find(transforms[i]);
Chris@34 1144 if (ti == m_transformActionsReverse.end()) {
Chris@34 1145 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
Chris@34 1146 << "Unknown transform \"" << transforms[i].toStdString()
Chris@34 1147 << "\" in recent transforms list" << std::endl;
Chris@34 1148 continue;
Chris@34 1149 }
Chris@34 1150 m_recentTransformsMenu->addAction(ti->second);
Chris@34 1151 }
Chris@34 1152 }
Chris@34 1153
Chris@34 1154 void
Chris@0 1155 MainWindow::setupExistingLayersMenu()
Chris@0 1156 {
Chris@0 1157 if (!m_existingLayersMenu) return; // should have been created by setupMenus
Chris@0 1158
Chris@0 1159 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl;
Chris@0 1160
Chris@0 1161 m_existingLayersMenu->clear();
Chris@0 1162 m_existingLayerActions.clear();
Chris@0 1163
Chris@33 1164 vector<Layer *> orderedLayers;
Chris@33 1165 set<Layer *> observedLayers;
Chris@0 1166
Chris@0 1167 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 1168
Chris@0 1169 Pane *pane = m_paneStack->getPane(i);
Chris@0 1170 if (!pane) continue;
Chris@0 1171
Chris@0 1172 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 1173
Chris@0 1174 Layer *layer = pane->getLayer(j);
Chris@0 1175 if (!layer) continue;
Chris@0 1176 if (observedLayers.find(layer) != observedLayers.end()) {
Chris@0 1177 std::cerr << "found duplicate layer " << layer << std::endl;
Chris@0 1178 continue;
Chris@0 1179 }
Chris@0 1180
Chris@0 1181 // std::cerr << "found new layer " << layer << " (name = "
Chris@0 1182 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl;
Chris@0 1183
Chris@0 1184 orderedLayers.push_back(layer);
Chris@0 1185 observedLayers.insert(layer);
Chris@0 1186 }
Chris@0 1187 }
Chris@0 1188
Chris@33 1189 map<QString, int> observedNames;
Chris@0 1190
Chris@0 1191 for (int i = 0; i < orderedLayers.size(); ++i) {
Chris@0 1192
Chris@0 1193 QString name = orderedLayers[i]->getLayerPresentationName();
Chris@0 1194 int n = ++observedNames[name];
Chris@0 1195 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
Chris@0 1196
Chris@0 1197 QAction *action = new QAction(name, this);
Chris@0 1198 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@0 1199 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1200 m_existingLayerActions[action] = orderedLayers[i];
Chris@0 1201
Chris@0 1202 m_existingLayersMenu->addAction(action);
Chris@0 1203 }
Chris@0 1204 }
Chris@0 1205
Chris@0 1206 void
Chris@0 1207 MainWindow::setupToolbars()
Chris@0 1208 {
Chris@0 1209 QToolBar *toolbar = addToolBar(tr("Transport Toolbar"));
Chris@0 1210
Chris@0 1211 QAction *action = toolbar->addAction(QIcon(":/icons/rewind-start.png"),
Chris@0 1212 tr("Rewind to Start"));
Chris@0 1213 action->setShortcut(tr("Home"));
Chris@0 1214 action->setStatusTip(tr("Rewind to the start"));
Chris@0 1215 connect(action, SIGNAL(triggered()), this, SLOT(rewindStart()));
Chris@0 1216 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1217
Chris@0 1218 action = toolbar->addAction(QIcon(":/icons/rewind.png"),
Chris@0 1219 tr("Rewind"));
Chris@0 1220 action->setShortcut(tr("PageUp"));
Chris@0 1221 action->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
Chris@0 1222 connect(action, SIGNAL(triggered()), this, SLOT(rewind()));
Chris@0 1223 connect(this, SIGNAL(canRewind(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1224
Chris@0 1225 action = toolbar->addAction(QIcon(":/icons/playpause.png"),
Chris@0 1226 tr("Play / Pause"));
Chris@0 1227 action->setCheckable(true);
Chris@0 1228 action->setShortcut(tr("Space"));
Chris@0 1229 action->setStatusTip(tr("Start or stop playback from the current position"));
Chris@0 1230 connect(action, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 1231 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
Chris@0 1232 action, SLOT(setChecked(bool)));
Chris@0 1233 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1234
Chris@0 1235 action = toolbar->addAction(QIcon(":/icons/ffwd.png"),
Chris@0 1236 tr("Fast Forward"));
Chris@0 1237 action->setShortcut(tr("PageDown"));
Chris@0 1238 action->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
Chris@0 1239 connect(action, SIGNAL(triggered()), this, SLOT(ffwd()));
Chris@0 1240 connect(this, SIGNAL(canFfwd(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1241
Chris@0 1242 action = toolbar->addAction(QIcon(":/icons/ffwd-end.png"),
Chris@0 1243 tr("Fast Forward to End"));
Chris@0 1244 action->setShortcut(tr("End"));
Chris@0 1245 action->setStatusTip(tr("Fast-forward to the end"));
Chris@0 1246 connect(action, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
Chris@0 1247 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1248
Chris@0 1249 toolbar = addToolBar(tr("Play Mode Toolbar"));
Chris@0 1250
Chris@0 1251 action = toolbar->addAction(QIcon(":/icons/playselection.png"),
Chris@0 1252 tr("Constrain Playback to Selection"));
Chris@0 1253 action->setCheckable(true);
Chris@0 1254 action->setChecked(m_viewManager->getPlaySelectionMode());
Chris@0 1255 action->setShortcut(tr("s"));
Chris@0 1256 action->setStatusTip(tr("Constrain playback to the selected area"));
Chris@0 1257 connect(action, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
Chris@0 1258 connect(this, SIGNAL(canPlaySelection(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1259
Chris@0 1260 action = toolbar->addAction(QIcon(":/icons/playloop.png"),
Chris@0 1261 tr("Loop Playback"));
Chris@0 1262 action->setCheckable(true);
Chris@0 1263 action->setChecked(m_viewManager->getPlayLoopMode());
Chris@0 1264 action->setShortcut(tr("l"));
Chris@0 1265 action->setStatusTip(tr("Loop playback"));
Chris@0 1266 connect(action, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
Chris@0 1267 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1268
Chris@0 1269 toolbar = addToolBar(tr("Edit Toolbar"));
Chris@0 1270 CommandHistory::getInstance()->registerToolbar(toolbar);
Chris@0 1271
Chris@0 1272 toolbar = addToolBar(tr("Tools Toolbar"));
Chris@0 1273 QActionGroup *group = new QActionGroup(this);
Chris@0 1274
Chris@0 1275 action = toolbar->addAction(QIcon(":/icons/navigate.png"),
Chris@0 1276 tr("Navigate"));
Chris@0 1277 action->setCheckable(true);
Chris@0 1278 action->setChecked(true);
Chris@0 1279 action->setShortcut(tr("1"));
Chris@0 1280 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
Chris@0 1281 group->addAction(action);
Chris@0 1282 m_toolActions[ViewManager::NavigateMode] = action;
Chris@0 1283
Chris@0 1284 action = toolbar->addAction(QIcon(":/icons/select.png"),
Chris@0 1285 tr("Select"));
Chris@0 1286 action->setCheckable(true);
Chris@0 1287 action->setShortcut(tr("2"));
Chris@0 1288 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
Chris@0 1289 group->addAction(action);
Chris@0 1290 m_toolActions[ViewManager::SelectMode] = action;
Chris@0 1291
Chris@0 1292 action = toolbar->addAction(QIcon(":/icons/move.png"),
Chris@0 1293 tr("Edit"));
Chris@0 1294 action->setCheckable(true);
Chris@0 1295 action->setShortcut(tr("3"));
Chris@0 1296 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
Chris@0 1297 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1298 group->addAction(action);
Chris@0 1299 m_toolActions[ViewManager::EditMode] = action;
Chris@0 1300
Chris@0 1301 action = toolbar->addAction(QIcon(":/icons/draw.png"),
Chris@0 1302 tr("Draw"));
Chris@0 1303 action->setCheckable(true);
Chris@0 1304 action->setShortcut(tr("4"));
Chris@0 1305 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
Chris@0 1306 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1307 group->addAction(action);
Chris@0 1308 m_toolActions[ViewManager::DrawMode] = action;
Chris@0 1309
Chris@0 1310 // action = toolbar->addAction(QIcon(":/icons/text.png"),
Chris@0 1311 // tr("Text"));
Chris@0 1312 // action->setCheckable(true);
Chris@0 1313 // action->setShortcut(tr("5"));
Chris@0 1314 // connect(action, SIGNAL(triggered()), this, SLOT(toolTextSelected()));
Chris@0 1315 // group->addAction(action);
Chris@0 1316 // m_toolActions[ViewManager::TextMode] = action;
Chris@0 1317
Chris@0 1318 toolNavigateSelected();
Chris@0 1319 }
Chris@0 1320
Chris@0 1321 void
Chris@0 1322 MainWindow::updateMenuStates()
Chris@0 1323 {
Chris@0 1324 bool haveCurrentPane =
Chris@0 1325 (m_paneStack &&
Chris@0 1326 (m_paneStack->getCurrentPane() != 0));
Chris@0 1327 bool haveCurrentLayer =
Chris@0 1328 (haveCurrentPane &&
Chris@0 1329 (m_paneStack->getCurrentPane()->getSelectedLayer()));
Chris@0 1330 bool haveMainModel =
Chris@0 1331 (getMainModel() != 0);
Chris@0 1332 bool havePlayTarget =
Chris@0 1333 (m_playTarget != 0);
Chris@0 1334 bool haveSelection =
Chris@0 1335 (m_viewManager &&
Chris@0 1336 !m_viewManager->getSelections().empty());
Chris@0 1337 bool haveCurrentEditableLayer =
Chris@0 1338 (haveCurrentLayer &&
Chris@0 1339 m_paneStack->getCurrentPane()->getSelectedLayer()->
Chris@0 1340 isLayerEditable());
Chris@0 1341 bool haveCurrentTimeInstantsLayer =
Chris@0 1342 (haveCurrentLayer &&
Chris@0 1343 dynamic_cast<TimeInstantLayer *>
Chris@0 1344 (m_paneStack->getCurrentPane()->getSelectedLayer()));
Chris@0 1345 bool haveCurrentTimeValueLayer =
Chris@0 1346 (haveCurrentLayer &&
Chris@0 1347 dynamic_cast<TimeValueLayer *>
Chris@0 1348 (m_paneStack->getCurrentPane()->getSelectedLayer()));
Chris@0 1349 bool haveCurrentColour3DPlot =
Chris@0 1350 (haveCurrentLayer &&
Chris@0 1351 dynamic_cast<Colour3DPlotLayer *>
Chris@0 1352 (m_paneStack->getCurrentPane()->getSelectedLayer()));
Chris@0 1353 bool haveClipboardContents =
Chris@0 1354 (m_viewManager &&
Chris@0 1355 !m_viewManager->getClipboard().empty());
Chris@0 1356
Chris@0 1357 emit canAddPane(haveMainModel);
Chris@0 1358 emit canDeleteCurrentPane(haveCurrentPane);
Chris@0 1359 emit canZoom(haveMainModel && haveCurrentPane);
Chris@0 1360 emit canScroll(haveMainModel && haveCurrentPane);
Chris@0 1361 emit canAddLayer(haveMainModel && haveCurrentPane);
Chris@0 1362 emit canImportMoreAudio(haveMainModel);
Chris@0 1363 emit canImportLayer(haveMainModel && haveCurrentPane);
Chris@0 1364 emit canExportAudio(haveMainModel);
Chris@0 1365 emit canExportLayer(haveMainModel &&
Chris@0 1366 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
Chris@0 1367 emit canDeleteCurrentLayer(haveCurrentLayer);
Chris@0 1368 emit canRenameLayer(haveCurrentLayer);
Chris@0 1369 emit canEditLayer(haveCurrentEditableLayer);
Chris@0 1370 emit canSelect(haveMainModel && haveCurrentPane);
Chris@0 1371 emit canPlay(/*!!! haveMainModel && */ havePlayTarget);
Chris@0 1372 emit canFfwd(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
Chris@0 1373 emit canRewind(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
Chris@0 1374 emit canPaste(haveCurrentEditableLayer && haveClipboardContents);
Chris@0 1375 emit canInsertInstant(haveCurrentPane);
Chris@0 1376 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
Chris@0 1377 emit canClearSelection(haveSelection);
Chris@0 1378 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
Chris@0 1379 emit canSave(m_sessionFile != "" && m_documentModified);
Chris@0 1380 }
Chris@0 1381
Chris@0 1382 void
Chris@0 1383 MainWindow::updateDescriptionLabel()
Chris@0 1384 {
Chris@0 1385 if (!getMainModel()) {
Chris@0 1386 m_descriptionLabel->setText(tr("No audio file loaded."));
Chris@0 1387 return;
Chris@0 1388 }
Chris@0 1389
Chris@0 1390 QString description;
Chris@0 1391
Chris@0 1392 size_t ssr = getMainModel()->getSampleRate();
Chris@0 1393 size_t tsr = ssr;
Chris@0 1394 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
Chris@0 1395
Chris@0 1396 if (ssr != tsr) {
Chris@0 1397 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
Chris@0 1398 } else {
Chris@0 1399 description = QString("%1Hz").arg(ssr);
Chris@0 1400 }
Chris@0 1401
Chris@0 1402 description = QString("%1 - %2")
Chris@0 1403 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
Chris@0 1404 .toText(false).c_str())
Chris@0 1405 .arg(description);
Chris@0 1406
Chris@0 1407 m_descriptionLabel->setText(description);
Chris@0 1408 }
Chris@0 1409
Chris@0 1410 void
Chris@0 1411 MainWindow::documentModified()
Chris@0 1412 {
Chris@0 1413 // std::cerr << "MainWindow::documentModified" << std::endl;
Chris@0 1414
Chris@0 1415 if (!m_documentModified) {
Chris@0 1416 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
Chris@0 1417 }
Chris@0 1418
Chris@0 1419 m_documentModified = true;
Chris@0 1420 updateMenuStates();
Chris@0 1421 }
Chris@0 1422
Chris@0 1423 void
Chris@0 1424 MainWindow::documentRestored()
Chris@0 1425 {
Chris@0 1426 // std::cerr << "MainWindow::documentRestored" << std::endl;
Chris@0 1427
Chris@0 1428 if (m_documentModified) {
Chris@0 1429 QString wt(windowTitle());
Chris@0 1430 wt.replace(tr(" (modified)"), "");
Chris@0 1431 setWindowTitle(wt);
Chris@0 1432 }
Chris@0 1433
Chris@0 1434 m_documentModified = false;
Chris@0 1435 updateMenuStates();
Chris@0 1436 }
Chris@0 1437
Chris@0 1438 void
Chris@0 1439 MainWindow::playLoopToggled()
Chris@0 1440 {
Chris@0 1441 QAction *action = dynamic_cast<QAction *>(sender());
Chris@0 1442
Chris@0 1443 if (action) {
Chris@0 1444 m_viewManager->setPlayLoopMode(action->isChecked());
Chris@0 1445 } else {
Chris@0 1446 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
Chris@0 1447 }
Chris@0 1448 }
Chris@0 1449
Chris@0 1450 void
Chris@0 1451 MainWindow::playSelectionToggled()
Chris@0 1452 {
Chris@0 1453 QAction *action = dynamic_cast<QAction *>(sender());
Chris@0 1454
Chris@0 1455 if (action) {
Chris@0 1456 m_viewManager->setPlaySelectionMode(action->isChecked());
Chris@0 1457 } else {
Chris@0 1458 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
Chris@0 1459 }
Chris@0 1460 }
Chris@0 1461
Chris@0 1462 void
Chris@0 1463 MainWindow::currentPaneChanged(Pane *)
Chris@0 1464 {
Chris@0 1465 updateMenuStates();
Chris@0 1466 }
Chris@0 1467
Chris@0 1468 void
Chris@0 1469 MainWindow::currentLayerChanged(Pane *, Layer *)
Chris@0 1470 {
Chris@0 1471 updateMenuStates();
Chris@0 1472 }
Chris@0 1473
Chris@0 1474 void
Chris@0 1475 MainWindow::toolNavigateSelected()
Chris@0 1476 {
Chris@0 1477 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@0 1478 }
Chris@0 1479
Chris@0 1480 void
Chris@0 1481 MainWindow::toolSelectSelected()
Chris@0 1482 {
Chris@0 1483 m_viewManager->setToolMode(ViewManager::SelectMode);
Chris@0 1484 }
Chris@0 1485
Chris@0 1486 void
Chris@0 1487 MainWindow::toolEditSelected()
Chris@0 1488 {
Chris@0 1489 m_viewManager->setToolMode(ViewManager::EditMode);
Chris@0 1490 }
Chris@0 1491
Chris@0 1492 void
Chris@0 1493 MainWindow::toolDrawSelected()
Chris@0 1494 {
Chris@0 1495 m_viewManager->setToolMode(ViewManager::DrawMode);
Chris@0 1496 }
Chris@0 1497
Chris@0 1498 //void
Chris@0 1499 //MainWindow::toolTextSelected()
Chris@0 1500 //{
Chris@0 1501 // m_viewManager->setToolMode(ViewManager::TextMode);
Chris@0 1502 //}
Chris@0 1503
Chris@0 1504 void
Chris@0 1505 MainWindow::selectAll()
Chris@0 1506 {
Chris@0 1507 if (!getMainModel()) return;
Chris@0 1508 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@0 1509 getMainModel()->getEndFrame()));
Chris@0 1510 }
Chris@0 1511
Chris@0 1512 void
Chris@0 1513 MainWindow::selectToStart()
Chris@0 1514 {
Chris@0 1515 if (!getMainModel()) return;
Chris@0 1516 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@0 1517 m_viewManager->getGlobalCentreFrame()));
Chris@0 1518 }
Chris@0 1519
Chris@0 1520 void
Chris@0 1521 MainWindow::selectToEnd()
Chris@0 1522 {
Chris@0 1523 if (!getMainModel()) return;
Chris@0 1524 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
Chris@0 1525 getMainModel()->getEndFrame()));
Chris@0 1526 }
Chris@0 1527
Chris@0 1528 void
Chris@0 1529 MainWindow::selectVisible()
Chris@0 1530 {
Chris@0 1531 Model *model = getMainModel();
Chris@0 1532 if (!model) return;
Chris@0 1533
Chris@0 1534 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1535 if (!currentPane) return;
Chris@0 1536
Chris@0 1537 size_t startFrame, endFrame;
Chris@0 1538
Chris@0 1539 if (currentPane->getStartFrame() < 0) startFrame = 0;
Chris@0 1540 else startFrame = currentPane->getStartFrame();
Chris@0 1541
Chris@0 1542 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
Chris@0 1543 else endFrame = currentPane->getEndFrame();
Chris@0 1544
Chris@0 1545 m_viewManager->setSelection(Selection(startFrame, endFrame));
Chris@0 1546 }
Chris@0 1547
Chris@0 1548 void
Chris@0 1549 MainWindow::clearSelection()
Chris@0 1550 {
Chris@0 1551 m_viewManager->clearSelections();
Chris@0 1552 }
Chris@0 1553
Chris@0 1554 void
Chris@0 1555 MainWindow::cut()
Chris@0 1556 {
Chris@0 1557 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1558 if (!currentPane) return;
Chris@0 1559
Chris@0 1560 Layer *layer = currentPane->getSelectedLayer();
Chris@0 1561 if (!layer) return;
Chris@0 1562
Chris@0 1563 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 1564 clipboard.clear();
Chris@0 1565
Chris@0 1566 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 1567
Chris@0 1568 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
Chris@0 1569
Chris@0 1570 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 1571 i != selections.end(); ++i) {
Chris@0 1572 layer->copy(*i, clipboard);
Chris@0 1573 layer->deleteSelection(*i);
Chris@0 1574 }
Chris@0 1575
Chris@0 1576 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 1577 }
Chris@0 1578
Chris@0 1579 void
Chris@0 1580 MainWindow::copy()
Chris@0 1581 {
Chris@0 1582 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1583 if (!currentPane) return;
Chris@0 1584
Chris@0 1585 Layer *layer = currentPane->getSelectedLayer();
Chris@0 1586 if (!layer) return;
Chris@0 1587
Chris@0 1588 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 1589 clipboard.clear();
Chris@0 1590
Chris@0 1591 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 1592
Chris@0 1593 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 1594 i != selections.end(); ++i) {
Chris@0 1595 layer->copy(*i, clipboard);
Chris@0 1596 }
Chris@0 1597 }
Chris@0 1598
Chris@0 1599 void
Chris@0 1600 MainWindow::paste()
Chris@0 1601 {
Chris@0 1602 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1603 if (!currentPane) return;
Chris@0 1604
Chris@0 1605 //!!! if we have no current layer, we should create one of the most
Chris@0 1606 // appropriate type
Chris@0 1607
Chris@0 1608 Layer *layer = currentPane->getSelectedLayer();
Chris@0 1609 if (!layer) return;
Chris@0 1610
Chris@0 1611 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 1612 Clipboard::PointList contents = clipboard.getPoints();
Chris@0 1613 /*
Chris@0 1614 long minFrame = 0;
Chris@0 1615 bool have = false;
Chris@0 1616 for (int i = 0; i < contents.size(); ++i) {
Chris@0 1617 if (!contents[i].haveFrame()) continue;
Chris@0 1618 if (!have || contents[i].getFrame() < minFrame) {
Chris@0 1619 minFrame = contents[i].getFrame();
Chris@0 1620 have = true;
Chris@0 1621 }
Chris@0 1622 }
Chris@0 1623
Chris@0 1624 long frameOffset = long(m_viewManager->getGlobalCentreFrame()) - minFrame;
Chris@0 1625
Chris@0 1626 layer->paste(clipboard, frameOffset);
Chris@0 1627 */
Chris@0 1628 layer->paste(clipboard, 0, true);
Chris@0 1629 }
Chris@0 1630
Chris@0 1631 void
Chris@0 1632 MainWindow::deleteSelected()
Chris@0 1633 {
Chris@0 1634 if (m_paneStack->getCurrentPane() &&
Chris@0 1635 m_paneStack->getCurrentPane()->getSelectedLayer()) {
Chris@0 1636
Chris@0 1637 MultiSelection::SelectionList selections =
Chris@0 1638 m_viewManager->getSelections();
Chris@0 1639
Chris@0 1640 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 1641 i != selections.end(); ++i) {
Chris@0 1642
Chris@0 1643 m_paneStack->getCurrentPane()->getSelectedLayer()->deleteSelection(*i);
Chris@0 1644 }
Chris@0 1645 }
Chris@0 1646 }
Chris@0 1647
Chris@0 1648 void
Chris@0 1649 MainWindow::insertInstant()
Chris@0 1650 {
Chris@0 1651 int frame = m_viewManager->getPlaybackFrame();
Chris@0 1652
Chris@0 1653 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 1654 if (!pane) {
Chris@0 1655 return;
Chris@0 1656 }
Chris@0 1657
Chris@0 1658 Layer *layer = dynamic_cast<TimeInstantLayer *>
Chris@0 1659 (pane->getSelectedLayer());
Chris@0 1660
Chris@0 1661 if (!layer) {
Chris@0 1662 for (int i = pane->getLayerCount(); i > 0; --i) {
Chris@0 1663 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
Chris@0 1664 if (layer) break;
Chris@0 1665 }
Chris@0 1666
Chris@0 1667 if (!layer) {
Chris@0 1668 CommandHistory::getInstance()->startCompoundOperation
Chris@0 1669 (tr("Add Point"), true);
Chris@0 1670 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
Chris@0 1671 if (layer) {
Chris@0 1672 m_document->addLayerToView(pane, layer);
Chris@0 1673 m_paneStack->setCurrentLayer(pane, layer);
Chris@0 1674 }
Chris@0 1675 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 1676 }
Chris@0 1677 }
Chris@0 1678
Chris@0 1679 if (layer) {
Chris@0 1680
Chris@0 1681 Model *model = layer->getModel();
Chris@0 1682 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
Chris@0 1683 (model);
Chris@0 1684
Chris@0 1685 if (sodm) {
Chris@0 1686 SparseOneDimensionalModel::Point point
Chris@0 1687 (frame, QString("%1").arg(sodm->getPointCount() + 1));
Chris@0 1688 CommandHistory::getInstance()->addCommand
Chris@0 1689 (new SparseOneDimensionalModel::AddPointCommand(sodm, point,
Chris@0 1690 tr("Add Points")),
Chris@0 1691 true, true); // bundled
Chris@0 1692 }
Chris@0 1693 }
Chris@0 1694 }
Chris@0 1695
Chris@0 1696 void
Chris@0 1697 MainWindow::importAudio()
Chris@0 1698 {
Chris@0 1699 QString orig = m_audioFile;
Chris@0 1700
Chris@0 1701 // std::cerr << "orig = " << orig.toStdString() << std::endl;
Chris@0 1702
Chris@0 1703 if (orig == "") orig = ".";
Chris@0 1704
Chris@0 1705 QString path = QFileDialog::getOpenFileName
Chris@0 1706 (this, tr("Select an audio file"), orig,
Chris@0 1707 tr("Audio files (%1)\nAll files (*.*)")
Chris@0 1708 .arg(AudioFileReaderFactory::getKnownExtensions()));
Chris@0 1709
Chris@0 1710 if (path != "") {
Chris@0 1711 if (!openAudioFile(path, ReplaceMainModel)) {
Chris@0 1712 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1713 tr("Audio file \"%1\" could not be opened").arg(path));
Chris@0 1714 }
Chris@0 1715 }
Chris@0 1716 }
Chris@0 1717
Chris@0 1718 void
Chris@0 1719 MainWindow::importMoreAudio()
Chris@0 1720 {
Chris@0 1721 QString orig = m_audioFile;
Chris@0 1722
Chris@0 1723 // std::cerr << "orig = " << orig.toStdString() << std::endl;
Chris@0 1724
Chris@0 1725 if (orig == "") orig = ".";
Chris@0 1726
Chris@0 1727 QString path = QFileDialog::getOpenFileName
Chris@0 1728 (this, tr("Select an audio file"), orig,
Chris@0 1729 tr("Audio files (%1)\nAll files (*.*)")
Chris@0 1730 .arg(AudioFileReaderFactory::getKnownExtensions()));
Chris@0 1731
Chris@0 1732 if (path != "") {
Chris@0 1733 if (!openAudioFile(path, CreateAdditionalModel)) {
Chris@0 1734 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1735 tr("Audio file \"%1\" could not be opened").arg(path));
Chris@0 1736 }
Chris@0 1737 }
Chris@0 1738 }
Chris@0 1739
Chris@0 1740 void
Chris@0 1741 MainWindow::exportAudio()
Chris@0 1742 {
Chris@0 1743 if (!getMainModel()) return;
Chris@0 1744
Chris@0 1745 QString path = QFileDialog::getSaveFileName
Chris@0 1746 (this, tr("Select a file to export to"), ".",
Chris@0 1747 tr("WAV audio files (*.wav)\nAll files (*.*)"));
Chris@0 1748
Chris@0 1749 if (path == "") return;
Chris@0 1750
Chris@0 1751 if (!path.endsWith(".wav")) path = path + ".wav";
Chris@0 1752
Chris@0 1753 bool ok = false;
Chris@0 1754 QString error;
Chris@0 1755
Chris@0 1756 MultiSelection ms = m_viewManager->getSelection();
Chris@0 1757 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 1758
Chris@0 1759 bool multiple = false;
Chris@0 1760
Chris@38 1761 MultiSelection *selectionToWrite = 0;
Chris@38 1762
Chris@38 1763 if (selections.size() == 1) {
Chris@0 1764
Chris@0 1765 QStringList items;
Chris@0 1766 items << tr("Export the selected region only")
Chris@0 1767 << tr("Export the whole audio file");
Chris@0 1768
Chris@0 1769 bool ok = false;
Chris@0 1770 QString item = ListInputDialog::getItem
Chris@0 1771 (this, tr("Select region to export"),
Chris@0 1772 tr("Which region from the original audio file do you want to export?"),
Chris@0 1773 items, 0, &ok);
Chris@0 1774
Chris@0 1775 if (!ok || item.isEmpty()) return;
Chris@0 1776
Chris@38 1777 if (item == items[0]) selectionToWrite = &ms;
Chris@38 1778
Chris@38 1779 } else if (selections.size() > 1) {
Chris@0 1780
Chris@0 1781 QStringList items;
Chris@0 1782 items << tr("Export the selected regions into a single audio file")
Chris@0 1783 << tr("Export the selected regions into separate files")
Chris@0 1784 << tr("Export the whole audio file");
Chris@0 1785
Chris@0 1786 QString item = ListInputDialog::getItem
Chris@0 1787 (this, tr("Select region to export"),
Chris@0 1788 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
Chris@0 1789 items, 0, &ok);
Chris@0 1790
Chris@0 1791 if (!ok || item.isEmpty()) return;
Chris@0 1792
Chris@0 1793 if (item == items[0]) {
Chris@0 1794
Chris@38 1795 selectionToWrite = &ms;
Chris@38 1796
Chris@38 1797 } else if (item == items[1]) {
Chris@0 1798
Chris@0 1799 multiple = true;
Chris@0 1800
Chris@0 1801 int n = 1;
Chris@0 1802 QString base = path;
Chris@0 1803 base.replace(".wav", "");
Chris@0 1804
Chris@0 1805 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 1806 i != selections.end(); ++i) {
Chris@0 1807
Chris@0 1808 MultiSelection subms;
Chris@0 1809 subms.setSelection(*i);
Chris@0 1810
Chris@0 1811 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
Chris@0 1812 ++n;
Chris@0 1813
Chris@0 1814 if (QFileInfo(subpath).exists()) {
Chris@0 1815 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
Chris@0 1816 break;
Chris@0 1817 }
Chris@0 1818
Chris@38 1819 WavFileWriter subwriter(subpath,
Chris@38 1820 getMainModel()->getSampleRate(),
Chris@38 1821 getMainModel()->getChannelCount());
Chris@38 1822 subwriter.writeModel(getMainModel(), &subms);
Chris@0 1823 ok = subwriter.isOK();
Chris@0 1824
Chris@0 1825 if (!ok) {
Chris@0 1826 error = subwriter.getError();
Chris@0 1827 break;
Chris@0 1828 }
Chris@0 1829 }
Chris@0 1830 }
Chris@0 1831 }
Chris@0 1832
Chris@38 1833 if (!multiple) {
Chris@38 1834 WavFileWriter writer(path,
Chris@38 1835 getMainModel()->getSampleRate(),
Chris@38 1836 getMainModel()->getChannelCount());
Chris@38 1837 writer.writeModel(getMainModel(), selectionToWrite);
Chris@38 1838 ok = writer.isOK();
Chris@38 1839 error = writer.getError();
Chris@0 1840 }
Chris@0 1841
Chris@0 1842 if (ok) {
Chris@0 1843 if (!multiple) {
Chris@34 1844 m_recentFiles.addFile(path);
Chris@0 1845 }
Chris@0 1846 } else {
Chris@0 1847 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 1848 }
Chris@0 1849 }
Chris@0 1850
Chris@0 1851 void
Chris@0 1852 MainWindow::importLayer()
Chris@0 1853 {
Chris@0 1854 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 1855
Chris@0 1856 if (!pane) {
Chris@0 1857 // shouldn't happen, as the menu action should have been disabled
Chris@0 1858 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
Chris@0 1859 return;
Chris@0 1860 }
Chris@0 1861
Chris@0 1862 if (!getMainModel()) {
Chris@0 1863 // shouldn't happen, as the menu action should have been disabled
Chris@0 1864 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
Chris@0 1865 return;
Chris@0 1866 }
Chris@0 1867
Chris@0 1868 QString path = QFileDialog::getOpenFileName
Chris@0 1869 (this, tr("Select file"), ".",
Chris@0 1870 tr("All supported files (%1)\nSonic Visualiser Layer XML files (*.svl)\nComma-separated data files (*.csv)\nSpace-separated .lab files (*.lab)\nMIDI files (*.mid)\nText files (*.txt)\nAll files (*.*)").arg(DataFileReaderFactory::getKnownExtensions()));
Chris@0 1871
Chris@0 1872 if (path != "") {
Chris@0 1873
Chris@0 1874 if (!openLayerFile(path)) {
Chris@0 1875 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1876 tr("File %1 could not be opened.").arg(path));
Chris@0 1877 return;
Chris@0 1878 }
Chris@0 1879 }
Chris@0 1880 }
Chris@0 1881
Chris@0 1882 bool
Chris@0 1883 MainWindow::openLayerFile(QString path)
Chris@0 1884 {
Chris@0 1885 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 1886
Chris@0 1887 if (!pane) {
Chris@0 1888 // shouldn't happen, as the menu action should have been disabled
Chris@0 1889 std::cerr << "WARNING: MainWindow::openLayerFile: no current pane" << std::endl;
Chris@0 1890 return false;
Chris@0 1891 }
Chris@0 1892
Chris@0 1893 if (!getMainModel()) {
Chris@0 1894 // shouldn't happen, as the menu action should have been disabled
Chris@0 1895 std::cerr << "WARNING: MainWindow::openLayerFile: No main model -- hence no default sample rate available" << std::endl;
Chris@0 1896 return false;
Chris@0 1897 }
Chris@0 1898
Chris@0 1899 if (path.endsWith(".svl") || path.endsWith(".xml")) {
Chris@0 1900
Chris@0 1901 PaneCallback callback(this);
Chris@0 1902 QFile file(path);
Chris@0 1903
Chris@0 1904 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
Chris@0 1905 std::cerr << "ERROR: MainWindow::openLayerFile("
Chris@0 1906 << path.toStdString()
Chris@0 1907 << "): Failed to open file for reading" << std::endl;
Chris@0 1908 return false;
Chris@0 1909 }
Chris@0 1910
Chris@0 1911 SVFileReader reader(m_document, callback);
Chris@0 1912 reader.setCurrentPane(pane);
Chris@0 1913
Chris@0 1914 QXmlInputSource inputSource(&file);
Chris@0 1915 reader.parse(inputSource);
Chris@0 1916
Chris@0 1917 if (!reader.isOK()) {
Chris@0 1918 std::cerr << "ERROR: MainWindow::openLayerFile("
Chris@0 1919 << path.toStdString()
Chris@0 1920 << "): Failed to read XML file: "
Chris@0 1921 << reader.getErrorString().toStdString() << std::endl;
Chris@0 1922 return false;
Chris@0 1923 }
Chris@0 1924
Chris@34 1925 m_recentFiles.addFile(path);
Chris@0 1926 return true;
Chris@0 1927
Chris@0 1928 } else {
Chris@0 1929
Chris@0 1930 Model *model = DataFileReaderFactory::load(path, getMainModel()->getSampleRate());
Chris@0 1931
Chris@0 1932 if (model) {
Chris@0 1933 Layer *newLayer = m_document->createImportedLayer(model);
Chris@0 1934 if (newLayer) {
Chris@0 1935 m_document->addLayerToView(pane, newLayer);
Chris@34 1936 m_recentFiles.addFile(path);
Chris@0 1937 return true;
Chris@0 1938 }
Chris@0 1939 }
Chris@0 1940 }
Chris@0 1941
Chris@0 1942 return false;
Chris@0 1943 }
Chris@0 1944
Chris@0 1945 void
Chris@0 1946 MainWindow::exportLayer()
Chris@0 1947 {
Chris@0 1948 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 1949 if (!pane) return;
Chris@0 1950
Chris@0 1951 Layer *layer = pane->getSelectedLayer();
Chris@0 1952 if (!layer) return;
Chris@0 1953
Chris@0 1954 Model *model = layer->getModel();
Chris@0 1955 if (!model) return;
Chris@0 1956
Chris@0 1957 QString path = QFileDialog::getSaveFileName
Chris@0 1958 (this, tr("Select a file to export to"), ".",
Chris@0 1959 tr("Sonic Visualiser Layer XML files (*.svl)\nComma-separated data files (*.csv)\nText files (*.txt)\nAll files (*.*)"));
Chris@0 1960
Chris@0 1961 if (path == "") return;
Chris@0 1962
Chris@0 1963 if (QFileInfo(path).suffix() == "") path += ".svl";
Chris@0 1964
Chris@0 1965 QString error;
Chris@0 1966
Chris@0 1967 if (path.endsWith(".xml") || path.endsWith(".svl")) {
Chris@0 1968
Chris@0 1969 QFile file(path);
Chris@0 1970 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@0 1971 error = tr("Failed to open file %1 for writing").arg(path);
Chris@0 1972 } else {
Chris@0 1973 QTextStream out(&file);
Chris@0 1974 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Chris@0 1975 << "<!DOCTYPE sonic-visualiser>\n"
Chris@0 1976 << "<sv>\n"
Chris@0 1977 << " <data>\n";
Chris@0 1978
Chris@0 1979 model->toXml(out, " ");
Chris@0 1980
Chris@0 1981 out << " </data>\n"
Chris@0 1982 << " <display>\n";
Chris@0 1983
Chris@0 1984 layer->toXml(out, " ");
Chris@0 1985
Chris@0 1986 out << " </display>\n"
Chris@0 1987 << "</sv>\n";
Chris@0 1988 }
Chris@0 1989
Chris@0 1990 } else {
Chris@0 1991
Chris@0 1992 CSVFileWriter writer(path, model,
Chris@0 1993 (path.endsWith(".csv") ? "," : "\t"));
Chris@0 1994 writer.write();
Chris@0 1995
Chris@0 1996 if (!writer.isOK()) {
Chris@0 1997 error = writer.getError();
Chris@0 1998 }
Chris@0 1999 }
Chris@0 2000
Chris@0 2001 if (error != "") {
Chris@0 2002 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2003 } else {
Chris@34 2004 m_recentFiles.addFile(path);
Chris@0 2005 }
Chris@0 2006 }
Chris@0 2007
Chris@0 2008 bool
Chris@0 2009 MainWindow::openAudioFile(QString path, AudioFileOpenMode mode)
Chris@0 2010 {
Chris@0 2011 if (!(QFileInfo(path).exists() &&
Chris@0 2012 QFileInfo(path).isFile() &&
Chris@0 2013 QFileInfo(path).isReadable())) {
Chris@0 2014 return false;
Chris@0 2015 }
Chris@0 2016
Chris@0 2017 WaveFileModel *newModel = new WaveFileModel(path);
Chris@0 2018
Chris@0 2019 if (!newModel->isOK()) {
Chris@0 2020 delete newModel;
Chris@0 2021 return false;
Chris@0 2022 }
Chris@0 2023
Chris@0 2024 bool setAsMain = true;
Chris@0 2025 static bool prevSetAsMain = true;
Chris@0 2026
Chris@0 2027 if (mode == CreateAdditionalModel) setAsMain = false;
Chris@0 2028 else if (mode == AskUser) {
Chris@0 2029 if (m_document->getMainModel()) {
Chris@0 2030
Chris@0 2031 QStringList items;
Chris@0 2032 items << tr("Replace the existing main waveform")
Chris@0 2033 << tr("Load this file into a new waveform pane");
Chris@0 2034
Chris@0 2035 bool ok = false;
Chris@0 2036 QString item = ListInputDialog::getItem
Chris@0 2037 (this, tr("Select target for import"),
Chris@0 2038 tr("You already have an audio waveform loaded.\nWhat would you like to do with the new audio file?"),
Chris@0 2039 items, prevSetAsMain ? 0 : 1, &ok);
Chris@0 2040
Chris@0 2041 if (!ok || item.isEmpty()) {
Chris@0 2042 delete newModel;
Chris@0 2043 return false;
Chris@0 2044 }
Chris@0 2045
Chris@0 2046 setAsMain = (item == items[0]);
Chris@0 2047 prevSetAsMain = setAsMain;
Chris@0 2048 }
Chris@0 2049 }
Chris@0 2050
Chris@0 2051 if (setAsMain) {
Chris@0 2052
Chris@0 2053 Model *prevMain = getMainModel();
Chris@0 2054 if (prevMain) m_playSource->removeModel(prevMain);
Chris@0 2055
Chris@0 2056 PlayParameterRepository::getInstance()->clear();
Chris@0 2057
Chris@0 2058 // The clear() call will have removed the parameters for the
Chris@0 2059 // main model. Re-add them with the new one.
Chris@0 2060 PlayParameterRepository::getInstance()->addModel(newModel);
Chris@0 2061
Chris@0 2062 m_document->setMainModel(newModel);
Chris@0 2063 setupMenus();
Chris@0 2064
Chris@0 2065 if (m_sessionFile == "") {
Chris@0 2066 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 2067 .arg(QFileInfo(path).fileName()));
Chris@0 2068 CommandHistory::getInstance()->clear();
Chris@0 2069 CommandHistory::getInstance()->documentSaved();
Chris@0 2070 m_documentModified = false;
Chris@0 2071 } else {
Chris@0 2072 setWindowTitle(tr("Sonic Visualiser: %1 [%2]")
Chris@0 2073 .arg(QFileInfo(m_sessionFile).fileName())
Chris@0 2074 .arg(QFileInfo(path).fileName()));
Chris@0 2075 if (m_documentModified) {
Chris@0 2076 m_documentModified = false;
Chris@0 2077 documentModified(); // so as to restore "(modified)" window title
Chris@0 2078 }
Chris@0 2079 }
Chris@0 2080
Chris@0 2081 m_audioFile = path;
Chris@0 2082
Chris@0 2083 } else { // !setAsMain
Chris@0 2084
Chris@0 2085 CommandHistory::getInstance()->startCompoundOperation
Chris@0 2086 (tr("Import \"%1\"").arg(QFileInfo(path).fileName()), true);
Chris@0 2087
Chris@0 2088 m_document->addImportedModel(newModel);
Chris@0 2089
Chris@0 2090 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2091 CommandHistory::getInstance()->addCommand(command);
Chris@0 2092
Chris@0 2093 Pane *pane = command->getPane();
Chris@0 2094
Chris@0 2095 if (!m_timeRulerLayer) {
Chris@0 2096 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2097 (LayerFactory::TimeRuler);
Chris@0 2098 }
Chris@0 2099
Chris@0 2100 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2101
Chris@0 2102 Layer *newLayer = m_document->createImportedLayer(newModel);
Chris@0 2103
Chris@0 2104 if (newLayer) {
Chris@0 2105 m_document->addLayerToView(pane, newLayer);
Chris@0 2106 }
Chris@0 2107
Chris@0 2108 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 2109 }
Chris@0 2110
Chris@0 2111 updateMenuStates();
Chris@34 2112 m_recentFiles.addFile(path);
Chris@0 2113
Chris@0 2114 return true;
Chris@0 2115 }
Chris@0 2116
Chris@0 2117 void
Chris@0 2118 MainWindow::createPlayTarget()
Chris@0 2119 {
Chris@0 2120 if (m_playTarget) return;
Chris@0 2121
Chris@0 2122 m_playTarget = AudioTargetFactory::createCallbackTarget(m_playSource);
Chris@0 2123 if (!m_playTarget) {
Chris@0 2124 QMessageBox::warning
Chris@0 2125 (this, tr("Couldn't open audio device"),
Chris@0 2126 tr("Could not open an audio device for playback.\nAudio playback will not be available during this session.\n"),
Chris@0 2127 QMessageBox::Ok, 0);
Chris@0 2128 }
Chris@0 2129 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@0 2130 m_playTarget, SLOT(setOutputGain(float)));
Chris@0 2131 }
Chris@0 2132
Chris@0 2133 WaveFileModel *
Chris@0 2134 MainWindow::getMainModel()
Chris@0 2135 {
Chris@0 2136 if (!m_document) return 0;
Chris@0 2137 return m_document->getMainModel();
Chris@0 2138 }
Chris@0 2139
Chris@0 2140 void
Chris@0 2141 MainWindow::newSession()
Chris@0 2142 {
Chris@0 2143 if (!checkSaveModified()) return;
Chris@0 2144
Chris@0 2145 closeSession();
Chris@0 2146 createDocument();
Chris@0 2147
Chris@0 2148 Pane *pane = m_paneStack->addPane();
Chris@0 2149
Chris@0 2150 if (!m_timeRulerLayer) {
Chris@0 2151 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2152 (LayerFactory::TimeRuler);
Chris@0 2153 }
Chris@0 2154
Chris@0 2155 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2156
Chris@0 2157 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@0 2158 m_document->addLayerToView(pane, waveform);
Chris@0 2159
Chris@65 2160 m_overview->registerView(pane);
Chris@0 2161
Chris@0 2162 CommandHistory::getInstance()->clear();
Chris@0 2163 CommandHistory::getInstance()->documentSaved();
Chris@0 2164 documentRestored();
Chris@0 2165 updateMenuStates();
Chris@0 2166 }
Chris@0 2167
Chris@0 2168 void
Chris@0 2169 MainWindow::createDocument()
Chris@0 2170 {
Chris@0 2171 m_document = new Document;
Chris@0 2172
Chris@0 2173 connect(m_document, SIGNAL(layerAdded(Layer *)),
Chris@0 2174 this, SLOT(layerAdded(Layer *)));
Chris@0 2175 connect(m_document, SIGNAL(layerRemoved(Layer *)),
Chris@0 2176 this, SLOT(layerRemoved(Layer *)));
Chris@0 2177 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
Chris@0 2178 this, SLOT(layerAboutToBeDeleted(Layer *)));
Chris@0 2179 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
Chris@0 2180 this, SLOT(layerInAView(Layer *, bool)));
Chris@0 2181
Chris@0 2182 connect(m_document, SIGNAL(modelAdded(Model *)),
Chris@0 2183 this, SLOT(modelAdded(Model *)));
Chris@0 2184 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
Chris@0 2185 this, SLOT(mainModelChanged(WaveFileModel *)));
Chris@0 2186 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@0 2187 this, SLOT(modelAboutToBeDeleted(Model *)));
Chris@0 2188
Chris@0 2189 connect(m_document, SIGNAL(modelGenerationFailed(QString)),
Chris@0 2190 this, SLOT(modelGenerationFailed(QString)));
Chris@63 2191 connect(m_document, SIGNAL(modelRegenerationFailed(QString, QString)),
Chris@63 2192 this, SLOT(modelRegenerationFailed(QString, QString)));
Chris@0 2193 }
Chris@0 2194
Chris@0 2195 void
Chris@0 2196 MainWindow::closeSession()
Chris@0 2197 {
Chris@0 2198 if (!checkSaveModified()) return;
Chris@0 2199
Chris@0 2200 while (m_paneStack->getPaneCount() > 0) {
Chris@0 2201
Chris@0 2202 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@0 2203
Chris@0 2204 while (pane->getLayerCount() > 0) {
Chris@0 2205 m_document->removeLayerFromView
Chris@0 2206 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2207 }
Chris@0 2208
Chris@65 2209 m_overview->unregisterView(pane);
Chris@0 2210 m_paneStack->deletePane(pane);
Chris@0 2211 }
Chris@0 2212
Chris@0 2213 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 2214
Chris@0 2215 Pane *pane = m_paneStack->getHiddenPane
Chris@0 2216 (m_paneStack->getHiddenPaneCount() - 1);
Chris@0 2217
Chris@0 2218 while (pane->getLayerCount() > 0) {
Chris@0 2219 m_document->removeLayerFromView
Chris@0 2220 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2221 }
Chris@0 2222
Chris@65 2223 m_overview->unregisterView(pane);
Chris@0 2224 m_paneStack->deletePane(pane);
Chris@0 2225 }
Chris@0 2226
Chris@0 2227 delete m_document;
Chris@0 2228 m_document = 0;
Chris@0 2229 m_viewManager->clearSelections();
Chris@0 2230 m_timeRulerLayer = 0; // document owned this
Chris@0 2231
Chris@0 2232 m_sessionFile = "";
Chris@0 2233 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 2234
Chris@0 2235 CommandHistory::getInstance()->clear();
Chris@0 2236 CommandHistory::getInstance()->documentSaved();
Chris@0 2237 documentRestored();
Chris@0 2238 }
Chris@0 2239
Chris@0 2240 void
Chris@0 2241 MainWindow::openSession()
Chris@0 2242 {
Chris@0 2243 if (!checkSaveModified()) return;
Chris@0 2244
Chris@0 2245 QString orig = m_audioFile;
Chris@0 2246 if (orig == "") orig = ".";
Chris@0 2247 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2248
Chris@0 2249 QString path = QFileDialog::getOpenFileName
Chris@0 2250 (this, tr("Select a session file"), orig,
Chris@0 2251 tr("Sonic Visualiser session files (*.sv)\nAll files (*.*)"));
Chris@0 2252
Chris@0 2253 if (path.isEmpty()) return;
Chris@0 2254
Chris@0 2255 if (!(QFileInfo(path).exists() &&
Chris@0 2256 QFileInfo(path).isFile() &&
Chris@0 2257 QFileInfo(path).isReadable())) {
Chris@0 2258 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2259 tr("File \"%1\" does not exist or is not a readable file").arg(path));
Chris@0 2260 return;
Chris@0 2261 }
Chris@0 2262
Chris@0 2263 if (!openSessionFile(path)) {
Chris@0 2264 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2265 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2266 }
Chris@0 2267 }
Chris@0 2268
Chris@0 2269 void
Chris@0 2270 MainWindow::openSomething()
Chris@0 2271 {
Chris@0 2272 QString orig = m_audioFile;
Chris@0 2273 if (orig == "") orig = ".";
Chris@0 2274 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2275
Chris@0 2276 bool canImportLayer = (getMainModel() != 0 &&
Chris@0 2277 m_paneStack != 0 &&
Chris@0 2278 m_paneStack->getCurrentPane() != 0);
Chris@0 2279
Chris@0 2280 QString importSpec;
Chris@0 2281
Chris@0 2282 if (canImportLayer) {
Chris@0 2283 importSpec = tr("All supported files (*.sv %1 %2)\nSonic Visualiser session files (*.sv)\nAudio files (%1)\nLayer files (%2)\nAll files (*.*)")
Chris@0 2284 .arg(AudioFileReaderFactory::getKnownExtensions())
Chris@0 2285 .arg(DataFileReaderFactory::getKnownExtensions());
Chris@0 2286 } else {
Chris@0 2287 importSpec = tr("All supported files (*.sv %1)\nSonic Visualiser session files (*.sv)\nAudio files (%1)\nAll files (*.*)")
Chris@0 2288 .arg(AudioFileReaderFactory::getKnownExtensions());
Chris@0 2289 }
Chris@0 2290
Chris@0 2291 QString path = QFileDialog::getOpenFileName
Chris@0 2292 (this, tr("Select a file to open"), orig, importSpec);
Chris@0 2293
Chris@0 2294 if (path.isEmpty()) return;
Chris@0 2295
Chris@0 2296 if (!(QFileInfo(path).exists() &&
Chris@0 2297 QFileInfo(path).isFile() &&
Chris@0 2298 QFileInfo(path).isReadable())) {
Chris@0 2299 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2300 tr("File \"%1\" does not exist or is not a readable file").arg(path));
Chris@0 2301 return;
Chris@0 2302 }
Chris@0 2303
Chris@0 2304 if (path.endsWith(".sv")) {
Chris@0 2305
Chris@0 2306 if (!checkSaveModified()) return;
Chris@0 2307
Chris@0 2308 if (!openSessionFile(path)) {
Chris@0 2309 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2310 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2311 }
Chris@0 2312
Chris@0 2313 } else {
Chris@0 2314
Chris@0 2315 if (!openAudioFile(path, AskUser)) {
Chris@0 2316
Chris@0 2317 if (!canImportLayer || !openLayerFile(path)) {
Chris@0 2318
Chris@0 2319 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2320 tr("File \"%1\" could not be opened").arg(path));
Chris@0 2321 }
Chris@0 2322 }
Chris@0 2323 }
Chris@0 2324 }
Chris@0 2325
Chris@0 2326 void
Chris@0 2327 MainWindow::openRecentFile()
Chris@0 2328 {
Chris@0 2329 QObject *obj = sender();
Chris@0 2330 QAction *action = dynamic_cast<QAction *>(obj);
Chris@0 2331
Chris@0 2332 if (!action) {
Chris@0 2333 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@0 2334 << std::endl;
Chris@0 2335 return;
Chris@0 2336 }
Chris@0 2337
Chris@0 2338 QString path = action->text();
Chris@0 2339 if (path == "") return;
Chris@0 2340
Chris@0 2341 if (path.endsWith("sv")) {
Chris@0 2342
Chris@0 2343 if (!checkSaveModified()) return ;
Chris@0 2344
Chris@0 2345 if (!openSessionFile(path)) {
Chris@0 2346 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2347 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2348 }
Chris@0 2349
Chris@0 2350 } else {
Chris@0 2351
Chris@0 2352 if (!openAudioFile(path, AskUser)) {
Chris@0 2353
Chris@0 2354 bool canImportLayer = (getMainModel() != 0 &&
Chris@0 2355 m_paneStack != 0 &&
Chris@0 2356 m_paneStack->getCurrentPane() != 0);
Chris@0 2357
Chris@0 2358 if (!canImportLayer || !openLayerFile(path)) {
Chris@0 2359
Chris@0 2360 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2361 tr("File \"%1\" could not be opened").arg(path));
Chris@0 2362 }
Chris@0 2363 }
Chris@0 2364 }
Chris@0 2365 }
Chris@0 2366
Chris@0 2367 bool
Chris@54 2368 MainWindow::openSomeFile(QString path, AudioFileOpenMode mode)
Chris@0 2369 {
Chris@54 2370 if (openAudioFile(path, mode)) {
Chris@0 2371 return true;
Chris@0 2372 } else if (openSessionFile(path)) {
Chris@0 2373 return true;
Chris@0 2374 } else {
Chris@0 2375 return false;
Chris@0 2376 }
Chris@0 2377 }
Chris@0 2378
Chris@0 2379 bool
Chris@0 2380 MainWindow::openSessionFile(QString path)
Chris@0 2381 {
Chris@0 2382 BZipFileDevice bzFile(path);
Chris@0 2383 if (!bzFile.open(QIODevice::ReadOnly)) {
Chris@0 2384 std::cerr << "Failed to open session file \"" << path.toStdString()
Chris@0 2385 << "\": " << bzFile.errorString().toStdString() << std::endl;
Chris@0 2386 return false;
Chris@0 2387 }
Chris@0 2388
Chris@0 2389 QString error;
Chris@0 2390 closeSession();
Chris@0 2391 createDocument();
Chris@0 2392
Chris@0 2393 PaneCallback callback(this);
Chris@0 2394 m_viewManager->clearSelections();
Chris@0 2395
Chris@0 2396 SVFileReader reader(m_document, callback);
Chris@0 2397 QXmlInputSource inputSource(&bzFile);
Chris@0 2398 reader.parse(inputSource);
Chris@0 2399
Chris@0 2400 if (!reader.isOK()) {
Chris@0 2401 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
Chris@0 2402 }
Chris@0 2403
Chris@0 2404 bzFile.close();
Chris@0 2405
Chris@0 2406 bool ok = (error == "");
Chris@0 2407
Chris@0 2408 if (ok) {
Chris@0 2409 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 2410 .arg(QFileInfo(path).fileName()));
Chris@0 2411 m_sessionFile = path;
Chris@0 2412 setupMenus();
Chris@0 2413 CommandHistory::getInstance()->clear();
Chris@0 2414 CommandHistory::getInstance()->documentSaved();
Chris@0 2415 m_documentModified = false;
Chris@0 2416 updateMenuStates();
Chris@34 2417 m_recentFiles.addFile(path);
Chris@0 2418 } else {
Chris@0 2419 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 2420 }
Chris@0 2421
Chris@0 2422 return ok;
Chris@0 2423 }
Chris@0 2424
Chris@0 2425 void
Chris@0 2426 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 2427 {
Chris@0 2428 if (!checkSaveModified()) {
Chris@0 2429 e->ignore();
Chris@0 2430 return;
Chris@0 2431 }
Chris@0 2432
Chris@5 2433 QSettings settings;
Chris@5 2434 settings.beginGroup("MainWindow");
Chris@5 2435 settings.setValue("size", size());
Chris@5 2436 settings.setValue("position", pos());
Chris@5 2437 settings.endGroup();
Chris@5 2438
Chris@0 2439 e->accept();
Chris@0 2440 return;
Chris@0 2441 }
Chris@0 2442
Chris@0 2443 bool
Chris@11 2444 MainWindow::commitData(bool mayAskUser)
Chris@11 2445 {
Chris@11 2446 if (mayAskUser) {
Chris@11 2447 return checkSaveModified();
Chris@11 2448 } else {
Chris@11 2449 if (!m_documentModified) return true;
Chris@11 2450
Chris@11 2451 // If we can't check with the user first, then we can't save
Chris@11 2452 // to the original session file (even if we have it) -- have
Chris@11 2453 // to use a temporary file
Chris@11 2454
Chris@11 2455 QString svDirBase = ".sv1";
Chris@11 2456 QString svDir = QDir::home().filePath(svDirBase);
Chris@11 2457
Chris@11 2458 if (!QFileInfo(svDir).exists()) {
Chris@11 2459 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@11 2460 } else {
Chris@11 2461 if (!QFileInfo(svDir).isDir()) return false;
Chris@11 2462 }
Chris@11 2463
Chris@11 2464 // This name doesn't have to be unguessable
Chris@11 2465
Chris@11 2466 QString fname = QString("tmp-%1-%2.sv")
Chris@11 2467 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@11 2468 .arg(QProcess().pid());
Chris@11 2469 QString fpath = QDir(svDir).filePath(fname);
Chris@11 2470 if (saveSessionFile(fpath)) {
Chris@34 2471 m_recentFiles.addFile(fpath);
Chris@11 2472 return true;
Chris@11 2473 } else {
Chris@11 2474 return false;
Chris@11 2475 }
Chris@11 2476 }
Chris@11 2477 }
Chris@11 2478
Chris@11 2479 bool
Chris@0 2480 MainWindow::checkSaveModified()
Chris@0 2481 {
Chris@0 2482 // Called before some destructive operation (e.g. new session,
Chris@0 2483 // exit program). Return true if we can safely proceed, false to
Chris@0 2484 // cancel.
Chris@0 2485
Chris@0 2486 if (!m_documentModified) return true;
Chris@0 2487
Chris@0 2488 int button =
Chris@0 2489 QMessageBox::warning(this,
Chris@0 2490 tr("Session modified"),
Chris@0 2491 tr("The current session has been modified.\nDo you want to save it?"),
Chris@0 2492 QMessageBox::Yes,
Chris@0 2493 QMessageBox::No,
Chris@0 2494 QMessageBox::Cancel);
Chris@0 2495
Chris@0 2496 if (button == QMessageBox::Yes) {
Chris@0 2497 saveSession();
Chris@0 2498 if (m_documentModified) { // save failed -- don't proceed!
Chris@0 2499 return false;
Chris@0 2500 } else {
Chris@0 2501 return true; // saved, so it's safe to continue now
Chris@0 2502 }
Chris@0 2503 } else if (button == QMessageBox::No) {
Chris@0 2504 m_documentModified = false; // so we know to abandon it
Chris@0 2505 return true;
Chris@0 2506 }
Chris@0 2507
Chris@0 2508 // else cancel
Chris@0 2509 return false;
Chris@0 2510 }
Chris@0 2511
Chris@0 2512 void
Chris@0 2513 MainWindow::saveSession()
Chris@0 2514 {
Chris@0 2515 if (m_sessionFile != "") {
Chris@0 2516 if (!saveSessionFile(m_sessionFile)) {
Chris@0 2517 QMessageBox::critical(this, tr("Failed to save file"),
Chris@0 2518 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 2519 } else {
Chris@0 2520 CommandHistory::getInstance()->documentSaved();
Chris@0 2521 documentRestored();
Chris@0 2522 }
Chris@0 2523 } else {
Chris@0 2524 saveSessionAs();
Chris@0 2525 }
Chris@0 2526 }
Chris@0 2527
Chris@0 2528 void
Chris@0 2529 MainWindow::saveSessionAs()
Chris@0 2530 {
Chris@0 2531 QString orig = m_audioFile;
Chris@0 2532 if (orig == "") orig = ".";
Chris@0 2533 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2534
Chris@0 2535 QString path;
Chris@0 2536 bool good = false;
Chris@0 2537
Chris@0 2538 while (!good) {
Chris@0 2539
Chris@0 2540 path = QFileDialog::getSaveFileName
Chris@0 2541 (this, tr("Select a file to save to"), orig,
Chris@0 2542 tr("Sonic Visualiser session files (*.sv)\nAll files (*.*)"), 0,
Chris@0 2543 QFileDialog::DontConfirmOverwrite); // we'll do that
Chris@0 2544
Chris@0 2545 if (path.isEmpty()) return;
Chris@0 2546
Chris@0 2547 if (!path.endsWith(".sv")) path = path + ".sv";
Chris@0 2548
Chris@0 2549 QFileInfo fi(path);
Chris@0 2550
Chris@0 2551 if (fi.isDir()) {
Chris@0 2552 QMessageBox::critical(this, tr("Directory selected"),
Chris@0 2553 tr("File \"%1\" is a directory").arg(path));
Chris@0 2554 continue;
Chris@0 2555 }
Chris@0 2556
Chris@0 2557 if (fi.exists()) {
Chris@0 2558 if (QMessageBox::question(this, tr("File exists"),
Chris@0 2559 tr("The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path),
Chris@0 2560 QMessageBox::Ok,
Chris@0 2561 QMessageBox::Cancel) == QMessageBox::Ok) {
Chris@0 2562 good = true;
Chris@0 2563 } else {
Chris@0 2564 continue;
Chris@0 2565 }
Chris@0 2566 }
Chris@0 2567
Chris@0 2568 good = true;
Chris@0 2569 }
Chris@0 2570
Chris@0 2571 if (!saveSessionFile(path)) {
Chris@0 2572 QMessageBox::critical(this, tr("Failed to save file"),
Chris@0 2573 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 2574 } else {
Chris@0 2575 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 2576 .arg(QFileInfo(path).fileName()));
Chris@0 2577 m_sessionFile = path;
Chris@0 2578 CommandHistory::getInstance()->documentSaved();
Chris@0 2579 documentRestored();
Chris@34 2580 m_recentFiles.addFile(path);
Chris@0 2581 }
Chris@0 2582 }
Chris@0 2583
Chris@0 2584 bool
Chris@0 2585 MainWindow::saveSessionFile(QString path)
Chris@0 2586 {
Chris@0 2587 BZipFileDevice bzFile(path);
Chris@0 2588 if (!bzFile.open(QIODevice::WriteOnly)) {
Chris@0 2589 std::cerr << "Failed to open session file \"" << path.toStdString()
Chris@0 2590 << "\" for writing: "
Chris@0 2591 << bzFile.errorString().toStdString() << std::endl;
Chris@0 2592 return false;
Chris@0 2593 }
Chris@0 2594
Chris@0 2595 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
Chris@0 2596
Chris@0 2597 QTextStream out(&bzFile);
Chris@0 2598 toXml(out);
Chris@0 2599 out.flush();
Chris@0 2600
Chris@0 2601 QApplication::restoreOverrideCursor();
Chris@0 2602
Chris@0 2603 if (bzFile.errorString() != "") {
Chris@0 2604 QMessageBox::critical(this, tr("Failed to write file"),
Chris@0 2605 tr("Failed to write to file \"%1\": %2")
Chris@0 2606 .arg(path).arg(bzFile.errorString()));
Chris@0 2607 bzFile.close();
Chris@0 2608 return false;
Chris@0 2609 }
Chris@0 2610
Chris@0 2611 bzFile.close();
Chris@0 2612 return true;
Chris@0 2613 }
Chris@0 2614
Chris@0 2615 void
Chris@0 2616 MainWindow::toXml(QTextStream &out)
Chris@0 2617 {
Chris@0 2618 QString indent(" ");
Chris@0 2619
Chris@0 2620 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
Chris@0 2621 out << "<!DOCTYPE sonic-visualiser>\n";
Chris@0 2622 out << "<sv>\n";
Chris@0 2623
Chris@0 2624 m_document->toXml(out, "", "");
Chris@0 2625
Chris@0 2626 out << "<display>\n";
Chris@0 2627
Chris@0 2628 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
Chris@0 2629 .arg(width()).arg(height());
Chris@0 2630
Chris@0 2631 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 2632
Chris@0 2633 Pane *pane = m_paneStack->getPane(i);
Chris@0 2634
Chris@0 2635 if (pane) {
Chris@0 2636 pane->toXml(out, indent);
Chris@0 2637 }
Chris@0 2638 }
Chris@0 2639
Chris@0 2640 out << "</display>\n";
Chris@0 2641
Chris@0 2642 m_viewManager->getSelection().toXml(out);
Chris@0 2643
Chris@0 2644 out << "</sv>\n";
Chris@0 2645 }
Chris@0 2646
Chris@0 2647 Pane *
Chris@0 2648 MainWindow::addPaneToStack()
Chris@0 2649 {
Chris@0 2650 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2651 CommandHistory::getInstance()->addCommand(command);
Chris@0 2652 return command->getPane();
Chris@0 2653 }
Chris@0 2654
Chris@0 2655 void
Chris@0 2656 MainWindow::zoomIn()
Chris@0 2657 {
Chris@0 2658 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2659 if (currentPane) currentPane->zoom(true);
Chris@0 2660 }
Chris@0 2661
Chris@0 2662 void
Chris@0 2663 MainWindow::zoomOut()
Chris@0 2664 {
Chris@0 2665 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2666 if (currentPane) currentPane->zoom(false);
Chris@0 2667 }
Chris@0 2668
Chris@0 2669 void
Chris@0 2670 MainWindow::zoomToFit()
Chris@0 2671 {
Chris@0 2672 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2673 if (!currentPane) return;
Chris@0 2674
Chris@0 2675 Model *model = getMainModel();
Chris@0 2676 if (!model) return;
Chris@0 2677
Chris@0 2678 size_t start = model->getStartFrame();
Chris@0 2679 size_t end = model->getEndFrame();
Chris@0 2680 size_t pixels = currentPane->width();
Chris@0 2681 size_t zoomLevel = (end - start) / pixels;
Chris@0 2682
Chris@0 2683 currentPane->setZoomLevel(zoomLevel);
Chris@0 2684 currentPane->setStartFrame(start);
Chris@0 2685 }
Chris@0 2686
Chris@0 2687 void
Chris@0 2688 MainWindow::zoomDefault()
Chris@0 2689 {
Chris@0 2690 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2691 if (currentPane) currentPane->setZoomLevel(1024);
Chris@0 2692 }
Chris@0 2693
Chris@0 2694 void
Chris@0 2695 MainWindow::scrollLeft()
Chris@0 2696 {
Chris@0 2697 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2698 if (currentPane) currentPane->scroll(false, false);
Chris@0 2699 }
Chris@0 2700
Chris@0 2701 void
Chris@0 2702 MainWindow::jumpLeft()
Chris@0 2703 {
Chris@0 2704 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2705 if (currentPane) currentPane->scroll(false, true);
Chris@0 2706 }
Chris@0 2707
Chris@0 2708 void
Chris@0 2709 MainWindow::scrollRight()
Chris@0 2710 {
Chris@0 2711 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2712 if (currentPane) currentPane->scroll(true, false);
Chris@0 2713 }
Chris@0 2714
Chris@0 2715 void
Chris@0 2716 MainWindow::jumpRight()
Chris@0 2717 {
Chris@0 2718 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2719 if (currentPane) currentPane->scroll(true, true);
Chris@0 2720 }
Chris@0 2721
Chris@0 2722 void
Chris@0 2723 MainWindow::showNoOverlays()
Chris@0 2724 {
Chris@0 2725 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@0 2726 }
Chris@0 2727
Chris@0 2728 void
Chris@0 2729 MainWindow::showBasicOverlays()
Chris@0 2730 {
Chris@0 2731 m_viewManager->setOverlayMode(ViewManager::BasicOverlays);
Chris@0 2732 }
Chris@0 2733
Chris@0 2734 void
Chris@7 2735 MainWindow::showAllTextOverlays()
Chris@0 2736 {
Chris@0 2737 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@0 2738 }
Chris@0 2739
Chris@0 2740 void
Chris@7 2741 MainWindow::toggleZoomWheels()
Chris@7 2742 {
Chris@7 2743 if (m_viewManager->getZoomWheelsEnabled()) {
Chris@7 2744 m_viewManager->setZoomWheelsEnabled(false);
Chris@7 2745 } else {
Chris@7 2746 m_viewManager->setZoomWheelsEnabled(true);
Chris@7 2747 }
Chris@7 2748 }
Chris@7 2749
Chris@7 2750 void
Chris@0 2751 MainWindow::play()
Chris@0 2752 {
Chris@0 2753 if (m_playSource->isPlaying()) {
Chris@0 2754 m_playSource->stop();
Chris@0 2755 } else {
Chris@0 2756 m_playSource->play(m_viewManager->getPlaybackFrame());
Chris@0 2757 }
Chris@0 2758 }
Chris@0 2759
Chris@0 2760 void
Chris@0 2761 MainWindow::ffwd()
Chris@0 2762 {
Chris@0 2763 if (!getMainModel()) return;
Chris@0 2764
Chris@0 2765 int frame = m_viewManager->getPlaybackFrame();
Chris@0 2766 ++frame;
Chris@0 2767
Chris@0 2768 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2769 if (!pane) return;
Chris@0 2770
Chris@0 2771 Layer *layer = pane->getSelectedLayer();
Chris@0 2772
Chris@0 2773 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@0 2774 !dynamic_cast<TimeValueLayer *>(layer)) return;
Chris@0 2775
Chris@0 2776 size_t resolution = 0;
Chris@0 2777 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapRight)) {
Chris@0 2778 frame = getMainModel()->getEndFrame();
Chris@0 2779 }
Chris@0 2780
Chris@0 2781 m_viewManager->setPlaybackFrame(frame);
Chris@0 2782 }
Chris@0 2783
Chris@0 2784 void
Chris@0 2785 MainWindow::ffwdEnd()
Chris@0 2786 {
Chris@0 2787 if (!getMainModel()) return;
Chris@0 2788 m_viewManager->setPlaybackFrame(getMainModel()->getEndFrame());
Chris@0 2789 }
Chris@0 2790
Chris@0 2791 void
Chris@0 2792 MainWindow::rewind()
Chris@0 2793 {
Chris@0 2794 if (!getMainModel()) return;
Chris@0 2795
Chris@0 2796 int frame = m_viewManager->getPlaybackFrame();
Chris@0 2797 if (frame > 0) --frame;
Chris@0 2798
Chris@0 2799 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2800 if (!pane) return;
Chris@0 2801
Chris@0 2802 Layer *layer = pane->getSelectedLayer();
Chris@0 2803
Chris@0 2804 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@0 2805 !dynamic_cast<TimeValueLayer *>(layer)) return;
Chris@0 2806
Chris@0 2807 size_t resolution = 0;
Chris@0 2808 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapLeft)) {
Chris@0 2809 frame = getMainModel()->getEndFrame();
Chris@0 2810 }
Chris@0 2811
Chris@0 2812 m_viewManager->setPlaybackFrame(frame);
Chris@0 2813 }
Chris@0 2814
Chris@0 2815 void
Chris@0 2816 MainWindow::rewindStart()
Chris@0 2817 {
Chris@0 2818 if (!getMainModel()) return;
Chris@0 2819 m_viewManager->setPlaybackFrame(getMainModel()->getStartFrame());
Chris@0 2820 }
Chris@0 2821
Chris@0 2822 void
Chris@0 2823 MainWindow::stop()
Chris@0 2824 {
Chris@0 2825 m_playSource->stop();
Chris@0 2826 }
Chris@0 2827
Chris@0 2828 void
Chris@0 2829 MainWindow::addPane()
Chris@0 2830 {
Chris@0 2831 QObject *s = sender();
Chris@0 2832 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 2833
Chris@0 2834 if (!action) {
Chris@0 2835 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
Chris@0 2836 << std::endl;
Chris@0 2837 return;
Chris@0 2838 }
Chris@0 2839
Chris@0 2840 PaneActionMap::iterator i = m_paneActions.find(action);
Chris@0 2841
Chris@0 2842 if (i == m_paneActions.end()) {
Chris@0 2843 std::cerr << "WARNING: MainWindow::addPane: unknown action "
Chris@0 2844 << action->objectName().toStdString() << std::endl;
Chris@0 2845 return;
Chris@0 2846 }
Chris@0 2847
Chris@0 2848 CommandHistory::getInstance()->startCompoundOperation
Chris@0 2849 (action->text(), true);
Chris@0 2850
Chris@0 2851 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2852 CommandHistory::getInstance()->addCommand(command);
Chris@0 2853
Chris@0 2854 Pane *pane = command->getPane();
Chris@0 2855
Chris@7 2856 if (i->second.layer == LayerFactory::Spectrum) {
Chris@7 2857 pane->setPlaybackFollow(View::PlaybackScrollContinuous);
Chris@7 2858 }
Chris@7 2859
Chris@8 2860 if (i->second.layer != LayerFactory::TimeRuler &&
Chris@8 2861 i->second.layer != LayerFactory::Spectrum) {
Chris@8 2862
Chris@0 2863 if (!m_timeRulerLayer) {
Chris@0 2864 // std::cerr << "no time ruler layer, creating one" << std::endl;
Chris@0 2865 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2866 (LayerFactory::TimeRuler);
Chris@0 2867 }
Chris@0 2868
Chris@0 2869 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
Chris@0 2870
Chris@0 2871 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2872 }
Chris@0 2873
Chris@0 2874 Layer *newLayer = m_document->createLayer(i->second.layer);
Chris@66 2875
Chris@66 2876 Model *suggestedModel = i->second.sourceModel;
Chris@66 2877 Model *model = 0;
Chris@66 2878
Chris@66 2879 if (suggestedModel) {
Chris@66 2880
Chris@66 2881 // check its validity
Chris@66 2882 std::vector<Model *> inputModels = m_document->getTransformInputModels();
Chris@66 2883 for (size_t j = 0; j < inputModels.size(); ++j) {
Chris@66 2884 if (inputModels[j] == suggestedModel) {
Chris@66 2885 model = suggestedModel;
Chris@66 2886 break;
Chris@66 2887 }
Chris@66 2888 }
Chris@66 2889
Chris@66 2890 if (!model) {
Chris@66 2891 std::cerr << "WARNING: Model " << (void *)suggestedModel
Chris@66 2892 << " appears in pane action map, but is not reported "
Chris@66 2893 << "by document as a valid transform source" << std::endl;
Chris@66 2894 }
Chris@66 2895 }
Chris@66 2896
Chris@66 2897 if (!model) model = m_document->getMainModel();
Chris@66 2898
Chris@66 2899 m_document->setModel(newLayer, model);
Chris@66 2900
Chris@0 2901 m_document->setChannel(newLayer, i->second.channel);
Chris@0 2902 m_document->addLayerToView(pane, newLayer);
Chris@0 2903
Chris@0 2904 m_paneStack->setCurrentPane(pane);
Chris@0 2905
Chris@0 2906 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 2907
Chris@0 2908 updateMenuStates();
Chris@0 2909 }
Chris@0 2910
Chris@0 2911 MainWindow::AddPaneCommand::AddPaneCommand(MainWindow *mw) :
Chris@0 2912 m_mw(mw),
Chris@0 2913 m_pane(0),
Chris@0 2914 m_prevCurrentPane(0),
Chris@0 2915 m_added(false)
Chris@0 2916 {
Chris@0 2917 }
Chris@0 2918
Chris@0 2919 MainWindow::AddPaneCommand::~AddPaneCommand()
Chris@0 2920 {
Chris@0 2921 if (m_pane && !m_added) {
Chris@0 2922 m_mw->m_paneStack->deletePane(m_pane);
Chris@0 2923 }
Chris@0 2924 }
Chris@0 2925
Chris@0 2926 QString
Chris@0 2927 MainWindow::AddPaneCommand::getName() const
Chris@0 2928 {
Chris@0 2929 return tr("Add Pane");
Chris@0 2930 }
Chris@0 2931
Chris@0 2932 void
Chris@0 2933 MainWindow::AddPaneCommand::execute()
Chris@0 2934 {
Chris@0 2935 if (!m_pane) {
Chris@0 2936 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@0 2937 m_pane = m_mw->m_paneStack->addPane();
Chris@0 2938 } else {
Chris@0 2939 m_mw->m_paneStack->showPane(m_pane);
Chris@0 2940 }
Chris@0 2941
Chris@0 2942 m_mw->m_paneStack->setCurrentPane(m_pane);
Chris@65 2943 m_mw->m_overview->registerView(m_pane);
Chris@0 2944 m_added = true;
Chris@0 2945 }
Chris@0 2946
Chris@0 2947 void
Chris@0 2948 MainWindow::AddPaneCommand::unexecute()
Chris@0 2949 {
Chris@0 2950 m_mw->m_paneStack->hidePane(m_pane);
Chris@0 2951 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@65 2952 m_mw->m_overview->unregisterView(m_pane);
Chris@0 2953 m_added = false;
Chris@0 2954 }
Chris@0 2955
Chris@0 2956 MainWindow::RemovePaneCommand::RemovePaneCommand(MainWindow *mw, Pane *pane) :
Chris@0 2957 m_mw(mw),
Chris@0 2958 m_pane(pane),
Chris@0 2959 m_added(true)
Chris@0 2960 {
Chris@0 2961 }
Chris@0 2962
Chris@0 2963 MainWindow::RemovePaneCommand::~RemovePaneCommand()
Chris@0 2964 {
Chris@0 2965 if (m_pane && !m_added) {
Chris@0 2966 m_mw->m_paneStack->deletePane(m_pane);
Chris@0 2967 }
Chris@0 2968 }
Chris@0 2969
Chris@0 2970 QString
Chris@0 2971 MainWindow::RemovePaneCommand::getName() const
Chris@0 2972 {
Chris@0 2973 return tr("Remove Pane");
Chris@0 2974 }
Chris@0 2975
Chris@0 2976 void
Chris@0 2977 MainWindow::RemovePaneCommand::execute()
Chris@0 2978 {
Chris@0 2979 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@0 2980 m_mw->m_paneStack->hidePane(m_pane);
Chris@65 2981 m_mw->m_overview->unregisterView(m_pane);
Chris@0 2982 m_added = false;
Chris@0 2983 }
Chris@0 2984
Chris@0 2985 void
Chris@0 2986 MainWindow::RemovePaneCommand::unexecute()
Chris@0 2987 {
Chris@0 2988 m_mw->m_paneStack->showPane(m_pane);
Chris@0 2989 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@65 2990 m_mw->m_overview->registerView(m_pane);
Chris@0 2991 m_added = true;
Chris@0 2992 }
Chris@0 2993
Chris@0 2994 void
Chris@0 2995 MainWindow::addLayer()
Chris@0 2996 {
Chris@0 2997 QObject *s = sender();
Chris@0 2998 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 2999
Chris@0 3000 if (!action) {
Chris@0 3001 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
Chris@0 3002 << std::endl;
Chris@0 3003 return;
Chris@0 3004 }
Chris@0 3005
Chris@0 3006 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3007
Chris@0 3008 if (!pane) {
Chris@0 3009 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@0 3010 return;
Chris@0 3011 }
Chris@0 3012
Chris@0 3013 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
Chris@0 3014
Chris@0 3015 if (ei != m_existingLayerActions.end()) {
Chris@0 3016 Layer *newLayer = ei->second;
Chris@0 3017 m_document->addLayerToView(pane, newLayer);
Chris@0 3018 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3019 return;
Chris@0 3020 }
Chris@0 3021
Chris@34 3022 TransformActionMap::iterator i = m_transformActions.find(action);
Chris@34 3023
Chris@34 3024 if (i == m_transformActions.end()) {
Chris@0 3025
Chris@0 3026 LayerActionMap::iterator i = m_layerActions.find(action);
Chris@0 3027
Chris@0 3028 if (i == m_layerActions.end()) {
Chris@0 3029 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
Chris@0 3030 << action->objectName().toStdString() << std::endl;
Chris@0 3031 return;
Chris@0 3032 }
Chris@0 3033
Chris@0 3034 LayerFactory::LayerType type = i->second;
Chris@0 3035
Chris@0 3036 LayerFactory::LayerTypeSet emptyTypes =
Chris@0 3037 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 3038
Chris@0 3039 Layer *newLayer;
Chris@0 3040
Chris@0 3041 if (emptyTypes.find(type) != emptyTypes.end()) {
Chris@0 3042
Chris@0 3043 newLayer = m_document->createEmptyLayer(type);
Chris@0 3044 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@0 3045
Chris@0 3046 } else {
Chris@0 3047
Chris@0 3048 newLayer = m_document->createMainModelLayer(type);
Chris@0 3049 }
Chris@0 3050
Chris@0 3051 m_document->addLayerToView(pane, newLayer);
Chris@0 3052 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3053
Chris@0 3054 return;
Chris@0 3055 }
Chris@0 3056
Chris@0 3057 TransformName transform = i->second;
Chris@0 3058 TransformFactory *factory = TransformFactory::getInstance();
Chris@0 3059
Chris@0 3060 QString configurationXml;
Chris@0 3061
Chris@0 3062 int channel = -1;
Chris@0 3063 // pick up the default channel from any existing layers on the same pane
Chris@0 3064 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3065 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
Chris@0 3066 if (c != -1) {
Chris@0 3067 channel = c;
Chris@0 3068 break;
Chris@0 3069 }
Chris@0 3070 }
Chris@0 3071
Chris@33 3072 // We always ask for configuration, even if the plugin isn't
Chris@33 3073 // supposed to be configurable, because we need to let the user
Chris@33 3074 // change the execution context (block size etc).
Chris@0 3075
Chris@27 3076 PluginTransform::ExecutionContext context(channel);
Chris@27 3077
Chris@66 3078 std::vector<Model *> candidateInputModels =
Chris@66 3079 m_document->getTransformInputModels();
Chris@53 3080
Chris@54 3081 Model *inputModel = factory->getConfigurationForTransform(transform,
Chris@54 3082 candidateInputModels,
Chris@54 3083 context,
Chris@54 3084 configurationXml,
Chris@54 3085 m_playSource);
Chris@54 3086 if (!inputModel) return;
Chris@54 3087
Chris@54 3088 std::cerr << "Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << std::endl;
Chris@0 3089
Chris@0 3090 Layer *newLayer = m_document->createDerivedLayer(transform,
Chris@54 3091 inputModel,
Chris@27 3092 context,
Chris@0 3093 configurationXml);
Chris@0 3094
Chris@0 3095 if (newLayer) {
Chris@0 3096 m_document->addLayerToView(pane, newLayer);
Chris@27 3097 m_document->setChannel(newLayer, context.channel);
Chris@34 3098 m_recentTransforms.add(transform);
Chris@0 3099 }
Chris@0 3100
Chris@0 3101 updateMenuStates();
Chris@0 3102 }
Chris@0 3103
Chris@0 3104 void
Chris@0 3105 MainWindow::deleteCurrentPane()
Chris@0 3106 {
Chris@0 3107 CommandHistory::getInstance()->startCompoundOperation
Chris@0 3108 (tr("Delete Pane"), true);
Chris@0 3109
Chris@0 3110 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3111 if (pane) {
Chris@0 3112 while (pane->getLayerCount() > 0) {
Chris@0 3113 Layer *layer = pane->getLayer(0);
Chris@0 3114 if (layer) {
Chris@0 3115 m_document->removeLayerFromView(pane, layer);
Chris@0 3116 } else {
Chris@0 3117 break;
Chris@0 3118 }
Chris@0 3119 }
Chris@0 3120
Chris@0 3121 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
Chris@0 3122 CommandHistory::getInstance()->addCommand(command);
Chris@0 3123 }
Chris@0 3124
Chris@0 3125 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 3126
Chris@0 3127 updateMenuStates();
Chris@0 3128 }
Chris@0 3129
Chris@0 3130 void
Chris@0 3131 MainWindow::deleteCurrentLayer()
Chris@0 3132 {
Chris@0 3133 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3134 if (pane) {
Chris@0 3135 Layer *layer = pane->getSelectedLayer();
Chris@0 3136 if (layer) {
Chris@0 3137 m_document->removeLayerFromView(pane, layer);
Chris@0 3138 }
Chris@0 3139 }
Chris@0 3140 updateMenuStates();
Chris@0 3141 }
Chris@0 3142
Chris@0 3143 void
Chris@0 3144 MainWindow::renameCurrentLayer()
Chris@0 3145 {
Chris@0 3146 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3147 if (pane) {
Chris@0 3148 Layer *layer = pane->getSelectedLayer();
Chris@0 3149 if (layer) {
Chris@0 3150 bool ok = false;
Chris@0 3151 QString newName = QInputDialog::getText
Chris@0 3152 (this, tr("Rename Layer"),
Chris@0 3153 tr("New name for this layer:"),
Chris@0 3154 QLineEdit::Normal, layer->objectName(), &ok);
Chris@0 3155 if (ok) {
Chris@0 3156 layer->setObjectName(newName);
Chris@0 3157 setupExistingLayersMenu();
Chris@0 3158 }
Chris@0 3159 }
Chris@0 3160 }
Chris@0 3161 }
Chris@0 3162
Chris@0 3163 void
Chris@59 3164 MainWindow::playSpeedChanged(int position)
Chris@0 3165 {
Chris@59 3166 PlaySpeedRangeMapper mapper(0, 200);
Chris@60 3167
Chris@60 3168 float percent = m_playSpeed->mappedValue();
Chris@60 3169
Chris@60 3170 float factor = mapper.getFactorForValue(percent);
Chris@60 3171
Chris@60 3172 // float factor = mapper.getFactorForPosition(position);
Chris@60 3173 // float percent = mapper.getValueForPosition(position);
Chris@60 3174
Chris@60 3175 std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
Chris@60 3176
Chris@60 3177 //!!! bool slow = (position < 100);
Chris@59 3178 bool something = (position != 100);
Chris@60 3179 /*!!!
Chris@59 3180 int pc = lrintf(percent);
Chris@21 3181
Chris@21 3182 m_playSpeed->setToolTip(tr("Playback speed: %1%2%")
Chris@60 3183 .arg(!slow ? "+" : "")
Chris@21 3184 .arg(pc));
Chris@60 3185 */
Chris@25 3186 m_playSharpen->setEnabled(something);
Chris@26 3187 m_playMono->setEnabled(something);
Chris@25 3188 bool sharpen = (something && m_playSharpen->isChecked());
Chris@26 3189 bool mono = (something && m_playMono->isChecked());
Chris@26 3190 m_playSource->setTimeStretch(factor, sharpen, mono);
Chris@16 3191 }
Chris@16 3192
Chris@16 3193 void
Chris@16 3194 MainWindow::playSharpenToggled()
Chris@16 3195 {
Chris@21 3196 QSettings settings;
Chris@21 3197 settings.beginGroup("MainWindow");
Chris@21 3198 settings.setValue("playsharpen", m_playSharpen->isChecked());
Chris@21 3199 settings.endGroup();
Chris@21 3200
Chris@16 3201 playSpeedChanged(m_playSpeed->value());
Chris@0 3202 }
Chris@0 3203
Chris@0 3204 void
Chris@26 3205 MainWindow::playMonoToggled()
Chris@26 3206 {
Chris@26 3207 QSettings settings;
Chris@26 3208 settings.beginGroup("MainWindow");
Chris@26 3209 settings.setValue("playmono", m_playMono->isChecked());
Chris@26 3210 settings.endGroup();
Chris@26 3211
Chris@26 3212 playSpeedChanged(m_playSpeed->value());
Chris@26 3213 }
Chris@26 3214
Chris@26 3215 void
Chris@0 3216 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 3217 {
Chris@0 3218 m_fader->setPeakLeft(left);
Chris@0 3219 m_fader->setPeakRight(right);
Chris@0 3220 }
Chris@0 3221
Chris@0 3222 void
Chris@0 3223 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
Chris@0 3224 bool willResample)
Chris@0 3225 {
Chris@0 3226 if (!willResample) {
Chris@0 3227 //!!! more helpful message needed
Chris@0 3228 QMessageBox::information
Chris@0 3229 (this, tr("Sample rate mismatch"),
Chris@0 3230 tr("The sample rate of this audio file (%1 Hz) does not match\nthe current playback rate (%2 Hz).\n\nThe file will play at the wrong speed.")
Chris@0 3231 .arg(requested).arg(actual));
Chris@0 3232 }
Chris@0 3233
Chris@0 3234 /*!!! Let's not do this for now, and see how we go -- now that we're putting
Chris@0 3235 sample rate information in the status bar
Chris@0 3236
Chris@0 3237 QMessageBox::information
Chris@0 3238 (this, tr("Sample rate mismatch"),
Chris@0 3239 tr("The sample rate of this audio file (%1 Hz) does not match\nthat of the output audio device (%2 Hz).\n\nThe file will be resampled automatically during playback.")
Chris@0 3240 .arg(requested).arg(actual));
Chris@0 3241 */
Chris@0 3242
Chris@0 3243 updateDescriptionLabel();
Chris@0 3244 }
Chris@0 3245
Chris@0 3246 void
Chris@42 3247 MainWindow::audioOverloadPluginDisabled()
Chris@42 3248 {
Chris@42 3249 QMessageBox::information
Chris@42 3250 (this, tr("Audio processing overload"),
Chris@42 3251 tr("Audio effects plugin auditioning has been disabled\ndue to a processing overload."));
Chris@42 3252 }
Chris@42 3253
Chris@42 3254 void
Chris@0 3255 MainWindow::layerAdded(Layer *layer)
Chris@0 3256 {
Chris@0 3257 // std::cerr << "MainWindow::layerAdded(" << layer << ")" << std::endl;
Chris@0 3258 // setupExistingLayersMenu();
Chris@0 3259 updateMenuStates();
Chris@0 3260 }
Chris@0 3261
Chris@0 3262 void
Chris@0 3263 MainWindow::layerRemoved(Layer *layer)
Chris@0 3264 {
Chris@0 3265 // std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl;
Chris@0 3266 setupExistingLayersMenu();
Chris@0 3267 updateMenuStates();
Chris@0 3268 }
Chris@0 3269
Chris@0 3270 void
Chris@0 3271 MainWindow::layerAboutToBeDeleted(Layer *layer)
Chris@0 3272 {
Chris@0 3273 // std::cerr << "MainWindow::layerAboutToBeDeleted(" << layer << ")" << std::endl;
Chris@0 3274 if (layer == m_timeRulerLayer) {
Chris@0 3275 // std::cerr << "(this is the time ruler layer)" << std::endl;
Chris@0 3276 m_timeRulerLayer = 0;
Chris@0 3277 }
Chris@0 3278 }
Chris@0 3279
Chris@0 3280 void
Chris@0 3281 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 3282 {
Chris@0 3283 // std::cerr << "MainWindow::layerInAView(" << layer << "," << inAView << ")" << std::endl;
Chris@0 3284
Chris@0 3285 // Check whether we need to add or remove model from play source
Chris@0 3286 Model *model = layer->getModel();
Chris@0 3287 if (model) {
Chris@0 3288 if (inAView) {
Chris@0 3289 m_playSource->addModel(model);
Chris@0 3290 } else {
Chris@0 3291 bool found = false;
Chris@0 3292 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 3293 Pane *pane = m_paneStack->getPane(i);
Chris@0 3294 if (!pane) continue;
Chris@0 3295 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3296 Layer *pl = pane->getLayer(j);
Chris@0 3297 if (pl && pl->getModel() == model) {
Chris@0 3298 found = true;
Chris@0 3299 break;
Chris@0 3300 }
Chris@0 3301 }
Chris@0 3302 if (found) break;
Chris@0 3303 }
Chris@0 3304 if (!found) m_playSource->removeModel(model);
Chris@0 3305 }
Chris@0 3306 }
Chris@0 3307
Chris@0 3308 setupExistingLayersMenu();
Chris@0 3309 updateMenuStates();
Chris@0 3310 }
Chris@0 3311
Chris@0 3312 void
Chris@0 3313 MainWindow::modelAdded(Model *model)
Chris@0 3314 {
Chris@0 3315 // std::cerr << "MainWindow::modelAdded(" << model << ")" << std::endl;
Chris@0 3316 m_playSource->addModel(model);
Chris@66 3317 if (dynamic_cast<DenseTimeValueModel *>(model)) {
Chris@66 3318 setupPaneAndLayerMenus();
Chris@66 3319 }
Chris@0 3320 }
Chris@0 3321
Chris@0 3322 void
Chris@0 3323 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 3324 {
Chris@0 3325 // std::cerr << "MainWindow::mainModelChanged(" << model << ")" << std::endl;
Chris@0 3326 updateDescriptionLabel();
Chris@0 3327 m_panLayer->setModel(model);
Chris@0 3328 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
Chris@46 3329 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
Chris@0 3330 }
Chris@0 3331
Chris@0 3332 void
Chris@0 3333 MainWindow::modelAboutToBeDeleted(Model *model)
Chris@0 3334 {
Chris@0 3335 // std::cerr << "MainWindow::modelAboutToBeDeleted(" << model << ")" << std::endl;
Chris@0 3336 m_playSource->removeModel(model);
Chris@0 3337 }
Chris@0 3338
Chris@0 3339 void
Chris@0 3340 MainWindow::modelGenerationFailed(QString transformName)
Chris@0 3341 {
Chris@0 3342 QMessageBox::warning
Chris@0 3343 (this,
Chris@0 3344 tr("Failed to generate layer"),
Chris@34 3345 tr("Failed to generate a derived layer.\n\nThe layer transform \"%1\" failed.\n\nThis probably means that a plugin failed to initialise, perhaps because it\nrejected the processing block size that was requested.")
Chris@0 3346 .arg(transformName),
Chris@0 3347 QMessageBox::Ok, 0);
Chris@0 3348 }
Chris@0 3349
Chris@0 3350 void
Chris@0 3351 MainWindow::modelRegenerationFailed(QString layerName, QString transformName)
Chris@0 3352 {
Chris@0 3353 QMessageBox::warning
Chris@0 3354 (this,
Chris@0 3355 tr("Failed to regenerate layer"),
Chris@34 3356 tr("Failed to regenerate derived layer \"%1\".\n\nThe layer transform \"%2\" failed to run.\n\nThis probably means the layer used a plugin that is not currently available.")
Chris@0 3357 .arg(layerName).arg(transformName),
Chris@0 3358 QMessageBox::Ok, 0);
Chris@0 3359 }
Chris@0 3360
Chris@0 3361 void
Chris@0 3362 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 3363 {
Chris@0 3364 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
Chris@0 3365 m_paneStack->setCurrentPane(pane);
Chris@0 3366 m_rightButtonMenu->popup(position);
Chris@0 3367 }
Chris@0 3368
Chris@0 3369 void
Chris@0 3370 MainWindow::showLayerTree()
Chris@0 3371 {
Chris@0 3372 QTreeView *view = new QTreeView();
Chris@0 3373 LayerTreeModel *tree = new LayerTreeModel(m_paneStack);
Chris@0 3374 view->expand(tree->index(0, 0, QModelIndex()));
Chris@0 3375 view->setModel(tree);
Chris@0 3376 view->show();
Chris@0 3377 }
Chris@0 3378
Chris@0 3379 void
Chris@0 3380 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
Chris@0 3381 {
Chris@0 3382 if (name == "Property Box Layout") {
Chris@0 3383 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@0 3384 Preferences::VerticallyStacked) {
Chris@0 3385 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@0 3386 } else {
Chris@0 3387 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@0 3388 }
Chris@0 3389 }
Chris@0 3390 }
Chris@0 3391
Chris@0 3392 void
Chris@0 3393 MainWindow::preferences()
Chris@0 3394 {
Chris@0 3395 if (!m_preferencesDialog.isNull()) {
Chris@0 3396 m_preferencesDialog->show();
Chris@0 3397 m_preferencesDialog->raise();
Chris@0 3398 return;
Chris@0 3399 }
Chris@0 3400
Chris@0 3401 m_preferencesDialog = new PreferencesDialog(this);
Chris@0 3402
Chris@0 3403 // DeleteOnClose is safe here, because m_preferencesDialog is a
Chris@0 3404 // QPointer that will be zeroed when the dialog is deleted. We
Chris@0 3405 // use it in preference to leaving the dialog lying around because
Chris@0 3406 // if you Cancel the dialog, it resets the preferences state
Chris@0 3407 // without resetting its own widgets, so its state will be
Chris@0 3408 // incorrect when next shown unless we construct it afresh
Chris@0 3409 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@0 3410
Chris@0 3411 m_preferencesDialog->show();
Chris@0 3412 }
Chris@0 3413
Chris@0 3414 void
Chris@0 3415 MainWindow::website()
Chris@0 3416 {
Chris@0 3417 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
Chris@0 3418 }
Chris@0 3419
Chris@0 3420 void
Chris@0 3421 MainWindow::help()
Chris@0 3422 {
Chris@0 3423 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/en/"));
Chris@0 3424 }
Chris@0 3425
Chris@0 3426 void
Chris@0 3427 MainWindow::openHelpUrl(QString url)
Chris@0 3428 {
Chris@0 3429 // This method mostly lifted from Qt Assistant source code
Chris@0 3430
Chris@0 3431 QProcess *process = new QProcess(this);
Chris@0 3432 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
Chris@0 3433
Chris@0 3434 QStringList args;
Chris@0 3435
Chris@0 3436 #ifdef Q_OS_MAC
Chris@0 3437 args.append(url);
Chris@0 3438 process->start("open", args);
Chris@0 3439 #else
Chris@0 3440 #ifdef Q_OS_WIN32
Chris@0 3441
Chris@0 3442 QString pf(getenv("ProgramFiles"));
Chris@0 3443 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
Chris@0 3444
Chris@0 3445 args.append(url);
Chris@0 3446 process->start(command, args);
Chris@0 3447
Chris@0 3448 #else
Chris@0 3449 #ifdef Q_WS_X11
Chris@0 3450 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
Chris@0 3451 args.append("exec");
Chris@0 3452 args.append(url);
Chris@0 3453 process->start("kfmclient", args);
Chris@0 3454 } else if (!qgetenv("BROWSER").isEmpty()) {
Chris@0 3455 args.append(url);
Chris@0 3456 process->start(qgetenv("BROWSER"), args);
Chris@0 3457 } else {
Chris@0 3458 args.append(url);
Chris@0 3459 process->start("firefox", args);
Chris@0 3460 }
Chris@0 3461 #endif
Chris@0 3462 #endif
Chris@0 3463 #endif
Chris@0 3464 }
Chris@0 3465
Chris@0 3466 void
Chris@0 3467 MainWindow::about()
Chris@0 3468 {
Chris@0 3469 bool debug = false;
Chris@0 3470 QString version = "(unknown version)";
Chris@0 3471
Chris@0 3472 #ifdef BUILD_DEBUG
Chris@0 3473 debug = true;
Chris@0 3474 #endif
Chris@0 3475 #ifdef SV_VERSION
Chris@0 3476 #ifdef SVNREV
Chris@0 3477 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
Chris@0 3478 #else
Chris@0 3479 version = tr("Release %1").arg(SV_VERSION);
Chris@0 3480 #endif
Chris@0 3481 #else
Chris@0 3482 #ifdef SVNREV
Chris@0 3483 version = tr("Unreleased : Revision %1").arg(SVNREV);
Chris@0 3484 #endif
Chris@0 3485 #endif
Chris@0 3486
Chris@0 3487 QString aboutText;
Chris@0 3488
Chris@0 3489 aboutText += tr("<h3>About Sonic Visualiser</h3>");
Chris@0 3490 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for semantic music analysis and annotation.</p>");
Chris@0 3491 aboutText += tr("<p>%1 : %2 build</p>")
Chris@0 3492 .arg(version)
Chris@0 3493 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 3494
Chris@0 3495 #ifdef BUILD_STATIC
Chris@0 3496 aboutText += tr("<p>Statically linked");
Chris@0 3497 #ifndef QT_SHARED
Chris@0 3498 aboutText += tr("<br>With Qt (v%1) &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@0 3499 #endif
Chris@0 3500 #ifdef HAVE_JACK
Chris@0 3501 aboutText += tr("<br>With JACK audio output (v%1) &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@0 3502 #endif
Chris@0 3503 #ifdef HAVE_PORTAUDIO
Chris@0 3504 aboutText += tr("<br>With PortAudio audio output &copy; Ross Bencina and Phil Burk");
Chris@0 3505 #endif
Chris@0 3506 #ifdef HAVE_OGGZ
Chris@0 3507 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@0 3508 #endif
Chris@0 3509 #ifdef HAVE_MAD
Chris@0 3510 aboutText += tr("<br>With MAD mp3 decoder (v%1) &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@0 3511 #endif
Chris@0 3512 #ifdef HAVE_SAMPLERATE
Chris@0 3513 aboutText += tr("<br>With libsamplerate (v%1) &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@0 3514 #endif
Chris@0 3515 #ifdef HAVE_SNDFILE
Chris@0 3516 aboutText += tr("<br>With libsndfile (v%1) &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@0 3517 #endif
Chris@0 3518 #ifdef HAVE_FFTW3
Chris@0 3519 aboutText += tr("<br>With FFTW3 (v%1) &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@0 3520 #endif
Chris@0 3521 #ifdef HAVE_VAMP
Chris@0 3522 aboutText += tr("<br>With Vamp plugin support (API v%1, SDK v%2) &copy; Chris Cannam").arg(VAMP_API_VERSION).arg(VAMP_SDK_VERSION);
Chris@0 3523 #endif
Chris@0 3524 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 3525 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@0 3526 aboutText += "</p>";
Chris@0 3527 #endif
Chris@0 3528
Chris@0 3529 aboutText +=
Chris@0 3530 "<p>Sonic Visualiser Copyright &copy; 2005 - 2006 Chris Cannam<br>"
Chris@0 3531 "Centre for Digital Music, Queen Mary, University of London.</p>"
Chris@0 3532 "<p>This program is free software; you can redistribute it and/or<br>"
Chris@0 3533 "modify it under the terms of the GNU General Public License as<br>"
Chris@0 3534 "published by the Free Software Foundation; either version 2 of the<br>"
Chris@0 3535 "License, or (at your option) any later version.<br>See the file "
Chris@0 3536 "COPYING included with this distribution for more information.</p>";
Chris@0 3537
Chris@0 3538 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
Chris@0 3539 }
Chris@0 3540
Chris@0 3541
Chris@0 3542 #ifdef INCLUDE_MOCFILES
Chris@0 3543 #include "MainWindow.moc.cpp"
Chris@0 3544 #endif