comparison main/main.cpp @ 246:ddbde90773b0 spectrogram-cache-rejig

* Merge from trunk
author Chris Cannam
date Wed, 27 Feb 2008 11:59:42 +0000
parents 37847fc0b381
children
comparison
equal deleted inserted replaced
214:37847fc0b381 246:ddbde90773b0
30 #include <QLocale> 30 #include <QLocale>
31 #include <QSettings> 31 #include <QSettings>
32 #include <QIcon> 32 #include <QIcon>
33 #include <QSessionManager> 33 #include <QSessionManager>
34 #include <QDir> 34 #include <QDir>
35 #include <QSplashScreen>
35 36
36 #include <iostream> 37 #include <iostream>
37 #include <signal.h> 38 #include <signal.h>
38 39
39 #ifdef HAVE_FFTW3F 40 #ifdef HAVE_FFTW3F
51 52
52 - Main window class, document class, and file parser: MainWindow, 53 - Main window class, document class, and file parser: MainWindow,
53 Document, SVFileReader 54 Document, SVFileReader
54 55
55 - Turning one model (e.g. audio) into another (e.g. more audio, or a 56 - Turning one model (e.g. audio) into another (e.g. more audio, or a
56 curve extracted from it): Transform and subclasses 57 curve extracted from it): Transform, encapsulating the data that need
58 to be stored to be able to reproduce a given transformation;
59 TransformFactory, for discovering the available types of transform;
60 ModelTransformerFactory, ModelTransformer and subclasses, providing
61 the mechanisms for applying transforms to data models
57 62
58 - Creating the plugins used by transforms: RealTimePluginFactory, 63 - Creating the plugins used by transforms: RealTimePluginFactory,
59 FeatureExtractionPluginFactory. See also the API documentation for 64 FeatureExtractionPluginFactory. See also the API documentation for
60 Vamp feature extraction plugins at 65 Vamp feature extraction plugins at
61 http://www.vamp-plugins.org/code-doc/. 66 http://www.vamp-plugins.org/code-doc/.
227 232
228 QApplication::setOrganizationName("sonic-visualiser"); 233 QApplication::setOrganizationName("sonic-visualiser");
229 QApplication::setOrganizationDomain("sonicvisualiser.org"); 234 QApplication::setOrganizationDomain("sonicvisualiser.org");
230 QApplication::setApplicationName(QApplication::tr("Sonic Visualiser")); 235 QApplication::setApplicationName(QApplication::tr("Sonic Visualiser"));
231 236
237 QPixmap pixmap(":/icons/sv-splash.png");
238 QSplashScreen splash(pixmap);
239
240 QSettings settings;
241
242 settings.beginGroup("Preferences");
243 if (settings.value("show-splash", true).toBool()) {
244 splash.show();
245 application.processEvents();
246 }
247 settings.endGroup();
248
232 QIcon icon; 249 QIcon icon;
233 int sizes[] = { 16, 22, 24, 32, 48, 64, 128 }; 250 int sizes[] = { 16, 22, 24, 32, 48, 64, 128 };
234 for (int i = 0; i < sizeof(sizes)/sizeof(sizes[0]); ++i) { 251 for (int i = 0; i < sizeof(sizes)/sizeof(sizes[0]); ++i) {
235 icon.addFile(QString(":icons/sv-%1x%2.png").arg(sizes[i]).arg(sizes[i])); 252 icon.addFile(QString(":icons/sv-%1x%2.png").arg(sizes[i]).arg(sizes[i]));
236 } 253 }
264 281
265 // Permit size_t and PropertyName to be used as args in queued signal calls 282 // Permit size_t and PropertyName to be used as args in queued signal calls
266 qRegisterMetaType<size_t>("size_t"); 283 qRegisterMetaType<size_t>("size_t");
267 qRegisterMetaType<PropertyContainer::PropertyName>("PropertyContainer::PropertyName"); 284 qRegisterMetaType<PropertyContainer::PropertyName>("PropertyContainer::PropertyName");
268 285
269 MainWindow gui(audioOutput, oscSupport); 286 MainWindow *gui = new MainWindow(audioOutput, oscSupport);
270 application.setMainWindow(&gui); 287 application.setMainWindow(gui);
271 288
272 QDesktopWidget *desktop = QApplication::desktop(); 289 QDesktopWidget *desktop = QApplication::desktop();
273 QRect available = desktop->availableGeometry(); 290 QRect available = desktop->availableGeometry();
274 291
275 int width = available.width() * 2 / 3; 292 int width = available.width() * 2 / 3;
276 int height = available.height() / 2; 293 int height = available.height() / 2;
277 if (height < 450) height = available.height() * 2 / 3; 294 if (height < 450) height = available.height() * 2 / 3;
278 if (width > height * 2) width = height * 2; 295 if (width > height * 2) width = height * 2;
279 296
280 QSettings settings;
281 settings.beginGroup("MainWindow"); 297 settings.beginGroup("MainWindow");
282 QSize size = settings.value("size", QSize(width, height)).toSize(); 298 QSize size = settings.value("size", QSize(width, height)).toSize();
283 gui.resize(size); 299 gui->resize(size);
284 if (settings.contains("position")) { 300 if (settings.contains("position")) {
285 gui.move(settings.value("position").toPoint()); 301 gui->move(settings.value("position").toPoint());
286 } 302 }
287 settings.endGroup(); 303 settings.endGroup();
288 304
289 gui.show(); 305 gui->show();
290 306
291 // The MainWindow class seems to have trouble dealing with this if 307 // The MainWindow class seems to have trouble dealing with this if
292 // it tries to adapt to this preference before the constructor is 308 // it tries to adapt to this preference before the constructor is
293 // complete. As a lazy hack, apply it explicitly from here 309 // complete. As a lazy hack, apply it explicitly from here
294 gui.preferenceChanged("Property Box Layout"); 310 gui->preferenceChanged("Property Box Layout");
295 311
296 bool haveSession = false; 312 bool haveSession = false;
297 bool haveMainModel = false; 313 bool haveMainModel = false;
298 bool havePriorCommandLineModel = false; 314 bool havePriorCommandLineModel = false;
299 315
306 322
307 QString path = *i; 323 QString path = *i;
308 324
309 if (path.endsWith("sv")) { 325 if (path.endsWith("sv")) {
310 if (!haveSession) { 326 if (!haveSession) {
311 status = gui.openSessionFile(path); 327 status = gui->openSessionFile(path);
312 if (status == MainWindow::FileOpenSucceeded) { 328 if (status == MainWindow::FileOpenSucceeded) {
313 haveSession = true; 329 haveSession = true;
314 haveMainModel = true; 330 haveMainModel = true;
315 } 331 }
316 } else { 332 } else {
318 status = MainWindow::FileOpenSucceeded; 334 status = MainWindow::FileOpenSucceeded;
319 } 335 }
320 } 336 }
321 if (status != MainWindow::FileOpenSucceeded) { 337 if (status != MainWindow::FileOpenSucceeded) {
322 if (!haveMainModel) { 338 if (!haveMainModel) {
323 status = gui.open(path, MainWindow::ReplaceMainModel); 339 status = gui->open(path, MainWindow::ReplaceMainModel);
324 if (status == MainWindow::FileOpenSucceeded) { 340 if (status == MainWindow::FileOpenSucceeded) {
325 haveMainModel = true; 341 haveMainModel = true;
326 } 342 }
327 } else { 343 } else {
328 if (haveSession && !havePriorCommandLineModel) { 344 if (haveSession && !havePriorCommandLineModel) {
329 status = gui.open(path, MainWindow::AskUser); 345 status = gui->open(path, MainWindow::AskUser);
330 if (status == MainWindow::FileOpenSucceeded) { 346 if (status == MainWindow::FileOpenSucceeded) {
331 havePriorCommandLineModel = true; 347 havePriorCommandLineModel = true;
332 } 348 }
333 } else { 349 } else {
334 status = gui.open(path, MainWindow::CreateAdditionalModel); 350 status = gui->open(path, MainWindow::CreateAdditionalModel);
335 } 351 }
336 } 352 }
337 } 353 }
338 if (status == MainWindow::FileOpenFailed) { 354 if (status == MainWindow::FileOpenFailed) {
339 QMessageBox::critical 355 QMessageBox::critical
340 (&gui, QMessageBox::tr("Failed to open file"), 356 (gui, QMessageBox::tr("Failed to open file"),
341 QMessageBox::tr("File or URL \"%1\" could not be opened").arg(path)); 357 QMessageBox::tr("File or URL \"%1\" could not be opened").arg(path));
342 } 358 }
343 } 359 }
344 360
345 #ifdef HAVE_FFTW3F 361 #ifdef HAVE_FFTW3F
349 fftwf_import_wisdom_from_string(wisdom.toLocal8Bit().data()); 365 fftwf_import_wisdom_from_string(wisdom.toLocal8Bit().data());
350 } 366 }
351 settings.endGroup(); 367 settings.endGroup();
352 #endif 368 #endif
353 369
370 splash.finish(gui);
354 371
355 /* 372 /*
356 TipDialog tipDialog; 373 TipDialog tipDialog;
357 if (tipDialog.isOK()) { 374 if (tipDialog.isOK()) {
358 tipDialog.exec(); 375 tipDialog.exec();
359 } 376 }
360 */ 377 */
361 int rv = application.exec(); 378 int rv = application.exec();
362 // std::cerr << "application.exec() returned " << rv << std::endl; 379 std::cerr << "application.exec() returned " << rv << std::endl;
363 380
364 cleanupMutex.lock(); 381 cleanupMutex.lock();
365 TempDirectory::getInstance()->cleanup(); 382 TempDirectory::getInstance()->cleanup();
383
366 application.releaseMainWindow(); 384 application.releaseMainWindow();
367 385
368 #ifdef HAVE_FFTW3F 386 #ifdef HAVE_FFTW3F
369 char *cwisdom = fftwf_export_wisdom_to_string(); 387 char *cwisdom = fftwf_export_wisdom_to_string();
370 if (cwisdom) { 388 if (cwisdom) {
373 settings.endGroup(); 391 settings.endGroup();
374 fftwf_free(cwisdom); 392 fftwf_free(cwisdom);
375 } 393 }
376 #endif 394 #endif
377 395
396 delete gui;
397
378 return rv; 398 return rv;
379 } 399 }