annotate src/MainWindow.cpp @ 374:ff797e8967b6 tonioni_multi_transform

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