annotate main/MainWindow.cpp @ 209:55a4719c8e7d

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