annotate main/main.cpp @ 578:31940304272f with-dependencies

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