annotate src/MainWindow.cpp @ 61:85ac2e8e3872 r0.1_win32_testbuild

Subrepo state
author Chris Cannam <chris.cannam@eecs.qmul.ac.uk>
date Wed, 17 Jul 2013 16:31:03 +0100
parents 8b7383948381
children 5310637392f6
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 Tony
Chris@0 5 An intonation analysis and annotation tool
Chris@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7 This file copyright 2006-2012 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@0 16 #include "../version.h"
Chris@0 17
Chris@0 18 #include "MainWindow.h"
Chris@6 19 #include "Analyser.h"
Chris@6 20
Chris@0 21 #include "framework/Document.h"
Chris@0 22
Chris@0 23 #include "view/Pane.h"
Chris@0 24 #include "view/PaneStack.h"
Chris@0 25 #include "data/model/WaveFileModel.h"
matthiasm@26 26 #include "data/model/NoteModel.h"
matthiasm@26 27 #include "data/model/FlexiNoteModel.h"
matthiasm@42 28 #include "layer/FlexiNoteLayer.h"
matthiasm@26 29 #include "data/model/NoteModel.h"
Chris@0 30 #include "view/ViewManager.h"
Chris@0 31 #include "base/Preferences.h"
Chris@0 32 #include "layer/WaveformLayer.h"
Chris@0 33 #include "layer/TimeInstantLayer.h"
Chris@0 34 #include "layer/TimeValueLayer.h"
Chris@0 35 #include "widgets/Fader.h"
Chris@0 36 #include "view/Overview.h"
Chris@0 37 #include "widgets/AudioDial.h"
Chris@0 38 #include "widgets/IconLoader.h"
Chris@0 39 #include "widgets/KeyReference.h"
Chris@0 40 #include "audioio/AudioCallbackPlaySource.h"
Chris@0 41 #include "audioio/AudioCallbackPlayTarget.h"
Chris@0 42 #include "audioio/PlaySpeedRangeMapper.h"
Chris@0 43 #include "base/Profiler.h"
Chris@0 44 #include "base/UnitDatabase.h"
Chris@0 45 #include "layer/ColourDatabase.h"
Chris@0 46
matthiasm@26 47 #include "data/fileio/CSVFileWriter.h"
matthiasm@26 48 #include "data/fileio/MIDIFileWriter.h"
matthiasm@26 49 #include "rdf/RDFExporter.h"
matthiasm@26 50
Chris@0 51 // For version information
Chris@0 52 #include "vamp/vamp.h"
Chris@0 53 #include "vamp-sdk/PluginBase.h"
Chris@0 54 #include "plugin/api/ladspa.h"
Chris@0 55 #include "plugin/api/dssi.h"
Chris@0 56
Chris@0 57 #include <QApplication>
Chris@0 58 #include <QMessageBox>
Chris@0 59 #include <QGridLayout>
Chris@0 60 #include <QLabel>
Chris@0 61 #include <QMenuBar>
Chris@0 62 #include <QToolBar>
Chris@0 63 #include <QToolButton>
Chris@0 64 #include <QInputDialog>
Chris@0 65 #include <QStatusBar>
Chris@0 66 #include <QFileInfo>
Chris@0 67 #include <QDir>
Chris@0 68 #include <QProcess>
Chris@2 69 #include <QPushButton>
Chris@0 70 #include <QSettings>
Chris@0 71 #include <QScrollArea>
Chris@0 72
Chris@0 73 #include <iostream>
Chris@0 74 #include <cstdio>
Chris@0 75 #include <errno.h>
Chris@0 76
Chris@0 77 using std::cerr;
Chris@0 78 using std::endl;
Chris@0 79
Chris@0 80 using std::vector;
Chris@0 81
Chris@0 82
Chris@0 83 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) :
Chris@0 84 MainWindowBase(withAudioOutput, withOSCSupport, false),
Chris@0 85 m_overview(0),
Chris@0 86 m_mainMenusCreated(false),
gyorgyf@45 87 m_intelligentActionOn(true), //GF: !!! temporary
Chris@0 88 m_playbackMenu(0),
gyorgyf@45 89 m_recentFilesMenu(0),
Chris@0 90 m_rightButtonMenu(0),
Chris@0 91 m_rightButtonPlaybackMenu(0),
Chris@0 92 m_deleteSelectedAction(0),
Chris@0 93 m_ffwdAction(0),
Chris@0 94 m_rwdAction(0),
Chris@0 95 m_keyReference(new KeyReference())
Chris@0 96 {
Chris@0 97 setWindowTitle(QApplication::applicationName());
Chris@0 98
Chris@0 99 UnitDatabase *udb = UnitDatabase::getInstance();
Chris@0 100 udb->registerUnit("Hz");
Chris@0 101 udb->registerUnit("dB");
Chris@0 102 udb->registerUnit("s");
Chris@0 103
Chris@0 104 ColourDatabase *cdb = ColourDatabase::getInstance();
Chris@0 105 cdb->addColour(Qt::black, tr("Black"));
Chris@0 106 cdb->addColour(Qt::darkRed, tr("Red"));
Chris@0 107 cdb->addColour(Qt::darkBlue, tr("Blue"));
Chris@0 108 cdb->addColour(Qt::darkGreen, tr("Green"));
Chris@0 109 cdb->addColour(QColor(200, 50, 255), tr("Purple"));
Chris@0 110 cdb->addColour(QColor(255, 150, 50), tr("Orange"));
Chris@0 111 cdb->setUseDarkBackground(cdb->addColour(Qt::white, tr("White")), true);
Chris@0 112 cdb->setUseDarkBackground(cdb->addColour(Qt::red, tr("Bright Red")), true);
Chris@0 113 cdb->setUseDarkBackground(cdb->addColour(QColor(30, 150, 255), tr("Bright Blue")), true);
Chris@0 114 cdb->setUseDarkBackground(cdb->addColour(Qt::green, tr("Bright Green")), true);
Chris@0 115 cdb->setUseDarkBackground(cdb->addColour(QColor(225, 74, 255), tr("Bright Purple")), true);
Chris@0 116 cdb->setUseDarkBackground(cdb->addColour(QColor(255, 188, 80), tr("Bright Orange")), true);
Chris@0 117
Chris@0 118 Preferences::getInstance()->setResampleOnLoad(true);
Chris@0 119 Preferences::getInstance()->setSpectrogramSmoothing
Chris@0 120 (Preferences::SpectrogramInterpolated);
Chris@0 121
Chris@0 122 QSettings settings;
Chris@0 123
Chris@0 124 settings.beginGroup("MainWindow");
Chris@0 125 settings.setValue("showstatusbar", false);
Chris@0 126 settings.endGroup();
Chris@0 127
Chris@6 128 m_viewManager->setAlignMode(false);
Chris@6 129 m_viewManager->setPlaySoloMode(false);
Chris@0 130 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@0 131 m_viewManager->setZoomWheelsEnabled(false);
Chris@6 132 m_viewManager->setIlluminateLocalFeatures(true);
Chris@0 133 m_viewManager->setShowWorkTitle(true);
Chris@6 134 m_viewManager->setShowCentreLine(false);
Chris@6 135 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@0 136
Chris@0 137 QFrame *frame = new QFrame;
Chris@0 138 setCentralWidget(frame);
Chris@0 139
Chris@0 140 QGridLayout *layout = new QGridLayout;
Chris@0 141
Chris@0 142 QScrollArea *scroll = new QScrollArea(frame);
Chris@0 143 scroll->setWidgetResizable(true);
Chris@0 144 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Chris@0 145 scroll->setFrameShape(QFrame::NoFrame);
Chris@0 146
Chris@6 147 // We have a pane stack: it comes with the territory. However, we
Chris@6 148 // have a fixed and known number of panes in it (e.g. 1) -- it
Chris@6 149 // isn't variable
Chris@0 150 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
Chris@0 151 scroll->setWidget(m_paneStack);
Chris@6 152
Chris@0 153 m_overview = new Overview(frame);
Chris@0 154 m_overview->setViewManager(m_viewManager);
Chris@0 155 m_overview->setFixedHeight(40);
Chris@0 156 #ifndef _WIN32
Chris@0 157 // For some reason, the contents of the overview never appear if we
Chris@0 158 // make this setting on Windows. I have no inclination at the moment
Chris@0 159 // to track down the reason why.
Chris@0 160 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@0 161 #endif
Chris@0 162 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
Chris@0 163 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 164
Chris@0 165 m_panLayer = new WaveformLayer;
Chris@0 166 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
Chris@0 167 m_panLayer->setAggressiveCacheing(true);
Chris@0 168 m_overview->addLayer(m_panLayer);
Chris@0 169
Chris@0 170 if (m_viewManager->getGlobalDarkBackground()) {
Chris@0 171 m_panLayer->setBaseColour
Chris@0 172 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@0 173 } else {
Chris@0 174 m_panLayer->setBaseColour
matthiasm@13 175 (ColourDatabase::getInstance()->getColourIndex(tr("Blue")));
Chris@0 176 }
Chris@0 177
Chris@0 178 m_fader = new Fader(frame, false);
Chris@0 179 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@0 180 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@0 181
Chris@0 182 m_playSpeed = new AudioDial(frame);
Chris@0 183 m_playSpeed->setMinimum(0);
Chris@0 184 m_playSpeed->setMaximum(200);
Chris@0 185 m_playSpeed->setValue(100);
Chris@0 186 m_playSpeed->setFixedWidth(24);
Chris@0 187 m_playSpeed->setFixedHeight(24);
Chris@0 188 m_playSpeed->setNotchesVisible(true);
Chris@0 189 m_playSpeed->setPageStep(10);
Chris@0 190 m_playSpeed->setObjectName(tr("Playback Speedup"));
Chris@0 191 m_playSpeed->setDefaultValue(100);
Chris@0 192 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
Chris@0 193 m_playSpeed->setShowToolTip(true);
Chris@0 194 connect(m_playSpeed, SIGNAL(valueChanged(int)),
gyorgyf@27 195 this, SLOT(playSpeedChanged(int)));
Chris@0 196 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@0 197 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@0 198
Chris@0 199 layout->setSpacing(4);
Chris@6 200 layout->addWidget(m_overview, 0, 1);
Chris@6 201 layout->addWidget(scroll, 1, 1);
Chris@0 202
Chris@0 203 layout->setColumnStretch(1, 10);
Chris@0 204
Chris@0 205 frame->setLayout(layout);
Chris@0 206
gyorgyf@21 207 m_analyser = new Analyser();
gyorgyf@21 208
Chris@0 209 setupMenus();
Chris@0 210 setupToolbars();
Chris@0 211 setupHelpMenu();
Chris@0 212
Chris@0 213 statusBar();
Chris@0 214
gyorgyf@21 215 // m_analyser = new Analyser();
Chris@6 216
Chris@0 217 newSession();
Chris@0 218 }
Chris@0 219
Chris@0 220 MainWindow::~MainWindow()
Chris@0 221 {
Chris@6 222 delete m_analyser;
Chris@0 223 delete m_keyReference;
Chris@0 224 Profiles::getInstance()->dump();
Chris@0 225 }
Chris@0 226
Chris@0 227 void
Chris@0 228 MainWindow::setupMenus()
Chris@0 229 {
Chris@0 230 if (!m_mainMenusCreated) {
Chris@0 231 m_rightButtonMenu = new QMenu();
Chris@0 232 }
Chris@0 233
Chris@0 234 if (!m_mainMenusCreated) {
Chris@0 235 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
Chris@0 236 m_rightButtonMenu->addSeparator();
Chris@0 237 }
Chris@0 238
Chris@0 239 setupFileMenu();
Chris@0 240 setupEditMenu();
Chris@0 241 setupViewMenu();
Chris@0 242
Chris@0 243 m_mainMenusCreated = true;
Chris@0 244 }
Chris@0 245
Chris@0 246 void
Chris@0 247 MainWindow::setupFileMenu()
Chris@0 248 {
Chris@0 249 if (m_mainMenusCreated) return;
Chris@0 250
Chris@0 251 QMenu *menu = menuBar()->addMenu(tr("&File"));
Chris@0 252 menu->setTearOffEnabled(true);
Chris@0 253 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
Chris@0 254
Chris@0 255 m_keyReference->setCategory(tr("File and Session Management"));
Chris@0 256
Chris@0 257 IconLoader il;
Chris@1 258 QIcon icon;
Chris@1 259 QAction *action;
Chris@0 260
Chris@0 261 icon = il.load("fileopen");
Chris@0 262 icon.addPixmap(il.loadPixmap("fileopen-22"));
Chris@1 263 action = new QAction(icon, tr("&Open..."), this);
Chris@0 264 action->setShortcut(tr("Ctrl+O"));
Chris@1 265 action->setStatusTip(tr("Open a file"));
Chris@0 266 connect(action, SIGNAL(triggered()), this, SLOT(openFile()));
Chris@0 267 m_keyReference->registerShortcut(action);
Chris@0 268 menu->addAction(action);
Chris@0 269 toolbar->addAction(action);
Chris@0 270
Chris@1 271 action = new QAction(tr("Open Lo&cation..."), this);
Chris@0 272 action->setShortcut(tr("Ctrl+Shift+O"));
Chris@1 273 action->setStatusTip(tr("Open a file from a remote URL"));
Chris@0 274 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
Chris@0 275 m_keyReference->registerShortcut(action);
Chris@0 276 menu->addAction(action);
Chris@0 277
Chris@1 278 m_recentFilesMenu = menu->addMenu(tr("Open &Recent"));
Chris@0 279 m_recentFilesMenu->setTearOffEnabled(true);
Chris@0 280 setupRecentFilesMenu();
Chris@0 281 connect(&m_recentFiles, SIGNAL(recentChanged()),
Chris@0 282 this, SLOT(setupRecentFilesMenu()));
Chris@0 283
Chris@0 284 menu->addSeparator();
matthiasm@26 285 action = new QAction(tr("Export Annotation Layer..."), this);
matthiasm@26 286 action->setStatusTip(tr("Export layer data to a file"));
matthiasm@26 287 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
matthiasm@26 288 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
matthiasm@26 289 menu->addAction(action);
matthiasm@26 290
matthiasm@26 291 menu->addSeparator();
Chris@0 292 action = new QAction(il.load("exit"), tr("&Quit"), this);
Chris@0 293 action->setShortcut(tr("Ctrl+Q"));
Chris@0 294 action->setStatusTip(tr("Exit %1").arg(QApplication::applicationName()));
Chris@0 295 connect(action, SIGNAL(triggered()), this, SLOT(close()));
Chris@0 296 m_keyReference->registerShortcut(action);
Chris@0 297 menu->addAction(action);
Chris@0 298 }
Chris@0 299
Chris@0 300 void
Chris@0 301 MainWindow::setupEditMenu()
Chris@0 302 {
Chris@0 303 if (m_mainMenusCreated) return;
Chris@0 304
Chris@0 305 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
Chris@0 306 menu->setTearOffEnabled(true);
Chris@0 307 CommandHistory::getInstance()->registerMenu(menu);
Chris@0 308 }
Chris@0 309
Chris@0 310 void
Chris@0 311 MainWindow::setupViewMenu()
Chris@0 312 {
Chris@0 313 if (m_mainMenusCreated) return;
Chris@0 314
Chris@0 315 IconLoader il;
Chris@0 316
Chris@0 317 QAction *action = 0;
Chris@0 318
Chris@0 319 m_keyReference->setCategory(tr("Panning and Navigation"));
Chris@0 320
Chris@0 321 QMenu *menu = menuBar()->addMenu(tr("&View"));
Chris@0 322 menu->setTearOffEnabled(true);
Chris@0 323 action = new QAction(tr("Scroll &Left"), this);
Chris@0 324 action->setShortcut(tr("Left"));
Chris@0 325 action->setStatusTip(tr("Scroll the current pane to the left"));
Chris@0 326 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
Chris@0 327 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 328 m_keyReference->registerShortcut(action);
Chris@0 329 menu->addAction(action);
gyorgyf@27 330
Chris@0 331 action = new QAction(tr("Scroll &Right"), this);
Chris@0 332 action->setShortcut(tr("Right"));
Chris@0 333 action->setStatusTip(tr("Scroll the current pane to the right"));
Chris@0 334 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
Chris@0 335 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 336 m_keyReference->registerShortcut(action);
Chris@0 337 menu->addAction(action);
gyorgyf@27 338
Chris@0 339 action = new QAction(tr("&Jump Left"), this);
Chris@0 340 action->setShortcut(tr("Ctrl+Left"));
Chris@0 341 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
Chris@0 342 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
Chris@0 343 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 344 m_keyReference->registerShortcut(action);
Chris@0 345 menu->addAction(action);
gyorgyf@27 346
Chris@0 347 action = new QAction(tr("J&ump Right"), this);
Chris@0 348 action->setShortcut(tr("Ctrl+Right"));
Chris@0 349 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
Chris@0 350 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
Chris@0 351 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 352 m_keyReference->registerShortcut(action);
Chris@0 353 menu->addAction(action);
Chris@0 354
Chris@0 355 menu->addSeparator();
Chris@0 356
Chris@0 357 m_keyReference->setCategory(tr("Zoom"));
Chris@0 358
Chris@0 359 action = new QAction(il.load("zoom-in"),
Chris@0 360 tr("Zoom &In"), this);
Chris@0 361 action->setShortcut(tr("Up"));
Chris@0 362 action->setStatusTip(tr("Increase the zoom level"));
Chris@0 363 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
Chris@0 364 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 365 m_keyReference->registerShortcut(action);
Chris@0 366 menu->addAction(action);
gyorgyf@27 367
Chris@0 368 action = new QAction(il.load("zoom-out"),
Chris@0 369 tr("Zoom &Out"), this);
Chris@0 370 action->setShortcut(tr("Down"));
Chris@0 371 action->setStatusTip(tr("Decrease the zoom level"));
Chris@0 372 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
Chris@0 373 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 374 m_keyReference->registerShortcut(action);
Chris@0 375 menu->addAction(action);
gyorgyf@27 376
Chris@0 377 action = new QAction(tr("Restore &Default Zoom"), this);
Chris@0 378 action->setStatusTip(tr("Restore the zoom level to the default"));
Chris@0 379 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
Chris@0 380 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 381 menu->addAction(action);
Chris@0 382
Chris@0 383 action = new QAction(il.load("zoom-fit"),
Chris@0 384 tr("Zoom to &Fit"), this);
Chris@0 385 action->setShortcut(tr("F"));
Chris@0 386 action->setStatusTip(tr("Zoom to show the whole file"));
Chris@0 387 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
Chris@0 388 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 389 m_keyReference->registerShortcut(action);
Chris@0 390 menu->addAction(action);
Chris@0 391 }
Chris@0 392
Chris@0 393 void
Chris@0 394 MainWindow::setupHelpMenu()
Chris@0 395 {
Chris@0 396 QMenu *menu = menuBar()->addMenu(tr("&Help"));
Chris@0 397 menu->setTearOffEnabled(true);
Chris@0 398
Chris@0 399 m_keyReference->setCategory(tr("Help"));
Chris@0 400
Chris@0 401 IconLoader il;
Chris@0 402
Chris@1 403 QString name = QApplication::applicationName();
Chris@1 404
Chris@0 405 QAction *action = new QAction(il.load("help"),
Chris@0 406 tr("&Help Reference"), this);
Chris@0 407 action->setShortcut(tr("F1"));
Chris@1 408 action->setStatusTip(tr("Open the %1 reference manual").arg(name));
Chris@0 409 connect(action, SIGNAL(triggered()), this, SLOT(help()));
Chris@0 410 m_keyReference->registerShortcut(action);
Chris@0 411 menu->addAction(action);
Chris@0 412
Chris@0 413 action = new QAction(tr("&Key and Mouse Reference"), this);
Chris@0 414 action->setShortcut(tr("F2"));
Chris@1 415 action->setStatusTip(tr("Open a window showing the keystrokes you can use in %1").arg(name));
Chris@0 416 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
Chris@0 417 m_keyReference->registerShortcut(action);
Chris@0 418 menu->addAction(action);
Chris@0 419
Chris@1 420 action = new QAction(tr("%1 on the &Web").arg(name), this);
Chris@1 421 action->setStatusTip(tr("Open the %1 website").arg(name));
Chris@0 422 connect(action, SIGNAL(triggered()), this, SLOT(website()));
Chris@0 423 menu->addAction(action);
Chris@0 424
Chris@1 425 action = new QAction(tr("&About %1").arg(name), this);
Chris@1 426 action->setStatusTip(tr("Show information about %1").arg(name));
Chris@0 427 connect(action, SIGNAL(triggered()), this, SLOT(about()));
Chris@0 428 menu->addAction(action);
Chris@0 429 }
Chris@0 430
Chris@0 431 void
Chris@0 432 MainWindow::setupRecentFilesMenu()
Chris@0 433 {
Chris@0 434 m_recentFilesMenu->clear();
Chris@0 435 vector<QString> files = m_recentFiles.getRecent();
Chris@0 436 for (size_t i = 0; i < files.size(); ++i) {
Chris@50 437 QAction *action = new QAction(files[i], this);
Chris@50 438 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
Chris@0 439 if (i == 0) {
Chris@0 440 action->setShortcut(tr("Ctrl+R"));
Chris@0 441 m_keyReference->registerShortcut
Chris@0 442 (tr("Re-open"),
Chris@50 443 action->shortcut().toString(),
Chris@0 444 tr("Re-open the current or most recently opened file"));
Chris@0 445 }
Chris@50 446 m_recentFilesMenu->addAction(action);
Chris@0 447 }
Chris@0 448 }
Chris@0 449
Chris@0 450 void
Chris@0 451 MainWindow::setupToolbars()
Chris@0 452 {
Chris@0 453 m_keyReference->setCategory(tr("Playback and Transport Controls"));
Chris@0 454
Chris@0 455 IconLoader il;
Chris@0 456
Chris@0 457 QMenu *menu = m_playbackMenu = menuBar()->addMenu(tr("Play&back"));
Chris@0 458 menu->setTearOffEnabled(true);
Chris@0 459 m_rightButtonMenu->addSeparator();
Chris@0 460 m_rightButtonPlaybackMenu = m_rightButtonMenu->addMenu(tr("Playback"));
Chris@0 461
Chris@0 462 QToolBar *toolbar = addToolBar(tr("Playback Toolbar"));
Chris@0 463
Chris@0 464 QAction *rwdStartAction = toolbar->addAction(il.load("rewind-start"),
Chris@0 465 tr("Rewind to Start"));
Chris@0 466 rwdStartAction->setShortcut(tr("Home"));
Chris@0 467 rwdStartAction->setStatusTip(tr("Rewind to the start"));
Chris@0 468 connect(rwdStartAction, SIGNAL(triggered()), this, SLOT(rewindStart()));
Chris@0 469 connect(this, SIGNAL(canPlay(bool)), rwdStartAction, SLOT(setEnabled(bool)));
Chris@0 470
Chris@0 471 QAction *m_rwdAction = toolbar->addAction(il.load("rewind"),
Chris@0 472 tr("Rewind"));
Chris@0 473 m_rwdAction->setShortcut(tr("PgUp"));
Chris@0 474 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant or time ruler notch"));
Chris@0 475 connect(m_rwdAction, SIGNAL(triggered()), this, SLOT(rewind()));
Chris@0 476 connect(this, SIGNAL(canRewind(bool)), m_rwdAction, SLOT(setEnabled(bool)));
Chris@0 477
Chris@0 478 QAction *playAction = toolbar->addAction(il.load("playpause"),
Chris@0 479 tr("Play / Pause"));
Chris@0 480 playAction->setCheckable(true);
Chris@0 481 playAction->setShortcut(tr("Space"));
Chris@0 482 playAction->setStatusTip(tr("Start or stop playback from the current position"));
Chris@0 483 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 484 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
gyorgyf@27 485 playAction, SLOT(setChecked(bool)));
Chris@0 486 connect(this, SIGNAL(canPlay(bool)), playAction, SLOT(setEnabled(bool)));
Chris@0 487
Chris@0 488 m_ffwdAction = toolbar->addAction(il.load("ffwd"),
Chris@0 489 tr("Fast Forward"));
Chris@0 490 m_ffwdAction->setShortcut(tr("PgDown"));
Chris@0 491 m_ffwdAction->setStatusTip(tr("Fast-forward to the next time instant or time ruler notch"));
Chris@0 492 connect(m_ffwdAction, SIGNAL(triggered()), this, SLOT(ffwd()));
Chris@0 493 connect(this, SIGNAL(canFfwd(bool)), m_ffwdAction, SLOT(setEnabled(bool)));
Chris@0 494
Chris@0 495 QAction *ffwdEndAction = toolbar->addAction(il.load("ffwd-end"),
Chris@0 496 tr("Fast Forward to End"));
Chris@0 497 ffwdEndAction->setShortcut(tr("End"));
Chris@0 498 ffwdEndAction->setStatusTip(tr("Fast-forward to the end"));
Chris@0 499 connect(ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
Chris@0 500 connect(this, SIGNAL(canPlay(bool)), ffwdEndAction, SLOT(setEnabled(bool)));
Chris@6 501
Chris@0 502 toolbar = addToolBar(tr("Play Mode Toolbar"));
Chris@0 503
Chris@0 504 QAction *psAction = toolbar->addAction(il.load("playselection"),
Chris@0 505 tr("Constrain Playback to Selection"));
Chris@0 506 psAction->setCheckable(true);
Chris@0 507 psAction->setChecked(m_viewManager->getPlaySelectionMode());
Chris@0 508 psAction->setShortcut(tr("s"));
Chris@0 509 psAction->setStatusTip(tr("Constrain playback to the selected regions"));
Chris@0 510 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
Chris@0 511 psAction, SLOT(setChecked(bool)));
Chris@0 512 connect(psAction, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
Chris@0 513 connect(this, SIGNAL(canPlaySelection(bool)), psAction, SLOT(setEnabled(bool)));
Chris@0 514
Chris@0 515 QAction *plAction = toolbar->addAction(il.load("playloop"),
Chris@0 516 tr("Loop Playback"));
Chris@0 517 plAction->setCheckable(true);
Chris@0 518 plAction->setChecked(m_viewManager->getPlayLoopMode());
Chris@0 519 plAction->setShortcut(tr("l"));
Chris@0 520 plAction->setStatusTip(tr("Loop playback"));
Chris@0 521 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
Chris@0 522 plAction, SLOT(setChecked(bool)));
Chris@0 523 connect(plAction, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
Chris@0 524 connect(this, SIGNAL(canPlay(bool)), plAction, SLOT(setEnabled(bool)));
Chris@0 525
Chris@0 526 m_keyReference->registerShortcut(psAction);
Chris@0 527 m_keyReference->registerShortcut(plAction);
Chris@0 528 m_keyReference->registerShortcut(playAction);
Chris@0 529 m_keyReference->registerShortcut(m_rwdAction);
Chris@0 530 m_keyReference->registerShortcut(m_ffwdAction);
Chris@0 531 m_keyReference->registerShortcut(rwdStartAction);
Chris@0 532 m_keyReference->registerShortcut(ffwdEndAction);
Chris@0 533
Chris@6 534 menu->addAction(playAction);
Chris@0 535 menu->addAction(psAction);
Chris@0 536 menu->addAction(plAction);
Chris@0 537 menu->addSeparator();
Chris@0 538 menu->addAction(m_rwdAction);
Chris@0 539 menu->addAction(m_ffwdAction);
Chris@0 540 menu->addSeparator();
Chris@0 541 menu->addAction(rwdStartAction);
Chris@0 542 menu->addAction(ffwdEndAction);
Chris@0 543 menu->addSeparator();
Chris@0 544
Chris@0 545 m_rightButtonPlaybackMenu->addAction(playAction);
Chris@0 546 m_rightButtonPlaybackMenu->addAction(psAction);
Chris@0 547 m_rightButtonPlaybackMenu->addAction(plAction);
Chris@0 548 m_rightButtonPlaybackMenu->addSeparator();
Chris@0 549 m_rightButtonPlaybackMenu->addAction(m_rwdAction);
Chris@0 550 m_rightButtonPlaybackMenu->addAction(m_ffwdAction);
Chris@0 551 m_rightButtonPlaybackMenu->addSeparator();
Chris@0 552 m_rightButtonPlaybackMenu->addAction(rwdStartAction);
Chris@0 553 m_rightButtonPlaybackMenu->addAction(ffwdEndAction);
Chris@0 554 m_rightButtonPlaybackMenu->addSeparator();
Chris@0 555
Chris@0 556 QAction *fastAction = menu->addAction(tr("Speed Up"));
Chris@0 557 fastAction->setShortcut(tr("Ctrl+PgUp"));
Chris@0 558 fastAction->setStatusTip(tr("Time-stretch playback to speed it up without changing pitch"));
Chris@0 559 connect(fastAction, SIGNAL(triggered()), this, SLOT(speedUpPlayback()));
Chris@0 560 connect(this, SIGNAL(canSpeedUpPlayback(bool)), fastAction, SLOT(setEnabled(bool)));
Chris@0 561
Chris@0 562 QAction *slowAction = menu->addAction(tr("Slow Down"));
Chris@0 563 slowAction->setShortcut(tr("Ctrl+PgDown"));
Chris@0 564 slowAction->setStatusTip(tr("Time-stretch playback to slow it down without changing pitch"));
Chris@0 565 connect(slowAction, SIGNAL(triggered()), this, SLOT(slowDownPlayback()));
Chris@0 566 connect(this, SIGNAL(canSlowDownPlayback(bool)), slowAction, SLOT(setEnabled(bool)));
Chris@0 567
Chris@0 568 QAction *normalAction = menu->addAction(tr("Restore Normal Speed"));
Chris@0 569 normalAction->setShortcut(tr("Ctrl+Home"));
Chris@0 570 normalAction->setStatusTip(tr("Restore non-time-stretched playback"));
Chris@0 571 connect(normalAction, SIGNAL(triggered()), this, SLOT(restoreNormalPlayback()));
Chris@0 572 connect(this, SIGNAL(canChangePlaybackSpeed(bool)), normalAction, SLOT(setEnabled(bool)));
Chris@0 573
Chris@0 574 m_keyReference->registerShortcut(fastAction);
Chris@0 575 m_keyReference->registerShortcut(slowAction);
Chris@0 576 m_keyReference->registerShortcut(normalAction);
Chris@0 577
Chris@0 578 m_rightButtonPlaybackMenu->addAction(fastAction);
Chris@0 579 m_rightButtonPlaybackMenu->addAction(slowAction);
Chris@0 580 m_rightButtonPlaybackMenu->addAction(normalAction);
Chris@6 581
Chris@6 582 toolbar = addToolBar(tr("Playback Controls"));
Chris@6 583 toolbar->addWidget(m_playSpeed);
Chris@6 584 toolbar->addWidget(m_fader);
Chris@0 585
gyorgyf@27 586 toolbar = addToolBar(tr("Test actions toolbar")); // GF: temporary toolbar for triggering actions manually
gyorgyf@27 587
gyorgyf@27 588 // GF: TEMP : this created a menu item
gyorgyf@24 589 m_editSelectAction = toolbar->addAction(il.load("move"), tr("Edit"));
gyorgyf@24 590 m_editSelectAction->setShortcut(tr("Home"));
gyorgyf@24 591 m_editSelectAction->setStatusTip(tr("Edit Notes"));
gyorgyf@27 592 m_editSelectAction->setEnabled(true);
gyorgyf@21 593 // connect(test, SIGNAL(triggered()), this, SLOT(about()));
gyorgyf@21 594 // connect(test, SIGNAL(triggered()), m_analyser, SLOT(resizeLayer()));
gyorgyf@27 595 connect(m_editSelectAction, SIGNAL(triggered()), this, SLOT(selectNoteEditMode()));
gyorgyf@21 596 // connect(this, SIGNAL(canPlay(bool)), test, SLOT(setEnabled(bool)));
gyorgyf@27 597 menu->addAction(m_editSelectAction);
gyorgyf@45 598
gyorgyf@45 599 m_toggleIntelligenceAction = toolbar->addAction(il.load("notes"), tr("EditMode"));
gyorgyf@45 600 // m_toggleIntelligenceAction->setShortcut(tr("Home"));
gyorgyf@45 601 m_toggleIntelligenceAction->setStatusTip(tr("Toggle note edit boundary constraints and automation"));
gyorgyf@45 602 m_toggleIntelligenceAction->setEnabled(true);
gyorgyf@45 603 connect(m_toggleIntelligenceAction, SIGNAL(triggered()), this, SLOT(toggleNoteEditIntelligence()));
gyorgyf@21 604
Chris@0 605 Pane::registerShortcuts(*m_keyReference);
Chris@0 606 }
Chris@0 607
Chris@0 608 void
gyorgyf@27 609 MainWindow::selectNoteEditMode()
gyorgyf@21 610 {
gyorgyf@27 611 IconLoader il;
gyorgyf@27 612 if (m_viewManager->getToolMode() == ViewManager::NoteEditMode) {
gyorgyf@27 613 m_viewManager->setToolMode(ViewManager::NavigateMode);
gyorgyf@27 614 m_editSelectAction->setIcon(il.load("move"));
gyorgyf@27 615 } else {
gyorgyf@27 616 std::cerr << "NoteEdit mode selected" << std::endl;
gyorgyf@27 617 m_viewManager->setToolMode(ViewManager::NoteEditMode);
gyorgyf@27 618 m_editSelectAction->setIcon(il.load("navigate"));
gyorgyf@45 619 }
gyorgyf@45 620 }
gyorgyf@45 621
gyorgyf@45 622 void
gyorgyf@45 623 MainWindow::toggleNoteEditIntelligence()
gyorgyf@45 624 {
gyorgyf@45 625 IconLoader il;
gyorgyf@45 626 if (m_intelligentActionOn == true) {
gyorgyf@45 627 m_toggleIntelligenceAction->setIcon(il.load("values"));
gyorgyf@45 628 m_intelligentActionOn = false;
gyorgyf@45 629 m_analyser->setIntelligentActions(false);
gyorgyf@45 630 } else {
gyorgyf@45 631 m_toggleIntelligenceAction->setIcon(il.load("notes"));
gyorgyf@45 632 m_intelligentActionOn = true;
gyorgyf@45 633 m_analyser->setIntelligentActions(true);
gyorgyf@27 634 }
gyorgyf@21 635 }
gyorgyf@21 636
gyorgyf@21 637 void
Chris@0 638 MainWindow::updateMenuStates()
Chris@0 639 {
Chris@0 640 MainWindowBase::updateMenuStates();
Chris@0 641
Chris@0 642 Pane *currentPane = 0;
Chris@0 643 Layer *currentLayer = 0;
Chris@0 644
Chris@0 645 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@0 646 if (currentPane) currentLayer = currentPane->getSelectedLayer();
Chris@0 647
Chris@0 648 bool haveCurrentPane =
Chris@0 649 (currentPane != 0);
Chris@0 650 bool haveCurrentLayer =
Chris@0 651 (haveCurrentPane &&
Chris@0 652 (currentLayer != 0));
Chris@0 653 bool haveSelection =
gyorgyf@27 654 (m_viewManager &&
gyorgyf@27 655 !m_viewManager->getSelections().empty());
Chris@0 656 bool haveCurrentEditableLayer =
gyorgyf@27 657 (haveCurrentLayer &&
gyorgyf@27 658 currentLayer->isLayerEditable());
Chris@0 659 bool haveCurrentTimeInstantsLayer =
gyorgyf@27 660 (haveCurrentLayer &&
gyorgyf@27 661 qobject_cast<TimeInstantLayer *>(currentLayer));
Chris@0 662 bool haveCurrentTimeValueLayer =
gyorgyf@27 663 (haveCurrentLayer &&
gyorgyf@27 664 qobject_cast<TimeValueLayer *>(currentLayer));
Chris@0 665
Chris@0 666 emit canChangePlaybackSpeed(true);
Chris@0 667 int v = m_playSpeed->value();
Chris@0 668 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
Chris@0 669 emit canSlowDownPlayback(v > m_playSpeed->minimum());
Chris@0 670
Chris@0 671 if (m_ffwdAction && m_rwdAction) {
Chris@0 672 if (haveCurrentTimeInstantsLayer) {
Chris@0 673 m_ffwdAction->setText(tr("Fast Forward to Next Instant"));
Chris@0 674 m_ffwdAction->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
Chris@0 675 m_rwdAction->setText(tr("Rewind to Previous Instant"));
Chris@0 676 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
Chris@0 677 } else if (haveCurrentTimeValueLayer) {
Chris@0 678 m_ffwdAction->setText(tr("Fast Forward to Next Point"));
Chris@0 679 m_ffwdAction->setStatusTip(tr("Fast forward to the next point in the current layer"));
Chris@0 680 m_rwdAction->setText(tr("Rewind to Previous Point"));
Chris@0 681 m_rwdAction->setStatusTip(tr("Rewind to the previous point in the current layer"));
Chris@0 682 } else {
Chris@0 683 m_ffwdAction->setText(tr("Fast Forward"));
Chris@0 684 m_ffwdAction->setStatusTip(tr("Fast forward"));
Chris@0 685 m_rwdAction->setText(tr("Rewind"));
Chris@0 686 m_rwdAction->setStatusTip(tr("Rewind"));
Chris@0 687 }
Chris@0 688 }
Chris@0 689 }
Chris@0 690
Chris@0 691 void
Chris@0 692 MainWindow::updateDescriptionLabel()
Chris@0 693 {
Chris@6 694 // Nothing, we don't have one
Chris@0 695 }
Chris@0 696
Chris@0 697 void
Chris@0 698 MainWindow::documentModified()
Chris@0 699 {
Chris@0 700 MainWindowBase::documentModified();
Chris@0 701 }
Chris@0 702
Chris@0 703 void
Chris@0 704 MainWindow::documentRestored()
Chris@0 705 {
Chris@0 706 MainWindowBase::documentRestored();
Chris@0 707 }
Chris@0 708
Chris@0 709 void
Chris@0 710 MainWindow::newSession()
Chris@0 711 {
Chris@0 712 if (!checkSaveModified()) return;
Chris@0 713
Chris@0 714 closeSession();
Chris@0 715 createDocument();
Chris@0 716 m_document->setAutoAlignment(true);
Chris@0 717
Chris@0 718 Pane *pane = m_paneStack->addPane();
Chris@0 719
Chris@0 720 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@0 721 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 722
Chris@6 723 // Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@6 724 // m_document->addLayerToView(pane, waveform);
Chris@0 725
Chris@0 726 m_overview->registerView(pane);
Chris@0 727
Chris@0 728 CommandHistory::getInstance()->clear();
Chris@0 729 CommandHistory::getInstance()->documentSaved();
Chris@0 730 documentRestored();
Chris@0 731 updateMenuStates();
Chris@0 732 }
Chris@0 733
Chris@0 734 void
Chris@0 735 MainWindow::closeSession()
Chris@0 736 {
Chris@0 737 if (!checkSaveModified()) return;
Chris@0 738
Chris@0 739 while (m_paneStack->getPaneCount() > 0) {
Chris@0 740
gyorgyf@27 741 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@0 742
gyorgyf@27 743 while (pane->getLayerCount() > 0) {
gyorgyf@27 744 m_document->removeLayerFromView
gyorgyf@27 745 (pane, pane->getLayer(pane->getLayerCount() - 1));
gyorgyf@27 746 }
Chris@0 747
gyorgyf@27 748 m_overview->unregisterView(pane);
gyorgyf@27 749 m_paneStack->deletePane(pane);
Chris@0 750 }
Chris@0 751
Chris@0 752 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 753
gyorgyf@27 754 Pane *pane = m_paneStack->getHiddenPane
gyorgyf@27 755 (m_paneStack->getHiddenPaneCount() - 1);
Chris@0 756
gyorgyf@27 757 while (pane->getLayerCount() > 0) {
gyorgyf@27 758 m_document->removeLayerFromView
gyorgyf@27 759 (pane, pane->getLayer(pane->getLayerCount() - 1));
gyorgyf@27 760 }
Chris@0 761
gyorgyf@27 762 m_overview->unregisterView(pane);
gyorgyf@27 763 m_paneStack->deletePane(pane);
Chris@0 764 }
Chris@0 765
Chris@0 766 delete m_document;
Chris@0 767 m_document = 0;
Chris@0 768 m_viewManager->clearSelections();
Chris@0 769 m_timeRulerLayer = 0; // document owned this
Chris@0 770
Chris@0 771 m_sessionFile = "";
Chris@0 772
Chris@0 773 CommandHistory::getInstance()->clear();
Chris@0 774 CommandHistory::getInstance()->documentSaved();
Chris@0 775 documentRestored();
Chris@0 776 }
Chris@0 777
Chris@0 778 void
Chris@0 779 MainWindow::openFile()
Chris@0 780 {
Chris@0 781 QString orig = m_audioFile;
Chris@0 782 if (orig == "") orig = ".";
Chris@0 783 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 784
Chris@0 785 QString path = getOpenFileName(FileFinder::AnyFile);
Chris@0 786
Chris@0 787 if (path.isEmpty()) return;
Chris@0 788
Chris@1 789 FileOpenStatus status = open(path, ReplaceSession);
Chris@0 790
Chris@0 791 if (status == FileOpenFailed) {
Chris@0 792 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 793 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path));
Chris@0 794 } else if (status == FileOpenWrongMode) {
Chris@0 795 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 796 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 797 } else {
Chris@0 798 configureNewPane(m_paneStack->getCurrentPane());
Chris@0 799 }
Chris@0 800 }
Chris@0 801
Chris@0 802 void
Chris@0 803 MainWindow::openLocation()
Chris@0 804 {
Chris@0 805 QSettings settings;
Chris@0 806 settings.beginGroup("MainWindow");
Chris@0 807 QString lastLocation = settings.value("lastremote", "").toString();
Chris@0 808
Chris@0 809 bool ok = false;
Chris@0 810 QString text = QInputDialog::getText
Chris@0 811 (this, tr("Open Location"),
Chris@0 812 tr("Please enter the URL of the location to open:"),
Chris@0 813 QLineEdit::Normal, lastLocation, &ok);
Chris@0 814
Chris@0 815 if (!ok) return;
Chris@0 816
Chris@0 817 settings.setValue("lastremote", text);
Chris@0 818
Chris@0 819 if (text.isEmpty()) return;
Chris@0 820
Chris@1 821 FileOpenStatus status = open(text, ReplaceSession);
Chris@0 822
Chris@0 823 if (status == FileOpenFailed) {
Chris@0 824 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 825 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text));
Chris@0 826 } else if (status == FileOpenWrongMode) {
Chris@0 827 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 828 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 829 } else {
Chris@0 830 configureNewPane(m_paneStack->getCurrentPane());
Chris@0 831 }
Chris@0 832 }
Chris@0 833
Chris@0 834 void
Chris@0 835 MainWindow::openRecentFile()
Chris@0 836 {
Chris@0 837 QObject *obj = sender();
Chris@3 838 QAction *action = qobject_cast<QAction *>(obj);
Chris@0 839
Chris@0 840 if (!action) {
gyorgyf@27 841 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
gyorgyf@27 842 << std::endl;
gyorgyf@27 843 return;
Chris@0 844 }
Chris@0 845
Chris@0 846 QString path = action->text();
Chris@0 847 if (path == "") return;
Chris@0 848
Chris@1 849 FileOpenStatus status = open(path, ReplaceSession);
Chris@0 850
Chris@0 851 if (status == FileOpenFailed) {
Chris@0 852 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 853 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path));
Chris@0 854 } else if (status == FileOpenWrongMode) {
Chris@0 855 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 856 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 857 } else {
Chris@0 858 configureNewPane(m_paneStack->getCurrentPane());
Chris@0 859 }
Chris@0 860 }
Chris@0 861
Chris@0 862 void
Chris@0 863 MainWindow::paneAdded(Pane *pane)
Chris@0 864 {
Chris@6 865 pane->setPlaybackFollow(PlaybackScrollPage);
Chris@0 866 m_paneStack->sizePanesEqually();
Chris@0 867 if (m_overview) m_overview->registerView(pane);
Chris@0 868 }
Chris@0 869
Chris@0 870 void
Chris@0 871 MainWindow::paneHidden(Pane *pane)
Chris@0 872 {
Chris@0 873 if (m_overview) m_overview->unregisterView(pane);
Chris@0 874 }
Chris@0 875
Chris@0 876 void
Chris@0 877 MainWindow::paneAboutToBeDeleted(Pane *pane)
Chris@0 878 {
Chris@0 879 if (m_overview) m_overview->unregisterView(pane);
Chris@0 880 }
Chris@0 881
Chris@0 882 void
Chris@0 883 MainWindow::paneDropAccepted(Pane *pane, QStringList uriList)
Chris@0 884 {
Chris@4 885 if (pane) m_paneStack->setCurrentPane(pane);
Chris@0 886
Chris@0 887 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) {
Chris@0 888
Chris@1 889 FileOpenStatus status = open(*i, ReplaceSession);
Chris@0 890
Chris@0 891 if (status == FileOpenFailed) {
Chris@0 892 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@0 893 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i));
Chris@0 894 } else if (status == FileOpenWrongMode) {
Chris@0 895 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@0 896 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 897 } else {
Chris@0 898 configureNewPane(m_paneStack->getCurrentPane());
Chris@0 899 }
Chris@0 900 }
Chris@0 901 }
Chris@0 902
Chris@0 903 void
Chris@0 904 MainWindow::paneDropAccepted(Pane *pane, QString text)
Chris@0 905 {
Chris@0 906 if (pane) m_paneStack->setCurrentPane(pane);
Chris@0 907
Chris@0 908 QUrl testUrl(text);
Chris@0 909 if (testUrl.scheme() == "file" ||
Chris@0 910 testUrl.scheme() == "http" ||
Chris@0 911 testUrl.scheme() == "ftp") {
Chris@0 912 QStringList list;
Chris@0 913 list.push_back(text);
Chris@0 914 paneDropAccepted(pane, list);
Chris@0 915 return;
Chris@0 916 }
Chris@0 917
Chris@0 918 //!!! open as text -- but by importing as if a CSV, or just adding
Chris@0 919 //to a text layer?
Chris@0 920 }
Chris@0 921
Chris@0 922 void
Chris@0 923 MainWindow::configureNewPane(Pane *pane)
Chris@0 924 {
Chris@0 925 std::cerr << "MainWindow::configureNewPane(" << pane << ")" << std::endl;
Chris@0 926
Chris@6 927 if (!pane) {
Chris@6 928 pane = m_paneStack->addPane();
Chris@6 929 }
Chris@0 930
Chris@6 931 m_analyser->newFileLoaded(m_document, getMainModel(), m_paneStack, pane);
Chris@0 932 }
Chris@0 933
Chris@0 934 void
Chris@0 935 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 936 {
Chris@0 937 // std::cerr << "MainWindow::closeEvent" << std::endl;
Chris@0 938
Chris@0 939 if (m_openingAudioFile) {
Chris@0 940 // std::cerr << "Busy - ignoring close event" << std::endl;
gyorgyf@27 941 e->ignore();
gyorgyf@27 942 return;
Chris@0 943 }
Chris@0 944
Chris@0 945 if (!m_abandoning && !checkSaveModified()) {
Chris@0 946 // std::cerr << "Ignoring close event" << std::endl;
gyorgyf@27 947 e->ignore();
gyorgyf@27 948 return;
Chris@0 949 }
Chris@0 950
Chris@0 951 QSettings settings;
Chris@0 952 settings.beginGroup("MainWindow");
Chris@0 953 settings.setValue("size", size());
Chris@0 954 settings.setValue("position", pos());
Chris@0 955 settings.endGroup();
Chris@0 956
Chris@0 957 delete m_keyReference;
Chris@0 958 m_keyReference = 0;
Chris@0 959
Chris@0 960 closeSession();
Chris@0 961
Chris@0 962 e->accept();
Chris@0 963 return;
Chris@0 964 }
Chris@0 965
Chris@0 966 bool
Chris@0 967 MainWindow::commitData(bool mayAskUser)
Chris@0 968 {
Chris@0 969 if (mayAskUser) {
Chris@0 970 bool rv = checkSaveModified();
Chris@0 971 return rv;
Chris@0 972 } else {
Chris@0 973 if (!m_documentModified) return true;
Chris@0 974
Chris@0 975 // If we can't check with the user first, then we can't save
Chris@0 976 // to the original session file (even if we have it) -- have
Chris@0 977 // to use a temporary file
Chris@0 978
Chris@0 979 QString svDirBase = ".sv1";
Chris@0 980 QString svDir = QDir::home().filePath(svDirBase);
Chris@0 981
Chris@0 982 if (!QFileInfo(svDir).exists()) {
Chris@0 983 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@0 984 } else {
Chris@0 985 if (!QFileInfo(svDir).isDir()) return false;
Chris@0 986 }
Chris@0 987
Chris@0 988 // This name doesn't have to be unguessable
Chris@0 989 #ifndef _WIN32
Chris@0 990 QString fname = QString("tmp-%1-%2.sv")
Chris@0 991 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@0 992 .arg(QProcess().pid());
Chris@0 993 #else
Chris@0 994 QString fname = QString("tmp-%1.sv")
Chris@0 995 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@0 996 #endif
Chris@0 997 QString fpath = QDir(svDir).filePath(fname);
Chris@0 998 if (saveSessionFile(fpath)) {
Chris@0 999 m_recentFiles.addFile(fpath);
Chris@0 1000 return true;
Chris@0 1001 } else {
Chris@0 1002 return false;
Chris@0 1003 }
Chris@0 1004 }
Chris@0 1005 }
Chris@0 1006
Chris@0 1007 bool
Chris@0 1008 MainWindow::checkSaveModified()
Chris@0 1009 {
Chris@0 1010 // Called before some destructive operation (e.g. new session,
Chris@0 1011 // exit program). Return true if we can safely proceed, false to
Chris@0 1012 // cancel.
Chris@0 1013
Chris@0 1014 if (!m_documentModified) return true;
Chris@0 1015
Chris@0 1016 int button =
gyorgyf@27 1017 QMessageBox::warning(this,
gyorgyf@27 1018 tr("Session modified"),
gyorgyf@27 1019 tr("The current session has been modified.\nDo you want to save it?"),
gyorgyf@27 1020 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@0 1021 QMessageBox::Yes);
Chris@0 1022
Chris@0 1023 if (button == QMessageBox::Yes) {
gyorgyf@27 1024 saveSession();
gyorgyf@27 1025 if (m_documentModified) { // save failed -- don't proceed!
gyorgyf@27 1026 return false;
gyorgyf@27 1027 } else {
Chris@0 1028 return true; // saved, so it's safe to continue now
Chris@0 1029 }
Chris@0 1030 } else if (button == QMessageBox::No) {
gyorgyf@27 1031 m_documentModified = false; // so we know to abandon it
gyorgyf@27 1032 return true;
Chris@0 1033 }
Chris@0 1034
Chris@0 1035 // else cancel
Chris@0 1036 return false;
Chris@0 1037 }
Chris@0 1038
Chris@0 1039 void
Chris@0 1040 MainWindow::saveSession()
Chris@0 1041 {
Chris@0 1042 if (m_sessionFile != "") {
gyorgyf@27 1043 if (!saveSessionFile(m_sessionFile)) {
gyorgyf@27 1044 QMessageBox::critical(this, tr("Failed to save file"),
gyorgyf@27 1045 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 1046 } else {
gyorgyf@27 1047 CommandHistory::getInstance()->documentSaved();
gyorgyf@27 1048 documentRestored();
gyorgyf@27 1049 }
gyorgyf@27 1050 } else {
gyorgyf@27 1051 saveSessionAs();
Chris@0 1052 }
Chris@0 1053 }
Chris@0 1054
Chris@0 1055 void
Chris@0 1056 MainWindow::saveSessionAs()
Chris@0 1057 {
Chris@0 1058 QString orig = m_audioFile;
Chris@0 1059 if (orig == "") orig = ".";
Chris@0 1060 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 1061
Chris@0 1062 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@0 1063
Chris@0 1064 if (path == "") return;
Chris@0 1065
Chris@0 1066 if (!saveSessionFile(path)) {
gyorgyf@27 1067 QMessageBox::critical(this, tr("Failed to save file"),
gyorgyf@27 1068 tr("Session file \"%1\" could not be saved.").arg(path));
Chris@0 1069 } else {
gyorgyf@27 1070 setWindowTitle(tr("%1: %2")
Chris@0 1071 .arg(QApplication::applicationName())
gyorgyf@27 1072 .arg(QFileInfo(path).fileName()));
gyorgyf@27 1073 m_sessionFile = path;
gyorgyf@27 1074 CommandHistory::getInstance()->documentSaved();
gyorgyf@27 1075 documentRestored();
Chris@0 1076 m_recentFiles.addFile(path);
Chris@0 1077 }
Chris@0 1078 }
Chris@0 1079
Chris@0 1080 void
matthiasm@26 1081 MainWindow::exportLayer()
matthiasm@26 1082 {
matthiasm@26 1083 Pane *pane = m_paneStack->getCurrentPane();
matthiasm@26 1084 if (!pane) return;
matthiasm@26 1085
matthiasm@26 1086 Layer *layer = pane->getSelectedLayer();
matthiasm@26 1087 if (!layer) return;
matthiasm@26 1088
matthiasm@26 1089 Model *model = layer->getModel();
matthiasm@26 1090 if (!model) return;
matthiasm@26 1091
matthiasm@26 1092 FileFinder::FileType type = FileFinder::LayerFileNoMidi;
matthiasm@26 1093
matthiasm@26 1094 if (dynamic_cast<FlexiNoteModel *>(model)) type = FileFinder::LayerFile;
matthiasm@26 1095
matthiasm@26 1096 QString path = getSaveFileName(type);
matthiasm@26 1097
matthiasm@26 1098 if (path == "") return;
matthiasm@26 1099
matthiasm@26 1100 if (QFileInfo(path).suffix() == "") path += ".svl";
matthiasm@26 1101
matthiasm@26 1102 QString suffix = QFileInfo(path).suffix().toLower();
matthiasm@26 1103
matthiasm@26 1104 QString error;
matthiasm@26 1105
matthiasm@26 1106 if (suffix == "xml" || suffix == "svl") {
matthiasm@26 1107
matthiasm@26 1108 QFile file(path);
matthiasm@26 1109 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
matthiasm@26 1110 error = tr("Failed to open file %1 for writing").arg(path);
matthiasm@26 1111 } else {
matthiasm@26 1112 QTextStream out(&file);
matthiasm@26 1113 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
matthiasm@26 1114 << "<!DOCTYPE sonic-visualiser>\n"
matthiasm@26 1115 << "<sv>\n"
matthiasm@26 1116 << " <data>\n";
matthiasm@26 1117
matthiasm@26 1118 model->toXml(out, " ");
matthiasm@26 1119
matthiasm@26 1120 out << " </data>\n"
matthiasm@26 1121 << " <display>\n";
matthiasm@26 1122
matthiasm@26 1123 layer->toXml(out, " ");
matthiasm@26 1124
matthiasm@26 1125 out << " </display>\n"
matthiasm@26 1126 << "</sv>\n";
matthiasm@26 1127 }
matthiasm@26 1128
matthiasm@26 1129 // } else if (suffix == "mid" || suffix == "midi") {
matthiasm@26 1130 //
matthiasm@26 1131 // FlexiNoteModel *nm = dynamic_cast<FlexiNoteModel *>(model);
matthiasm@26 1132 //
matthiasm@26 1133 // if (!nm) {
matthiasm@26 1134 // error = tr("Can't export non-note layers to MIDI");
matthiasm@26 1135 // } else {
matthiasm@26 1136 // MIDIFileWriter writer(path, nm);
matthiasm@26 1137 // writer.write();
matthiasm@26 1138 // if (!writer.isOK()) {
matthiasm@26 1139 // error = writer.getError();
matthiasm@26 1140 // }
matthiasm@26 1141 // }
matthiasm@26 1142
matthiasm@26 1143 } else if (suffix == "ttl" || suffix == "n3") {
matthiasm@26 1144
matthiasm@26 1145 if (!RDFExporter::canExportModel(model)) {
matthiasm@26 1146 error = tr("Sorry, cannot export this layer type to RDF (supported types are: region, note, text, time instants, time values)");
matthiasm@26 1147 } else {
matthiasm@26 1148 RDFExporter exporter(path, model);
matthiasm@26 1149 exporter.write();
matthiasm@26 1150 if (!exporter.isOK()) {
matthiasm@26 1151 error = exporter.getError();
matthiasm@26 1152 }
matthiasm@26 1153 }
matthiasm@26 1154
matthiasm@26 1155 } else {
matthiasm@26 1156
matthiasm@26 1157 CSVFileWriter writer(path, model,
matthiasm@26 1158 ((suffix == "csv") ? "," : "\t"));
matthiasm@26 1159 writer.write();
matthiasm@26 1160
matthiasm@26 1161 if (!writer.isOK()) {
matthiasm@26 1162 error = writer.getError();
matthiasm@26 1163 }
matthiasm@26 1164 }
matthiasm@26 1165
matthiasm@26 1166 if (error != "") {
matthiasm@26 1167 QMessageBox::critical(this, tr("Failed to write file"), error);
matthiasm@26 1168 } else {
matthiasm@26 1169 m_recentFiles.addFile(path);
matthiasm@26 1170 emit activity(tr("Export layer to \"%1\"").arg(path));
matthiasm@26 1171 }
matthiasm@26 1172 }
matthiasm@26 1173
matthiasm@26 1174
matthiasm@26 1175 void
Chris@0 1176 MainWindow::renameCurrentLayer()
Chris@0 1177 {
Chris@0 1178 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 1179 if (pane) {
gyorgyf@27 1180 Layer *layer = pane->getSelectedLayer();
gyorgyf@27 1181 if (layer) {
gyorgyf@27 1182 bool ok = false;
gyorgyf@27 1183 QString newName = QInputDialog::getText
gyorgyf@27 1184 (this, tr("Rename Layer"),
gyorgyf@27 1185 tr("New name for this layer:"),
gyorgyf@27 1186 QLineEdit::Normal, layer->objectName(), &ok);
gyorgyf@27 1187 if (ok) {
gyorgyf@27 1188 layer->setObjectName(newName);
gyorgyf@27 1189 }
gyorgyf@27 1190 }
Chris@0 1191 }
Chris@0 1192 }
Chris@0 1193
Chris@0 1194 void
Chris@0 1195 MainWindow::playSpeedChanged(int position)
Chris@0 1196 {
Chris@0 1197 PlaySpeedRangeMapper mapper(0, 200);
Chris@0 1198
Chris@0 1199 float percent = m_playSpeed->mappedValue();
Chris@0 1200 float factor = mapper.getFactorForValue(percent);
Chris@0 1201
Chris@0 1202 std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
Chris@0 1203
Chris@0 1204 bool something = (position != 100);
Chris@0 1205
Chris@0 1206 int pc = lrintf(percent);
Chris@0 1207
Chris@0 1208 if (!something) {
Chris@0 1209 contextHelpChanged(tr("Playback speed: Normal"));
Chris@0 1210 } else {
Chris@0 1211 contextHelpChanged(tr("Playback speed: %1%2%")
Chris@0 1212 .arg(position > 100 ? "+" : "")
Chris@0 1213 .arg(pc));
Chris@0 1214 }
Chris@0 1215
Chris@0 1216 m_playSource->setTimeStretch(factor);
Chris@0 1217
Chris@0 1218 updateMenuStates();
Chris@0 1219 }
Chris@0 1220
Chris@0 1221 void
Chris@0 1222 MainWindow::playSharpenToggled()
Chris@0 1223 {
Chris@0 1224 QSettings settings;
Chris@0 1225 settings.beginGroup("MainWindow");
Chris@0 1226 settings.setValue("playsharpen", m_playSharpen->isChecked());
Chris@0 1227 settings.endGroup();
Chris@0 1228
Chris@0 1229 playSpeedChanged(m_playSpeed->value());
Chris@0 1230 }
Chris@0 1231
Chris@0 1232 void
Chris@0 1233 MainWindow::playMonoToggled()
Chris@0 1234 {
Chris@0 1235 QSettings settings;
Chris@0 1236 settings.beginGroup("MainWindow");
Chris@0 1237 settings.setValue("playmono", m_playMono->isChecked());
Chris@0 1238 settings.endGroup();
Chris@0 1239
Chris@0 1240 playSpeedChanged(m_playSpeed->value());
Chris@0 1241 }
Chris@0 1242
Chris@0 1243 void
Chris@0 1244 MainWindow::speedUpPlayback()
Chris@0 1245 {
Chris@0 1246 int value = m_playSpeed->value();
Chris@0 1247 value = value + m_playSpeed->pageStep();
Chris@0 1248 if (value > m_playSpeed->maximum()) value = m_playSpeed->maximum();
Chris@0 1249 m_playSpeed->setValue(value);
Chris@0 1250 }
Chris@0 1251
Chris@0 1252 void
Chris@0 1253 MainWindow::slowDownPlayback()
Chris@0 1254 {
Chris@0 1255 int value = m_playSpeed->value();
Chris@0 1256 value = value - m_playSpeed->pageStep();
Chris@0 1257 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
Chris@0 1258 m_playSpeed->setValue(value);
Chris@0 1259 }
Chris@0 1260
Chris@0 1261 void
Chris@0 1262 MainWindow::restoreNormalPlayback()
Chris@0 1263 {
Chris@0 1264 m_playSpeed->setValue(m_playSpeed->defaultValue());
Chris@0 1265 }
Chris@0 1266
Chris@0 1267 void
Chris@0 1268 MainWindow::updateVisibleRangeDisplay(Pane *p) const
Chris@0 1269 {
Chris@0 1270 if (!getMainModel() || !p) {
Chris@0 1271 return;
Chris@0 1272 }
Chris@0 1273
Chris@0 1274 bool haveSelection = false;
Chris@0 1275 size_t startFrame = 0, endFrame = 0;
Chris@0 1276
Chris@0 1277 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
Chris@0 1278
Chris@0 1279 bool exclusive = false;
Chris@0 1280 Selection s = m_viewManager->getInProgressSelection(exclusive);
Chris@0 1281
Chris@0 1282 if (!s.isEmpty()) {
Chris@0 1283 haveSelection = true;
Chris@0 1284 startFrame = s.getStartFrame();
Chris@0 1285 endFrame = s.getEndFrame();
Chris@0 1286 }
Chris@0 1287 }
Chris@0 1288
Chris@0 1289 if (!haveSelection) {
Chris@0 1290 startFrame = p->getFirstVisibleFrame();
Chris@0 1291 endFrame = p->getLastVisibleFrame();
Chris@0 1292 }
Chris@0 1293
Chris@0 1294 RealTime start = RealTime::frame2RealTime
Chris@0 1295 (startFrame, getMainModel()->getSampleRate());
Chris@0 1296
Chris@0 1297 RealTime end = RealTime::frame2RealTime
Chris@0 1298 (endFrame, getMainModel()->getSampleRate());
Chris@0 1299
Chris@0 1300 RealTime duration = end - start;
Chris@0 1301
Chris@0 1302 QString startStr, endStr, durationStr;
Chris@0 1303 startStr = start.toText(true).c_str();
Chris@0 1304 endStr = end.toText(true).c_str();
Chris@0 1305 durationStr = duration.toText(true).c_str();
Chris@0 1306
Chris@0 1307 if (haveSelection) {
Chris@0 1308 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
Chris@0 1309 .arg(startStr).arg(endStr).arg(durationStr);
Chris@0 1310 } else {
Chris@0 1311 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
Chris@0 1312 .arg(startStr).arg(endStr).arg(durationStr);
Chris@0 1313 }
matthiasm@42 1314
matthiasm@42 1315 // scale Y axis
matthiasm@42 1316 FlexiNoteLayer *fnl = dynamic_cast<FlexiNoteLayer *>(p->getLayer(2));
matthiasm@42 1317 if (fnl) {
matthiasm@42 1318 fnl->setVerticalRangeToNoteRange(p);
matthiasm@42 1319 }
matthiasm@42 1320
Chris@0 1321 statusBar()->showMessage(m_myStatusMessage);
Chris@0 1322 }
Chris@0 1323
Chris@0 1324 void
Chris@0 1325 MainWindow::updatePositionStatusDisplays() const
Chris@0 1326 {
Chris@0 1327 if (!statusBar()->isVisible()) return;
Chris@0 1328
Chris@0 1329 }
Chris@0 1330
Chris@0 1331 void
Chris@0 1332 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 1333 {
Chris@0 1334 m_fader->setPeakLeft(left);
Chris@0 1335 m_fader->setPeakRight(right);
Chris@0 1336 }
Chris@0 1337
Chris@0 1338 void
Chris@0 1339 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
Chris@0 1340 bool willResample)
Chris@0 1341 {
Chris@0 1342 updateDescriptionLabel();
Chris@0 1343 }
Chris@0 1344
Chris@0 1345 void
Chris@0 1346 MainWindow::audioOverloadPluginDisabled()
Chris@0 1347 {
Chris@0 1348 QMessageBox::information
Chris@0 1349 (this, tr("Audio processing overload"),
Chris@0 1350 tr("<b>Overloaded</b><p>Audio effects plugin auditioning has been disabled due to a processing overload."));
Chris@0 1351 }
Chris@0 1352
Chris@0 1353 void
Chris@0 1354 MainWindow::audioTimeStretchMultiChannelDisabled()
Chris@0 1355 {
Chris@0 1356 static bool shownOnce = false;
Chris@0 1357 if (shownOnce) return;
Chris@0 1358 QMessageBox::information
Chris@0 1359 (this, tr("Audio processing overload"),
Chris@0 1360 tr("<b>Overloaded</b><p>Audio playback speed processing has been reduced to a single channel, due to a processing overload."));
Chris@0 1361 shownOnce = true;
Chris@0 1362 }
Chris@0 1363
Chris@0 1364 void
Chris@0 1365 MainWindow::layerRemoved(Layer *layer)
Chris@0 1366 {
Chris@0 1367 MainWindowBase::layerRemoved(layer);
Chris@0 1368 }
Chris@0 1369
Chris@0 1370 void
Chris@0 1371 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 1372 {
Chris@0 1373 MainWindowBase::layerInAView(layer, inAView);
Chris@0 1374 }
Chris@0 1375
Chris@0 1376 void
Chris@0 1377 MainWindow::modelAdded(Model *model)
Chris@0 1378 {
Chris@0 1379 MainWindowBase::modelAdded(model);
Chris@3 1380 DenseTimeValueModel *dtvm = qobject_cast<DenseTimeValueModel *>(model);
Chris@0 1381 if (dtvm) {
Chris@0 1382 std::cerr << "A dense time-value model (such as an audio file) has been loaded" << std::endl;
Chris@0 1383 }
Chris@0 1384 }
Chris@0 1385
Chris@0 1386 void
Chris@0 1387 MainWindow::modelAboutToBeDeleted(Model *model)
Chris@0 1388 {
Chris@0 1389 MainWindowBase::modelAboutToBeDeleted(model);
Chris@0 1390 }
Chris@0 1391
Chris@0 1392 void
Chris@0 1393 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 1394 {
Chris@0 1395 m_panLayer->setModel(model);
Chris@0 1396
Chris@0 1397 MainWindowBase::mainModelChanged(model);
Chris@0 1398
Chris@0 1399 if (m_playTarget) {
Chris@0 1400 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@0 1401 m_playTarget, SLOT(setOutputGain(float)));
Chris@0 1402 }
Chris@0 1403 }
Chris@0 1404
Chris@0 1405 void
Chris@0 1406 MainWindow::modelGenerationFailed(QString transformName, QString message)
Chris@0 1407 {
Chris@0 1408 if (message != "") {
Chris@0 1409
Chris@0 1410 QMessageBox::warning
Chris@0 1411 (this,
Chris@0 1412 tr("Failed to generate layer"),
Chris@0 1413 tr("<b>Layer generation failed</b><p>Failed to generate derived layer.<p>The layer transform \"%1\" failed:<p>%2")
Chris@0 1414 .arg(transformName).arg(message),
Chris@0 1415 QMessageBox::Ok);
Chris@0 1416 } else {
Chris@0 1417 QMessageBox::warning
Chris@0 1418 (this,
Chris@0 1419 tr("Failed to generate layer"),
Chris@0 1420 tr("<b>Layer generation failed</b><p>Failed to generate a derived layer.<p>The layer transform \"%1\" failed.<p>No error information is available.")
Chris@0 1421 .arg(transformName),
Chris@0 1422 QMessageBox::Ok);
Chris@0 1423 }
Chris@0 1424 }
Chris@0 1425
Chris@0 1426 void
Chris@0 1427 MainWindow::modelGenerationWarning(QString transformName, QString message)
Chris@0 1428 {
Chris@0 1429 QMessageBox::warning
Chris@0 1430 (this, tr("Warning"), message, QMessageBox::Ok);
Chris@0 1431 }
Chris@0 1432
Chris@0 1433 void
Chris@0 1434 MainWindow::modelRegenerationFailed(QString layerName,
Chris@0 1435 QString transformName, QString message)
Chris@0 1436 {
Chris@0 1437 if (message != "") {
Chris@0 1438
Chris@0 1439 QMessageBox::warning
Chris@0 1440 (this,
Chris@0 1441 tr("Failed to regenerate layer"),
Chris@0 1442 tr("<b>Layer generation failed</b><p>Failed to regenerate derived layer \"%1\" using new data model as input.<p>The layer transform \"%2\" failed:<p>%3")
Chris@0 1443 .arg(layerName).arg(transformName).arg(message),
Chris@0 1444 QMessageBox::Ok);
Chris@0 1445 } else {
Chris@0 1446 QMessageBox::warning
Chris@0 1447 (this,
Chris@0 1448 tr("Failed to regenerate layer"),
Chris@0 1449 tr("<b>Layer generation failed</b><p>Failed to regenerate derived layer \"%1\" using new data model as input.<p>The layer transform \"%2\" failed.<p>No error information is available.")
Chris@0 1450 .arg(layerName).arg(transformName),
Chris@0 1451 QMessageBox::Ok);
Chris@0 1452 }
Chris@0 1453 }
Chris@0 1454
Chris@0 1455 void
Chris@0 1456 MainWindow::modelRegenerationWarning(QString layerName,
Chris@0 1457 QString transformName, QString message)
Chris@0 1458 {
Chris@0 1459 QMessageBox::warning
Chris@0 1460 (this, tr("Warning"), tr("<b>Warning when regenerating layer</b><p>When regenerating the derived layer \"%1\" using new data model as input:<p>%2").arg(layerName).arg(message), QMessageBox::Ok);
Chris@0 1461 }
Chris@0 1462
Chris@0 1463 void
Chris@0 1464 MainWindow::alignmentFailed(QString transformName, QString message)
Chris@0 1465 {
Chris@0 1466 QMessageBox::warning
Chris@0 1467 (this,
Chris@0 1468 tr("Failed to calculate alignment"),
Chris@0 1469 tr("<b>Alignment calculation failed</b><p>Failed to calculate an audio alignment using transform \"%1\":<p>%2")
Chris@0 1470 .arg(transformName).arg(message),
Chris@0 1471 QMessageBox::Ok);
Chris@0 1472 }
Chris@0 1473
Chris@0 1474 void
Chris@0 1475 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 1476 {
Chris@0 1477 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
Chris@0 1478 m_paneStack->setCurrentPane(pane);
Chris@0 1479 m_rightButtonMenu->popup(position);
Chris@0 1480 }
Chris@0 1481
Chris@0 1482 void
Chris@0 1483 MainWindow::handleOSCMessage(const OSCMessage &message)
Chris@0 1484 {
Chris@0 1485 std::cerr << "MainWindow::handleOSCMessage: Not implemented" << std::endl;
Chris@0 1486 }
Chris@0 1487
Chris@0 1488 void
Chris@0 1489 MainWindow::mouseEnteredWidget()
Chris@0 1490 {
Chris@3 1491 QWidget *w = qobject_cast<QWidget *>(sender());
Chris@0 1492 if (!w) return;
Chris@0 1493
Chris@0 1494 if (w == m_fader) {
Chris@0 1495 contextHelpChanged(tr("Adjust the master playback level"));
Chris@0 1496 } else if (w == m_playSpeed) {
Chris@0 1497 contextHelpChanged(tr("Adjust the master playback speed"));
Chris@0 1498 } else if (w == m_playSharpen && w->isEnabled()) {
Chris@0 1499 contextHelpChanged(tr("Toggle transient sharpening for playback time scaling"));
Chris@0 1500 } else if (w == m_playMono && w->isEnabled()) {
Chris@0 1501 contextHelpChanged(tr("Toggle mono mode for playback time scaling"));
Chris@0 1502 }
Chris@0 1503 }
Chris@0 1504
Chris@0 1505 void
Chris@0 1506 MainWindow::mouseLeftWidget()
Chris@0 1507 {
Chris@0 1508 contextHelpChanged("");
Chris@0 1509 }
Chris@0 1510
Chris@0 1511 void
Chris@0 1512 MainWindow::website()
Chris@0 1513 {
Chris@4 1514 //!!! todo: URL!
Chris@4 1515 openHelpUrl(tr("http://code.soundsoftware.ac.uk/projects/tony/"));
Chris@0 1516 }
Chris@0 1517
Chris@0 1518 void
Chris@0 1519 MainWindow::help()
Chris@0 1520 {
Chris@4 1521 //!!! todo: help URL!
Chris@4 1522 openHelpUrl(tr("http://code.soundsoftware.ac.uk/projects/tony/"));
Chris@0 1523 }
Chris@0 1524
Chris@0 1525 void
Chris@0 1526 MainWindow::about()
Chris@0 1527 {
Chris@0 1528 bool debug = false;
Chris@0 1529 QString version = "(unknown version)";
Chris@0 1530
Chris@0 1531 #ifdef BUILD_DEBUG
Chris@0 1532 debug = true;
Chris@0 1533 #endif
Chris@0 1534 version = tr("Release %1").arg(TONY_VERSION);
Chris@0 1535
Chris@0 1536 QString aboutText;
Chris@0 1537
Chris@0 1538 aboutText += tr("<h3>About Tony</h3>");
Chris@0 1539 aboutText += tr("<p>Tony is a program for interactive note and pitch analysis and annotation.</p>");
Chris@0 1540 aboutText += tr("<p>%1 : %2 configuration</p>")
Chris@0 1541 .arg(version)
Chris@0 1542 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 1543
Chris@0 1544 #ifndef BUILD_STATIC
Chris@0 1545 aboutText += tr("<br>Using Qt v%1 &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@0 1546 #else
Chris@0 1547 #ifdef QT_SHARED
Chris@0 1548 aboutText += tr("<br>Using Qt v%1 &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@0 1549 #endif
Chris@0 1550 #endif
Chris@0 1551
Chris@0 1552 #ifdef BUILD_STATIC
Chris@0 1553 aboutText += tr("<p>Statically linked");
Chris@0 1554 #ifndef QT_SHARED
Chris@0 1555 aboutText += tr("<br>With Qt (v%1) &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@0 1556 #endif
Chris@0 1557 #ifdef HAVE_JACK
Chris@0 1558 #ifdef JACK_VERSION
Chris@0 1559 aboutText += tr("<br>With JACK audio output (v%1) &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@0 1560 #else
Chris@0 1561 aboutText += tr("<br>With JACK audio output &copy; Paul Davis and Jack O'Quin");
Chris@0 1562 #endif
Chris@0 1563 #endif
Chris@0 1564 #ifdef HAVE_PORTAUDIO
Chris@0 1565 aboutText += tr("<br>With PortAudio audio output &copy; Ross Bencina and Phil Burk");
Chris@0 1566 #endif
Chris@0 1567 #ifdef HAVE_OGGZ
Chris@0 1568 #ifdef OGGZ_VERSION
Chris@0 1569 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@0 1570 #else
Chris@0 1571 aboutText += tr("<br>With Ogg file decoder &copy; CSIRO Australia");
Chris@0 1572 #endif
Chris@0 1573 #endif
Chris@0 1574 #ifdef HAVE_MAD
Chris@0 1575 #ifdef MAD_VERSION
Chris@0 1576 aboutText += tr("<br>With MAD mp3 decoder (v%1) &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@0 1577 #else
Chris@0 1578 aboutText += tr("<br>With MAD mp3 decoder &copy; Underbit Technologies Inc");
Chris@0 1579 #endif
Chris@0 1580 #endif
Chris@0 1581 #ifdef HAVE_SAMPLERATE
Chris@0 1582 #ifdef SAMPLERATE_VERSION
Chris@0 1583 aboutText += tr("<br>With libsamplerate (v%1) &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@0 1584 #else
Chris@0 1585 aboutText += tr("<br>With libsamplerate &copy; Erik de Castro Lopo");
Chris@0 1586 #endif
Chris@0 1587 #endif
Chris@0 1588 #ifdef HAVE_SNDFILE
Chris@0 1589 #ifdef SNDFILE_VERSION
Chris@0 1590 aboutText += tr("<br>With libsndfile (v%1) &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@0 1591 #else
Chris@0 1592 aboutText += tr("<br>With libsndfile &copy; Erik de Castro Lopo");
Chris@0 1593 #endif
Chris@0 1594 #endif
Chris@0 1595 #ifdef HAVE_FFTW3F
Chris@0 1596 #ifdef FFTW3_VERSION
Chris@0 1597 aboutText += tr("<br>With FFTW3 (v%1) &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@0 1598 #else
Chris@0 1599 aboutText += tr("<br>With FFTW3 &copy; Matteo Frigo and MIT");
Chris@0 1600 #endif
Chris@0 1601 #endif
Chris@0 1602 #ifdef HAVE_VAMP
Chris@0 1603 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 1604 #endif
Chris@0 1605 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 1606 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@0 1607 #ifdef HAVE_LIBLO
Chris@0 1608 #ifdef LIBLO_VERSION
Chris@0 1609 aboutText += tr("<br>With liblo Lite OSC library (v%1) &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@0 1610 #else
Chris@0 1611 aboutText += tr("<br>With liblo Lite OSC library &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@0 1612 #endif
Chris@0 1613 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@0 1614 aboutText += tr("<p>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
Chris@0 1615 }
Chris@0 1616 #endif
Chris@0 1617 aboutText += "</p>";
Chris@0 1618 #endif
Chris@0 1619
Chris@0 1620 aboutText +=
Chris@0 1621 "<p>Copyright &copy; 2005&ndash;2012 Chris Cannam and<br>"
Chris@0 1622 "Queen Mary, University of London.</p>"
Chris@0 1623 "<p>This program is free software; you can redistribute it and/or<br>"
Chris@0 1624 "modify it under the terms of the GNU General Public License as<br>"
Chris@0 1625 "published by the Free Software Foundation; either version 2 of the<br>"
Chris@0 1626 "License, or (at your option) any later version.<br>See the file "
Chris@0 1627 "COPYING included with this distribution for more information.</p>";
Chris@0 1628
Chris@0 1629 QMessageBox::about(this, tr("About %1").arg(QApplication::applicationName()), aboutText);
Chris@0 1630 }
Chris@0 1631
Chris@0 1632 void
Chris@0 1633 MainWindow::keyReference()
Chris@0 1634 {
Chris@0 1635 m_keyReference->show();
Chris@0 1636 }
Chris@0 1637
Chris@0 1638