annotate main/main.cpp @ 590:7a6fd7150f2d with-dependencies

Line endings
author Chris Cannam
date Tue, 23 Jul 2013 16:12:08 +0100
parents 31940304272f
children c06a9e8e2748
rev   line source
Chris@590 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@590 2
Chris@590 3 /*
Chris@590 4 Sonic Visualiser
Chris@590 5 An audio file viewer and annotation editor.
Chris@590 6 Centre for Digital Music, Queen Mary, University of London.
Chris@590 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@590 8
Chris@590 9 This program is free software; you can redistribute it and/or
Chris@590 10 modify it under the terms of the GNU General Public License as
Chris@590 11 published by the Free Software Foundation; either version 2 of the
Chris@590 12 License, or (at your option) any later version. See the file
Chris@590 13 COPYING included with this distribution for more information.
Chris@590 14 */
Chris@590 15
Chris@590 16 #include "MainWindow.h"
Chris@590 17
Chris@590 18 #include "system/System.h"
Chris@590 19 #include "system/Init.h"
Chris@590 20 #include "base/TempDirectory.h"
Chris@590 21 #include "base/PropertyContainer.h"
Chris@590 22 #include "base/Preferences.h"
Chris@590 23 #include "widgets/TipDialog.h"
Chris@590 24 #include "transform/TransformFactory.h"
Chris@590 25
Chris@590 26 #include <QMetaType>
Chris@590 27 #include <QApplication>
Chris@590 28 #include <QDesktopWidget>
Chris@590 29 #include <QMessageBox>
Chris@590 30 #include <QTranslator>
Chris@590 31 #include <QLocale>
Chris@590 32 #include <QSettings>
Chris@590 33 #include <QIcon>
Chris@590 34 #include <QSessionManager>
Chris@590 35 #include <QDir>
Chris@590 36 #include <QSplashScreen>
Chris@590 37 #include <QTimer>
Chris@590 38 #include <QPainter>
Chris@590 39 #include <QFileOpenEvent>
Chris@590 40
Chris@590 41 #include "../version.h"
Chris@590 42
Chris@590 43 #include <iostream>
Chris@590 44 #include <signal.h>
Chris@590 45
Chris@590 46 #ifdef HAVE_FFTW3F
Chris@590 47 #include <fftw3.h>
Chris@590 48 #endif
Chris@590 49
Chris@590 50 /*! \mainpage Sonic Visualiser
Chris@590 51
Chris@590 52 \section interesting Summary of interesting classes
Chris@590 53
Chris@590 54 - Data models: Model and subclasses, e.g. WaveFileModel
Chris@590 55
Chris@590 56 - Graphical layers: Layer and subclasses, displayed on View and its
Chris@590 57 subclass widgets.
Chris@590 58
Chris@590 59 - Main window class, document class, and file parser: MainWindow,
Chris@590 60 Document, SVFileReader
Chris@590 61
Chris@590 62 - Turning one model (e.g. audio) into another (e.g. more audio, or a
Chris@590 63 curve extracted from it): Transform, encapsulating the data that need
Chris@590 64 to be stored to be able to reproduce a given transformation;
Chris@590 65 TransformFactory, for discovering the available types of transform;
Chris@590 66 ModelTransformerFactory, ModelTransformer and subclasses, providing
Chris@590 67 the mechanisms for applying transforms to data models
Chris@590 68
Chris@590 69 - Creating the plugins used by transforms: RealTimePluginFactory,
Chris@590 70 FeatureExtractionPluginFactory. See also the API documentation for
Chris@590 71 Vamp feature extraction plugins at
Chris@590 72 http://www.vamp-plugins.org/code-doc/.
Chris@590 73
Chris@590 74 - File reading and writing code: AudioFileReader and subclasses,
Chris@590 75 WavFileWriter, DataFileReader, SVFileReader
Chris@590 76
Chris@590 77 - FFT calculation and cacheing: FFTModel, FFTDataServer
Chris@590 78
Chris@590 79 - Widgets that show groups of editable properties: PropertyBox for
Chris@590 80 layer properties (contained in a PropertyStack), PluginParameterBox
Chris@590 81 for plugins (contained in a PluginParameterDialog)
Chris@590 82
Chris@590 83 - Audio playback: AudioCallbackPlaySource and subclasses,
Chris@590 84 AudioCallbackPlayTarget and subclasses, AudioGenerator
Chris@590 85
Chris@590 86 \section model Data sources: the Model hierarchy
Chris@590 87
Chris@590 88 A Model is something containing, or knowing how to obtain, data.
Chris@590 89
Chris@590 90 For example, WaveFileModel is a model that knows how to get data
Chris@590 91 from an audio file; SparseTimeValueModel is a model containing
Chris@590 92 editable "curve" data.
Chris@590 93
Chris@590 94 Models typically subclass one of a number of abstract subclasses of
Chris@590 95 Model. For example, WaveFileModel subclasses DenseTimeValueModel,
Chris@590 96 which describes an interface for models that have a value at each
Chris@590 97 time point for a given sampling resolution. (Note that
Chris@590 98 WaveFileModel does not actually read the files itself: it uses
Chris@590 99 AudioFileReader classes for that. It just makes data from the
Chris@590 100 files available in a Model.) SparseTimeValueModel uses the
Chris@590 101 SparseModel template class, which provides most of the
Chris@590 102 implementation for models that contain a series of points of some
Chris@590 103 sort -- also used by NoteModel, TextModel, and
Chris@590 104 SparseOneDimensionalModel.
Chris@590 105
Chris@590 106 Everything that goes on the screen originates from a model, via a
Chris@590 107 layer (see below). The models are contained in a Document object.
Chris@590 108 There is no containment hierarchy or ordering of models in the
Chris@590 109 document. One model is the main model, which defines the sample
Chris@590 110 rate for playback.
Chris@590 111
Chris@590 112 A model may also be marked as a "derived" model, which means it was
Chris@590 113 generated from another model using some transform (feature
Chris@590 114 extraction or effect plugin, etc) -- the idea being that they can
Chris@590 115 be re-generated using the same transform if a new source model is
Chris@590 116 loaded.
Chris@590 117
Chris@590 118 \section layer Things that can display data: the Layer hierarchy
Chris@590 119
Chris@590 120 A Layer is something that knows how to draw parts of a model onto a
Chris@590 121 timeline.
Chris@590 122
Chris@590 123 For example, WaveformLayer is a layer which draws waveforms, based
Chris@590 124 on WaveFileModel; TimeValueLayer draws curves, based on
Chris@590 125 SparseTimeValueModel; SpectrogramLayer draws spectrograms, based on
Chris@590 126 WaveFileModel (via FFTModel).
Chris@590 127
Chris@590 128 The most basic functions of a layer are: to draw itself onto a
Chris@590 129 Pane, against a timeline on the x axis; and to permit user
Chris@590 130 interaction. If you were thinking of adding the capability to
Chris@590 131 display a new sort of something, then you would want to add a new
Chris@590 132 layer type. (You may also need a new model type, depending on
Chris@590 133 whether any existing model can capture the data you need.)
Chris@590 134 Depending on the sort of data in question, there are various
Chris@590 135 existing layers that might be appropriate to start from -- for
Chris@590 136 example, a layer that displays images that the user has imported
Chris@590 137 and associated with particular times might have something in common
Chris@590 138 with the existing TextLayer which displays pieces of text that are
Chris@590 139 associated with particular times.
Chris@590 140
Chris@590 141 Although layers are visual objects, they are contained in the
Chris@590 142 Document in Sonic Visualiser rather than being managed together
Chris@590 143 with display widgets. The Sonic Visualiser file format has
Chris@590 144 separate data and layout sections, and the layers are defined in
Chris@590 145 the data section and then referred to in the layout section which
Chris@590 146 determines which layers may go on which panes (see Pane below).
Chris@590 147
Chris@590 148 Once a layer class is defined, some basic data about it needs to be
Chris@590 149 set up in the LayerFactory class, and then it will appear in the
Chris@590 150 menus and so on on the main window.
Chris@590 151
Chris@590 152 \section view Widgets that are used to show layers: The View hierarchy
Chris@590 153
Chris@590 154 A View is a widget that displays a stack of layers. The most
Chris@590 155 important subclass is Pane, the widget that is used to show most of
Chris@590 156 the data in the main window of Sonic Visualiser.
Chris@590 157
Chris@590 158 All a pane really does is contain a set of layers and get them to
Chris@590 159 render themselves (one on top of the other, with the topmost layer
Chris@590 160 being the one that is currently interacted with), cache the
Chris@590 161 results, negotiate user interaction with them, and so on. This is
Chris@590 162 generally fiddly, if not especially interesting. Panes are
Chris@590 163 strictly layout objects and are not stored in the Document class;
Chris@590 164 instead the MainWindow contains a PaneStack widget (the widget that
Chris@590 165 takes up most of Sonic Visualiser's main window) which contains a
Chris@590 166 set of panes stacked vertically.
Chris@590 167
Chris@590 168 Another View subclass is Overview, which is the widget that
Chris@590 169 contains that green waveform showing the entire file at the bottom
Chris@590 170 of the window.
Chris@590 171
Chris@590 172 */
Chris@590 173
Chris@590 174 static QMutex cleanupMutex;
Chris@590 175
Chris@590 176 static void
Chris@590 177 signalHandler(int /* signal */)
Chris@590 178 {
Chris@590 179 // Avoid this happening more than once across threads
Chris@590 180
Chris@590 181 cleanupMutex.lock();
Chris@590 182 std::cerr << "signalHandler: cleaning up and exiting" << std::endl;
Chris@590 183 TempDirectory::getInstance()->cleanup();
Chris@590 184 exit(0); // without releasing mutex
Chris@590 185 }
Chris@590 186
Chris@590 187 class SVApplication : public QApplication
Chris@590 188 {
Chris@590 189 public:
Chris@590 190 SVApplication(int &argc, char **argv) :
Chris@590 191 QApplication(argc, argv),
Chris@590 192 m_readyForFiles(false),
Chris@590 193 m_filepathQueue(QStringList()),
Chris@590 194 m_mainWindow(0)
Chris@590 195 {
Chris@590 196 #ifdef Q_OS_MAC
Chris@590 197 // Override the Qt plugin load path. The default contains the
Chris@590 198 // Qt installation location as well as the application
Chris@590 199 // directory, but we don't ever want to load plugins from
Chris@590 200 // outside the app bundle because we don't know for sure what
Chris@590 201 // (potentially different) versions of the Qt framework
Chris@590 202 // libraries they may have dyld dependencies on.
Chris@590 203 QString apploc(applicationFilePath());
Chris@590 204 apploc.truncate(apploc.lastIndexOf(QLatin1Char('/')));
Chris@590 205 apploc = QDir(apploc).canonicalPath();
Chris@590 206 if (QFile::exists(apploc)) {
Chris@590 207 setLibraryPaths(QStringList() << apploc);
Chris@590 208 } else {
Chris@590 209 setLibraryPaths(QStringList());
Chris@590 210 }
Chris@590 211 #endif
Chris@590 212 }
Chris@590 213 virtual ~SVApplication() { }
Chris@590 214
Chris@590 215 void setMainWindow(MainWindow *mw) { m_mainWindow = mw; }
Chris@590 216 void releaseMainWindow() { m_mainWindow = 0; }
Chris@590 217
Chris@590 218 virtual void commitData(QSessionManager &manager) {
Chris@590 219 if (!m_mainWindow) return;
Chris@590 220 bool mayAskUser = manager.allowsInteraction();
Chris@590 221 bool success = m_mainWindow->commitData(mayAskUser);
Chris@590 222 manager.release();
Chris@590 223 if (!success) manager.cancel();
Chris@590 224 }
Chris@590 225
Chris@590 226 void handleFilepathArgument(QString path, QSplashScreen *splash);
Chris@590 227
Chris@590 228 bool m_readyForFiles;
Chris@590 229 QStringList m_filepathQueue;
Chris@590 230
Chris@590 231 protected:
Chris@590 232 MainWindow *m_mainWindow;
Chris@590 233 bool event(QEvent *);
Chris@590 234
Chris@590 235 };
Chris@590 236
Chris@590 237 int
Chris@590 238 main(int argc, char **argv)
Chris@590 239 {
Chris@590 240 svSystemSpecificInitialisation();
Chris@590 241
Chris@590 242 #ifdef Q_WS_X11
Chris@590 243 #if QT_VERSION >= 0x040500
Chris@590 244 // QApplication::setGraphicsSystem("raster");
Chris@590 245 #endif
Chris@590 246 #endif
Chris@590 247
Chris@590 248 SVApplication application(argc, argv);
Chris@590 249
Chris@590 250 QStringList args = application.arguments();
Chris@590 251
Chris@590 252 signal(SIGINT, signalHandler);
Chris@590 253 signal(SIGTERM, signalHandler);
Chris@590 254
Chris@590 255 #ifndef Q_WS_WIN32
Chris@590 256 //??? signal(SIGHUP, signalHandler);
Chris@590 257 //??? signal(SIGQUIT, signalHandler);
Chris@590 258 #endif
Chris@590 259
Chris@590 260 bool audioOutput = true;
Chris@590 261 bool oscSupport = true;
Chris@590 262
Chris@590 263 if (args.contains("--help") || args.contains("-h") || args.contains("-?")) {
Chris@590 264 std::cerr << QApplication::tr(
Chris@590 265 "\nSonic Visualiser is a program for viewing and exploring audio data\nfor semantic music analysis and annotation.\n\nUsage:\n\n %1 [--no-audio] [--no-osc] [<file> ...]\n\n --no-audio: Do not attempt to open an audio output device\n --no-osc: Do not provide an Open Sound Control port for remote control\n <file>: One or more Sonic Visualiser (.sv) and audio files may be provided.\n").arg(argv[0]) << std::endl;
Chris@590 266 exit(2);
Chris@590 267 }
Chris@590 268
Chris@590 269 if (args.contains("--no-audio")) audioOutput = false;
Chris@590 270 if (args.contains("--no-osc")) oscSupport = false;
Chris@590 271
Chris@590 272 QApplication::setOrganizationName("sonic-visualiser");
Chris@590 273 QApplication::setOrganizationDomain("sonicvisualiser.org");
Chris@590 274 QApplication::setApplicationName(QApplication::tr("Sonic Visualiser"));
Chris@590 275
Chris@590 276 QSplashScreen *splash = 0;
Chris@590 277
Chris@590 278 QSettings settings;
Chris@590 279
Chris@590 280 settings.beginGroup("Preferences");
Chris@590 281 if (settings.value("show-splash", true).toBool()) {
Chris@590 282 QPixmap pixmap(":/icons/sv-splash.png");
Chris@590 283 QPainter painter;
Chris@590 284 painter.begin(&pixmap);
Chris@590 285 QString text = QString("v%1").arg(SV_VERSION);
Chris@590 286 painter.drawText
Chris@590 287 (pixmap.width() - painter.fontMetrics().width(text) - 10,
Chris@590 288 10 + painter.fontMetrics().ascent(),
Chris@590 289 text);
Chris@590 290 painter.end();
Chris@590 291 splash = new QSplashScreen(pixmap);
Chris@590 292 splash->show();
Chris@590 293 QTimer::singleShot(5000, splash, SLOT(hide()));
Chris@590 294 application.processEvents();
Chris@590 295 }
Chris@590 296 settings.endGroup();
Chris@590 297
Chris@590 298 settings.beginGroup("RDF");
Chris@590 299 if (!settings.contains("rdf-indices")) {
Chris@590 300 QStringList list;
Chris@590 301 list << "http://www.vamp-plugins.org/rdf/plugins/index.txt";
Chris@590 302 settings.setValue("rdf-indices", list);
Chris@590 303 }
Chris@590 304 settings.endGroup();
Chris@590 305
Chris@590 306 QIcon icon;
Chris@590 307 int sizes[] = { 16, 22, 24, 32, 48, 64, 128 };
Chris@590 308 for (int i = 0; i < sizeof(sizes)/sizeof(sizes[0]); ++i) {
Chris@590 309 icon.addFile(QString(":icons/sv-%1x%2.png").arg(sizes[i]).arg(sizes[i]));
Chris@590 310 }
Chris@590 311 QApplication::setWindowIcon(icon);
Chris@590 312
Chris@590 313 QString language = QLocale::system().name();
Chris@590 314
Chris@590 315 QTranslator qtTranslator;
Chris@590 316 QString qtTrName = QString("qt_%1").arg(language);
Chris@590 317 SVDEBUG << "Loading " << qtTrName << "... ";
Chris@590 318 bool success = false;
Chris@590 319 if (!(success = qtTranslator.load(qtTrName))) {
Chris@590 320 QString qtDir = getenv("QTDIR");
Chris@590 321 if (qtDir != "") {
Chris@590 322 success = qtTranslator.load
Chris@590 323 (qtTrName, QDir(qtDir).filePath("translations"));
Chris@590 324 }
Chris@590 325 }
Chris@590 326 if (!success) {
Chris@590 327 SVDEBUG << "Failed\nFailed to load Qt translation for locale" << endl;
Chris@590 328 } else {
Chris@590 329 std::cerr << "Done" << std::endl;
Chris@590 330 }
Chris@590 331 application.installTranslator(&qtTranslator);
Chris@590 332
Chris@590 333 QTranslator svTranslator;
Chris@590 334 QString svTrName = QString("sonic-visualiser_%1").arg(language);
Chris@590 335 SVDEBUG << "Loading " << svTrName << "... ";
Chris@590 336 svTranslator.load(svTrName, ":i18n");
Chris@590 337 SVDEBUG << "Done" << endl;
Chris@590 338 application.installTranslator(&svTranslator);
Chris@590 339
Chris@590 340 StoreStartupLocale();
Chris@590 341
Chris@590 342 // Permit size_t and PropertyName to be used as args in queued signal calls
Chris@590 343 qRegisterMetaType<size_t>("size_t");
Chris@590 344 qRegisterMetaType<PropertyContainer::PropertyName>("PropertyContainer::PropertyName");
Chris@590 345
Chris@590 346 MainWindow *gui = new MainWindow(audioOutput, oscSupport);
Chris@590 347 application.setMainWindow(gui);
Chris@590 348 if (splash) {
Chris@590 349 QObject::connect(gui, SIGNAL(hideSplash()), splash, SLOT(hide()));
Chris@590 350 }
Chris@590 351
Chris@590 352 QDesktopWidget *desktop = QApplication::desktop();
Chris@590 353 QRect available = desktop->availableGeometry();
Chris@590 354
Chris@590 355 int width = (available.width() * 2) / 3;
Chris@590 356 int height = available.height() / 2;
Chris@590 357 if (height < 450) height = (available.height() * 2) / 3;
Chris@590 358 if (width > height * 2) width = height * 2;
Chris@590 359
Chris@590 360 settings.beginGroup("MainWindow");
Chris@590 361 QSize size = settings.value("size", QSize(width, height)).toSize();
Chris@590 362 gui->resizeConstrained(size);
Chris@590 363 if (settings.contains("position")) {
Chris@590 364 QRect prevrect(settings.value("position").toPoint(), size);
Chris@590 365 if (!(available & prevrect).isEmpty()) {
Chris@590 366 gui->move(prevrect.topLeft());
Chris@590 367 }
Chris@590 368 }
Chris@590 369 settings.endGroup();
Chris@590 370
Chris@590 371 gui->show();
Chris@590 372
Chris@590 373 // The MainWindow class seems to have trouble dealing with this if
Chris@590 374 // it tries to adapt to this preference before the constructor is
Chris@590 375 // complete. As a lazy hack, apply it explicitly from here
Chris@590 376 gui->preferenceChanged("Property Box Layout");
Chris@590 377
Chris@590 378 application.m_readyForFiles = true; // Ready to receive files from e.g. Apple Events
Chris@590 379
Chris@590 380 for (QStringList::iterator i = args.begin(); i != args.end(); ++i) {
Chris@590 381
Chris@590 382 if (i == args.begin()) continue;
Chris@590 383 if (i->startsWith('-')) continue;
Chris@590 384
Chris@590 385 QString path = *i;
Chris@590 386
Chris@590 387 application.handleFilepathArgument(path, splash);
Chris@590 388 }
Chris@590 389
Chris@590 390 for (QStringList::iterator i = application.m_filepathQueue.begin(); i != application.m_filepathQueue.end(); ++i) {
Chris@590 391 QString path = *i;
Chris@590 392 application.handleFilepathArgument(path, splash);
Chris@590 393 }
Chris@590 394
Chris@590 395 #ifdef HAVE_FFTW3F
Chris@590 396 settings.beginGroup("FFTWisdom");
Chris@590 397 QString wisdom = settings.value("wisdom").toString();
Chris@590 398 if (wisdom != "") {
Chris@590 399 fftwf_import_wisdom_from_string(wisdom.toLocal8Bit().data());
Chris@590 400 }
Chris@590 401 #ifdef HAVE_FFTW3
Chris@590 402 wisdom = settings.value("wisdom_d").toString();
Chris@590 403 if (wisdom != "") {
Chris@590 404 fftw_import_wisdom_from_string(wisdom.toLocal8Bit().data());
Chris@590 405 }
Chris@590 406 #endif
Chris@590 407 settings.endGroup();
Chris@590 408 #endif
Chris@590 409
Chris@590 410 if (splash) splash->finish(gui);
Chris@590 411 delete splash;
Chris@590 412
Chris@590 413 /*
Chris@590 414 TipDialog tipDialog;
Chris@590 415 if (tipDialog.isOK()) {
Chris@590 416 tipDialog.exec();
Chris@590 417 }
Chris@590 418 */
Chris@590 419 int rv = application.exec();
Chris@590 420
Chris@590 421 gui->hide();
Chris@590 422
Chris@590 423 cleanupMutex.lock();
Chris@590 424
Chris@590 425 TransformFactory::deleteInstance();
Chris@590 426 TempDirectory::getInstance()->cleanup();
Chris@590 427 application.releaseMainWindow();
Chris@590 428
Chris@590 429 #ifdef HAVE_FFTW3F
Chris@590 430 settings.beginGroup("FFTWisdom");
Chris@590 431 char *cwisdom = fftwf_export_wisdom_to_string();
Chris@590 432 if (cwisdom) {
Chris@590 433 settings.setValue("wisdom", cwisdom);
Chris@590 434 free(cwisdom);
Chris@590 435 }
Chris@590 436 #ifdef HAVE_FFTW3
Chris@590 437 cwisdom = fftw_export_wisdom_to_string();
Chris@590 438 if (cwisdom) {
Chris@590 439 settings.setValue("wisdom_d", cwisdom);
Chris@590 440 free(cwisdom);
Chris@590 441 }
Chris@590 442 #endif
Chris@590 443 settings.endGroup();
Chris@590 444 #endif
Chris@590 445
Chris@590 446 delete gui;
Chris@590 447
Chris@590 448 cleanupMutex.unlock();
Chris@590 449
Chris@590 450 return rv;
Chris@590 451 }
Chris@590 452
Chris@590 453 bool SVApplication::event(QEvent *event){
Chris@590 454 QString thePath;
Chris@590 455 switch (event->type()) {
Chris@590 456 case QEvent::FileOpen:
Chris@590 457 thePath = static_cast<QFileOpenEvent *>(event)->file();
Chris@590 458 if(m_readyForFiles)
Chris@590 459 handleFilepathArgument(thePath, NULL);
Chris@590 460 else
Chris@590 461 m_filepathQueue.append(thePath);
Chris@590 462 return true;
Chris@590 463 default:
Chris@590 464 return QApplication::event(event);
Chris@590 465 }
Chris@590 466 }
Chris@590 467
Chris@590 468 /** Application-global handler for filepaths passed in, e.g. as command-line arguments or apple events */
Chris@590 469 void SVApplication::handleFilepathArgument(QString path, QSplashScreen *splash){
Chris@590 470 static bool haveSession = false;
Chris@590 471 static bool haveMainModel = false;
Chris@590 472 static bool havePriorCommandLineModel = false;
Chris@590 473
Chris@590 474 MainWindow::FileOpenStatus status = MainWindow::FileOpenFailed;
Chris@590 475
Chris@590 476 if (path.endsWith("sv")) {
Chris@590 477 if (!haveSession) {
Chris@590 478 status = m_mainWindow->openSessionFile(path);
Chris@590 479 if (status == MainWindow::FileOpenSucceeded) {
Chris@590 480 haveSession = true;
Chris@590 481 haveMainModel = true;
Chris@590 482 }
Chris@590 483 } else {
Chris@590 484 std::cerr << "WARNING: Ignoring additional session file argument \"" << path << "\"" << std::endl;
Chris@590 485 status = MainWindow::FileOpenSucceeded;
Chris@590 486 }
Chris@590 487 }
Chris@590 488 if (status != MainWindow::FileOpenSucceeded) {
Chris@590 489 if (!haveMainModel) {
Chris@590 490 status = m_mainWindow->open(path, MainWindow::ReplaceSession);
Chris@590 491 if (status == MainWindow::FileOpenSucceeded) {
Chris@590 492 haveMainModel = true;
Chris@590 493 }
Chris@590 494 } else {
Chris@590 495 if (haveSession && !havePriorCommandLineModel) {
Chris@590 496 status = m_mainWindow->open(path, MainWindow::AskUser);
Chris@590 497 if (status == MainWindow::FileOpenSucceeded) {
Chris@590 498 havePriorCommandLineModel = true;
Chris@590 499 }
Chris@590 500 } else {
Chris@590 501 status = m_mainWindow->open(path, MainWindow::CreateAdditionalModel);
Chris@590 502 }
Chris@590 503 }
Chris@590 504 }
Chris@590 505 if (status == MainWindow::FileOpenFailed) {
Chris@590 506 if (splash) splash->hide();
Chris@590 507 QMessageBox::critical
Chris@590 508 (m_mainWindow, QMessageBox::tr("Failed to open file"),
Chris@590 509 QMessageBox::tr("File or URL \"%1\" could not be opened").arg(path));
Chris@590 510 } else if (status == MainWindow::FileOpenWrongMode) {
Chris@590 511 if (splash) splash->hide();
Chris@590 512 QMessageBox::critical
Chris@590 513 (m_mainWindow, QMessageBox::tr("Failed to open file"),
Chris@590 514 QMessageBox::tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@590 515 }
Chris@590 516 }