annotate src/MainWindow.cpp @ 367:3c8dccd0cafe

removed unhelpful help item from help menu
author matthiasm
date Tue, 15 Jul 2014 18:15:37 +0100
parents 6439ca6e7de1
children a848ca75b5d2
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@95 19 #include "NetworkPermissionTester.h"
Chris@6 20 #include "Analyser.h"
Chris@6 21
Chris@0 22 #include "framework/Document.h"
Chris@95 23 #include "framework/VersionTester.h"
Chris@0 24
Chris@0 25 #include "view/Pane.h"
Chris@0 26 #include "view/PaneStack.h"
Chris@0 27 #include "data/model/WaveFileModel.h"
matthiasm@26 28 #include "data/model/NoteModel.h"
matthiasm@26 29 #include "data/model/FlexiNoteModel.h"
matthiasm@42 30 #include "layer/FlexiNoteLayer.h"
matthiasm@26 31 #include "data/model/NoteModel.h"
Chris@0 32 #include "view/ViewManager.h"
Chris@0 33 #include "base/Preferences.h"
Chris@0 34 #include "layer/WaveformLayer.h"
Chris@0 35 #include "layer/TimeInstantLayer.h"
Chris@0 36 #include "layer/TimeValueLayer.h"
Chris@192 37 #include "layer/SpectrogramLayer.h"
Chris@0 38 #include "widgets/Fader.h"
Chris@0 39 #include "view/Overview.h"
Chris@0 40 #include "widgets/AudioDial.h"
Chris@0 41 #include "widgets/IconLoader.h"
Chris@0 42 #include "widgets/KeyReference.h"
Chris@0 43 #include "audioio/AudioCallbackPlaySource.h"
Chris@0 44 #include "audioio/AudioCallbackPlayTarget.h"
Chris@0 45 #include "audioio/PlaySpeedRangeMapper.h"
Chris@0 46 #include "base/Profiler.h"
Chris@0 47 #include "base/UnitDatabase.h"
Chris@0 48 #include "layer/ColourDatabase.h"
Chris@139 49 #include "base/Selection.h"
Chris@0 50
Chris@174 51 #include "rdf/RDFImporter.h"
Chris@174 52 #include "data/fileio/DataFileReaderFactory.h"
Chris@174 53 #include "data/fileio/CSVFormat.h"
matthiasm@26 54 #include "data/fileio/CSVFileWriter.h"
matthiasm@26 55 #include "data/fileio/MIDIFileWriter.h"
matthiasm@26 56 #include "rdf/RDFExporter.h"
matthiasm@26 57
Chris@227 58 #include "widgets/RangeInputDialog.h"
Chris@244 59 #include "widgets/ActivityLog.h"
Chris@227 60
Chris@0 61 // For version information
Chris@0 62 #include "vamp/vamp.h"
Chris@0 63 #include "vamp-sdk/PluginBase.h"
Chris@0 64 #include "plugin/api/ladspa.h"
Chris@0 65 #include "plugin/api/dssi.h"
Chris@0 66
Chris@0 67 #include <QApplication>
Chris@0 68 #include <QMessageBox>
Chris@0 69 #include <QGridLayout>
Chris@0 70 #include <QLabel>
Chris@0 71 #include <QMenuBar>
Chris@0 72 #include <QToolBar>
Chris@0 73 #include <QToolButton>
Chris@0 74 #include <QInputDialog>
Chris@0 75 #include <QStatusBar>
Chris@0 76 #include <QFileInfo>
Chris@0 77 #include <QDir>
Chris@0 78 #include <QProcess>
Chris@2 79 #include <QPushButton>
Chris@0 80 #include <QSettings>
Chris@0 81 #include <QScrollArea>
Chris@128 82 #include <QPainter>
Chris@0 83
Chris@0 84 #include <iostream>
Chris@0 85 #include <cstdio>
Chris@0 86 #include <errno.h>
Chris@0 87
Chris@0 88 using std::vector;
Chris@0 89
Chris@0 90
matthiasm@364 91 MainWindow::MainWindow(bool withAudioOutput, bool withSonification, bool withSpectrogram) :
Chris@277 92 MainWindowBase(withAudioOutput, false),
Chris@0 93 m_overview(0),
Chris@0 94 m_mainMenusCreated(false),
Chris@0 95 m_playbackMenu(0),
gyorgyf@45 96 m_recentFilesMenu(0),
Chris@0 97 m_rightButtonMenu(0),
Chris@0 98 m_rightButtonPlaybackMenu(0),
Chris@0 99 m_deleteSelectedAction(0),
Chris@0 100 m_ffwdAction(0),
Chris@0 101 m_rwdAction(0),
Chris@168 102 m_intelligentActionOn(true), //GF: !!! temporary
Chris@244 103 m_activityLog(new ActivityLog()),
matthiasm@296 104 m_keyReference(new KeyReference()),
matthiasm@364 105 m_selectionAnchor(0),
matthiasm@364 106 m_withSonification(withSonification),
matthiasm@364 107 m_withSpectrogram(withSpectrogram)
Chris@0 108 {
Chris@0 109 setWindowTitle(QApplication::applicationName());
Chris@0 110
Chris@206 111 #ifdef Q_OS_MAC
Chris@206 112 #if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
Chris@206 113 setUnifiedTitleAndToolBarOnMac(true);
Chris@206 114 #endif
Chris@206 115 #endif
Chris@206 116
Chris@0 117 UnitDatabase *udb = UnitDatabase::getInstance();
Chris@0 118 udb->registerUnit("Hz");
Chris@0 119 udb->registerUnit("dB");
Chris@0 120 udb->registerUnit("s");
Chris@0 121
Chris@0 122 ColourDatabase *cdb = ColourDatabase::getInstance();
Chris@0 123 cdb->addColour(Qt::black, tr("Black"));
Chris@0 124 cdb->addColour(Qt::darkRed, tr("Red"));
Chris@0 125 cdb->addColour(Qt::darkBlue, tr("Blue"));
Chris@0 126 cdb->addColour(Qt::darkGreen, tr("Green"));
Chris@0 127 cdb->addColour(QColor(200, 50, 255), tr("Purple"));
Chris@0 128 cdb->addColour(QColor(255, 150, 50), tr("Orange"));
Chris@120 129 cdb->addColour(QColor(180, 180, 180), tr("Grey"));
Chris@0 130 cdb->setUseDarkBackground(cdb->addColour(Qt::white, tr("White")), true);
Chris@0 131 cdb->setUseDarkBackground(cdb->addColour(Qt::red, tr("Bright Red")), true);
Chris@0 132 cdb->setUseDarkBackground(cdb->addColour(QColor(30, 150, 255), tr("Bright Blue")), true);
Chris@0 133 cdb->setUseDarkBackground(cdb->addColour(Qt::green, tr("Bright Green")), true);
Chris@0 134 cdb->setUseDarkBackground(cdb->addColour(QColor(225, 74, 255), tr("Bright Purple")), true);
Chris@0 135 cdb->setUseDarkBackground(cdb->addColour(QColor(255, 188, 80), tr("Bright Orange")), true);
Chris@0 136
Chris@0 137 Preferences::getInstance()->setResampleOnLoad(true);
Chris@315 138 Preferences::getInstance()->setFixedSampleRate(44100);
Chris@0 139 Preferences::getInstance()->setSpectrogramSmoothing
Chris@0 140 (Preferences::SpectrogramInterpolated);
Chris@332 141 Preferences::getInstance()->setNormaliseAudio(true);
Chris@0 142
Chris@0 143 QSettings settings;
Chris@0 144
Chris@0 145 settings.beginGroup("MainWindow");
Chris@0 146 settings.setValue("showstatusbar", false);
Chris@0 147 settings.endGroup();
Chris@0 148
Chris@96 149 settings.beginGroup("Transformer");
Chris@96 150 settings.setValue("use-flexi-note-model", true);
Chris@96 151 settings.endGroup();
Chris@96 152
Chris@73 153 settings.beginGroup("LayerDefaults");
Chris@73 154 settings.setValue("waveform",
Chris@73 155 QString("<layer scale=\"%1\" channelMode=\"%2\"/>")
Chris@73 156 .arg(int(WaveformLayer::LinearScale))
Chris@73 157 .arg(int(WaveformLayer::MixChannels)));
Chris@73 158 settings.endGroup();
Chris@73 159
Chris@6 160 m_viewManager->setAlignMode(false);
Chris@6 161 m_viewManager->setPlaySoloMode(false);
Chris@0 162 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@0 163 m_viewManager->setZoomWheelsEnabled(false);
Chris@6 164 m_viewManager->setIlluminateLocalFeatures(true);
Chris@0 165 m_viewManager->setShowWorkTitle(true);
Chris@6 166 m_viewManager->setShowCentreLine(false);
Chris@213 167 m_viewManager->setOverlayMode(ViewManager::GlobalOverlays);
Chris@0 168
Chris@192 169 connect(m_viewManager, SIGNAL(selectionChangedByUser()),
Chris@192 170 this, SLOT(selectionChangedByUser()));
Chris@164 171
Chris@0 172 QFrame *frame = new QFrame;
Chris@0 173 setCentralWidget(frame);
Chris@0 174
Chris@0 175 QGridLayout *layout = new QGridLayout;
Chris@0 176
Chris@0 177 QScrollArea *scroll = new QScrollArea(frame);
Chris@0 178 scroll->setWidgetResizable(true);
Chris@0 179 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Chris@0 180 scroll->setFrameShape(QFrame::NoFrame);
Chris@0 181
Chris@6 182 // We have a pane stack: it comes with the territory. However, we
Chris@120 183 // have a fixed and known number of panes in it -- it isn't
Chris@120 184 // variable
Chris@0 185 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
Chris@137 186 m_paneStack->setShowPaneAccessories(false);
Chris@355 187 connect(m_paneStack, SIGNAL(doubleClickSelectInvoked(int)),
Chris@355 188 this, SLOT(doubleClickSelectInvoked(int)));
Chris@0 189 scroll->setWidget(m_paneStack);
Chris@6 190
Chris@0 191 m_overview = new Overview(frame);
Chris@362 192 m_overview->setPlaybackFollow(PlaybackScrollPage);
Chris@0 193 m_overview->setViewManager(m_viewManager);
Chris@0 194 m_overview->setFixedHeight(40);
Chris@0 195 #ifndef _WIN32
Chris@0 196 // For some reason, the contents of the overview never appear if we
Chris@0 197 // make this setting on Windows. I have no inclination at the moment
Chris@0 198 // to track down the reason why.
Chris@0 199 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@0 200 #endif
Chris@0 201 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
Chris@0 202 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 203
Chris@0 204 m_panLayer = new WaveformLayer;
Chris@0 205 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
Chris@0 206 m_panLayer->setAggressiveCacheing(true);
Chris@0 207 m_overview->addLayer(m_panLayer);
Chris@0 208
Chris@0 209 if (m_viewManager->getGlobalDarkBackground()) {
Chris@0 210 m_panLayer->setBaseColour
Chris@0 211 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@0 212 } else {
Chris@0 213 m_panLayer->setBaseColour
matthiasm@13 214 (ColourDatabase::getInstance()->getColourIndex(tr("Blue")));
Chris@0 215 }
Chris@0 216
Chris@0 217 m_fader = new Fader(frame, false);
Chris@0 218 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@0 219 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@0 220
Chris@0 221 m_playSpeed = new AudioDial(frame);
Chris@343 222 m_playSpeed->setMeterColor(Qt::darkBlue);
Chris@0 223 m_playSpeed->setMinimum(0);
Chris@0 224 m_playSpeed->setMaximum(200);
Chris@0 225 m_playSpeed->setValue(100);
Chris@0 226 m_playSpeed->setFixedWidth(24);
Chris@0 227 m_playSpeed->setFixedHeight(24);
Chris@0 228 m_playSpeed->setNotchesVisible(true);
Chris@0 229 m_playSpeed->setPageStep(10);
Chris@0 230 m_playSpeed->setObjectName(tr("Playback Speedup"));
Chris@0 231 m_playSpeed->setDefaultValue(100);
Chris@0 232 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
Chris@0 233 m_playSpeed->setShowToolTip(true);
Chris@0 234 connect(m_playSpeed, SIGNAL(valueChanged(int)),
gyorgyf@27 235 this, SLOT(playSpeedChanged(int)));
Chris@0 236 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@0 237 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@0 238
justin@159 239 // Gain controls
justin@159 240 m_gainAudio = new AudioDial(frame);
Chris@343 241 m_gainAudio->setMeterColor(Qt::darkRed);
justin@159 242 m_gainAudio->setMinimum(-50);
justin@159 243 m_gainAudio->setMaximum(50);
justin@159 244 m_gainAudio->setValue(0);
justin@159 245 m_gainAudio->setDefaultValue(0);
justin@220 246 //m_gainAudio->setFixedWidth(40);
justin@159 247 m_gainAudio->setFixedWidth(24);
justin@159 248 m_gainAudio->setFixedHeight(24);
justin@159 249 m_gainAudio->setNotchesVisible(true);
justin@159 250 m_gainAudio->setPageStep(10);
justin@159 251 m_gainAudio->setObjectName(tr("Audio Track Gain"));
justin@159 252 m_gainAudio->setRangeMapper(new LinearRangeMapper(-50, 50, -25, 25, tr("dB")));
justin@159 253 m_gainAudio->setShowToolTip(true);
justin@159 254 connect(m_gainAudio, SIGNAL(valueChanged(int)),
justin@159 255 this, SLOT(audioGainChanged(int)));
justin@159 256 connect(m_gainAudio, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
justin@159 257 connect(m_gainAudio, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
justin@159 258
matthiasm@366 259 if (m_withSonification)
matthiasm@366 260 {
matthiasm@366 261 m_gainPitch = new AudioDial(frame);
matthiasm@366 262 m_gainPitch->setMeterColor(Qt::darkRed);
matthiasm@366 263 m_gainPitch->setMinimum(-50);
matthiasm@366 264 m_gainPitch->setMaximum(50);
matthiasm@366 265 m_gainPitch->setValue(0);
matthiasm@366 266 m_gainPitch->setDefaultValue(0);
matthiasm@366 267 m_gainPitch->setFixedWidth(24);
matthiasm@366 268 m_gainPitch->setFixedHeight(24);
matthiasm@366 269 m_gainPitch->setNotchesVisible(true);
matthiasm@366 270 m_gainPitch->setPageStep(10);
matthiasm@366 271 m_gainPitch->setObjectName(tr("Pitch Track Gain"));
matthiasm@366 272 m_gainPitch->setRangeMapper(new LinearRangeMapper(-50, 50, -25, 25, tr("dB")));
matthiasm@366 273 m_gainPitch->setShowToolTip(true);
matthiasm@366 274 connect(m_gainPitch, SIGNAL(valueChanged(int)),
matthiasm@366 275 this, SLOT(pitchGainChanged(int)));
matthiasm@366 276 connect(m_gainPitch, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
matthiasm@366 277 connect(m_gainPitch, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
matthiasm@366 278
matthiasm@366 279 m_gainNotes = new AudioDial(frame);
matthiasm@366 280 m_gainNotes->setMeterColor(Qt::darkRed);
matthiasm@366 281 m_gainNotes->setMinimum(-50);
matthiasm@366 282 m_gainNotes->setMaximum(50);
matthiasm@366 283 m_gainNotes->setValue(0);
matthiasm@366 284 m_gainNotes->setDefaultValue(0);
matthiasm@366 285 m_gainNotes->setFixedWidth(24);
matthiasm@366 286 m_gainNotes->setFixedHeight(24);
matthiasm@366 287 m_gainNotes->setNotchesVisible(true);
matthiasm@366 288 m_gainNotes->setPageStep(10);
matthiasm@366 289 m_gainNotes->setObjectName(tr("Note Gain"));
matthiasm@366 290 m_gainNotes->setRangeMapper(new LinearRangeMapper(-50, 50, -25, 25, tr("dB")));
matthiasm@366 291 m_gainNotes->setShowToolTip(true);
matthiasm@366 292 connect(m_gainNotes, SIGNAL(valueChanged(int)),
matthiasm@366 293 this, SLOT(notesGainChanged(int)));
matthiasm@366 294 connect(m_gainNotes, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
matthiasm@366 295 connect(m_gainNotes, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
matthiasm@366 296 }
justin@159 297 // End of Gain controls
justin@159 298
justin@160 299 // Pan controls
justin@160 300 m_panAudio = new AudioDial(frame);
Chris@343 301 m_panAudio->setMeterColor(Qt::darkGreen);
justin@160 302 m_panAudio->setMinimum(-100);
justin@160 303 m_panAudio->setMaximum(100);
justin@160 304 m_panAudio->setValue(-100);
justin@160 305 m_panAudio->setDefaultValue(-100);
justin@160 306 m_panAudio->setFixedWidth(24);
justin@220 307 //m_panAudio->setFixedWidth(40);
justin@160 308 m_panAudio->setFixedHeight(24);
justin@160 309 m_panAudio->setNotchesVisible(true);
justin@160 310 m_panAudio->setPageStep(10);
justin@160 311 m_panAudio->setObjectName(tr("Audio Track Pan"));
justin@160 312 m_panAudio->setRangeMapper(new LinearRangeMapper(-100, 100, -100, 100, tr("")));
justin@160 313 m_panAudio->setShowToolTip(true);
justin@160 314 connect(m_panAudio, SIGNAL(valueChanged(int)),
justin@160 315 this, SLOT(audioPanChanged(int)));
justin@160 316 connect(m_panAudio, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
justin@160 317 connect(m_panAudio, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
justin@160 318
matthiasm@366 319
matthiasm@366 320
matthiasm@366 321 if (m_withSonification)
matthiasm@366 322 {
matthiasm@366 323 m_panPitch = new AudioDial(frame);
matthiasm@366 324 m_panPitch->setMeterColor(Qt::darkGreen);
matthiasm@366 325 m_panPitch->setMinimum(-100);
matthiasm@366 326 m_panPitch->setMaximum(100);
matthiasm@366 327 m_panPitch->setValue(100);
matthiasm@366 328 m_panPitch->setDefaultValue(100);
matthiasm@366 329 m_panPitch->setFixedWidth(24);
matthiasm@366 330 m_panPitch->setFixedHeight(24);
matthiasm@366 331 m_panPitch->setNotchesVisible(true);
matthiasm@366 332 m_panPitch->setPageStep(10);
matthiasm@366 333 m_panPitch->setObjectName(tr("Pitch Track Pan"));
matthiasm@366 334 m_panPitch->setRangeMapper(new LinearRangeMapper(-100, 100, -100, 100, tr("")));
matthiasm@366 335 m_panPitch->setShowToolTip(true);
matthiasm@366 336 connect(m_panPitch, SIGNAL(valueChanged(int)),
matthiasm@366 337 this, SLOT(pitchPanChanged(int)));
matthiasm@366 338 connect(m_panPitch, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
matthiasm@366 339 connect(m_panPitch, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
matthiasm@366 340
matthiasm@366 341 m_panNotes = new AudioDial(frame);
matthiasm@366 342 m_panNotes->setMeterColor(Qt::darkGreen);
matthiasm@366 343 m_panNotes->setMinimum(-100);
matthiasm@366 344 m_panNotes->setMaximum(100);
matthiasm@366 345 m_panNotes->setValue(100);
matthiasm@366 346 m_panNotes->setDefaultValue(100);
matthiasm@366 347 m_panNotes->setFixedWidth(24);
matthiasm@366 348 m_panNotes->setFixedHeight(24);
matthiasm@366 349 m_panNotes->setNotchesVisible(true);
matthiasm@366 350 m_panNotes->setPageStep(10);
matthiasm@366 351 m_panNotes->setObjectName(tr("Note Pan"));
matthiasm@366 352 m_panNotes->setRangeMapper(new LinearRangeMapper(-100, 100, -100, 100, tr("")));
matthiasm@366 353 m_panNotes->setShowToolTip(true);
matthiasm@366 354 connect(m_panNotes, SIGNAL(valueChanged(int)),
matthiasm@366 355 this, SLOT(notesPanChanged(int)));
matthiasm@366 356 connect(m_panNotes, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
matthiasm@366 357 connect(m_panNotes, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
matthiasm@366 358 }
matthiasm@366 359
justin@160 360 // End of Pan controls
justin@160 361
Chris@0 362 layout->setSpacing(4);
Chris@6 363 layout->addWidget(m_overview, 0, 1);
Chris@6 364 layout->addWidget(scroll, 1, 1);
Chris@0 365
Chris@0 366 layout->setColumnStretch(1, 10);
Chris@0 367
Chris@0 368 frame->setLayout(layout);
Chris@0 369
gyorgyf@21 370 m_analyser = new Analyser();
Chris@128 371 connect(m_analyser, SIGNAL(layersChanged()),
Chris@128 372 this, SLOT(updateLayerStatuses()));
Chris@187 373 connect(m_analyser, SIGNAL(layersChanged()),
Chris@187 374 this, SLOT(updateMenuStates()));
gyorgyf@21 375
Chris@0 376 setupMenus();
Chris@0 377 setupToolbars();
Chris@0 378 setupHelpMenu();
Chris@0 379
Chris@0 380 statusBar();
Chris@0 381
Chris@288 382 finaliseMenus();
Chris@288 383
Chris@244 384 connect(m_viewManager, SIGNAL(activity(QString)),
Chris@244 385 m_activityLog, SLOT(activityHappened(QString)));
Chris@244 386 connect(m_playSource, SIGNAL(activity(QString)),
Chris@244 387 m_activityLog, SLOT(activityHappened(QString)));
Chris@244 388 connect(CommandHistory::getInstance(), SIGNAL(activity(QString)),
Chris@244 389 m_activityLog, SLOT(activityHappened(QString)));
Chris@244 390 connect(this, SIGNAL(activity(QString)),
Chris@244 391 m_activityLog, SLOT(activityHappened(QString)));
Chris@244 392 connect(this, SIGNAL(replacedDocument()), this, SLOT(documentReplaced()));
Chris@260 393 connect(this, SIGNAL(sessionLoaded()), this, SLOT(analyseNewMainModel()));
Chris@260 394 connect(this, SIGNAL(audioFileLoaded()), this, SLOT(analyseNewMainModel()));
Chris@244 395 m_activityLog->hide();
Chris@244 396
Chris@95 397 newSession();
Chris@6 398
Chris@95 399 settings.beginGroup("MainWindow");
Chris@95 400 settings.setValue("zoom-default", 512);
Chris@95 401 settings.endGroup();
Chris@95 402 zoomDefault();
Chris@95 403
Chris@95 404 NetworkPermissionTester tester;
Chris@95 405 bool networkPermission = tester.havePermission();
Chris@95 406 if (networkPermission) {
Chris@95 407 m_versionTester = new VersionTester
Chris@95 408 ("sonicvisualiser.org", "latest-tony-version.txt", TONY_VERSION);
Chris@95 409 connect(m_versionTester, SIGNAL(newerVersionAvailable(QString)),
Chris@95 410 this, SLOT(newerVersionAvailable(QString)));
Chris@95 411 } else {
Chris@95 412 m_versionTester = 0;
Chris@95 413 }
Chris@0 414 }
Chris@0 415
Chris@0 416 MainWindow::~MainWindow()
Chris@0 417 {
Chris@6 418 delete m_analyser;
Chris@0 419 delete m_keyReference;
Chris@0 420 Profiles::getInstance()->dump();
Chris@0 421 }
Chris@0 422
Chris@0 423 void
Chris@0 424 MainWindow::setupMenus()
Chris@0 425 {
Chris@0 426 if (!m_mainMenusCreated) {
Chris@0 427 m_rightButtonMenu = new QMenu();
Chris@0 428 }
Chris@0 429
Chris@0 430 if (!m_mainMenusCreated) {
Chris@0 431 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
Chris@0 432 m_rightButtonMenu->addSeparator();
Chris@0 433 }
Chris@0 434
Chris@0 435 setupFileMenu();
Chris@0 436 setupEditMenu();
Chris@0 437 setupViewMenu();
matthiasm@317 438 setupAnalysisMenu();
Chris@0 439
Chris@0 440 m_mainMenusCreated = true;
Chris@0 441 }
Chris@0 442
Chris@0 443 void
Chris@0 444 MainWindow::setupFileMenu()
Chris@0 445 {
Chris@0 446 if (m_mainMenusCreated) return;
Chris@0 447
Chris@0 448 QMenu *menu = menuBar()->addMenu(tr("&File"));
Chris@0 449 menu->setTearOffEnabled(true);
Chris@0 450 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
Chris@0 451
Chris@0 452 m_keyReference->setCategory(tr("File and Session Management"));
Chris@0 453
Chris@0 454 IconLoader il;
Chris@1 455 QIcon icon;
Chris@1 456 QAction *action;
Chris@0 457
Chris@0 458 icon = il.load("fileopen");
Chris@0 459 icon.addPixmap(il.loadPixmap("fileopen-22"));
Chris@1 460 action = new QAction(icon, tr("&Open..."), this);
Chris@0 461 action->setShortcut(tr("Ctrl+O"));
Chris@257 462 action->setStatusTip(tr("Open a session or audio file"));
Chris@0 463 connect(action, SIGNAL(triggered()), this, SLOT(openFile()));
Chris@0 464 m_keyReference->registerShortcut(action);
Chris@0 465 menu->addAction(action);
Chris@0 466 toolbar->addAction(action);
Chris@0 467
Chris@1 468 action = new QAction(tr("Open Lo&cation..."), this);
Chris@0 469 action->setShortcut(tr("Ctrl+Shift+O"));
Chris@1 470 action->setStatusTip(tr("Open a file from a remote URL"));
Chris@0 471 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
Chris@0 472 m_keyReference->registerShortcut(action);
Chris@0 473 menu->addAction(action);
Chris@0 474
Chris@1 475 m_recentFilesMenu = menu->addMenu(tr("Open &Recent"));
Chris@0 476 m_recentFilesMenu->setTearOffEnabled(true);
Chris@0 477 setupRecentFilesMenu();
Chris@0 478 connect(&m_recentFiles, SIGNAL(recentChanged()),
Chris@0 479 this, SLOT(setupRecentFilesMenu()));
Chris@0 480
Chris@0 481 menu->addSeparator();
Chris@257 482
Chris@257 483 icon = il.load("filesave");
Chris@257 484 icon.addPixmap(il.loadPixmap("filesave-22"));
Chris@257 485 action = new QAction(icon, tr("&Save Session"), this);
Chris@257 486 action->setShortcut(tr("Ctrl+S"));
Chris@257 487 action->setStatusTip(tr("Save the current session into a %1 session file").arg(QApplication::applicationName()));
Chris@257 488 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
Chris@257 489 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
Chris@257 490 m_keyReference->registerShortcut(action);
Chris@257 491 menu->addAction(action);
Chris@257 492 toolbar->addAction(action);
Chris@257 493
Chris@257 494 icon = il.load("filesaveas");
Chris@257 495 icon.addPixmap(il.loadPixmap("filesaveas-22"));
Chris@257 496 action = new QAction(icon, tr("Save Session &As..."), this);
Chris@257 497 action->setShortcut(tr("Ctrl+Shift+S"));
Chris@257 498 action->setStatusTip(tr("Save the current session into a new %1 session file").arg(QApplication::applicationName()));
Chris@257 499 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
Chris@313 500 connect(this, SIGNAL(canSaveAs(bool)), action, SLOT(setEnabled(bool)));
Chris@257 501 menu->addAction(action);
Chris@257 502 toolbar->addAction(action);
Chris@257 503
matthiasm@319 504 action = new QAction(tr("Save Session to Audio &Path"), this);
matthiasm@310 505 action->setShortcut(tr("Ctrl+Alt+S"));
Chris@313 506 action->setStatusTip(tr("Save the current session into a %1 session file with the same filename as the audio but a .ton extension.").arg(QApplication::applicationName()));
matthiasm@310 507 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionInAudioPath()));
Chris@313 508 connect(this, SIGNAL(canSaveAs(bool)), action, SLOT(setEnabled(bool)));
matthiasm@310 509 menu->addAction(action);
matthiasm@310 510
Chris@257 511 menu->addSeparator();
Chris@257 512
Chris@253 513 action = new QAction(tr("I&mport Pitch Track Data..."), this);
Chris@253 514 action->setStatusTip(tr("Import pitch-track data from a CSV, RDF, or layer XML file"));
Chris@174 515 connect(action, SIGNAL(triggered()), this, SLOT(importPitchLayer()));
Chris@174 516 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@174 517 menu->addAction(action);
Chris@174 518
Chris@253 519 action = new QAction(tr("E&xport Pitch Track Data..."), this);
Chris@253 520 action->setStatusTip(tr("Export pitch-track data to a CSV, RDF, or layer XML file"));
Chris@85 521 connect(action, SIGNAL(triggered()), this, SLOT(exportPitchLayer()));
Chris@224 522 connect(this, SIGNAL(canExportPitchTrack(bool)), action, SLOT(setEnabled(bool)));
Chris@85 523 menu->addAction(action);
Chris@85 524
Chris@253 525 action = new QAction(tr("&Export Note Data..."), this);
Chris@253 526 action->setStatusTip(tr("Export note data to a CSV, RDF, layer XML, or MIDI file"));
Chris@85 527 connect(action, SIGNAL(triggered()), this, SLOT(exportNoteLayer()));
Chris@224 528 connect(this, SIGNAL(canExportNotes(bool)), action, SLOT(setEnabled(bool)));
matthiasm@26 529 menu->addAction(action);
matthiasm@26 530
matthiasm@26 531 menu->addSeparator();
Chris@0 532 action = new QAction(il.load("exit"), tr("&Quit"), this);
Chris@0 533 action->setShortcut(tr("Ctrl+Q"));
Chris@0 534 action->setStatusTip(tr("Exit %1").arg(QApplication::applicationName()));
Chris@0 535 connect(action, SIGNAL(triggered()), this, SLOT(close()));
Chris@0 536 m_keyReference->registerShortcut(action);
Chris@0 537 menu->addAction(action);
Chris@0 538 }
Chris@0 539
Chris@0 540 void
Chris@0 541 MainWindow::setupEditMenu()
Chris@0 542 {
Chris@0 543 if (m_mainMenusCreated) return;
Chris@0 544
Chris@0 545 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
Chris@0 546 menu->setTearOffEnabled(true);
Chris@0 547 CommandHistory::getInstance()->registerMenu(menu);
Chris@126 548 menu->addSeparator();
Chris@126 549
Chris@254 550 m_keyReference->setCategory
Chris@254 551 (tr("Selection Strip Mouse Actions"));
Chris@254 552 m_keyReference->registerShortcut
Chris@254 553 (tr("Jump"), tr("Left"),
Chris@254 554 tr("Click left button to move the playback position to a time"));
Chris@254 555 m_keyReference->registerShortcut
Chris@254 556 (tr("Select"), tr("Left"),
Chris@254 557 tr("Click left button and drag to select a region of time"));
Chris@254 558 m_keyReference->registerShortcut
Chris@254 559 (tr("Select Note Duration"), tr("Double-Click Left"),
Chris@254 560 tr("Double-click left button to select the region of time corresponding to a note"));
Chris@254 561
Chris@126 562 QToolBar *toolbar = addToolBar(tr("Tools Toolbar"));
Chris@126 563
Chris@126 564 CommandHistory::getInstance()->registerToolbar(toolbar);
Chris@126 565
Chris@250 566 QActionGroup *group = new QActionGroup(this);
Chris@250 567
Chris@250 568 IconLoader il;
Chris@250 569
Chris@126 570 m_keyReference->setCategory(tr("Tool Selection"));
Chris@126 571 QAction *action = toolbar->addAction(il.load("navigate"),
Chris@126 572 tr("Navigate"));
Chris@126 573 action->setCheckable(true);
Chris@126 574 action->setChecked(true);
Chris@126 575 action->setShortcut(tr("1"));
Chris@126 576 action->setStatusTip(tr("Navigate"));
Chris@126 577 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
Chris@126 578 connect(this, SIGNAL(replacedDocument()), action, SLOT(trigger()));
Chris@126 579 group->addAction(action);
Chris@126 580 menu->addAction(action);
Chris@126 581 m_keyReference->registerShortcut(action);
Chris@126 582
Chris@250 583 m_keyReference->setCategory
Chris@250 584 (tr("Navigate Tool Mouse Actions"));
Chris@250 585 m_keyReference->registerShortcut
Chris@250 586 (tr("Navigate"), tr("Left"),
Chris@250 587 tr("Click left button and drag to move around"));
Chris@250 588 m_keyReference->registerShortcut
Chris@250 589 (tr("Re-Analyse Area"), tr("Shift+Left"),
Chris@250 590 tr("Shift-click left button and drag to define a specific pitch and time range to re-analyse"));
Chris@250 591 m_keyReference->registerShortcut
Chris@250 592 (tr("Edit"), tr("Double-Click Left"),
Chris@250 593 tr("Double-click left button on an item to edit it"));
Chris@250 594
Chris@250 595 m_keyReference->setCategory(tr("Tool Selection"));
Chris@126 596 action = toolbar->addAction(il.load("move"),
Chris@126 597 tr("Edit"));
Chris@126 598 action->setCheckable(true);
Chris@126 599 action->setShortcut(tr("2"));
Chris@126 600 action->setStatusTip(tr("Edit with Note Intelligence"));
Chris@126 601 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
Chris@126 602 group->addAction(action);
Chris@126 603 menu->addAction(action);
Chris@126 604 m_keyReference->registerShortcut(action);
Chris@126 605
Chris@250 606 m_keyReference->setCategory
Chris@250 607 (tr("Note Edit Tool Mouse Actions"));
Chris@250 608 m_keyReference->registerShortcut
Chris@250 609 (tr("Adjust Pitch"), tr("Left"),
Chris@250 610 tr("Click left button on the main part of a note and drag to move it up or down"));
Chris@250 611 m_keyReference->registerShortcut
Chris@250 612 (tr("Split"), tr("Left"),
Chris@250 613 tr("Click left button on the bottom edge of a note to split it at the click point"));
Chris@250 614 m_keyReference->registerShortcut
Chris@250 615 (tr("Resize"), tr("Left"),
Chris@250 616 tr("Click left button on the left or right edge of a note and drag to change the time or duration of the note"));
Chris@250 617 m_keyReference->registerShortcut
Chris@250 618 (tr("Erase"), tr("Shift+Left"),
Chris@250 619 tr("Shift-click left button on a note to remove it"));
Chris@250 620
Chris@250 621
Chris@126 622 /* Remove for now...
Chris@126 623
Chris@250 624 m_keyReference->setCategory(tr("Tool Selection"));
Chris@126 625 action = toolbar->addAction(il.load("notes"),
Chris@126 626 tr("Free Edit"));
Chris@126 627 action->setCheckable(true);
Chris@126 628 action->setShortcut(tr("3"));
Chris@126 629 action->setStatusTip(tr("Free Edit"));
Chris@126 630 connect(action, SIGNAL(triggered()), this, SLOT(toolFreeEditSelected()));
Chris@126 631 group->addAction(action);
Chris@126 632 m_keyReference->registerShortcut(action);
Chris@126 633 */
Chris@142 634
Chris@142 635 menu->addSeparator();
Chris@142 636
Chris@143 637 m_keyReference->setCategory(tr("Selection"));
Chris@143 638
Chris@143 639 action = new QAction(tr("Select &All"), this);
Chris@143 640 action->setShortcut(tr("Ctrl+A"));
Chris@143 641 action->setStatusTip(tr("Select the whole duration of the current session"));
Chris@143 642 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
Chris@143 643 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@143 644 m_keyReference->registerShortcut(action);
Chris@143 645 menu->addAction(action);
Chris@143 646 m_rightButtonMenu->addAction(action);
Chris@143 647
Chris@287 648 action = new QAction(tr("C&lear Selection"), this);
Chris@211 649 action->setShortcuts(QList<QKeySequence>()
Chris@211 650 << QKeySequence(tr("Esc"))
Chris@211 651 << QKeySequence(tr("Ctrl+Esc")));
Chris@211 652 action->setStatusTip(tr("Clear the selection and abandon any pending pitch choices in it"));
Chris@194 653 connect(action, SIGNAL(triggered()), this, SLOT(abandonSelection()));
Chris@143 654 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@143 655 m_keyReference->registerShortcut(action);
Chris@211 656 m_keyReference->registerAlternativeShortcut(action, QKeySequence(tr("Ctrl+Esc")));
Chris@143 657 menu->addAction(action);
Chris@143 658 m_rightButtonMenu->addAction(action);
Chris@143 659
Chris@143 660 menu->addSeparator();
Chris@189 661 m_rightButtonMenu->addSeparator();
Chris@143 662
Chris@189 663 m_keyReference->setCategory(tr("Pitch Track"));
Chris@211 664
Chris@211 665 action = new QAction(tr("Choose Higher Pitch"), this);
Chris@211 666 action->setShortcut(tr("Ctrl+Up"));
Chris@211 667 action->setStatusTip(tr("Move pitches up an octave, or to the next higher pitch candidate"));
Chris@211 668 m_keyReference->registerShortcut(action);
Chris@211 669 connect(action, SIGNAL(triggered()), this, SLOT(switchPitchUp()));
Chris@211 670 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@211 671 menu->addAction(action);
Chris@211 672 m_rightButtonMenu->addAction(action);
Chris@211 673
Chris@211 674 action = new QAction(tr("Choose Lower Pitch"), this);
Chris@211 675 action->setShortcut(tr("Ctrl+Down"));
Chris@211 676 action->setStatusTip(tr("Move pitches down an octave, or to the next lower pitch candidate"));
Chris@211 677 m_keyReference->registerShortcut(action);
Chris@211 678 connect(action, SIGNAL(triggered()), this, SLOT(switchPitchDown()));
Chris@211 679 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@211 680 menu->addAction(action);
Chris@211 681 m_rightButtonMenu->addAction(action);
Chris@189 682
Chris@187 683 m_showCandidatesAction = new QAction(tr("Show Pitch Candidates"), this);
Chris@187 684 m_showCandidatesAction->setShortcut(tr("Ctrl+Return"));
Chris@189 685 m_showCandidatesAction->setStatusTip(tr("Toggle the display of alternative pitch candidates for the selected region"));
Chris@189 686 m_keyReference->registerShortcut(m_showCandidatesAction);
Chris@187 687 connect(m_showCandidatesAction, SIGNAL(triggered()), this, SLOT(togglePitchCandidates()));
Chris@187 688 connect(this, SIGNAL(canClearSelection(bool)), m_showCandidatesAction, SLOT(setEnabled(bool)));
Chris@187 689 menu->addAction(m_showCandidatesAction);
Chris@189 690 m_rightButtonMenu->addAction(m_showCandidatesAction);
Chris@187 691
Chris@287 692 action = new QAction(tr("Remove Pitches"), this);
matthiasm@327 693 action->setShortcut(tr("Ctrl+Backspace"));
Chris@211 694 action->setStatusTip(tr("Remove all pitch estimates within the selected region, making it unvoiced"));
Chris@189 695 m_keyReference->registerShortcut(action);
Chris@187 696 connect(action, SIGNAL(triggered()), this, SLOT(clearPitches()));
Chris@167 697 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@167 698 menu->addAction(action);
Chris@189 699 m_rightButtonMenu->addAction(action);
Chris@237 700
Chris@237 701 menu->addSeparator();
Chris@237 702 m_rightButtonMenu->addSeparator();
Chris@237 703
matthiasm@327 704 m_keyReference->setCategory(tr("Note Track"));
matthiasm@327 705
Chris@287 706 action = new QAction(tr("Split Note"), this);
matthiasm@327 707 action->setShortcut(tr("/"));
Chris@240 708 action->setStatusTip(tr("Split the note at the current playback position into two"));
Chris@237 709 m_keyReference->registerShortcut(action);
Chris@240 710 connect(action, SIGNAL(triggered()), this, SLOT(splitNote()));
Chris@240 711 connect(this, SIGNAL(canExportNotes(bool)), action, SLOT(setEnabled(bool)));
Chris@237 712 menu->addAction(action);
Chris@237 713 m_rightButtonMenu->addAction(action);
Chris@238 714
Chris@287 715 action = new QAction(tr("Merge Notes"), this);
matthiasm@327 716 action->setShortcut(tr("\\"));
Chris@238 717 action->setStatusTip(tr("Merge all notes within the selected region into a single note"));
Chris@238 718 m_keyReference->registerShortcut(action);
Chris@238 719 connect(action, SIGNAL(triggered()), this, SLOT(mergeNotes()));
Chris@238 720 connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
Chris@238 721 menu->addAction(action);
Chris@238 722 m_rightButtonMenu->addAction(action);
matthiasm@292 723
matthiasm@292 724 action = new QAction(tr("Delete Notes"), this);
matthiasm@327 725 action->setShortcut(tr("Backspace"));
matthiasm@327 726 action->setStatusTip(tr("Delete all notes within the selected region"));
matthiasm@292 727 m_keyReference->registerShortcut(action);
matthiasm@292 728 connect(action, SIGNAL(triggered()), this, SLOT(deleteNotes()));
matthiasm@292 729 connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
matthiasm@292 730 menu->addAction(action);
matthiasm@292 731 m_rightButtonMenu->addAction(action);
Chris@238 732
Chris@240 733 action = new QAction(tr("Form Note from Selection"), this);
matthiasm@327 734 action->setShortcut(tr("="));
Chris@240 735 action->setStatusTip(tr("Form a note spanning the selected region, splitting any existing notes at its boundaries"));
Chris@240 736 m_keyReference->registerShortcut(action);
Chris@240 737 connect(action, SIGNAL(triggered()), this, SLOT(formNoteFromSelection()));
Chris@240 738 connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
Chris@240 739 menu->addAction(action);
Chris@240 740 m_rightButtonMenu->addAction(action);
Chris@247 741
Chris@238 742 action = new QAction(tr("Snap Notes to Pitch Track"), this);
Chris@238 743 action->setStatusTip(tr("Set notes within the selected region to the median frequency of their underlying pitches, or remove them if there are no underlying pitches"));
matthiasm@327 744 // m_keyReference->registerShortcut(action);
Chris@238 745 connect(action, SIGNAL(triggered()), this, SLOT(snapNotesToPitches()));
Chris@238 746 connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
Chris@238 747 menu->addAction(action);
Chris@238 748 m_rightButtonMenu->addAction(action);
Chris@0 749 }
Chris@0 750
Chris@0 751 void
Chris@0 752 MainWindow::setupViewMenu()
Chris@0 753 {
Chris@0 754 if (m_mainMenusCreated) return;
Chris@0 755
Chris@0 756 IconLoader il;
Chris@0 757
Chris@0 758 QAction *action = 0;
Chris@0 759
Chris@0 760 m_keyReference->setCategory(tr("Panning and Navigation"));
Chris@0 761
Chris@0 762 QMenu *menu = menuBar()->addMenu(tr("&View"));
Chris@0 763 menu->setTearOffEnabled(true);
Chris@300 764 action = new QAction(tr("Peek &Left"), this);
Chris@300 765 action->setShortcut(tr("Alt+Left"));
Chris@300 766 action->setStatusTip(tr("Scroll the current pane to the left without changing the play position"));
Chris@0 767 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
Chris@0 768 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 769 m_keyReference->registerShortcut(action);
Chris@0 770 menu->addAction(action);
gyorgyf@27 771
Chris@300 772 action = new QAction(tr("Peek &Right"), this);
Chris@300 773 action->setShortcut(tr("Alt+Right"));
Chris@300 774 action->setStatusTip(tr("Scroll the current pane to the right without changing the play position"));
Chris@0 775 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
Chris@0 776 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 777 m_keyReference->registerShortcut(action);
Chris@0 778 menu->addAction(action);
matthiasm@283 779
Chris@0 780 menu->addSeparator();
Chris@0 781
Chris@0 782 m_keyReference->setCategory(tr("Zoom"));
Chris@0 783
Chris@0 784 action = new QAction(il.load("zoom-in"),
Chris@0 785 tr("Zoom &In"), this);
Chris@0 786 action->setShortcut(tr("Up"));
Chris@0 787 action->setStatusTip(tr("Increase the zoom level"));
Chris@0 788 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
Chris@0 789 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 790 m_keyReference->registerShortcut(action);
Chris@0 791 menu->addAction(action);
gyorgyf@27 792
Chris@0 793 action = new QAction(il.load("zoom-out"),
Chris@0 794 tr("Zoom &Out"), this);
Chris@0 795 action->setShortcut(tr("Down"));
Chris@0 796 action->setStatusTip(tr("Decrease the zoom level"));
Chris@0 797 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
Chris@0 798 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 799 m_keyReference->registerShortcut(action);
Chris@0 800 menu->addAction(action);
gyorgyf@27 801
Chris@0 802 action = new QAction(tr("Restore &Default Zoom"), this);
Chris@0 803 action->setStatusTip(tr("Restore the zoom level to the default"));
Chris@0 804 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
Chris@0 805 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 806 menu->addAction(action);
Chris@0 807
Chris@0 808 action = new QAction(il.load("zoom-fit"),
Chris@0 809 tr("Zoom to &Fit"), this);
Chris@0 810 action->setShortcut(tr("F"));
Chris@0 811 action->setStatusTip(tr("Zoom to show the whole file"));
Chris@0 812 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
Chris@0 813 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 814 m_keyReference->registerShortcut(action);
Chris@0 815 menu->addAction(action);
Chris@227 816
Chris@227 817 menu->addSeparator();
Chris@227 818
Chris@227 819 action = new QAction(tr("Set Displayed Fre&quency Range..."), this);
Chris@227 820 action->setStatusTip(tr("Set the minimum and maximum frequencies in the visible display"));
Chris@227 821 connect(action, SIGNAL(triggered()), this, SLOT(editDisplayExtents()));
Chris@227 822 menu->addAction(action);
Chris@0 823 }
Chris@0 824
Chris@0 825 void
matthiasm@317 826 MainWindow::setupAnalysisMenu()
matthiasm@317 827 {
matthiasm@317 828 if (m_mainMenusCreated) return;
matthiasm@317 829
matthiasm@317 830 IconLoader il;
matthiasm@317 831
matthiasm@317 832 QAction *action = 0;
matthiasm@317 833
matthiasm@317 834 QMenu *menu = menuBar()->addMenu(tr("&Analysis"));
matthiasm@317 835 menu->setTearOffEnabled(true);
matthiasm@317 836
matthiasm@333 837
matthiasm@333 838 action = new QAction(tr("&Analyse now!"), this);
matthiasm@333 839 action->setStatusTip(tr("Trigger analysis of pitches and notes. (This will delete all existing pitches and notes.)"));
Chris@323 840 connect(action, SIGNAL(triggered()), this, SLOT(analyseNow()));
matthiasm@317 841 menu->addAction(action);
matthiasm@317 842 m_keyReference->registerShortcut(action);
matthiasm@317 843
matthiasm@317 844 menu->addSeparator();
matthiasm@317 845
Chris@323 846 QSettings settings;
Chris@323 847 settings.beginGroup("Analyser");
Chris@323 848 bool autoAnalyse = settings.value("auto-analysis", true).toBool();
Chris@323 849 bool precise = settings.value("precision-analysis", false).toBool();
matthiasm@345 850 bool lowamp = settings.value("lowamp-analysis", true).toBool();
Chris@323 851 settings.endGroup();
Chris@323 852
matthiasm@333 853 action = new QAction(tr("Auto-Analyse &New Audio"), this);
matthiasm@333 854 action->setStatusTip(tr("Automatically trigger analysis upon opening of a new audio file."));
matthiasm@317 855 action->setCheckable(true);
Chris@323 856 action->setChecked(autoAnalyse);
Chris@323 857 connect(action, SIGNAL(triggered()), this, SLOT(autoAnalysisToggled()));
matthiasm@317 858 menu->addAction(action);
matthiasm@317 859
matthiasm@333 860 action = new QAction(tr("&Unbiased Timing (slow)"), this);
matthiasm@333 861 action->setStatusTip(tr("Use a symmetric window in YIN to remove frequency-dependent timing bias. (This is slow!)"));
matthiasm@317 862 action->setCheckable(true);
Chris@323 863 action->setChecked(precise);
Chris@323 864 connect(action, SIGNAL(triggered()), this, SLOT(precisionAnalysisToggled()));
matthiasm@317 865 menu->addAction(action);
matthiasm@345 866
matthiasm@348 867 action = new QAction(tr("&Penalise Soft Pitches"), this);
matthiasm@345 868 action->setStatusTip(tr("Reduce the likelihood of detecting a pitch when the signal has low amplitude."));
matthiasm@345 869 action->setCheckable(true);
matthiasm@345 870 action->setChecked(lowamp);
matthiasm@345 871 connect(action, SIGNAL(triggered()), this, SLOT(lowampAnalysisToggled()));
matthiasm@345 872 menu->addAction(action);
matthiasm@345 873
Chris@323 874 }
Chris@323 875
Chris@323 876 void
Chris@323 877 MainWindow::autoAnalysisToggled()
Chris@323 878 {
Chris@323 879 QAction *a = qobject_cast<QAction *>(sender());
Chris@323 880 if (!a) return;
Chris@323 881
Chris@323 882 bool set = a->isChecked();
Chris@323 883
Chris@323 884 QSettings settings;
Chris@323 885 settings.beginGroup("Analyser");
Chris@323 886 settings.setValue("auto-analysis", set);
Chris@323 887 settings.endGroup();
Chris@323 888 }
Chris@323 889
Chris@323 890 void
Chris@323 891 MainWindow::precisionAnalysisToggled()
Chris@323 892 {
Chris@323 893 QAction *a = qobject_cast<QAction *>(sender());
Chris@323 894 if (!a) return;
Chris@323 895
Chris@323 896 bool set = a->isChecked();
Chris@323 897
Chris@323 898 QSettings settings;
Chris@323 899 settings.beginGroup("Analyser");
Chris@323 900 settings.setValue("precision-analysis", set);
Chris@323 901 settings.endGroup();
Chris@323 902
Chris@326 903 // don't run analyseNow() automatically -- it's a destructive operation
matthiasm@317 904 }
matthiasm@317 905
matthiasm@317 906 void
matthiasm@345 907 MainWindow::lowampAnalysisToggled()
matthiasm@345 908 {
matthiasm@345 909 QAction *a = qobject_cast<QAction *>(sender());
matthiasm@345 910 if (!a) return;
matthiasm@345 911
matthiasm@345 912 bool set = a->isChecked();
matthiasm@345 913
matthiasm@345 914 QSettings settings;
matthiasm@345 915 settings.beginGroup("Analyser");
matthiasm@345 916 settings.setValue("lowamp-analysis", set);
matthiasm@345 917 settings.endGroup();
matthiasm@345 918
matthiasm@345 919 // don't run analyseNow() automatically -- it's a destructive operation
matthiasm@345 920 }
matthiasm@345 921
matthiasm@345 922 void
Chris@0 923 MainWindow::setupHelpMenu()
Chris@0 924 {
Chris@0 925 QMenu *menu = menuBar()->addMenu(tr("&Help"));
Chris@0 926 menu->setTearOffEnabled(true);
Chris@0 927
Chris@0 928 m_keyReference->setCategory(tr("Help"));
Chris@0 929
Chris@0 930 IconLoader il;
Chris@0 931
Chris@1 932 QString name = QApplication::applicationName();
matthiasm@367 933 QAction *action;
matthiasm@367 934
matthiasm@367 935 // action = new QAction(il.load("help"),
matthiasm@367 936 // tr("&Help Reference"), this);
matthiasm@367 937 // action->setShortcut(tr("F1"));
matthiasm@367 938 // action->setStatusTip(tr("Open the %1 reference manual").arg(name));
matthiasm@367 939 // connect(action, SIGNAL(triggered()), this, SLOT(help()));
matthiasm@367 940 // m_keyReference->registerShortcut(action);
matthiasm@367 941 // menu->addAction(action);
Chris@0 942
Chris@0 943 action = new QAction(tr("&Key and Mouse Reference"), this);
Chris@0 944 action->setShortcut(tr("F2"));
Chris@1 945 action->setStatusTip(tr("Open a window showing the keystrokes you can use in %1").arg(name));
Chris@0 946 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
Chris@0 947 m_keyReference->registerShortcut(action);
Chris@0 948 menu->addAction(action);
Chris@0 949
Chris@1 950 action = new QAction(tr("%1 on the &Web").arg(name), this);
Chris@1 951 action->setStatusTip(tr("Open the %1 website").arg(name));
Chris@0 952 connect(action, SIGNAL(triggered()), this, SLOT(website()));
Chris@0 953 menu->addAction(action);
Chris@0 954
Chris@1 955 action = new QAction(tr("&About %1").arg(name), this);
Chris@1 956 action->setStatusTip(tr("Show information about %1").arg(name));
Chris@0 957 connect(action, SIGNAL(triggered()), this, SLOT(about()));
Chris@0 958 menu->addAction(action);
Chris@0 959 }
Chris@0 960
Chris@0 961 void
Chris@0 962 MainWindow::setupRecentFilesMenu()
Chris@0 963 {
Chris@0 964 m_recentFilesMenu->clear();
Chris@0 965 vector<QString> files = m_recentFiles.getRecent();
Chris@0 966 for (size_t i = 0; i < files.size(); ++i) {
Chris@50 967 QAction *action = new QAction(files[i], this);
Chris@50 968 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
Chris@0 969 if (i == 0) {
Chris@0 970 action->setShortcut(tr("Ctrl+R"));
Chris@0 971 m_keyReference->registerShortcut
Chris@0 972 (tr("Re-open"),
Chris@50 973 action->shortcut().toString(),
Chris@0 974 tr("Re-open the current or most recently opened file"));
Chris@0 975 }
Chris@50 976 m_recentFilesMenu->addAction(action);
Chris@0 977 }
Chris@0 978 }
Chris@0 979
Chris@0 980 void
Chris@0 981 MainWindow::setupToolbars()
Chris@0 982 {
Chris@0 983 m_keyReference->setCategory(tr("Playback and Transport Controls"));
Chris@0 984
Chris@0 985 IconLoader il;
Chris@0 986
Chris@0 987 QMenu *menu = m_playbackMenu = menuBar()->addMenu(tr("Play&back"));
Chris@0 988 menu->setTearOffEnabled(true);
Chris@0 989 m_rightButtonMenu->addSeparator();
Chris@0 990 m_rightButtonPlaybackMenu = m_rightButtonMenu->addMenu(tr("Playback"));
Chris@0 991
Chris@0 992 QToolBar *toolbar = addToolBar(tr("Playback Toolbar"));
Chris@0 993
Chris@0 994 QAction *rwdStartAction = toolbar->addAction(il.load("rewind-start"),
Chris@0 995 tr("Rewind to Start"));
Chris@0 996 rwdStartAction->setShortcut(tr("Home"));
Chris@0 997 rwdStartAction->setStatusTip(tr("Rewind to the start"));
Chris@0 998 connect(rwdStartAction, SIGNAL(triggered()), this, SLOT(rewindStart()));
Chris@0 999 connect(this, SIGNAL(canPlay(bool)), rwdStartAction, SLOT(setEnabled(bool)));
Chris@0 1000
Chris@0 1001 QAction *m_rwdAction = toolbar->addAction(il.load("rewind"),
Chris@0 1002 tr("Rewind"));
Chris@300 1003 m_rwdAction->setShortcut(tr("Left"));
Chris@300 1004 m_rwdAction->setStatusTip(tr("Rewind to the previous one-second boundary"));
Chris@0 1005 connect(m_rwdAction, SIGNAL(triggered()), this, SLOT(rewind()));
Chris@0 1006 connect(this, SIGNAL(canRewind(bool)), m_rwdAction, SLOT(setEnabled(bool)));
Chris@0 1007
Chris@300 1008 setDefaultFfwdRwdStep(RealTime(1, 0));
Chris@300 1009
Chris@0 1010 QAction *playAction = toolbar->addAction(il.load("playpause"),
Chris@0 1011 tr("Play / Pause"));
Chris@0 1012 playAction->setCheckable(true);
Chris@0 1013 playAction->setShortcut(tr("Space"));
Chris@0 1014 playAction->setStatusTip(tr("Start or stop playback from the current position"));
Chris@0 1015 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 1016 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
gyorgyf@27 1017 playAction, SLOT(setChecked(bool)));
Chris@0 1018 connect(this, SIGNAL(canPlay(bool)), playAction, SLOT(setEnabled(bool)));
Chris@0 1019
Chris@0 1020 m_ffwdAction = toolbar->addAction(il.load("ffwd"),
Chris@0 1021 tr("Fast Forward"));
Chris@300 1022 m_ffwdAction->setShortcut(tr("Right"));
Chris@300 1023 m_ffwdAction->setStatusTip(tr("Fast-forward to the next one-second boundary"));
Chris@0 1024 connect(m_ffwdAction, SIGNAL(triggered()), this, SLOT(ffwd()));
Chris@0 1025 connect(this, SIGNAL(canFfwd(bool)), m_ffwdAction, SLOT(setEnabled(bool)));
Chris@0 1026
Chris@0 1027 QAction *ffwdEndAction = toolbar->addAction(il.load("ffwd-end"),
Chris@0 1028 tr("Fast Forward to End"));
Chris@0 1029 ffwdEndAction->setShortcut(tr("End"));
Chris@0 1030 ffwdEndAction->setStatusTip(tr("Fast-forward to the end"));
Chris@0 1031 connect(ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
Chris@0 1032 connect(this, SIGNAL(canPlay(bool)), ffwdEndAction, SLOT(setEnabled(bool)));
Chris@6 1033
Chris@0 1034 toolbar = addToolBar(tr("Play Mode Toolbar"));
Chris@0 1035
Chris@0 1036 QAction *psAction = toolbar->addAction(il.load("playselection"),
Chris@0 1037 tr("Constrain Playback to Selection"));
Chris@0 1038 psAction->setCheckable(true);
Chris@0 1039 psAction->setChecked(m_viewManager->getPlaySelectionMode());
Chris@0 1040 psAction->setShortcut(tr("s"));
Chris@0 1041 psAction->setStatusTip(tr("Constrain playback to the selected regions"));
Chris@0 1042 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
Chris@0 1043 psAction, SLOT(setChecked(bool)));
Chris@0 1044 connect(psAction, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
Chris@0 1045 connect(this, SIGNAL(canPlaySelection(bool)), psAction, SLOT(setEnabled(bool)));
Chris@0 1046
Chris@0 1047 QAction *plAction = toolbar->addAction(il.load("playloop"),
Chris@0 1048 tr("Loop Playback"));
Chris@0 1049 plAction->setCheckable(true);
Chris@0 1050 plAction->setChecked(m_viewManager->getPlayLoopMode());
Chris@0 1051 plAction->setShortcut(tr("l"));
Chris@0 1052 plAction->setStatusTip(tr("Loop playback"));
Chris@0 1053 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
Chris@0 1054 plAction, SLOT(setChecked(bool)));
Chris@0 1055 connect(plAction, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
Chris@0 1056 connect(this, SIGNAL(canPlay(bool)), plAction, SLOT(setEnabled(bool)));
Chris@0 1057
Chris@300 1058 QAction *oneLeftAction = new QAction(tr("&One Note Left"), this);
Chris@300 1059 oneLeftAction->setShortcut(tr("Ctrl+Left"));
Chris@300 1060 oneLeftAction->setStatusTip(tr("Move cursor to the preceding note (or silence) onset."));
Chris@300 1061 connect(oneLeftAction, SIGNAL(triggered()), this, SLOT(moveOneNoteLeft()));
Chris@300 1062 connect(this, SIGNAL(canScroll(bool)), oneLeftAction, SLOT(setEnabled(bool)));
Chris@300 1063
Chris@300 1064 QAction *oneRightAction = new QAction(tr("O&ne Note Right"), this);
Chris@300 1065 oneRightAction->setShortcut(tr("Ctrl+Right"));
Chris@300 1066 oneRightAction->setStatusTip(tr("Move cursor to the succeeding note (or silence)."));
Chris@300 1067 connect(oneRightAction, SIGNAL(triggered()), this, SLOT(moveOneNoteRight()));
Chris@300 1068 connect(this, SIGNAL(canScroll(bool)), oneRightAction, SLOT(setEnabled(bool)));
Chris@300 1069
Chris@300 1070 QAction *selectOneLeftAction = new QAction(tr("&Select One Note Left"), this);
Chris@300 1071 selectOneLeftAction->setShortcut(tr("Ctrl+Shift+Left"));
Chris@300 1072 selectOneLeftAction->setStatusTip(tr("Select to the preceding note (or silence) onset."));
Chris@300 1073 connect(selectOneLeftAction, SIGNAL(triggered()), this, SLOT(selectOneNoteLeft()));
Chris@300 1074 connect(this, SIGNAL(canScroll(bool)), selectOneLeftAction, SLOT(setEnabled(bool)));
Chris@300 1075
Chris@300 1076 QAction *selectOneRightAction = new QAction(tr("S&elect One Note Right"), this);
Chris@300 1077 selectOneRightAction->setShortcut(tr("Ctrl+Shift+Right"));
Chris@300 1078 selectOneRightAction->setStatusTip(tr("Select to the succeeding note (or silence)."));
Chris@300 1079 connect(selectOneRightAction, SIGNAL(triggered()), this, SLOT(selectOneNoteRight()));
Chris@300 1080 connect(this, SIGNAL(canScroll(bool)), selectOneRightAction, SLOT(setEnabled(bool)));
Chris@300 1081
Chris@0 1082 m_keyReference->registerShortcut(psAction);
Chris@0 1083 m_keyReference->registerShortcut(plAction);
Chris@0 1084 m_keyReference->registerShortcut(playAction);
Chris@0 1085 m_keyReference->registerShortcut(m_rwdAction);
Chris@0 1086 m_keyReference->registerShortcut(m_ffwdAction);
Chris@0 1087 m_keyReference->registerShortcut(rwdStartAction);
Chris@0 1088 m_keyReference->registerShortcut(ffwdEndAction);
Chris@300 1089 m_keyReference->registerShortcut(oneLeftAction);
Chris@300 1090 m_keyReference->registerShortcut(oneRightAction);
Chris@300 1091 m_keyReference->registerShortcut(selectOneLeftAction);
Chris@300 1092 m_keyReference->registerShortcut(selectOneRightAction);
Chris@0 1093
Chris@6 1094 menu->addAction(playAction);
Chris@0 1095 menu->addAction(psAction);
Chris@0 1096 menu->addAction(plAction);
Chris@0 1097 menu->addSeparator();
Chris@0 1098 menu->addAction(m_rwdAction);
Chris@0 1099 menu->addAction(m_ffwdAction);
Chris@0 1100 menu->addSeparator();
Chris@0 1101 menu->addAction(rwdStartAction);
Chris@0 1102 menu->addAction(ffwdEndAction);
Chris@0 1103 menu->addSeparator();
Chris@300 1104 menu->addAction(oneLeftAction);
Chris@300 1105 menu->addAction(oneRightAction);
Chris@300 1106 menu->addAction(selectOneLeftAction);
Chris@300 1107 menu->addAction(selectOneRightAction);
Chris@300 1108 menu->addSeparator();
Chris@0 1109
Chris@0 1110 m_rightButtonPlaybackMenu->addAction(playAction);
Chris@0 1111 m_rightButtonPlaybackMenu->addAction(psAction);
Chris@0 1112 m_rightButtonPlaybackMenu->addAction(plAction);
Chris@0 1113 m_rightButtonPlaybackMenu->addSeparator();
Chris@0 1114 m_rightButtonPlaybackMenu->addAction(m_rwdAction);
Chris@0 1115 m_rightButtonPlaybackMenu->addAction(m_ffwdAction);
Chris@0 1116 m_rightButtonPlaybackMenu->addSeparator();
Chris@0 1117 m_rightButtonPlaybackMenu->addAction(rwdStartAction);
Chris@0 1118 m_rightButtonPlaybackMenu->addAction(ffwdEndAction);
Chris@0 1119 m_rightButtonPlaybackMenu->addSeparator();
Chris@300 1120 m_rightButtonPlaybackMenu->addAction(oneLeftAction);
Chris@300 1121 m_rightButtonPlaybackMenu->addAction(oneRightAction);
Chris@300 1122 m_rightButtonPlaybackMenu->addAction(selectOneLeftAction);
Chris@300 1123 m_rightButtonPlaybackMenu->addAction(selectOneRightAction);
Chris@300 1124 m_rightButtonPlaybackMenu->addSeparator();
Chris@0 1125
Chris@0 1126 QAction *fastAction = menu->addAction(tr("Speed Up"));
Chris@0 1127 fastAction->setShortcut(tr("Ctrl+PgUp"));
Chris@0 1128 fastAction->setStatusTip(tr("Time-stretch playback to speed it up without changing pitch"));
Chris@0 1129 connect(fastAction, SIGNAL(triggered()), this, SLOT(speedUpPlayback()));
Chris@0 1130 connect(this, SIGNAL(canSpeedUpPlayback(bool)), fastAction, SLOT(setEnabled(bool)));
Chris@0 1131
Chris@0 1132 QAction *slowAction = menu->addAction(tr("Slow Down"));
Chris@0 1133 slowAction->setShortcut(tr("Ctrl+PgDown"));
Chris@0 1134 slowAction->setStatusTip(tr("Time-stretch playback to slow it down without changing pitch"));
Chris@0 1135 connect(slowAction, SIGNAL(triggered()), this, SLOT(slowDownPlayback()));
Chris@0 1136 connect(this, SIGNAL(canSlowDownPlayback(bool)), slowAction, SLOT(setEnabled(bool)));
Chris@0 1137
Chris@0 1138 QAction *normalAction = menu->addAction(tr("Restore Normal Speed"));
Chris@0 1139 normalAction->setShortcut(tr("Ctrl+Home"));
Chris@0 1140 normalAction->setStatusTip(tr("Restore non-time-stretched playback"));
Chris@0 1141 connect(normalAction, SIGNAL(triggered()), this, SLOT(restoreNormalPlayback()));
Chris@0 1142 connect(this, SIGNAL(canChangePlaybackSpeed(bool)), normalAction, SLOT(setEnabled(bool)));
Chris@0 1143
Chris@0 1144 m_keyReference->registerShortcut(fastAction);
Chris@0 1145 m_keyReference->registerShortcut(slowAction);
Chris@0 1146 m_keyReference->registerShortcut(normalAction);
Chris@0 1147
Chris@0 1148 m_rightButtonPlaybackMenu->addAction(fastAction);
Chris@0 1149 m_rightButtonPlaybackMenu->addAction(slowAction);
Chris@0 1150 m_rightButtonPlaybackMenu->addAction(normalAction);
Chris@6 1151
Chris@195 1152 toolbar = new QToolBar(tr("Playback Controls"));
Chris@195 1153 addToolBar(Qt::BottomToolBarArea, toolbar);
Chris@195 1154
Chris@6 1155 toolbar->addWidget(m_playSpeed);
Chris@6 1156 toolbar->addWidget(m_fader);
Chris@0 1157
Chris@128 1158 toolbar = addToolBar(tr("Show and Play"));
matthiasm@258 1159 addToolBar(Qt::BottomToolBarArea, toolbar);
Chris@144 1160
Chris@144 1161 m_showAudio = toolbar->addAction(il.load("waveform"), tr("Show Audio"));
Chris@144 1162 m_showAudio->setCheckable(true);
Chris@144 1163 connect(m_showAudio, SIGNAL(triggered()), this, SLOT(showAudioToggled()));
Chris@144 1164 connect(this, SIGNAL(canPlay(bool)), m_showAudio, SLOT(setEnabled(bool)));
Chris@144 1165
Chris@290 1166 m_playAudio = toolbar->addAction(il.load("speaker"), tr("Play Audio"));
Chris@290 1167 m_playAudio->setCheckable(true);
Chris@290 1168 connect(m_playAudio, SIGNAL(triggered()), this, SLOT(playAudioToggled()));
Chris@291 1169 connect(this, SIGNAL(canPlayWaveform(bool)), m_playAudio, SLOT(setEnabled(bool)));
Chris@290 1170
Chris@290 1171 toolbar->addWidget(m_gainAudio);
Chris@290 1172 toolbar->addWidget(m_panAudio);
Chris@290 1173
Chris@290 1174 // Pitch (f0)
Chris@290 1175 QLabel *spacer = new QLabel; // blank
Chris@290 1176 spacer->setFixedWidth(40);
Chris@290 1177 toolbar->addWidget(spacer);
Chris@145 1178
Chris@144 1179 m_showPitch = toolbar->addAction(il.load("values"), tr("Show Pitch Track"));
Chris@144 1180 m_showPitch->setCheckable(true);
Chris@144 1181 connect(m_showPitch, SIGNAL(triggered()), this, SLOT(showPitchToggled()));
Chris@144 1182 connect(this, SIGNAL(canPlay(bool)), m_showPitch, SLOT(setEnabled(bool)));
Chris@144 1183
matthiasm@366 1184 if (!m_withSonification)
matthiasm@366 1185 {
matthiasm@366 1186 m_playPitch = new QAction(tr("Play Pitch Track"), this);
matthiasm@366 1187 } else {
matthiasm@366 1188 m_playPitch = toolbar->addAction(il.load("speaker"), tr("Play Pitch Track"));
matthiasm@366 1189 toolbar->addWidget(m_gainPitch);
matthiasm@366 1190 toolbar->addWidget(m_panPitch);
matthiasm@366 1191 }
Chris@290 1192 m_playPitch->setCheckable(true);
Chris@290 1193 connect(m_playPitch, SIGNAL(triggered()), this, SLOT(playPitchToggled()));
Chris@291 1194 connect(this, SIGNAL(canPlayPitch(bool)), m_playPitch, SLOT(setEnabled(bool)));
Chris@290 1195
Chris@290 1196 // Notes
Chris@290 1197 spacer = new QLabel;
Chris@290 1198 spacer->setFixedWidth(40);
Chris@290 1199 toolbar->addWidget(spacer);
Chris@290 1200
Chris@144 1201 m_showNotes = toolbar->addAction(il.load("notes"), tr("Show Notes"));
Chris@144 1202 m_showNotes->setCheckable(true);
Chris@144 1203 connect(m_showNotes, SIGNAL(triggered()), this, SLOT(showNotesToggled()));
Chris@144 1204 connect(this, SIGNAL(canPlay(bool)), m_showNotes, SLOT(setEnabled(bool)));
justin@156 1205
matthiasm@366 1206 if (!m_withSonification)
matthiasm@366 1207 {
matthiasm@366 1208 m_playNotes = new QAction(tr("Play Notes"), this);
matthiasm@366 1209 } else {
matthiasm@366 1210 m_playNotes = toolbar->addAction(il.load("speaker"), tr("Play Notes"));
matthiasm@366 1211 toolbar->addWidget(m_gainNotes);
matthiasm@366 1212 toolbar->addWidget(m_panNotes);
matthiasm@366 1213 }
justin@156 1214 m_playNotes->setCheckable(true);
justin@156 1215 connect(m_playNotes, SIGNAL(triggered()), this, SLOT(playNotesToggled()));
Chris@291 1216 connect(this, SIGNAL(canPlayNotes(bool)), m_playNotes, SLOT(setEnabled(bool)));
justin@156 1217
justin@156 1218 // Spectrogram
Chris@290 1219 spacer = new QLabel;
Chris@290 1220 spacer->setFixedWidth(40);
Chris@290 1221 toolbar->addWidget(spacer);
Chris@290 1222
matthiasm@366 1223 if (!m_withSpectrogram)
matthiasm@366 1224 {
matthiasm@366 1225 m_showSpect = new QAction(tr("Show Spectrogram"), this);
matthiasm@366 1226 } else {
matthiasm@366 1227 m_showSpect = toolbar->addAction(il.load("spectrogram"), tr("Show Spectrogram"));
matthiasm@366 1228 }
justin@156 1229 m_showSpect->setCheckable(true);
justin@156 1230 connect(m_showSpect, SIGNAL(triggered()), this, SLOT(showSpectToggled()));
justin@156 1231 connect(this, SIGNAL(canPlay(bool)), m_showSpect, SLOT(setEnabled(bool)));
Chris@128 1232
Chris@0 1233 Pane::registerShortcuts(*m_keyReference);
matthiasm@366 1234
Chris@0 1235 }
Chris@0 1236
matthiasm@281 1237
matthiasm@281 1238 void
matthiasm@281 1239 MainWindow::moveOneNoteRight()
matthiasm@281 1240 {
matthiasm@281 1241 // cerr << "MainWindow::moveOneNoteRight" << endl;
matthiasm@296 1242 moveByOneNote(true, false);
matthiasm@281 1243 }
matthiasm@281 1244
matthiasm@281 1245 void
matthiasm@281 1246 MainWindow::moveOneNoteLeft()
matthiasm@281 1247 {
matthiasm@281 1248 // cerr << "MainWindow::moveOneNoteLeft" << endl;
matthiasm@296 1249 moveByOneNote(false, false);
matthiasm@281 1250 }
matthiasm@281 1251
matthiasm@281 1252 void
matthiasm@283 1253 MainWindow::selectOneNoteRight()
matthiasm@283 1254 {
matthiasm@296 1255 moveByOneNote(true, true);
matthiasm@283 1256 }
matthiasm@283 1257
matthiasm@283 1258 void
matthiasm@283 1259 MainWindow::selectOneNoteLeft()
matthiasm@283 1260 {
matthiasm@296 1261 moveByOneNote(false, true);
matthiasm@283 1262 }
matthiasm@283 1263
matthiasm@283 1264
matthiasm@283 1265 void
matthiasm@296 1266 MainWindow::moveByOneNote(bool right, bool doSelect)
matthiasm@281 1267 {
matthiasm@281 1268 int frame = m_viewManager->getPlaybackFrame();
matthiasm@301 1269 cerr << "MainWindow::moveByOneNote startframe: " << frame << endl;
matthiasm@281 1270
matthiasm@304 1271 bool isAtSelectionBoundary = false;
matthiasm@304 1272 MultiSelection::SelectionList selections = m_viewManager->getSelections();
matthiasm@304 1273 if (!selections.empty()) {
matthiasm@304 1274 Selection sel = *selections.begin();
matthiasm@342 1275 isAtSelectionBoundary = (frame == sel.getStartFrame()) || (frame == sel.getEndFrame());
matthiasm@304 1276 }
matthiasm@304 1277 if (!doSelect || !isAtSelectionBoundary) {
matthiasm@296 1278 m_selectionAnchor = frame;
matthiasm@296 1279 }
matthiasm@296 1280
matthiasm@281 1281 Layer *layer = m_analyser->getLayer(Analyser::Notes);
matthiasm@281 1282 if (!layer) return;
matthiasm@281 1283
matthiasm@281 1284 FlexiNoteModel *model = qobject_cast<FlexiNoteModel *>(layer->getModel());
matthiasm@281 1285 if (!model) return;
matthiasm@281 1286
matthiasm@281 1287 FlexiNoteModel::PointList points = model->getPoints();
matthiasm@281 1288 if (points.empty()) return;
matthiasm@281 1289
matthiasm@281 1290 FlexiNoteModel::PointList::iterator i = points.begin();
matthiasm@281 1291 std::set<int> snapFrames;
matthiasm@281 1292 snapFrames.insert(0);
matthiasm@281 1293 while (i != points.end()) {
matthiasm@281 1294 snapFrames.insert(i->frame);
matthiasm@281 1295 snapFrames.insert(i->frame + i->duration + 1);
matthiasm@281 1296 ++i;
matthiasm@281 1297 }
matthiasm@281 1298 std::set<int>::iterator i2;
matthiasm@281 1299 if (snapFrames.find(frame) == snapFrames.end())
matthiasm@281 1300 {
matthiasm@281 1301 // we're not on an existing snap point, so go to previous
matthiasm@281 1302 snapFrames.insert(frame);
matthiasm@281 1303 }
matthiasm@281 1304 i2 = snapFrames.find(frame);
matthiasm@281 1305 if (right)
matthiasm@281 1306 {
matthiasm@281 1307 i2++;
matthiasm@281 1308 if (i2 == snapFrames.end()) i2--;
matthiasm@281 1309 } else {
matthiasm@281 1310 if (i2 != snapFrames.begin()) i2--;
matthiasm@281 1311 }
matthiasm@281 1312 frame = *i2;
matthiasm@281 1313 m_viewManager->setPlaybackFrame(frame);
matthiasm@296 1314 if (doSelect) {
matthiasm@296 1315 Selection sel;
matthiasm@296 1316 if (frame > m_selectionAnchor) {
matthiasm@342 1317 sel = Selection(m_selectionAnchor, frame);
matthiasm@296 1318 } else {
matthiasm@342 1319 sel = Selection(frame, m_selectionAnchor);
matthiasm@296 1320 }
matthiasm@296 1321 m_viewManager->setSelection(sel);
matthiasm@296 1322 }
matthiasm@301 1323 cerr << "MainWindow::moveByOneNote endframe: " << frame << endl;
matthiasm@281 1324 }
matthiasm@281 1325
Chris@0 1326 void
Chris@70 1327 MainWindow::toolNavigateSelected()
Chris@70 1328 {
Chris@70 1329 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@70 1330 m_intelligentActionOn = true;
Chris@70 1331 }
Chris@70 1332
Chris@70 1333 void
Chris@70 1334 MainWindow::toolEditSelected()
Chris@70 1335 {
matthiasm@294 1336 cerr << "MainWindow::toolEditSelected" << endl;
Chris@77 1337 m_viewManager->setToolMode(ViewManager::NoteEditMode);
Chris@70 1338 m_intelligentActionOn = true;
Chris@70 1339 m_analyser->setIntelligentActions(m_intelligentActionOn);
Chris@70 1340 }
Chris@70 1341
Chris@70 1342 void
Chris@70 1343 MainWindow::toolFreeEditSelected()
Chris@70 1344 {
Chris@77 1345 m_viewManager->setToolMode(ViewManager::NoteEditMode);
Chris@70 1346 m_intelligentActionOn = false;
Chris@70 1347 m_analyser->setIntelligentActions(m_intelligentActionOn);
Chris@70 1348 }
Chris@70 1349
gyorgyf@21 1350 void
Chris@0 1351 MainWindow::updateMenuStates()
Chris@0 1352 {
Chris@0 1353 MainWindowBase::updateMenuStates();
Chris@0 1354
Chris@0 1355 Pane *currentPane = 0;
Chris@0 1356 Layer *currentLayer = 0;
Chris@0 1357
Chris@0 1358 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@0 1359 if (currentPane) currentLayer = currentPane->getSelectedLayer();
Chris@0 1360
Chris@291 1361 bool haveMainModel =
Chris@291 1362 (getMainModel() != 0);
Chris@291 1363 bool havePlayTarget =
Chris@291 1364 (m_playTarget != 0);
Chris@0 1365 bool haveCurrentPane =
Chris@0 1366 (currentPane != 0);
Chris@0 1367 bool haveCurrentLayer =
Chris@0 1368 (haveCurrentPane &&
Chris@0 1369 (currentLayer != 0));
Chris@0 1370 bool haveSelection =
Chris@187 1371 (m_viewManager &&
Chris@187 1372 !m_viewManager->getSelections().empty());
Chris@0 1373 bool haveCurrentTimeInstantsLayer =
Chris@187 1374 (haveCurrentLayer &&
Chris@187 1375 qobject_cast<TimeInstantLayer *>(currentLayer));
Chris@0 1376 bool haveCurrentTimeValueLayer =
Chris@187 1377 (haveCurrentLayer &&
Chris@187 1378 qobject_cast<TimeValueLayer *>(currentLayer));
Chris@187 1379 bool pitchCandidatesVisible =
Chris@187 1380 m_analyser->arePitchCandidatesShown();
Chris@0 1381
Chris@0 1382 emit canChangePlaybackSpeed(true);
Chris@0 1383 int v = m_playSpeed->value();
Chris@0 1384 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
Chris@0 1385 emit canSlowDownPlayback(v > m_playSpeed->minimum());
Chris@0 1386
Chris@291 1387 bool haveWaveform =
Chris@291 1388 m_analyser->isVisible(Analyser::Audio) &&
Chris@291 1389 m_analyser->getLayer(Analyser::Audio);
Chris@291 1390
Chris@237 1391 bool havePitchTrack =
Chris@237 1392 m_analyser->isVisible(Analyser::PitchTrack) &&
Chris@237 1393 m_analyser->getLayer(Analyser::PitchTrack);
Chris@237 1394
Chris@237 1395 bool haveNotes =
Chris@237 1396 m_analyser->isVisible(Analyser::Notes) &&
Chris@237 1397 m_analyser->getLayer(Analyser::Notes);
Chris@237 1398
Chris@237 1399 emit canExportPitchTrack(havePitchTrack);
Chris@237 1400 emit canExportNotes(haveNotes);
Chris@237 1401 emit canSnapNotes(haveSelection && haveNotes);
Chris@224 1402
Chris@291 1403 emit canPlayWaveform(haveWaveform && haveMainModel && havePlayTarget);
Chris@291 1404 emit canPlayPitch(havePitchTrack && haveMainModel && havePlayTarget);
Chris@291 1405 emit canPlayNotes(haveNotes && haveMainModel && havePlayTarget);
Chris@291 1406
Chris@187 1407 if (pitchCandidatesVisible) {
Chris@187 1408 m_showCandidatesAction->setText(tr("Hide Pitch Candidates"));
Chris@187 1409 m_showCandidatesAction->setStatusTip(tr("Remove the display of alternate pitch candidates for the selected region"));
Chris@187 1410 } else {
Chris@187 1411 m_showCandidatesAction->setText(tr("Show Pitch Candidates"));
Chris@187 1412 m_showCandidatesAction->setStatusTip(tr("Show alternate pitch candidates for the selected region"));
Chris@187 1413 }
Chris@187 1414
Chris@0 1415 if (m_ffwdAction && m_rwdAction) {
Chris@0 1416 if (haveCurrentTimeInstantsLayer) {
Chris@0 1417 m_ffwdAction->setText(tr("Fast Forward to Next Instant"));
Chris@0 1418 m_ffwdAction->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
Chris@0 1419 m_rwdAction->setText(tr("Rewind to Previous Instant"));
Chris@0 1420 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
Chris@0 1421 } else if (haveCurrentTimeValueLayer) {
Chris@0 1422 m_ffwdAction->setText(tr("Fast Forward to Next Point"));
Chris@0 1423 m_ffwdAction->setStatusTip(tr("Fast forward to the next point in the current layer"));
Chris@0 1424 m_rwdAction->setText(tr("Rewind to Previous Point"));
Chris@0 1425 m_rwdAction->setStatusTip(tr("Rewind to the previous point in the current layer"));
Chris@0 1426 } else {
Chris@0 1427 m_ffwdAction->setText(tr("Fast Forward"));
Chris@0 1428 m_ffwdAction->setStatusTip(tr("Fast forward"));
Chris@0 1429 m_rwdAction->setText(tr("Rewind"));
Chris@0 1430 m_rwdAction->setStatusTip(tr("Rewind"));
Chris@0 1431 }
Chris@0 1432 }
Chris@0 1433 }
Chris@0 1434
Chris@0 1435 void
Chris@144 1436 MainWindow::showAudioToggled()
Chris@128 1437 {
Chris@144 1438 m_analyser->toggleVisible(Analyser::Audio);
justin@220 1439
Chris@291 1440 QSettings settings;
Chris@291 1441 settings.beginGroup("MainWindow");
Chris@291 1442
Chris@291 1443 bool playOn = false;
Chris@291 1444 if (m_analyser->isVisible(Analyser::Audio)) {
Chris@291 1445 // just switched layer on; check whether playback was also on previously
Chris@291 1446 playOn = settings.value("playaudiowas", true).toBool();
Chris@291 1447 } else {
Chris@291 1448 settings.setValue("playaudiowas", m_playAudio->isChecked());
justin@220 1449 }
Chris@291 1450 m_analyser->setAudible(Analyser::Audio, playOn);
Chris@291 1451 m_playAudio->setChecked(playOn);
Chris@291 1452
Chris@291 1453 settings.endGroup();
Chris@291 1454
Chris@291 1455 updateMenuStates();
Chris@128 1456 }
Chris@128 1457
Chris@128 1458 void
Chris@144 1459 MainWindow::showPitchToggled()
Chris@128 1460 {
Chris@144 1461 m_analyser->toggleVisible(Analyser::PitchTrack);
justin@185 1462
Chris@291 1463 QSettings settings;
Chris@291 1464 settings.beginGroup("MainWindow");
Chris@291 1465
Chris@291 1466 bool playOn = false;
Chris@291 1467 if (m_analyser->isVisible(Analyser::PitchTrack)) {
Chris@291 1468 // just switched layer on; check whether playback was also on previously
Chris@291 1469 playOn = settings.value("playpitchwas", true).toBool();
Chris@291 1470 } else {
Chris@291 1471 settings.setValue("playpitchwas", m_playPitch->isChecked());
justin@185 1472 }
Chris@291 1473 m_analyser->setAudible(Analyser::PitchTrack, playOn);
Chris@291 1474 m_playPitch->setChecked(playOn);
Chris@291 1475
Chris@291 1476 settings.endGroup();
Chris@291 1477
Chris@291 1478 updateMenuStates();
Chris@128 1479 }
Chris@128 1480
Chris@128 1481 void
Chris@145 1482 MainWindow::showSpectToggled()
Chris@145 1483 {
Chris@145 1484 m_analyser->toggleVisible(Analyser::Spectrogram);
Chris@145 1485 }
Chris@145 1486
Chris@145 1487 void
Chris@144 1488 MainWindow::showNotesToggled()
Chris@128 1489 {
Chris@144 1490 m_analyser->toggleVisible(Analyser::Notes);
justin@220 1491
Chris@291 1492 QSettings settings;
Chris@291 1493 settings.beginGroup("MainWindow");
Chris@291 1494
Chris@291 1495 bool playOn = false;
Chris@291 1496 if (m_analyser->isVisible(Analyser::Notes)) {
Chris@291 1497 // just switched layer on; check whether playback was also on previously
Chris@291 1498 playOn = settings.value("playnoteswas", true).toBool();
Chris@291 1499 } else {
Chris@291 1500 settings.setValue("playnoteswas", m_playNotes->isChecked());
justin@220 1501 }
Chris@291 1502 m_analyser->setAudible(Analyser::Notes, playOn);
Chris@291 1503 m_playNotes->setChecked(playOn);
Chris@291 1504
Chris@291 1505 settings.endGroup();
Chris@291 1506
Chris@291 1507 updateMenuStates();
Chris@144 1508 }
Chris@144 1509
Chris@144 1510 void
Chris@144 1511 MainWindow::playAudioToggled()
Chris@144 1512 {
Chris@144 1513 m_analyser->toggleAudible(Analyser::Audio);
Chris@144 1514 }
Chris@144 1515
Chris@144 1516 void
Chris@144 1517 MainWindow::playPitchToggled()
Chris@144 1518 {
Chris@144 1519 m_analyser->toggleAudible(Analyser::PitchTrack);
Chris@144 1520 }
Chris@144 1521
Chris@144 1522 void
Chris@144 1523 MainWindow::playNotesToggled()
Chris@144 1524 {
Chris@144 1525 m_analyser->toggleAudible(Analyser::Notes);
Chris@144 1526 }
Chris@144 1527
Chris@144 1528 void
Chris@144 1529 MainWindow::updateLayerStatuses()
Chris@144 1530 {
Chris@144 1531 m_showAudio->setChecked(m_analyser->isVisible(Analyser::Audio));
Chris@145 1532 m_showSpect->setChecked(m_analyser->isVisible(Analyser::Spectrogram));
Chris@144 1533 m_showPitch->setChecked(m_analyser->isVisible(Analyser::PitchTrack));
Chris@144 1534 m_showNotes->setChecked(m_analyser->isVisible(Analyser::Notes));
Chris@144 1535 m_playAudio->setChecked(m_analyser->isAudible(Analyser::Audio));
Chris@144 1536 m_playPitch->setChecked(m_analyser->isAudible(Analyser::PitchTrack));
Chris@144 1537 m_playNotes->setChecked(m_analyser->isAudible(Analyser::Notes));
Chris@128 1538 }
Chris@128 1539
Chris@128 1540 void
Chris@227 1541 MainWindow::editDisplayExtents()
Chris@227 1542 {
Chris@227 1543 float min, max;
Chris@227 1544 float vmin = 0;
Chris@227 1545 float vmax = getMainModel()->getSampleRate() /2;
Chris@227 1546
Chris@227 1547 if (!m_analyser->getDisplayFrequencyExtents(min, max)) {
Chris@227 1548 //!!!
Chris@227 1549 return;
Chris@227 1550 }
Chris@227 1551
Chris@227 1552 RangeInputDialog dialog(tr("Set frequency range"),
Chris@227 1553 tr("Enter new frequency range, from %1 to %2 Hz.\nThese values will be rounded to the nearest spectrogram bin.")
Chris@227 1554 .arg(vmin).arg(vmax),
Chris@227 1555 "Hz", vmin, vmax, this);
Chris@227 1556 dialog.setRange(min, max);
Chris@227 1557
Chris@227 1558 if (dialog.exec() == QDialog::Accepted) {
Chris@227 1559 dialog.getRange(min, max);
Chris@227 1560 if (min > max) {
Chris@227 1561 float tmp = max;
Chris@227 1562 max = min;
Chris@227 1563 min = tmp;
Chris@227 1564 }
Chris@227 1565 m_analyser->setDisplayFrequencyExtents(min, max);
Chris@227 1566 }
Chris@227 1567 }
Chris@227 1568
Chris@227 1569 void
Chris@0 1570 MainWindow::updateDescriptionLabel()
Chris@0 1571 {
Chris@6 1572 // Nothing, we don't have one
Chris@0 1573 }
Chris@0 1574
Chris@0 1575 void
Chris@0 1576 MainWindow::documentModified()
Chris@0 1577 {
Chris@0 1578 MainWindowBase::documentModified();
Chris@0 1579 }
Chris@0 1580
Chris@0 1581 void
Chris@0 1582 MainWindow::documentRestored()
Chris@0 1583 {
Chris@0 1584 MainWindowBase::documentRestored();
Chris@0 1585 }
Chris@0 1586
Chris@0 1587 void
Chris@0 1588 MainWindow::newSession()
Chris@0 1589 {
Chris@0 1590 if (!checkSaveModified()) return;
Chris@0 1591
Chris@0 1592 closeSession();
Chris@0 1593 createDocument();
Chris@0 1594 m_document->setAutoAlignment(true);
Chris@0 1595
Chris@0 1596 Pane *pane = m_paneStack->addPane();
Chris@362 1597 pane->setPlaybackFollow(PlaybackScrollPage);
Chris@0 1598
Chris@0 1599 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@0 1600 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 1601
Chris@6 1602 // Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@6 1603 // m_document->addLayerToView(pane, waveform);
Chris@0 1604
Chris@0 1605 m_overview->registerView(pane);
Chris@0 1606
Chris@0 1607 CommandHistory::getInstance()->clear();
Chris@0 1608 CommandHistory::getInstance()->documentSaved();
Chris@0 1609 documentRestored();
Chris@0 1610 updateMenuStates();
Chris@0 1611 }
Chris@0 1612
Chris@0 1613 void
Chris@244 1614 MainWindow::documentReplaced()
Chris@244 1615 {
Chris@244 1616 if (m_document) {
Chris@244 1617 connect(m_document, SIGNAL(activity(QString)),
Chris@244 1618 m_activityLog, SLOT(activityHappened(QString)));
Chris@244 1619 }
Chris@244 1620 }
Chris@244 1621
Chris@244 1622 void
Chris@0 1623 MainWindow::closeSession()
Chris@0 1624 {
Chris@0 1625 if (!checkSaveModified()) return;
Chris@0 1626
Chris@226 1627 m_analyser->fileClosed();
Chris@226 1628
Chris@0 1629 while (m_paneStack->getPaneCount() > 0) {
Chris@0 1630
Chris@167 1631 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@0 1632
Chris@167 1633 while (pane->getLayerCount() > 0) {
Chris@167 1634 m_document->removeLayerFromView
Chris@167 1635 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@167 1636 }
Chris@167 1637
Chris@167 1638 m_overview->unregisterView(pane);
Chris@167 1639 m_paneStack->deletePane(pane);
Chris@0 1640 }
Chris@0 1641
Chris@0 1642 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 1643
Chris@167 1644 Pane *pane = m_paneStack->getHiddenPane
Chris@167 1645 (m_paneStack->getHiddenPaneCount() - 1);
Chris@167 1646
Chris@167 1647 while (pane->getLayerCount() > 0) {
Chris@167 1648 m_document->removeLayerFromView
Chris@167 1649 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@167 1650 }
Chris@167 1651
Chris@167 1652 m_overview->unregisterView(pane);
Chris@167 1653 m_paneStack->deletePane(pane);
Chris@0 1654 }
Chris@0 1655
Chris@0 1656 delete m_document;
Chris@0 1657 m_document = 0;
Chris@0 1658 m_viewManager->clearSelections();
Chris@0 1659 m_timeRulerLayer = 0; // document owned this
Chris@0 1660
Chris@0 1661 m_sessionFile = "";
Chris@0 1662
Chris@0 1663 CommandHistory::getInstance()->clear();
Chris@0 1664 CommandHistory::getInstance()->documentSaved();
Chris@0 1665 documentRestored();
Chris@0 1666 }
Chris@0 1667
Chris@0 1668 void
Chris@0 1669 MainWindow::openFile()
Chris@0 1670 {
Chris@0 1671 QString orig = m_audioFile;
Chris@0 1672 if (orig == "") orig = ".";
Chris@0 1673 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 1674
Chris@0 1675 QString path = getOpenFileName(FileFinder::AnyFile);
Chris@0 1676
Chris@0 1677 if (path.isEmpty()) return;
Chris@0 1678
Chris@1 1679 FileOpenStatus status = open(path, ReplaceSession);
Chris@0 1680
Chris@0 1681 if (status == FileOpenFailed) {
Chris@0 1682 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1683 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path));
Chris@0 1684 } else if (status == FileOpenWrongMode) {
Chris@0 1685 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1686 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 1687 }
Chris@0 1688 }
Chris@0 1689
Chris@0 1690 void
Chris@0 1691 MainWindow::openLocation()
Chris@0 1692 {
Chris@0 1693 QSettings settings;
Chris@0 1694 settings.beginGroup("MainWindow");
Chris@0 1695 QString lastLocation = settings.value("lastremote", "").toString();
Chris@0 1696
Chris@0 1697 bool ok = false;
Chris@0 1698 QString text = QInputDialog::getText
Chris@0 1699 (this, tr("Open Location"),
Chris@0 1700 tr("Please enter the URL of the location to open:"),
Chris@0 1701 QLineEdit::Normal, lastLocation, &ok);
Chris@0 1702
Chris@0 1703 if (!ok) return;
Chris@0 1704
Chris@0 1705 settings.setValue("lastremote", text);
Chris@0 1706
Chris@0 1707 if (text.isEmpty()) return;
Chris@0 1708
Chris@1 1709 FileOpenStatus status = open(text, ReplaceSession);
Chris@0 1710
Chris@0 1711 if (status == FileOpenFailed) {
Chris@0 1712 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 1713 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text));
Chris@0 1714 } else if (status == FileOpenWrongMode) {
Chris@0 1715 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 1716 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 1717 }
Chris@0 1718 }
Chris@0 1719
Chris@0 1720 void
Chris@0 1721 MainWindow::openRecentFile()
Chris@0 1722 {
Chris@0 1723 QObject *obj = sender();
Chris@3 1724 QAction *action = qobject_cast<QAction *>(obj);
Chris@0 1725
Chris@0 1726 if (!action) {
Chris@188 1727 cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@188 1728 << endl;
Chris@188 1729 return;
Chris@0 1730 }
Chris@0 1731
Chris@0 1732 QString path = action->text();
Chris@0 1733 if (path == "") return;
Chris@0 1734
Chris@1 1735 FileOpenStatus status = open(path, ReplaceSession);
Chris@0 1736
Chris@0 1737 if (status == FileOpenFailed) {
Chris@0 1738 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 1739 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path));
Chris@0 1740 } else if (status == FileOpenWrongMode) {
Chris@0 1741 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 1742 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 1743 }
Chris@0 1744 }
Chris@0 1745
Chris@0 1746 void
Chris@0 1747 MainWindow::paneAdded(Pane *pane)
Chris@0 1748 {
Chris@6 1749 pane->setPlaybackFollow(PlaybackScrollPage);
Chris@0 1750 m_paneStack->sizePanesEqually();
Chris@0 1751 if (m_overview) m_overview->registerView(pane);
Chris@0 1752 }
Chris@0 1753
Chris@0 1754 void
Chris@0 1755 MainWindow::paneHidden(Pane *pane)
Chris@0 1756 {
Chris@0 1757 if (m_overview) m_overview->unregisterView(pane);
Chris@0 1758 }
Chris@0 1759
Chris@0 1760 void
Chris@0 1761 MainWindow::paneAboutToBeDeleted(Pane *pane)
Chris@0 1762 {
Chris@0 1763 if (m_overview) m_overview->unregisterView(pane);
Chris@0 1764 }
Chris@0 1765
Chris@0 1766 void
Chris@0 1767 MainWindow::paneDropAccepted(Pane *pane, QStringList uriList)
Chris@0 1768 {
Chris@4 1769 if (pane) m_paneStack->setCurrentPane(pane);
Chris@0 1770
Chris@0 1771 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) {
Chris@0 1772
Chris@1 1773 FileOpenStatus status = open(*i, ReplaceSession);
Chris@0 1774
Chris@0 1775 if (status == FileOpenFailed) {
Chris@0 1776 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@0 1777 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i));
Chris@0 1778 } else if (status == FileOpenWrongMode) {
Chris@0 1779 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@0 1780 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 1781 }
Chris@0 1782 }
Chris@0 1783 }
Chris@0 1784
Chris@0 1785 void
Chris@0 1786 MainWindow::paneDropAccepted(Pane *pane, QString text)
Chris@0 1787 {
Chris@0 1788 if (pane) m_paneStack->setCurrentPane(pane);
Chris@0 1789
Chris@0 1790 QUrl testUrl(text);
Chris@0 1791 if (testUrl.scheme() == "file" ||
Chris@0 1792 testUrl.scheme() == "http" ||
Chris@0 1793 testUrl.scheme() == "ftp") {
Chris@0 1794 QStringList list;
Chris@0 1795 list.push_back(text);
Chris@0 1796 paneDropAccepted(pane, list);
Chris@0 1797 return;
Chris@0 1798 }
Chris@0 1799
Chris@0 1800 //!!! open as text -- but by importing as if a CSV, or just adding
Chris@0 1801 //to a text layer?
Chris@0 1802 }
Chris@0 1803
Chris@0 1804 void
Chris@0 1805 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 1806 {
Chris@70 1807 // cerr << "MainWindow::closeEvent" << endl;
Chris@0 1808
Chris@0 1809 if (m_openingAudioFile) {
Chris@70 1810 // cerr << "Busy - ignoring close event" << endl;
Chris@257 1811 e->ignore();
Chris@257 1812 return;
Chris@0 1813 }
Chris@0 1814
Chris@0 1815 if (!m_abandoning && !checkSaveModified()) {
Chris@70 1816 // cerr << "Ignoring close event" << endl;
Chris@257 1817 e->ignore();
Chris@257 1818 return;
Chris@0 1819 }
Chris@0 1820
Chris@0 1821 QSettings settings;
Chris@0 1822 settings.beginGroup("MainWindow");
Chris@0 1823 settings.setValue("size", size());
Chris@0 1824 settings.setValue("position", pos());
Chris@0 1825 settings.endGroup();
Chris@0 1826
Chris@0 1827 delete m_keyReference;
Chris@0 1828 m_keyReference = 0;
Chris@0 1829
Chris@0 1830 closeSession();
Chris@0 1831
Chris@0 1832 e->accept();
Chris@0 1833 return;
Chris@0 1834 }
Chris@0 1835
Chris@0 1836 bool
Chris@0 1837 MainWindow::commitData(bool mayAskUser)
Chris@0 1838 {
Chris@0 1839 if (mayAskUser) {
Chris@0 1840 bool rv = checkSaveModified();
Chris@0 1841 return rv;
Chris@0 1842 } else {
Chris@0 1843 if (!m_documentModified) return true;
Chris@0 1844
Chris@0 1845 // If we can't check with the user first, then we can't save
Chris@0 1846 // to the original session file (even if we have it) -- have
Chris@0 1847 // to use a temporary file
Chris@0 1848
Chris@0 1849 QString svDirBase = ".sv1";
Chris@0 1850 QString svDir = QDir::home().filePath(svDirBase);
Chris@0 1851
Chris@0 1852 if (!QFileInfo(svDir).exists()) {
Chris@0 1853 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@0 1854 } else {
Chris@0 1855 if (!QFileInfo(svDir).isDir()) return false;
Chris@0 1856 }
Chris@0 1857
Chris@0 1858 // This name doesn't have to be unguessable
Chris@0 1859 #ifndef _WIN32
Chris@0 1860 QString fname = QString("tmp-%1-%2.sv")
Chris@0 1861 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@0 1862 .arg(QProcess().pid());
Chris@0 1863 #else
Chris@0 1864 QString fname = QString("tmp-%1.sv")
Chris@0 1865 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@0 1866 #endif
Chris@0 1867 QString fpath = QDir(svDir).filePath(fname);
Chris@0 1868 if (saveSessionFile(fpath)) {
Chris@0 1869 m_recentFiles.addFile(fpath);
Chris@0 1870 return true;
Chris@0 1871 } else {
Chris@0 1872 return false;
Chris@0 1873 }
Chris@0 1874 }
Chris@0 1875 }
Chris@0 1876
Chris@0 1877 bool
Chris@0 1878 MainWindow::checkSaveModified()
Chris@0 1879 {
Chris@0 1880 // Called before some destructive operation (e.g. new session,
Chris@0 1881 // exit program). Return true if we can safely proceed, false to
Chris@0 1882 // cancel.
Chris@0 1883
Chris@0 1884 if (!m_documentModified) return true;
Chris@0 1885
Chris@0 1886 int button =
Chris@257 1887 QMessageBox::warning(this,
Chris@257 1888 tr("Session modified"),
Chris@257 1889 tr("The current session has been modified.\nDo you want to save it?"),
Chris@257 1890 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@0 1891 QMessageBox::Yes);
Chris@0 1892
Chris@0 1893 if (button == QMessageBox::Yes) {
Chris@257 1894 saveSession();
Chris@257 1895 if (m_documentModified) { // save failed -- don't proceed!
Chris@257 1896 return false;
Chris@257 1897 } else {
Chris@0 1898 return true; // saved, so it's safe to continue now
Chris@0 1899 }
Chris@0 1900 } else if (button == QMessageBox::No) {
Chris@257 1901 m_documentModified = false; // so we know to abandon it
Chris@257 1902 return true;
Chris@0 1903 }
Chris@0 1904
Chris@0 1905 // else cancel
Chris@0 1906 return false;
Chris@0 1907 }
Chris@0 1908
Chris@314 1909 bool
Chris@314 1910 MainWindow::waitForInitialAnalysis()
Chris@314 1911 {
Chris@314 1912 // Called before saving a session. We can't safely save while the
Chris@314 1913 // initial analysis is happening, because then we end up with an
Chris@314 1914 // incomplete session on reload. There are certainly theoretically
Chris@314 1915 // better ways to handle this...
Chris@314 1916
Chris@330 1917 QSettings settings;
Chris@330 1918 settings.beginGroup("Analyser");
Chris@330 1919 bool autoAnalyse = settings.value("auto-analysis", true).toBool();
Chris@330 1920 settings.endGroup();
Chris@330 1921
Chris@330 1922 if (!autoAnalyse) {
Chris@330 1923 return true;
Chris@330 1924 }
Chris@330 1925
Chris@314 1926 if (!m_analyser || m_analyser->getInitialAnalysisCompletion() >= 100) {
Chris@314 1927 return true;
Chris@314 1928 }
Chris@314 1929
Chris@314 1930 QMessageBox mb(QMessageBox::Information,
Chris@314 1931 tr("Waiting for analysis"),
Chris@314 1932 tr("Waiting for initial analysis to complete before saving..."),
Chris@314 1933 QMessageBox::Cancel,
Chris@314 1934 this);
Chris@314 1935
Chris@314 1936 connect(m_analyser, SIGNAL(initialAnalysisCompleted()),
Chris@314 1937 &mb, SLOT(accept()));
Chris@314 1938
Chris@314 1939 if (mb.exec() == QDialog::Accepted) {
Chris@314 1940 return true;
Chris@314 1941 } else {
Chris@314 1942 return false;
Chris@314 1943 }
Chris@314 1944 }
Chris@314 1945
Chris@0 1946 void
Chris@0 1947 MainWindow::saveSession()
Chris@0 1948 {
Chris@269 1949 // We do not want to save mid-analysis regions -- that would cause
Chris@269 1950 // confusion on reloading
Chris@269 1951 m_analyser->clearReAnalysis();
Chris@269 1952 clearSelection();
Chris@269 1953
Chris@0 1954 if (m_sessionFile != "") {
Chris@257 1955 if (!saveSessionFile(m_sessionFile)) {
Chris@257 1956 QMessageBox::critical
Chris@257 1957 (this, tr("Failed to save file"),
Chris@257 1958 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@257 1959 } else {
Chris@257 1960 CommandHistory::getInstance()->documentSaved();
Chris@257 1961 documentRestored();
Chris@257 1962 }
Chris@0 1963 } else {
Chris@257 1964 saveSessionAs();
Chris@0 1965 }
Chris@0 1966 }
Chris@0 1967
Chris@0 1968 void
matthiasm@310 1969 MainWindow::saveSessionInAudioPath()
matthiasm@310 1970 {
matthiasm@311 1971 if (m_audioFile == "") return;
matthiasm@311 1972
Chris@314 1973 if (!waitForInitialAnalysis()) return;
Chris@314 1974
matthiasm@310 1975 // We do not want to save mid-analysis regions -- that would cause
matthiasm@310 1976 // confusion on reloading
matthiasm@310 1977 m_analyser->clearReAnalysis();
matthiasm@310 1978 clearSelection();
matthiasm@310 1979
matthiasm@310 1980 QString filepath = QFileInfo(m_audioFile).absoluteDir().canonicalPath();
matthiasm@310 1981 QString basename = QFileInfo(m_audioFile).completeBaseName();
matthiasm@310 1982
matthiasm@310 1983 QString path = QDir(filepath).filePath(basename + ".ton");
matthiasm@310 1984
matthiasm@310 1985 cerr << path << endl;
matthiasm@310 1986
Chris@313 1987 // We don't want to overwrite an existing .ton file unless we put
Chris@313 1988 // it there in the first place
Chris@313 1989 bool shouldVerify = true;
Chris@313 1990 if (m_sessionFile == path) {
Chris@313 1991 shouldVerify = false;
Chris@313 1992 }
Chris@313 1993
Chris@313 1994 if (shouldVerify && QFileInfo(path).exists()) {
Chris@313 1995 if (QMessageBox::question(0, tr("File exists"),
Chris@313 1996 tr("<b>File exists</b><p>The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path),
Chris@313 1997 QMessageBox::Ok,
Chris@313 1998 QMessageBox::Cancel) != QMessageBox::Ok) {
Chris@313 1999 return;
Chris@313 2000 }
Chris@313 2001 }
Chris@313 2002
Chris@314 2003 if (!waitForInitialAnalysis()) {
Chris@314 2004 QMessageBox::warning(this, tr("File not saved"),
Chris@314 2005 tr("Wait cancelled: the session has not been saved."));
Chris@314 2006 }
Chris@314 2007
matthiasm@310 2008 if (!saveSessionFile(path)) {
matthiasm@310 2009 QMessageBox::critical(this, tr("Failed to save file"),
matthiasm@310 2010 tr("Session file \"%1\" could not be saved.").arg(path));
matthiasm@310 2011 } else {
matthiasm@310 2012 setWindowTitle(tr("%1: %2")
matthiasm@310 2013 .arg(QApplication::applicationName())
matthiasm@310 2014 .arg(QFileInfo(path).fileName()));
matthiasm@310 2015 m_sessionFile = path;
matthiasm@310 2016 CommandHistory::getInstance()->documentSaved();
matthiasm@310 2017 documentRestored();
matthiasm@310 2018 m_recentFiles.addFile(path);
matthiasm@310 2019 }
matthiasm@310 2020 }
matthiasm@310 2021
matthiasm@310 2022 void
Chris@0 2023 MainWindow::saveSessionAs()
Chris@0 2024 {
Chris@270 2025 // We do not want to save mid-analysis regions -- that would cause
Chris@270 2026 // confusion on reloading
Chris@270 2027 m_analyser->clearReAnalysis();
Chris@270 2028 clearSelection();
Chris@270 2029
Chris@0 2030 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@0 2031
Chris@309 2032 if (path == "") {
Chris@309 2033 return;
Chris@309 2034 }
Chris@0 2035
Chris@314 2036 if (!waitForInitialAnalysis()) {
Chris@314 2037 QMessageBox::warning(this, tr("File not saved"),
Chris@314 2038 tr("Wait cancelled: the session has not been saved."));
Chris@314 2039 return;
Chris@314 2040 }
Chris@314 2041
Chris@0 2042 if (!saveSessionFile(path)) {
Chris@85 2043 QMessageBox::critical(this, tr("Failed to save file"),
Chris@85 2044 tr("Session file \"%1\" could not be saved.").arg(path));
Chris@0 2045 } else {
Chris@85 2046 setWindowTitle(tr("%1: %2")
Chris@0 2047 .arg(QApplication::applicationName())
Chris@85 2048 .arg(QFileInfo(path).fileName()));
Chris@85 2049 m_sessionFile = path;
Chris@85 2050 CommandHistory::getInstance()->documentSaved();
Chris@85 2051 documentRestored();
Chris@0 2052 m_recentFiles.addFile(path);
Chris@0 2053 }
Chris@0 2054 }
Chris@0 2055
Chris@85 2056 QString
Chris@85 2057 MainWindow::exportToSVL(QString path, Layer *layer)
Chris@85 2058 {
Chris@85 2059 Model *model = layer->getModel();
Chris@85 2060
Chris@85 2061 QFile file(path);
Chris@85 2062 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@85 2063 return tr("Failed to open file %1 for writing").arg(path);
Chris@85 2064 } else {
Chris@85 2065 QTextStream out(&file);
Chris@85 2066 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Chris@85 2067 << "<!DOCTYPE sonic-visualiser>\n"
Chris@85 2068 << "<sv>\n"
Chris@85 2069 << " <data>\n";
Chris@85 2070
Chris@85 2071 model->toXml(out, " ");
Chris@85 2072
Chris@85 2073 out << " </data>\n"
Chris@85 2074 << " <display>\n";
Chris@85 2075
Chris@85 2076 layer->toXml(out, " ");
Chris@85 2077
Chris@85 2078 out << " </display>\n"
Chris@85 2079 << "</sv>\n";
Chris@85 2080
Chris@85 2081 return "";
Chris@85 2082 }
Chris@85 2083 }
Chris@85 2084
Chris@0 2085 void
Chris@174 2086 MainWindow::importPitchLayer()
Chris@174 2087 {
Chris@174 2088 QString path = getOpenFileName(FileFinder::LayerFileNoMidiNonSV);
Chris@174 2089 if (path == "") return;
Chris@174 2090
Chris@174 2091 FileOpenStatus status = importPitchLayer(path);
Chris@174 2092
Chris@174 2093 if (status == FileOpenFailed) {
Chris@174 2094 emit hideSplash();
Chris@174 2095 QMessageBox::critical(this, tr("Failed to open file"),
Chris@174 2096 tr("<b>File open failed</b><p>Layer file %1 could not be opened.").arg(path));
Chris@174 2097 return;
Chris@174 2098 } else if (status == FileOpenWrongMode) {
Chris@174 2099 emit hideSplash();
Chris@174 2100 QMessageBox::critical(this, tr("Failed to open file"),
Chris@174 2101 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(path));
Chris@174 2102 }
Chris@174 2103 }
Chris@174 2104
Chris@174 2105 MainWindow::FileOpenStatus
Chris@174 2106 MainWindow::importPitchLayer(FileSource source)
Chris@174 2107 {
Chris@174 2108 if (!source.isAvailable()) return FileOpenFailed;
Chris@174 2109 source.waitForData();
Chris@174 2110
Chris@174 2111 QString path = source.getLocalFilename();
Chris@174 2112
Chris@174 2113 RDFImporter::RDFDocumentType rdfType =
Chris@174 2114 RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString());
Chris@174 2115
Chris@174 2116 if (rdfType != RDFImporter::NotRDF) {
Chris@174 2117
Chris@174 2118 //!!!
Chris@174 2119 return FileOpenFailed;
Chris@174 2120
Chris@174 2121 } else if (source.getExtension().toLower() == "svl" ||
Chris@174 2122 (source.getExtension().toLower() == "xml" &&
Chris@174 2123 (SVFileReader::identifyXmlFile(source.getLocalFilename())
Chris@174 2124 == SVFileReader::SVLayerFile))) {
Chris@174 2125
Chris@174 2126 //!!!
Chris@174 2127 return FileOpenFailed;
Chris@174 2128
Chris@174 2129 } else {
Chris@174 2130
Chris@174 2131 try {
Chris@174 2132
Chris@174 2133 CSVFormat format(path);
Chris@174 2134 format.setSampleRate(getMainModel()->getSampleRate());
Chris@174 2135
Chris@174 2136 if (format.getModelType() != CSVFormat::TwoDimensionalModel) {
Chris@174 2137 //!!! error report
Chris@174 2138 return FileOpenFailed;
Chris@174 2139 }
Chris@174 2140
Chris@174 2141 Model *model = DataFileReaderFactory::loadCSV
Chris@174 2142 (path, format, getMainModel()->getSampleRate());
Chris@174 2143
Chris@174 2144 if (model) {
Chris@174 2145
Chris@174 2146 SVDEBUG << "MainWindow::importPitchLayer: Have model" << endl;
Chris@174 2147
Chris@174 2148 CommandHistory::getInstance()->startCompoundOperation
Chris@174 2149 (tr("Import Pitch Track"), true);
Chris@174 2150
Chris@174 2151 Layer *newLayer = m_document->createImportedLayer(model);
Chris@174 2152
Chris@174 2153 m_analyser->takePitchTrackFrom(newLayer);
Chris@174 2154
Chris@174 2155 m_document->deleteLayer(newLayer);
Chris@174 2156
Chris@174 2157 CommandHistory::getInstance()->endCompoundOperation();
Chris@174 2158
Chris@174 2159 //!!! swap all data in to existing layer instead of this
Chris@174 2160
Chris@174 2161 if (!source.isRemote()) {
Chris@174 2162 registerLastOpenedFilePath
Chris@174 2163 (FileFinder::LayerFile,
Chris@174 2164 path); // for file dialog
Chris@174 2165 }
Chris@174 2166
Chris@174 2167 return FileOpenSucceeded;
Chris@174 2168 }
Chris@174 2169 } catch (DataFileReaderFactory::Exception e) {
Chris@174 2170 if (e == DataFileReaderFactory::ImportCancelled) {
Chris@174 2171 return FileOpenCancelled;
Chris@174 2172 }
Chris@174 2173 }
Chris@174 2174 }
Chris@174 2175
Chris@174 2176 return FileOpenFailed;
Chris@174 2177 }
Chris@174 2178
Chris@174 2179 void
Chris@85 2180 MainWindow::exportPitchLayer()
matthiasm@26 2181 {
Chris@174 2182 Layer *layer = m_analyser->getLayer(Analyser::PitchTrack);
matthiasm@26 2183 if (!layer) return;
matthiasm@26 2184
Chris@85 2185 SparseTimeValueModel *model =
Chris@85 2186 qobject_cast<SparseTimeValueModel *>(layer->getModel());
matthiasm@26 2187 if (!model) return;
matthiasm@26 2188
Chris@96 2189 FileFinder::FileType type = FileFinder::LayerFileNoMidiNonSV;
matthiasm@26 2190
matthiasm@26 2191 QString path = getSaveFileName(type);
matthiasm@26 2192
matthiasm@26 2193 if (path == "") return;
matthiasm@26 2194
matthiasm@26 2195 if (QFileInfo(path).suffix() == "") path += ".svl";
matthiasm@26 2196
matthiasm@26 2197 QString suffix = QFileInfo(path).suffix().toLower();
matthiasm@26 2198
matthiasm@26 2199 QString error;
matthiasm@26 2200
matthiasm@26 2201 if (suffix == "xml" || suffix == "svl") {
matthiasm@26 2202
Chris@85 2203 error = exportToSVL(path, layer);
matthiasm@26 2204
matthiasm@26 2205 } else if (suffix == "ttl" || suffix == "n3") {
matthiasm@26 2206
Chris@85 2207 RDFExporter exporter(path, model);
Chris@85 2208 exporter.write();
Chris@85 2209 if (!exporter.isOK()) {
Chris@85 2210 error = exporter.getError();
Chris@85 2211 }
Chris@85 2212
Chris@85 2213 } else {
Chris@85 2214
Chris@85 2215 CSVFileWriter writer(path, model,
Chris@85 2216 ((suffix == "csv") ? "," : "\t"));
Chris@85 2217 writer.write();
Chris@85 2218
Chris@85 2219 if (!writer.isOK()) {
Chris@85 2220 error = writer.getError();
Chris@85 2221 }
Chris@85 2222 }
Chris@85 2223
Chris@85 2224 if (error != "") {
Chris@85 2225 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@85 2226 } else {
Chris@85 2227 emit activity(tr("Export layer to \"%1\"").arg(path));
Chris@85 2228 }
Chris@85 2229 }
Chris@85 2230
Chris@85 2231 void
Chris@85 2232 MainWindow::exportNoteLayer()
Chris@85 2233 {
Chris@174 2234 Layer *layer = m_analyser->getLayer(Analyser::Notes);
Chris@85 2235 if (!layer) return;
Chris@85 2236
Chris@85 2237 FlexiNoteModel *model = qobject_cast<FlexiNoteModel *>(layer->getModel());
Chris@85 2238 if (!model) return;
Chris@85 2239
Chris@96 2240 FileFinder::FileType type = FileFinder::LayerFileNonSV;
Chris@85 2241
Chris@85 2242 QString path = getSaveFileName(type);
Chris@85 2243
Chris@85 2244 if (path == "") return;
Chris@85 2245
Chris@85 2246 if (QFileInfo(path).suffix() == "") path += ".svl";
Chris@85 2247
Chris@85 2248 QString suffix = QFileInfo(path).suffix().toLower();
Chris@85 2249
Chris@85 2250 QString error;
Chris@85 2251
Chris@85 2252 if (suffix == "xml" || suffix == "svl") {
Chris@85 2253
Chris@85 2254 error = exportToSVL(path, layer);
Chris@85 2255
Chris@85 2256 } else if (suffix == "mid" || suffix == "midi") {
Chris@85 2257
Chris@85 2258 MIDIFileWriter writer(path, model, model->getSampleRate());
Chris@85 2259 writer.write();
Chris@85 2260 if (!writer.isOK()) {
Chris@85 2261 error = writer.getError();
Chris@85 2262 }
Chris@85 2263
Chris@85 2264 } else if (suffix == "ttl" || suffix == "n3") {
Chris@85 2265
Chris@85 2266 RDFExporter exporter(path, model);
Chris@85 2267 exporter.write();
Chris@85 2268 if (!exporter.isOK()) {
Chris@85 2269 error = exporter.getError();
matthiasm@26 2270 }
matthiasm@26 2271
matthiasm@26 2272 } else {
matthiasm@26 2273
matthiasm@26 2274 CSVFileWriter writer(path, model,
matthiasm@26 2275 ((suffix == "csv") ? "," : "\t"));
matthiasm@26 2276 writer.write();
matthiasm@26 2277
matthiasm@26 2278 if (!writer.isOK()) {
matthiasm@26 2279 error = writer.getError();
matthiasm@26 2280 }
matthiasm@26 2281 }
matthiasm@26 2282
matthiasm@26 2283 if (error != "") {
matthiasm@26 2284 QMessageBox::critical(this, tr("Failed to write file"), error);
matthiasm@26 2285 } else {
matthiasm@26 2286 emit activity(tr("Export layer to \"%1\"").arg(path));
matthiasm@26 2287 }
matthiasm@26 2288 }
matthiasm@26 2289
Chris@139 2290 void
Chris@355 2291 MainWindow::doubleClickSelectInvoked(int frame)
Chris@139 2292 {
Chris@355 2293 int f0, f1;
Chris@139 2294 m_analyser->getEnclosingSelectionScope(frame, f0, f1);
Chris@139 2295
Chris@139 2296 cerr << "MainWindow::doubleClickSelectInvoked(" << frame << "): [" << f0 << "," << f1 << "]" << endl;
Chris@139 2297
Chris@164 2298 Selection sel(f0, f1);
Chris@164 2299 m_viewManager->setSelection(sel);
Chris@164 2300 }
Chris@164 2301
Chris@164 2302 void
Chris@194 2303 MainWindow::abandonSelection()
Chris@167 2304 {
Chris@194 2305 // Named abandonSelection rather than clearSelection to indicate
Chris@194 2306 // that this is an active operation -- it restores the original
Chris@194 2307 // content of the pitch track in the selected region rather than
Chris@194 2308 // simply un-selecting.
Chris@194 2309
Chris@194 2310 cerr << "MainWindow::abandonSelection()" << endl;
Chris@167 2311
Chris@199 2312 CommandHistory::getInstance()->startCompoundOperation(tr("Abandon Selection"), true);
Chris@168 2313
Chris@194 2314 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@194 2315 if (!selections.empty()) {
Chris@194 2316 Selection sel = *selections.begin();
Chris@199 2317 m_analyser->abandonReAnalysis(sel);
Chris@252 2318 auxSnapNotes(sel);
Chris@194 2319 }
Chris@194 2320
Chris@167 2321 MainWindowBase::clearSelection();
Chris@168 2322
Chris@168 2323 CommandHistory::getInstance()->endCompoundOperation();
Chris@167 2324 }
Chris@167 2325
Chris@167 2326 void
Chris@192 2327 MainWindow::selectionChangedByUser()
Chris@164 2328 {
Chris@221 2329 if (!m_document) {
Chris@221 2330 // we're exiting, most likely
Chris@221 2331 return;
Chris@221 2332 }
Chris@221 2333
Chris@164 2334 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@164 2335
Chris@192 2336 cerr << "MainWindow::selectionChangedByUser" << endl;
Chris@192 2337
Chris@192 2338 m_analyser->showPitchCandidates(m_pendingConstraint.isConstrained());
Chris@190 2339
Chris@164 2340 if (!selections.empty()) {
Chris@164 2341 Selection sel = *selections.begin();
Chris@192 2342 cerr << "MainWindow::selectionChangedByUser: have selection" << endl;
Chris@192 2343 QString error = m_analyser->reAnalyseSelection
Chris@192 2344 (sel, m_pendingConstraint);
Chris@164 2345 if (error != "") {
Chris@164 2346 QMessageBox::critical
Chris@164 2347 (this, tr("Failed to analyse selection"),
Chris@164 2348 tr("<b>Analysis failed</b><p>%2</p>").arg(error));
Chris@164 2349 }
Chris@164 2350 }
Chris@192 2351
Chris@192 2352 m_pendingConstraint = Analyser::FrequencyRange();
Chris@192 2353 }
Chris@192 2354
Chris@192 2355 void
Chris@192 2356 MainWindow::regionOutlined(QRect r)
Chris@192 2357 {
Chris@192 2358 cerr << "MainWindow::regionOutlined(" << r.x() << "," << r.y() << "," << r.width() << "," << r.height() << ")" << endl;
Chris@192 2359
Chris@192 2360 Pane *pane = qobject_cast<Pane *>(sender());
Chris@192 2361 if (!pane) {
Chris@192 2362 cerr << "MainWindow::regionOutlined: not sent by pane, ignoring" << endl;
Chris@192 2363 return;
Chris@192 2364 }
Chris@192 2365
Chris@192 2366 if (!m_analyser) {
Chris@192 2367 cerr << "MainWindow::regionOutlined: no analyser, ignoring" << endl;
Chris@192 2368 return;
Chris@192 2369 }
Chris@192 2370
Chris@192 2371 SpectrogramLayer *spectrogram = qobject_cast<SpectrogramLayer *>
Chris@192 2372 (m_analyser->getLayer(Analyser::Spectrogram));
Chris@192 2373 if (!spectrogram) {
Chris@192 2374 cerr << "MainWindow::regionOutlined: no spectrogram layer, ignoring" << endl;
Chris@192 2375 return;
Chris@192 2376 }
Chris@192 2377
Chris@192 2378 int f0 = pane->getFrameForX(r.x());
Chris@192 2379 int f1 = pane->getFrameForX(r.x() + r.width());
Chris@192 2380
Chris@192 2381 float v0 = spectrogram->getFrequencyForY(pane, r.y() + r.height());
Chris@192 2382 float v1 = spectrogram->getFrequencyForY(pane, r.y());
Chris@192 2383
Chris@192 2384 cerr << "MainWindow::regionOutlined: frame " << f0 << " -> " << f1
Chris@192 2385 << ", frequency " << v0 << " -> " << v1 << endl;
Chris@192 2386
Chris@192 2387 m_pendingConstraint = Analyser::FrequencyRange(v0, v1);
Chris@192 2388
Chris@192 2389 Selection sel(f0, f1);
Chris@192 2390 m_viewManager->setSelection(sel);
Chris@0 2391 }
Chris@0 2392
Chris@0 2393 void
Chris@168 2394 MainWindow::clearPitches()
Chris@168 2395 {
Chris@168 2396 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@168 2397
Chris@168 2398 CommandHistory::getInstance()->startCompoundOperation(tr("Clear Pitches"), true);
Chris@168 2399
Chris@168 2400 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@168 2401 k != selections.end(); ++k) {
Chris@184 2402 m_analyser->deletePitches(*k);
Chris@252 2403 auxSnapNotes(*k);
Chris@168 2404 }
Chris@168 2405
Chris@168 2406 CommandHistory::getInstance()->endCompoundOperation();
Chris@168 2407 }
Chris@168 2408
Chris@168 2409 void
Chris@142 2410 MainWindow::octaveShift(bool up)
Chris@142 2411 {
Chris@142 2412 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@142 2413
Chris@211 2414 CommandHistory::getInstance()->startCompoundOperation
Chris@211 2415 (up ? tr("Choose Higher Octave") : tr("Choose Lower Octave"), true);
Chris@142 2416
Chris@168 2417 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@168 2418 k != selections.end(); ++k) {
Chris@142 2419
Chris@168 2420 m_analyser->shiftOctave(*k, up);
Chris@252 2421 auxSnapNotes(*k);
Chris@142 2422 }
Chris@142 2423
Chris@142 2424 CommandHistory::getInstance()->endCompoundOperation();
Chris@142 2425 }
Chris@142 2426
Chris@142 2427 void
Chris@184 2428 MainWindow::togglePitchCandidates()
Chris@184 2429 {
Chris@199 2430 CommandHistory::getInstance()->startCompoundOperation(tr("Toggle Pitch Candidates"), true);
Chris@199 2431
Chris@184 2432 m_analyser->showPitchCandidates(!m_analyser->arePitchCandidatesShown());
Chris@199 2433
Chris@199 2434 CommandHistory::getInstance()->endCompoundOperation();
Chris@199 2435
Chris@187 2436 updateMenuStates();
Chris@184 2437 }
Chris@184 2438
Chris@184 2439 void
Chris@184 2440 MainWindow::switchPitchUp()
Chris@167 2441 {
Chris@211 2442 if (m_analyser->arePitchCandidatesShown()) {
Chris@211 2443 if (m_analyser->haveHigherPitchCandidate()) {
Chris@211 2444
Chris@211 2445 CommandHistory::getInstance()->startCompoundOperation
Chris@211 2446 (tr("Choose Higher Pitch Candidate"), true);
Chris@211 2447
Chris@211 2448 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@211 2449
Chris@211 2450 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@211 2451 k != selections.end(); ++k) {
Chris@211 2452 m_analyser->switchPitchCandidate(*k, true);
Chris@252 2453 auxSnapNotes(*k);
Chris@211 2454 }
Chris@211 2455
Chris@211 2456 CommandHistory::getInstance()->endCompoundOperation();
Chris@211 2457 }
Chris@211 2458 } else {
Chris@211 2459 octaveShift(true);
Chris@167 2460 }
Chris@167 2461 }
Chris@167 2462
Chris@167 2463 void
Chris@184 2464 MainWindow::switchPitchDown()
Chris@184 2465 {
Chris@211 2466 if (m_analyser->arePitchCandidatesShown()) {
Chris@211 2467 if (m_analyser->haveLowerPitchCandidate()) {
Chris@211 2468
Chris@211 2469 CommandHistory::getInstance()->startCompoundOperation
Chris@211 2470 (tr("Choose Lower Pitch Candidate"), true);
Chris@211 2471
Chris@211 2472 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@211 2473
Chris@211 2474 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@211 2475 k != selections.end(); ++k) {
Chris@211 2476 m_analyser->switchPitchCandidate(*k, false);
Chris@252 2477 auxSnapNotes(*k);
Chris@211 2478 }
Chris@211 2479
Chris@211 2480 CommandHistory::getInstance()->endCompoundOperation();
Chris@211 2481 }
Chris@211 2482 } else {
Chris@211 2483 octaveShift(false);
Chris@184 2484 }
Chris@184 2485 }
Chris@184 2486
Chris@184 2487 void
Chris@237 2488 MainWindow::snapNotesToPitches()
Chris@237 2489 {
matthiasm@274 2490 cerr << "in snapNotesToPitches" << endl;
Chris@237 2491 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@237 2492
Chris@237 2493 if (!selections.empty()) {
Chris@237 2494
Chris@237 2495 CommandHistory::getInstance()->startCompoundOperation
Chris@237 2496 (tr("Snap Notes to Pitches"), true);
Chris@237 2497
Chris@237 2498 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@237 2499 k != selections.end(); ++k) {
Chris@239 2500 auxSnapNotes(*k);
Chris@237 2501 }
Chris@237 2502
Chris@237 2503 CommandHistory::getInstance()->endCompoundOperation();
Chris@237 2504 }
Chris@237 2505 }
Chris@237 2506
Chris@237 2507 void
Chris@239 2508 MainWindow::auxSnapNotes(Selection s)
Chris@239 2509 {
matthiasm@274 2510 cerr << "in auxSnapNotes" << endl;
Chris@239 2511 FlexiNoteLayer *layer =
Chris@239 2512 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
Chris@239 2513 if (!layer) return;
Chris@239 2514
Chris@239 2515 layer->snapSelectedNotesToPitchTrack(m_analyser->getPane(), s);
Chris@239 2516 }
Chris@239 2517
Chris@239 2518 void
Chris@240 2519 MainWindow::splitNote()
Chris@237 2520 {
Chris@237 2521 FlexiNoteLayer *layer =
Chris@237 2522 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
Chris@237 2523 if (!layer) return;
Chris@237 2524
Chris@240 2525 layer->splitNotesAt(m_analyser->getPane(), m_viewManager->getPlaybackFrame());
Chris@237 2526 }
Chris@237 2527
Chris@237 2528 void
Chris@238 2529 MainWindow::mergeNotes()
Chris@238 2530 {
Chris@238 2531 FlexiNoteLayer *layer =
Chris@238 2532 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
Chris@238 2533 if (!layer) return;
Chris@238 2534
Chris@238 2535 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@238 2536
Chris@238 2537 if (!selections.empty()) {
Chris@238 2538
Chris@238 2539 CommandHistory::getInstance()->startCompoundOperation
Chris@238 2540 (tr("Merge Notes"), true);
Chris@238 2541
Chris@238 2542 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@238 2543 k != selections.end(); ++k) {
Chris@240 2544 layer->mergeNotes(m_analyser->getPane(), *k, true);
Chris@238 2545 }
Chris@238 2546
Chris@238 2547 CommandHistory::getInstance()->endCompoundOperation();
Chris@238 2548 }
Chris@238 2549 }
Chris@238 2550
Chris@238 2551 void
matthiasm@292 2552 MainWindow::deleteNotes()
matthiasm@292 2553 {
matthiasm@292 2554 FlexiNoteLayer *layer =
matthiasm@292 2555 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
matthiasm@292 2556 if (!layer) return;
matthiasm@292 2557
matthiasm@292 2558 MultiSelection::SelectionList selections = m_viewManager->getSelections();
matthiasm@292 2559
matthiasm@292 2560 if (!selections.empty()) {
matthiasm@292 2561
matthiasm@292 2562 CommandHistory::getInstance()->startCompoundOperation
matthiasm@292 2563 (tr("Delete Notes"), true);
matthiasm@292 2564
matthiasm@292 2565 for (MultiSelection::SelectionList::iterator k = selections.begin();
matthiasm@292 2566 k != selections.end(); ++k) {
matthiasm@294 2567 layer->deleteSelectionInclusive(*k);
matthiasm@292 2568 }
matthiasm@292 2569
matthiasm@292 2570 CommandHistory::getInstance()->endCompoundOperation();
matthiasm@292 2571 }
matthiasm@292 2572 }
matthiasm@292 2573
matthiasm@292 2574
matthiasm@292 2575 void
Chris@240 2576 MainWindow::formNoteFromSelection()
Chris@240 2577 {
matthiasm@293 2578 Layer *layer0 = m_analyser->getLayer(Analyser::Notes);
matthiasm@293 2579 FlexiNoteModel *model = qobject_cast<FlexiNoteModel *>(layer0->getModel());
matthiasm@293 2580
Chris@240 2581 FlexiNoteLayer *layer =
Chris@240 2582 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
Chris@240 2583 if (!layer) return;
Chris@240 2584
Chris@240 2585 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@240 2586
Chris@240 2587 if (!selections.empty()) {
Chris@240 2588
Chris@240 2589 CommandHistory::getInstance()->startCompoundOperation
Chris@240 2590 (tr("Form Note from Selection"), true);
Chris@240 2591 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@240 2592 k != selections.end(); ++k) {
Chris@355 2593 if (!model->getNotesWithin(k->getStartFrame(), k->getEndFrame()).empty()) {
matthiasm@293 2594 layer->splitNotesAt(m_analyser->getPane(), k->getStartFrame());
matthiasm@293 2595 layer->splitNotesAt(m_analyser->getPane(), k->getEndFrame());
matthiasm@293 2596 layer->mergeNotes(m_analyser->getPane(), *k, false);
matthiasm@293 2597 } else {
matthiasm@293 2598 layer->addNoteOn(k->getStartFrame(), 100, 100);
matthiasm@293 2599 layer->addNoteOff(k->getEndFrame(), 100);
matthiasm@293 2600 layer->mergeNotes(m_analyser->getPane(), *k, false); // only so the note adapts in case of exisitng pitch track
matthiasm@293 2601 }
Chris@240 2602 }
Chris@240 2603
matthiasm@293 2604 CommandHistory::getInstance()->endCompoundOperation();
Chris@240 2605 }
Chris@240 2606 }
Chris@240 2607
Chris@240 2608 void
Chris@0 2609 MainWindow::playSpeedChanged(int position)
Chris@0 2610 {
Chris@0 2611 PlaySpeedRangeMapper mapper(0, 200);
Chris@0 2612
Chris@0 2613 float percent = m_playSpeed->mappedValue();
Chris@0 2614 float factor = mapper.getFactorForValue(percent);
Chris@0 2615
Chris@70 2616 cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << endl;
Chris@0 2617
Chris@0 2618 bool something = (position != 100);
Chris@0 2619
Chris@0 2620 int pc = lrintf(percent);
Chris@0 2621
Chris@0 2622 if (!something) {
Chris@0 2623 contextHelpChanged(tr("Playback speed: Normal"));
Chris@0 2624 } else {
Chris@0 2625 contextHelpChanged(tr("Playback speed: %1%2%")
Chris@0 2626 .arg(position > 100 ? "+" : "")
Chris@0 2627 .arg(pc));
Chris@0 2628 }
Chris@0 2629
Chris@0 2630 m_playSource->setTimeStretch(factor);
Chris@0 2631
Chris@0 2632 updateMenuStates();
Chris@0 2633 }
Chris@0 2634
Chris@0 2635 void
Chris@0 2636 MainWindow::playSharpenToggled()
Chris@0 2637 {
Chris@0 2638 QSettings settings;
Chris@0 2639 settings.beginGroup("MainWindow");
Chris@0 2640 settings.setValue("playsharpen", m_playSharpen->isChecked());
Chris@0 2641 settings.endGroup();
Chris@0 2642
Chris@0 2643 playSpeedChanged(m_playSpeed->value());
justin@157 2644 // TODO: pitch gain?
Chris@0 2645 }
Chris@0 2646
Chris@0 2647 void
Chris@0 2648 MainWindow::playMonoToggled()
Chris@0 2649 {
Chris@0 2650 QSettings settings;
Chris@0 2651 settings.beginGroup("MainWindow");
Chris@0 2652 settings.setValue("playmono", m_playMono->isChecked());
Chris@0 2653 settings.endGroup();
Chris@0 2654
Chris@0 2655 playSpeedChanged(m_playSpeed->value());
justin@157 2656 // TODO: pitch gain?
Chris@0 2657 }
Chris@0 2658
Chris@0 2659 void
Chris@0 2660 MainWindow::speedUpPlayback()
Chris@0 2661 {
Chris@0 2662 int value = m_playSpeed->value();
Chris@0 2663 value = value + m_playSpeed->pageStep();
Chris@0 2664 if (value > m_playSpeed->maximum()) value = m_playSpeed->maximum();
Chris@0 2665 m_playSpeed->setValue(value);
Chris@0 2666 }
Chris@0 2667
Chris@0 2668 void
Chris@0 2669 MainWindow::slowDownPlayback()
Chris@0 2670 {
Chris@0 2671 int value = m_playSpeed->value();
Chris@0 2672 value = value - m_playSpeed->pageStep();
Chris@0 2673 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
Chris@0 2674 m_playSpeed->setValue(value);
Chris@0 2675 }
Chris@0 2676
Chris@0 2677 void
Chris@0 2678 MainWindow::restoreNormalPlayback()
Chris@0 2679 {
Chris@0 2680 m_playSpeed->setValue(m_playSpeed->defaultValue());
Chris@0 2681 }
Chris@0 2682
justin@157 2683 void
justin@159 2684 MainWindow::audioGainChanged(int position)
justin@159 2685 {
justin@159 2686 float level = m_gainAudio->mappedValue();
justin@159 2687 float gain = powf(10, level / 20.0);
justin@159 2688
justin@159 2689 cerr << "gain = " << gain << " (" << position << " dB)" << endl;
justin@159 2690
justin@159 2691 contextHelpChanged(tr("Audio Gain: %1 dB").arg(position));
justin@159 2692
justin@159 2693 m_analyser->setGain(Analyser::Audio, gain);
justin@159 2694
justin@159 2695 updateMenuStates();
justin@159 2696 }
justin@159 2697
justin@159 2698 void
justin@159 2699 MainWindow::increaseAudioGain()
justin@159 2700 {
justin@159 2701 int value = m_gainAudio->value();
justin@159 2702 value = value + m_gainAudio->pageStep();
justin@159 2703 if (value > m_gainAudio->maximum()) value = m_gainAudio->maximum();
justin@159 2704 m_gainAudio->setValue(value);
justin@159 2705 }
justin@159 2706
justin@159 2707 void
justin@159 2708 MainWindow::decreaseAudioGain()
justin@159 2709 {
justin@159 2710 int value = m_gainAudio->value();
justin@159 2711 value = value - m_gainAudio->pageStep();
justin@159 2712 if (value < m_gainAudio->minimum()) value = m_gainAudio->minimum();
justin@159 2713 m_gainAudio->setValue(value);
justin@159 2714 }
justin@159 2715
justin@159 2716 void
justin@159 2717 MainWindow::restoreNormalAudioGain()
justin@159 2718 {
justin@159 2719 m_gainAudio->setValue(m_gainAudio->defaultValue());
justin@159 2720 }
justin@159 2721
justin@159 2722 void
justin@157 2723 MainWindow::pitchGainChanged(int position)
justin@157 2724 {
Chris@158 2725 float level = m_gainPitch->mappedValue();
Chris@158 2726 float gain = powf(10, level / 20.0);
justin@157 2727
Chris@158 2728 cerr << "gain = " << gain << " (" << position << " dB)" << endl;
justin@157 2729
Chris@158 2730 contextHelpChanged(tr("Pitch Gain: %1 dB").arg(position));
justin@157 2731
Chris@158 2732 m_analyser->setGain(Analyser::PitchTrack, gain);
justin@157 2733
justin@157 2734 updateMenuStates();
justin@157 2735 }
justin@157 2736
justin@157 2737 void
justin@157 2738 MainWindow::increasePitchGain()
justin@157 2739 {
justin@157 2740 int value = m_gainPitch->value();
justin@157 2741 value = value + m_gainPitch->pageStep();
justin@157 2742 if (value > m_gainPitch->maximum()) value = m_gainPitch->maximum();
justin@157 2743 m_gainPitch->setValue(value);
justin@157 2744 }
justin@157 2745
justin@157 2746 void
justin@157 2747 MainWindow::decreasePitchGain()
justin@157 2748 {
justin@157 2749 int value = m_gainPitch->value();
justin@157 2750 value = value - m_gainPitch->pageStep();
justin@157 2751 if (value < m_gainPitch->minimum()) value = m_gainPitch->minimum();
justin@157 2752 m_gainPitch->setValue(value);
justin@157 2753 }
justin@157 2754
justin@157 2755 void
justin@157 2756 MainWindow::restoreNormalPitchGain()
justin@157 2757 {
justin@157 2758 m_gainPitch->setValue(m_gainPitch->defaultValue());
justin@157 2759 }
justin@157 2760
Chris@0 2761 void
justin@159 2762 MainWindow::notesGainChanged(int position)
justin@159 2763 {
justin@159 2764 float level = m_gainNotes->mappedValue();
justin@159 2765 float gain = powf(10, level / 20.0);
justin@159 2766
justin@159 2767 cerr << "gain = " << gain << " (" << position << " dB)" << endl;
justin@159 2768
justin@159 2769 contextHelpChanged(tr("Notes Gain: %1 dB").arg(position));
justin@159 2770
justin@159 2771 m_analyser->setGain(Analyser::Notes, gain);
justin@159 2772
justin@159 2773 updateMenuStates();
justin@159 2774 }
justin@159 2775
justin@159 2776 void
justin@159 2777 MainWindow::increaseNotesGain()
justin@159 2778 {
justin@159 2779 int value = m_gainNotes->value();
justin@159 2780 value = value + m_gainNotes->pageStep();
justin@159 2781 if (value > m_gainNotes->maximum()) value = m_gainNotes->maximum();
justin@159 2782 m_gainNotes->setValue(value);
justin@159 2783 }
justin@159 2784
justin@159 2785 void
justin@159 2786 MainWindow::decreaseNotesGain()
justin@159 2787 {
justin@159 2788 int value = m_gainNotes->value();
justin@159 2789 value = value - m_gainNotes->pageStep();
justin@159 2790 if (value < m_gainNotes->minimum()) value = m_gainNotes->minimum();
justin@159 2791 m_gainNotes->setValue(value);
justin@159 2792 }
justin@159 2793
justin@159 2794 void
justin@159 2795 MainWindow::restoreNormalNotesGain()
justin@159 2796 {
justin@159 2797 m_gainNotes->setValue(m_gainNotes->defaultValue());
justin@159 2798 }
justin@159 2799
justin@159 2800 void
justin@160 2801 MainWindow::audioPanChanged(int position)
justin@160 2802 {
justin@160 2803 float level = m_panAudio->mappedValue();
justin@160 2804 float pan = level/100.f;
justin@160 2805
justin@160 2806 cerr << "pan = " << pan << " (" << position << ")" << endl;
justin@160 2807
justin@160 2808 contextHelpChanged(tr("Audio Pan: %1").arg(position));
justin@160 2809
justin@160 2810 m_analyser->setPan(Analyser::Audio, pan);
justin@160 2811
justin@160 2812 updateMenuStates();
justin@160 2813 }
justin@160 2814
justin@160 2815 void
justin@160 2816 MainWindow::increaseAudioPan()
justin@160 2817 {
justin@160 2818 int value = m_panAudio->value();
justin@160 2819 value = value + m_panAudio->pageStep();
justin@160 2820 if (value > m_panAudio->maximum()) value = m_panAudio->maximum();
justin@160 2821 m_panAudio->setValue(value);
justin@160 2822 }
justin@160 2823
justin@160 2824 void
justin@160 2825 MainWindow::decreaseAudioPan()
justin@160 2826 {
justin@160 2827 int value = m_panAudio->value();
justin@160 2828 value = value - m_panAudio->pageStep();
justin@160 2829 if (value < m_panAudio->minimum()) value = m_panAudio->minimum();
justin@160 2830 m_panAudio->setValue(value);
justin@160 2831 }
justin@160 2832
justin@160 2833 void
justin@160 2834 MainWindow::restoreNormalAudioPan()
justin@160 2835 {
justin@160 2836 m_panAudio->setValue(m_panAudio->defaultValue());
justin@160 2837 }
justin@160 2838
justin@160 2839 void
justin@160 2840 MainWindow::pitchPanChanged(int position)
justin@160 2841 {
justin@160 2842 float level = m_panPitch->mappedValue();
justin@160 2843 float pan = level/100.f;
justin@160 2844
justin@160 2845 cerr << "pan = " << pan << " (" << position << ")" << endl;
justin@160 2846
justin@160 2847 contextHelpChanged(tr("Pitch Pan: %1").arg(position));
justin@160 2848
justin@160 2849 m_analyser->setPan(Analyser::PitchTrack, pan);
justin@160 2850
justin@160 2851 updateMenuStates();
justin@160 2852 }
justin@160 2853
justin@160 2854 void
justin@160 2855 MainWindow::increasePitchPan()
justin@160 2856 {
justin@160 2857 int value = m_panPitch->value();
justin@160 2858 value = value + m_panPitch->pageStep();
justin@160 2859 if (value > m_panPitch->maximum()) value = m_panPitch->maximum();
justin@160 2860 m_panPitch->setValue(value);
justin@160 2861 }
justin@160 2862
justin@160 2863 void
justin@160 2864 MainWindow::decreasePitchPan()
justin@160 2865 {
justin@160 2866 int value = m_panPitch->value();
justin@160 2867 value = value - m_panPitch->pageStep();
justin@160 2868 if (value < m_panPitch->minimum()) value = m_panPitch->minimum();
justin@160 2869 m_panPitch->setValue(value);
justin@160 2870 }
justin@160 2871
justin@160 2872 void
justin@160 2873 MainWindow::restoreNormalPitchPan()
justin@160 2874 {
justin@160 2875 m_panPitch->setValue(m_panPitch->defaultValue());
justin@160 2876 }
justin@160 2877
justin@160 2878 void
justin@160 2879 MainWindow::notesPanChanged(int position)
justin@160 2880 {
justin@160 2881 float level = m_panNotes->mappedValue();
justin@160 2882 float pan = level/100.f;
justin@160 2883
justin@160 2884 cerr << "pan = " << pan << " (" << position << ")" << endl;
justin@160 2885
justin@160 2886 contextHelpChanged(tr("Notes Pan: %1").arg(position));
justin@160 2887
justin@160 2888 m_analyser->setPan(Analyser::Notes, pan);
justin@160 2889
justin@160 2890 updateMenuStates();
justin@160 2891 }
justin@160 2892
justin@160 2893 void
justin@160 2894 MainWindow::increaseNotesPan()
justin@160 2895 {
justin@160 2896 int value = m_panNotes->value();
justin@160 2897 value = value + m_panNotes->pageStep();
justin@160 2898 if (value > m_panNotes->maximum()) value = m_panNotes->maximum();
justin@160 2899 m_panNotes->setValue(value);
justin@160 2900 }
justin@160 2901
justin@160 2902 void
justin@160 2903 MainWindow::decreaseNotesPan()
justin@160 2904 {
justin@160 2905 int value = m_panNotes->value();
justin@160 2906 value = value - m_panNotes->pageStep();
justin@160 2907 if (value < m_panNotes->minimum()) value = m_panNotes->minimum();
justin@160 2908 m_panNotes->setValue(value);
justin@160 2909 }
justin@160 2910
justin@160 2911 void
justin@160 2912 MainWindow::restoreNormalNotesPan()
justin@160 2913 {
justin@160 2914 m_panNotes->setValue(m_panNotes->defaultValue());
justin@160 2915 }
justin@160 2916
justin@160 2917 void
Chris@0 2918 MainWindow::updateVisibleRangeDisplay(Pane *p) const
Chris@0 2919 {
Chris@0 2920 if (!getMainModel() || !p) {
Chris@0 2921 return;
Chris@0 2922 }
Chris@0 2923
Chris@0 2924 bool haveSelection = false;
Chris@355 2925 int startFrame = 0, endFrame = 0;
Chris@0 2926
Chris@0 2927 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
Chris@0 2928
Chris@0 2929 bool exclusive = false;
Chris@0 2930 Selection s = m_viewManager->getInProgressSelection(exclusive);
Chris@0 2931
Chris@0 2932 if (!s.isEmpty()) {
Chris@0 2933 haveSelection = true;
Chris@0 2934 startFrame = s.getStartFrame();
Chris@0 2935 endFrame = s.getEndFrame();
Chris@0 2936 }
Chris@0 2937 }
Chris@0 2938
Chris@0 2939 if (!haveSelection) {
Chris@0 2940 startFrame = p->getFirstVisibleFrame();
Chris@0 2941 endFrame = p->getLastVisibleFrame();
Chris@0 2942 }
Chris@0 2943
Chris@0 2944 RealTime start = RealTime::frame2RealTime
Chris@0 2945 (startFrame, getMainModel()->getSampleRate());
Chris@0 2946
Chris@0 2947 RealTime end = RealTime::frame2RealTime
Chris@0 2948 (endFrame, getMainModel()->getSampleRate());
Chris@0 2949
Chris@0 2950 RealTime duration = end - start;
Chris@0 2951
Chris@0 2952 QString startStr, endStr, durationStr;
Chris@0 2953 startStr = start.toText(true).c_str();
Chris@0 2954 endStr = end.toText(true).c_str();
Chris@0 2955 durationStr = duration.toText(true).c_str();
Chris@0 2956
Chris@0 2957 if (haveSelection) {
Chris@0 2958 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
Chris@0 2959 .arg(startStr).arg(endStr).arg(durationStr);
Chris@0 2960 } else {
Chris@0 2961 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
Chris@0 2962 .arg(startStr).arg(endStr).arg(durationStr);
Chris@0 2963 }
matthiasm@42 2964
Chris@362 2965 getStatusLabel()->setText(m_myStatusMessage);
Chris@0 2966 }
Chris@0 2967
Chris@0 2968 void
Chris@0 2969 MainWindow::updatePositionStatusDisplays() const
Chris@0 2970 {
Chris@0 2971 if (!statusBar()->isVisible()) return;
Chris@0 2972
Chris@0 2973 }
Chris@0 2974
Chris@0 2975 void
Chris@0 2976 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 2977 {
Chris@0 2978 m_fader->setPeakLeft(left);
Chris@0 2979 m_fader->setPeakRight(right);
Chris@0 2980 }
Chris@0 2981
Chris@0 2982 void
Chris@355 2983 MainWindow::sampleRateMismatch(int /* requested */,
Chris@355 2984 int /* actual */,
Chris@355 2985 bool /* willResample */)
Chris@0 2986 {
Chris@0 2987 updateDescriptionLabel();
Chris@0 2988 }
Chris@0 2989
Chris@0 2990 void
Chris@0 2991 MainWindow::audioOverloadPluginDisabled()
Chris@0 2992 {
Chris@0 2993 QMessageBox::information
Chris@0 2994 (this, tr("Audio processing overload"),
Chris@0 2995 tr("<b>Overloaded</b><p>Audio effects plugin auditioning has been disabled due to a processing overload."));
Chris@0 2996 }
Chris@0 2997
Chris@0 2998 void
Chris@0 2999 MainWindow::audioTimeStretchMultiChannelDisabled()
Chris@0 3000 {
Chris@0 3001 static bool shownOnce = false;
Chris@0 3002 if (shownOnce) return;
Chris@0 3003 QMessageBox::information
Chris@0 3004 (this, tr("Audio processing overload"),
Chris@0 3005 tr("<b>Overloaded</b><p>Audio playback speed processing has been reduced to a single channel, due to a processing overload."));
Chris@0 3006 shownOnce = true;
Chris@0 3007 }
Chris@0 3008
Chris@0 3009 void
Chris@0 3010 MainWindow::layerRemoved(Layer *layer)
Chris@0 3011 {
Chris@0 3012 MainWindowBase::layerRemoved(layer);
Chris@0 3013 }
Chris@0 3014
Chris@0 3015 void
Chris@0 3016 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 3017 {
Chris@0 3018 MainWindowBase::layerInAView(layer, inAView);
Chris@0 3019 }
Chris@0 3020
Chris@0 3021 void
Chris@0 3022 MainWindow::modelAdded(Model *model)
Chris@0 3023 {
Chris@0 3024 MainWindowBase::modelAdded(model);
Chris@3 3025 DenseTimeValueModel *dtvm = qobject_cast<DenseTimeValueModel *>(model);
Chris@0 3026 if (dtvm) {
Chris@70 3027 cerr << "A dense time-value model (such as an audio file) has been loaded" << endl;
Chris@0 3028 }
Chris@0 3029 }
Chris@0 3030
Chris@0 3031 void
Chris@0 3032 MainWindow::modelAboutToBeDeleted(Model *model)
Chris@0 3033 {
Chris@0 3034 MainWindowBase::modelAboutToBeDeleted(model);
Chris@0 3035 }
Chris@0 3036
Chris@0 3037 void
Chris@0 3038 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 3039 {
Chris@0 3040 m_panLayer->setModel(model);
Chris@0 3041
Chris@0 3042 MainWindowBase::mainModelChanged(model);
Chris@0 3043
Chris@0 3044 if (m_playTarget) {
Chris@0 3045 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@0 3046 m_playTarget, SLOT(setOutputGain(float)));
Chris@0 3047 }
Chris@259 3048 }
Chris@259 3049
Chris@259 3050 void
Chris@323 3051 MainWindow::analyseNow()
Chris@323 3052 {
Chris@323 3053 cerr << "analyseNow called" << endl;
Chris@325 3054 if (!m_analyser) return;
Chris@325 3055
Chris@325 3056 CommandHistory::getInstance()->startCompoundOperation
Chris@325 3057 (tr("Analyse Audio"), true);
Chris@325 3058
Chris@325 3059 QString error = m_analyser->analyseExistingFile();
Chris@325 3060
Chris@325 3061 CommandHistory::getInstance()->endCompoundOperation();
Chris@325 3062
Chris@325 3063 if (error != "") {
Chris@325 3064 QMessageBox::warning
Chris@325 3065 (this,
Chris@325 3066 tr("Failed to analyse audio"),
Chris@325 3067 tr("<b>Analysis failed</b><p>%1</p>").arg(error),
Chris@325 3068 QMessageBox::Ok);
Chris@325 3069 }
Chris@323 3070 }
Chris@323 3071
Chris@323 3072 void
Chris@259 3073 MainWindow::analyseNewMainModel()
Chris@259 3074 {
Chris@259 3075 WaveFileModel *model = getMainModel();
Chris@260 3076
Chris@260 3077 cerr << "MainWindow::analyseNewMainModel: main model is " << model << endl;
Chris@260 3078
Chris@260 3079 cerr << "(document is " << m_document << ", it says main model is " << m_document->getMainModel() << ")" << endl;
Chris@259 3080
Chris@324 3081 if (!model) {
Chris@324 3082 cerr << "no main model!" << endl;
Chris@324 3083 return;
Chris@324 3084 }
Chris@324 3085
Chris@324 3086 if (!m_paneStack) {
Chris@324 3087 cerr << "no pane stack!" << endl;
Chris@324 3088 return;
Chris@324 3089 }
Chris@324 3090
Chris@324 3091 int pc = m_paneStack->getPaneCount();
Chris@324 3092 Pane *pane = 0;
Chris@324 3093 Pane *selectionStrip = 0;
Chris@324 3094
Chris@324 3095 if (pc < 2) {
Chris@324 3096 pane = m_paneStack->addPane();
Chris@324 3097 selectionStrip = m_paneStack->addPane();
Chris@324 3098 m_document->addLayerToView
Chris@324 3099 (selectionStrip,
Chris@324 3100 m_document->createMainModelLayer(LayerFactory::TimeRuler));
Chris@324 3101 } else {
Chris@324 3102 pane = m_paneStack->getPane(0);
Chris@324 3103 selectionStrip = m_paneStack->getPane(1);
Chris@324 3104 }
Chris@324 3105
Chris@362 3106 pane->setPlaybackFollow(PlaybackScrollPage);
Chris@362 3107
Chris@324 3108 if (selectionStrip) {
Chris@362 3109 selectionStrip->setPlaybackFollow(PlaybackScrollPage);
Chris@324 3110 selectionStrip->setFixedHeight(26);
Chris@324 3111 m_paneStack->sizePanesEqually();
Chris@324 3112 m_viewManager->clearToolModeOverrides();
Chris@324 3113 m_viewManager->setToolModeFor(selectionStrip,
Chris@324 3114 ViewManager::SelectMode);
Chris@324 3115 }
Chris@324 3116
Chris@324 3117 if (pane) {
Chris@324 3118
Chris@324 3119 disconnect(pane, SIGNAL(regionOutlined(QRect)),
Chris@324 3120 pane, SLOT(zoomToRegion(QRect)));
Chris@324 3121 connect(pane, SIGNAL(regionOutlined(QRect)),
Chris@324 3122 this, SLOT(regionOutlined(QRect)));
Chris@324 3123
Chris@324 3124 QString error = m_analyser->newFileLoaded
Chris@324 3125 (m_document, getMainModel(), m_paneStack, pane);
Chris@324 3126 if (error != "") {
Chris@324 3127 QMessageBox::warning
Chris@324 3128 (this,
Chris@324 3129 tr("Failed to analyse audio"),
Chris@324 3130 tr("<b>Analysis failed</b><p>%1</p>").arg(error),
Chris@324 3131 QMessageBox::Ok);
Chris@72 3132 }
Chris@72 3133 }
matthiasm@366 3134
matthiasm@366 3135 if (!m_withSpectrogram)
matthiasm@366 3136 {
matthiasm@366 3137 m_analyser->setVisible(Analyser::Spectrogram, false);
matthiasm@366 3138 }
matthiasm@366 3139
matthiasm@366 3140 if (!m_withSonification)
matthiasm@366 3141 {
matthiasm@366 3142 m_analyser->setAudible(Analyser::PitchTrack, false);
matthiasm@366 3143 m_analyser->setAudible(Analyser::Notes, false);
matthiasm@366 3144 }
Chris@0 3145 }
Chris@0 3146
Chris@0 3147 void
Chris@0 3148 MainWindow::modelGenerationFailed(QString transformName, QString message)
Chris@0 3149 {
Chris@0 3150 if (message != "") {
Chris@0 3151
Chris@0 3152 QMessageBox::warning
Chris@0 3153 (this,
Chris@0 3154 tr("Failed to generate layer"),
Chris@0 3155 tr("<b>Layer generation failed</b><p>Failed to generate derived layer.<p>The layer transform \"%1\" failed:<p>%2")
Chris@0 3156 .arg(transformName).arg(message),
Chris@0 3157 QMessageBox::Ok);
Chris@0 3158 } else {
Chris@0 3159 QMessageBox::warning
Chris@0 3160 (this,
Chris@0 3161 tr("Failed to generate layer"),
Chris@0 3162 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 3163 .arg(transformName),
Chris@0 3164 QMessageBox::Ok);
Chris@0 3165 }
Chris@0 3166 }
Chris@0 3167
Chris@0 3168 void
Chris@355 3169 MainWindow::modelGenerationWarning(QString /* transformName */, QString message)
Chris@0 3170 {
Chris@0 3171 QMessageBox::warning
Chris@0 3172 (this, tr("Warning"), message, QMessageBox::Ok);
Chris@0 3173 }
Chris@0 3174
Chris@0 3175 void
Chris@0 3176 MainWindow::modelRegenerationFailed(QString layerName,
Chris@0 3177 QString transformName, QString message)
Chris@0 3178 {
Chris@0 3179 if (message != "") {
Chris@0 3180
Chris@0 3181 QMessageBox::warning
Chris@0 3182 (this,
Chris@0 3183 tr("Failed to regenerate layer"),
Chris@0 3184 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 3185 .arg(layerName).arg(transformName).arg(message),
Chris@0 3186 QMessageBox::Ok);
Chris@0 3187 } else {
Chris@0 3188 QMessageBox::warning
Chris@0 3189 (this,
Chris@0 3190 tr("Failed to regenerate layer"),
Chris@0 3191 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 3192 .arg(layerName).arg(transformName),
Chris@0 3193 QMessageBox::Ok);
Chris@0 3194 }
Chris@0 3195 }
Chris@0 3196
Chris@0 3197 void
Chris@0 3198 MainWindow::modelRegenerationWarning(QString layerName,
Chris@355 3199 QString /* transformName */,
Chris@355 3200 QString message)
Chris@0 3201 {
Chris@0 3202 QMessageBox::warning
Chris@0 3203 (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 3204 }
Chris@0 3205
Chris@0 3206 void
Chris@0 3207 MainWindow::alignmentFailed(QString transformName, QString message)
Chris@0 3208 {
Chris@0 3209 QMessageBox::warning
Chris@0 3210 (this,
Chris@0 3211 tr("Failed to calculate alignment"),
Chris@0 3212 tr("<b>Alignment calculation failed</b><p>Failed to calculate an audio alignment using transform \"%1\":<p>%2")
Chris@0 3213 .arg(transformName).arg(message),
Chris@0 3214 QMessageBox::Ok);
Chris@0 3215 }
Chris@0 3216
Chris@0 3217 void
Chris@0 3218 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 3219 {
Chris@70 3220 // cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << endl;
Chris@0 3221 m_paneStack->setCurrentPane(pane);
Chris@0 3222 m_rightButtonMenu->popup(position);
Chris@0 3223 }
Chris@0 3224
Chris@0 3225 void
Chris@355 3226 MainWindow::handleOSCMessage(const OSCMessage &)
Chris@0 3227 {
Chris@70 3228 cerr << "MainWindow::handleOSCMessage: Not implemented" << endl;
Chris@0 3229 }
Chris@0 3230
Chris@0 3231 void
Chris@0 3232 MainWindow::mouseEnteredWidget()
Chris@0 3233 {
Chris@3 3234 QWidget *w = qobject_cast<QWidget *>(sender());
Chris@0 3235 if (!w) return;
Chris@0 3236
Chris@0 3237 if (w == m_fader) {
Chris@0 3238 contextHelpChanged(tr("Adjust the master playback level"));
Chris@0 3239 } else if (w == m_playSpeed) {
Chris@0 3240 contextHelpChanged(tr("Adjust the master playback speed"));
Chris@0 3241 } else if (w == m_playSharpen && w->isEnabled()) {
Chris@0 3242 contextHelpChanged(tr("Toggle transient sharpening for playback time scaling"));
Chris@0 3243 } else if (w == m_playMono && w->isEnabled()) {
Chris@0 3244 contextHelpChanged(tr("Toggle mono mode for playback time scaling"));
Chris@0 3245 }
Chris@0 3246 }
Chris@0 3247
Chris@0 3248 void
Chris@0 3249 MainWindow::mouseLeftWidget()
Chris@0 3250 {
Chris@0 3251 contextHelpChanged("");
Chris@0 3252 }
Chris@0 3253
Chris@0 3254 void
Chris@0 3255 MainWindow::website()
Chris@0 3256 {
Chris@4 3257 //!!! todo: URL!
Chris@4 3258 openHelpUrl(tr("http://code.soundsoftware.ac.uk/projects/tony/"));
Chris@0 3259 }
Chris@0 3260
Chris@0 3261 void
Chris@0 3262 MainWindow::help()
Chris@0 3263 {
Chris@4 3264 //!!! todo: help URL!
Chris@4 3265 openHelpUrl(tr("http://code.soundsoftware.ac.uk/projects/tony/"));
Chris@0 3266 }
Chris@0 3267
Chris@0 3268 void
Chris@0 3269 MainWindow::about()
Chris@0 3270 {
Chris@0 3271 bool debug = false;
Chris@0 3272 QString version = "(unknown version)";
Chris@0 3273
Chris@0 3274 #ifdef BUILD_DEBUG
Chris@0 3275 debug = true;
Chris@0 3276 #endif
Chris@0 3277 version = tr("Release %1").arg(TONY_VERSION);
Chris@0 3278
Chris@0 3279 QString aboutText;
Chris@0 3280
Chris@0 3281 aboutText += tr("<h3>About Tony</h3>");
Chris@0 3282 aboutText += tr("<p>Tony is a program for interactive note and pitch analysis and annotation.</p>");
Chris@0 3283 aboutText += tr("<p>%1 : %2 configuration</p>")
Chris@0 3284 .arg(version)
Chris@0 3285 .arg(debug ? tr("Debug") : tr("Release"));
Chris@212 3286 aboutText += tr("<p>Using Qt framework version %1.</p>")
Chris@206 3287 .arg(QT_VERSION_STR);
Chris@0 3288
Chris@0 3289 aboutText +=
Chris@266 3290 "<p>Copyright &copy; 2005&ndash;2014 Chris Cannam, Queen Mary University of London, and the Tony project authors: Matthias Mauch, George Fazekas, Justin Salamon, and Rachel Bittner.</p>"
Chris@212 3291 "<p>pYIN analysis plugin written by Matthias Mauch.</p>"
Chris@90 3292 "<p>This program is free software; you can redistribute it and/or "
Chris@90 3293 "modify it under the terms of the GNU General Public License as "
Chris@90 3294 "published by the Free Software Foundation; either version 2 of the "
Chris@0 3295 "License, or (at your option) any later version.<br>See the file "
Chris@0 3296 "COPYING included with this distribution for more information.</p>";
Chris@0 3297
Chris@0 3298 QMessageBox::about(this, tr("About %1").arg(QApplication::applicationName()), aboutText);
Chris@0 3299 }
Chris@0 3300
Chris@0 3301 void
Chris@0 3302 MainWindow::keyReference()
Chris@0 3303 {
Chris@0 3304 m_keyReference->show();
Chris@0 3305 }
Chris@0 3306
Chris@231 3307 void
Chris@231 3308 MainWindow::newerVersionAvailable(QString version)
Chris@231 3309 {
Chris@231 3310 //!!! nicer URL would be nicer
Chris@231 3311 QSettings settings;
Chris@231 3312 settings.beginGroup("NewerVersionWarning");
Chris@231 3313 QString tag = QString("version-%1-available-show").arg(version);
Chris@231 3314 if (settings.value(tag, true).toBool()) {
Chris@231 3315 QString title(tr("Newer version available"));
Chris@231 3316 QString text(tr("<h3>Newer version available</h3><p>You are using version %1 of Tony, but version %2 is now available.</p><p>Please see the <a href=\"http://code.soundsoftware.ac.uk/projects/tony/\">Tony website</a> for more information.</p>").arg(TONY_VERSION).arg(version));
Chris@231 3317 QMessageBox::information(this, title, text);
Chris@231 3318 settings.setValue(tag, false);
Chris@231 3319 }
Chris@231 3320 settings.endGroup();
Chris@231 3321 }
Chris@231 3322
matthiasm@356 3323 void
matthiasm@356 3324 MainWindow::ffwd()
matthiasm@356 3325 {
matthiasm@356 3326 if (!getMainModel()) return;
matthiasm@356 3327
matthiasm@356 3328 int frame = m_viewManager->getPlaybackFrame();
matthiasm@356 3329 ++frame;
matthiasm@356 3330
matthiasm@356 3331 size_t sr = getMainModel()->getSampleRate();
matthiasm@356 3332
matthiasm@356 3333 // The step is supposed to scale and be as wide as a step of
matthiasm@357 3334 // m_defaultFfwdRwdStep seconds at zoom level 720 and sr = 44100
matthiasm@356 3335 size_t framesPerPixel = m_viewManager->getGlobalZoom();
matthiasm@357 3336 size_t defaultZoom = (720 * 44100) / sr;
matthiasm@356 3337
matthiasm@356 3338 float scaler = (framesPerPixel * 1.0f) / defaultZoom;
matthiasm@356 3339
matthiasm@356 3340
matthiasm@356 3341 frame = RealTime::realTime2Frame
matthiasm@356 3342 (RealTime::frame2RealTime(frame, sr) + m_defaultFfwdRwdStep * scaler, sr);
matthiasm@356 3343 if (frame > int(getMainModel()->getEndFrame())) {
matthiasm@356 3344 frame = getMainModel()->getEndFrame();
matthiasm@356 3345 }
matthiasm@356 3346
matthiasm@356 3347 if (frame < 0) frame = 0;
matthiasm@356 3348
matthiasm@356 3349 if (m_viewManager->getPlaySelectionMode()) {
matthiasm@356 3350 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
matthiasm@356 3351 }
matthiasm@356 3352
matthiasm@356 3353 m_viewManager->setPlaybackFrame(frame);
matthiasm@356 3354
matthiasm@356 3355 if (frame == (int)getMainModel()->getEndFrame() &&
matthiasm@356 3356 m_playSource &&
matthiasm@356 3357 m_playSource->isPlaying() &&
matthiasm@356 3358 !m_viewManager->getPlayLoopMode()) {
matthiasm@356 3359 stop();
matthiasm@356 3360 }
matthiasm@356 3361 }
matthiasm@356 3362
matthiasm@356 3363 void
matthiasm@356 3364 MainWindow::rewind()
matthiasm@356 3365 {
matthiasm@356 3366 if (!getMainModel()) return;
matthiasm@356 3367
matthiasm@356 3368 int frame = m_viewManager->getPlaybackFrame();
matthiasm@356 3369 if (frame > 0) --frame;
matthiasm@356 3370
matthiasm@356 3371 size_t sr = getMainModel()->getSampleRate();
matthiasm@356 3372
matthiasm@356 3373 // The step is supposed to scale and be as wide as a step of
matthiasm@357 3374 // m_defaultFfwdRwdStep seconds at zoom level 720 and sr = 44100
matthiasm@356 3375 size_t framesPerPixel = m_viewManager->getGlobalZoom();
matthiasm@357 3376 size_t defaultZoom = (720 * 44100) / sr;
matthiasm@356 3377
matthiasm@356 3378 float scaler = (framesPerPixel * 1.0f) / defaultZoom;
matthiasm@356 3379 frame = RealTime::realTime2Frame
matthiasm@356 3380 (RealTime::frame2RealTime(frame, sr) - m_defaultFfwdRwdStep * scaler, sr);
matthiasm@356 3381 if (frame < int(getMainModel()->getStartFrame())) {
matthiasm@356 3382 frame = getMainModel()->getStartFrame();
matthiasm@356 3383 }
matthiasm@356 3384
matthiasm@356 3385 if (frame < 0) frame = 0;
matthiasm@356 3386
matthiasm@356 3387 if (m_viewManager->getPlaySelectionMode()) {
matthiasm@356 3388 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
matthiasm@356 3389 }
matthiasm@356 3390
matthiasm@356 3391 m_viewManager->setPlaybackFrame(frame);
matthiasm@356 3392 }