annotate sv/main/MainWindow.cpp @ 217:c24fafc45d50

add the lock and unlock window
author benoitrigolleau
date Thu, 07 Feb 2008 15:17:13 +0000
parents c4e897bf012b
children e8175839a5ac
rev   line source
ivand_qmul@121 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
ivand_qmul@121 2
ivand_qmul@121 3 /*
ivand_qmul@121 4 Sonic Visualiser
ivand_qmul@121 5 An audio file viewer and annotation editor.
ivand_qmul@121 6 Centre for Digital Music, Queen Mary, University of London.
ivand_qmul@121 7 This file copyright 2006 Chris Cannam and QMUL.
ivand_qmul@121 8
ivand_qmul@121 9 This program is free software; you can redistribute it and/or
ivand_qmul@121 10 modify it under the terms of the GNU General Public License as
ivand_qmul@121 11 published by the Free Software Foundation; either version 2 of the
ivand_qmul@121 12 License, or (at your option) any later version. See the file
ivand_qmul@121 13 COPYING included with this distribution for more information.
ivand_qmul@121 14 */
ivand_qmul@121 15
ivand_qmul@121 16 #include "version.h"
ivand_qmul@121 17
ivand_qmul@121 18 #include "MainWindow.h"
ivand_qmul@121 19 #include "document/Document.h"
ivand_qmul@121 20 #include "PreferencesDialog.h"
ivand_qmul@121 21
ivand_qmul@121 22 #include "view/Pane.h"
ivand_qmul@121 23 #include "view/PaneStack.h"
ivand_qmul@121 24 #include "data/model/WaveFileModel.h"
ivand_qmul@121 25 #include "data/model/SparseOneDimensionalModel.h"
ivand_qmul@121 26 #include "view/ViewManager.h"
ivand_qmul@121 27 #include "base/Preferences.h"
ivand_qmul@121 28 #include "layer/WaveformLayer.h"
ivand_qmul@121 29 #include "layer/TimeRulerLayer.h"
ivand_qmul@121 30 #include "layer/TimeInstantLayer.h"
ivand_qmul@121 31 #include "layer/TimeValueLayer.h"
ivand_qmul@121 32 #include "layer/Colour3DPlotLayer.h"
ivand_qmul@121 33 #include "layer/SliceLayer.h"
ivand_qmul@121 34 #include "layer/SliceableLayer.h"
ivand_qmul@121 35 #include "widgets/Fader.h"
ivand_qmul@121 36 #include "view/Overview.h"
ivand_qmul@121 37 #include "widgets/PropertyBox.h"
ivand_qmul@121 38 #include "widgets/PropertyStack.h"
ivand_qmul@121 39 #include "widgets/AudioDial.h"
ivand_qmul@121 40 #include "widgets/LayerTree.h"
ivand_qmul@121 41 #include "widgets/ListInputDialog.h"
ivand_qmul@121 42 #include "widgets/SubdividingMenu.h"
ivand_qmul@121 43 #include "widgets/NotifyingPushButton.h"
lbajardsilogic@2 44 #include "widgets/InfoWidget.h"
lbajardsilogic@2 45 #include "widgets/SearchWidget.h"
ivand_qmul@121 46 #include "widgets/QueryResultsWidget.h"
lbajardsilogic@143 47 #include "widgets/RelatedMediaWidget.h"
ivand_qmul@121 48 #include "widgets/ExpandWidget.h"
ivand_qmul@121 49 #include "widgets/AdvancedToolBox.h"
ivand_qmul@121 50 #include "widgets/ConnectionStatus.h"
ivand_qmul@121 51 #include "widgets/LayerViewerWidget.h"
ivand_qmul@121 52
ivand_qmul@121 53 #include "audioio/AudioCallbackPlaySource.h"
ivand_qmul@121 54 #include "audioio/AudioCallbackPlayTarget.h"
ivand_qmul@121 55 #include "audioio/AudioTargetFactory.h"
ivand_qmul@121 56 #include "audioio/PlaySpeedRangeMapper.h"
ivand_qmul@121 57 #include "data/fileio/AudioFileReaderFactory.h"
ivand_qmul@121 58 #include "data/fileio/DataFileReaderFactory.h"
ivand_qmul@121 59 #include "data/fileio/WavFileWriter.h"
ivand_qmul@121 60 #include "data/fileio/CSVFileWriter.h"
ivand_qmul@121 61 #include "data/fileio/BZipFileDevice.h"
ivand_qmul@121 62 #include "data/fileio/RemoteFile.h"
ivand_qmul@121 63 #include "data/fft/FFTDataServer.h"
ivand_qmul@121 64 #include "base/RecentFiles.h"
ivand_qmul@121 65 #include "transform/TransformFactory.h"
ivand_qmul@121 66 #include "base/PlayParameterRepository.h"
ivand_qmul@121 67 #include "base/XmlExportable.h"
ivand_qmul@121 68 #include "base/CommandHistory.h"
ivand_qmul@121 69 #include "base/Profiler.h"
ivand_qmul@121 70 #include "base/Clipboard.h"
ivand_qmul@121 71 #include "base/TempDirectory.h"
ivand_qmul@121 72 #include "osc/OSCQueue.h"
lbajardsilogic@21 73 #include "main/EasaierSessionManager.h"
ivand_qmul@121 74 #include "widgets/RealTimeFilterPropertyStack.h"
ivand_qmul@121 75 #include "filter/FilterStack.h"
ivand_qmul@121 76 #include "filter/RealTimeFilterFactory.h"
ivand_qmul@121 77
ivand_qmul@121 78 // For version information
ivand_qmul@121 79 #include "vamp/vamp.h"
ivand_qmul@121 80 #include "vamp-sdk/PluginBase.h"
ivand_qmul@121 81 #include "plugin/api/ladspa.h"
ivand_qmul@121 82 #include "plugin/api/dssi.h"
ivand_qmul@121 83
ivand_qmul@121 84 #include <QApplication>
ivand_qmul@121 85 #include <QMessageBox>
ivand_qmul@121 86 #include <QGridLayout>
ivand_qmul@121 87 #include <QLabel>
ivand_qmul@121 88 #include <QAction>
ivand_qmul@121 89 #include <QMenuBar>
ivand_qmul@121 90 #include <QToolBar>
ivand_qmul@121 91 #include <QInputDialog>
ivand_qmul@121 92 #include <QStatusBar>
ivand_qmul@121 93 #include <QTreeView>
ivand_qmul@121 94 #include <QFile>
ivand_qmul@121 95 #include <QFileInfo>
ivand_qmul@121 96 #include <QDir>
ivand_qmul@121 97 #include <QTextStream>
ivand_qmul@121 98 #include <QProcess>
ivand_qmul@121 99 #include <QShortcut>
ivand_qmul@121 100 #include <QSettings>
ivand_qmul@121 101 #include <QDateTime>
ivand_qmul@121 102 #include <QProcess>
ivand_qmul@121 103 #include <QCheckBox>
ivand_qmul@121 104 #include <QRegExp>
ivand_qmul@121 105 #include <QFileDialog>
ivand_qmul@121 106
ivand_qmul@121 107 #include <iostream>
ivand_qmul@121 108 #include <cstdio>
ivand_qmul@121 109 #include <errno.h>
ivand_qmul@121 110
ivand_qmul@121 111 using std::cerr;
ivand_qmul@121 112 using std::endl;
ivand_qmul@121 113
ivand_qmul@121 114 using std::vector;
ivand_qmul@121 115 using std::map;
ivand_qmul@121 116 using std::set;
ivand_qmul@121 117
ivand_qmul@129 118 extern long long countFreq;
ivand_qmul@129 119
lbajardsilogic@2 120 MainWindow * MainWindow::m_instance = 0;
lbajardsilogic@2 121
lbajardsilogic@2 122 MainWindow * MainWindow::instance()
lbajardsilogic@2 123 {
lbajardsilogic@2 124 return m_instance;
ivand_qmul@121 125 }
ivand_qmul@121 126
ivand_qmul@121 127 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) :
ivand_qmul@121 128 m_document(0),
ivand_qmul@121 129 m_paneStack(0),
ivand_qmul@121 130 m_viewManager(0),
ivand_qmul@121 131 m_overview(0),
ivand_qmul@121 132 m_timeRulerLayer(0),
ivand_qmul@121 133 m_audioOutput(withAudioOutput),
ivand_qmul@121 134 m_playSource(0),
ivand_qmul@121 135 m_playTarget(0),
ivand_qmul@121 136 m_oscQueue(withOSCSupport ? new OSCQueue() : 0),
ivand_qmul@121 137 m_recentFiles("RecentFiles", 20),
ivand_qmul@121 138 m_recentTransforms("RecentTransforms", 20),
ivand_qmul@121 139 m_mainMenusCreated(false),
ivand_qmul@121 140 m_paneMenu(0),
ivand_qmul@121 141 m_layerMenu(0),
ivand_qmul@121 142 m_transformsMenu(0),
ivand_qmul@121 143 m_existingLayersMenu(0),
ivand_qmul@121 144 m_sliceMenu(0),
ivand_qmul@121 145 m_recentFilesMenu(0),
ivand_qmul@121 146 m_recentTransformsMenu(0),
ivand_qmul@121 147 m_rightButtonMenu(0),
ivand_qmul@121 148 m_rightButtonLayerMenu(0),
ivand_qmul@121 149 m_rightButtonTransformsMenu(0),
ivand_qmul@121 150 m_documentModified(false),
ivand_qmul@121 151 m_openingAudioFile(false),
ivand_qmul@121 152 m_abandoning(false),
lbajardsilogic@135 153 m_preferencesDialog(0),
lbajardsilogic@214 154 m_playSpeedVal(1),
benoitrigolleau@217 155 m_curSender(0),
benoitrigolleau@217 156 m_nbLock(0)
ivand_qmul@121 157 {
benoitrigolleau@130 158
benoitrigolleau@130 159 m_videoWidget = 0;
ivand_qmul@121 160 m_instance = this;
ivand_qmul@121 161
ivand_qmul@121 162 setWindowTitle(tr("Sound Access"));
ivand_qmul@121 163
ivand_qmul@121 164 UnitDatabase::getInstance()->registerUnit("Hz");
ivand_qmul@121 165 UnitDatabase::getInstance()->registerUnit("dB");
ivand_qmul@121 166
ivand_qmul@121 167 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
ivand_qmul@121 168 this, SLOT(documentModified()));
ivand_qmul@121 169 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
ivand_qmul@121 170 this, SLOT(documentRestored()));
ivand_qmul@121 171
ivand_qmul@121 172 QFrame *frame = new QFrame;
ivand_qmul@121 173 setCentralWidget(frame);
ivand_qmul@121 174
ivand_qmul@121 175 QGridLayout *layout = new QGridLayout;
ivand_qmul@121 176
ivand_qmul@121 177 m_viewManager = new ViewManager();
ivand_qmul@121 178 connect(m_viewManager, SIGNAL(selectionChanged()),
ivand_qmul@121 179 this, SLOT(updateMenuStates()));
ivand_qmul@121 180 connect(m_viewManager, SIGNAL(inProgressSelectionChanged()),
ivand_qmul@121 181 this, SLOT(inProgressSelectionChanged()));
ivand_qmul@121 182
ivand_qmul@121 183 m_descriptionLabel = new QLabel;
ivand_qmul@121 184
ivand_qmul@121 185 m_paneStack = new PaneStack(frame, m_viewManager);
ivand_qmul@121 186 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
ivand_qmul@121 187 this, SLOT(currentPaneChanged(Pane *)));
ivand_qmul@121 188 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
ivand_qmul@121 189 this, SLOT(currentLayerChanged(Pane *, Layer *)));
ivand_qmul@121 190 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
ivand_qmul@121 191 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
ivand_qmul@121 192 connect(m_paneStack, SIGNAL(propertyStacksResized()),
ivand_qmul@121 193 this, SLOT(propertyStacksResized()));
ivand_qmul@121 194 connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)),
ivand_qmul@121 195 this, SLOT(contextHelpChanged(const QString &)));
ivand_qmul@121 196
ivand_qmul@121 197 m_overview = new Overview(frame);
ivand_qmul@121 198 m_overview->setViewManager(m_viewManager);
ivand_qmul@121 199 m_overview->setFixedHeight(40);
ivand_qmul@121 200 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
ivand_qmul@121 201 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
ivand_qmul@121 202 this, SLOT(contextHelpChanged(const QString &)));
ivand_qmul@121 203
ivand_qmul@121 204 m_panLayer = new WaveformLayer;
ivand_qmul@121 205 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
ivand_qmul@121 206 // m_panLayer->setScale(WaveformLayer::MeterScale);
ivand_qmul@121 207 // m_panLayer->setAutoNormalize(true);
ivand_qmul@121 208 m_panLayer->setBaseColour(Qt::darkGreen);
ivand_qmul@121 209 m_panLayer->setAggressiveCacheing(true);
ivand_qmul@121 210 m_overview->addLayer(m_panLayer);
ivand_qmul@121 211
ivand_qmul@121 212 m_playSource = new AudioCallbackPlaySource(m_viewManager);
ivand_qmul@121 213
ivand_qmul@121 214 connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)),
ivand_qmul@121 215 this, SLOT(sampleRateMismatch(size_t, size_t, bool)));
ivand_qmul@121 216 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
ivand_qmul@121 217 this, SLOT(audioOverloadPluginDisabled()));
ivand_qmul@121 218
ivand_qmul@121 219 m_fader = new Fader(frame, false);
ivand_qmul@121 220 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
ivand_qmul@121 221 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
ivand_qmul@121 222
lbajardsilogic@127 223 /* m_playSpeed = new AudioDial(frame);
ivand_qmul@121 224 m_playSpeed->setMinimum(0);
ivand_qmul@121 225 m_playSpeed->setMaximum(200);
ivand_qmul@121 226 m_playSpeed->setValue(100);
ivand_qmul@121 227 m_playSpeed->setFixedWidth(24);
ivand_qmul@121 228 m_playSpeed->setFixedHeight(24);
ivand_qmul@121 229 m_playSpeed->setNotchesVisible(true);
ivand_qmul@121 230 m_playSpeed->setPageStep(10);
ivand_qmul@121 231 m_playSpeed->setObjectName(tr("Playback Speedup"));
ivand_qmul@121 232 m_playSpeed->setDefaultValue(100);
ivand_qmul@121 233 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
ivand_qmul@121 234 m_playSpeed->setShowToolTip(true);
ivand_qmul@121 235 connect(m_playSpeed, SIGNAL(valueChanged(int)),
ivand_qmul@121 236 this, SLOT(playSpeedChanged(int)));
ivand_qmul@121 237 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
ivand_qmul@121 238 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
ivand_qmul@121 239
ivand_qmul@121 240 m_playSharpen = new NotifyingPushButton(frame);
ivand_qmul@121 241 m_playSharpen->setToolTip(tr("Sharpen percussive transients"));
ivand_qmul@121 242 m_playSharpen->setFixedSize(20, 20);
ivand_qmul@121 243 // m_playSharpen->setFlat(true);
ivand_qmul@121 244 m_playSharpen->setEnabled(false);
ivand_qmul@121 245 m_playSharpen->setCheckable(true);
ivand_qmul@121 246 m_playSharpen->setChecked(false);
ivand_qmul@121 247 m_playSharpen->setIcon(QIcon(":icons/sharpen.png"));
ivand_qmul@121 248 connect(m_playSharpen, SIGNAL(clicked()), this, SLOT(playSharpenToggled()));
ivand_qmul@121 249 connect(m_playSharpen, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
ivand_qmul@121 250 connect(m_playSharpen, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
ivand_qmul@121 251
ivand_qmul@121 252 m_playMono = new NotifyingPushButton(frame);
ivand_qmul@121 253 m_playMono->setToolTip(tr("Run time stretcher in mono only"));
ivand_qmul@121 254 m_playMono->setFixedSize(20, 20);
ivand_qmul@121 255 // m_playMono->setFlat(true);
ivand_qmul@121 256 m_playMono->setEnabled(false);
ivand_qmul@121 257 m_playMono->setCheckable(true);
ivand_qmul@121 258 m_playMono->setChecked(false);
ivand_qmul@121 259 m_playMono->setIcon(QIcon(":icons/mono.png"));
ivand_qmul@121 260 connect(m_playMono, SIGNAL(clicked()), this, SLOT(playMonoToggled()));
ivand_qmul@121 261 connect(m_playMono, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
ivand_qmul@121 262 connect(m_playMono, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
lbajardsilogic@127 263 */
lbajardsilogic@127 264
lbajardsilogic@127 265 /*QSettings settings;
ivand_qmul@121 266 settings.beginGroup("MainWindow");
ivand_qmul@121 267 m_playSharpen->setChecked(settings.value("playsharpen", true).toBool());
ivand_qmul@121 268 m_playMono->setChecked(settings.value("playmono", false).toBool());
lbajardsilogic@127 269 settings.endGroup();*/
ivand_qmul@121 270
lbajardsilogic@154 271 m_relMediaWidget = new RelatedMediaWidget();
lbajardsilogic@154 272 m_infoWidget = new InfoWidget(m_relMediaWidget);
lbajardsilogic@2 273 m_searchWidget = new SearchWidget();
ivand_qmul@121 274 m_resultsWidget = new QueryResultsWidget();
lbajardsilogic@154 275
lbajardsilogic@2 276 m_qtabwidget = new QTabWidget();
lbajardsilogic@2 277 m_qtabwidget->addTab(m_searchWidget, tr("Search"));
lbajardsilogic@2 278 m_qtabwidget->addTab(m_resultsWidget, tr("Result"));
lbajardsilogic@2 279 m_qtabwidget->addTab(m_infoWidget, tr("Info"));
lbajardsilogic@154 280 //m_qtabwidget->addTab(m_relMediaWidget, tr("Related media"));
ivand_qmul@121 281
lbajardsilogic@2 282 QGridLayout *auxlayout = new QGridLayout;
benoitrigolleau@130 283 auxlayout->addWidget(m_paneStack, 0, 0, 1, 2);
ivand_qmul@121 284 auxlayout->addWidget(m_overview, 1, 0);
ivand_qmul@121 285 auxlayout->addWidget(m_fader, 1, 1);
lbajardsilogic@127 286 //auxlayout->addWidget(m_playSpeed, 1, 2);
lbajardsilogic@127 287 //auxlayout->addWidget(m_playSharpen, 1, 3);
lbajardsilogic@127 288 //auxlayout->addWidget(m_playMono, 1, 4);
lbajardsilogic@2 289 QWidget *auxwidget = new QWidget;
lbajardsilogic@2 290 auxwidget->setLayout(auxlayout);
lbajardsilogic@2 291
lbajardsilogic@101 292 m_leftExpandWidget = new ExpandWidget();
lbajardsilogic@101 293 m_leftExpandWidget->setWidgetLocation(ExpandWidget::Location_Bottom);
lbajardsilogic@101 294 m_leftExpandWidget->setPanes(auxwidget, m_qtabwidget);
lbajardsilogic@101 295 m_leftExpandWidget->setPercentage( 1, 4);
lbajardsilogic@2 296
lbajardsilogic@2 297 m_toolBox = new AdvancedToolBox();
lbajardsilogic@2 298 m_toolBox->addItem("Layers", new QWidget);
benoitrigolleau@74 299
lbajardsilogic@79 300 m_filterPropertyStack = new RealTimeFilterPropertyStack();
lbajardsilogic@79 301 m_toolBox->addItem("Real-time filters",m_filterPropertyStack);
lbajardsilogic@98 302
lbajardsilogic@206 303 connect(m_filterPropertyStack, SIGNAL(contextHelpChanged(const QString &)),
lbajardsilogic@206 304 this, SLOT(contextHelpChanged(const QString &)));
lbajardsilogic@206 305
benoitrigolleau@58 306 /******** only for logo ****/
benoitrigolleau@58 307 QLabel *logo = new QLabel;
benoitrigolleau@58 308 logo->setPixmap(QPixmap(":icons/easaier.png"));
benoitrigolleau@58 309 logo->setMinimumSize(0,0);
benoitrigolleau@58 310 logo->setAlignment(Qt::AlignRight);
benoitrigolleau@58 311
benoitrigolleau@58 312 QVBoxLayout *logoLayout= new QVBoxLayout;
benoitrigolleau@58 313 logoLayout->setMargin(0);
benoitrigolleau@58 314 logoLayout->setSpacing(0);
benoitrigolleau@58 315 logoLayout->addWidget(m_toolBox);
benoitrigolleau@58 316 logoLayout->addStretch();
benoitrigolleau@58 317 logoLayout->addWidget(logo);
lbajardsilogic@98 318
benoitrigolleau@58 319 QWidget *widgetAuxForLogo = new QWidget;
benoitrigolleau@58 320 widgetAuxForLogo->setLayout(logoLayout);
benoitrigolleau@58 321 /****************************/
benoitrigolleau@58 322
benoitrigolleau@130 323 /************video***********/
benoitrigolleau@145 324 m_sdlWidget = new SDLWidget();
benoitrigolleau@130 325 QHBoxLayout *videoHLayout= new QHBoxLayout;
benoitrigolleau@144 326
benoitrigolleau@130 327 videoHLayout->addStretch();
benoitrigolleau@145 328 videoHLayout->addWidget(m_sdlWidget);
benoitrigolleau@130 329 videoHLayout->addStretch();
benoitrigolleau@130 330 QVBoxLayout *videoVLayout= new QVBoxLayout;
benoitrigolleau@130 331 videoVLayout->addStretch();
benoitrigolleau@130 332 videoVLayout->addLayout(videoHLayout);
benoitrigolleau@130 333 videoVLayout->addStretch();
benoitrigolleau@130 334
benoitrigolleau@130 335 QWidget *ttaux = new QWidget;
benoitrigolleau@130 336 ttaux->setLayout(videoVLayout);
benoitrigolleau@139 337
benoitrigolleau@139 338 QScrollArea *sa = new QScrollArea();
benoitrigolleau@139 339 sa->setWidgetResizable( true );
benoitrigolleau@139 340 sa->setWidget( ttaux );
benoitrigolleau@139 341
benoitrigolleau@139 342 m_qtabwidget->addTab(sa, tr("Video"));
benoitrigolleau@130 343
benoitrigolleau@130 344 /****************************/
benoitrigolleau@130 345
lbajardsilogic@101 346 m_rightExpandWidget = new ExpandWidget();
lbajardsilogic@101 347 m_rightExpandWidget->setWidgetLocation(ExpandWidget::Location_Right);
lbajardsilogic@101 348 m_rightExpandWidget->setPanes(m_leftExpandWidget, widgetAuxForLogo);
lbajardsilogic@101 349 m_rightExpandWidget->setPercentage( 3, 1);
lbajardsilogic@2 350
ivand_qmul@121 351 layout->addWidget(m_rightExpandWidget, 0, 0);
ivand_qmul@121 352
ivand_qmul@121 353 m_paneStack->setPropertyStackMinWidth
lbajardsilogic@127 354 (m_fader->width() /*+ m_playSpeed->width() + m_playSharpen->width() +
lbajardsilogic@127 355 m_playMono->width()*/ + layout->spacing() * 4);
ivand_qmul@121 356
ivand_qmul@121 357 layout->setColumnStretch(0, 10);
ivand_qmul@121 358
ivand_qmul@121 359 frame->setLayout(layout);
ivand_qmul@121 360
ivand_qmul@121 361 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
ivand_qmul@121 362 this, SLOT(outputLevelsChanged(float, float)));
ivand_qmul@121 363
ivand_qmul@121 364 connect(m_viewManager, SIGNAL(playbackFrameChanged(unsigned long)),
ivand_qmul@121 365 this, SLOT(playbackFrameChanged(unsigned long)));
ivand_qmul@121 366
ivand_qmul@121 367 connect(m_viewManager, SIGNAL(globalCentreFrameChanged(unsigned long)),
ivand_qmul@121 368 this, SLOT(globalCentreFrameChanged(unsigned long)));
ivand_qmul@121 369
ivand_qmul@121 370 connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, unsigned long)),
ivand_qmul@121 371 this, SLOT(viewCentreFrameChanged(View *, unsigned long)));
ivand_qmul@121 372
ivand_qmul@121 373 connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, unsigned long, bool)),
ivand_qmul@121 374 this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool)));
ivand_qmul@121 375
lbajardsilogic@204 376 /*connect(Preferences::getInstance(),
ivand_qmul@121 377 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
ivand_qmul@121 378 this,
lbajardsilogic@204 379 SLOT(preferenceChanged(PropertyContainer::PropertyName)));*/
ivand_qmul@121 380
ivand_qmul@121 381 if (m_oscQueue && m_oscQueue->isOK()) {
ivand_qmul@121 382 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
ivand_qmul@121 383 QTimer *oscTimer = new QTimer(this);
ivand_qmul@121 384 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
ivand_qmul@121 385 oscTimer->start(1000);
ivand_qmul@121 386 }
ivand_qmul@121 387
ivand_qmul@121 388 m_httpClient = new HttpClient(TempDirectory::getInstance()->getConfigPath());
lbajardsilogic@21 389 m_EasaierManager = new EasaierSessionManager(m_httpClient);
lbajardsilogic@21 390
lbajardsilogic@21 391 connect(m_EasaierManager, SIGNAL(queryModelLoaded(QueryModel*)),
ivand_qmul@121 392 this, SLOT(queryModelLoaded(QueryModel*)));
ivand_qmul@121 393
benoitrigolleau@217 394
lbajardsilogic@214 395 connect(m_EasaierManager, SIGNAL(audioFileLoaded()),
lbajardsilogic@214 396 this, SLOT(audioFileLoaded()));
lbajardsilogic@214 397
benoitrigolleau@217 398 connect(m_EasaierManager, SIGNAL(audioFileLoaded()),
benoitrigolleau@217 399 this, SLOT(unlockWindow()));
benoitrigolleau@217 400
ivand_qmul@121 401 setupMenus();
ivand_qmul@121 402 setupToolbars();
ivand_qmul@121 403
ivand_qmul@121 404 statusBar();
ivand_qmul@121 405
lbajardsilogic@202 406 newEasaierSession();
ivand_qmul@121 407
ivand_qmul@121 408 }
benoitrigolleau@217 409
benoitrigolleau@217 410 void MainWindow::lockWindow(){
benoitrigolleau@217 411 //lock the menu
benoitrigolleau@217 412 QWidget *menu = this->menuWidget();
benoitrigolleau@217 413 if(menu){
benoitrigolleau@217 414 menu->setEnabled(false);
benoitrigolleau@217 415 }
benoitrigolleau@217 416
benoitrigolleau@217 417 // lock the toolbar
benoitrigolleau@217 418 for(int i=0; i< m_toolBarVector.count();i++){
benoitrigolleau@217 419 m_toolBarVectorValues.append(m_toolBarVector[i]->isEnabled());
benoitrigolleau@217 420 m_toolBarVector[i]->setEnabled(false);
benoitrigolleau@217 421 }
benoitrigolleau@217 422
benoitrigolleau@217 423 //lock the central widget
benoitrigolleau@217 424
benoitrigolleau@217 425 QWidget *centralWidget = this->centralWidget();
benoitrigolleau@217 426 if(centralWidget){
benoitrigolleau@217 427 QLayout *centralLayout = centralWidget->layout();
benoitrigolleau@217 428 if(centralLayout){
benoitrigolleau@217 429 m_waitwidget = new WaitingWidget;
benoitrigolleau@217 430 m_waitwidget->setAnimation(true);
benoitrigolleau@217 431 ((QGridLayout*) centralLayout)->addWidget(m_waitwidget , 0,0);
benoitrigolleau@217 432 m_waitwidget->setGeometry(-20,-20,100,100);
benoitrigolleau@217 433 }
benoitrigolleau@217 434 }
benoitrigolleau@217 435 m_nbLock++;
benoitrigolleau@217 436 }
benoitrigolleau@217 437
benoitrigolleau@217 438 void MainWindow::unlockWindow(){
benoitrigolleau@217 439 m_nbLock--;
benoitrigolleau@217 440 if(m_nbLock<=0){
benoitrigolleau@217 441 //unlock the menu
benoitrigolleau@217 442 QWidget *menu = this->menuWidget();
benoitrigolleau@217 443 if(menu){
benoitrigolleau@217 444 menu->setEnabled(true);
benoitrigolleau@217 445 }
benoitrigolleau@217 446
benoitrigolleau@217 447 // unlock the toolbar
benoitrigolleau@217 448 for(int i=0; i< m_toolBarVector.count();i++){
benoitrigolleau@217 449 m_toolBarVector[i]->setEnabled(m_toolBarVectorValues[i]);
benoitrigolleau@217 450 }
benoitrigolleau@217 451 m_toolBarVectorValues.clear();
benoitrigolleau@217 452
benoitrigolleau@217 453 // unlock the central widget
benoitrigolleau@217 454 QWidget *centralWidget = this->centralWidget();
benoitrigolleau@217 455 if(centralWidget){
benoitrigolleau@217 456 QLayout *centralLayout = centralWidget->layout();
benoitrigolleau@217 457 if(centralLayout){
benoitrigolleau@217 458 centralLayout->removeWidget(m_waitwidget);
benoitrigolleau@217 459 delete m_waitwidget;
benoitrigolleau@217 460
benoitrigolleau@217 461 }
benoitrigolleau@217 462 }
benoitrigolleau@217 463 }
benoitrigolleau@217 464 }
benoitrigolleau@217 465
ivand_qmul@121 466
ivand_qmul@121 467 MainWindow::~MainWindow()
ivand_qmul@121 468 {
ivand_qmul@121 469 // std::cerr << "MainWindow::~MainWindow()" << std::endl;
ivand_qmul@121 470
ivand_qmul@121 471 if (!m_abandoning) {
ivand_qmul@121 472 closeSession();
ivand_qmul@121 473 }
lbajardsilogic@21 474 delete m_EasaierManager;
ivand_qmul@121 475 delete m_httpClient;
ivand_qmul@121 476 delete m_playTarget;
ivand_qmul@121 477 delete m_playSource;
ivand_qmul@121 478 delete m_viewManager;
ivand_qmul@121 479 delete m_oscQueue;
ivand_qmul@121 480 Profiles::getInstance()->dump();
ivand_qmul@121 481
ivand_qmul@121 482 m_instance = 0;
ivand_qmul@121 483 }
ivand_qmul@121 484
benoitrigolleau@130 485 QWidget* MainWindow::getVideoWidget(){
benoitrigolleau@130 486 return m_videoWidget;
benoitrigolleau@130 487 }
benoitrigolleau@130 488
ivand_qmul@121 489 QString
ivand_qmul@121 490 MainWindow::getOpenFileName(FileFinder::FileType type)
ivand_qmul@121 491 {
ivand_qmul@121 492 FileFinder *ff = FileFinder::getInstance();
ivand_qmul@121 493 switch (type) {
ivand_qmul@121 494 case FileFinder::SessionFile:
ivand_qmul@121 495 return ff->getOpenFileName(type, m_sessionFile);
ivand_qmul@121 496 case FileFinder::AudioFile:
ivand_qmul@121 497 return ff->getOpenFileName(type, m_audioFile);
ivand_qmul@121 498 // Ivan Damnjanovic 09-10/2007 added video file import
ivand_qmul@121 499 case FileFinder::VideoFile:
ivand_qmul@121 500 return ff->getOpenFileName(type, m_videoFile);
ivand_qmul@121 501 //
ivand_qmul@121 502 case FileFinder::LayerFile:
ivand_qmul@121 503 return ff->getOpenFileName(type, m_sessionFile);
ivand_qmul@121 504 case FileFinder::SessionOrAudioFile:
ivand_qmul@121 505 return ff->getOpenFileName(type, m_sessionFile);
ivand_qmul@121 506 case FileFinder::ImageFile:
ivand_qmul@121 507 return ff->getOpenFileName(type, m_sessionFile);
ivand_qmul@121 508 case FileFinder::AnyFile:
ivand_qmul@121 509 if (getMainModel() != 0 &&
ivand_qmul@121 510 m_paneStack != 0 &&
ivand_qmul@121 511 m_paneStack->getCurrentPane() != 0) { // can import a layer
ivand_qmul@121 512 return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile);
ivand_qmul@121 513 } else {
ivand_qmul@121 514 return ff->getOpenFileName(FileFinder::SessionOrAudioFile,
ivand_qmul@121 515 m_sessionFile);
ivand_qmul@121 516 }
ivand_qmul@121 517 }
ivand_qmul@121 518 return "";
ivand_qmul@121 519 }
ivand_qmul@121 520
ivand_qmul@121 521 QString
ivand_qmul@121 522 MainWindow::getSaveFileName(FileFinder::FileType type)
ivand_qmul@121 523 {
ivand_qmul@121 524 FileFinder *ff = FileFinder::getInstance();
ivand_qmul@121 525 switch (type) {
ivand_qmul@121 526 case FileFinder::SessionFile:
ivand_qmul@121 527 return ff->getSaveFileName(type, m_sessionFile);
ivand_qmul@121 528 case FileFinder::AudioFile:
ivand_qmul@121 529 return ff->getSaveFileName(type, m_audioFile);
ivand_qmul@121 530 case FileFinder::LayerFile:
ivand_qmul@121 531 return ff->getSaveFileName(type, m_sessionFile);
ivand_qmul@121 532 case FileFinder::SessionOrAudioFile:
ivand_qmul@121 533 return ff->getSaveFileName(type, m_sessionFile);
ivand_qmul@121 534 case FileFinder::ImageFile:
ivand_qmul@121 535 return ff->getSaveFileName(type, m_sessionFile);
ivand_qmul@121 536 case FileFinder::AnyFile:
ivand_qmul@121 537 return ff->getSaveFileName(type, m_sessionFile);
ivand_qmul@121 538 }
ivand_qmul@121 539 return "";
ivand_qmul@121 540 }
ivand_qmul@121 541
ivand_qmul@121 542 void
ivand_qmul@121 543 MainWindow::registerLastOpenedFilePath(FileFinder::FileType type, QString path)
ivand_qmul@121 544 {
ivand_qmul@121 545 FileFinder *ff = FileFinder::getInstance();
ivand_qmul@121 546 ff->registerLastOpenedFilePath(type, path);
ivand_qmul@121 547 }
ivand_qmul@121 548
ivand_qmul@121 549 void
ivand_qmul@121 550 MainWindow::setupMenus()
ivand_qmul@121 551 {
ivand_qmul@121 552 if (!m_mainMenusCreated) {
ivand_qmul@121 553 m_rightButtonMenu = new QMenu();
ivand_qmul@121 554
ivand_qmul@121 555 // No -- we don't want tear-off enabled on the right-button
ivand_qmul@121 556 // menu. If it is enabled, then simply right-clicking and
ivand_qmul@121 557 // releasing will pop up the menu, activate the tear-off, and
ivand_qmul@121 558 // leave the torn-off menu window in front of the main window.
ivand_qmul@121 559 // That isn't desirable. I'm not sure it ever would be, in a
ivand_qmul@121 560 // context menu -- perhaps technically a Qt bug?
ivand_qmul@121 561 // m_rightButtonMenu->setTearOffEnabled(true);
ivand_qmul@121 562 }
ivand_qmul@121 563
ivand_qmul@121 564 if (m_rightButtonLayerMenu) {
ivand_qmul@121 565 m_rightButtonLayerMenu->clear();
ivand_qmul@121 566 } else {
ivand_qmul@121 567 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
ivand_qmul@121 568 m_rightButtonLayerMenu->setTearOffEnabled(true);
ivand_qmul@121 569 m_rightButtonMenu->addSeparator();
ivand_qmul@121 570 }
ivand_qmul@121 571
ivand_qmul@121 572 if (m_rightButtonTransformsMenu) {
ivand_qmul@121 573 m_rightButtonTransformsMenu->clear();
ivand_qmul@121 574 } else {
ivand_qmul@121 575 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
ivand_qmul@121 576 m_rightButtonTransformsMenu->setTearOffEnabled(true);
ivand_qmul@121 577 m_rightButtonMenu->addSeparator();
ivand_qmul@121 578 }
ivand_qmul@121 579
ivand_qmul@121 580 if (!m_mainMenusCreated) {
ivand_qmul@121 581 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
ivand_qmul@121 582 m_rightButtonMenu->addSeparator();
ivand_qmul@121 583 }
ivand_qmul@121 584
ivand_qmul@121 585 setupFileMenu();
ivand_qmul@121 586 setupEasaierMenu();
ivand_qmul@121 587 setupEditMenu();
ivand_qmul@121 588 setupViewMenu();
ivand_qmul@121 589 setupPaneAndLayerMenus();
ivand_qmul@121 590 setupTransformsMenu();
ivand_qmul@121 591 setupSettingMenu();
ivand_qmul@121 592 setupHelpMenu();
ivand_qmul@121 593
ivand_qmul@121 594 m_mainMenusCreated = true;
ivand_qmul@121 595 }
ivand_qmul@121 596
ivand_qmul@121 597 void
ivand_qmul@121 598 MainWindow::setupFileMenu()
ivand_qmul@121 599 {
ivand_qmul@121 600 if (m_mainMenusCreated) return;
ivand_qmul@121 601
ivand_qmul@121 602 QMenu *menu = menuBar()->addMenu(tr("&File"));
ivand_qmul@121 603 menu->setTearOffEnabled(true);
ivand_qmul@121 604 //QToolBar *toolbar = addToolBar(tr("File Toolbar"));
ivand_qmul@121 605
ivand_qmul@121 606 QIcon icon(":icons/filenew.png");
ivand_qmul@121 607 icon.addFile(":icons/filenew-22.png");
ivand_qmul@121 608 QAction *action = new QAction(icon, tr("&New Session"), this);
ivand_qmul@121 609 action->setShortcut(tr("Ctrl+N"));
ivand_qmul@121 610 action->setStatusTip(tr("Abandon the current Sonic Visualiser session and start a new one"));
ivand_qmul@121 611 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
ivand_qmul@121 612 menu->addAction(action);
ivand_qmul@121 613 //toolbar->addAction(action);
ivand_qmul@121 614
ivand_qmul@121 615 icon = QIcon(":icons/fileopensession.png");
ivand_qmul@121 616 action = new QAction(icon, tr("&Open Session..."), this);
ivand_qmul@121 617 action->setShortcut(tr("Ctrl+O"));
ivand_qmul@121 618 action->setStatusTip(tr("Open a previously saved Sonic Visualiser session file"));
ivand_qmul@121 619 connect(action, SIGNAL(triggered()), this, SLOT(openSession()));
ivand_qmul@121 620 menu->addAction(action);
ivand_qmul@121 621
ivand_qmul@121 622 icon = QIcon(":icons/fileopen.png");
ivand_qmul@121 623 icon.addFile(":icons/fileopen-22.png");
ivand_qmul@121 624
ivand_qmul@121 625 action = new QAction(icon, tr("&Open..."), this);
ivand_qmul@121 626 action->setStatusTip(tr("Open a session file, audio file, or layer"));
ivand_qmul@121 627 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
ivand_qmul@121 628 //toolbar->addAction(action);
ivand_qmul@121 629
ivand_qmul@121 630 icon = QIcon(":icons/filesave.png");
ivand_qmul@121 631 icon.addFile(":icons/filesave-22.png");
ivand_qmul@121 632 action = new QAction(icon, tr("&Save Session"), this);
ivand_qmul@121 633 action->setShortcut(tr("Ctrl+S"));
ivand_qmul@121 634 action->setStatusTip(tr("Save the current session into a Sonic Visualiser session file"));
ivand_qmul@121 635 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
ivand_qmul@121 636 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 637 menu->addAction(action);
ivand_qmul@121 638 //toolbar->addAction(action);
ivand_qmul@121 639
ivand_qmul@121 640 icon = QIcon(":icons/filesaveas.png");
ivand_qmul@121 641 icon.addFile(":icons/filesaveas-22.png");
ivand_qmul@121 642 action = new QAction(icon, tr("Save Session &As..."), this);
ivand_qmul@121 643 action->setStatusTip(tr("Save the current session into a new Sonic Visualiser session file"));
ivand_qmul@121 644 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
ivand_qmul@121 645 menu->addAction(action);
ivand_qmul@121 646 //toolbar->addAction(action);
ivand_qmul@121 647
ivand_qmul@121 648 menu->addSeparator();
ivand_qmul@121 649
ivand_qmul@121 650 icon = QIcon(":icons/fileopenaudio.png");
ivand_qmul@121 651 action = new QAction(icon, tr("&Import Audio File..."), this);
ivand_qmul@121 652 action->setShortcut(tr("Ctrl+I"));
ivand_qmul@121 653 action->setStatusTip(tr("Import an existing audio file"));
ivand_qmul@121 654 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
ivand_qmul@121 655 menu->addAction(action);
ivand_qmul@121 656
ivand_qmul@121 657 action = new QAction(tr("Import Secondary Audio File..."), this);
ivand_qmul@121 658 action->setShortcut(tr("Ctrl+Shift+I"));
ivand_qmul@121 659 action->setStatusTip(tr("Import an extra audio file as a separate layer"));
ivand_qmul@121 660 connect(action, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
ivand_qmul@121 661 connect(this, SIGNAL(canImportMoreAudio(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 662 menu->addAction(action);
ivand_qmul@121 663
ivand_qmul@121 664 action = new QAction(tr("&Export Audio File..."), this);
ivand_qmul@121 665 action->setStatusTip(tr("Export selection as an audio file"));
ivand_qmul@121 666 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
ivand_qmul@121 667 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 668 menu->addAction(action);
ivand_qmul@121 669 // Ivan Damnjanovic 09-10/2007 added video file import
ivand_qmul@121 670 menu->addSeparator();
ivand_qmul@121 671 action = new QAction(tr("&Import Video File..."), this);
ivand_qmul@121 672 action->setShortcut(tr("Ctrl+Alt+I"));
ivand_qmul@121 673 action->setStatusTip(tr("Import an existing video file"));
ivand_qmul@121 674 connect(action, SIGNAL(triggered()), this, SLOT(importVideo()));
ivand_qmul@121 675 menu->addAction(action);
ivand_qmul@121 676 //
ivand_qmul@121 677 menu->addSeparator();
ivand_qmul@121 678
ivand_qmul@121 679 action = new QAction(tr("Import Annotation &Layer..."), this);
ivand_qmul@121 680 action->setShortcut(tr("Ctrl+L"));
ivand_qmul@121 681 action->setStatusTip(tr("Import layer data from an existing file"));
ivand_qmul@121 682 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
ivand_qmul@121 683 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 684 menu->addAction(action);
ivand_qmul@121 685
ivand_qmul@121 686 action = new QAction(tr("Export Annotation Layer..."), this);
ivand_qmul@121 687 action->setStatusTip(tr("Export layer data to a file"));
ivand_qmul@121 688 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
ivand_qmul@121 689 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 690 menu->addAction(action);
ivand_qmul@121 691
ivand_qmul@121 692 menu->addSeparator();
ivand_qmul@121 693
ivand_qmul@121 694 action = new QAction(tr("Export Image File..."), this);
ivand_qmul@121 695 action->setStatusTip(tr("Export a single pane to an image file"));
ivand_qmul@121 696 connect(action, SIGNAL(triggered()), this, SLOT(exportImage()));
ivand_qmul@121 697 connect(this, SIGNAL(canExportImage(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 698 menu->addAction(action);
ivand_qmul@121 699
ivand_qmul@121 700 menu->addSeparator();
ivand_qmul@121 701
ivand_qmul@121 702 action = new QAction(tr("Open Lo&cation..."), this);
ivand_qmul@121 703 action->setShortcut(tr("Ctrl+Shift+O"));
ivand_qmul@121 704 action->setStatusTip(tr("Open or import a file from a remote URL"));
ivand_qmul@121 705 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
ivand_qmul@121 706 menu->addAction(action);
ivand_qmul@121 707
ivand_qmul@121 708 menu->addSeparator();
ivand_qmul@121 709
ivand_qmul@121 710 m_recentFilesMenu = menu->addMenu(tr("&Recent Files"));
ivand_qmul@121 711 m_recentFilesMenu->setTearOffEnabled(true);
ivand_qmul@121 712 setupRecentFilesMenu();
ivand_qmul@121 713 connect(&m_recentFiles, SIGNAL(recentChanged()),
ivand_qmul@121 714 this, SLOT(setupRecentFilesMenu()));
ivand_qmul@121 715
ivand_qmul@121 716 menu->addSeparator();
ivand_qmul@121 717 action = new QAction(tr("&Preferences..."), this);
ivand_qmul@121 718 action->setStatusTip(tr("Adjust the application preferences"));
ivand_qmul@121 719 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
ivand_qmul@121 720 menu->addAction(action);
ivand_qmul@121 721
ivand_qmul@121 722 /*!!!
ivand_qmul@121 723 menu->addSeparator();
ivand_qmul@121 724
ivand_qmul@121 725 action = new QAction(tr("Play / Pause"), this);
ivand_qmul@121 726 action->setShortcut(tr("Space"));
ivand_qmul@121 727 action->setStatusTip(tr("Start or stop playback from the current position"));
ivand_qmul@121 728 connect(action, SIGNAL(triggered()), this, SLOT(play()));
ivand_qmul@121 729 menu->addAction(action);
ivand_qmul@121 730 */
ivand_qmul@121 731
ivand_qmul@121 732 menu->addSeparator();
ivand_qmul@121 733 action = new QAction(QIcon(":/icons/exit.png"),
ivand_qmul@121 734 tr("&Quit"), this);
ivand_qmul@121 735 action->setShortcut(tr("Ctrl+Q"));
ivand_qmul@121 736 action->setStatusTip(tr("Exit Sonic Visualiser"));
ivand_qmul@121 737 connect(action, SIGNAL(triggered()), this, SLOT(exit()));
ivand_qmul@121 738 menu->addAction(action);
ivand_qmul@121 739 }
ivand_qmul@121 740
ivand_qmul@121 741 void
ivand_qmul@121 742 MainWindow::setupEasaierMenu()
ivand_qmul@121 743 {
lbajardsilogic@21 744 if (m_mainMenusCreated) return;
lbajardsilogic@21 745
lbajardsilogic@21 746 QMenu* menu = menuBar()->addMenu(tr("&Easaier"));
lbajardsilogic@21 747 QToolBar *toolbar = addToolBar(tr("Easaier session Toolbar"));
benoitrigolleau@217 748 m_toolBarVector.append(toolbar);
lbajardsilogic@21 749
lbajardsilogic@21 750 QIcon icon(":icons/filenew.png");
lbajardsilogic@21 751 QAction *action = new QAction(icon, tr("&New Session"), this);
lbajardsilogic@21 752 action->setShortcut(tr("Ctrl+N"));
lbajardsilogic@21 753 action->setStatusTip(tr("Clear the current Easaier session and start a new one"));
lbajardsilogic@21 754 connect(action, SIGNAL(triggered()), this, SLOT(newEasaierSession()));
lbajardsilogic@21 755 menu->addAction(action);
lbajardsilogic@21 756 toolbar->addAction(action);
lbajardsilogic@21 757
lbajardsilogic@21 758 icon = QIcon(":icons/fileopen.png");
lbajardsilogic@21 759 action = new QAction(icon, tr("&Open Session..."), this);
lbajardsilogic@21 760 action->setShortcut(tr("Ctrl+O"));
lbajardsilogic@21 761 action->setStatusTip(tr("Open a previously saved Easaier session file"));
lbajardsilogic@21 762 connect(action, SIGNAL(triggered()), this, SLOT(openEasaierSession()));
lbajardsilogic@21 763 menu->addAction(action);
lbajardsilogic@21 764 toolbar->addAction(action);
lbajardsilogic@21 765
lbajardsilogic@21 766 icon = QIcon(":icons/filesave.png");
lbajardsilogic@21 767 action = new QAction(icon, tr("&Save Session"), this);
lbajardsilogic@21 768 action->setShortcut(tr("Ctrl+S"));
lbajardsilogic@21 769 action->setStatusTip(tr("Save the current session into a Easaier session file"));
lbajardsilogic@21 770 connect(action, SIGNAL(triggered()), this, SLOT(saveEasaierSession()));
lbajardsilogic@21 771 //connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
lbajardsilogic@21 772 menu->addAction(action);
lbajardsilogic@21 773 toolbar->addAction(action);
lbajardsilogic@21 774
lbajardsilogic@21 775 icon = QIcon(":icons/filesaveas.png");
lbajardsilogic@21 776 action = new QAction(icon, tr("Save Session &As..."), this);
lbajardsilogic@21 777 action->setStatusTip(tr("Save the current session into a new Easaier session file"));
lbajardsilogic@21 778 connect(action, SIGNAL(triggered()), this, SLOT(saveEasaierSessionAs()));
lbajardsilogic@21 779 menu->addAction(action);
lbajardsilogic@21 780 toolbar->addAction(action);
lbajardsilogic@21 781
lbajardsilogic@21 782 menu->addSeparator();
lbajardsilogic@21 783
lbajardsilogic@21 784 action = new QAction(QIcon(":/icons/exit.png"),
lbajardsilogic@21 785 tr("&Quit"), this);
lbajardsilogic@21 786 action->setShortcut(tr("Ctrl+Q"));
lbajardsilogic@21 787 connect(action, SIGNAL(triggered()), this, SLOT(exit()));
lbajardsilogic@21 788 menu->addAction(action);
lbajardsilogic@21 789
ivand_qmul@121 790 }
ivand_qmul@121 791
ivand_qmul@121 792 void
ivand_qmul@121 793 MainWindow::setupEditMenu()
ivand_qmul@121 794 {
ivand_qmul@121 795 if (m_mainMenusCreated) return;
ivand_qmul@121 796
ivand_qmul@121 797 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
ivand_qmul@121 798 menu->setTearOffEnabled(true);
ivand_qmul@121 799 CommandHistory::getInstance()->registerMenu(menu);
ivand_qmul@121 800
ivand_qmul@121 801 menu->addSeparator();
ivand_qmul@121 802
ivand_qmul@121 803 QAction *action = new QAction(QIcon(":/icons/editcut.png"),
ivand_qmul@121 804 tr("Cu&t"), this);
ivand_qmul@121 805 action->setShortcut(tr("Ctrl+X"));
ivand_qmul@121 806 action->setStatusTip(tr("Cut the selection from the current layer to the clipboard"));
ivand_qmul@121 807 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
ivand_qmul@121 808 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 809 menu->addAction(action);
ivand_qmul@121 810 m_rightButtonMenu->addAction(action);
ivand_qmul@121 811
ivand_qmul@121 812 action = new QAction(QIcon(":/icons/editcopy.png"),
ivand_qmul@121 813 tr("&Copy"), this);
ivand_qmul@121 814 action->setShortcut(tr("Ctrl+C"));
ivand_qmul@121 815 action->setStatusTip(tr("Copy the selection from the current layer to the clipboard"));
ivand_qmul@121 816 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
ivand_qmul@121 817 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 818 menu->addAction(action);
ivand_qmul@121 819 m_rightButtonMenu->addAction(action);
ivand_qmul@121 820
ivand_qmul@121 821 action = new QAction(QIcon(":/icons/editpaste.png"),
ivand_qmul@121 822 tr("&Paste"), this);
ivand_qmul@121 823 action->setShortcut(tr("Ctrl+V"));
ivand_qmul@121 824 action->setStatusTip(tr("Paste from the clipboard to the current layer"));
ivand_qmul@121 825 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
ivand_qmul@121 826 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 827 menu->addAction(action);
ivand_qmul@121 828 m_rightButtonMenu->addAction(action);
ivand_qmul@121 829
ivand_qmul@121 830 action = new QAction(tr("&Delete Selected Items"), this);
ivand_qmul@121 831 action->setShortcut(tr("Del"));
ivand_qmul@121 832 action->setStatusTip(tr("Delete the selection from the current layer"));
ivand_qmul@121 833 connect(action, SIGNAL(triggered()), this, SLOT(deleteSelected()));
ivand_qmul@121 834 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 835 menu->addAction(action);
ivand_qmul@121 836 m_rightButtonMenu->addAction(action);
ivand_qmul@121 837
ivand_qmul@121 838 menu->addSeparator();
ivand_qmul@121 839 m_rightButtonMenu->addSeparator();
ivand_qmul@121 840
ivand_qmul@121 841 action = new QAction(tr("Select &All"), this);
ivand_qmul@121 842 action->setShortcut(tr("Ctrl+A"));
ivand_qmul@121 843 action->setStatusTip(tr("Select the whole duration of the current session"));
ivand_qmul@121 844 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
ivand_qmul@121 845 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 846 menu->addAction(action);
ivand_qmul@121 847 m_rightButtonMenu->addAction(action);
ivand_qmul@121 848
ivand_qmul@121 849 action = new QAction(tr("Select &Visible Range"), this);
ivand_qmul@121 850 action->setShortcut(tr("Ctrl+Shift+A"));
ivand_qmul@121 851 action->setStatusTip(tr("Select the time range corresponding to the current window width"));
ivand_qmul@121 852 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
ivand_qmul@121 853 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 854 menu->addAction(action);
ivand_qmul@121 855
ivand_qmul@121 856 action = new QAction(tr("Select to &Start"), this);
ivand_qmul@121 857 action->setShortcut(tr("Shift+Left"));
ivand_qmul@121 858 action->setStatusTip(tr("Select from the start of the session to the current playback position"));
ivand_qmul@121 859 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
ivand_qmul@121 860 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 861 menu->addAction(action);
ivand_qmul@121 862
ivand_qmul@121 863 action = new QAction(tr("Select to &End"), this);
ivand_qmul@121 864 action->setShortcut(tr("Shift+Right"));
ivand_qmul@121 865 action->setStatusTip(tr("Select from the current playback position to the end of the session"));
ivand_qmul@121 866 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
ivand_qmul@121 867 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 868 menu->addAction(action);
ivand_qmul@121 869
ivand_qmul@121 870 action = new QAction(tr("C&lear Selection"), this);
ivand_qmul@121 871 action->setShortcut(tr("Esc"));
ivand_qmul@121 872 action->setStatusTip(tr("Clear the selection"));
ivand_qmul@121 873 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
ivand_qmul@121 874 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 875 menu->addAction(action);
ivand_qmul@121 876 m_rightButtonMenu->addAction(action);
ivand_qmul@121 877
ivand_qmul@121 878 menu->addSeparator();
ivand_qmul@121 879
ivand_qmul@121 880 action = new QAction(tr("&Insert Instant at Playback Position"), this);
ivand_qmul@121 881 action->setShortcut(tr("Enter"));
ivand_qmul@121 882 action->setStatusTip(tr("Insert a new time instant at the current playback position, in a new layer if necessary"));
ivand_qmul@121 883 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
ivand_qmul@121 884 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 885 menu->addAction(action);
ivand_qmul@121 886
ivand_qmul@121 887 action = new QAction(tr("Insert Instants at Selection &Boundaries"), this);
ivand_qmul@121 888 action->setShortcut(tr("Shift+Enter"));
ivand_qmul@121 889 action->setStatusTip(tr("Insert new time instants at the start and end of the current selection, in a new layer if necessary"));
ivand_qmul@121 890 connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries()));
ivand_qmul@121 891 connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 892 menu->addAction(action);
ivand_qmul@121 893
ivand_qmul@121 894 // Laptop shortcut (no keypad Enter key)
ivand_qmul@121 895 connect(new QShortcut(tr(";"), this), SIGNAL(activated()),
ivand_qmul@121 896 this, SLOT(insertInstant()));
ivand_qmul@121 897 }
ivand_qmul@121 898
ivand_qmul@121 899 void
ivand_qmul@121 900 MainWindow::setupSettingMenu()
ivand_qmul@121 901 {
ivand_qmul@121 902 if (m_mainMenusCreated) return;
ivand_qmul@121 903
ivand_qmul@121 904 QAction *action = 0;
ivand_qmul@121 905 QMenu *menu = 0;
ivand_qmul@121 906
ivand_qmul@121 907 menu = menuBar()->addMenu(tr("&Settings"));
ivand_qmul@121 908 menu->setTearOffEnabled(true);
lbajardsilogic@2 909
lbajardsilogic@10 910 action = new QAction(tr("&Connection settings"), this);
lbajardsilogic@10 911 connect(action, SIGNAL(triggered()), this, SLOT(connectionSettings()));
lbajardsilogic@10 912 menu->addAction(action);
lbajardsilogic@2 913
lbajardsilogic@2 914 action = new QAction(tr("&Style setting"), this);
lbajardsilogic@2 915 connect(action, SIGNAL(triggered()), this, SLOT(styleSetting()));
ivand_qmul@121 916 menu->addAction(action);
ivand_qmul@121 917 }
ivand_qmul@121 918
ivand_qmul@121 919 void
ivand_qmul@121 920 MainWindow::setupViewMenu()
ivand_qmul@121 921 {
ivand_qmul@121 922 if (m_mainMenusCreated) return;
ivand_qmul@121 923
ivand_qmul@121 924 QAction *action = 0;
ivand_qmul@121 925
ivand_qmul@121 926 QMenu *menu = menuBar()->addMenu(tr("&View"));
ivand_qmul@121 927 menu->setTearOffEnabled(true);
ivand_qmul@121 928 action = new QAction(tr("Scroll &Left"), this);
ivand_qmul@121 929 action->setShortcut(tr("Left"));
ivand_qmul@121 930 action->setStatusTip(tr("Scroll the current pane to the left"));
ivand_qmul@121 931 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
ivand_qmul@121 932 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 933 menu->addAction(action);
ivand_qmul@121 934
ivand_qmul@121 935 action = new QAction(tr("Scroll &Right"), this);
ivand_qmul@121 936 action->setShortcut(tr("Right"));
ivand_qmul@121 937 action->setStatusTip(tr("Scroll the current pane to the right"));
ivand_qmul@121 938 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
ivand_qmul@121 939 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 940 menu->addAction(action);
ivand_qmul@121 941
ivand_qmul@121 942 action = new QAction(tr("&Jump Left"), this);
ivand_qmul@121 943 action->setShortcut(tr("Ctrl+Left"));
ivand_qmul@121 944 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
ivand_qmul@121 945 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
ivand_qmul@121 946 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 947 menu->addAction(action);
ivand_qmul@121 948
ivand_qmul@121 949 action = new QAction(tr("J&ump Right"), this);
ivand_qmul@121 950 action->setShortcut(tr("Ctrl+Right"));
ivand_qmul@121 951 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
ivand_qmul@121 952 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
ivand_qmul@121 953 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 954 menu->addAction(action);
ivand_qmul@121 955
ivand_qmul@121 956 menu->addSeparator();
ivand_qmul@121 957
ivand_qmul@121 958 action = new QAction(QIcon(":/icons/zoom-in.png"),
ivand_qmul@121 959 tr("Zoom &In"), this);
ivand_qmul@121 960 action->setShortcut(tr("Up"));
ivand_qmul@121 961 action->setStatusTip(tr("Increase the zoom level"));
ivand_qmul@121 962 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
ivand_qmul@121 963 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 964 menu->addAction(action);
ivand_qmul@121 965
ivand_qmul@121 966 action = new QAction(QIcon(":/icons/zoom-out.png"),
ivand_qmul@121 967 tr("Zoom &Out"), this);
ivand_qmul@121 968 action->setShortcut(tr("Down"));
ivand_qmul@121 969 action->setStatusTip(tr("Decrease the zoom level"));
ivand_qmul@121 970 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
ivand_qmul@121 971 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 972 menu->addAction(action);
ivand_qmul@121 973
ivand_qmul@121 974 action = new QAction(tr("Restore &Default Zoom"), this);
ivand_qmul@121 975 action->setStatusTip(tr("Restore the zoom level to the default"));
ivand_qmul@121 976 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
ivand_qmul@121 977 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 978 menu->addAction(action);
ivand_qmul@121 979
ivand_qmul@121 980 action = new QAction(QIcon(":/icons/zoom-fit.png"),
ivand_qmul@121 981 tr("Zoom to &Fit"), this);
ivand_qmul@121 982 action->setStatusTip(tr("Zoom to show the whole file"));
ivand_qmul@121 983 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
ivand_qmul@121 984 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 985 menu->addAction(action);
ivand_qmul@121 986
ivand_qmul@121 987 menu->addSeparator();
ivand_qmul@121 988
ivand_qmul@121 989 QActionGroup *overlayGroup = new QActionGroup(this);
ivand_qmul@121 990
ivand_qmul@121 991 action = new QAction(tr("Show &No Overlays"), this);
ivand_qmul@121 992 action->setShortcut(tr("0"));
ivand_qmul@121 993 action->setStatusTip(tr("Hide centre indicator, frame times, layer names and scale"));
ivand_qmul@121 994 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
ivand_qmul@121 995 action->setCheckable(true);
ivand_qmul@121 996 action->setChecked(false);
ivand_qmul@121 997 overlayGroup->addAction(action);
ivand_qmul@121 998 menu->addAction(action);
ivand_qmul@121 999
ivand_qmul@121 1000 action = new QAction(tr("Show &Minimal Overlays"), this);
ivand_qmul@121 1001 action->setShortcut(tr("9"));
ivand_qmul@121 1002 action->setStatusTip(tr("Show centre indicator only"));
ivand_qmul@121 1003 connect(action, SIGNAL(triggered()), this, SLOT(showMinimalOverlays()));
ivand_qmul@121 1004 action->setCheckable(true);
ivand_qmul@121 1005 action->setChecked(false);
ivand_qmul@121 1006 overlayGroup->addAction(action);
ivand_qmul@121 1007 menu->addAction(action);
ivand_qmul@121 1008
ivand_qmul@121 1009 action = new QAction(tr("Show &Standard Overlays"), this);
ivand_qmul@121 1010 action->setShortcut(tr("8"));
ivand_qmul@121 1011 action->setStatusTip(tr("Show centre indicator, frame times and scale"));
ivand_qmul@121 1012 connect(action, SIGNAL(triggered()), this, SLOT(showStandardOverlays()));
ivand_qmul@121 1013 action->setCheckable(true);
ivand_qmul@121 1014 action->setChecked(true);
ivand_qmul@121 1015 overlayGroup->addAction(action);
ivand_qmul@121 1016 menu->addAction(action);
ivand_qmul@121 1017
ivand_qmul@121 1018 action = new QAction(tr("Show &All Overlays"), this);
ivand_qmul@121 1019 action->setShortcut(tr("7"));
ivand_qmul@121 1020 action->setStatusTip(tr("Show all texts and scale"));
ivand_qmul@121 1021 connect(action, SIGNAL(triggered()), this, SLOT(showAllOverlays()));
ivand_qmul@121 1022 action->setCheckable(true);
ivand_qmul@121 1023 action->setChecked(false);
ivand_qmul@121 1024 overlayGroup->addAction(action);
ivand_qmul@121 1025 menu->addAction(action);
ivand_qmul@121 1026
ivand_qmul@121 1027 menu->addSeparator();
ivand_qmul@121 1028
ivand_qmul@121 1029 action = new QAction(tr("Show &Zoom Wheels"), this);
ivand_qmul@121 1030 action->setShortcut(tr("Z"));
ivand_qmul@121 1031 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
ivand_qmul@121 1032 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
ivand_qmul@121 1033 action->setCheckable(true);
ivand_qmul@121 1034 action->setChecked(m_viewManager->getZoomWheelsEnabled());
ivand_qmul@121 1035 menu->addAction(action);
ivand_qmul@121 1036
lbajardsilogic@205 1037 action = new QAction(tr("Show Layers and &Filters"), this);
lbajardsilogic@205 1038 action->setShortcut(tr("F"));
lbajardsilogic@205 1039 action->setStatusTip(tr("Show the layers and the real-time filters activated at the side of the main window"));
lbajardsilogic@205 1040 connect(action, SIGNAL(triggered()), m_rightExpandWidget, SLOT(changePaneState()));
lbajardsilogic@205 1041 connect(m_rightExpandWidget, SIGNAL(paneStateChanged(bool)), action, SLOT(setChecked(bool)));
lbajardsilogic@205 1042 action->setCheckable(true);
lbajardsilogic@205 1043 action->setChecked(m_rightExpandWidget->isVisible());
lbajardsilogic@205 1044 menu->addAction(action);
lbajardsilogic@205 1045
lbajardsilogic@205 1046 action = new QAction(tr("Show Search/Tracks &Info Panes"), this);
lbajardsilogic@205 1047 action->setShortcut(tr("I"));
lbajardsilogic@205 1048 action->setStatusTip(tr("Show the search funtionalities and tracks information at the bottom of the main window"));
lbajardsilogic@205 1049 connect(action, SIGNAL(triggered()), m_leftExpandWidget, SLOT(changePaneState()));
lbajardsilogic@205 1050 connect(m_leftExpandWidget, SIGNAL(paneStateChanged(bool)), action, SLOT(setChecked(bool)));
lbajardsilogic@205 1051 action->setCheckable(true);
lbajardsilogic@205 1052 action->setChecked(m_leftExpandWidget->isVisible());
lbajardsilogic@205 1053 menu->addAction(action);
ivand_qmul@121 1054
ivand_qmul@121 1055 action = new QAction(tr("Show Status &Bar"), this);
ivand_qmul@121 1056 action->setStatusTip(tr("Show context help information in the status bar at the bottom of the window"));
ivand_qmul@121 1057 connect(action, SIGNAL(triggered()), this, SLOT(toggleStatusBar()));
ivand_qmul@121 1058 action->setCheckable(true);
ivand_qmul@121 1059 action->setChecked(true);
ivand_qmul@121 1060 menu->addAction(action);
ivand_qmul@121 1061
ivand_qmul@121 1062 QSettings settings;
ivand_qmul@121 1063 settings.beginGroup("MainWindow");
ivand_qmul@121 1064 bool sb = settings.value("showstatusbar", true).toBool();
ivand_qmul@121 1065 if (!sb) {
ivand_qmul@121 1066 action->setChecked(false);
ivand_qmul@121 1067 statusBar()->hide();
ivand_qmul@121 1068 }
ivand_qmul@121 1069 settings.endGroup();
ivand_qmul@121 1070
ivand_qmul@121 1071 /*!!! This one doesn't work properly yet
ivand_qmul@121 1072
ivand_qmul@121 1073 menu->addSeparator();
ivand_qmul@121 1074
ivand_qmul@121 1075 action = new QAction(tr("Show La&yer Hierarchy"), this);
ivand_qmul@121 1076 action->setShortcut(tr("Alt+L"));
ivand_qmul@121 1077 action->setStatusTip(tr("Open a window displaying the hierarchy of panes and layers in this session"));
ivand_qmul@121 1078 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
ivand_qmul@121 1079 menu->addAction(action);
ivand_qmul@121 1080 */
ivand_qmul@121 1081 }
ivand_qmul@121 1082
ivand_qmul@121 1083 void
ivand_qmul@121 1084 MainWindow::setupPaneAndLayerMenus()
ivand_qmul@121 1085 {
ivand_qmul@121 1086 if (m_paneMenu) {
ivand_qmul@121 1087 m_paneActions.clear();
ivand_qmul@121 1088 m_paneMenu->clear();
ivand_qmul@121 1089 } else {
ivand_qmul@121 1090 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
ivand_qmul@121 1091 m_paneMenu->setTearOffEnabled(true);
ivand_qmul@121 1092 }
ivand_qmul@121 1093
ivand_qmul@121 1094 if (m_layerMenu) {
ivand_qmul@121 1095 m_layerActions.clear();
ivand_qmul@121 1096 m_layerMenu->clear();
ivand_qmul@121 1097 } else {
ivand_qmul@121 1098 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
ivand_qmul@121 1099 m_layerMenu->setTearOffEnabled(true);
ivand_qmul@121 1100 }
ivand_qmul@121 1101
ivand_qmul@121 1102 QMenu *menu = m_paneMenu;
ivand_qmul@121 1103
ivand_qmul@121 1104 QAction *action = new QAction(QIcon(":/icons/pane.png"), tr("Add &New Pane"), this);
ivand_qmul@121 1105 action->setShortcut(tr("Alt+N"));
ivand_qmul@121 1106 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
ivand_qmul@121 1107 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
ivand_qmul@121 1108 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1109 m_paneActions[action] = PaneConfiguration(LayerFactory::TimeRuler);
ivand_qmul@121 1110 menu->addAction(action);
ivand_qmul@121 1111
ivand_qmul@121 1112 menu->addSeparator();
ivand_qmul@121 1113
ivand_qmul@121 1114 menu = m_layerMenu;
ivand_qmul@121 1115
ivand_qmul@121 1116 // menu->addSeparator();
ivand_qmul@121 1117
ivand_qmul@121 1118 LayerFactory::LayerTypeSet emptyLayerTypes =
ivand_qmul@121 1119 LayerFactory::getInstance()->getValidEmptyLayerTypes();
ivand_qmul@121 1120
ivand_qmul@121 1121 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
ivand_qmul@121 1122 i != emptyLayerTypes.end(); ++i) {
ivand_qmul@121 1123
ivand_qmul@121 1124 QIcon icon;
ivand_qmul@121 1125 QString mainText, tipText, channelText;
ivand_qmul@121 1126 LayerFactory::LayerType type = *i;
ivand_qmul@121 1127 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
ivand_qmul@121 1128
ivand_qmul@121 1129 icon = QIcon(QString(":/icons/%1.png")
ivand_qmul@121 1130 .arg(LayerFactory::getInstance()->getLayerIconName(type)));
ivand_qmul@121 1131
ivand_qmul@121 1132 mainText = tr("Add New %1 Layer").arg(name);
ivand_qmul@121 1133 tipText = tr("Add a new empty layer of type %1").arg(name);
ivand_qmul@121 1134
ivand_qmul@121 1135 action = new QAction(icon, mainText, this);
ivand_qmul@121 1136 action->setStatusTip(tipText);
ivand_qmul@121 1137
ivand_qmul@121 1138 if (type == LayerFactory::Text) {
ivand_qmul@121 1139 action->setShortcut(tr("Alt+T"));
ivand_qmul@121 1140 }
ivand_qmul@121 1141
ivand_qmul@121 1142 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
ivand_qmul@121 1143 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1144 m_layerActions[action] = type;
ivand_qmul@121 1145 menu->addAction(action);
ivand_qmul@121 1146 m_rightButtonLayerMenu->addAction(action);
ivand_qmul@121 1147 }
ivand_qmul@121 1148
ivand_qmul@121 1149 m_rightButtonLayerMenu->addSeparator();
ivand_qmul@121 1150 menu->addSeparator();
ivand_qmul@121 1151
ivand_qmul@121 1152 LayerFactory::LayerType backgroundTypes[] = {
ivand_qmul@121 1153 LayerFactory::Waveform,
ivand_qmul@121 1154 LayerFactory::Spectrogram,
ivand_qmul@121 1155 LayerFactory::MelodicRangeSpectrogram,
ivand_qmul@121 1156 LayerFactory::PeakFrequencySpectrogram,
ivand_qmul@121 1157 LayerFactory::Spectrum
ivand_qmul@121 1158 };
ivand_qmul@121 1159
ivand_qmul@121 1160 std::vector<Model *> models;
ivand_qmul@121 1161 if (m_document) models = m_document->getTransformInputModels(); //!!! not well named for this!
ivand_qmul@121 1162 bool plural = (models.size() > 1);
ivand_qmul@121 1163 if (models.empty()) {
ivand_qmul@121 1164 models.push_back(getMainModel()); // probably 0
ivand_qmul@121 1165 }
ivand_qmul@121 1166
ivand_qmul@121 1167 for (unsigned int i = 0;
ivand_qmul@121 1168 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
ivand_qmul@121 1169
ivand_qmul@121 1170 for (int menuType = 0; menuType <= 1; ++menuType) { // pane, layer
ivand_qmul@121 1171
ivand_qmul@121 1172 if (menuType == 0) menu = m_paneMenu;
ivand_qmul@121 1173 else menu = m_layerMenu;
ivand_qmul@121 1174
ivand_qmul@121 1175 QMenu *submenu = 0;
ivand_qmul@121 1176
ivand_qmul@121 1177 QIcon icon;
ivand_qmul@121 1178 QString mainText, shortcutText, tipText, channelText;
ivand_qmul@121 1179 LayerFactory::LayerType type = backgroundTypes[i];
ivand_qmul@121 1180 bool mono = true;
ivand_qmul@121 1181
ivand_qmul@121 1182 switch (type) {
ivand_qmul@121 1183
ivand_qmul@121 1184 case LayerFactory::Waveform:
ivand_qmul@121 1185 icon = QIcon(":/icons/waveform.png");
ivand_qmul@121 1186 mainText = tr("Add &Waveform");
ivand_qmul@121 1187 if (menuType == 0) {
ivand_qmul@121 1188 shortcutText = tr("Alt+W");
ivand_qmul@121 1189 tipText = tr("Add a new pane showing a waveform view");
ivand_qmul@121 1190 } else {
ivand_qmul@121 1191 tipText = tr("Add a new layer showing a waveform view");
ivand_qmul@121 1192 }
ivand_qmul@121 1193 mono = false;
ivand_qmul@121 1194 break;
ivand_qmul@121 1195
ivand_qmul@121 1196 case LayerFactory::Spectrogram:
ivand_qmul@121 1197 icon = QIcon(":/icons/spectrogram.png");
ivand_qmul@121 1198 mainText = tr("Add &Spectrogram");
ivand_qmul@121 1199 if (menuType == 0) {
ivand_qmul@121 1200 shortcutText = tr("Alt+S");
ivand_qmul@121 1201 tipText = tr("Add a new pane showing a spectrogram");
ivand_qmul@121 1202 } else {
ivand_qmul@121 1203 tipText = tr("Add a new layer showing a spectrogram");
ivand_qmul@121 1204 }
ivand_qmul@121 1205 break;
ivand_qmul@121 1206
ivand_qmul@121 1207 case LayerFactory::MelodicRangeSpectrogram:
ivand_qmul@121 1208 icon = QIcon(":/icons/spectrogram.png");
ivand_qmul@121 1209 mainText = tr("Add &Melodic Range Spectrogram");
ivand_qmul@121 1210 if (menuType == 0) {
ivand_qmul@121 1211 shortcutText = tr("Alt+M");
ivand_qmul@121 1212 tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches");
ivand_qmul@121 1213 } else {
ivand_qmul@121 1214 tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches");
ivand_qmul@121 1215 }
ivand_qmul@121 1216 break;
ivand_qmul@121 1217
ivand_qmul@121 1218 case LayerFactory::PeakFrequencySpectrogram:
ivand_qmul@121 1219 icon = QIcon(":/icons/spectrogram.png");
ivand_qmul@121 1220 mainText = tr("Add &Peak Frequency Spectrogram");
ivand_qmul@121 1221 if (menuType == 0) {
ivand_qmul@121 1222 shortcutText = tr("Alt+P");
ivand_qmul@121 1223 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
ivand_qmul@121 1224 } else {
ivand_qmul@121 1225 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
ivand_qmul@121 1226 }
ivand_qmul@121 1227 break;
ivand_qmul@121 1228
ivand_qmul@121 1229 case LayerFactory::Spectrum:
ivand_qmul@121 1230 icon = QIcon(":/icons/spectrum.png");
ivand_qmul@121 1231 mainText = tr("Add Spectr&um");
ivand_qmul@121 1232 if (menuType == 0) {
ivand_qmul@121 1233 shortcutText = tr("Alt+U");
ivand_qmul@121 1234 tipText = tr("Add a new pane showing a frequency spectrum");
ivand_qmul@121 1235 } else {
ivand_qmul@121 1236 tipText = tr("Add a new layer showing a frequency spectrum");
ivand_qmul@121 1237 }
ivand_qmul@121 1238 break;
ivand_qmul@121 1239
ivand_qmul@121 1240 default: break;
ivand_qmul@121 1241 }
ivand_qmul@121 1242
ivand_qmul@121 1243 std::vector<Model *> candidateModels;
ivand_qmul@121 1244 if (menuType == 0) {
ivand_qmul@121 1245 candidateModels = models;
ivand_qmul@121 1246 } else {
ivand_qmul@121 1247 candidateModels.push_back(0);
ivand_qmul@121 1248 }
ivand_qmul@121 1249
ivand_qmul@121 1250 for (std::vector<Model *>::iterator mi =
ivand_qmul@121 1251 candidateModels.begin();
ivand_qmul@121 1252 mi != candidateModels.end(); ++mi) {
ivand_qmul@121 1253
ivand_qmul@121 1254 Model *model = *mi;
ivand_qmul@121 1255
ivand_qmul@121 1256 int channels = 0;
ivand_qmul@121 1257 if (model) {
ivand_qmul@121 1258 DenseTimeValueModel *dtvm =
ivand_qmul@121 1259 dynamic_cast<DenseTimeValueModel *>(model);
ivand_qmul@121 1260 if (dtvm) channels = dtvm->getChannelCount();
ivand_qmul@121 1261 }
ivand_qmul@121 1262 if (channels < 1 && getMainModel()) {
ivand_qmul@121 1263 channels = getMainModel()->getChannelCount();
ivand_qmul@121 1264 }
ivand_qmul@121 1265 if (channels < 1) channels = 1;
ivand_qmul@121 1266
ivand_qmul@121 1267 for (int c = 0; c <= channels; ++c) {
ivand_qmul@121 1268
ivand_qmul@121 1269 if (c == 1 && channels == 1) continue;
ivand_qmul@121 1270 bool isDefault = (c == 0);
ivand_qmul@121 1271 bool isOnly = (isDefault && (channels == 1));
ivand_qmul@121 1272
ivand_qmul@121 1273 if (menuType == 1) {
ivand_qmul@121 1274 if (isDefault) isOnly = true;
ivand_qmul@121 1275 else continue;
ivand_qmul@121 1276 }
ivand_qmul@121 1277
ivand_qmul@121 1278 if (isOnly && (!plural || menuType == 1)) {
ivand_qmul@121 1279
ivand_qmul@121 1280 if (menuType == 1 && type != LayerFactory::Waveform) {
ivand_qmul@121 1281 action = new QAction(mainText, this);
ivand_qmul@121 1282 } else {
ivand_qmul@121 1283 action = new QAction(icon, mainText, this);
ivand_qmul@121 1284 }
ivand_qmul@121 1285
ivand_qmul@121 1286 action->setShortcut(shortcutText);
ivand_qmul@121 1287 action->setStatusTip(tipText);
ivand_qmul@121 1288 if (menuType == 0) {
ivand_qmul@121 1289 connect(action, SIGNAL(triggered()),
ivand_qmul@121 1290 this, SLOT(addPane()));
ivand_qmul@121 1291 connect(this, SIGNAL(canAddPane(bool)),
ivand_qmul@121 1292 action, SLOT(setEnabled(bool)));
ivand_qmul@121 1293 m_paneActions[action] = PaneConfiguration(type);
ivand_qmul@121 1294 } else {
ivand_qmul@121 1295 connect(action, SIGNAL(triggered()),
ivand_qmul@121 1296 this, SLOT(addLayer()));
ivand_qmul@121 1297 connect(this, SIGNAL(canAddLayer(bool)),
ivand_qmul@121 1298 action, SLOT(setEnabled(bool)));
ivand_qmul@121 1299 m_layerActions[action] = type;
ivand_qmul@121 1300 }
ivand_qmul@121 1301 menu->addAction(action);
ivand_qmul@121 1302
ivand_qmul@121 1303 } else {
ivand_qmul@121 1304
ivand_qmul@121 1305 if (!submenu) {
ivand_qmul@121 1306 submenu = menu->addMenu(mainText);
ivand_qmul@121 1307 submenu->setTearOffEnabled(true);
ivand_qmul@121 1308 } else if (isDefault) {
ivand_qmul@121 1309 submenu->addSeparator();
ivand_qmul@121 1310 }
ivand_qmul@121 1311
ivand_qmul@121 1312 QString actionText;
ivand_qmul@121 1313 if (c == 0) {
ivand_qmul@121 1314 if (mono) {
ivand_qmul@121 1315 actionText = tr("&All Channels Mixed");
ivand_qmul@121 1316 } else {
ivand_qmul@121 1317 actionText = tr("&All Channels");
ivand_qmul@121 1318 }
ivand_qmul@121 1319 } else {
ivand_qmul@121 1320 actionText = tr("Channel &%1").arg(c);
ivand_qmul@121 1321 }
ivand_qmul@121 1322
ivand_qmul@121 1323 if (model) {
ivand_qmul@121 1324 actionText = tr("%1: %2")
ivand_qmul@121 1325 .arg(model->objectName())
ivand_qmul@121 1326 .arg(actionText);
ivand_qmul@121 1327 }
ivand_qmul@121 1328
ivand_qmul@121 1329 if (isDefault) {
ivand_qmul@121 1330 action = new QAction(icon, actionText, this);
ivand_qmul@121 1331 if (!model || model == getMainModel()) {
ivand_qmul@121 1332 action->setShortcut(shortcutText);
ivand_qmul@121 1333 }
ivand_qmul@121 1334 } else {
ivand_qmul@121 1335 action = new QAction(actionText, this);
ivand_qmul@121 1336 }
ivand_qmul@121 1337
ivand_qmul@121 1338 action->setStatusTip(tipText);
ivand_qmul@121 1339
ivand_qmul@121 1340 if (menuType == 0) {
ivand_qmul@121 1341 connect(action, SIGNAL(triggered()),
ivand_qmul@121 1342 this, SLOT(addPane()));
ivand_qmul@121 1343 connect(this, SIGNAL(canAddPane(bool)),
ivand_qmul@121 1344 action, SLOT(setEnabled(bool)));
ivand_qmul@121 1345 m_paneActions[action] =
ivand_qmul@121 1346 PaneConfiguration(type, model, c - 1);
ivand_qmul@121 1347 } else {
ivand_qmul@121 1348 connect(action, SIGNAL(triggered()),
ivand_qmul@121 1349 this, SLOT(addLayer()));
ivand_qmul@121 1350 connect(this, SIGNAL(canAddLayer(bool)),
ivand_qmul@121 1351 action, SLOT(setEnabled(bool)));
ivand_qmul@121 1352 m_layerActions[action] = type;
ivand_qmul@121 1353 }
ivand_qmul@121 1354
ivand_qmul@121 1355 submenu->addAction(action);
ivand_qmul@121 1356 }
ivand_qmul@121 1357 }
ivand_qmul@121 1358 }
ivand_qmul@121 1359 }
ivand_qmul@121 1360 }
ivand_qmul@121 1361
ivand_qmul@121 1362 menu = m_paneMenu;
ivand_qmul@121 1363
ivand_qmul@121 1364 menu->addSeparator();
ivand_qmul@121 1365
ivand_qmul@121 1366 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Pane"), this);
ivand_qmul@121 1367 action->setShortcut(tr("Alt+D"));
ivand_qmul@121 1368 action->setStatusTip(tr("Delete the currently active pane"));
ivand_qmul@121 1369 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
ivand_qmul@121 1370 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1371 menu->addAction(action);
ivand_qmul@121 1372
ivand_qmul@121 1373 menu = m_layerMenu;
ivand_qmul@121 1374
ivand_qmul@121 1375 action = new QAction(QIcon(":/icons/timeruler.png"), tr("Add &Time Ruler"), this);
ivand_qmul@121 1376 action->setStatusTip(tr("Add a new layer showing a time ruler"));
ivand_qmul@121 1377 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
ivand_qmul@121 1378 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1379 m_layerActions[action] = LayerFactory::TimeRuler;
ivand_qmul@121 1380 menu->addAction(action);
ivand_qmul@121 1381
ivand_qmul@121 1382 menu->addSeparator();
ivand_qmul@121 1383
ivand_qmul@121 1384 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
ivand_qmul@121 1385 m_existingLayersMenu->setTearOffEnabled(true);
ivand_qmul@121 1386 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
ivand_qmul@121 1387
ivand_qmul@121 1388 m_sliceMenu = menu->addMenu(tr("Add S&lice of Layer"));
ivand_qmul@121 1389 m_sliceMenu->setTearOffEnabled(true);
ivand_qmul@121 1390 m_rightButtonLayerMenu->addMenu(m_sliceMenu);
ivand_qmul@121 1391
ivand_qmul@121 1392 setupExistingLayersMenus();
ivand_qmul@121 1393
ivand_qmul@121 1394 m_rightButtonLayerMenu->addSeparator();
ivand_qmul@121 1395 menu->addSeparator();
ivand_qmul@121 1396
ivand_qmul@121 1397 action = new QAction(tr("&Rename Layer..."), this);
ivand_qmul@121 1398 action->setShortcut(tr("Alt+R"));
ivand_qmul@121 1399 action->setStatusTip(tr("Rename the currently active layer"));
ivand_qmul@121 1400 connect(action, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
ivand_qmul@121 1401 connect(this, SIGNAL(canRenameLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1402 menu->addAction(action);
ivand_qmul@121 1403 m_rightButtonLayerMenu->addAction(action);
ivand_qmul@121 1404
ivand_qmul@121 1405 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Layer"), this);
ivand_qmul@121 1406 action->setShortcut(tr("Alt+Shift+D"));
ivand_qmul@121 1407 action->setStatusTip(tr("Delete the currently active layer"));
ivand_qmul@121 1408 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
ivand_qmul@121 1409 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1410 menu->addAction(action);
ivand_qmul@121 1411 m_rightButtonLayerMenu->addAction(action);
ivand_qmul@121 1412 }
ivand_qmul@121 1413
ivand_qmul@121 1414 void
ivand_qmul@121 1415 MainWindow::setupTransformsMenu()
ivand_qmul@121 1416 {
ivand_qmul@121 1417 if (m_transformsMenu) {
ivand_qmul@121 1418 m_transformActions.clear();
ivand_qmul@121 1419 m_transformActionsReverse.clear();
ivand_qmul@121 1420 m_transformsMenu->clear();
ivand_qmul@121 1421 } else {
ivand_qmul@121 1422 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
ivand_qmul@121 1423 m_transformsMenu->setTearOffEnabled(true);
ivand_qmul@121 1424 }
ivand_qmul@121 1425
ivand_qmul@121 1426 TransformFactory::TransformList transforms =
ivand_qmul@121 1427 TransformFactory::getInstance()->getAllTransforms();
ivand_qmul@121 1428
ivand_qmul@121 1429 vector<QString> types =
ivand_qmul@121 1430 TransformFactory::getInstance()->getAllTransformTypes();
ivand_qmul@121 1431
ivand_qmul@121 1432 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
ivand_qmul@121 1433 map<QString, map<QString, SubdividingMenu *> > makerMenus;
ivand_qmul@121 1434
ivand_qmul@121 1435 map<QString, SubdividingMenu *> byPluginNameMenus;
ivand_qmul@121 1436 map<QString, map<QString, QMenu *> > pluginNameMenus;
ivand_qmul@121 1437
ivand_qmul@121 1438 set<SubdividingMenu *> pendingMenus;
ivand_qmul@121 1439
ivand_qmul@121 1440 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
ivand_qmul@121 1441 m_recentTransformsMenu->setTearOffEnabled(true);
ivand_qmul@121 1442 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
ivand_qmul@121 1443 connect(&m_recentTransforms, SIGNAL(recentChanged()),
ivand_qmul@121 1444 this, SLOT(setupRecentTransformsMenu()));
ivand_qmul@121 1445
ivand_qmul@121 1446 m_transformsMenu->addSeparator();
ivand_qmul@121 1447 m_rightButtonTransformsMenu->addSeparator();
ivand_qmul@121 1448
ivand_qmul@121 1449 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
ivand_qmul@121 1450
ivand_qmul@121 1451 if (i != types.begin()) {
ivand_qmul@121 1452 m_transformsMenu->addSeparator();
ivand_qmul@121 1453 m_rightButtonTransformsMenu->addSeparator();
ivand_qmul@121 1454 }
ivand_qmul@121 1455
ivand_qmul@121 1456 QString byCategoryLabel = tr("%1 by Category").arg(*i);
ivand_qmul@121 1457 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
ivand_qmul@121 1458 20, 40);
ivand_qmul@121 1459 byCategoryMenu->setTearOffEnabled(true);
ivand_qmul@121 1460 m_transformsMenu->addMenu(byCategoryMenu);
ivand_qmul@121 1461 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
ivand_qmul@121 1462 pendingMenus.insert(byCategoryMenu);
ivand_qmul@121 1463
ivand_qmul@121 1464 vector<QString> categories =
ivand_qmul@121 1465 TransformFactory::getInstance()->getTransformCategories(*i);
ivand_qmul@121 1466
ivand_qmul@121 1467 for (vector<QString>::iterator j = categories.begin();
ivand_qmul@121 1468 j != categories.end(); ++j) {
ivand_qmul@121 1469
ivand_qmul@121 1470 QString category = *j;
ivand_qmul@121 1471 if (category == "") category = tr("Unclassified");
ivand_qmul@121 1472
ivand_qmul@121 1473 if (categories.size() < 2) {
ivand_qmul@121 1474 categoryMenus[*i][category] = byCategoryMenu;
ivand_qmul@121 1475 continue;
ivand_qmul@121 1476 }
ivand_qmul@121 1477
ivand_qmul@121 1478 QStringList components = category.split(" > ");
ivand_qmul@121 1479 QString key;
ivand_qmul@121 1480
ivand_qmul@121 1481 for (QStringList::iterator k = components.begin();
ivand_qmul@121 1482 k != components.end(); ++k) {
ivand_qmul@121 1483
ivand_qmul@121 1484 QString parentKey = key;
ivand_qmul@121 1485 if (key != "") key += " > ";
ivand_qmul@121 1486 key += *k;
ivand_qmul@121 1487
ivand_qmul@121 1488 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
ivand_qmul@121 1489 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
ivand_qmul@121 1490 m->setTearOffEnabled(true);
ivand_qmul@121 1491 pendingMenus.insert(m);
ivand_qmul@121 1492 categoryMenus[*i][key] = m;
ivand_qmul@121 1493 if (parentKey == "") {
ivand_qmul@121 1494 byCategoryMenu->addMenu(m);
ivand_qmul@121 1495 } else {
ivand_qmul@121 1496 categoryMenus[*i][parentKey]->addMenu(m);
ivand_qmul@121 1497 }
ivand_qmul@121 1498 }
ivand_qmul@121 1499 }
ivand_qmul@121 1500 }
ivand_qmul@121 1501
ivand_qmul@121 1502 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
ivand_qmul@121 1503 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
ivand_qmul@121 1504 byPluginNameMenus[*i]->setTearOffEnabled(true);
ivand_qmul@121 1505 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
ivand_qmul@121 1506 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
ivand_qmul@121 1507 pendingMenus.insert(byPluginNameMenus[*i]);
ivand_qmul@121 1508
ivand_qmul@121 1509 QString byMakerLabel = tr("%1 by Maker").arg(*i);
ivand_qmul@121 1510 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
ivand_qmul@121 1511 byMakerMenu->setTearOffEnabled(true);
ivand_qmul@121 1512 m_transformsMenu->addMenu(byMakerMenu);
ivand_qmul@121 1513 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
ivand_qmul@121 1514 pendingMenus.insert(byMakerMenu);
ivand_qmul@121 1515
ivand_qmul@121 1516 vector<QString> makers =
ivand_qmul@121 1517 TransformFactory::getInstance()->getTransformMakers(*i);
ivand_qmul@121 1518
ivand_qmul@121 1519 for (vector<QString>::iterator j = makers.begin();
ivand_qmul@121 1520 j != makers.end(); ++j) {
ivand_qmul@121 1521
ivand_qmul@121 1522 QString maker = *j;
ivand_qmul@121 1523 if (maker == "") maker = tr("Unknown");
ivand_qmul@121 1524 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
ivand_qmul@121 1525
ivand_qmul@121 1526 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
ivand_qmul@121 1527 makerMenus[*i][maker]->setTearOffEnabled(true);
ivand_qmul@121 1528 byMakerMenu->addMenu(makerMenus[*i][maker]);
ivand_qmul@121 1529 pendingMenus.insert(makerMenus[*i][maker]);
ivand_qmul@121 1530 }
ivand_qmul@121 1531 }
ivand_qmul@121 1532
ivand_qmul@121 1533 for (unsigned int i = 0; i < transforms.size(); ++i) {
ivand_qmul@121 1534
ivand_qmul@121 1535 QString name = transforms[i].name;
ivand_qmul@121 1536 if (name == "") name = transforms[i].identifier;
ivand_qmul@121 1537
ivand_qmul@121 1538 // std::cerr << "Plugin Name: " << name.toStdString() << std::endl;
ivand_qmul@121 1539
ivand_qmul@121 1540 QString type = transforms[i].type;
ivand_qmul@121 1541
ivand_qmul@121 1542 QString category = transforms[i].category;
ivand_qmul@121 1543 if (category == "") category = tr("Unclassified");
ivand_qmul@121 1544
ivand_qmul@121 1545 QString maker = transforms[i].maker;
ivand_qmul@121 1546 if (maker == "") maker = tr("Unknown");
ivand_qmul@121 1547 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
ivand_qmul@121 1548
ivand_qmul@121 1549 QString pluginName = name.section(": ", 0, 0);
ivand_qmul@121 1550 QString output = name.section(": ", 1);
ivand_qmul@121 1551
ivand_qmul@121 1552 QAction *action = new QAction(tr("%1...").arg(name), this);
ivand_qmul@121 1553 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
ivand_qmul@121 1554 m_transformActions[action] = transforms[i].identifier;
ivand_qmul@121 1555 m_transformActionsReverse[transforms[i].identifier] = action;
ivand_qmul@121 1556 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1557
ivand_qmul@121 1558 action->setStatusTip(transforms[i].description);
ivand_qmul@121 1559
ivand_qmul@121 1560 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
ivand_qmul@121 1561 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
ivand_qmul@121 1562 << "No category menu for transform \""
ivand_qmul@121 1563 << name.toStdString() << "\" (category = \""
ivand_qmul@121 1564 << category.toStdString() << "\")" << std::endl;
ivand_qmul@121 1565 } else {
ivand_qmul@121 1566 categoryMenus[type][category]->addAction(action);
ivand_qmul@121 1567 }
ivand_qmul@121 1568
ivand_qmul@121 1569 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
ivand_qmul@121 1570 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
ivand_qmul@121 1571 << "No maker menu for transform \""
ivand_qmul@121 1572 << name.toStdString() << "\" (maker = \""
ivand_qmul@121 1573 << maker.toStdString() << "\")" << std::endl;
ivand_qmul@121 1574 } else {
ivand_qmul@121 1575 makerMenus[type][maker]->addAction(action);
ivand_qmul@121 1576 }
ivand_qmul@121 1577
ivand_qmul@121 1578 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
ivand_qmul@121 1579 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
ivand_qmul@121 1580 m_transformActions[action] = transforms[i].identifier;
ivand_qmul@121 1581 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1582 action->setStatusTip(transforms[i].description);
ivand_qmul@121 1583
ivand_qmul@121 1584 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
ivand_qmul@121 1585
ivand_qmul@121 1586 if (pluginNameMenus[type].find(pluginName) ==
ivand_qmul@121 1587 pluginNameMenus[type].end()) {
ivand_qmul@121 1588
ivand_qmul@121 1589 SubdividingMenu *parentMenu = byPluginNameMenus[type];
ivand_qmul@121 1590 parentMenu->setTearOffEnabled(true);
ivand_qmul@121 1591
ivand_qmul@121 1592 if (output == "") {
ivand_qmul@121 1593 parentMenu->addAction(pluginName, action);
ivand_qmul@121 1594 } else {
ivand_qmul@121 1595 pluginNameMenus[type][pluginName] =
ivand_qmul@121 1596 parentMenu->addMenu(pluginName);
ivand_qmul@121 1597 connect(this, SIGNAL(canAddLayer(bool)),
ivand_qmul@121 1598 pluginNameMenus[type][pluginName],
ivand_qmul@121 1599 SLOT(setEnabled(bool)));
ivand_qmul@121 1600 }
ivand_qmul@121 1601 }
ivand_qmul@121 1602
ivand_qmul@121 1603 if (pluginNameMenus[type].find(pluginName) !=
ivand_qmul@121 1604 pluginNameMenus[type].end()) {
ivand_qmul@121 1605 pluginNameMenus[type][pluginName]->addAction(action);
ivand_qmul@121 1606 }
ivand_qmul@121 1607 }
ivand_qmul@121 1608
ivand_qmul@121 1609 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
ivand_qmul@121 1610 i != pendingMenus.end(); ++i) {
ivand_qmul@121 1611 (*i)->entriesAdded();
ivand_qmul@121 1612 }
ivand_qmul@121 1613
ivand_qmul@121 1614 setupRecentTransformsMenu();
ivand_qmul@121 1615 }
ivand_qmul@121 1616
ivand_qmul@121 1617 void
ivand_qmul@121 1618 MainWindow::setupHelpMenu()
ivand_qmul@121 1619 {
ivand_qmul@121 1620 if (m_mainMenusCreated) return;
ivand_qmul@121 1621
ivand_qmul@121 1622 QMenu *menu = menuBar()->addMenu(tr("&Help"));
ivand_qmul@121 1623 menu->setTearOffEnabled(true);
ivand_qmul@121 1624
ivand_qmul@121 1625 QAction *action = new QAction(QIcon(":icons/help.png"),
ivand_qmul@121 1626 tr("&Help Reference"), this);
ivand_qmul@121 1627 action->setStatusTip(tr("Open the Sonic Visualiser reference manual"));
ivand_qmul@121 1628 connect(action, SIGNAL(triggered()), this, SLOT(help()));
ivand_qmul@121 1629 menu->addAction(action);
ivand_qmul@121 1630
ivand_qmul@121 1631 action = new QAction(tr("Sonic Visualiser on the &Web"), this);
ivand_qmul@121 1632 action->setStatusTip(tr("Open the Sonic Visualiser website"));
ivand_qmul@121 1633 connect(action, SIGNAL(triggered()), this, SLOT(website()));
ivand_qmul@121 1634 menu->addAction(action);
ivand_qmul@121 1635
ivand_qmul@121 1636 action = new QAction(tr("&About Sound Access"), this);
ivand_qmul@121 1637 action->setStatusTip(tr("Show information about Sound Access"));
ivand_qmul@121 1638 connect(action, SIGNAL(triggered()), this, SLOT(about()));
ivand_qmul@121 1639 menu->addAction(action);
ivand_qmul@121 1640 }
ivand_qmul@121 1641
ivand_qmul@121 1642 void
ivand_qmul@121 1643 MainWindow::setupRecentFilesMenu()
ivand_qmul@121 1644 {
ivand_qmul@121 1645 m_recentFilesMenu->clear();
ivand_qmul@121 1646 vector<QString> files = m_recentFiles.getRecent();
ivand_qmul@121 1647 for (size_t i = 0; i < files.size(); ++i) {
ivand_qmul@121 1648 QAction *action = new QAction(files[i], this);
ivand_qmul@121 1649 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
ivand_qmul@121 1650 m_recentFilesMenu->addAction(action);
ivand_qmul@121 1651 }
ivand_qmul@121 1652 }
ivand_qmul@121 1653
ivand_qmul@121 1654 void
ivand_qmul@121 1655 MainWindow::setupRecentTransformsMenu()
ivand_qmul@121 1656 {
ivand_qmul@121 1657 m_recentTransformsMenu->clear();
ivand_qmul@121 1658 vector<QString> transforms = m_recentTransforms.getRecent();
ivand_qmul@121 1659 for (size_t i = 0; i < transforms.size(); ++i) {
ivand_qmul@121 1660 TransformActionReverseMap::iterator ti =
ivand_qmul@121 1661 m_transformActionsReverse.find(transforms[i]);
ivand_qmul@121 1662 if (ti == m_transformActionsReverse.end()) {
ivand_qmul@121 1663 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
ivand_qmul@121 1664 << "Unknown transform \"" << transforms[i].toStdString()
ivand_qmul@121 1665 << "\" in recent transforms list" << std::endl;
ivand_qmul@121 1666 continue;
ivand_qmul@121 1667 }
ivand_qmul@121 1668 m_recentTransformsMenu->addAction(ti->second);
ivand_qmul@121 1669 }
ivand_qmul@121 1670 }
ivand_qmul@121 1671
ivand_qmul@121 1672 void
ivand_qmul@121 1673 MainWindow::setupExistingLayersMenus()
ivand_qmul@121 1674 {
ivand_qmul@121 1675 if (!m_existingLayersMenu) return; // should have been created by setupMenus
ivand_qmul@121 1676
ivand_qmul@121 1677 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl;
ivand_qmul@121 1678
ivand_qmul@121 1679 m_existingLayersMenu->clear();
ivand_qmul@121 1680 m_existingLayerActions.clear();
ivand_qmul@121 1681
ivand_qmul@121 1682 m_sliceMenu->clear();
ivand_qmul@121 1683 m_sliceActions.clear();
ivand_qmul@121 1684
ivand_qmul@121 1685 vector<Layer *> orderedLayers;
ivand_qmul@121 1686 set<Layer *> observedLayers;
ivand_qmul@121 1687 set<Layer *> sliceableLayers;
ivand_qmul@121 1688
ivand_qmul@121 1689 LayerFactory *factory = LayerFactory::getInstance();
ivand_qmul@121 1690
ivand_qmul@121 1691 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
ivand_qmul@121 1692
ivand_qmul@121 1693 Pane *pane = m_paneStack->getPane(i);
ivand_qmul@121 1694 if (!pane) continue;
ivand_qmul@121 1695
ivand_qmul@121 1696 for (int j = 0; j < pane->getLayerCount(); ++j) {
ivand_qmul@121 1697
ivand_qmul@121 1698 Layer *layer = pane->getLayer(j);
ivand_qmul@121 1699 if (!layer) continue;
ivand_qmul@121 1700 if (observedLayers.find(layer) != observedLayers.end()) {
ivand_qmul@121 1701 // std::cerr << "found duplicate layer " << layer << std::endl;
ivand_qmul@121 1702 continue;
ivand_qmul@121 1703 }
ivand_qmul@121 1704
ivand_qmul@121 1705 // std::cerr << "found new layer " << layer << " (name = "
ivand_qmul@121 1706 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl;
ivand_qmul@121 1707
ivand_qmul@121 1708 orderedLayers.push_back(layer);
ivand_qmul@121 1709 observedLayers.insert(layer);
ivand_qmul@121 1710
ivand_qmul@121 1711 if (factory->isLayerSliceable(layer)) {
ivand_qmul@121 1712 sliceableLayers.insert(layer);
ivand_qmul@121 1713 }
ivand_qmul@121 1714 }
ivand_qmul@121 1715 }
ivand_qmul@121 1716
ivand_qmul@121 1717 map<QString, int> observedNames;
ivand_qmul@121 1718
ivand_qmul@121 1719 for (size_t i = 0; i < orderedLayers.size(); ++i) {
ivand_qmul@121 1720
ivand_qmul@121 1721 Layer *layer = orderedLayers[i];
ivand_qmul@121 1722
ivand_qmul@121 1723 QString name = layer->getLayerPresentationName();
ivand_qmul@121 1724 int n = ++observedNames[name];
ivand_qmul@121 1725 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
ivand_qmul@121 1726
ivand_qmul@121 1727 QIcon icon = QIcon(QString(":/icons/%1.png")
ivand_qmul@121 1728 .arg(factory->getLayerIconName
ivand_qmul@121 1729 (factory->getLayerType(layer))));
ivand_qmul@121 1730
ivand_qmul@121 1731 QAction *action = new QAction(icon, name, this);
ivand_qmul@121 1732 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
ivand_qmul@121 1733 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1734 m_existingLayerActions[action] = layer;
ivand_qmul@121 1735
ivand_qmul@121 1736 m_existingLayersMenu->addAction(action);
ivand_qmul@121 1737
ivand_qmul@121 1738 if (sliceableLayers.find(layer) != sliceableLayers.end()) {
ivand_qmul@121 1739 action = new QAction(icon, name, this);
ivand_qmul@121 1740 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
ivand_qmul@121 1741 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1742 m_sliceActions[action] = layer;
ivand_qmul@121 1743 m_sliceMenu->addAction(action);
ivand_qmul@121 1744 }
ivand_qmul@121 1745 }
ivand_qmul@121 1746
ivand_qmul@121 1747 m_sliceMenu->setEnabled(!m_sliceActions.empty());
ivand_qmul@121 1748 }
ivand_qmul@121 1749
ivand_qmul@121 1750 void
ivand_qmul@121 1751 MainWindow::setupToolbars()
ivand_qmul@121 1752 {
ivand_qmul@121 1753 QToolBar *toolbar = addToolBar(tr("Transport Toolbar"));
benoitrigolleau@217 1754 m_toolBarVector.append(toolbar);
ivand_qmul@121 1755
ivand_qmul@121 1756 QAction *action = toolbar->addAction(QIcon(":/icons/rewind-start.png"),
ivand_qmul@121 1757 tr("Rewind to Start"));
ivand_qmul@121 1758 action->setShortcut(tr("Home"));
ivand_qmul@121 1759 action->setStatusTip(tr("Rewind to the start"));
ivand_qmul@121 1760 connect(action, SIGNAL(triggered()), this, SLOT(rewindStart()));
ivand_qmul@121 1761 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1762
ivand_qmul@121 1763 action = toolbar->addAction(QIcon(":/icons/rewind.png"),
ivand_qmul@121 1764 tr("Rewind"));
ivand_qmul@121 1765 action->setShortcut(tr("PageUp"));
ivand_qmul@121 1766 action->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
ivand_qmul@121 1767 connect(action, SIGNAL(triggered()), this, SLOT(rewind()));
ivand_qmul@121 1768 connect(this, SIGNAL(canRewind(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1769
ivand_qmul@121 1770 action = toolbar->addAction(QIcon(":/icons/playpause.png"),
ivand_qmul@121 1771 tr("Play / Pause"));
ivand_qmul@121 1772 action->setCheckable(true);
ivand_qmul@121 1773 action->setShortcut(tr("Space"));
ivand_qmul@121 1774 action->setStatusTip(tr("Start or stop playback from the current position"));
ivand_qmul@121 1775 connect(action, SIGNAL(triggered()), this, SLOT(play()));
ivand_qmul@121 1776 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
ivand_qmul@121 1777 action, SLOT(setChecked(bool)));
ivand_qmul@121 1778 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1779
ivand_qmul@121 1780 action = toolbar->addAction(QIcon(":/icons/ffwd.png"),
ivand_qmul@121 1781 tr("Fast Forward"));
ivand_qmul@121 1782 action->setShortcut(tr("PageDown"));
ivand_qmul@121 1783 action->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
ivand_qmul@121 1784 connect(action, SIGNAL(triggered()), this, SLOT(ffwd()));
ivand_qmul@121 1785 connect(this, SIGNAL(canFfwd(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1786
ivand_qmul@121 1787 action = toolbar->addAction(QIcon(":/icons/ffwd-end.png"),
ivand_qmul@121 1788 tr("Fast Forward to End"));
ivand_qmul@121 1789 action->setShortcut(tr("End"));
ivand_qmul@121 1790 action->setStatusTip(tr("Fast-forward to the end"));
ivand_qmul@121 1791 connect(action, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
ivand_qmul@121 1792 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1793
ivand_qmul@121 1794 toolbar = addToolBar(tr("Play Mode Toolbar"));
benoitrigolleau@217 1795 m_toolBarVector.append(toolbar);
ivand_qmul@121 1796
ivand_qmul@121 1797 action = toolbar->addAction(QIcon(":/icons/playselection.png"),
ivand_qmul@121 1798 tr("Constrain Playback to Selection"));
ivand_qmul@121 1799 action->setCheckable(true);
ivand_qmul@121 1800 action->setChecked(m_viewManager->getPlaySelectionMode());
ivand_qmul@121 1801 action->setShortcut(tr("s"));
ivand_qmul@121 1802 action->setStatusTip(tr("Constrain playback to the selected area"));
ivand_qmul@121 1803 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
ivand_qmul@121 1804 action, SLOT(setChecked(bool)));
ivand_qmul@121 1805 connect(action, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
ivand_qmul@121 1806 connect(this, SIGNAL(canPlaySelection(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1807
ivand_qmul@121 1808 action = toolbar->addAction(QIcon(":/icons/playloop.png"),
ivand_qmul@121 1809 tr("Loop Playback"));
ivand_qmul@121 1810 action->setCheckable(true);
ivand_qmul@121 1811 action->setChecked(m_viewManager->getPlayLoopMode());
ivand_qmul@121 1812 action->setShortcut(tr("l"));
ivand_qmul@121 1813 action->setStatusTip(tr("Loop playback"));
ivand_qmul@121 1814 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
ivand_qmul@121 1815 action, SLOT(setChecked(bool)));
ivand_qmul@121 1816 connect(action, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
ivand_qmul@121 1817 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1818
ivand_qmul@121 1819 toolbar = addToolBar(tr("Edit Toolbar"));
benoitrigolleau@217 1820 m_toolBarVector.append(toolbar);
benoitrigolleau@217 1821
ivand_qmul@121 1822 CommandHistory::getInstance()->registerToolbar(toolbar);
ivand_qmul@121 1823
ivand_qmul@121 1824 toolbar = addToolBar(tr("Tools Toolbar"));
benoitrigolleau@217 1825 m_toolBarVector.append(toolbar);
benoitrigolleau@217 1826
ivand_qmul@121 1827 QActionGroup *group = new QActionGroup(this);
ivand_qmul@121 1828
ivand_qmul@121 1829 action = toolbar->addAction(QIcon(":/icons/navigate.png"),
ivand_qmul@121 1830 tr("Navigate"));
ivand_qmul@121 1831 action->setCheckable(true);
ivand_qmul@121 1832 action->setChecked(true);
ivand_qmul@121 1833 action->setShortcut(tr("1"));
ivand_qmul@121 1834 action->setStatusTip(tr("Navigate"));
ivand_qmul@121 1835 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
ivand_qmul@121 1836 group->addAction(action);
ivand_qmul@121 1837 m_toolActions[ViewManager::NavigateMode] = action;
ivand_qmul@121 1838
ivand_qmul@121 1839 action = toolbar->addAction(QIcon(":/icons/select.png"),
ivand_qmul@121 1840 tr("Select"));
ivand_qmul@121 1841 action->setCheckable(true);
ivand_qmul@121 1842 action->setShortcut(tr("2"));
ivand_qmul@121 1843 action->setStatusTip(tr("Select ranges"));
ivand_qmul@121 1844 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
ivand_qmul@121 1845 group->addAction(action);
ivand_qmul@121 1846 m_toolActions[ViewManager::SelectMode] = action;
ivand_qmul@121 1847
ivand_qmul@121 1848 action = toolbar->addAction(QIcon(":/icons/move.png"),
ivand_qmul@121 1849 tr("Edit"));
ivand_qmul@121 1850 action->setCheckable(true);
ivand_qmul@121 1851 action->setShortcut(tr("3"));
ivand_qmul@121 1852 action->setStatusTip(tr("Edit items in layer"));
ivand_qmul@121 1853 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
ivand_qmul@121 1854 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1855 group->addAction(action);
ivand_qmul@121 1856 m_toolActions[ViewManager::EditMode] = action;
ivand_qmul@121 1857
ivand_qmul@121 1858 action = toolbar->addAction(QIcon(":/icons/draw.png"),
ivand_qmul@121 1859 tr("Draw"));
ivand_qmul@121 1860 action->setCheckable(true);
ivand_qmul@121 1861 action->setShortcut(tr("4"));
ivand_qmul@121 1862 action->setStatusTip(tr("Draw new items in layer"));
ivand_qmul@121 1863 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
ivand_qmul@121 1864 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
ivand_qmul@121 1865 group->addAction(action);
ivand_qmul@121 1866 m_toolActions[ViewManager::DrawMode] = action;
ivand_qmul@121 1867
ivand_qmul@121 1868 // action = toolbar->addAction(QIcon(":/icons/text.png"),
ivand_qmul@121 1869 // tr("Text"));
ivand_qmul@121 1870 // action->setCheckable(true);
ivand_qmul@121 1871 // action->setShortcut(tr("5"));
ivand_qmul@121 1872 // connect(action, SIGNAL(triggered()), this, SLOT(toolTextSelected()));
ivand_qmul@121 1873 // group->addAction(action);
ivand_qmul@121 1874 // m_toolActions[ViewManager::TextMode] = action;
ivand_qmul@121 1875
lbajardsilogic@25 1876 ConnectionStatus *connectionStatus = new ConnectionStatus(m_httpClient, tr("Connection status"));
ivand_qmul@121 1877 addToolBar(connectionStatus);
ivand_qmul@121 1878
ivand_qmul@121 1879 toolNavigateSelected();
ivand_qmul@121 1880 }
ivand_qmul@121 1881
ivand_qmul@121 1882 void
ivand_qmul@121 1883 MainWindow::updateMenuStates()
ivand_qmul@121 1884 {
ivand_qmul@121 1885 Pane *currentPane = 0;
ivand_qmul@121 1886 Layer *currentLayer = 0;
ivand_qmul@121 1887
ivand_qmul@121 1888 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 1889 if (currentPane) currentLayer = currentPane->getSelectedLayer();
ivand_qmul@121 1890
ivand_qmul@121 1891 bool haveCurrentPane =
ivand_qmul@121 1892 (currentPane != 0);
ivand_qmul@121 1893 bool haveCurrentLayer =
ivand_qmul@121 1894 (haveCurrentPane &&
ivand_qmul@121 1895 (currentLayer != 0));
ivand_qmul@121 1896 bool haveMainModel =
ivand_qmul@121 1897 (getMainModel() != 0);
ivand_qmul@121 1898 bool havePlayTarget =
ivand_qmul@121 1899 (m_playTarget != 0);
ivand_qmul@121 1900 bool haveSelection =
ivand_qmul@121 1901 (m_viewManager &&
ivand_qmul@121 1902 !m_viewManager->getSelections().empty());
ivand_qmul@121 1903 bool haveCurrentEditableLayer =
ivand_qmul@121 1904 (haveCurrentLayer &&
ivand_qmul@121 1905 currentLayer->isLayerEditable());
ivand_qmul@121 1906 bool haveCurrentTimeInstantsLayer =
ivand_qmul@121 1907 (haveCurrentLayer &&
ivand_qmul@121 1908 dynamic_cast<TimeInstantLayer *>(currentLayer));
ivand_qmul@121 1909 bool haveCurrentTimeValueLayer =
ivand_qmul@121 1910 (haveCurrentLayer &&
ivand_qmul@121 1911 dynamic_cast<TimeValueLayer *>(currentLayer));
ivand_qmul@121 1912 bool haveCurrentColour3DPlot =
ivand_qmul@121 1913 (haveCurrentLayer &&
ivand_qmul@121 1914 dynamic_cast<Colour3DPlotLayer *>(currentLayer));
ivand_qmul@121 1915 bool haveClipboardContents =
ivand_qmul@121 1916 (m_viewManager &&
ivand_qmul@121 1917 !m_viewManager->getClipboard().empty());
ivand_qmul@121 1918
ivand_qmul@121 1919 emit canAddPane(haveMainModel);
ivand_qmul@121 1920 emit canDeleteCurrentPane(haveCurrentPane);
ivand_qmul@121 1921 emit canZoom(haveMainModel && haveCurrentPane);
ivand_qmul@121 1922 emit canScroll(haveMainModel && haveCurrentPane);
ivand_qmul@121 1923 emit canAddLayer(haveMainModel && haveCurrentPane);
ivand_qmul@121 1924 emit canImportMoreAudio(haveMainModel);
ivand_qmul@121 1925 emit canImportLayer(haveMainModel && haveCurrentPane);
ivand_qmul@121 1926 emit canExportAudio(haveMainModel);
ivand_qmul@121 1927 emit canExportLayer(haveMainModel &&
ivand_qmul@121 1928 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
ivand_qmul@121 1929 emit canExportImage(haveMainModel && haveCurrentPane);
ivand_qmul@121 1930 emit canDeleteCurrentLayer(haveCurrentLayer);
ivand_qmul@121 1931 emit canRenameLayer(haveCurrentLayer);
ivand_qmul@121 1932 emit canEditLayer(haveCurrentEditableLayer);
ivand_qmul@121 1933 emit canSelect(haveMainModel && haveCurrentPane);
ivand_qmul@121 1934 emit canPlay(/*!!! haveMainModel && */ havePlayTarget);
ivand_qmul@121 1935 emit canFfwd(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
ivand_qmul@121 1936 emit canRewind(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
ivand_qmul@121 1937 emit canPaste(haveCurrentEditableLayer && haveClipboardContents);
ivand_qmul@121 1938 emit canInsertInstant(haveCurrentPane);
ivand_qmul@121 1939 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
ivand_qmul@121 1940 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
ivand_qmul@121 1941 emit canClearSelection(haveSelection);
ivand_qmul@121 1942 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
ivand_qmul@121 1943 emit canSave(m_sessionFile != "" && m_documentModified);
ivand_qmul@121 1944 }
ivand_qmul@121 1945
ivand_qmul@121 1946 void
ivand_qmul@121 1947 MainWindow::updateDescriptionLabel()
ivand_qmul@121 1948 {
ivand_qmul@121 1949 if (!getMainModel()) {
ivand_qmul@121 1950 m_descriptionLabel->setText(tr("No audio file loaded."));
ivand_qmul@121 1951 return;
ivand_qmul@121 1952 }
ivand_qmul@121 1953
ivand_qmul@121 1954 QString description;
ivand_qmul@121 1955
ivand_qmul@121 1956 size_t ssr = getMainModel()->getSampleRate();
ivand_qmul@121 1957 size_t tsr = ssr;
ivand_qmul@121 1958 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
ivand_qmul@121 1959
ivand_qmul@121 1960 if (ssr != tsr) {
ivand_qmul@121 1961 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
ivand_qmul@121 1962 } else {
ivand_qmul@121 1963 description = QString("%1Hz").arg(ssr);
ivand_qmul@121 1964 }
ivand_qmul@121 1965
ivand_qmul@121 1966 description = QString("%1 - %2")
ivand_qmul@121 1967 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
ivand_qmul@121 1968 .toText(false).c_str())
ivand_qmul@121 1969 .arg(description);
ivand_qmul@121 1970
ivand_qmul@121 1971 m_descriptionLabel->setText(description);
ivand_qmul@121 1972 }
ivand_qmul@121 1973
ivand_qmul@121 1974 void
ivand_qmul@121 1975 MainWindow::documentModified()
ivand_qmul@121 1976 {
ivand_qmul@121 1977 // std::cerr << "MainWindow::documentModified" << std::endl;
ivand_qmul@121 1978
ivand_qmul@121 1979 if (!m_documentModified) {
ivand_qmul@121 1980 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
ivand_qmul@121 1981 }
ivand_qmul@121 1982
ivand_qmul@121 1983 m_documentModified = true;
ivand_qmul@121 1984 updateMenuStates();
ivand_qmul@121 1985 }
ivand_qmul@121 1986
ivand_qmul@121 1987 void
ivand_qmul@121 1988 MainWindow::documentRestored()
ivand_qmul@121 1989 {
ivand_qmul@121 1990 // std::cerr << "MainWindow::documentRestored" << std::endl;
ivand_qmul@121 1991
ivand_qmul@121 1992 if (m_documentModified) {
ivand_qmul@121 1993 QString wt(windowTitle());
ivand_qmul@121 1994 wt.replace(tr(" (modified)"), "");
ivand_qmul@121 1995 setWindowTitle(wt);
ivand_qmul@121 1996 }
ivand_qmul@121 1997
ivand_qmul@121 1998 m_documentModified = false;
ivand_qmul@121 1999 updateMenuStates();
ivand_qmul@121 2000 }
ivand_qmul@121 2001
ivand_qmul@121 2002 void
ivand_qmul@121 2003 MainWindow::playLoopToggled()
ivand_qmul@121 2004 {
ivand_qmul@121 2005 QAction *action = dynamic_cast<QAction *>(sender());
ivand_qmul@121 2006
ivand_qmul@121 2007 if (action) {
ivand_qmul@121 2008 m_viewManager->setPlayLoopMode(action->isChecked());
ivand_qmul@121 2009 } else {
ivand_qmul@121 2010 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
ivand_qmul@121 2011 }
ivand_qmul@121 2012 }
ivand_qmul@121 2013
ivand_qmul@121 2014 void
ivand_qmul@121 2015 MainWindow::playSelectionToggled()
ivand_qmul@121 2016 {
ivand_qmul@121 2017 QAction *action = dynamic_cast<QAction *>(sender());
ivand_qmul@121 2018
ivand_qmul@121 2019 if (action) {
ivand_qmul@121 2020 m_viewManager->setPlaySelectionMode(action->isChecked());
ivand_qmul@121 2021 } else {
ivand_qmul@121 2022 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
ivand_qmul@121 2023 }
ivand_qmul@121 2024 }
ivand_qmul@121 2025
ivand_qmul@121 2026 void
ivand_qmul@121 2027 MainWindow::currentPaneChanged(Pane *p)
ivand_qmul@121 2028 {
ivand_qmul@121 2029 updateMenuStates();
ivand_qmul@121 2030 updateVisibleRangeDisplay(p);
ivand_qmul@121 2031 emit newCurrentPane(p);
ivand_qmul@121 2032 }
ivand_qmul@121 2033
ivand_qmul@121 2034 void
ivand_qmul@121 2035 MainWindow::currentLayerChanged(Pane *p, Layer *)
ivand_qmul@121 2036 {
ivand_qmul@121 2037 updateMenuStates();
ivand_qmul@121 2038 updateVisibleRangeDisplay(p);
ivand_qmul@121 2039 }
ivand_qmul@121 2040
ivand_qmul@121 2041 void
ivand_qmul@121 2042 MainWindow::toolNavigateSelected()
ivand_qmul@121 2043 {
ivand_qmul@121 2044 m_viewManager->setToolMode(ViewManager::NavigateMode);
ivand_qmul@121 2045 }
ivand_qmul@121 2046
ivand_qmul@121 2047 void
ivand_qmul@121 2048 MainWindow::toolSelectSelected()
ivand_qmul@121 2049 {
ivand_qmul@121 2050 m_viewManager->setToolMode(ViewManager::SelectMode);
ivand_qmul@121 2051 }
ivand_qmul@121 2052
ivand_qmul@121 2053 void
ivand_qmul@121 2054 MainWindow::toolEditSelected()
ivand_qmul@121 2055 {
ivand_qmul@121 2056 m_viewManager->setToolMode(ViewManager::EditMode);
ivand_qmul@121 2057 }
ivand_qmul@121 2058
ivand_qmul@121 2059 void
ivand_qmul@121 2060 MainWindow::toolDrawSelected()
ivand_qmul@121 2061 {
ivand_qmul@121 2062 m_viewManager->setToolMode(ViewManager::DrawMode);
ivand_qmul@121 2063 }
ivand_qmul@121 2064
ivand_qmul@121 2065 //void
ivand_qmul@121 2066 //MainWindow::toolTextSelected()
ivand_qmul@121 2067 //{
ivand_qmul@121 2068 // m_viewManager->setToolMode(ViewManager::TextMode);
ivand_qmul@121 2069 //}
ivand_qmul@121 2070
ivand_qmul@121 2071 void
ivand_qmul@121 2072 MainWindow::selectAll()
ivand_qmul@121 2073 {
ivand_qmul@121 2074 if (!getMainModel()) return;
ivand_qmul@121 2075 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
ivand_qmul@121 2076 getMainModel()->getEndFrame()));
ivand_qmul@121 2077 }
ivand_qmul@121 2078
ivand_qmul@121 2079 void
ivand_qmul@121 2080 MainWindow::selectToStart()
ivand_qmul@121 2081 {
ivand_qmul@121 2082 if (!getMainModel()) return;
ivand_qmul@121 2083 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
ivand_qmul@121 2084 m_viewManager->getGlobalCentreFrame()));
ivand_qmul@121 2085 }
ivand_qmul@121 2086
ivand_qmul@121 2087 void
ivand_qmul@121 2088 MainWindow::selectToEnd()
ivand_qmul@121 2089 {
ivand_qmul@121 2090 if (!getMainModel()) return;
ivand_qmul@121 2091 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
ivand_qmul@121 2092 getMainModel()->getEndFrame()));
ivand_qmul@121 2093 }
ivand_qmul@121 2094
ivand_qmul@121 2095 void
ivand_qmul@121 2096 MainWindow::selectVisible()
ivand_qmul@121 2097 {
ivand_qmul@121 2098 Model *model = getMainModel();
ivand_qmul@121 2099 if (!model) return;
ivand_qmul@121 2100
ivand_qmul@121 2101 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 2102 if (!currentPane) return;
ivand_qmul@121 2103
ivand_qmul@121 2104 size_t startFrame, endFrame;
ivand_qmul@121 2105
ivand_qmul@121 2106 if (currentPane->getStartFrame() < 0) startFrame = 0;
ivand_qmul@121 2107 else startFrame = currentPane->getStartFrame();
ivand_qmul@121 2108
ivand_qmul@121 2109 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
ivand_qmul@121 2110 else endFrame = currentPane->getEndFrame();
ivand_qmul@121 2111
ivand_qmul@121 2112 m_viewManager->setSelection(Selection(startFrame, endFrame));
ivand_qmul@121 2113 }
ivand_qmul@121 2114
ivand_qmul@121 2115 void
ivand_qmul@121 2116 MainWindow::clearSelection()
ivand_qmul@121 2117 {
ivand_qmul@121 2118 m_viewManager->clearSelections();
ivand_qmul@121 2119 }
ivand_qmul@121 2120
ivand_qmul@121 2121 void
ivand_qmul@121 2122 MainWindow::cut()
ivand_qmul@121 2123 {
ivand_qmul@121 2124 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 2125 if (!currentPane) return;
ivand_qmul@121 2126
ivand_qmul@121 2127 Layer *layer = currentPane->getSelectedLayer();
ivand_qmul@121 2128 if (!layer) return;
ivand_qmul@121 2129
ivand_qmul@121 2130 Clipboard &clipboard = m_viewManager->getClipboard();
ivand_qmul@121 2131 clipboard.clear();
ivand_qmul@121 2132
ivand_qmul@121 2133 MultiSelection::SelectionList selections = m_viewManager->getSelections();
ivand_qmul@121 2134
ivand_qmul@121 2135 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
ivand_qmul@121 2136
ivand_qmul@121 2137 for (MultiSelection::SelectionList::iterator i = selections.begin();
ivand_qmul@121 2138 i != selections.end(); ++i) {
ivand_qmul@121 2139 layer->copy(*i, clipboard);
ivand_qmul@121 2140 layer->deleteSelection(*i);
ivand_qmul@121 2141 }
ivand_qmul@121 2142
ivand_qmul@121 2143 CommandHistory::getInstance()->endCompoundOperation();
ivand_qmul@121 2144 }
ivand_qmul@121 2145
ivand_qmul@121 2146 void
ivand_qmul@121 2147 MainWindow::copy()
ivand_qmul@121 2148 {
ivand_qmul@121 2149 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 2150 if (!currentPane) return;
ivand_qmul@121 2151
ivand_qmul@121 2152 Layer *layer = currentPane->getSelectedLayer();
ivand_qmul@121 2153 if (!layer) return;
ivand_qmul@121 2154
ivand_qmul@121 2155 Clipboard &clipboard = m_viewManager->getClipboard();
ivand_qmul@121 2156 clipboard.clear();
ivand_qmul@121 2157
ivand_qmul@121 2158 MultiSelection::SelectionList selections = m_viewManager->getSelections();
ivand_qmul@121 2159
ivand_qmul@121 2160 for (MultiSelection::SelectionList::iterator i = selections.begin();
ivand_qmul@121 2161 i != selections.end(); ++i) {
ivand_qmul@121 2162 layer->copy(*i, clipboard);
ivand_qmul@121 2163 }
ivand_qmul@121 2164 }
ivand_qmul@121 2165
ivand_qmul@121 2166 void
ivand_qmul@121 2167 MainWindow::paste()
ivand_qmul@121 2168 {
ivand_qmul@121 2169 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 2170 if (!currentPane) return;
ivand_qmul@121 2171
ivand_qmul@121 2172 //!!! if we have no current layer, we should create one of the most
ivand_qmul@121 2173 // appropriate type
ivand_qmul@121 2174
ivand_qmul@121 2175 Layer *layer = currentPane->getSelectedLayer();
ivand_qmul@121 2176 if (!layer) return;
ivand_qmul@121 2177
ivand_qmul@121 2178 Clipboard &clipboard = m_viewManager->getClipboard();
ivand_qmul@121 2179 Clipboard::PointList contents = clipboard.getPoints();
ivand_qmul@121 2180 /*
ivand_qmul@121 2181 long minFrame = 0;
ivand_qmul@121 2182 bool have = false;
ivand_qmul@121 2183 for (int i = 0; i < contents.size(); ++i) {
ivand_qmul@121 2184 if (!contents[i].haveFrame()) continue;
ivand_qmul@121 2185 if (!have || contents[i].getFrame() < minFrame) {
ivand_qmul@121 2186 minFrame = contents[i].getFrame();
ivand_qmul@121 2187 have = true;
ivand_qmul@121 2188 }
ivand_qmul@121 2189 }
ivand_qmul@121 2190
ivand_qmul@121 2191 long frameOffset = long(m_viewManager->getGlobalCentreFrame()) - minFrame;
ivand_qmul@121 2192
ivand_qmul@121 2193 layer->paste(clipboard, frameOffset);
ivand_qmul@121 2194 */
ivand_qmul@121 2195 layer->paste(clipboard, 0, true);
ivand_qmul@121 2196 }
ivand_qmul@121 2197
ivand_qmul@121 2198 void
ivand_qmul@121 2199 MainWindow::deleteSelected()
ivand_qmul@121 2200 {
ivand_qmul@121 2201 if (m_paneStack->getCurrentPane() &&
ivand_qmul@121 2202 m_paneStack->getCurrentPane()->getSelectedLayer()) {
ivand_qmul@121 2203
ivand_qmul@121 2204 MultiSelection::SelectionList selections =
ivand_qmul@121 2205 m_viewManager->getSelections();
ivand_qmul@121 2206
ivand_qmul@121 2207 for (MultiSelection::SelectionList::iterator i = selections.begin();
ivand_qmul@121 2208 i != selections.end(); ++i) {
ivand_qmul@121 2209
ivand_qmul@121 2210 m_paneStack->getCurrentPane()->getSelectedLayer()->deleteSelection(*i);
ivand_qmul@121 2211 }
ivand_qmul@121 2212 }
ivand_qmul@121 2213 }
ivand_qmul@121 2214
ivand_qmul@121 2215 void
ivand_qmul@121 2216 MainWindow::insertInstant()
ivand_qmul@121 2217 {
ivand_qmul@121 2218 int frame = m_viewManager->getPlaybackFrame();
ivand_qmul@121 2219 insertInstantAt(frame);
ivand_qmul@121 2220 }
ivand_qmul@121 2221
ivand_qmul@121 2222 void
ivand_qmul@121 2223 MainWindow::insertInstantsAtBoundaries()
ivand_qmul@121 2224 {
ivand_qmul@121 2225 MultiSelection::SelectionList selections = m_viewManager->getSelections();
ivand_qmul@121 2226 for (MultiSelection::SelectionList::iterator i = selections.begin();
ivand_qmul@121 2227 i != selections.end(); ++i) {
ivand_qmul@121 2228 size_t start = i->getStartFrame();
ivand_qmul@121 2229 size_t end = i->getEndFrame();
ivand_qmul@121 2230 if (start != end) {
ivand_qmul@121 2231 insertInstantAt(i->getStartFrame());
ivand_qmul@121 2232 insertInstantAt(i->getEndFrame());
ivand_qmul@121 2233 }
ivand_qmul@121 2234 }
ivand_qmul@121 2235 }
ivand_qmul@121 2236
ivand_qmul@121 2237 void
ivand_qmul@121 2238 MainWindow::insertInstantAt(size_t frame)
ivand_qmul@121 2239 {
ivand_qmul@121 2240 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 2241 if (!pane) {
ivand_qmul@121 2242 return;
ivand_qmul@121 2243 }
ivand_qmul@121 2244
ivand_qmul@121 2245 Layer *layer = dynamic_cast<TimeInstantLayer *>
ivand_qmul@121 2246 (pane->getSelectedLayer());
ivand_qmul@121 2247
ivand_qmul@121 2248 if (!layer) {
ivand_qmul@121 2249 for (int i = pane->getLayerCount(); i > 0; --i) {
ivand_qmul@121 2250 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
ivand_qmul@121 2251 if (layer) break;
ivand_qmul@121 2252 }
ivand_qmul@121 2253
ivand_qmul@121 2254 if (!layer) {
ivand_qmul@121 2255 CommandHistory::getInstance()->startCompoundOperation
ivand_qmul@121 2256 (tr("Add Point"), true);
ivand_qmul@121 2257 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
ivand_qmul@121 2258 if (layer) {
ivand_qmul@121 2259 m_document->addLayerToView(pane, layer);
ivand_qmul@121 2260 m_paneStack->setCurrentLayer(pane, layer);
ivand_qmul@121 2261 }
ivand_qmul@121 2262 CommandHistory::getInstance()->endCompoundOperation();
ivand_qmul@121 2263 }
ivand_qmul@121 2264 }
ivand_qmul@121 2265
ivand_qmul@121 2266 if (layer) {
ivand_qmul@121 2267
ivand_qmul@121 2268 Model *model = layer->getModel();
ivand_qmul@121 2269 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
ivand_qmul@121 2270 (model);
ivand_qmul@121 2271
ivand_qmul@121 2272 if (sodm) {
ivand_qmul@121 2273 SparseOneDimensionalModel::Point point
ivand_qmul@121 2274 (frame, QString("%1").arg(sodm->getPointCount() + 1));
ivand_qmul@121 2275 CommandHistory::getInstance()->addCommand
ivand_qmul@121 2276 (new SparseOneDimensionalModel::AddPointCommand(sodm, point,
ivand_qmul@121 2277 tr("Add Points")),
ivand_qmul@121 2278 true, true); // bundled
ivand_qmul@121 2279 }
ivand_qmul@121 2280 }
ivand_qmul@121 2281 }
ivand_qmul@121 2282
ivand_qmul@121 2283 void
ivand_qmul@121 2284 MainWindow::importAudio()
ivand_qmul@121 2285 {
ivand_qmul@121 2286 QString path = getOpenFileName(FileFinder::AudioFile);
ivand_qmul@121 2287
ivand_qmul@121 2288 if (path != "") {
ivand_qmul@121 2289 if (openAudioFile(path, ReplaceMainModel) == FileOpenFailed) {
ivand_qmul@121 2290 QMessageBox::critical(this, tr("Failed to open file"),
ivand_qmul@121 2291 tr("Audio file \"%1\" could not be opened").arg(path));
ivand_qmul@121 2292 }
ivand_qmul@121 2293 }
ivand_qmul@121 2294 }
ivand_qmul@121 2295
ivand_qmul@121 2296 void
ivand_qmul@121 2297 MainWindow::importMoreAudio()
ivand_qmul@121 2298 {
ivand_qmul@121 2299 QString path = getOpenFileName(FileFinder::AudioFile);
ivand_qmul@121 2300
ivand_qmul@121 2301 if (path != "") {
ivand_qmul@121 2302 if (openAudioFile(path, CreateAdditionalModel) == FileOpenFailed) {
ivand_qmul@121 2303 QMessageBox::critical(this, tr("Failed to open file"),
ivand_qmul@121 2304 tr("Audio file \"%1\" could not be opened").arg(path));
ivand_qmul@121 2305 }
ivand_qmul@121 2306 }
ivand_qmul@121 2307 }
ivand_qmul@121 2308
ivand_qmul@121 2309 void
ivand_qmul@121 2310 MainWindow::exportAudio()
ivand_qmul@121 2311 {
ivand_qmul@121 2312 if (!getMainModel()) return;
ivand_qmul@121 2313
ivand_qmul@121 2314 QString path = getSaveFileName(FileFinder::AudioFile);
ivand_qmul@121 2315
ivand_qmul@121 2316 if (path == "") return;
ivand_qmul@121 2317
ivand_qmul@121 2318 bool ok = false;
ivand_qmul@121 2319 QString error;
ivand_qmul@121 2320
ivand_qmul@121 2321 MultiSelection ms = m_viewManager->getSelection();
ivand_qmul@121 2322 MultiSelection::SelectionList selections = m_viewManager->getSelections();
ivand_qmul@121 2323
ivand_qmul@121 2324 bool multiple = false;
ivand_qmul@121 2325
ivand_qmul@121 2326 MultiSelection *selectionToWrite = 0;
ivand_qmul@121 2327
ivand_qmul@121 2328 if (selections.size() == 1) {
ivand_qmul@121 2329
ivand_qmul@121 2330 QStringList items;
ivand_qmul@121 2331 items << tr("Export the selected region only")
ivand_qmul@121 2332 << tr("Export the whole audio file");
ivand_qmul@121 2333
ivand_qmul@121 2334 bool ok = false;
ivand_qmul@121 2335 QString item = ListInputDialog::getItem
ivand_qmul@121 2336 (this, tr("Select region to export"),
ivand_qmul@121 2337 tr("Which region from the original audio file do you want to export?"),
ivand_qmul@121 2338 items, 0, &ok);
ivand_qmul@121 2339
ivand_qmul@121 2340 if (!ok || item.isEmpty()) return;
ivand_qmul@121 2341
ivand_qmul@121 2342 if (item == items[0]) selectionToWrite = &ms;
ivand_qmul@121 2343
ivand_qmul@121 2344 } else if (selections.size() > 1) {
ivand_qmul@121 2345
ivand_qmul@121 2346 QStringList items;
ivand_qmul@121 2347 items << tr("Export the selected regions into a single audio file")
ivand_qmul@121 2348 << tr("Export the selected regions into separate files")
ivand_qmul@121 2349 << tr("Export the whole audio file");
ivand_qmul@121 2350
ivand_qmul@121 2351 QString item = ListInputDialog::getItem
ivand_qmul@121 2352 (this, tr("Select region to export"),
ivand_qmul@121 2353 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
ivand_qmul@121 2354 items, 0, &ok);
ivand_qmul@121 2355
ivand_qmul@121 2356 if (!ok || item.isEmpty()) return;
ivand_qmul@121 2357
ivand_qmul@121 2358 if (item == items[0]) {
ivand_qmul@121 2359
ivand_qmul@121 2360 selectionToWrite = &ms;
ivand_qmul@121 2361
ivand_qmul@121 2362 } else if (item == items[1]) {
ivand_qmul@121 2363
ivand_qmul@121 2364 multiple = true;
ivand_qmul@121 2365
ivand_qmul@121 2366 int n = 1;
ivand_qmul@121 2367 QString base = path;
ivand_qmul@121 2368 base.replace(".wav", "");
ivand_qmul@121 2369
ivand_qmul@121 2370 for (MultiSelection::SelectionList::iterator i = selections.begin();
ivand_qmul@121 2371 i != selections.end(); ++i) {
ivand_qmul@121 2372
ivand_qmul@121 2373 MultiSelection subms;
ivand_qmul@121 2374 subms.setSelection(*i);
ivand_qmul@121 2375
ivand_qmul@121 2376 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
ivand_qmul@121 2377 ++n;
ivand_qmul@121 2378
ivand_qmul@121 2379 if (QFileInfo(subpath).exists()) {
ivand_qmul@121 2380 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
ivand_qmul@121 2381 break;
ivand_qmul@121 2382 }
ivand_qmul@121 2383
ivand_qmul@121 2384 WavFileWriter subwriter(subpath,
ivand_qmul@121 2385 getMainModel()->getSampleRate(),
ivand_qmul@121 2386 getMainModel()->getChannelCount());
ivand_qmul@121 2387 subwriter.writeModel(getMainModel(), &subms);
ivand_qmul@121 2388 ok = subwriter.isOK();
ivand_qmul@121 2389
ivand_qmul@121 2390 if (!ok) {
ivand_qmul@121 2391 error = subwriter.getError();
ivand_qmul@121 2392 break;
ivand_qmul@121 2393 }
ivand_qmul@121 2394 }
ivand_qmul@121 2395 }
ivand_qmul@121 2396 }
ivand_qmul@121 2397
ivand_qmul@121 2398 if (!multiple) {
ivand_qmul@121 2399 WavFileWriter writer(path,
ivand_qmul@121 2400 getMainModel()->getSampleRate(),
ivand_qmul@121 2401 getMainModel()->getChannelCount());
ivand_qmul@121 2402 writer.writeModel(getMainModel(), selectionToWrite);
ivand_qmul@121 2403 ok = writer.isOK();
ivand_qmul@121 2404 error = writer.getError();
ivand_qmul@121 2405 }
ivand_qmul@121 2406
ivand_qmul@121 2407 if (ok) {
ivand_qmul@121 2408 if (!multiple) {
ivand_qmul@121 2409 m_recentFiles.addFile(path);
ivand_qmul@121 2410 }
ivand_qmul@121 2411 } else {
ivand_qmul@121 2412 QMessageBox::critical(this, tr("Failed to write file"), error);
ivand_qmul@121 2413 }
ivand_qmul@121 2414 }
ivand_qmul@121 2415
ivand_qmul@129 2416 // Ivan Damnjanovic 09-10/2007 added video file import
ivand_qmul@121 2417 void
ivand_qmul@121 2418 MainWindow::importVideo()
ivand_qmul@121 2419 {
ivand_qmul@121 2420 QString path = getOpenFileName(FileFinder::VideoFile);
ivand_qmul@121 2421
ivand_qmul@121 2422 if (path != "") {
benoitrigolleau@130 2423 if (openVideoFile(path, ReplaceMainModel) == FileOpenFailed) {
benoitrigolleau@130 2424 QMessageBox::critical(this, tr("Failed to open file"),
benoitrigolleau@130 2425 tr("Video file \"%1\" could not be opened").arg(path));
benoitrigolleau@130 2426 }
benoitrigolleau@130 2427
ivand_qmul@121 2428 }
ivand_qmul@121 2429 }
ivand_qmul@121 2430 //
ivand_qmul@121 2431 void
ivand_qmul@121 2432 MainWindow::importLayer()
ivand_qmul@121 2433 {
ivand_qmul@121 2434 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 2435
ivand_qmul@121 2436 if (!pane) {
ivand_qmul@121 2437 // shouldn't happen, as the menu action should have been disabled
ivand_qmul@121 2438 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
ivand_qmul@121 2439 return;
ivand_qmul@121 2440 }
ivand_qmul@121 2441
ivand_qmul@121 2442 if (!getMainModel()) {
ivand_qmul@121 2443 // shouldn't happen, as the menu action should have been disabled
ivand_qmul@121 2444 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
ivand_qmul@121 2445 return;
ivand_qmul@121 2446 }
ivand_qmul@121 2447
ivand_qmul@121 2448 QString path = getOpenFileName(FileFinder::LayerFile);
ivand_qmul@121 2449
ivand_qmul@121 2450 if (path != "") {
ivand_qmul@121 2451
ivand_qmul@121 2452 if (openLayerFile(path) == FileOpenFailed) {
ivand_qmul@121 2453 QMessageBox::critical(this, tr("Failed to open file"),
ivand_qmul@121 2454 tr("File %1 could not be opened.").arg(path));
ivand_qmul@121 2455 return;
ivand_qmul@121 2456 }
ivand_qmul@121 2457 }
ivand_qmul@121 2458 }
ivand_qmul@121 2459
ivand_qmul@121 2460 MainWindow::FileOpenStatus
ivand_qmul@121 2461 MainWindow::openLayerFile(QString path)
ivand_qmul@121 2462 {
ivand_qmul@121 2463 return openLayerFile(path, path);
ivand_qmul@121 2464 }
ivand_qmul@121 2465
ivand_qmul@121 2466 MainWindow::FileOpenStatus
ivand_qmul@121 2467 MainWindow::openLayerFile(QString path, QString location)
ivand_qmul@121 2468 {
ivand_qmul@121 2469 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 2470
ivand_qmul@121 2471 if (!pane) {
ivand_qmul@121 2472 // shouldn't happen, as the menu action should have been disabled
ivand_qmul@121 2473 std::cerr << "WARNING: MainWindow::openLayerFile: no current pane" << std::endl;
ivand_qmul@121 2474 return FileOpenFailed;
ivand_qmul@121 2475 }
ivand_qmul@121 2476
ivand_qmul@121 2477 if (!getMainModel()) {
ivand_qmul@121 2478 // shouldn't happen, as the menu action should have been disabled
ivand_qmul@121 2479 std::cerr << "WARNING: MainWindow::openLayerFile: No main model -- hence no default sample rate available" << std::endl;
ivand_qmul@121 2480 return FileOpenFailed;
ivand_qmul@121 2481 }
ivand_qmul@121 2482
ivand_qmul@121 2483 bool realFile = (location == path);
ivand_qmul@121 2484
ivand_qmul@121 2485 if (path.endsWith(".svl") || path.endsWith(".xml")) {
ivand_qmul@121 2486
ivand_qmul@121 2487 PaneCallback callback(this);
ivand_qmul@121 2488 QFile file(path);
ivand_qmul@121 2489
ivand_qmul@121 2490 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
ivand_qmul@121 2491 std::cerr << "ERROR: MainWindow::openLayerFile("
ivand_qmul@121 2492 << location.toStdString()
ivand_qmul@121 2493 << "): Failed to open file for reading" << std::endl;
ivand_qmul@121 2494 return FileOpenFailed;
ivand_qmul@121 2495 }
ivand_qmul@121 2496
ivand_qmul@121 2497 SVFileReader reader(m_document, callback, location);
ivand_qmul@121 2498 reader.setCurrentPane(pane);
ivand_qmul@121 2499
ivand_qmul@121 2500 QXmlInputSource inputSource(&file);
ivand_qmul@121 2501 reader.parse(inputSource);
ivand_qmul@121 2502
ivand_qmul@121 2503 if (!reader.isOK()) {
ivand_qmul@121 2504 std::cerr << "ERROR: MainWindow::openLayerFile("
ivand_qmul@121 2505 << location.toStdString()
ivand_qmul@121 2506 << "): Failed to read XML file: "
ivand_qmul@121 2507 << reader.getErrorString().toStdString() << std::endl;
ivand_qmul@121 2508 return FileOpenFailed;
ivand_qmul@121 2509 }
ivand_qmul@121 2510
ivand_qmul@121 2511 m_recentFiles.addFile(location);
ivand_qmul@121 2512
ivand_qmul@121 2513 if (realFile) {
ivand_qmul@121 2514 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
ivand_qmul@121 2515 }
ivand_qmul@121 2516
ivand_qmul@121 2517 return FileOpenSucceeded;
ivand_qmul@121 2518
ivand_qmul@121 2519 } else {
ivand_qmul@121 2520
ivand_qmul@121 2521 Model *model = DataFileReaderFactory::load(path, getMainModel()->getSampleRate());
ivand_qmul@121 2522
ivand_qmul@121 2523 if (model) {
ivand_qmul@121 2524
ivand_qmul@121 2525 Layer *newLayer = m_document->createImportedLayer(model);
ivand_qmul@121 2526
ivand_qmul@121 2527 if (newLayer) {
ivand_qmul@121 2528
ivand_qmul@121 2529 m_document->addLayerToView(pane, newLayer);
ivand_qmul@121 2530 m_recentFiles.addFile(location);
ivand_qmul@121 2531
ivand_qmul@121 2532 if (realFile) {
ivand_qmul@121 2533 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
ivand_qmul@121 2534 }
ivand_qmul@121 2535
ivand_qmul@121 2536 return FileOpenSucceeded;
ivand_qmul@121 2537 }
ivand_qmul@121 2538 }
ivand_qmul@121 2539 }
ivand_qmul@121 2540
ivand_qmul@121 2541 return FileOpenFailed;
ivand_qmul@121 2542 }
ivand_qmul@121 2543
ivand_qmul@121 2544 void
ivand_qmul@121 2545 MainWindow::exportLayer()
ivand_qmul@121 2546 {
ivand_qmul@121 2547 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 2548 if (!pane) return;
ivand_qmul@121 2549
ivand_qmul@121 2550 Layer *layer = pane->getSelectedLayer();
ivand_qmul@121 2551 if (!layer) return;
ivand_qmul@121 2552
ivand_qmul@121 2553 Model *model = layer->getModel();
ivand_qmul@121 2554 if (!model) return;
ivand_qmul@121 2555
ivand_qmul@121 2556 QString path = getSaveFileName(FileFinder::LayerFile);
ivand_qmul@121 2557
ivand_qmul@121 2558 if (path == "") return;
ivand_qmul@121 2559
ivand_qmul@121 2560 if (QFileInfo(path).suffix() == "") path += ".svl";
ivand_qmul@121 2561
ivand_qmul@121 2562 QString error;
ivand_qmul@121 2563
ivand_qmul@121 2564 if (path.endsWith(".xml") || path.endsWith(".svl")) {
ivand_qmul@121 2565
ivand_qmul@121 2566 QFile file(path);
ivand_qmul@121 2567 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
ivand_qmul@121 2568 error = tr("Failed to open file %1 for writing").arg(path);
ivand_qmul@121 2569 } else {
ivand_qmul@121 2570 QTextStream out(&file);
ivand_qmul@121 2571 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
ivand_qmul@121 2572 << "<!DOCTYPE sonic-visualiser>\n"
ivand_qmul@121 2573 << "<sv>\n"
ivand_qmul@121 2574 << " <data>\n";
ivand_qmul@121 2575
ivand_qmul@121 2576 model->toXml(out, " ");
ivand_qmul@121 2577
ivand_qmul@121 2578 out << " </data>\n"
ivand_qmul@121 2579 << " <display>\n";
ivand_qmul@121 2580
ivand_qmul@121 2581 layer->toXml(out, " ");
ivand_qmul@121 2582
ivand_qmul@121 2583 out << " </display>\n"
ivand_qmul@121 2584 << "</sv>\n";
ivand_qmul@121 2585 }
ivand_qmul@121 2586
ivand_qmul@121 2587 } else {
ivand_qmul@121 2588
ivand_qmul@121 2589 CSVFileWriter writer(path, model,
ivand_qmul@121 2590 (path.endsWith(".csv") ? "," : "\t"));
ivand_qmul@121 2591 writer.write();
ivand_qmul@121 2592
ivand_qmul@121 2593 if (!writer.isOK()) {
ivand_qmul@121 2594 error = writer.getError();
ivand_qmul@121 2595 }
ivand_qmul@121 2596 }
ivand_qmul@121 2597
ivand_qmul@121 2598 if (error != "") {
ivand_qmul@121 2599 QMessageBox::critical(this, tr("Failed to write file"), error);
ivand_qmul@121 2600 } else {
ivand_qmul@121 2601 m_recentFiles.addFile(path);
ivand_qmul@121 2602 }
ivand_qmul@121 2603 }
ivand_qmul@121 2604
ivand_qmul@121 2605 void
ivand_qmul@121 2606 MainWindow::exportImage()
ivand_qmul@121 2607 {
ivand_qmul@121 2608 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 2609 if (!pane) return;
ivand_qmul@121 2610
ivand_qmul@121 2611 QString path = getSaveFileName(FileFinder::ImageFile);
ivand_qmul@121 2612
ivand_qmul@121 2613 if (path == "") return;
ivand_qmul@121 2614
ivand_qmul@121 2615 if (QFileInfo(path).suffix() == "") path += ".png";
ivand_qmul@121 2616
ivand_qmul@121 2617 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty();
ivand_qmul@121 2618
ivand_qmul@121 2619 QSize total, visible, selected;
ivand_qmul@121 2620 total = pane->getImageSize();
ivand_qmul@121 2621 visible = pane->getImageSize(pane->getFirstVisibleFrame(),
ivand_qmul@121 2622 pane->getLastVisibleFrame());
ivand_qmul@121 2623
ivand_qmul@121 2624 size_t sf0 = 0, sf1 = 0;
ivand_qmul@121 2625
ivand_qmul@121 2626 if (haveSelection) {
ivand_qmul@121 2627 MultiSelection::SelectionList selections = m_viewManager->getSelections();
ivand_qmul@121 2628 sf0 = selections.begin()->getStartFrame();
ivand_qmul@121 2629 MultiSelection::SelectionList::iterator e = selections.end();
ivand_qmul@121 2630 --e;
ivand_qmul@121 2631 sf1 = e->getEndFrame();
ivand_qmul@121 2632 selected = pane->getImageSize(sf0, sf1);
ivand_qmul@121 2633 }
ivand_qmul@121 2634
ivand_qmul@121 2635 QStringList items;
ivand_qmul@121 2636 items << tr("Export the whole pane (%1x%2 pixels)")
ivand_qmul@121 2637 .arg(total.width()).arg(total.height());
ivand_qmul@121 2638 items << tr("Export the visible area only (%1x%2 pixels)")
ivand_qmul@121 2639 .arg(visible.width()).arg(visible.height());
ivand_qmul@121 2640 if (haveSelection) {
ivand_qmul@121 2641 items << tr("Export the selection extent (%1x%2 pixels)")
ivand_qmul@121 2642 .arg(selected.width()).arg(selected.height());
ivand_qmul@121 2643 } else {
ivand_qmul@121 2644 items << tr("Export the selection extent");
ivand_qmul@121 2645 }
ivand_qmul@121 2646
ivand_qmul@121 2647 QSettings settings;
ivand_qmul@121 2648 settings.beginGroup("MainWindow");
ivand_qmul@121 2649 int deflt = settings.value("lastimageexportregion", 0).toInt();
ivand_qmul@121 2650 if (deflt == 2 && !haveSelection) deflt = 1;
ivand_qmul@121 2651 if (deflt == 0 && total.width() > 32767) deflt = 1;
ivand_qmul@121 2652
ivand_qmul@121 2653 ListInputDialog *lid = new ListInputDialog
ivand_qmul@121 2654 (this, tr("Select region to export"),
ivand_qmul@121 2655 tr("Which region of the current pane do you want to export as an image?"),
ivand_qmul@121 2656 items, deflt);
ivand_qmul@121 2657
ivand_qmul@121 2658 if (!haveSelection) {
ivand_qmul@121 2659 lid->setItemAvailability(2, false);
ivand_qmul@121 2660 }
ivand_qmul@121 2661 if (total.width() > 32767) { // appears to be the limit of a QImage
ivand_qmul@121 2662 lid->setItemAvailability(0, false);
ivand_qmul@121 2663 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image."));
ivand_qmul@121 2664 }
ivand_qmul@121 2665
ivand_qmul@121 2666 bool ok = lid->exec();
ivand_qmul@121 2667 QString item = lid->getCurrentString();
ivand_qmul@121 2668 delete lid;
lbajardsilogic@180 2669 lid = 0;
ivand_qmul@121 2670
ivand_qmul@121 2671 if (!ok || item.isEmpty()) return;
ivand_qmul@121 2672
ivand_qmul@121 2673 settings.setValue("lastimageexportregion", deflt);
ivand_qmul@121 2674
ivand_qmul@121 2675 QImage *image = 0;
ivand_qmul@121 2676
ivand_qmul@121 2677 if (item == items[0]) {
ivand_qmul@121 2678 image = pane->toNewImage();
ivand_qmul@121 2679 } else if (item == items[1]) {
ivand_qmul@121 2680 image = pane->toNewImage(pane->getFirstVisibleFrame(),
ivand_qmul@121 2681 pane->getLastVisibleFrame());
ivand_qmul@121 2682 } else if (haveSelection) {
ivand_qmul@121 2683 image = pane->toNewImage(sf0, sf1);
ivand_qmul@121 2684 }
ivand_qmul@121 2685
ivand_qmul@121 2686 if (!image) return;
ivand_qmul@121 2687
ivand_qmul@121 2688 if (!image->save(path, "PNG")) {
ivand_qmul@121 2689 QMessageBox::critical(this, tr("Failed to save image file"),
ivand_qmul@121 2690 tr("Failed to save image file %1").arg(path));
ivand_qmul@121 2691 }
ivand_qmul@121 2692
ivand_qmul@121 2693 delete image;
lbajardsilogic@180 2694 image = 0;
ivand_qmul@121 2695 }
ivand_qmul@121 2696
ivand_qmul@121 2697 // Ivan Damnjanovic 09-10/2007 added video file import
ivand_qmul@121 2698 MainWindow::FileOpenStatus
ivand_qmul@121 2699 MainWindow::openVideoFile(QString path, AudioFileOpenMode mode)
ivand_qmul@121 2700 {
lbajardsilogic@146 2701 m_qtabwidget->setCurrentIndex(Video);
lbajardsilogic@146 2702
ivand_qmul@121 2703 return openAudioFile(path, path, mode);
ivand_qmul@121 2704 }
ivand_qmul@121 2705 //
ivand_qmul@121 2706 MainWindow::FileOpenStatus
ivand_qmul@121 2707 MainWindow::openAudioFile(QString path, AudioFileOpenMode mode)
ivand_qmul@121 2708 {
ivand_qmul@121 2709 return openAudioFile(path, path, mode);
ivand_qmul@121 2710 }
ivand_qmul@121 2711
ivand_qmul@121 2712 MainWindow::FileOpenStatus
ivand_qmul@121 2713 MainWindow::openAudioFile(QString path, QString location, AudioFileOpenMode mode)
ivand_qmul@121 2714 {
ivand_qmul@121 2715 if (!(QFileInfo(path).exists() &&
ivand_qmul@121 2716 QFileInfo(path).isFile() &&
ivand_qmul@121 2717 QFileInfo(path).isReadable())) {
ivand_qmul@121 2718 return FileOpenFailed;
ivand_qmul@121 2719 }
ivand_qmul@121 2720
ivand_qmul@121 2721 m_openingAudioFile = true;
ivand_qmul@121 2722
ivand_qmul@121 2723 WaveFileModel *newModel = new WaveFileModel(path, location);
ivand_qmul@121 2724
ivand_qmul@121 2725 if (!newModel->isOK()) {
lbajardsilogic@180 2726 delete newModel;
lbajardsilogic@180 2727 newModel = 0;
ivand_qmul@121 2728 m_openingAudioFile = false;
lbajardsilogic@180 2729 return FileOpenFailed;
ivand_qmul@121 2730 }
ivand_qmul@121 2731
ivand_qmul@121 2732 bool setAsMain = true;
ivand_qmul@121 2733 static bool prevSetAsMain = true;
ivand_qmul@121 2734
ivand_qmul@121 2735 bool realFile = (location == path);
ivand_qmul@121 2736
ivand_qmul@121 2737 if (mode == CreateAdditionalModel) setAsMain = false;
ivand_qmul@121 2738 else if (mode == AskUser) {
ivand_qmul@121 2739 if (m_document->getMainModel()) {
ivand_qmul@121 2740
ivand_qmul@121 2741 QStringList items;
ivand_qmul@121 2742 items << tr("Replace the existing main waveform")
ivand_qmul@121 2743 << tr("Load this file into a new waveform pane");
ivand_qmul@121 2744
ivand_qmul@121 2745 bool ok = false;
ivand_qmul@121 2746 QString item = ListInputDialog::getItem
ivand_qmul@121 2747 (this, tr("Select target for import"),
ivand_qmul@121 2748 tr("You already have an audio waveform loaded.\nWhat would you like to do with the new audio file?"),
ivand_qmul@121 2749 items, prevSetAsMain ? 0 : 1, &ok);
ivand_qmul@121 2750
ivand_qmul@121 2751 if (!ok || item.isEmpty()) {
ivand_qmul@121 2752 delete newModel;
lbajardsilogic@180 2753 newModel = 0;
ivand_qmul@121 2754 m_openingAudioFile = false;
ivand_qmul@121 2755 return FileOpenCancelled;
ivand_qmul@121 2756 }
ivand_qmul@121 2757
ivand_qmul@121 2758 setAsMain = (item == items[0]);
ivand_qmul@121 2759 prevSetAsMain = setAsMain;
ivand_qmul@121 2760 }
ivand_qmul@121 2761 }
ivand_qmul@121 2762
ivand_qmul@121 2763 if (setAsMain) {
ivand_qmul@121 2764
ivand_qmul@121 2765 Model *prevMain = getMainModel();
ivand_qmul@121 2766 if (prevMain) {
ivand_qmul@121 2767 m_playSource->removeModel(prevMain);
ivand_qmul@121 2768 PlayParameterRepository::getInstance()->removeModel(prevMain);
ivand_qmul@121 2769 }
ivand_qmul@121 2770
ivand_qmul@121 2771 PlayParameterRepository::getInstance()->addModel(newModel);
ivand_qmul@121 2772
ivand_qmul@121 2773 m_document->setMainModel(newModel);
ivand_qmul@121 2774 setupMenus();
ivand_qmul@121 2775
ivand_qmul@121 2776 if (m_sessionFile == "") {
ivand_qmul@121 2777 setWindowTitle(tr("Sound Access: %1")
ivand_qmul@121 2778 .arg(QFileInfo(location).fileName()));
ivand_qmul@121 2779 CommandHistory::getInstance()->clear();
ivand_qmul@121 2780 CommandHistory::getInstance()->documentSaved();
ivand_qmul@121 2781 m_documentModified = false;
ivand_qmul@121 2782 } else {
ivand_qmul@121 2783 setWindowTitle(tr("Sound Access: %1 [%2]")
ivand_qmul@121 2784 .arg(QFileInfo(m_sessionFile).fileName())
ivand_qmul@121 2785 .arg(QFileInfo(location).fileName()));
ivand_qmul@121 2786 if (m_documentModified) {
ivand_qmul@121 2787 m_documentModified = false;
ivand_qmul@121 2788 documentModified(); // so as to restore "(modified)" window title
ivand_qmul@121 2789 }
ivand_qmul@121 2790 }
ivand_qmul@121 2791
ivand_qmul@121 2792 if (realFile) m_audioFile = path;
ivand_qmul@121 2793
ivand_qmul@121 2794 } else { // !setAsMain
ivand_qmul@121 2795
ivand_qmul@121 2796 CommandHistory::getInstance()->startCompoundOperation
ivand_qmul@121 2797 (tr("Import \"%1\"").arg(QFileInfo(location).fileName()), true);
ivand_qmul@121 2798
ivand_qmul@121 2799 m_document->addImportedModel(newModel);
ivand_qmul@121 2800
ivand_qmul@121 2801 AddPaneCommand *command = new AddPaneCommand(this);
ivand_qmul@121 2802 CommandHistory::getInstance()->addCommand(command);
ivand_qmul@121 2803
ivand_qmul@121 2804 Pane *pane = command->getPane();
ivand_qmul@121 2805
ivand_qmul@121 2806 if (!m_timeRulerLayer) {
ivand_qmul@121 2807 m_timeRulerLayer = m_document->createMainModelLayer
ivand_qmul@121 2808 (LayerFactory::TimeRuler);
ivand_qmul@121 2809 }
ivand_qmul@121 2810
ivand_qmul@121 2811 m_document->addLayerToView(pane, m_timeRulerLayer);
ivand_qmul@121 2812
ivand_qmul@121 2813 Layer *newLayer = m_document->createImportedLayer(newModel);
ivand_qmul@121 2814
ivand_qmul@121 2815 if (newLayer) {
ivand_qmul@121 2816 m_document->addLayerToView(pane, newLayer);
ivand_qmul@121 2817 }
ivand_qmul@121 2818
ivand_qmul@121 2819 CommandHistory::getInstance()->endCompoundOperation();
ivand_qmul@121 2820 }
ivand_qmul@121 2821
ivand_qmul@121 2822 updateMenuStates();
ivand_qmul@121 2823 m_recentFiles.addFile(location);
ivand_qmul@121 2824 if (realFile) {
ivand_qmul@121 2825 registerLastOpenedFilePath(FileFinder::AudioFile, path); // for file dialog
ivand_qmul@121 2826 }
ivand_qmul@121 2827 m_openingAudioFile = false;
ivand_qmul@121 2828
ivand_qmul@121 2829 return FileOpenSucceeded;
ivand_qmul@121 2830 }
ivand_qmul@121 2831
ivand_qmul@121 2832 void
ivand_qmul@121 2833 MainWindow::createPlayTarget()
ivand_qmul@121 2834 {
ivand_qmul@121 2835 if (m_playTarget) return;
ivand_qmul@121 2836
ivand_qmul@121 2837 m_playTarget = AudioTargetFactory::createCallbackTarget(m_playSource);
ivand_qmul@121 2838 if (!m_playTarget) {
ivand_qmul@121 2839 QMessageBox::warning
ivand_qmul@121 2840 (this, tr("Couldn't open audio device"),
ivand_qmul@121 2841 tr("Could not open an audio device for playback.\nAudio playback will not be available during this session.\n"),
ivand_qmul@121 2842 QMessageBox::Ok, 0);
ivand_qmul@121 2843 }
ivand_qmul@121 2844 connect(m_fader, SIGNAL(valueChanged(float)),
ivand_qmul@121 2845 m_playTarget, SLOT(setOutputGain(float)));
ivand_qmul@121 2846 }
ivand_qmul@121 2847
ivand_qmul@121 2848 WaveFileModel *
ivand_qmul@121 2849 MainWindow::getMainModel()
ivand_qmul@121 2850 {
ivand_qmul@121 2851 if (!m_document) return 0;
ivand_qmul@121 2852 return m_document->getMainModel();
ivand_qmul@121 2853 }
ivand_qmul@121 2854
ivand_qmul@121 2855 const WaveFileModel *
ivand_qmul@121 2856 MainWindow::getMainModel() const
ivand_qmul@121 2857 {
ivand_qmul@121 2858 if (!m_document) return 0;
ivand_qmul@121 2859 return m_document->getMainModel();
ivand_qmul@121 2860 }
ivand_qmul@121 2861
ivand_qmul@121 2862 void
ivand_qmul@121 2863 MainWindow::newSession()
ivand_qmul@121 2864 {
ivand_qmul@121 2865 if (!checkSaveModified()) return;
ivand_qmul@121 2866
ivand_qmul@121 2867 closeSession();
ivand_qmul@121 2868 createDocument();
ivand_qmul@121 2869 createMultiPaneLayerContainer();
ivand_qmul@121 2870
ivand_qmul@121 2871 Pane *pane = m_paneStack->addPane();
ivand_qmul@121 2872
ivand_qmul@121 2873 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
ivand_qmul@121 2874 this, SLOT(contextHelpChanged(const QString &)));
ivand_qmul@121 2875
ivand_qmul@121 2876 if (!m_timeRulerLayer) {
ivand_qmul@121 2877 m_timeRulerLayer = m_document->createMainModelLayer
ivand_qmul@121 2878 (LayerFactory::TimeRuler);
ivand_qmul@121 2879 }
ivand_qmul@121 2880
ivand_qmul@121 2881 m_document->addLayerToView(pane, m_timeRulerLayer);
ivand_qmul@121 2882
ivand_qmul@121 2883 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
ivand_qmul@121 2884 m_document->addLayerToView(pane, waveform);
ivand_qmul@121 2885
ivand_qmul@121 2886 m_overview->registerView(pane);
ivand_qmul@121 2887
ivand_qmul@121 2888 m_EasaierManager->newSession();
ivand_qmul@121 2889
ivand_qmul@121 2890 CommandHistory::getInstance()->clear();
ivand_qmul@121 2891 CommandHistory::getInstance()->documentSaved();
ivand_qmul@121 2892 documentRestored();
ivand_qmul@121 2893 updateMenuStates();
lbajardsilogic@2 2894
lbajardsilogic@202 2895 setupFiltersMenu();
lbajardsilogic@202 2896
ivand_qmul@121 2897 }
ivand_qmul@121 2898
ivand_qmul@121 2899 void
ivand_qmul@121 2900 MainWindow::createDocument()
ivand_qmul@121 2901 {
ivand_qmul@121 2902 m_document = new Document;
ivand_qmul@121 2903
ivand_qmul@121 2904 connect(m_document, SIGNAL(layerAdded(Layer *)),
ivand_qmul@121 2905 this, SLOT(layerAdded(Layer *)));
ivand_qmul@121 2906 connect(m_document, SIGNAL(layerRemoved(Layer *)),
ivand_qmul@121 2907 this, SLOT(layerRemoved(Layer *)));
ivand_qmul@121 2908 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
ivand_qmul@121 2909 this, SLOT(layerAboutToBeDeleted(Layer *)));
ivand_qmul@121 2910 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
ivand_qmul@121 2911 this, SLOT(layerInAView(Layer *, bool)));
ivand_qmul@121 2912
ivand_qmul@121 2913 connect(m_document, SIGNAL(modelAdded(Model *)),
ivand_qmul@121 2914 this, SLOT(modelAdded(Model *)));
ivand_qmul@121 2915 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
ivand_qmul@121 2916 this, SLOT(mainModelChanged(WaveFileModel *)));
ivand_qmul@121 2917 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
ivand_qmul@121 2918 this, SLOT(modelAboutToBeDeleted(Model *)));
ivand_qmul@121 2919
lbajardsilogic@21 2920 connect(m_document, SIGNAL(audioSourceInfoAdded(AudioSourceInfoModel *)),
ivand_qmul@121 2921 this, SLOT(audioSourceInfoAdded(AudioSourceInfoModel *)));
ivand_qmul@121 2922
ivand_qmul@121 2923 connect(m_document, SIGNAL(modelGenerationFailed(QString)),
ivand_qmul@121 2924 this, SLOT(modelGenerationFailed(QString)));
ivand_qmul@121 2925 connect(m_document, SIGNAL(modelRegenerationFailed(QString, QString)),
ivand_qmul@121 2926 this, SLOT(modelRegenerationFailed(QString, QString)));
ivand_qmul@121 2927
ivand_qmul@121 2928 connect(m_document, SIGNAL(newFilterAdded(Filter *)),
ivand_qmul@121 2929 m_filterPropertyStack, SLOT(filterAdded(Filter *)));
ivand_qmul@121 2930 connect(m_document, SIGNAL(filterRemoved(QString)),
ivand_qmul@121 2931 m_filterPropertyStack, SLOT(filterRemoved(QString)));
ivand_qmul@121 2932
ivand_qmul@121 2933 m_playSource->setRealTimeFilterStack(m_document->getRealTimeFilterStack());
ivand_qmul@121 2934
ivand_qmul@121 2935 }
ivand_qmul@121 2936
ivand_qmul@121 2937 void
ivand_qmul@121 2938 MainWindow::closeSession()
ivand_qmul@121 2939 {
ivand_qmul@121 2940 if (!checkSaveModified()) return;
ivand_qmul@121 2941
ivand_qmul@121 2942 while (m_paneStack->getPaneCount() > 0) {
ivand_qmul@121 2943
ivand_qmul@121 2944 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
ivand_qmul@121 2945
ivand_qmul@121 2946 while (pane->getLayerCount() > 0) {
ivand_qmul@121 2947 m_document->removeLayerFromView
ivand_qmul@121 2948 (pane, pane->getLayer(pane->getLayerCount() - 1));
ivand_qmul@121 2949 }
ivand_qmul@121 2950
ivand_qmul@121 2951 m_overview->unregisterView(pane);
ivand_qmul@121 2952 m_paneStack->deletePane(pane);
ivand_qmul@121 2953 }
ivand_qmul@121 2954
ivand_qmul@121 2955 while (m_paneStack->getHiddenPaneCount() > 0) {
ivand_qmul@121 2956
ivand_qmul@121 2957 Pane *pane = m_paneStack->getHiddenPane
ivand_qmul@121 2958 (m_paneStack->getHiddenPaneCount() - 1);
ivand_qmul@121 2959
ivand_qmul@121 2960 while (pane->getLayerCount() > 0) {
ivand_qmul@121 2961 m_document->removeLayerFromView
ivand_qmul@121 2962 (pane, pane->getLayer(pane->getLayerCount() - 1));
ivand_qmul@121 2963 }
ivand_qmul@121 2964
ivand_qmul@121 2965 m_overview->unregisterView(pane);
ivand_qmul@121 2966 m_paneStack->deletePane(pane);
ivand_qmul@121 2967 }
ivand_qmul@121 2968
lbajardsilogic@21 2969 m_infoWidget->reset();
lbajardsilogic@21 2970 m_searchWidget->reset();
ivand_qmul@121 2971 m_resultsWidget->reset();
lbajardsilogic@143 2972 m_relMediaWidget->reset();
ivand_qmul@121 2973
ivand_qmul@121 2974 delete m_document;
ivand_qmul@121 2975 m_document = 0;
ivand_qmul@121 2976 m_viewManager->clearSelections();
ivand_qmul@121 2977 m_timeRulerLayer = 0; // document owned this
ivand_qmul@121 2978
ivand_qmul@121 2979 m_sessionFile = "";
ivand_qmul@121 2980 setWindowTitle(tr("Sound Access"));
ivand_qmul@121 2981
ivand_qmul@121 2982 CommandHistory::getInstance()->clear();
ivand_qmul@121 2983 CommandHistory::getInstance()->documentSaved();
ivand_qmul@121 2984 documentRestored();
ivand_qmul@121 2985
ivand_qmul@121 2986 m_EasaierManager->closeSession();
ivand_qmul@121 2987
ivand_qmul@121 2988 m_toolBox->removeItem(0);
ivand_qmul@121 2989 m_multiPaneLayerContainer = 0;
ivand_qmul@121 2990
ivand_qmul@121 2991 TempDirectory::getInstance()->cleanup();
ivand_qmul@121 2992 }
ivand_qmul@121 2993
ivand_qmul@121 2994 void
ivand_qmul@121 2995 MainWindow::openSession()
ivand_qmul@121 2996 {
ivand_qmul@121 2997 if (!checkSaveModified()) return;
ivand_qmul@121 2998
ivand_qmul@121 2999 QString orig = m_audioFile;
ivand_qmul@121 3000 if (orig == "") orig = ".";
ivand_qmul@121 3001 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
ivand_qmul@121 3002
ivand_qmul@121 3003 QString path = getOpenFileName(FileFinder::SessionFile);
ivand_qmul@121 3004
ivand_qmul@121 3005 if (path.isEmpty()) return;
ivand_qmul@121 3006
ivand_qmul@121 3007 if (openSessionFile(path) == FileOpenFailed) {
ivand_qmul@121 3008 QMessageBox::critical(this, tr("Failed to open file"),
ivand_qmul@121 3009 tr("Session file \"%1\" could not be opened").arg(path));
ivand_qmul@121 3010 }
ivand_qmul@121 3011 }
ivand_qmul@121 3012
ivand_qmul@121 3013 void
ivand_qmul@121 3014 MainWindow::openSomething()
ivand_qmul@121 3015 {
ivand_qmul@121 3016 QString orig = m_audioFile;
ivand_qmul@121 3017 if (orig == "") orig = ".";
ivand_qmul@121 3018 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
ivand_qmul@121 3019
ivand_qmul@121 3020 bool canImportLayer = (getMainModel() != 0 &&
ivand_qmul@121 3021 m_paneStack != 0 &&
ivand_qmul@121 3022 m_paneStack->getCurrentPane() != 0);
ivand_qmul@121 3023
ivand_qmul@121 3024 QString path = getOpenFileName(FileFinder::AnyFile);
ivand_qmul@121 3025
ivand_qmul@121 3026 if (path.isEmpty()) return;
ivand_qmul@121 3027
ivand_qmul@121 3028 if (path.endsWith(".sv")) {
ivand_qmul@121 3029
ivand_qmul@121 3030 if (!checkSaveModified()) return;
ivand_qmul@121 3031
ivand_qmul@121 3032 if (openSessionFile(path) == FileOpenFailed) {
ivand_qmul@121 3033 QMessageBox::critical(this, tr("Failed to open file"),
ivand_qmul@121 3034 tr("Session file \"%1\" could not be opened").arg(path));
ivand_qmul@121 3035 }
ivand_qmul@121 3036
ivand_qmul@121 3037 } else {
ivand_qmul@121 3038
ivand_qmul@121 3039 if (openAudioFile(path, AskUser) == FileOpenFailed) {
ivand_qmul@121 3040
ivand_qmul@121 3041 if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) {
ivand_qmul@121 3042
ivand_qmul@121 3043 QMessageBox::critical(this, tr("Failed to open file"),
ivand_qmul@121 3044 tr("File \"%1\" could not be opened").arg(path));
ivand_qmul@121 3045 }
ivand_qmul@121 3046 }
ivand_qmul@121 3047 }
ivand_qmul@121 3048 }
ivand_qmul@121 3049
ivand_qmul@121 3050 void
ivand_qmul@121 3051 MainWindow::openLocation()
ivand_qmul@121 3052 {
ivand_qmul@121 3053 QSettings settings;
ivand_qmul@121 3054 settings.beginGroup("MainWindow");
ivand_qmul@121 3055 QString lastLocation = settings.value("lastremote", "").toString();
ivand_qmul@121 3056
ivand_qmul@121 3057 bool ok = false;
ivand_qmul@121 3058 QString text = QInputDialog::getText
ivand_qmul@121 3059 (this, tr("Open Location"),
ivand_qmul@121 3060 tr("Please enter the URL of the location to open:"),
ivand_qmul@121 3061 QLineEdit::Normal, lastLocation, &ok);
ivand_qmul@121 3062
ivand_qmul@121 3063 if (!ok) return;
ivand_qmul@121 3064
ivand_qmul@121 3065 settings.setValue("lastremote", text);
ivand_qmul@121 3066
ivand_qmul@121 3067 if (text.isEmpty()) return;
ivand_qmul@121 3068
ivand_qmul@121 3069 if (openURL(QUrl(text)) == FileOpenFailed) {
ivand_qmul@121 3070 QMessageBox::critical(this, tr("Failed to open location"),
ivand_qmul@121 3071 tr("URL \"%1\" could not be opened").arg(text));
ivand_qmul@121 3072 }
ivand_qmul@121 3073 }
ivand_qmul@121 3074
ivand_qmul@121 3075 void
ivand_qmul@121 3076 MainWindow::openRecentFile()
ivand_qmul@121 3077 {
ivand_qmul@121 3078 QObject *obj = sender();
ivand_qmul@121 3079 QAction *action = dynamic_cast<QAction *>(obj);
ivand_qmul@121 3080
ivand_qmul@121 3081 if (!action) {
ivand_qmul@121 3082 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
ivand_qmul@121 3083 << std::endl;
ivand_qmul@121 3084 return;
ivand_qmul@121 3085 }
ivand_qmul@121 3086
ivand_qmul@121 3087 QString path = action->text();
ivand_qmul@121 3088 if (path == "") return;
ivand_qmul@121 3089
ivand_qmul@121 3090 QUrl url(path);
ivand_qmul@121 3091 if (RemoteFile::canHandleScheme(url)) {
ivand_qmul@121 3092 openURL(url);
ivand_qmul@121 3093 return;
ivand_qmul@121 3094 }
ivand_qmul@121 3095
ivand_qmul@121 3096 if (path.endsWith("sv")) {
ivand_qmul@121 3097
ivand_qmul@121 3098 if (!checkSaveModified()) return;
ivand_qmul@121 3099
ivand_qmul@121 3100 if (openSessionFile(path) == FileOpenFailed) {
ivand_qmul@121 3101 QMessageBox::critical(this, tr("Failed to open file"),
ivand_qmul@121 3102 tr("Session file \"%1\" could not be opened").arg(path));
ivand_qmul@121 3103 }
ivand_qmul@121 3104
ivand_qmul@121 3105 } else {
ivand_qmul@121 3106
ivand_qmul@121 3107 if (openAudioFile(path, AskUser) == FileOpenFailed) {
ivand_qmul@121 3108
ivand_qmul@121 3109 bool canImportLayer = (getMainModel() != 0 &&
ivand_qmul@121 3110 m_paneStack != 0 &&
ivand_qmul@121 3111 m_paneStack->getCurrentPane() != 0);
ivand_qmul@121 3112
ivand_qmul@121 3113 if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) {
ivand_qmul@121 3114
ivand_qmul@121 3115 QMessageBox::critical(this, tr("Failed to open file"),
ivand_qmul@121 3116 tr("File \"%1\" could not be opened").arg(path));
ivand_qmul@121 3117 }
ivand_qmul@121 3118 }
ivand_qmul@121 3119 }
ivand_qmul@121 3120 }
ivand_qmul@121 3121
ivand_qmul@121 3122 MainWindow::FileOpenStatus
ivand_qmul@121 3123 MainWindow::openURL(QUrl url)
ivand_qmul@121 3124 {
ivand_qmul@121 3125 if (url.scheme().toLower() == "file") {
ivand_qmul@121 3126 return openSomeFile(url.toLocalFile());
ivand_qmul@121 3127 } else if (!RemoteFile::canHandleScheme(url)) {
ivand_qmul@121 3128 QMessageBox::critical(this, tr("Unsupported scheme in URL"),
ivand_qmul@121 3129 tr("The URL scheme \"%1\" is not supported")
ivand_qmul@121 3130 .arg(url.scheme()));
ivand_qmul@121 3131 return FileOpenFailed;
ivand_qmul@121 3132 } else {
ivand_qmul@121 3133 RemoteFile rf(url);
ivand_qmul@121 3134 rf.wait();
ivand_qmul@121 3135 if (!rf.isOK()) {
ivand_qmul@121 3136 QMessageBox::critical(this, tr("File download failed"),
ivand_qmul@121 3137 tr("Failed to download URL \"%1\": %2")
ivand_qmul@121 3138 .arg(url.toString()).arg(rf.getErrorString()));
ivand_qmul@121 3139 return FileOpenFailed;
ivand_qmul@121 3140 }
ivand_qmul@121 3141 FileOpenStatus status;
ivand_qmul@121 3142 if ((status = openSomeFile(rf.getLocalFilename(), url.toString())) !=
ivand_qmul@121 3143 FileOpenSucceeded) {
ivand_qmul@121 3144 rf.deleteLocalFile();
ivand_qmul@121 3145 }
ivand_qmul@121 3146 return status;
ivand_qmul@121 3147 }
ivand_qmul@121 3148 }
ivand_qmul@121 3149
ivand_qmul@121 3150 MainWindow::FileOpenStatus
ivand_qmul@121 3151 MainWindow::openSomeFile(QString path, AudioFileOpenMode mode)
ivand_qmul@121 3152 {
ivand_qmul@121 3153 return openSomeFile(path, path, mode);
ivand_qmul@121 3154 }
ivand_qmul@121 3155
ivand_qmul@121 3156 MainWindow::FileOpenStatus
ivand_qmul@121 3157 MainWindow::openSomeFile(QString path, QString location,
ivand_qmul@121 3158 AudioFileOpenMode mode)
ivand_qmul@121 3159 {
ivand_qmul@121 3160 FileOpenStatus status;
ivand_qmul@121 3161
ivand_qmul@121 3162 bool canImportLayer = (getMainModel() != 0 &&
ivand_qmul@121 3163 m_paneStack != 0 &&
ivand_qmul@121 3164 m_paneStack->getCurrentPane() != 0);
ivand_qmul@121 3165
ivand_qmul@121 3166 if ((status = openAudioFile(path, location, mode)) != FileOpenFailed) {
ivand_qmul@121 3167 return status;
ivand_qmul@121 3168 } else if ((status = openSessionFile(path, location)) != FileOpenFailed) {
ivand_qmul@121 3169 return status;
ivand_qmul@121 3170 } else if (!canImportLayer) {
ivand_qmul@121 3171 return FileOpenFailed;
ivand_qmul@121 3172 } else if ((status = openLayerFile(path, location)) != FileOpenFailed) {
ivand_qmul@121 3173 return status;
ivand_qmul@121 3174 } else {
ivand_qmul@121 3175 return FileOpenFailed;
ivand_qmul@121 3176 }
ivand_qmul@121 3177 }
ivand_qmul@121 3178
ivand_qmul@121 3179 MainWindow::FileOpenStatus
ivand_qmul@121 3180 MainWindow::openSessionFile(QString path)
ivand_qmul@121 3181 {
ivand_qmul@121 3182 return openSessionFile(path, path);
ivand_qmul@121 3183 }
ivand_qmul@121 3184
ivand_qmul@121 3185 MainWindow::FileOpenStatus
ivand_qmul@121 3186 MainWindow::openSessionFile(QString path, QString location)
ivand_qmul@121 3187 {
ivand_qmul@121 3188 BZipFileDevice bzFile(path);
ivand_qmul@121 3189 if (!bzFile.open(QIODevice::ReadOnly)) {
ivand_qmul@121 3190 std::cerr << "Failed to open session file \"" << location.toStdString()
ivand_qmul@121 3191 << "\": " << bzFile.errorString().toStdString() << std::endl;
ivand_qmul@121 3192 return FileOpenFailed;
ivand_qmul@121 3193 }
ivand_qmul@121 3194
ivand_qmul@121 3195 if (!checkSaveModified()) return FileOpenCancelled;
ivand_qmul@121 3196
ivand_qmul@121 3197 QString error;
ivand_qmul@121 3198 closeSession();
ivand_qmul@121 3199 createDocument();
ivand_qmul@121 3200 createMultiPaneLayerContainer();
ivand_qmul@121 3201 PaneCallback callback(this);
ivand_qmul@121 3202 m_viewManager->clearSelections();
lbajardsilogic@203 3203 setupFiltersMenu();
lbajardsilogic@203 3204
ivand_qmul@121 3205 SVFileReader reader(m_document, callback, location);
ivand_qmul@121 3206 QXmlInputSource inputSource(&bzFile);
ivand_qmul@121 3207 reader.parse(inputSource);
ivand_qmul@121 3208
ivand_qmul@121 3209 if (!reader.isOK()) {
ivand_qmul@121 3210 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
ivand_qmul@121 3211 }
ivand_qmul@121 3212
ivand_qmul@121 3213 bzFile.close();
ivand_qmul@121 3214
ivand_qmul@121 3215 bool ok = (error == "");
ivand_qmul@121 3216
ivand_qmul@121 3217 bool realFile = (location == path);
ivand_qmul@121 3218
ivand_qmul@121 3219 if (ok) {
ivand_qmul@121 3220
ivand_qmul@121 3221 setWindowTitle(tr("Sound Access: %1")
ivand_qmul@121 3222 .arg(QFileInfo(location).fileName()));
ivand_qmul@121 3223
ivand_qmul@121 3224 if (realFile) m_sessionFile = path;
ivand_qmul@121 3225
ivand_qmul@121 3226 setupMenus();
ivand_qmul@121 3227 CommandHistory::getInstance()->clear();
ivand_qmul@121 3228 CommandHistory::getInstance()->documentSaved();
ivand_qmul@121 3229 m_documentModified = false;
ivand_qmul@121 3230 updateMenuStates();
ivand_qmul@121 3231
ivand_qmul@121 3232 m_recentFiles.addFile(location);
ivand_qmul@121 3233
ivand_qmul@121 3234 if (realFile) {
ivand_qmul@121 3235 registerLastOpenedFilePath(FileFinder::SessionFile, path); // for file dialog
ivand_qmul@121 3236 }
ivand_qmul@121 3237
ivand_qmul@121 3238 } else {
ivand_qmul@121 3239 setWindowTitle(tr("Sound Access"));
ivand_qmul@121 3240 }
lbajardsilogic@52 3241
lbajardsilogic@52 3242 m_EasaierManager->newSession();
lbajardsilogic@52 3243
ivand_qmul@121 3244 return ok ? FileOpenSucceeded : FileOpenFailed;
ivand_qmul@121 3245 }
ivand_qmul@121 3246
ivand_qmul@121 3247 void
ivand_qmul@121 3248 MainWindow::closeEvent(QCloseEvent *e)
ivand_qmul@121 3249 {
benoitrigolleau@140 3250
ivand_qmul@121 3251 // std::cerr << "MainWindow::closeEvent" << std::endl;
ivand_qmul@121 3252
ivand_qmul@121 3253 if (m_openingAudioFile) {
ivand_qmul@121 3254 // std::cerr << "Busy - ignoring close event" << std::endl;
ivand_qmul@121 3255 e->ignore();
ivand_qmul@121 3256 return;
ivand_qmul@121 3257 }
ivand_qmul@121 3258
ivand_qmul@121 3259 if (!m_abandoning && !checkSaveModified()) {
ivand_qmul@121 3260 // std::cerr << "Ignoring close event" << std::endl;
ivand_qmul@121 3261 e->ignore();
ivand_qmul@121 3262 return;
ivand_qmul@121 3263 }
ivand_qmul@121 3264
ivand_qmul@121 3265 QSettings settings;
ivand_qmul@121 3266 settings.beginGroup("MainWindow");
ivand_qmul@121 3267 settings.setValue("size", size());
ivand_qmul@121 3268 settings.setValue("position", pos());
ivand_qmul@121 3269 settings.endGroup();
ivand_qmul@121 3270
ivand_qmul@121 3271 e->accept();
benoitrigolleau@133 3272 exit();
ivand_qmul@121 3273 return;
benoitrigolleau@140 3274
benoitrigolleau@140 3275 //exit();
ivand_qmul@121 3276 }
ivand_qmul@121 3277
ivand_qmul@121 3278 bool
ivand_qmul@121 3279 MainWindow::commitData(bool mayAskUser)
ivand_qmul@121 3280 {
ivand_qmul@121 3281 if (mayAskUser) {
ivand_qmul@121 3282 return checkSaveModified();
ivand_qmul@121 3283 } else {
ivand_qmul@121 3284 if (!m_documentModified) return true;
ivand_qmul@121 3285
ivand_qmul@121 3286 // If we can't check with the user first, then we can't save
ivand_qmul@121 3287 // to the original session file (even if we have it) -- have
ivand_qmul@121 3288 // to use a temporary file
ivand_qmul@121 3289
ivand_qmul@121 3290 QString svDirBase = ".sv1";
ivand_qmul@121 3291 QString svDir = QDir::home().filePath(svDirBase);
ivand_qmul@121 3292
ivand_qmul@121 3293 if (!QFileInfo(svDir).exists()) {
ivand_qmul@121 3294 if (!QDir::home().mkdir(svDirBase)) return false;
ivand_qmul@121 3295 } else {
ivand_qmul@121 3296 if (!QFileInfo(svDir).isDir()) return false;
ivand_qmul@121 3297 }
ivand_qmul@121 3298
ivand_qmul@121 3299 // This name doesn't have to be unguessable
ivand_qmul@121 3300 #ifndef _WIN32
ivand_qmul@121 3301 QString fname = QString("tmp-%1-%2.sv")
ivand_qmul@121 3302 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
ivand_qmul@121 3303 .arg(QProcess().pid());
ivand_qmul@121 3304 #else
ivand_qmul@121 3305 QString fname = QString("tmp-%1.sv")
ivand_qmul@121 3306 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
ivand_qmul@121 3307 #endif
ivand_qmul@121 3308 QString fpath = QDir(svDir).filePath(fname);
ivand_qmul@121 3309 if (saveSessionFile(fpath)) {
ivand_qmul@121 3310 m_recentFiles.addFile(fpath);
ivand_qmul@121 3311 return true;
ivand_qmul@121 3312 } else {
ivand_qmul@121 3313 return false;
ivand_qmul@121 3314 }
ivand_qmul@121 3315 }
ivand_qmul@121 3316 }
ivand_qmul@121 3317
ivand_qmul@121 3318 bool
ivand_qmul@121 3319 MainWindow::checkSaveModified()
ivand_qmul@121 3320 {
ivand_qmul@121 3321 // Called before some destructive operation (e.g. new session,
ivand_qmul@121 3322 // exit program). Return true if we can safely proceed, false to
ivand_qmul@121 3323 // cancel.
ivand_qmul@121 3324
ivand_qmul@121 3325 if (!m_documentModified) return true;
ivand_qmul@121 3326
ivand_qmul@121 3327 int button =
ivand_qmul@121 3328 QMessageBox::warning(this,
ivand_qmul@121 3329 tr("Session modified"),
ivand_qmul@121 3330 tr("The current session has been modified.\nDo you want to save it?"),
ivand_qmul@121 3331 QMessageBox::Yes,
ivand_qmul@121 3332 QMessageBox::No,
ivand_qmul@121 3333 QMessageBox::Cancel);
ivand_qmul@121 3334
ivand_qmul@121 3335 if (button == QMessageBox::Yes) {
ivand_qmul@121 3336 saveEasaierSession();
ivand_qmul@121 3337 if (m_documentModified) { // save failed -- don't proceed!
ivand_qmul@121 3338 return false;
ivand_qmul@121 3339 } else {
ivand_qmul@121 3340 return true; // saved, so it's safe to continue now
ivand_qmul@121 3341 }
ivand_qmul@121 3342 } else if (button == QMessageBox::No) {
ivand_qmul@121 3343 m_documentModified = false; // so we know to abandon it
ivand_qmul@121 3344 return true;
ivand_qmul@121 3345 }
ivand_qmul@121 3346
ivand_qmul@121 3347 // else cancel
ivand_qmul@121 3348 return false;
ivand_qmul@121 3349 }
ivand_qmul@121 3350
ivand_qmul@121 3351 void
ivand_qmul@121 3352 MainWindow::saveSession()
ivand_qmul@121 3353 {
ivand_qmul@121 3354 if (m_sessionFile != "") {
ivand_qmul@121 3355 if (!saveSessionFile(m_sessionFile)) {
ivand_qmul@121 3356 QMessageBox::critical(this, tr("Failed to save file"),
ivand_qmul@121 3357 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
ivand_qmul@121 3358 } else {
ivand_qmul@121 3359 CommandHistory::getInstance()->documentSaved();
ivand_qmul@121 3360 documentRestored();
ivand_qmul@121 3361 }
ivand_qmul@121 3362 } else {
ivand_qmul@121 3363 saveSessionAs();
ivand_qmul@121 3364 }
ivand_qmul@121 3365 }
ivand_qmul@121 3366
ivand_qmul@121 3367 void
ivand_qmul@121 3368 MainWindow::saveSessionAs()
ivand_qmul@121 3369 {
ivand_qmul@121 3370 QString orig = m_audioFile;
ivand_qmul@121 3371 if (orig == "") orig = ".";
ivand_qmul@121 3372 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
ivand_qmul@121 3373
ivand_qmul@121 3374 QString path = getSaveFileName(FileFinder::SessionFile);
ivand_qmul@121 3375
ivand_qmul@121 3376 if (path == "") return;
ivand_qmul@121 3377
ivand_qmul@121 3378 if (!saveSessionFile(path)) {
ivand_qmul@121 3379 QMessageBox::critical(this, tr("Failed to save file"),
ivand_qmul@121 3380 tr("Session file \"%1\" could not be saved.").arg(path));
ivand_qmul@121 3381 } else {
ivand_qmul@121 3382 setWindowTitle(tr("Sound Access: %1")
ivand_qmul@121 3383 .arg(QFileInfo(path).fileName()));
ivand_qmul@121 3384 m_sessionFile = path;
ivand_qmul@121 3385 CommandHistory::getInstance()->documentSaved();
ivand_qmul@121 3386 documentRestored();
ivand_qmul@121 3387 m_recentFiles.addFile(path);
ivand_qmul@121 3388 }
ivand_qmul@121 3389 }
ivand_qmul@121 3390
ivand_qmul@121 3391 bool
ivand_qmul@121 3392 MainWindow::saveSessionFile(QString path)
ivand_qmul@121 3393 {
ivand_qmul@121 3394 BZipFileDevice bzFile(path);
ivand_qmul@121 3395 if (!bzFile.open(QIODevice::WriteOnly)) {
ivand_qmul@121 3396 std::cerr << "Failed to open session file \"" << path.toStdString()
ivand_qmul@121 3397 << "\" for writing: "
ivand_qmul@121 3398 << bzFile.errorString().toStdString() << std::endl;
ivand_qmul@121 3399 return false;
ivand_qmul@121 3400 }
ivand_qmul@121 3401
ivand_qmul@121 3402 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
ivand_qmul@121 3403
ivand_qmul@121 3404 QTextStream out(&bzFile);
ivand_qmul@121 3405 toXml(out);
ivand_qmul@121 3406 out.flush();
ivand_qmul@121 3407
ivand_qmul@121 3408 QApplication::restoreOverrideCursor();
ivand_qmul@121 3409
ivand_qmul@121 3410 if (!bzFile.isOK()) {
ivand_qmul@121 3411 QMessageBox::critical(this, tr("Failed to write file"),
ivand_qmul@121 3412 tr("Failed to write to file \"%1\": %2")
ivand_qmul@121 3413 .arg(path).arg(bzFile.errorString()));
ivand_qmul@121 3414 bzFile.close();
ivand_qmul@121 3415 return false;
ivand_qmul@121 3416 }
ivand_qmul@121 3417
ivand_qmul@121 3418 bzFile.close();
ivand_qmul@121 3419 return true;
ivand_qmul@121 3420 }
ivand_qmul@121 3421
ivand_qmul@121 3422 void
ivand_qmul@121 3423 MainWindow::toXml(QTextStream &out)
ivand_qmul@121 3424 {
ivand_qmul@121 3425 QString indent(" ");
ivand_qmul@121 3426
ivand_qmul@121 3427 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
ivand_qmul@121 3428 out << "<!DOCTYPE sonic-visualiser>\n";
ivand_qmul@121 3429 out << "<sv>\n";
ivand_qmul@121 3430
ivand_qmul@121 3431 m_document->toXml(out, "", "");
ivand_qmul@121 3432
ivand_qmul@121 3433 out << "<display>\n";
ivand_qmul@121 3434
ivand_qmul@121 3435 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
ivand_qmul@121 3436 .arg(width()).arg(height());
ivand_qmul@121 3437
ivand_qmul@121 3438 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
ivand_qmul@121 3439
ivand_qmul@121 3440 Pane *pane = m_paneStack->getPane(i);
ivand_qmul@121 3441
ivand_qmul@121 3442 if (pane) {
ivand_qmul@121 3443 pane->toXml(out, indent);
ivand_qmul@121 3444 }
ivand_qmul@121 3445 }
ivand_qmul@121 3446
ivand_qmul@121 3447 out << "</display>\n";
ivand_qmul@121 3448
ivand_qmul@121 3449 m_viewManager->getSelection().toXml(out);
ivand_qmul@121 3450
ivand_qmul@121 3451 out << "</sv>\n";
ivand_qmul@121 3452 }
ivand_qmul@121 3453
lbajardsilogic@21 3454 void MainWindow::toEasaierXml(QTextStream &out)
lbajardsilogic@21 3455 {
lbajardsilogic@21 3456 QString s;
lbajardsilogic@21 3457 QString indent(" ");
lbajardsilogic@21 3458
lbajardsilogic@21 3459 s += "<?xml version=\"1.0\"?>\n";
lbajardsilogic@21 3460 s += "<easaierSession>\n";
lbajardsilogic@21 3461
lbajardsilogic@21 3462 s += "<display>\n";
lbajardsilogic@21 3463
lbajardsilogic@21 3464 s += QString(" <window width=\"%1\" height=\"%2\"/>\n")
lbajardsilogic@21 3465 .arg(width()).arg(height());
lbajardsilogic@21 3466
lbajardsilogic@21 3467 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
lbajardsilogic@21 3468
lbajardsilogic@21 3469 Pane *pane = m_paneStack->getPane(i);
lbajardsilogic@21 3470
lbajardsilogic@21 3471 if (pane) {
lbajardsilogic@21 3472 s += pane->toEasaierXmlString(indent);
lbajardsilogic@21 3473 }
lbajardsilogic@21 3474 }
lbajardsilogic@21 3475
lbajardsilogic@21 3476 s += "</display>\n";
lbajardsilogic@21 3477
lbajardsilogic@21 3478 s += m_document->toEasaierXmlString(indent, "");
lbajardsilogic@21 3479
lbajardsilogic@21 3480 s += "</easaierSession>\n";
lbajardsilogic@21 3481
lbajardsilogic@21 3482 out << s;
ivand_qmul@121 3483 }
ivand_qmul@121 3484
ivand_qmul@121 3485 Pane *
ivand_qmul@121 3486 MainWindow::addPaneToStack()
ivand_qmul@121 3487 {
ivand_qmul@121 3488 AddPaneCommand *command = new AddPaneCommand(this);
ivand_qmul@121 3489 CommandHistory::getInstance()->addCommand(command);
ivand_qmul@121 3490 return command->getPane();
ivand_qmul@121 3491 }
ivand_qmul@121 3492
ivand_qmul@121 3493 void
ivand_qmul@121 3494 MainWindow::zoomIn()
ivand_qmul@121 3495 {
ivand_qmul@121 3496 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 3497 if (currentPane) currentPane->zoom(true);
ivand_qmul@121 3498 }
ivand_qmul@121 3499
ivand_qmul@121 3500 void
ivand_qmul@121 3501 MainWindow::zoomOut()
ivand_qmul@121 3502 {
ivand_qmul@121 3503 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 3504 if (currentPane) currentPane->zoom(false);
ivand_qmul@121 3505 }
ivand_qmul@121 3506
ivand_qmul@121 3507 void
ivand_qmul@121 3508 MainWindow::zoomToFit()
ivand_qmul@121 3509 {
ivand_qmul@121 3510 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 3511 if (!currentPane) return;
ivand_qmul@121 3512
ivand_qmul@121 3513 Model *model = getMainModel();
ivand_qmul@121 3514 if (!model) return;
ivand_qmul@121 3515
ivand_qmul@121 3516 size_t start = model->getStartFrame();
ivand_qmul@121 3517 size_t end = model->getEndFrame();
ivand_qmul@121 3518 size_t pixels = currentPane->width();
ivand_qmul@121 3519 size_t zoomLevel = (end - start) / pixels;
ivand_qmul@121 3520
ivand_qmul@121 3521 currentPane->setZoomLevel(zoomLevel);
ivand_qmul@121 3522 currentPane->setStartFrame(start);
ivand_qmul@121 3523 }
ivand_qmul@121 3524
ivand_qmul@121 3525 void
ivand_qmul@121 3526 MainWindow::zoomDefault()
ivand_qmul@121 3527 {
ivand_qmul@121 3528 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 3529 if (currentPane) currentPane->setZoomLevel(1024);
ivand_qmul@121 3530 }
ivand_qmul@121 3531
ivand_qmul@121 3532 void
ivand_qmul@121 3533 MainWindow::scrollLeft()
ivand_qmul@121 3534 {
ivand_qmul@121 3535 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 3536 if (currentPane) currentPane->scroll(false, false);
ivand_qmul@121 3537 }
ivand_qmul@121 3538
ivand_qmul@121 3539 void
ivand_qmul@121 3540 MainWindow::jumpLeft()
ivand_qmul@121 3541 {
ivand_qmul@121 3542 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 3543 if (currentPane) currentPane->scroll(false, true);
ivand_qmul@121 3544 }
ivand_qmul@121 3545
ivand_qmul@121 3546 void
ivand_qmul@121 3547 MainWindow::scrollRight()
ivand_qmul@121 3548 {
ivand_qmul@121 3549 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 3550 if (currentPane) currentPane->scroll(true, false);
ivand_qmul@121 3551 }
ivand_qmul@121 3552
ivand_qmul@121 3553 void
ivand_qmul@121 3554 MainWindow::jumpRight()
ivand_qmul@121 3555 {
ivand_qmul@121 3556 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 3557 if (currentPane) currentPane->scroll(true, true);
ivand_qmul@121 3558 }
ivand_qmul@121 3559
ivand_qmul@121 3560 void
ivand_qmul@121 3561 MainWindow::showNoOverlays()
ivand_qmul@121 3562 {
ivand_qmul@121 3563 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
ivand_qmul@121 3564 }
ivand_qmul@121 3565
ivand_qmul@121 3566 void
ivand_qmul@121 3567 MainWindow::showMinimalOverlays()
ivand_qmul@121 3568 {
ivand_qmul@121 3569 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
ivand_qmul@121 3570 }
ivand_qmul@121 3571
ivand_qmul@121 3572 void
ivand_qmul@121 3573 MainWindow::showStandardOverlays()
ivand_qmul@121 3574 {
ivand_qmul@121 3575 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
ivand_qmul@121 3576 }
ivand_qmul@121 3577
ivand_qmul@121 3578 void
ivand_qmul@121 3579 MainWindow::showAllOverlays()
ivand_qmul@121 3580 {
ivand_qmul@121 3581 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
ivand_qmul@121 3582 }
ivand_qmul@121 3583
ivand_qmul@121 3584 void
ivand_qmul@121 3585 MainWindow::toggleZoomWheels()
ivand_qmul@121 3586 {
ivand_qmul@121 3587 if (m_viewManager->getZoomWheelsEnabled()) {
ivand_qmul@121 3588 m_viewManager->setZoomWheelsEnabled(false);
ivand_qmul@121 3589 } else {
ivand_qmul@121 3590 m_viewManager->setZoomWheelsEnabled(true);
ivand_qmul@121 3591 }
ivand_qmul@121 3592 }
ivand_qmul@121 3593
ivand_qmul@121 3594 void
ivand_qmul@121 3595 MainWindow::toggleStatusBar()
ivand_qmul@121 3596 {
ivand_qmul@121 3597 QSettings settings;
ivand_qmul@121 3598 settings.beginGroup("MainWindow");
ivand_qmul@121 3599 bool sb = settings.value("showstatusbar", true).toBool();
ivand_qmul@121 3600
ivand_qmul@121 3601 if (sb) {
ivand_qmul@121 3602 statusBar()->hide();
ivand_qmul@121 3603 } else {
ivand_qmul@121 3604 statusBar()->show();
ivand_qmul@121 3605 }
ivand_qmul@121 3606
ivand_qmul@121 3607 settings.setValue("showstatusbar", !sb);
ivand_qmul@121 3608
ivand_qmul@121 3609 settings.endGroup();
ivand_qmul@121 3610 }
ivand_qmul@121 3611
lbajardsilogic@204 3612 /*void
ivand_qmul@121 3613 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
ivand_qmul@121 3614 {
lbajardsilogic@204 3615
lbajardsilogic@204 3616 }*/
ivand_qmul@121 3617
ivand_qmul@121 3618 void
ivand_qmul@121 3619 MainWindow::play()
ivand_qmul@121 3620 {
ivand_qmul@121 3621 if (m_playSource->isPlaying()) {
ivand_qmul@121 3622 stop();
ivand_qmul@121 3623 } else {
ivand_qmul@121 3624 playbackFrameChanged(m_viewManager->getPlaybackFrame());
ivand_qmul@121 3625 m_playSource->play(m_viewManager->getPlaybackFrame());
ivand_qmul@121 3626 }
ivand_qmul@129 3627 m_playSource->hardwareBufferedTime=0;
ivand_qmul@129 3628 m_playSource->lastAudioTime=0;
ivand_qmul@121 3629 }
lbajardsilogic@191 3630 // Ivan Damnjanovic 16/10/2007 functions to access data needed for video player
lbajardsilogic@191 3631 unsigned long
lbajardsilogic@191 3632 MainWindow::Get_CurAudioTime()
lbajardsilogic@191 3633 {
lbajardsilogic@192 3634 unsigned long pos = 0;
lbajardsilogic@191 3635 unsigned long newAudioTime=m_viewManager->getPlaybackFrame()/(getMainModel()->getSampleRate()/1000);
lbajardsilogic@191 3636 if(!(m_playSource->lastAudioTime==newAudioTime))
lbajardsilogic@191 3637 {
lbajardsilogic@191 3638 m_playSource->lastAudioTime=newAudioTime;
lbajardsilogic@192 3639 long long cntClick = 0;
lbajardsilogic@192 3640 #ifdef _WIN32
ivand_qmul@129 3641 QueryPerformanceCounter((LARGE_INTEGER *)(&cntClick));
lbajardsilogic@192 3642 #endif
lbajardsilogic@191 3643 m_playSource->hardwareBufferedTime=cntClick;
lbajardsilogic@191 3644 pos=0;
lbajardsilogic@191 3645 }
lbajardsilogic@191 3646 else
lbajardsilogic@191 3647 {
lbajardsilogic@192 3648 long long timeTemp = 0;
lbajardsilogic@192 3649 #ifdef _WIN32
lbajardsilogic@192 3650 QueryPerformanceCounter((LARGE_INTEGER *)(&timeTemp));
lbajardsilogic@193 3651 pos=(timeTemp-m_playSource->hardwareBufferedTime)/(countFreq);
lbajardsilogic@192 3652 #endif
lbajardsilogic@192 3653 pos*=getPlaySpeedVal();
lbajardsilogic@191 3654 }
lbajardsilogic@191 3655 return (newAudioTime+pos);
lbajardsilogic@191 3656 }
lbajardsilogic@192 3657
lbajardsilogic@191 3658 unsigned long long
lbajardsilogic@191 3659 MainWindow::Get_HardwareBufferTime()
lbajardsilogic@191 3660 {
lbajardsilogic@191 3661 return (m_playSource->hardwareBufferedTime);
lbajardsilogic@191 3662 }
ivand_qmul@121 3663 bool MainWindow::isAudioPlaying()
ivand_qmul@121 3664 {
ivand_qmul@121 3665 return (m_playSource->isPlaying());
ivand_qmul@121 3666 }
ivand_qmul@121 3667 //
ivand_qmul@121 3668 void
ivand_qmul@121 3669 MainWindow::ffwd()
ivand_qmul@121 3670 {
ivand_qmul@121 3671 if (!getMainModel()) return;
ivand_qmul@121 3672
ivand_qmul@121 3673 int frame = m_viewManager->getPlaybackFrame();
ivand_qmul@121 3674 ++frame;
ivand_qmul@121 3675
ivand_qmul@121 3676 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 3677 if (!pane) return;
ivand_qmul@121 3678
ivand_qmul@121 3679 Layer *layer = pane->getSelectedLayer();
ivand_qmul@121 3680
ivand_qmul@121 3681 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
ivand_qmul@121 3682 !dynamic_cast<TimeValueLayer *>(layer)) return;
ivand_qmul@121 3683
ivand_qmul@121 3684 size_t resolution = 0;
ivand_qmul@121 3685 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapRight)) {
ivand_qmul@121 3686 frame = getMainModel()->getEndFrame();
ivand_qmul@121 3687 }
ivand_qmul@121 3688
ivand_qmul@121 3689 m_viewManager->setPlaybackFrame(frame);
ivand_qmul@121 3690 }
ivand_qmul@121 3691
ivand_qmul@121 3692 void
ivand_qmul@121 3693 MainWindow::ffwdEnd()
ivand_qmul@121 3694 {
ivand_qmul@121 3695 if (!getMainModel()) return;
ivand_qmul@121 3696 m_viewManager->setPlaybackFrame(getMainModel()->getEndFrame());
ivand_qmul@121 3697 }
ivand_qmul@121 3698
ivand_qmul@121 3699 void
ivand_qmul@121 3700 MainWindow::rewind()
ivand_qmul@121 3701 {
ivand_qmul@121 3702 if (!getMainModel()) return;
ivand_qmul@121 3703
ivand_qmul@121 3704 int frame = m_viewManager->getPlaybackFrame();
ivand_qmul@121 3705 if (frame > 0) --frame;
ivand_qmul@121 3706
ivand_qmul@121 3707 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 3708 if (!pane) return;
ivand_qmul@121 3709
ivand_qmul@121 3710 Layer *layer = pane->getSelectedLayer();
ivand_qmul@121 3711
ivand_qmul@121 3712 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
ivand_qmul@121 3713 !dynamic_cast<TimeValueLayer *>(layer)) return;
ivand_qmul@121 3714
ivand_qmul@121 3715 size_t resolution = 0;
ivand_qmul@121 3716 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapLeft)) {
ivand_qmul@121 3717 frame = getMainModel()->getEndFrame();
ivand_qmul@121 3718 }
ivand_qmul@121 3719
ivand_qmul@121 3720 m_viewManager->setPlaybackFrame(frame);
ivand_qmul@121 3721 }
ivand_qmul@121 3722
ivand_qmul@121 3723 void
ivand_qmul@121 3724 MainWindow::rewindStart()
ivand_qmul@121 3725 {
ivand_qmul@121 3726 if (!getMainModel()) return;
ivand_qmul@121 3727 m_viewManager->setPlaybackFrame(getMainModel()->getStartFrame());
ivand_qmul@121 3728 }
ivand_qmul@121 3729
ivand_qmul@121 3730 void
ivand_qmul@121 3731 MainWindow::stop()
ivand_qmul@121 3732 {
ivand_qmul@121 3733 m_playSource->stop();
ivand_qmul@121 3734
ivand_qmul@121 3735 if (m_paneStack && m_paneStack->getCurrentPane()) {
ivand_qmul@121 3736 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
ivand_qmul@121 3737 } else {
ivand_qmul@121 3738 m_myStatusMessage = "";
ivand_qmul@121 3739 statusBar()->showMessage("");
ivand_qmul@121 3740 }
ivand_qmul@121 3741 }
ivand_qmul@121 3742
ivand_qmul@121 3743 void
ivand_qmul@121 3744 MainWindow::addPane()
ivand_qmul@121 3745 {
ivand_qmul@121 3746 QObject *s = sender();
ivand_qmul@121 3747 QAction *action = dynamic_cast<QAction *>(s);
ivand_qmul@121 3748
ivand_qmul@121 3749 if (!action) {
ivand_qmul@121 3750 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
ivand_qmul@121 3751 << std::endl;
ivand_qmul@121 3752 return;
ivand_qmul@121 3753 }
ivand_qmul@121 3754
ivand_qmul@121 3755 PaneActionMap::iterator i = m_paneActions.find(action);
ivand_qmul@121 3756
ivand_qmul@121 3757 if (i == m_paneActions.end()) {
ivand_qmul@121 3758 std::cerr << "WARNING: MainWindow::addPane: unknown action "
ivand_qmul@121 3759 << action->objectName().toStdString() << std::endl;
ivand_qmul@121 3760 return;
ivand_qmul@121 3761 }
ivand_qmul@121 3762
ivand_qmul@121 3763 addPane(i->second, action->text());
ivand_qmul@121 3764 }
ivand_qmul@121 3765
ivand_qmul@121 3766 void
ivand_qmul@121 3767 MainWindow::addPane(const PaneConfiguration &configuration, QString text)
ivand_qmul@121 3768 {
ivand_qmul@121 3769 CommandHistory::getInstance()->startCompoundOperation(text, true);
ivand_qmul@121 3770
ivand_qmul@121 3771 AddPaneCommand *command = new AddPaneCommand(this);
ivand_qmul@121 3772 CommandHistory::getInstance()->addCommand(command);
ivand_qmul@121 3773
ivand_qmul@121 3774 Pane *pane = command->getPane();
ivand_qmul@121 3775
ivand_qmul@121 3776 if (configuration.layer == LayerFactory::Spectrum) {
ivand_qmul@121 3777 pane->setPlaybackFollow(PlaybackScrollContinuous);
ivand_qmul@121 3778 pane->setFollowGlobalZoom(false);
ivand_qmul@121 3779 pane->setZoomLevel(512);
ivand_qmul@121 3780 }
ivand_qmul@121 3781
ivand_qmul@121 3782 if (configuration.layer != LayerFactory::TimeRuler &&
ivand_qmul@121 3783 configuration.layer != LayerFactory::Spectrum) {
ivand_qmul@121 3784
ivand_qmul@121 3785 if (!m_timeRulerLayer) {
ivand_qmul@121 3786 // std::cerr << "no time ruler layer, creating one" << std::endl;
ivand_qmul@121 3787 m_timeRulerLayer = m_document->createMainModelLayer
ivand_qmul@121 3788 (LayerFactory::TimeRuler);
ivand_qmul@121 3789 }
ivand_qmul@121 3790
ivand_qmul@121 3791 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
ivand_qmul@121 3792
ivand_qmul@121 3793 m_document->addLayerToView(pane, m_timeRulerLayer);
ivand_qmul@121 3794 }
ivand_qmul@121 3795
ivand_qmul@121 3796 Layer *newLayer = m_document->createLayer(configuration.layer);
ivand_qmul@121 3797
ivand_qmul@121 3798 Model *suggestedModel = configuration.sourceModel;
ivand_qmul@121 3799 Model *model = 0;
ivand_qmul@121 3800
ivand_qmul@121 3801 if (suggestedModel) {
ivand_qmul@121 3802
ivand_qmul@121 3803 // check its validity
ivand_qmul@121 3804 std::vector<Model *> inputModels = m_document->getTransformInputModels();
ivand_qmul@121 3805 for (size_t j = 0; j < inputModels.size(); ++j) {
ivand_qmul@121 3806 if (inputModels[j] == suggestedModel) {
ivand_qmul@121 3807 model = suggestedModel;
ivand_qmul@121 3808 break;
ivand_qmul@121 3809 }
ivand_qmul@121 3810 }
ivand_qmul@121 3811
ivand_qmul@121 3812 if (!model) {
ivand_qmul@121 3813 std::cerr << "WARNING: Model " << (void *)suggestedModel
ivand_qmul@121 3814 << " appears in pane action map, but is not reported "
ivand_qmul@121 3815 << "by document as a valid transform source" << std::endl;
ivand_qmul@121 3816 }
ivand_qmul@121 3817 }
ivand_qmul@121 3818
ivand_qmul@121 3819 if (!model) model = m_document->getMainModel();
ivand_qmul@121 3820
ivand_qmul@121 3821 m_document->setModel(newLayer, model);
ivand_qmul@121 3822
ivand_qmul@121 3823 m_document->setChannel(newLayer, configuration.channel);
ivand_qmul@121 3824 m_document->addLayerToView(pane, newLayer);
ivand_qmul@121 3825
ivand_qmul@121 3826 m_paneStack->setCurrentPane(pane);
ivand_qmul@121 3827 m_paneStack->setCurrentLayer(pane, newLayer);
ivand_qmul@121 3828
ivand_qmul@121 3829 // std::cerr << "MainWindow::addPane: global centre frame is "
ivand_qmul@121 3830 // << m_viewManager->getGlobalCentreFrame() << std::endl;
ivand_qmul@121 3831 // pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
ivand_qmul@121 3832
ivand_qmul@121 3833 CommandHistory::getInstance()->endCompoundOperation();
ivand_qmul@121 3834
ivand_qmul@121 3835 updateMenuStates();
ivand_qmul@121 3836 }
ivand_qmul@121 3837
ivand_qmul@121 3838 MainWindow::AddPaneCommand::AddPaneCommand(MainWindow *mw) :
ivand_qmul@121 3839 m_mw(mw),
ivand_qmul@121 3840 m_pane(0),
ivand_qmul@121 3841 m_prevCurrentPane(0),
ivand_qmul@121 3842 m_added(false)
ivand_qmul@121 3843 {
ivand_qmul@121 3844 }
ivand_qmul@121 3845
ivand_qmul@121 3846 MainWindow::AddPaneCommand::~AddPaneCommand()
ivand_qmul@121 3847 {
ivand_qmul@121 3848 if (m_pane && !m_added) {
ivand_qmul@121 3849 m_mw->m_paneStack->deletePane(m_pane);
ivand_qmul@121 3850 }
ivand_qmul@121 3851 }
ivand_qmul@121 3852
ivand_qmul@121 3853 QString
ivand_qmul@121 3854 MainWindow::AddPaneCommand::getName() const
ivand_qmul@121 3855 {
ivand_qmul@121 3856 return tr("Add Pane");
ivand_qmul@121 3857 }
ivand_qmul@121 3858
ivand_qmul@121 3859 void
ivand_qmul@121 3860 MainWindow::AddPaneCommand::execute()
ivand_qmul@121 3861 {
ivand_qmul@121 3862 if (!m_pane) {
ivand_qmul@121 3863 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
ivand_qmul@121 3864 m_pane = m_mw->m_paneStack->addPane();
ivand_qmul@121 3865
ivand_qmul@121 3866 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
ivand_qmul@121 3867 m_mw, SLOT(contextHelpChanged(const QString &)));
ivand_qmul@121 3868 } else {
ivand_qmul@121 3869 m_mw->m_paneStack->showPane(m_pane);
ivand_qmul@121 3870 }
ivand_qmul@121 3871
ivand_qmul@121 3872 m_mw->m_paneStack->setCurrentPane(m_pane);
ivand_qmul@121 3873 m_mw->m_overview->registerView(m_pane);
ivand_qmul@121 3874 m_added = true;
ivand_qmul@121 3875 }
ivand_qmul@121 3876
ivand_qmul@121 3877 void
ivand_qmul@121 3878 MainWindow::AddPaneCommand::unexecute()
ivand_qmul@121 3879 {
ivand_qmul@121 3880 m_mw->m_paneStack->hidePane(m_pane);
ivand_qmul@121 3881 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
ivand_qmul@121 3882 m_mw->m_overview->unregisterView(m_pane);
ivand_qmul@121 3883 m_added = false;
ivand_qmul@121 3884 }
ivand_qmul@121 3885
ivand_qmul@121 3886 MainWindow::RemovePaneCommand::RemovePaneCommand(MainWindow *mw, Pane *pane) :
ivand_qmul@121 3887 m_mw(mw),
ivand_qmul@121 3888 m_pane(pane),
ivand_qmul@121 3889 m_added(true)
ivand_qmul@121 3890 {
ivand_qmul@121 3891 }
ivand_qmul@121 3892
ivand_qmul@121 3893 MainWindow::RemovePaneCommand::~RemovePaneCommand()
ivand_qmul@121 3894 {
ivand_qmul@121 3895 if (m_pane && !m_added) {
ivand_qmul@121 3896 m_mw->m_paneStack->deletePane(m_pane);
ivand_qmul@121 3897 }
ivand_qmul@121 3898 }
ivand_qmul@121 3899
ivand_qmul@121 3900 QString
ivand_qmul@121 3901 MainWindow::RemovePaneCommand::getName() const
ivand_qmul@121 3902 {
ivand_qmul@121 3903 return tr("Remove Pane");
ivand_qmul@121 3904 }
ivand_qmul@121 3905
ivand_qmul@121 3906 void
ivand_qmul@121 3907 MainWindow::RemovePaneCommand::execute()
ivand_qmul@121 3908 {
ivand_qmul@121 3909 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
ivand_qmul@121 3910 m_mw->m_paneStack->hidePane(m_pane);
ivand_qmul@121 3911 m_mw->m_overview->unregisterView(m_pane);
ivand_qmul@121 3912 m_added = false;
ivand_qmul@121 3913 }
ivand_qmul@121 3914
ivand_qmul@121 3915 void
ivand_qmul@121 3916 MainWindow::RemovePaneCommand::unexecute()
ivand_qmul@121 3917 {
ivand_qmul@121 3918 m_mw->m_paneStack->showPane(m_pane);
ivand_qmul@121 3919 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
ivand_qmul@121 3920 m_mw->m_overview->registerView(m_pane);
ivand_qmul@121 3921 m_added = true;
ivand_qmul@121 3922 }
ivand_qmul@121 3923
ivand_qmul@121 3924 void
ivand_qmul@121 3925 MainWindow::addLayer()
ivand_qmul@121 3926 {
ivand_qmul@121 3927 QObject *s = sender();
ivand_qmul@121 3928 QAction *action = dynamic_cast<QAction *>(s);
ivand_qmul@121 3929
ivand_qmul@121 3930 if (!action) {
ivand_qmul@121 3931 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
ivand_qmul@121 3932 << std::endl;
ivand_qmul@121 3933 return;
ivand_qmul@121 3934 }
ivand_qmul@121 3935
ivand_qmul@121 3936 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 3937
ivand_qmul@121 3938 if (!pane) {
ivand_qmul@121 3939 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
ivand_qmul@121 3940 return;
ivand_qmul@121 3941 }
ivand_qmul@121 3942
ivand_qmul@121 3943 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
ivand_qmul@121 3944
ivand_qmul@121 3945 if (ei != m_existingLayerActions.end()) {
ivand_qmul@121 3946 Layer *newLayer = ei->second;
ivand_qmul@121 3947 m_document->addLayerToView(pane, newLayer);
ivand_qmul@121 3948 m_paneStack->setCurrentLayer(pane, newLayer);
ivand_qmul@121 3949 return;
ivand_qmul@121 3950 }
ivand_qmul@121 3951
ivand_qmul@121 3952 ei = m_sliceActions.find(action);
ivand_qmul@121 3953
ivand_qmul@121 3954 if (ei != m_sliceActions.end()) {
ivand_qmul@121 3955 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
ivand_qmul@121 3956 // document->setModel(newLayer, ei->second->getModel());
ivand_qmul@121 3957 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
ivand_qmul@121 3958 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
ivand_qmul@121 3959 if (source && dest) {
ivand_qmul@121 3960 dest->setSliceableModel(source->getSliceableModel());
ivand_qmul@121 3961 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
ivand_qmul@121 3962 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
ivand_qmul@121 3963 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
ivand_qmul@121 3964 dest, SLOT(modelAboutToBeDeleted(Model *)));
ivand_qmul@121 3965 }
ivand_qmul@121 3966 m_document->addLayerToView(pane, newLayer);
ivand_qmul@121 3967 m_paneStack->setCurrentLayer(pane, newLayer);
ivand_qmul@121 3968 return;
ivand_qmul@121 3969 }
ivand_qmul@121 3970
ivand_qmul@121 3971 TransformActionMap::iterator i = m_transformActions.find(action);
ivand_qmul@121 3972
ivand_qmul@121 3973 if (i == m_transformActions.end()) {
ivand_qmul@121 3974
ivand_qmul@121 3975 LayerActionMap::iterator i = m_layerActions.find(action);
ivand_qmul@121 3976
ivand_qmul@121 3977 if (i == m_layerActions.end()) {
ivand_qmul@121 3978 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
ivand_qmul@121 3979 << action->objectName().toStdString() << std::endl;
ivand_qmul@121 3980 return;
ivand_qmul@121 3981 }
ivand_qmul@121 3982
ivand_qmul@121 3983 LayerFactory::LayerType type = i->second;
ivand_qmul@121 3984
ivand_qmul@121 3985 LayerFactory::LayerTypeSet emptyTypes =
ivand_qmul@121 3986 LayerFactory::getInstance()->getValidEmptyLayerTypes();
ivand_qmul@121 3987
ivand_qmul@121 3988 Layer *newLayer;
ivand_qmul@121 3989
ivand_qmul@121 3990 if (emptyTypes.find(type) != emptyTypes.end()) {
ivand_qmul@121 3991
ivand_qmul@121 3992 newLayer = m_document->createEmptyLayer(type);
ivand_qmul@121 3993 m_toolActions[ViewManager::DrawMode]->trigger();
ivand_qmul@121 3994
ivand_qmul@121 3995 } else {
ivand_qmul@121 3996
ivand_qmul@121 3997 newLayer = m_document->createMainModelLayer(type);
ivand_qmul@121 3998 }
ivand_qmul@121 3999
ivand_qmul@121 4000 m_document->addLayerToView(pane, newLayer);
ivand_qmul@121 4001 m_paneStack->setCurrentLayer(pane, newLayer);
ivand_qmul@121 4002
ivand_qmul@121 4003 return;
ivand_qmul@121 4004 }
ivand_qmul@121 4005
ivand_qmul@121 4006 TransformId transform = i->second;
ivand_qmul@121 4007 TransformFactory *factory = TransformFactory::getInstance();
ivand_qmul@121 4008
ivand_qmul@121 4009 QString configurationXml;
ivand_qmul@121 4010
ivand_qmul@121 4011 int channel = -1;
ivand_qmul@121 4012 // pick up the default channel from any existing layers on the same pane
ivand_qmul@121 4013 for (int j = 0; j < pane->getLayerCount(); ++j) {
ivand_qmul@121 4014 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
ivand_qmul@121 4015 if (c != -1) {
ivand_qmul@121 4016 channel = c;
ivand_qmul@121 4017 break;
ivand_qmul@121 4018 }
ivand_qmul@121 4019 }
ivand_qmul@121 4020
ivand_qmul@121 4021 // We always ask for configuration, even if the plugin isn't
ivand_qmul@121 4022 // supposed to be configurable, because we need to let the user
ivand_qmul@121 4023 // change the execution context (block size etc).
ivand_qmul@121 4024
ivand_qmul@121 4025 PluginTransform::ExecutionContext context(channel);
ivand_qmul@121 4026
ivand_qmul@121 4027 std::vector<Model *> candidateInputModels =
ivand_qmul@121 4028 m_document->getTransformInputModels();
ivand_qmul@121 4029
ivand_qmul@121 4030 Model *inputModel = factory->getConfigurationForTransform(transform,
ivand_qmul@121 4031 candidateInputModels,
ivand_qmul@121 4032 context,
ivand_qmul@121 4033 configurationXml,
ivand_qmul@121 4034 m_playSource);
ivand_qmul@121 4035 if (!inputModel) return;
ivand_qmul@121 4036
ivand_qmul@121 4037 // std::cerr << "MainWindow::addLayer: Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << "\"" << std::endl;
ivand_qmul@121 4038
ivand_qmul@121 4039 Layer *newLayer = m_document->createDerivedLayer(transform,
ivand_qmul@121 4040 inputModel,
ivand_qmul@121 4041 context,
ivand_qmul@121 4042 configurationXml);
ivand_qmul@121 4043
ivand_qmul@121 4044 if (newLayer) {
ivand_qmul@121 4045 m_document->addLayerToView(pane, newLayer);
ivand_qmul@121 4046 m_document->setChannel(newLayer, context.channel);
ivand_qmul@121 4047 m_recentTransforms.add(transform);
ivand_qmul@121 4048 m_paneStack->setCurrentLayer(pane, newLayer);
ivand_qmul@121 4049 }
ivand_qmul@121 4050
ivand_qmul@121 4051 updateMenuStates();
ivand_qmul@121 4052 }
ivand_qmul@121 4053
ivand_qmul@121 4054 void
ivand_qmul@121 4055 MainWindow::deleteCurrentPane()
ivand_qmul@121 4056 {
ivand_qmul@121 4057 CommandHistory::getInstance()->startCompoundOperation
ivand_qmul@121 4058 (tr("Delete Pane"), true);
ivand_qmul@121 4059
ivand_qmul@121 4060 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 4061 if (pane) {
ivand_qmul@121 4062 while (pane->getLayerCount() > 0) {
ivand_qmul@121 4063 Layer *layer = pane->getLayer(0);
ivand_qmul@121 4064 if (layer) {
ivand_qmul@121 4065 m_document->removeLayerFromView(pane, layer);
ivand_qmul@121 4066 } else {
ivand_qmul@121 4067 break;
ivand_qmul@121 4068 }
ivand_qmul@121 4069 }
ivand_qmul@121 4070
ivand_qmul@121 4071 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
ivand_qmul@121 4072 CommandHistory::getInstance()->addCommand(command);
ivand_qmul@121 4073 }
ivand_qmul@121 4074
ivand_qmul@121 4075 CommandHistory::getInstance()->endCompoundOperation();
ivand_qmul@121 4076
ivand_qmul@121 4077 updateMenuStates();
ivand_qmul@121 4078 }
ivand_qmul@121 4079
ivand_qmul@121 4080 void
ivand_qmul@121 4081 MainWindow::deleteCurrentLayer()
ivand_qmul@121 4082 {
ivand_qmul@121 4083 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 4084 if (pane) {
ivand_qmul@121 4085 Layer *layer = pane->getSelectedLayer();
ivand_qmul@121 4086 if (layer) {
ivand_qmul@121 4087 m_document->removeLayerFromView(pane, layer);
ivand_qmul@121 4088 }
ivand_qmul@121 4089 }
ivand_qmul@121 4090 updateMenuStates();
ivand_qmul@121 4091 }
ivand_qmul@121 4092
ivand_qmul@121 4093 void
ivand_qmul@121 4094 MainWindow::renameCurrentLayer()
ivand_qmul@121 4095 {
ivand_qmul@121 4096 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 4097 if (pane) {
ivand_qmul@121 4098 Layer *layer = pane->getSelectedLayer();
ivand_qmul@121 4099 if (layer) {
ivand_qmul@121 4100 bool ok = false;
ivand_qmul@121 4101 QString newName = QInputDialog::getText
ivand_qmul@121 4102 (this, tr("Rename Layer"),
ivand_qmul@121 4103 tr("New name for this layer:"),
ivand_qmul@121 4104 QLineEdit::Normal, layer->objectName(), &ok);
ivand_qmul@121 4105 if (ok) {
ivand_qmul@121 4106 layer->setObjectName(newName);
ivand_qmul@121 4107 setupExistingLayersMenus();
ivand_qmul@121 4108 }
ivand_qmul@121 4109 }
ivand_qmul@121 4110 }
ivand_qmul@121 4111 }
ivand_qmul@121 4112
ivand_qmul@121 4113 void
lbajardsilogic@127 4114 MainWindow::playSpeedChanged(float value)
ivand_qmul@121 4115 {
lbajardsilogic@127 4116 /*
lbajardsilogic@127 4117 The value of the speed factor have been changed
lbajardsilogic@127 4118 in the TimeStretchFilter class.
lbajardsilogic@127 4119 The new hopfactor is given by value
lbajardsilogic@127 4120 */
lbajardsilogic@135 4121 m_playSpeedVal = value;
lbajardsilogic@127 4122
lbajardsilogic@137 4123 //std::cerr << "m_playSpeedVal : " << m_playSpeedVal << std::endl;
ivand_qmul@121 4124 }
ivand_qmul@121 4125
lbajardsilogic@127 4126 /*void
ivand_qmul@121 4127 MainWindow::playSharpenToggled()
ivand_qmul@121 4128 {
ivand_qmul@121 4129 QSettings settings;
ivand_qmul@121 4130 settings.beginGroup("MainWindow");
ivand_qmul@121 4131 settings.setValue("playsharpen", m_playSharpen->isChecked());
ivand_qmul@121 4132 settings.endGroup();
ivand_qmul@121 4133
ivand_qmul@121 4134 playSpeedChanged(m_playSpeed->value());
ivand_qmul@121 4135 }
ivand_qmul@121 4136
ivand_qmul@121 4137 void
ivand_qmul@121 4138 MainWindow::playMonoToggled()
ivand_qmul@121 4139 {
ivand_qmul@121 4140 QSettings settings;
ivand_qmul@121 4141 settings.beginGroup("MainWindow");
ivand_qmul@121 4142 settings.setValue("playmono", m_playMono->isChecked());
ivand_qmul@121 4143 settings.endGroup();
ivand_qmul@121 4144
ivand_qmul@121 4145 playSpeedChanged(m_playSpeed->value());
ivand_qmul@121 4146 }
lbajardsilogic@127 4147 */
ivand_qmul@121 4148 void
ivand_qmul@121 4149 MainWindow::playbackFrameChanged(unsigned long frame)
ivand_qmul@121 4150 {
ivand_qmul@121 4151 if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
ivand_qmul@121 4152
ivand_qmul@121 4153 RealTime now = RealTime::frame2RealTime
ivand_qmul@121 4154 (frame, getMainModel()->getSampleRate());
ivand_qmul@121 4155
ivand_qmul@121 4156 if (now.sec == m_lastPlayStatusSec) return;
ivand_qmul@121 4157
ivand_qmul@121 4158 RealTime then = RealTime::frame2RealTime
ivand_qmul@121 4159 (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
ivand_qmul@121 4160
ivand_qmul@121 4161 QString nowStr;
ivand_qmul@121 4162 QString thenStr;
ivand_qmul@121 4163 QString remainingStr;
ivand_qmul@121 4164
ivand_qmul@121 4165 if (then.sec > 10) {
ivand_qmul@121 4166 nowStr = now.toSecText().c_str();
ivand_qmul@121 4167 thenStr = then.toSecText().c_str();
ivand_qmul@121 4168 remainingStr = (then - now).toSecText().c_str();
ivand_qmul@121 4169 m_lastPlayStatusSec = now.sec;
ivand_qmul@121 4170 } else {
ivand_qmul@121 4171 nowStr = now.toText(true).c_str();
ivand_qmul@121 4172 thenStr = then.toText(true).c_str();
ivand_qmul@121 4173 remainingStr = (then - now).toText(true).c_str();
ivand_qmul@121 4174 }
ivand_qmul@121 4175
ivand_qmul@121 4176 m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
ivand_qmul@121 4177 .arg(nowStr).arg(thenStr).arg(remainingStr);
ivand_qmul@121 4178
ivand_qmul@121 4179 statusBar()->showMessage(m_myStatusMessage);
ivand_qmul@121 4180 }
ivand_qmul@121 4181
ivand_qmul@121 4182 void
ivand_qmul@121 4183 MainWindow::globalCentreFrameChanged(unsigned long )
ivand_qmul@121 4184 {
ivand_qmul@121 4185 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
ivand_qmul@121 4186 Pane *p = 0;
ivand_qmul@121 4187 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
ivand_qmul@121 4188 if (!p->getFollowGlobalPan()) return;
ivand_qmul@121 4189 updateVisibleRangeDisplay(p);
ivand_qmul@121 4190 }
ivand_qmul@121 4191
ivand_qmul@121 4192 void
ivand_qmul@121 4193 MainWindow::viewCentreFrameChanged(View *v, unsigned long )
ivand_qmul@121 4194 {
ivand_qmul@121 4195 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
ivand_qmul@121 4196 Pane *p = 0;
ivand_qmul@121 4197 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
ivand_qmul@121 4198 if (v == p) updateVisibleRangeDisplay(p);
ivand_qmul@121 4199 }
ivand_qmul@121 4200
ivand_qmul@121 4201 void
ivand_qmul@121 4202 MainWindow::viewZoomLevelChanged(View *v, unsigned long , bool )
ivand_qmul@121 4203 {
ivand_qmul@121 4204 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
ivand_qmul@121 4205 Pane *p = 0;
ivand_qmul@121 4206 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
ivand_qmul@121 4207 if (v == p) updateVisibleRangeDisplay(p);
ivand_qmul@121 4208 }
ivand_qmul@121 4209
ivand_qmul@121 4210 void
ivand_qmul@121 4211 MainWindow::updateVisibleRangeDisplay(Pane *p) const
ivand_qmul@121 4212 {
ivand_qmul@121 4213 if (!getMainModel() || !p) {
ivand_qmul@121 4214 return;
ivand_qmul@121 4215 }
ivand_qmul@121 4216
ivand_qmul@121 4217 bool haveSelection = false;
ivand_qmul@121 4218 size_t startFrame = 0, endFrame = 0;
ivand_qmul@121 4219
ivand_qmul@121 4220 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
ivand_qmul@121 4221
ivand_qmul@121 4222 bool exclusive = false;
ivand_qmul@121 4223 Selection s = m_viewManager->getInProgressSelection(exclusive);
ivand_qmul@121 4224
ivand_qmul@121 4225 if (!s.isEmpty()) {
ivand_qmul@121 4226 haveSelection = true;
ivand_qmul@121 4227 startFrame = s.getStartFrame();
ivand_qmul@121 4228 endFrame = s.getEndFrame();
ivand_qmul@121 4229 }
ivand_qmul@121 4230 }
ivand_qmul@121 4231
ivand_qmul@121 4232 if (!haveSelection) {
ivand_qmul@121 4233 startFrame = p->getFirstVisibleFrame();
ivand_qmul@121 4234 endFrame = p->getLastVisibleFrame();
ivand_qmul@121 4235 }
ivand_qmul@121 4236
ivand_qmul@121 4237 RealTime start = RealTime::frame2RealTime
ivand_qmul@121 4238 (startFrame, getMainModel()->getSampleRate());
ivand_qmul@121 4239
ivand_qmul@121 4240 RealTime end = RealTime::frame2RealTime
ivand_qmul@121 4241 (endFrame, getMainModel()->getSampleRate());
ivand_qmul@121 4242
ivand_qmul@121 4243 RealTime duration = end - start;
ivand_qmul@121 4244
ivand_qmul@121 4245 QString startStr, endStr, durationStr;
ivand_qmul@121 4246 startStr = start.toText(true).c_str();
ivand_qmul@121 4247 endStr = end.toText(true).c_str();
ivand_qmul@121 4248 durationStr = duration.toText(true).c_str();
ivand_qmul@121 4249
ivand_qmul@121 4250 if (haveSelection) {
ivand_qmul@121 4251 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
ivand_qmul@121 4252 .arg(startStr).arg(endStr).arg(durationStr);
ivand_qmul@121 4253 } else {
ivand_qmul@121 4254 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
ivand_qmul@121 4255 .arg(startStr).arg(endStr).arg(durationStr);
ivand_qmul@121 4256 }
ivand_qmul@121 4257
ivand_qmul@121 4258 statusBar()->showMessage(m_myStatusMessage);
ivand_qmul@121 4259 }
ivand_qmul@121 4260
ivand_qmul@121 4261 void
ivand_qmul@121 4262 MainWindow::outputLevelsChanged(float left, float right)
ivand_qmul@121 4263 {
ivand_qmul@121 4264 m_fader->setPeakLeft(left);
ivand_qmul@121 4265 m_fader->setPeakRight(right);
ivand_qmul@121 4266 }
ivand_qmul@121 4267
ivand_qmul@121 4268 void
ivand_qmul@121 4269 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
ivand_qmul@121 4270 bool willResample)
ivand_qmul@121 4271 {
ivand_qmul@121 4272 if (!willResample) {
ivand_qmul@121 4273 //!!! more helpful message needed
ivand_qmul@121 4274 QMessageBox::information
ivand_qmul@121 4275 (this, tr("Sample rate mismatch"),
ivand_qmul@121 4276 tr("The sample rate of this audio file (%1 Hz) does not match\nthe current playback rate (%2 Hz).\n\nThe file will play at the wrong speed and pitch.")
ivand_qmul@121 4277 .arg(requested).arg(actual));
ivand_qmul@121 4278 }
ivand_qmul@121 4279
ivand_qmul@121 4280 updateDescriptionLabel();
ivand_qmul@121 4281 }
ivand_qmul@121 4282
ivand_qmul@121 4283 void
ivand_qmul@121 4284 MainWindow::audioOverloadPluginDisabled()
ivand_qmul@121 4285 {
ivand_qmul@121 4286 QMessageBox::information
ivand_qmul@121 4287 (this, tr("Audio processing overload"),
ivand_qmul@121 4288 tr("Audio effects plugin auditioning has been disabled\ndue to a processing overload."));
ivand_qmul@121 4289 }
ivand_qmul@121 4290
ivand_qmul@121 4291 void
ivand_qmul@121 4292 MainWindow::layerAdded(Layer *)
ivand_qmul@121 4293 {
ivand_qmul@121 4294 // std::cerr << "MainWindow::layerAdded(" << layer << ")" << std::endl;
ivand_qmul@121 4295 // setupExistingLayersMenu();
ivand_qmul@121 4296 updateMenuStates();
ivand_qmul@121 4297 }
ivand_qmul@121 4298
ivand_qmul@121 4299 void
ivand_qmul@121 4300 MainWindow::layerRemoved(Layer *)
ivand_qmul@121 4301 {
ivand_qmul@121 4302 // std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl;
ivand_qmul@121 4303 setupExistingLayersMenus();
ivand_qmul@121 4304 updateMenuStates();
ivand_qmul@121 4305 }
ivand_qmul@121 4306
ivand_qmul@121 4307 void
ivand_qmul@121 4308 MainWindow::layerAboutToBeDeleted(Layer *layer)
ivand_qmul@121 4309 {
ivand_qmul@121 4310 // std::cerr << "MainWindow::layerAboutToBeDeleted(" << layer << ")" << std::endl;
ivand_qmul@121 4311 if (layer == m_timeRulerLayer) {
ivand_qmul@121 4312 // std::cerr << "(this is the time ruler layer)" << std::endl;
ivand_qmul@121 4313 m_timeRulerLayer = 0;
ivand_qmul@121 4314 }
ivand_qmul@121 4315 }
ivand_qmul@121 4316
ivand_qmul@121 4317 void
ivand_qmul@121 4318 MainWindow::layerInAView(Layer *layer, bool inAView)
ivand_qmul@121 4319 {
ivand_qmul@121 4320 // std::cerr << "MainWindow::layerInAView(" << layer << "," << inAView << ")" << std::endl;
ivand_qmul@121 4321
ivand_qmul@121 4322 // Check whether we need to add or remove model from play source
ivand_qmul@121 4323 Model *model = layer->getModel();
ivand_qmul@121 4324 if (model) {
ivand_qmul@121 4325 if (inAView) {
ivand_qmul@121 4326 m_playSource->addModel(model);
ivand_qmul@121 4327 } else {
ivand_qmul@121 4328 bool found = false;
ivand_qmul@121 4329 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
ivand_qmul@121 4330 Pane *pane = m_paneStack->getPane(i);
ivand_qmul@121 4331 if (!pane) continue;
ivand_qmul@121 4332 for (int j = 0; j < pane->getLayerCount(); ++j) {
ivand_qmul@121 4333 Layer *pl = pane->getLayer(j);
ivand_qmul@121 4334 if (pl && pl->getModel() == model) {
ivand_qmul@121 4335 found = true;
ivand_qmul@121 4336 break;
ivand_qmul@121 4337 }
ivand_qmul@121 4338 }
ivand_qmul@121 4339 if (found) break;
ivand_qmul@121 4340 }
ivand_qmul@121 4341 if (!found) m_playSource->removeModel(model);
ivand_qmul@121 4342 }
ivand_qmul@121 4343 }
ivand_qmul@121 4344
ivand_qmul@121 4345 setupExistingLayersMenus();
ivand_qmul@121 4346 updateMenuStates();
ivand_qmul@121 4347 }
ivand_qmul@121 4348
ivand_qmul@121 4349 void
ivand_qmul@121 4350 MainWindow::modelAdded(Model *model)
ivand_qmul@121 4351 {
ivand_qmul@121 4352 // std::cerr << "MainWindow::modelAdded(" << model << ")" << std::endl;
ivand_qmul@121 4353 m_playSource->addModel(model);
ivand_qmul@121 4354 if (dynamic_cast<DenseTimeValueModel *>(model)) {
ivand_qmul@121 4355 setupPaneAndLayerMenus();
ivand_qmul@121 4356 }
ivand_qmul@121 4357 }
ivand_qmul@121 4358
ivand_qmul@121 4359 void
ivand_qmul@121 4360 MainWindow::mainModelChanged(WaveFileModel *model)
ivand_qmul@121 4361 {
ivand_qmul@121 4362 // std::cerr << "MainWindow::mainModelChanged(" << model << ")" << std::endl;
ivand_qmul@121 4363 updateDescriptionLabel();
ivand_qmul@121 4364 m_panLayer->setModel(model);
ivand_qmul@121 4365 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
ivand_qmul@121 4366 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
ivand_qmul@121 4367
ivand_qmul@121 4368 updateMenuStates();
ivand_qmul@121 4369 }
ivand_qmul@121 4370
ivand_qmul@121 4371 void
ivand_qmul@121 4372 MainWindow::modelAboutToBeDeleted(Model *model)
ivand_qmul@121 4373 {
ivand_qmul@121 4374 // std::cerr << "MainWindow::modelAboutToBeDeleted(" << model << ")" << std::endl;
ivand_qmul@121 4375 m_playSource->removeModel(model);
ivand_qmul@121 4376 FFTDataServer::modelAboutToBeDeleted(model);
ivand_qmul@121 4377 }
ivand_qmul@121 4378
ivand_qmul@121 4379 void
ivand_qmul@121 4380 MainWindow::modelGenerationFailed(QString transformName)
ivand_qmul@121 4381 {
ivand_qmul@121 4382 QMessageBox::warning
ivand_qmul@121 4383 (this,
ivand_qmul@121 4384 tr("Failed to generate layer"),
ivand_qmul@121 4385 tr("Failed to generate a derived layer.\n\nThe layer transform \"%1\" failed.\n\nThis probably means that a plugin failed to initialise, perhaps because it\nrejected the processing block size that was requested.")
ivand_qmul@121 4386 .arg(transformName),
ivand_qmul@121 4387 QMessageBox::Ok, 0);
ivand_qmul@121 4388 }
ivand_qmul@121 4389
ivand_qmul@121 4390 void
ivand_qmul@121 4391 MainWindow::modelRegenerationFailed(QString layerName, QString transformName)
ivand_qmul@121 4392 {
ivand_qmul@121 4393 QMessageBox::warning
ivand_qmul@121 4394 (this,
ivand_qmul@121 4395 tr("Failed to regenerate layer"),
ivand_qmul@121 4396 tr("Failed to regenerate derived layer \"%1\".\n\nThe layer transform \"%2\" failed to run.\n\nThis probably means the layer used a plugin that is not currently available.")
ivand_qmul@121 4397 .arg(layerName).arg(transformName),
ivand_qmul@121 4398 QMessageBox::Ok, 0);
ivand_qmul@121 4399 }
ivand_qmul@121 4400
ivand_qmul@121 4401 void
ivand_qmul@121 4402 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
ivand_qmul@121 4403 {
ivand_qmul@121 4404 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
ivand_qmul@121 4405 m_paneStack->setCurrentPane(pane);
ivand_qmul@121 4406 m_rightButtonMenu->popup(position);
ivand_qmul@121 4407 }
ivand_qmul@121 4408
ivand_qmul@121 4409 void
ivand_qmul@121 4410 MainWindow::propertyStacksResized()
ivand_qmul@121 4411 {
ivand_qmul@121 4412 /*
ivand_qmul@121 4413 std::cerr << "MainWindow::propertyStacksResized" << std::endl;
ivand_qmul@121 4414 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 4415 if (pane && m_overview) {
ivand_qmul@121 4416 std::cerr << "Fixed width: " << pane->width() << std::endl;
ivand_qmul@121 4417 m_overview->setFixedWidth(pane->width());
ivand_qmul@121 4418 }
ivand_qmul@121 4419 */
ivand_qmul@121 4420 }
ivand_qmul@121 4421
ivand_qmul@121 4422 void
ivand_qmul@121 4423 MainWindow::showLayerTree()
ivand_qmul@121 4424 {
ivand_qmul@121 4425 QTreeView *view = new QTreeView();
ivand_qmul@121 4426 LayerTreeModel *tree = new LayerTreeModel(m_paneStack);
ivand_qmul@121 4427 view->expand(tree->index(0, 0, QModelIndex()));
ivand_qmul@121 4428 view->setModel(tree);
ivand_qmul@121 4429 view->show();
ivand_qmul@121 4430 }
ivand_qmul@121 4431
ivand_qmul@121 4432 void
ivand_qmul@121 4433 MainWindow::pollOSC()
ivand_qmul@121 4434 {
ivand_qmul@121 4435 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
ivand_qmul@121 4436 std::cerr << "MainWindow::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
ivand_qmul@121 4437
ivand_qmul@121 4438 if (m_openingAudioFile) return;
ivand_qmul@121 4439
ivand_qmul@121 4440 OSCMessage message = m_oscQueue->readMessage();
ivand_qmul@121 4441
ivand_qmul@121 4442 if (message.getTarget() != 0) {
ivand_qmul@121 4443 return; //!!! for now -- this class is target 0, others not handled yet
ivand_qmul@121 4444 }
ivand_qmul@121 4445
ivand_qmul@121 4446 handleOSCMessage(message);
ivand_qmul@121 4447 }
ivand_qmul@121 4448
ivand_qmul@121 4449 void
ivand_qmul@121 4450 MainWindow::handleOSCMessage(const OSCMessage &message)
ivand_qmul@121 4451 {
ivand_qmul@121 4452 std::cerr << "MainWindow::handleOSCMessage: thread id = "
ivand_qmul@121 4453 << QThread::currentThreadId() << std::endl;
ivand_qmul@121 4454
ivand_qmul@121 4455 // This large function should really be abstracted out.
ivand_qmul@121 4456
ivand_qmul@121 4457 if (message.getMethod() == "open") {
ivand_qmul@121 4458
ivand_qmul@121 4459 if (message.getArgCount() == 1 &&
ivand_qmul@121 4460 message.getArg(0).canConvert(QVariant::String)) {
ivand_qmul@121 4461 QString path = message.getArg(0).toString();
ivand_qmul@121 4462 if (openSomeFile(path, ReplaceMainModel) != FileOpenSucceeded) {
ivand_qmul@121 4463 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
ivand_qmul@121 4464 << path.toStdString() << "\"" << std::endl;
ivand_qmul@121 4465 }
ivand_qmul@121 4466 //!!! we really need to spin here and not return until the
ivand_qmul@121 4467 // file has been completely decoded...
ivand_qmul@121 4468 }
ivand_qmul@121 4469
ivand_qmul@121 4470 } else if (message.getMethod() == "openadditional") {
ivand_qmul@121 4471
ivand_qmul@121 4472 if (message.getArgCount() == 1 &&
ivand_qmul@121 4473 message.getArg(0).canConvert(QVariant::String)) {
ivand_qmul@121 4474 QString path = message.getArg(0).toString();
ivand_qmul@121 4475 if (openSomeFile(path, CreateAdditionalModel) != FileOpenSucceeded) {
ivand_qmul@121 4476 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
ivand_qmul@121 4477 << path.toStdString() << "\"" << std::endl;
ivand_qmul@121 4478 }
ivand_qmul@121 4479 }
ivand_qmul@121 4480
ivand_qmul@121 4481 } else if (message.getMethod() == "recent" ||
ivand_qmul@121 4482 message.getMethod() == "last") {
ivand_qmul@121 4483
ivand_qmul@121 4484 int n = 0;
ivand_qmul@121 4485 if (message.getMethod() == "recent" &&
ivand_qmul@121 4486 message.getArgCount() == 1 &&
ivand_qmul@121 4487 message.getArg(0).canConvert(QVariant::Int)) {
ivand_qmul@121 4488 n = message.getArg(0).toInt() - 1;
ivand_qmul@121 4489 }
ivand_qmul@121 4490 std::vector<QString> recent = m_recentFiles.getRecent();
ivand_qmul@121 4491 if (n >= 0 && n < int(recent.size())) {
ivand_qmul@121 4492 if (openSomeFile(recent[n], ReplaceMainModel) != FileOpenSucceeded) {
ivand_qmul@121 4493 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
ivand_qmul@121 4494 << recent[n].toStdString() << "\"" << std::endl;
ivand_qmul@121 4495 }
ivand_qmul@121 4496 }
ivand_qmul@121 4497
ivand_qmul@121 4498 } else if (message.getMethod() == "save") {
ivand_qmul@121 4499
ivand_qmul@121 4500 QString path;
ivand_qmul@121 4501 if (message.getArgCount() == 1 &&
ivand_qmul@121 4502 message.getArg(0).canConvert(QVariant::String)) {
ivand_qmul@121 4503 path = message.getArg(0).toString();
ivand_qmul@121 4504 if (QFileInfo(path).exists()) {
ivand_qmul@121 4505 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in save" << std::endl;
ivand_qmul@121 4506 } else {
ivand_qmul@121 4507 saveSessionFile(path);
ivand_qmul@121 4508 }
ivand_qmul@121 4509 }
ivand_qmul@121 4510
ivand_qmul@121 4511 } else if (message.getMethod() == "export") {
ivand_qmul@121 4512
ivand_qmul@121 4513 QString path;
ivand_qmul@121 4514 if (getMainModel()) {
ivand_qmul@121 4515 if (message.getArgCount() == 1 &&
ivand_qmul@121 4516 message.getArg(0).canConvert(QVariant::String)) {
ivand_qmul@121 4517 path = message.getArg(0).toString();
ivand_qmul@121 4518 if (QFileInfo(path).exists()) {
ivand_qmul@121 4519 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in export" << std::endl;
ivand_qmul@121 4520 } else {
ivand_qmul@121 4521 WavFileWriter writer(path,
ivand_qmul@121 4522 getMainModel()->getSampleRate(),
ivand_qmul@121 4523 getMainModel()->getChannelCount());
ivand_qmul@121 4524 MultiSelection ms = m_viewManager->getSelection();
ivand_qmul@121 4525 if (!ms.getSelections().empty()) {
ivand_qmul@121 4526 writer.writeModel(getMainModel(), &ms);
ivand_qmul@121 4527 } else {
ivand_qmul@121 4528 writer.writeModel(getMainModel());
ivand_qmul@121 4529 }
ivand_qmul@121 4530 }
ivand_qmul@121 4531 }
ivand_qmul@121 4532 }
ivand_qmul@121 4533
ivand_qmul@121 4534 } else if (message.getMethod() == "jump" ||
ivand_qmul@121 4535 message.getMethod() == "play") {
ivand_qmul@121 4536
ivand_qmul@121 4537 if (getMainModel()) {
ivand_qmul@121 4538
ivand_qmul@121 4539 unsigned long frame = m_viewManager->getPlaybackFrame();
ivand_qmul@121 4540 bool selection = false;
ivand_qmul@121 4541 bool play = (message.getMethod() == "play");
ivand_qmul@121 4542
ivand_qmul@121 4543 if (message.getArgCount() == 1) {
ivand_qmul@121 4544
ivand_qmul@121 4545 if (message.getArg(0).canConvert(QVariant::String) &&
ivand_qmul@121 4546 message.getArg(0).toString() == "selection") {
ivand_qmul@121 4547
ivand_qmul@121 4548 selection = true;
ivand_qmul@121 4549
ivand_qmul@121 4550 } else if (message.getArg(0).canConvert(QVariant::String) &&
ivand_qmul@121 4551 message.getArg(0).toString() == "end") {
ivand_qmul@121 4552
ivand_qmul@121 4553 frame = getMainModel()->getEndFrame();
ivand_qmul@121 4554
ivand_qmul@121 4555 } else if (message.getArg(0).canConvert(QVariant::Double)) {
ivand_qmul@121 4556
ivand_qmul@121 4557 double time = message.getArg(0).toDouble();
ivand_qmul@121 4558 if (time < 0.0) time = 0.0;
ivand_qmul@121 4559
ivand_qmul@121 4560 frame = lrint(time * getMainModel()->getSampleRate());
ivand_qmul@121 4561 }
ivand_qmul@121 4562 }
ivand_qmul@121 4563
ivand_qmul@121 4564 if (frame > getMainModel()->getEndFrame()) {
ivand_qmul@121 4565 frame = getMainModel()->getEndFrame();
ivand_qmul@121 4566 }
ivand_qmul@121 4567
ivand_qmul@121 4568 if (play) {
ivand_qmul@121 4569 m_viewManager->setPlaySelectionMode(selection);
ivand_qmul@121 4570 }
ivand_qmul@121 4571
ivand_qmul@121 4572 if (selection) {
ivand_qmul@121 4573 MultiSelection::SelectionList sl = m_viewManager->getSelections();
ivand_qmul@121 4574 if (!sl.empty()) {
ivand_qmul@121 4575 frame = sl.begin()->getStartFrame();
ivand_qmul@121 4576 }
ivand_qmul@121 4577 }
ivand_qmul@121 4578
ivand_qmul@121 4579 m_viewManager->setPlaybackFrame(frame);
ivand_qmul@121 4580
ivand_qmul@121 4581 if (play && !m_playSource->isPlaying()) {
ivand_qmul@121 4582 m_playSource->play(frame);
ivand_qmul@121 4583 }
ivand_qmul@121 4584 }
ivand_qmul@121 4585
ivand_qmul@121 4586 } else if (message.getMethod() == "stop") {
ivand_qmul@121 4587
ivand_qmul@121 4588 if (m_playSource->isPlaying()) m_playSource->stop();
ivand_qmul@121 4589
ivand_qmul@121 4590 } else if (message.getMethod() == "loop") {
ivand_qmul@121 4591
ivand_qmul@121 4592 if (message.getArgCount() == 1 &&
ivand_qmul@121 4593 message.getArg(0).canConvert(QVariant::String)) {
ivand_qmul@121 4594
ivand_qmul@121 4595 QString str = message.getArg(0).toString();
ivand_qmul@121 4596 if (str == "on") {
ivand_qmul@121 4597 m_viewManager->setPlayLoopMode(true);
ivand_qmul@121 4598 } else if (str == "off") {
ivand_qmul@121 4599 m_viewManager->setPlayLoopMode(false);
ivand_qmul@121 4600 }
ivand_qmul@121 4601 }
ivand_qmul@121 4602
ivand_qmul@121 4603 } else if (message.getMethod() == "select" ||
ivand_qmul@121 4604 message.getMethod() == "addselect") {
ivand_qmul@121 4605
ivand_qmul@121 4606 if (getMainModel()) {
ivand_qmul@121 4607
ivand_qmul@121 4608 int f0 = getMainModel()->getStartFrame();
ivand_qmul@121 4609 int f1 = getMainModel()->getEndFrame();
ivand_qmul@121 4610
ivand_qmul@121 4611 bool done = false;
ivand_qmul@121 4612
ivand_qmul@121 4613 if (message.getArgCount() == 2 &&
ivand_qmul@121 4614 message.getArg(0).canConvert(QVariant::Double) &&
ivand_qmul@121 4615 message.getArg(1).canConvert(QVariant::Double)) {
ivand_qmul@121 4616
ivand_qmul@121 4617 double t0 = message.getArg(0).toDouble();
ivand_qmul@121 4618 double t1 = message.getArg(1).toDouble();
ivand_qmul@121 4619 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; }
ivand_qmul@121 4620 if (t0 < 0.0) t0 = 0.0;
ivand_qmul@121 4621 if (t1 < 0.0) t1 = 0.0;
ivand_qmul@121 4622
ivand_qmul@121 4623 f0 = lrint(t0 * getMainModel()->getSampleRate());
ivand_qmul@121 4624 f1 = lrint(t1 * getMainModel()->getSampleRate());
ivand_qmul@121 4625
ivand_qmul@121 4626 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 4627 Layer *layer = 0;
ivand_qmul@121 4628 if (pane) layer = pane->getSelectedLayer();
ivand_qmul@121 4629 if (layer) {
ivand_qmul@121 4630 size_t resolution;
ivand_qmul@121 4631 layer->snapToFeatureFrame(pane, f0, resolution,
ivand_qmul@121 4632 Layer::SnapLeft);
ivand_qmul@121 4633 layer->snapToFeatureFrame(pane, f1, resolution,
ivand_qmul@121 4634 Layer::SnapRight);
ivand_qmul@121 4635 }
ivand_qmul@121 4636
ivand_qmul@121 4637 } else if (message.getArgCount() == 1 &&
ivand_qmul@121 4638 message.getArg(0).canConvert(QVariant::String)) {
ivand_qmul@121 4639
ivand_qmul@121 4640 QString str = message.getArg(0).toString();
ivand_qmul@121 4641 if (str == "none") {
ivand_qmul@121 4642 m_viewManager->clearSelections();
ivand_qmul@121 4643 done = true;
ivand_qmul@121 4644 }
ivand_qmul@121 4645 }
ivand_qmul@121 4646
ivand_qmul@121 4647 if (!done) {
ivand_qmul@121 4648 if (message.getMethod() == "select") {
ivand_qmul@121 4649 m_viewManager->setSelection(Selection(f0, f1));
ivand_qmul@121 4650 } else {
ivand_qmul@121 4651 m_viewManager->addSelection(Selection(f0, f1));
ivand_qmul@121 4652 }
ivand_qmul@121 4653 }
ivand_qmul@121 4654 }
ivand_qmul@121 4655
ivand_qmul@121 4656 } else if (message.getMethod() == "add") {
ivand_qmul@121 4657
ivand_qmul@121 4658 if (getMainModel()) {
ivand_qmul@121 4659
ivand_qmul@121 4660 if (message.getArgCount() >= 1 &&
ivand_qmul@121 4661 message.getArg(0).canConvert(QVariant::String)) {
ivand_qmul@121 4662
ivand_qmul@121 4663 int channel = -1;
ivand_qmul@121 4664 if (message.getArgCount() == 2 &&
ivand_qmul@121 4665 message.getArg(0).canConvert(QVariant::Int)) {
ivand_qmul@121 4666 channel = message.getArg(0).toInt();
ivand_qmul@121 4667 if (channel < -1 ||
ivand_qmul@121 4668 channel > int(getMainModel()->getChannelCount())) {
ivand_qmul@121 4669 std::cerr << "WARNING: MainWindow::handleOSCMessage: channel "
ivand_qmul@121 4670 << channel << " out of range" << std::endl;
ivand_qmul@121 4671 channel = -1;
ivand_qmul@121 4672 }
ivand_qmul@121 4673 }
ivand_qmul@121 4674
ivand_qmul@121 4675 QString str = message.getArg(0).toString();
ivand_qmul@121 4676
ivand_qmul@121 4677 LayerFactory::LayerType type =
ivand_qmul@121 4678 LayerFactory::getInstance()->getLayerTypeForName(str);
ivand_qmul@121 4679
ivand_qmul@121 4680 if (type == LayerFactory::UnknownLayer) {
ivand_qmul@121 4681 std::cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer "
ivand_qmul@121 4682 << "type " << str.toStdString() << std::endl;
ivand_qmul@121 4683 } else {
ivand_qmul@121 4684
ivand_qmul@121 4685 PaneConfiguration configuration(type,
ivand_qmul@121 4686 getMainModel(),
ivand_qmul@121 4687 channel);
ivand_qmul@121 4688
ivand_qmul@121 4689 addPane(configuration,
ivand_qmul@121 4690 tr("Add %1 Pane")
ivand_qmul@121 4691 .arg(LayerFactory::getInstance()->
ivand_qmul@121 4692 getLayerPresentationName(type)));
ivand_qmul@121 4693 }
ivand_qmul@121 4694 }
ivand_qmul@121 4695 }
ivand_qmul@121 4696
ivand_qmul@121 4697 } else if (message.getMethod() == "undo") {
ivand_qmul@121 4698
ivand_qmul@121 4699 CommandHistory::getInstance()->undo();
ivand_qmul@121 4700
ivand_qmul@121 4701 } else if (message.getMethod() == "redo") {
ivand_qmul@121 4702
ivand_qmul@121 4703 CommandHistory::getInstance()->redo();
ivand_qmul@121 4704
ivand_qmul@121 4705 } else if (message.getMethod() == "set") {
ivand_qmul@121 4706
ivand_qmul@121 4707 if (message.getArgCount() == 2 &&
ivand_qmul@121 4708 message.getArg(0).canConvert(QVariant::String) &&
ivand_qmul@121 4709 message.getArg(1).canConvert(QVariant::Double)) {
ivand_qmul@121 4710
ivand_qmul@121 4711 QString property = message.getArg(0).toString();
ivand_qmul@121 4712 float value = (float)message.getArg(1).toDouble();
ivand_qmul@121 4713
ivand_qmul@121 4714 if (property == "gain") {
ivand_qmul@121 4715 if (value < 0.0) value = 0.0;
ivand_qmul@121 4716 m_fader->setValue(value);
ivand_qmul@121 4717 if (m_playTarget) m_playTarget->setOutputGain(value);
lbajardsilogic@127 4718 } /*else if (property == "speedup") {
ivand_qmul@121 4719 m_playSpeed->setMappedValue(value);
lbajardsilogic@127 4720 }*/ else if (property == "overlays") {
ivand_qmul@121 4721 if (value < 0.5) {
ivand_qmul@121 4722 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
ivand_qmul@121 4723 } else if (value < 1.5) {
ivand_qmul@121 4724 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
ivand_qmul@121 4725 } else if (value < 2.5) {
ivand_qmul@121 4726 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
ivand_qmul@121 4727 } else {
ivand_qmul@121 4728 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
ivand_qmul@121 4729 }
ivand_qmul@121 4730 } else if (property == "zoomwheels") {
ivand_qmul@121 4731 m_viewManager->setZoomWheelsEnabled(value > 0.5);
lbajardsilogic@204 4732 }
ivand_qmul@121 4733
ivand_qmul@121 4734 } else {
ivand_qmul@121 4735 PropertyContainer *container = 0;
ivand_qmul@121 4736 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 4737 if (pane &&
ivand_qmul@121 4738 message.getArgCount() == 3 &&
ivand_qmul@121 4739 message.getArg(0).canConvert(QVariant::String) &&
ivand_qmul@121 4740 message.getArg(1).canConvert(QVariant::String) &&
ivand_qmul@121 4741 message.getArg(2).canConvert(QVariant::String)) {
ivand_qmul@121 4742 if (message.getArg(0).toString() == "pane") {
ivand_qmul@121 4743 container = pane->getPropertyContainer(0);
ivand_qmul@121 4744 } else if (message.getArg(0).toString() == "layer") {
ivand_qmul@121 4745 container = pane->getSelectedLayer();
ivand_qmul@121 4746 }
ivand_qmul@121 4747 }
ivand_qmul@121 4748 if (container) {
ivand_qmul@121 4749 QString nameString = message.getArg(1).toString();
ivand_qmul@121 4750 QString valueString = message.getArg(2).toString();
ivand_qmul@121 4751 container->setPropertyWithCommand(nameString, valueString);
ivand_qmul@121 4752 }
ivand_qmul@121 4753 }
ivand_qmul@121 4754
ivand_qmul@121 4755 } else if (message.getMethod() == "setcurrent") {
ivand_qmul@121 4756
ivand_qmul@121 4757 int paneIndex = -1, layerIndex = -1;
ivand_qmul@121 4758 bool wantLayer = false;
ivand_qmul@121 4759
ivand_qmul@121 4760 if (message.getArgCount() >= 1 &&
ivand_qmul@121 4761 message.getArg(0).canConvert(QVariant::Int)) {
ivand_qmul@121 4762
ivand_qmul@121 4763 paneIndex = message.getArg(0).toInt() - 1;
ivand_qmul@121 4764
ivand_qmul@121 4765 if (message.getArgCount() >= 2 &&
ivand_qmul@121 4766 message.getArg(1).canConvert(QVariant::Int)) {
ivand_qmul@121 4767 wantLayer = true;
ivand_qmul@121 4768 layerIndex = message.getArg(1).toInt() - 1;
ivand_qmul@121 4769 }
ivand_qmul@121 4770 }
ivand_qmul@121 4771
ivand_qmul@121 4772 if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) {
ivand_qmul@121 4773 Pane *pane = m_paneStack->getPane(paneIndex);
ivand_qmul@121 4774 m_paneStack->setCurrentPane(pane);
ivand_qmul@121 4775 if (layerIndex >= 0 && layerIndex < pane->getLayerCount()) {
ivand_qmul@121 4776 Layer *layer = pane->getLayer(layerIndex);
ivand_qmul@121 4777 m_paneStack->setCurrentLayer(pane, layer);
ivand_qmul@121 4778 } else if (wantLayer && layerIndex == -1) {
ivand_qmul@121 4779 m_paneStack->setCurrentLayer(pane, 0);
ivand_qmul@121 4780 }
ivand_qmul@121 4781 }
ivand_qmul@121 4782
ivand_qmul@121 4783 } else if (message.getMethod() == "delete") {
ivand_qmul@121 4784
ivand_qmul@121 4785 if (message.getArgCount() == 1 &&
ivand_qmul@121 4786 message.getArg(0).canConvert(QVariant::String)) {
ivand_qmul@121 4787
ivand_qmul@121 4788 QString target = message.getArg(0).toString();
ivand_qmul@121 4789
ivand_qmul@121 4790 if (target == "pane") {
ivand_qmul@121 4791
ivand_qmul@121 4792 deleteCurrentPane();
ivand_qmul@121 4793
ivand_qmul@121 4794 } else if (target == "layer") {
ivand_qmul@121 4795
ivand_qmul@121 4796 deleteCurrentLayer();
ivand_qmul@121 4797
ivand_qmul@121 4798 } else {
ivand_qmul@121 4799
ivand_qmul@121 4800 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target.toStdString() << std::endl;
ivand_qmul@121 4801 }
ivand_qmul@121 4802 }
ivand_qmul@121 4803
ivand_qmul@121 4804 } else if (message.getMethod() == "zoom") {
ivand_qmul@121 4805
ivand_qmul@121 4806 if (message.getArgCount() == 1) {
ivand_qmul@121 4807 if (message.getArg(0).canConvert(QVariant::String) &&
ivand_qmul@121 4808 message.getArg(0).toString() == "in") {
ivand_qmul@121 4809 zoomIn();
ivand_qmul@121 4810 } else if (message.getArg(0).canConvert(QVariant::String) &&
ivand_qmul@121 4811 message.getArg(0).toString() == "out") {
ivand_qmul@121 4812 zoomOut();
ivand_qmul@121 4813 } else if (message.getArg(0).canConvert(QVariant::String) &&
ivand_qmul@121 4814 message.getArg(0).toString() == "default") {
ivand_qmul@121 4815 zoomDefault();
ivand_qmul@121 4816 } else if (message.getArg(0).canConvert(QVariant::Double)) {
ivand_qmul@121 4817 double level = message.getArg(0).toDouble();
ivand_qmul@121 4818 Pane *currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 4819 if (level < 1.0) level = 1.0;
ivand_qmul@121 4820 if (currentPane) currentPane->setZoomLevel(lrint(level));
ivand_qmul@121 4821 }
ivand_qmul@121 4822 }
ivand_qmul@121 4823
ivand_qmul@121 4824 } else if (message.getMethod() == "zoomvertical") {
ivand_qmul@121 4825
ivand_qmul@121 4826 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 4827 Layer *layer = 0;
ivand_qmul@121 4828 if (pane && pane->getLayerCount() > 0) {
ivand_qmul@121 4829 layer = pane->getLayer(pane->getLayerCount() - 1);
ivand_qmul@121 4830 }
ivand_qmul@121 4831 int defaultStep = 0;
ivand_qmul@121 4832 int steps = 0;
ivand_qmul@121 4833 if (layer) {
ivand_qmul@121 4834 steps = layer->getVerticalZoomSteps(defaultStep);
ivand_qmul@121 4835 if (message.getArgCount() == 1 && steps > 0) {
ivand_qmul@121 4836 if (message.getArg(0).canConvert(QVariant::String) &&
ivand_qmul@121 4837 message.getArg(0).toString() == "in") {
ivand_qmul@121 4838 int step = layer->getCurrentVerticalZoomStep() + 1;
ivand_qmul@121 4839 if (step < steps) layer->setVerticalZoomStep(step);
ivand_qmul@121 4840 } else if (message.getArg(0).canConvert(QVariant::String) &&
ivand_qmul@121 4841 message.getArg(0).toString() == "out") {
ivand_qmul@121 4842 int step = layer->getCurrentVerticalZoomStep() - 1;
ivand_qmul@121 4843 if (step >= 0) layer->setVerticalZoomStep(step);
ivand_qmul@121 4844 } else if (message.getArg(0).canConvert(QVariant::String) &&
ivand_qmul@121 4845 message.getArg(0).toString() == "default") {
ivand_qmul@121 4846 layer->setVerticalZoomStep(defaultStep);
ivand_qmul@121 4847 }
ivand_qmul@121 4848 } else if (message.getArgCount() == 2) {
ivand_qmul@121 4849 if (message.getArg(0).canConvert(QVariant::Double) &&
ivand_qmul@121 4850 message.getArg(1).canConvert(QVariant::Double)) {
ivand_qmul@121 4851 double min = message.getArg(0).toDouble();
ivand_qmul@121 4852 double max = message.getArg(1).toDouble();
ivand_qmul@121 4853 layer->setDisplayExtents(min, max);
ivand_qmul@121 4854 }
ivand_qmul@121 4855 }
ivand_qmul@121 4856 }
ivand_qmul@121 4857
ivand_qmul@121 4858 } else if (message.getMethod() == "quit") {
ivand_qmul@121 4859
ivand_qmul@121 4860 m_abandoning = true;
ivand_qmul@121 4861 close();
ivand_qmul@121 4862
ivand_qmul@121 4863 } else if (message.getMethod() == "resize") {
ivand_qmul@121 4864
ivand_qmul@121 4865 if (message.getArgCount() == 2) {
ivand_qmul@121 4866
ivand_qmul@121 4867 int width = 0, height = 0;
ivand_qmul@121 4868
ivand_qmul@121 4869 if (message.getArg(1).canConvert(QVariant::Int)) {
ivand_qmul@121 4870
ivand_qmul@121 4871 height = message.getArg(1).toInt();
ivand_qmul@121 4872
ivand_qmul@121 4873 if (message.getArg(0).canConvert(QVariant::String) &&
ivand_qmul@121 4874 message.getArg(0).toString() == "pane") {
ivand_qmul@121 4875
ivand_qmul@121 4876 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 4877 if (pane) pane->resize(pane->width(), height);
ivand_qmul@121 4878
ivand_qmul@121 4879 } else if (message.getArg(0).canConvert(QVariant::Int)) {
ivand_qmul@121 4880
ivand_qmul@121 4881 width = message.getArg(0).toInt();
ivand_qmul@121 4882 resize(width, height);
ivand_qmul@121 4883 }
ivand_qmul@121 4884 }
ivand_qmul@121 4885 }
ivand_qmul@121 4886
ivand_qmul@121 4887 } else if (message.getMethod() == "transform") {
ivand_qmul@121 4888
ivand_qmul@121 4889 Pane *pane = m_paneStack->getCurrentPane();
ivand_qmul@121 4890
ivand_qmul@121 4891 if (getMainModel() &&
ivand_qmul@121 4892 pane &&
ivand_qmul@121 4893 message.getArgCount() == 1 &&
ivand_qmul@121 4894 message.getArg(0).canConvert(QVariant::String)) {
ivand_qmul@121 4895
ivand_qmul@121 4896 TransformId transform = message.getArg(0).toString();
ivand_qmul@121 4897
ivand_qmul@121 4898 Layer *newLayer = m_document->createDerivedLayer
ivand_qmul@121 4899 (transform,
ivand_qmul@121 4900 getMainModel(),
ivand_qmul@121 4901 TransformFactory::getInstance()->getDefaultContextForTransform
ivand_qmul@121 4902 (transform, getMainModel()),
ivand_qmul@121 4903 "");
ivand_qmul@121 4904
ivand_qmul@121 4905 if (newLayer) {
ivand_qmul@121 4906 m_document->addLayerToView(pane, newLayer);
ivand_qmul@121 4907 m_recentTransforms.add(transform);
ivand_qmul@121 4908 m_paneStack->setCurrentLayer(pane, newLayer);
ivand_qmul@121 4909 }
ivand_qmul@121 4910 }
ivand_qmul@121 4911
ivand_qmul@121 4912 } else {
ivand_qmul@121 4913 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported "
ivand_qmul@121 4914 << "method \"" << message.getMethod().toStdString()
ivand_qmul@121 4915 << "\"" << std::endl;
ivand_qmul@121 4916 }
ivand_qmul@121 4917
ivand_qmul@121 4918 }
ivand_qmul@121 4919
ivand_qmul@121 4920 void
ivand_qmul@121 4921 MainWindow::preferences()
ivand_qmul@121 4922 {
ivand_qmul@121 4923 if (!m_preferencesDialog.isNull()) {
ivand_qmul@121 4924 m_preferencesDialog->show();
ivand_qmul@121 4925 m_preferencesDialog->raise();
ivand_qmul@121 4926 return;
ivand_qmul@121 4927 }
ivand_qmul@121 4928
ivand_qmul@121 4929 m_preferencesDialog = new PreferencesDialog(this);
ivand_qmul@121 4930
ivand_qmul@121 4931 // DeleteOnClose is safe here, because m_preferencesDialog is a
ivand_qmul@121 4932 // QPointer that will be zeroed when the dialog is deleted. We
ivand_qmul@121 4933 // use it in preference to leaving the dialog lying around because
ivand_qmul@121 4934 // if you Cancel the dialog, it resets the preferences state
ivand_qmul@121 4935 // without resetting its own widgets, so its state will be
ivand_qmul@121 4936 // incorrect when next shown unless we construct it afresh
ivand_qmul@121 4937 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
ivand_qmul@121 4938
ivand_qmul@121 4939 m_preferencesDialog->show();
ivand_qmul@121 4940 }
ivand_qmul@121 4941
ivand_qmul@121 4942 void
ivand_qmul@121 4943 MainWindow::mouseEnteredWidget()
ivand_qmul@121 4944 {
ivand_qmul@121 4945 QWidget *w = dynamic_cast<QWidget *>(sender());
ivand_qmul@121 4946 if (!w) return;
ivand_qmul@121 4947
ivand_qmul@121 4948 if (w == m_fader) {
ivand_qmul@121 4949 contextHelpChanged(tr("Adjust the master playback level"));
lbajardsilogic@127 4950 } /*else if (w == m_playSpeed) {
ivand_qmul@121 4951 contextHelpChanged(tr("Adjust the master playback speed"));
ivand_qmul@121 4952 } else if (w == m_playSharpen && w->isEnabled()) {
ivand_qmul@121 4953 contextHelpChanged(tr("Toggle transient sharpening for playback time scaling"));
ivand_qmul@121 4954 } else if (w == m_playMono && w->isEnabled()) {
ivand_qmul@121 4955 contextHelpChanged(tr("Toggle mono mode for playback time scaling"));
lbajardsilogic@127 4956 }*/
ivand_qmul@121 4957 }
ivand_qmul@121 4958
ivand_qmul@121 4959 void
ivand_qmul@121 4960 MainWindow::mouseLeftWidget()
ivand_qmul@121 4961 {
ivand_qmul@121 4962 contextHelpChanged("");
ivand_qmul@121 4963 }
ivand_qmul@121 4964
ivand_qmul@121 4965 void
ivand_qmul@121 4966 MainWindow::inProgressSelectionChanged()
ivand_qmul@121 4967 {
ivand_qmul@121 4968 Pane *currentPane = 0;
ivand_qmul@121 4969 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
ivand_qmul@121 4970 if (currentPane) updateVisibleRangeDisplay(currentPane);
ivand_qmul@121 4971 }
ivand_qmul@121 4972
ivand_qmul@121 4973 void
ivand_qmul@121 4974 MainWindow::contextHelpChanged(const QString &s)
ivand_qmul@121 4975 {
ivand_qmul@121 4976 if (s == "" && m_myStatusMessage != "") {
ivand_qmul@121 4977 statusBar()->showMessage(m_myStatusMessage);
ivand_qmul@121 4978 return;
ivand_qmul@121 4979 }
ivand_qmul@121 4980 statusBar()->showMessage(s);
ivand_qmul@121 4981 }
ivand_qmul@121 4982
ivand_qmul@121 4983 void
ivand_qmul@121 4984 MainWindow::website()
ivand_qmul@121 4985 {
ivand_qmul@121 4986 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
ivand_qmul@121 4987 }
ivand_qmul@121 4988
ivand_qmul@121 4989 void
ivand_qmul@121 4990 MainWindow::help()
ivand_qmul@121 4991 {
ivand_qmul@121 4992 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/1.0/en/"));
ivand_qmul@121 4993 }
ivand_qmul@121 4994
ivand_qmul@121 4995 void
ivand_qmul@121 4996 MainWindow::openHelpUrl(QString url)
ivand_qmul@121 4997 {
ivand_qmul@121 4998 // This method mostly lifted from Qt Assistant source code
ivand_qmul@121 4999
ivand_qmul@121 5000 QProcess *process = new QProcess(this);
ivand_qmul@121 5001 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
ivand_qmul@121 5002
ivand_qmul@121 5003 QStringList args;
ivand_qmul@121 5004
ivand_qmul@121 5005 #ifdef Q_OS_MAC
ivand_qmul@121 5006 args.append(url);
ivand_qmul@121 5007 process->start("open", args);
ivand_qmul@121 5008 #else
ivand_qmul@121 5009 #ifdef Q_OS_WIN32
ivand_qmul@121 5010
ivand_qmul@121 5011 QString pf(getenv("ProgramFiles"));
ivand_qmul@121 5012 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
ivand_qmul@121 5013
ivand_qmul@121 5014 args.append(url);
ivand_qmul@121 5015 process->start(command, args);
ivand_qmul@121 5016
ivand_qmul@121 5017 #else
ivand_qmul@121 5018 #ifdef Q_WS_X11
ivand_qmul@121 5019 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
ivand_qmul@121 5020 args.append("exec");
ivand_qmul@121 5021 args.append(url);
ivand_qmul@121 5022 process->start("kfmclient", args);
ivand_qmul@121 5023 } else if (!qgetenv("BROWSER").isEmpty()) {
ivand_qmul@121 5024 args.append(url);
ivand_qmul@121 5025 process->start(qgetenv("BROWSER"), args);
ivand_qmul@121 5026 } else {
ivand_qmul@121 5027 args.append(url);
ivand_qmul@121 5028 process->start("firefox", args);
ivand_qmul@121 5029 }
ivand_qmul@121 5030 #endif
ivand_qmul@121 5031 #endif
ivand_qmul@121 5032 #endif
ivand_qmul@121 5033 }
ivand_qmul@121 5034
ivand_qmul@121 5035 void
ivand_qmul@121 5036 MainWindow::about()
ivand_qmul@121 5037 {
ivand_qmul@121 5038 bool debug = false;
ivand_qmul@121 5039 QString version = "(unknown version)";
ivand_qmul@121 5040
ivand_qmul@121 5041 #ifdef BUILD_DEBUG
ivand_qmul@121 5042 debug = true;
ivand_qmul@121 5043 #endif
ivand_qmul@121 5044 #ifdef SA_VERSION
ivand_qmul@121 5045 #ifdef SVNREV
ivand_qmul@121 5046 version = tr("Release %1 : Revision %2").arg(SA_VERSION).arg(SVNREV);
ivand_qmul@121 5047 #else
ivand_qmul@121 5048 version = tr("Release %1").arg(SA_VERSION);
ivand_qmul@121 5049 #endif
ivand_qmul@121 5050 #else
ivand_qmul@121 5051 #ifdef SVNREV
ivand_qmul@121 5052 version = tr("Unreleased : Revision %1").arg(SVNREV);
ivand_qmul@121 5053 #endif
ivand_qmul@121 5054 #endif
ivand_qmul@121 5055
ivand_qmul@121 5056 QString aboutText;
ivand_qmul@121 5057
lbajardsilogic@40 5058 aboutText += tr("<h3>About Sound Access</h3>");
lbajardsilogic@40 5059 aboutText += tr("<p>Sound Access is a program for viewing and exploring multimedia archives for semantic multimedia analysis and retrieval.</p>");
lbajardsilogic@40 5060 aboutText += tr("<p>EASAIER (EU-FP6-IST-033902) frontend client</p>");
lbajardsilogic@40 5061
lbajardsilogic@40 5062 aboutText += tr("<p>%1 : %2 build</p>")
lbajardsilogic@40 5063 .arg(version)
lbajardsilogic@40 5064 .arg(debug ? tr("Debug") : tr("Release"));
lbajardsilogic@40 5065
ivand_qmul@121 5066 aboutText += tr("<p>Based on Sonic Visualizer Copyright &copy; 2005 - 2007 Chris Cannam and Queen Mary, University of London (Version %1)</p>").arg(SV_VERSION);
ivand_qmul@121 5067
ivand_qmul@121 5068 #ifndef BUILD_STATIC
ivand_qmul@121 5069 aboutText += tr("<br>Using Qt v%1 &copy; Trolltech AS").arg(QT_VERSION_STR);
ivand_qmul@121 5070 #else
ivand_qmul@121 5071 #ifdef QT_SHARED
ivand_qmul@121 5072 aboutText += tr("<br>Using Qt v%1 &copy; Trolltech AS").arg(QT_VERSION_STR);
ivand_qmul@121 5073 #endif
ivand_qmul@121 5074 #endif
ivand_qmul@121 5075
ivand_qmul@121 5076 //#ifdef BUILD_STATIC
ivand_qmul@121 5077 aboutText += tr("<p>Linked with");
ivand_qmul@121 5078 #ifndef QT_SHARED
ivand_qmul@121 5079 aboutText += tr("<br>Qt (v%1) &copy; Trolltech AS").arg(QT_VERSION_STR);
ivand_qmul@121 5080 #endif
ivand_qmul@121 5081 #ifdef HAVE_JACK
ivand_qmul@121 5082 #ifdef JACK_VERSION
ivand_qmul@121 5083 aboutText += tr("<br>JACK audio output (v%1) &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
ivand_qmul@121 5084 #else
ivand_qmul@121 5085 aboutText += tr("<br>JACK audio output &copy; Paul Davis and Jack O'Quin");
ivand_qmul@121 5086 #endif
ivand_qmul@121 5087 #endif
ivand_qmul@121 5088 #ifdef HAVE_PORTAUDIO
ivand_qmul@121 5089 aboutText += tr("<br>PortAudio audio output &copy; Ross Bencina and Phil Burk");
ivand_qmul@121 5090 #endif
ivand_qmul@121 5091 #ifdef HAVE_OGGZ
ivand_qmul@121 5092 #ifdef OGGZ_VERSION
ivand_qmul@121 5093 aboutText += tr("<br>Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
ivand_qmul@121 5094 #else
ivand_qmul@121 5095 aboutText += tr("<br>Ogg file decoder &copy; CSIRO Australia");
ivand_qmul@121 5096 #endif
ivand_qmul@121 5097 #endif
ivand_qmul@121 5098 #ifdef HAVE_MAD
ivand_qmul@121 5099 #ifdef MAD_VERSION
ivand_qmul@121 5100 aboutText += tr("<br>MAD mp3 decoder (v%1) &copy; Underbit Technologies Inc").arg(MAD_VERSION);
ivand_qmul@121 5101 #else
ivand_qmul@121 5102 aboutText += tr("<br>MAD mp3 decoder &copy; Underbit Technologies Inc");
ivand_qmul@121 5103 #endif
ivand_qmul@121 5104 #endif
ivand_qmul@121 5105 #ifdef HAVE_SAMPLERATE
ivand_qmul@121 5106 #ifdef SAMPLERATE_VERSION
ivand_qmul@121 5107 aboutText += tr("<br>libsamplerate (v%1) &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
ivand_qmul@121 5108 #else
ivand_qmul@121 5109 aboutText += tr("<br>libsamplerate &copy; Erik de Castro Lopo");
ivand_qmul@121 5110 #endif
ivand_qmul@121 5111 #endif
ivand_qmul@121 5112 #ifdef HAVE_SNDFILE
ivand_qmul@121 5113 #ifdef SNDFILE_VERSION
ivand_qmul@121 5114 aboutText += tr("<br>libsndfile (v%1) &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
ivand_qmul@121 5115 #else
ivand_qmul@121 5116 aboutText += tr("<br>libsndfile &copy; Erik de Castro Lopo");
ivand_qmul@121 5117 #endif
ivand_qmul@121 5118 #endif
ivand_qmul@121 5119 #ifdef HAVE_FFTW3F
ivand_qmul@121 5120 #ifdef FFTW3_VERSION
ivand_qmul@121 5121 aboutText += tr("<br>FFTW3 (v%1) &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
ivand_qmul@121 5122 #else
ivand_qmul@121 5123 aboutText += tr("<br>FFTW3 &copy; Matteo Frigo and MIT");
ivand_qmul@121 5124 #endif
ivand_qmul@121 5125 #endif
ivand_qmul@121 5126 #ifdef HAVE_VAMP
ivand_qmul@121 5127 aboutText += tr("<br>Vamp plugin support (API v%1, host SDK v%2) &copy; Chris Cannam").arg(VAMP_API_VERSION).arg(VAMP_SDK_VERSION);
ivand_qmul@121 5128 #endif
ivand_qmul@121 5129 aboutText += tr("<br>LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
ivand_qmul@121 5130 aboutText += tr("<br>DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
ivand_qmul@121 5131 #ifdef HAVE_LIBLO
ivand_qmul@121 5132 #ifdef LIBLO_VERSION
ivand_qmul@121 5133 aboutText += tr("<br>liblo Lite OSC library (v%1) &copy; Steve Harris").arg(LIBLO_VERSION);
ivand_qmul@121 5134 #else
ivand_qmul@121 5135 aboutText += tr("<br>liblo Lite OSC library &copy; Steve Harris").arg(LIBLO_VERSION);
ivand_qmul@121 5136 #endif
ivand_qmul@121 5137 if (m_oscQueue && m_oscQueue->isOK()) {
ivand_qmul@121 5138 aboutText += tr("<p>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
ivand_qmul@121 5139 }
ivand_qmul@121 5140 #endif
lbajardsilogic@201 5141
lbajardsilogic@201 5142 aboutText += tr("<br>DIGITAL SIGNAL PROCESSING TOOLS (v%1) &copy; (1999) Laurent de Soras").arg(DSPT_VERSION);
lbajardsilogic@201 5143
ivand_qmul@121 5144 aboutText += "</p>";
ivand_qmul@121 5145 //#endif
ivand_qmul@121 5146
lbajardsilogic@40 5147 aboutText +=
lbajardsilogic@40 5148 tr("<p>This program is free software; you can redistribute it and/or<br>"
lbajardsilogic@40 5149 "modify it under the terms of the GNU General Public License as<br>"
lbajardsilogic@40 5150 "published by the Free Software Foundation; either version 2 of the<br>"
lbajardsilogic@40 5151 "License, or (at your option) any later version.<br>See the file "
lbajardsilogic@40 5152 "COPYING included with this distribution for more information.</p>");
lbajardsilogic@40 5153
ivand_qmul@121 5154 QMessageBox::about(this, tr("About Sound Access"), aboutText);
ivand_qmul@121 5155 }
ivand_qmul@121 5156
lbajardsilogic@10 5157 void MainWindow::connectionSettings()
lbajardsilogic@10 5158 {
lbajardsilogic@10 5159 ConnectionSettings* connection = new ConnectionSettings(m_httpClient);
ivand_qmul@121 5160 }
ivand_qmul@121 5161
lbajardsilogic@2 5162 void MainWindow::styleSetting()
lbajardsilogic@2 5163 {
lbajardsilogic@2 5164 m_gallery.show();
lbajardsilogic@10 5165 }
lbajardsilogic@10 5166
lbajardsilogic@10 5167 bool MainWindow::saveConfigFile()
lbajardsilogic@10 5168 {
lbajardsilogic@10 5169 QString s;
lbajardsilogic@10 5170
lbajardsilogic@10 5171 s += QString("<config>\n");
lbajardsilogic@10 5172
lbajardsilogic@10 5173 s += m_httpClient->toXmlString("\t");
lbajardsilogic@10 5174
lbajardsilogic@10 5175 s += QString("</config>\n");
lbajardsilogic@10 5176
lbajardsilogic@10 5177 QString filePath = TempDirectory::getInstance()->getConfigPath();
lbajardsilogic@10 5178
lbajardsilogic@10 5179 QFile *file = new QFile(filePath);
lbajardsilogic@10 5180
lbajardsilogic@10 5181 if (!file->open(QIODevice::WriteOnly))
lbajardsilogic@10 5182 return false;
lbajardsilogic@10 5183
lbajardsilogic@10 5184 QTextStream config(file);
lbajardsilogic@10 5185
lbajardsilogic@10 5186 config << s;
lbajardsilogic@10 5187
lbajardsilogic@10 5188 file->close();
lbajardsilogic@10 5189
lbajardsilogic@10 5190 return true;
lbajardsilogic@10 5191 }
lbajardsilogic@10 5192
lbajardsilogic@10 5193 void MainWindow::exit()
lbajardsilogic@10 5194 {
lbajardsilogic@10 5195 closeSession();
lbajardsilogic@10 5196 saveConfigFile();
lbajardsilogic@10 5197 close();
lbajardsilogic@21 5198 }
lbajardsilogic@21 5199
benoitrigolleau@133 5200
lbajardsilogic@21 5201 QueryResultsWidget * MainWindow::getQueryResultsWidget()
lbajardsilogic@21 5202 {
lbajardsilogic@21 5203 return m_resultsWidget;
lbajardsilogic@21 5204 }
lbajardsilogic@21 5205
lbajardsilogic@143 5206 RelatedMediaWidget *MainWindow::getRelatedMediaWidget()
lbajardsilogic@143 5207 {
lbajardsilogic@143 5208 return m_relMediaWidget;
lbajardsilogic@143 5209 }
lbajardsilogic@143 5210
lbajardsilogic@21 5211 void MainWindow::newEasaierSession()
lbajardsilogic@21 5212 {
lbajardsilogic@21 5213 if (!checkSaveModified()) return;
lbajardsilogic@21 5214
lbajardsilogic@21 5215 closeSession();
lbajardsilogic@21 5216 createDocument();
benoitrigolleau@66 5217 createMultiPaneLayerContainer();
lbajardsilogic@21 5218 Pane *pane = m_paneStack->addPane();
lbajardsilogic@21 5219
lbajardsilogic@21 5220 if (!m_timeRulerLayer) {
lbajardsilogic@21 5221 m_timeRulerLayer = m_document->createMainModelLayer
lbajardsilogic@21 5222 (LayerFactory::TimeRuler);
lbajardsilogic@21 5223 }
lbajardsilogic@21 5224
lbajardsilogic@21 5225 m_document->addLayerToView(pane, m_timeRulerLayer);
lbajardsilogic@21 5226
lbajardsilogic@21 5227 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
lbajardsilogic@21 5228 m_document->addLayerToView(pane, waveform);
lbajardsilogic@21 5229
lbajardsilogic@21 5230 m_overview->registerView(pane);
lbajardsilogic@21 5231
lbajardsilogic@21 5232 m_EasaierManager->newSession();
lbajardsilogic@21 5233
lbajardsilogic@21 5234 CommandHistory::getInstance()->clear();
lbajardsilogic@21 5235 CommandHistory::getInstance()->documentSaved();
lbajardsilogic@21 5236 documentRestored();
lbajardsilogic@21 5237 updateMenuStates();
lbajardsilogic@21 5238
lbajardsilogic@69 5239 m_qtabwidget->setCurrentIndex(Search);
lbajardsilogic@202 5240
lbajardsilogic@202 5241 setupFiltersMenu();
benoitrigolleau@66 5242
lbajardsilogic@21 5243 }
lbajardsilogic@21 5244
lbajardsilogic@21 5245 void MainWindow::openEasaierSession()
lbajardsilogic@21 5246 {
lbajardsilogic@21 5247 if (!checkSaveModified()) return;
lbajardsilogic@21 5248
lbajardsilogic@21 5249 QString orig = m_audioFile;
lbajardsilogic@21 5250 if (orig == "") orig = ".";
lbajardsilogic@21 5251 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
lbajardsilogic@21 5252
lbajardsilogic@21 5253 QString path = QFileDialog::getOpenFileName
lbajardsilogic@21 5254 (this, tr("Select a session file"), orig,
lbajardsilogic@21 5255 tr("Sound Access session files (*.xml)\nAll files (*.*)"));
lbajardsilogic@21 5256
lbajardsilogic@21 5257 if (path.isEmpty()) return;
lbajardsilogic@21 5258
lbajardsilogic@21 5259 if (!(QFileInfo(path).exists() &&
lbajardsilogic@21 5260 QFileInfo(path).isFile() &&
lbajardsilogic@21 5261 QFileInfo(path).isReadable())) {
lbajardsilogic@21 5262 QMessageBox::critical(this, tr("Failed to open file"),
lbajardsilogic@21 5263 tr("File \"%1\" does not exist or is not a readable file").arg(path));
lbajardsilogic@21 5264 return;
lbajardsilogic@21 5265 }
lbajardsilogic@21 5266
lbajardsilogic@21 5267 if (!openEasaierSessionFile(path)) {
lbajardsilogic@21 5268 QMessageBox::critical(this, tr("Failed to open file"),
lbajardsilogic@21 5269 tr("Session file \"%1\" could not be opened").arg(path));
lbajardsilogic@21 5270 }
lbajardsilogic@21 5271 }
lbajardsilogic@21 5272
lbajardsilogic@21 5273 bool MainWindow::openEasaierSessionFile(QString path)
lbajardsilogic@21 5274 {
lbajardsilogic@21 5275 QFile file(path);
lbajardsilogic@21 5276 if (!file.open(QIODevice::ReadOnly)) {
lbajardsilogic@21 5277 std::cerr << "Failed to open session file \"" << path.toStdString()
lbajardsilogic@21 5278 << "\": " << file.errorString().toStdString() << std::endl;
lbajardsilogic@21 5279 return false;
lbajardsilogic@21 5280 }
lbajardsilogic@21 5281
lbajardsilogic@21 5282 QString error;
lbajardsilogic@21 5283 closeSession();
lbajardsilogic@21 5284 createDocument();
benoitrigolleau@66 5285 createMultiPaneLayerContainer();
lbajardsilogic@21 5286 PaneCallback callback(this);
lbajardsilogic@21 5287 m_viewManager->clearSelections();
lbajardsilogic@203 5288 setupFiltersMenu();
lbajardsilogic@21 5289
lbajardsilogic@21 5290 ESFileReader reader(m_document, callback);
lbajardsilogic@21 5291 QXmlInputSource inputSource(&file);
lbajardsilogic@21 5292 reader.parse(inputSource);
lbajardsilogic@21 5293
lbajardsilogic@21 5294 if (!reader.isOK()) {
lbajardsilogic@21 5295 error = tr("Easaier XML file read error:\n%1").arg(reader.getErrorString());
lbajardsilogic@21 5296 }
lbajardsilogic@21 5297
lbajardsilogic@21 5298 file.close();
lbajardsilogic@21 5299
lbajardsilogic@21 5300 bool ok = (error == "");
lbajardsilogic@21 5301
lbajardsilogic@21 5302 if (ok) {
lbajardsilogic@21 5303 setWindowTitle(tr("Sound Access: %1")
lbajardsilogic@21 5304 .arg(QFileInfo(path).fileName()));
lbajardsilogic@21 5305 m_sessionFile = path;
lbajardsilogic@21 5306 setupMenus();
lbajardsilogic@21 5307 CommandHistory::getInstance()->clear();
lbajardsilogic@21 5308 CommandHistory::getInstance()->documentSaved();
lbajardsilogic@21 5309 m_documentModified = false;
lbajardsilogic@21 5310 updateMenuStates();
lbajardsilogic@21 5311 } else {
lbajardsilogic@21 5312 setWindowTitle(tr("Sound Access"));
lbajardsilogic@21 5313 }
lbajardsilogic@21 5314
lbajardsilogic@21 5315 m_EasaierManager->openSession(m_document);
lbajardsilogic@21 5316
lbajardsilogic@21 5317 return ok;
lbajardsilogic@21 5318 }
lbajardsilogic@21 5319
lbajardsilogic@21 5320 void MainWindow::saveEasaierSession()
lbajardsilogic@21 5321 {
lbajardsilogic@21 5322 if (m_sessionFile != "") {
lbajardsilogic@21 5323 if (!saveEasaierSessionFile(m_sessionFile)) {
lbajardsilogic@21 5324 QMessageBox::critical(this, tr("Failed to save file"),
lbajardsilogic@21 5325 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
lbajardsilogic@21 5326 } else {
lbajardsilogic@21 5327 CommandHistory::getInstance()->documentSaved();
lbajardsilogic@21 5328 documentRestored();
lbajardsilogic@21 5329 }
lbajardsilogic@21 5330 } else {
lbajardsilogic@21 5331 saveEasaierSessionAs();
lbajardsilogic@21 5332 }
lbajardsilogic@21 5333 }
lbajardsilogic@21 5334
lbajardsilogic@21 5335 void
lbajardsilogic@21 5336 MainWindow::saveEasaierSessionAs()
lbajardsilogic@21 5337 {
lbajardsilogic@21 5338 QString orig = m_audioFile;
lbajardsilogic@21 5339 if (orig == "") orig = ".";
lbajardsilogic@21 5340 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
lbajardsilogic@21 5341
lbajardsilogic@21 5342 QString path;
lbajardsilogic@21 5343 bool good = false;
lbajardsilogic@21 5344
lbajardsilogic@21 5345 while (!good) {
lbajardsilogic@21 5346
lbajardsilogic@21 5347 path = QFileDialog::getSaveFileName
lbajardsilogic@21 5348 (this, tr("Select a file to save to"), orig,
lbajardsilogic@21 5349 tr("Sound Access session files (*.xml)\nAll files (*.*)"), 0,
lbajardsilogic@21 5350 QFileDialog::DontConfirmOverwrite); // we'll do that
lbajardsilogic@21 5351
lbajardsilogic@21 5352 if (path.isEmpty()) return;
lbajardsilogic@21 5353
lbajardsilogic@21 5354 if (!path.endsWith(".xml")) path = path + ".xml";
lbajardsilogic@21 5355
lbajardsilogic@21 5356 QFileInfo fi(path);
lbajardsilogic@21 5357
lbajardsilogic@21 5358 if (fi.isDir()) {
lbajardsilogic@21 5359 QMessageBox::critical(this, tr("Directory selected"),
lbajardsilogic@21 5360 tr("File \"%1\" is a directory").arg(path));
lbajardsilogic@21 5361 continue;
lbajardsilogic@21 5362 }
lbajardsilogic@21 5363
lbajardsilogic@21 5364 if (fi.exists()) {
lbajardsilogic@21 5365 if (QMessageBox::question(this, tr("File exists"),
lbajardsilogic@21 5366 tr("The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path),
lbajardsilogic@21 5367 QMessageBox::Ok,
lbajardsilogic@21 5368 QMessageBox::Cancel) == QMessageBox::Ok) {
lbajardsilogic@21 5369 good = true;
lbajardsilogic@21 5370 } else {
lbajardsilogic@21 5371 continue;
lbajardsilogic@21 5372 }
lbajardsilogic@21 5373 }
lbajardsilogic@21 5374
lbajardsilogic@21 5375 good = true;
lbajardsilogic@21 5376 }
lbajardsilogic@21 5377
lbajardsilogic@21 5378 if (!saveEasaierSessionFile(path)) {
lbajardsilogic@21 5379 QMessageBox::critical(this, tr("Failed to save file"),
lbajardsilogic@21 5380 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
lbajardsilogic@21 5381 } else {
lbajardsilogic@21 5382 setWindowTitle(tr("Sound Access: %1")
lbajardsilogic@21 5383 .arg(QFileInfo(path).fileName()));
lbajardsilogic@21 5384 m_sessionFile = path;
lbajardsilogic@21 5385 CommandHistory::getInstance()->documentSaved();
lbajardsilogic@21 5386 documentRestored();
lbajardsilogic@21 5387 }
lbajardsilogic@21 5388 }
lbajardsilogic@21 5389
lbajardsilogic@21 5390 bool MainWindow::saveEasaierSessionFile(QString path)
lbajardsilogic@21 5391 {
lbajardsilogic@21 5392 QFile file(path);
lbajardsilogic@21 5393
lbajardsilogic@21 5394 if (!file.open(QIODevice::WriteOnly)) {
lbajardsilogic@21 5395 std::cerr << "Failed to open session file \"" << path.toStdString()
lbajardsilogic@21 5396 << "\" for writing: "
lbajardsilogic@21 5397 << file.errorString().toStdString() << std::endl;
lbajardsilogic@21 5398 return false;
lbajardsilogic@21 5399 }
lbajardsilogic@21 5400
lbajardsilogic@21 5401 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
lbajardsilogic@21 5402
ivand_qmul@121 5403 QTextStream out(&file);
ivand_qmul@121 5404 toEasaierXml(out);
lbajardsilogic@21 5405 out.flush();
lbajardsilogic@21 5406
lbajardsilogic@21 5407 QApplication::restoreOverrideCursor();
lbajardsilogic@21 5408
lbajardsilogic@21 5409 if (file.error()) {
lbajardsilogic@21 5410 QMessageBox::critical(this, tr("Failed to write file"),
lbajardsilogic@21 5411 tr("Failed to write to file \"%1\": %2")
lbajardsilogic@21 5412 .arg(path).arg(file.errorString()));
lbajardsilogic@21 5413 file.close();
lbajardsilogic@21 5414 return false;
lbajardsilogic@21 5415 }
lbajardsilogic@21 5416
lbajardsilogic@21 5417 file.close();
lbajardsilogic@21 5418 return true;
lbajardsilogic@21 5419 }
lbajardsilogic@21 5420
lbajardsilogic@21 5421 void MainWindow::importEasaierLayer(const QString& filename)
lbajardsilogic@21 5422 {
lbajardsilogic@21 5423 Pane *pane = m_paneStack->getCurrentPane();
lbajardsilogic@21 5424 m_EasaierManager->importMetadata(filename, pane);
lbajardsilogic@21 5425 }
lbajardsilogic@21 5426
lbajardsilogic@143 5427 void MainWindow::runExternProcess(const QString& filename)
lbajardsilogic@143 5428 {
lbajardsilogic@143 5429 int pos = filename.lastIndexOf('/');
lbajardsilogic@143 5430 QString dir = filename.left(pos);
lbajardsilogic@143 5431 QString name = filename.right(filename.length() - (pos + 1));
lbajardsilogic@194 5432 #ifdef _WIN32
lbajardsilogic@143 5433 QString program = "cmd /c start " + name;
lbajardsilogic@194 5434 #else
lbajardsilogic@194 5435 QString program;
lbajardsilogic@194 5436 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
lbajardsilogic@194 5437 program = "kfmclient exec " + name;
lbajardsilogic@194 5438 } else if (!qgetenv("BROWSER").isEmpty()) {
lbajardsilogic@194 5439 program = qgetenv("BROWSER") + " " + name;
lbajardsilogic@194 5440 } else
lbajardsilogic@194 5441 {
lbajardsilogic@194 5442 program = "gnome-open " + name;
lbajardsilogic@194 5443 }
lbajardsilogic@194 5444 #endif
lbajardsilogic@143 5445 QProcess *openFile = new QProcess(this);
lbajardsilogic@143 5446 openFile->setWorkingDirectory(dir);
lbajardsilogic@143 5447 openFile->start(program);
lbajardsilogic@143 5448 }
lbajardsilogic@143 5449
lbajardsilogic@21 5450 void MainWindow::importEasaierFile(const QString& filename)
lbajardsilogic@21 5451 {
lbajardsilogic@214 5452 if (!m_curSender)
lbajardsilogic@214 5453 {
lbajardsilogic@214 5454 m_curSender = sender();
lbajardsilogic@214 5455 m_curSender->blockSignals(true);
lbajardsilogic@214 5456 }
lbajardsilogic@214 5457
lbajardsilogic@176 5458 /*****remove all panes****/
lbajardsilogic@176 5459 while (m_paneStack->getPaneCount() > 0) {
lbajardsilogic@176 5460
lbajardsilogic@176 5461 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
lbajardsilogic@176 5462
lbajardsilogic@176 5463 while (pane->getLayerCount() > 0) {
lbajardsilogic@176 5464 m_document->removeLayerFromView
lbajardsilogic@176 5465 (pane, pane->getLayer(pane->getLayerCount() - 1));
lbajardsilogic@21 5466 }
lbajardsilogic@176 5467
lbajardsilogic@176 5468 m_overview->unregisterView(pane);
lbajardsilogic@176 5469 m_paneStack->deletePane(pane);
lbajardsilogic@21 5470 }
lbajardsilogic@21 5471
lbajardsilogic@176 5472 while (m_paneStack->getHiddenPaneCount() > 0) {
lbajardsilogic@176 5473
lbajardsilogic@176 5474 Pane *pane = m_paneStack->getHiddenPane
lbajardsilogic@176 5475 (m_paneStack->getHiddenPaneCount() - 1);
lbajardsilogic@176 5476
lbajardsilogic@176 5477 while (pane->getLayerCount() > 0) {
lbajardsilogic@176 5478 m_document->removeLayerFromView
lbajardsilogic@176 5479 (pane, pane->getLayer(pane->getLayerCount() - 1));
lbajardsilogic@176 5480 }
lbajardsilogic@176 5481
lbajardsilogic@176 5482 m_overview->unregisterView(pane);
lbajardsilogic@176 5483 m_paneStack->deletePane(pane);
lbajardsilogic@176 5484 }
lbajardsilogic@176 5485 /*********/
lbajardsilogic@176 5486
lbajardsilogic@175 5487 m_document->reset();
lbajardsilogic@21 5488
lbajardsilogic@176 5489 Pane *pane = m_paneStack->addPane();
lbajardsilogic@176 5490
lbajardsilogic@176 5491 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
lbajardsilogic@176 5492 this, SLOT(contextHelpChanged(const QString &)));
lbajardsilogic@21 5493
lbajardsilogic@21 5494 if (!m_timeRulerLayer) {
lbajardsilogic@21 5495 m_timeRulerLayer = m_document->createMainModelLayer(LayerFactory::TimeRuler);
lbajardsilogic@21 5496 }
lbajardsilogic@21 5497
lbajardsilogic@21 5498 m_document->addLayerToView(pane, m_timeRulerLayer);
lbajardsilogic@21 5499
lbajardsilogic@21 5500 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
lbajardsilogic@21 5501 m_document->addLayerToView(pane, waveform);
lbajardsilogic@21 5502
lbajardsilogic@208 5503 m_overview->registerView(pane);
lbajardsilogic@208 5504
lbajardsilogic@21 5505 m_document->setAudioSourceInfoFileName(filename);
lbajardsilogic@21 5506 m_EasaierManager->openAudioInfoFile(m_document);
lbajardsilogic@21 5507 }
lbajardsilogic@21 5508
lbajardsilogic@21 5509 void MainWindow::queryModelLoaded(QueryModel* queryModel)
lbajardsilogic@21 5510 {
lbajardsilogic@21 5511 if (m_searchWidget)
lbajardsilogic@21 5512 m_searchWidget->displayQuerymodel(queryModel);
lbajardsilogic@21 5513 }
lbajardsilogic@21 5514
lbajardsilogic@21 5515 void MainWindow::audioSourceInfoAdded(AudioSourceInfoModel * info)
lbajardsilogic@21 5516 {
lbajardsilogic@21 5517 if (m_infoWidget)
lbajardsilogic@143 5518 {
lbajardsilogic@21 5519 m_infoWidget->displayAudioSourceInfo(info);
lbajardsilogic@143 5520 m_relMediaWidget->reset();
lbajardsilogic@143 5521 }
lbajardsilogic@21 5522
lbajardsilogic@21 5523 m_qtabwidget->setCurrentIndex(Info);
lbajardsilogic@21 5524 }
lbajardsilogic@21 5525
lbajardsilogic@21 5526 void MainWindow::queryDatabase()
lbajardsilogic@21 5527 {
lbajardsilogic@21 5528 QString themeName = sender()->objectName();
benoitrigolleau@88 5529 m_EasaierManager->queryDatabase(themeName);
benoitrigolleau@88 5530 m_qtabwidget->setCurrentIndex(Result);
lbajardsilogic@21 5531
benoitrigolleau@66 5532 }
benoitrigolleau@66 5533
benoitrigolleau@66 5534 void MainWindow::createMultiPaneLayerContainer(){
ivand_qmul@121 5535 m_multiPaneLayerContainer = new MultiPaneLayerContainer;
ivand_qmul@121 5536 connect(m_paneStack, SIGNAL(newPaneAdded(Pane*)),m_multiPaneLayerContainer,SLOT(paneAdded(Pane*)));
ivand_qmul@121 5537 connect(m_paneStack, SIGNAL(paneDeleted(Pane*)),m_multiPaneLayerContainer,SLOT(paneRemoved(Pane*)));
ivand_qmul@121 5538 connect(m_multiPaneLayerContainer, SIGNAL(removeSelectedItem()), this, SLOT(deleteCurrentLayer()));
lbajardsilogic@206 5539 connect(m_multiPaneLayerContainer, SIGNAL(contextHelpChanged(const QString &)), this, SLOT(contextHelpChanged(const QString &)));
ivand_qmul@121 5540 connect(this, SIGNAL(newCurrentPane(Pane*)), m_multiPaneLayerContainer, SLOT(currentPaneChanged(Pane*)));
lbajardsilogic@96 5541 connect(m_multiPaneLayerContainer, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
lbajardsilogic@96 5542 m_paneStack, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
benoitrigolleau@66 5543 m_toolBox->insertItem(0,"Layers", m_multiPaneLayerContainer);
lbajardsilogic@79 5544 }
lbajardsilogic@79 5545
lbajardsilogic@79 5546 void MainWindow::setupFiltersMenu()
lbajardsilogic@79 5547 {
ivand_qmul@121 5548 RealTimeFilterFactory::FilterTypeSet filterTypes = RealTimeFilterFactory::getInstance()->getFilterTypes();
ivand_qmul@121 5549 RealTimeFilterFactory::FilterTypeSet::iterator iter;
ivand_qmul@121 5550
ivand_qmul@121 5551 for (iter = filterTypes.begin(); iter != filterTypes.end(); iter++) {
lbajardsilogic@202 5552 QString filterType = RealTimeFilterFactory::getInstance()->getFilterLabel(*iter);
lbajardsilogic@202 5553 Filter* filter = m_document->createFilter(RealTimeFilterFactory::getInstance()->getFilterType(filterType));
lbajardsilogic@79 5554 }
lbajardsilogic@79 5555
ivand_qmul@121 5556 connect(m_filterPropertyStack, SIGNAL(removeFilter(QString)), this, SLOT(removeFilter(QString)));
lbajardsilogic@79 5557
lbajardsilogic@79 5558 }
lbajardsilogic@79 5559
lbajardsilogic@79 5560 void MainWindow::removeFilter(QString name)
lbajardsilogic@79 5561 {
lbajardsilogic@79 5562 if (m_document)
lbajardsilogic@79 5563 m_document->removeFilter(name);
benoitrigolleau@133 5564 }
benoitrigolleau@133 5565
benoitrigolleau@145 5566 SDLWidget* MainWindow::getSDLWidget(){
benoitrigolleau@145 5567 return m_sdlWidget;
benoitrigolleau@145 5568 }
benoitrigolleau@145 5569
benoitrigolleau@145 5570 void MainWindow::setSDLInitSize(int w, int h){
benoitrigolleau@145 5571 m_sdlWidget->setInitSize(w,h);
lbajardsilogic@214 5572 }
lbajardsilogic@214 5573 void MainWindow::audioFileLoaded()
lbajardsilogic@214 5574 {
lbajardsilogic@214 5575 if (m_curSender)
lbajardsilogic@214 5576 {
lbajardsilogic@214 5577 m_curSender->blockSignals(false);
lbajardsilogic@214 5578 }
lbajardsilogic@214 5579 m_curSender = 0;
lbajardsilogic@214 5580 }
lbajardsilogic@214 5581