annotate sv/main/MainWindow.cpp @ 203:74d1b3bda5a3

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