Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 637:f45af8d8091e imaf_enc
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 04 Nov 2013 17:47:53 +0000 |
parents | 767789a78984 2484381b53a1 |
children | bfd68cc71a25 |
comparison
equal
deleted
inserted
replaced
636:767789a78984 | 637:f45af8d8091e |
---|---|
391 } | 391 } |
392 | 392 |
393 void | 393 void |
394 MainWindow::goFullScreen() | 394 MainWindow::goFullScreen() |
395 { | 395 { |
396 if (m_viewManager->getZoomWheelsEnabled()) { | |
397 // The wheels seem to end up in the wrong place in full-screen mode | |
398 toggleZoomWheels(); | |
399 } | |
400 | |
396 QWidget *ps = m_mainScroll->takeWidget(); | 401 QWidget *ps = m_mainScroll->takeWidget(); |
397 ps->setParent(0); | 402 ps->setParent(0); |
398 | 403 |
399 QShortcut *sc; | 404 QShortcut *sc; |
400 | 405 |
425 foreach (QObject *o, cl) { | 430 foreach (QObject *o, cl) { |
426 QShortcut *sc = qobject_cast<QShortcut *>(o); | 431 QShortcut *sc = qobject_cast<QShortcut *>(o); |
427 if (sc) delete sc; | 432 if (sc) delete sc; |
428 } | 433 } |
429 | 434 |
435 m_paneStack->showNormal(); | |
430 m_mainScroll->setWidget(m_paneStack); | 436 m_mainScroll->setWidget(m_paneStack); |
431 } | 437 } |
432 | 438 |
433 void | 439 void |
434 MainWindow::setupFileMenu() | 440 MainWindow::setupFileMenu() |
535 action->setStatusTip(tr("Export selection as an audio file")); | 541 action->setStatusTip(tr("Export selection as an audio file")); |
536 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio())); | 542 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio())); |
537 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); | 543 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); |
538 menu->addAction(action); | 544 menu->addAction(action); |
539 | 545 |
546 action = new QAction(tr("&Export Audio Data..."), this); | |
547 action->setStatusTip(tr("Export audio from selection into a data file")); | |
548 connect(action, SIGNAL(triggered()), this, SLOT(exportAudioData())); | |
549 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); | |
550 menu->addAction(action); | |
551 | |
540 QAction *actionCreateIMAF = new QAction(tr("&Export IMAF File..."), this); | 552 QAction *actionCreateIMAF = new QAction(tr("&Export IMAF File..."), this); |
541 actionCreateIMAF->setStatusTip(tr("Export selection as an IMAF file")); | 553 actionCreateIMAF->setStatusTip(tr("Export selection as an IMAF file")); |
542 menu->addAction(actionCreateIMAF); | 554 menu->addAction(actionCreateIMAF); |
543 connect(actionCreateIMAF,SIGNAL(triggered()),this,SLOT(exportIMAF())); | 555 connect(actionCreateIMAF,SIGNAL(triggered()),this,SLOT(exportIMAF())); |
544 | 556 |
545 QAction *actionOpenIMAF = new QAction(tr("&Import IMAF File..."), this); | 557 QAction *actionOpenIMAF = new QAction(tr("&Import IMAF File..."), this); |
546 actionOpenIMAF->setStatusTip(tr("Import IMAF file")); | 558 actionOpenIMAF->setStatusTip(tr("Import IMAF file")); |
547 menu->addAction(actionOpenIMAF); | 559 menu->addAction(actionOpenIMAF); |
548 connect(actionOpenIMAF,SIGNAL(triggered()),this,SLOT(importIMAF())); | 560 connect(actionOpenIMAF,SIGNAL(triggered()),this,SLOT(importIMAF())); |
549 | |
550 | |
551 | |
552 | 561 |
553 menu->addSeparator(); | 562 menu->addSeparator(); |
554 | 563 |
555 action = new QAction(tr("Import Annotation &Layer..."), this); | 564 action = new QAction(tr("Import Annotation &Layer..."), this); |
556 action->setShortcut(tr("Ctrl+L")); | 565 action->setShortcut(tr("Ctrl+L")); |
798 i->first == Labeller::ValueFromRealTime) { | 807 i->first == Labeller::ValueFromRealTime) { |
799 numberingMenu->addSeparator(); | 808 numberingMenu->addSeparator(); |
800 } | 809 } |
801 } | 810 } |
802 | 811 |
812 action = new QAction(tr("Reset Numbering Counters"), this); | |
813 action->setStatusTip(tr("Reset to 1 all the counters used for counter-based labelling")); | |
814 connect(action, SIGNAL(triggered()), this, SLOT(resetInstantsCounters())); | |
815 connect(this, SIGNAL(replacedDocument()), action, SLOT(trigger())); | |
816 menu->addAction(action); | |
817 | |
803 action = new QAction(tr("Set Numbering Counters..."), this); | 818 action = new QAction(tr("Set Numbering Counters..."), this); |
804 action->setStatusTip(tr("Set the counters used for counter-based labelling")); | 819 action->setStatusTip(tr("Set the counters used for counter-based labelling")); |
805 connect(action, SIGNAL(triggered()), this, SLOT(resetInstantsCounters())); | 820 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsCounters())); |
806 menu->addAction(action); | 821 menu->addAction(action); |
807 | 822 |
808 action = new QAction(tr("Renumber Selected Instants"), this); | 823 action = new QAction(tr("Renumber Selected Instants"), this); |
809 action->setStatusTip(tr("Renumber the selected instants using the current labelling scheme")); | 824 action->setStatusTip(tr("Renumber the selected instants using the current labelling scheme")); |
810 connect(action, SIGNAL(triggered()), this, SLOT(renumberInstants())); | 825 connect(action, SIGNAL(triggered()), this, SLOT(renumberInstants())); |
2083 action->setCheckable(true); | 2098 action->setCheckable(true); |
2084 action->setChecked(true); | 2099 action->setChecked(true); |
2085 action->setShortcut(tr("1")); | 2100 action->setShortcut(tr("1")); |
2086 action->setStatusTip(tr("Navigate")); | 2101 action->setStatusTip(tr("Navigate")); |
2087 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected())); | 2102 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected())); |
2103 connect(this, SIGNAL(replacedDocument()), action, SLOT(trigger())); | |
2088 group->addAction(action); | 2104 group->addAction(action); |
2089 m_keyReference->registerShortcut(action); | 2105 m_keyReference->registerShortcut(action); |
2090 m_toolActions[ViewManager::NavigateMode] = action; | 2106 m_toolActions[ViewManager::NavigateMode] = action; |
2091 | 2107 |
2092 action = toolbar->addAction(il.load("select"), | 2108 action = toolbar->addAction(il.load("select"), |
2354 } | 2370 } |
2355 } | 2371 } |
2356 | 2372 |
2357 void | 2373 void |
2358 MainWindow::exportAudio() | 2374 MainWindow::exportAudio() |
2375 { | |
2376 exportAudio(false); | |
2377 } | |
2378 | |
2379 void | |
2380 MainWindow::exportAudioData() | |
2381 { | |
2382 exportAudio(true); | |
2383 } | |
2384 | |
2385 void | |
2386 MainWindow::exportAudio(bool asData) | |
2359 { | 2387 { |
2360 if (!getMainModel()) return; | 2388 if (!getMainModel()) return; |
2361 | 2389 |
2362 RangeSummarisableTimeValueModel *model = getMainModel(); | 2390 RangeSummarisableTimeValueModel *model = getMainModel(); |
2363 std::set<RangeSummarisableTimeValueModel *> otherModels; | 2391 std::set<RangeSummarisableTimeValueModel *> otherModels; |
2416 model = m[item]; | 2444 model = m[item]; |
2417 } | 2445 } |
2418 } | 2446 } |
2419 } | 2447 } |
2420 | 2448 |
2421 QString path = getSaveFileName(FileFinder::AudioFile); | 2449 QString path; |
2450 if (asData) { | |
2451 path = getSaveFileName(FileFinder::CSVFile); | |
2452 } else { | |
2453 path = getSaveFileName(FileFinder::AudioFile); | |
2454 } | |
2422 if (path == "") return; | 2455 if (path == "") return; |
2423 | 2456 |
2424 bool ok = false; | 2457 bool ok = false; |
2425 QString error; | 2458 QString error; |
2426 | 2459 |
2447 | 2480 |
2448 if (item == items[0]) selectionToWrite = &ms; | 2481 if (item == items[0]) selectionToWrite = &ms; |
2449 | 2482 |
2450 } else if (selections.size() > 1) { | 2483 } else if (selections.size() > 1) { |
2451 | 2484 |
2452 QStringList items; | 2485 bool multiple = false; |
2453 items << tr("Export the selected regions into a single audio file") | 2486 |
2454 << tr("Export the selected regions into separate files") | 2487 if (!asData) { // Multi-file export not supported for data |
2455 << tr("Export the whole audio file"); | 2488 |
2456 | 2489 QStringList items; |
2457 QString item = ListInputDialog::getItem | 2490 items << tr("Export the selected regions into a single file") |
2458 (this, tr("Select region to export"), | 2491 << tr("Export the selected regions into separate files") |
2459 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"), | 2492 << tr("Export the whole file"); |
2460 items, 0, &ok); | 2493 |
2461 | 2494 QString item = ListInputDialog::getItem |
2462 if (!ok || item.isEmpty()) return; | 2495 (this, tr("Select region to export"), |
2463 | 2496 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"), |
2464 if (item == items[0]) { | 2497 items, 0, &ok); |
2465 | 2498 |
2499 if (!ok || item.isEmpty()) return; | |
2500 | |
2501 if (item == items[0]) { | |
2502 selectionToWrite = &ms; | |
2503 } else if (item == items[1]) { | |
2504 multiple = true; | |
2505 } | |
2506 } else { // asData | |
2466 selectionToWrite = &ms; | 2507 selectionToWrite = &ms; |
2467 | 2508 } |
2468 } else if (item == items[1]) { | 2509 |
2469 | 2510 if (multiple) { // Can only happen when asData false |
2470 multiple = true; | |
2471 | 2511 |
2472 int n = 1; | 2512 int n = 1; |
2473 QString base = path; | 2513 QString base = path; |
2474 base.replace(".wav", ""); | 2514 base.replace(".wav", ""); |
2475 | 2515 |
2501 } | 2541 } |
2502 } | 2542 } |
2503 } | 2543 } |
2504 | 2544 |
2505 if (!multiple) { | 2545 if (!multiple) { |
2506 WavFileWriter writer(path, | 2546 if (asData) { |
2507 model->getSampleRate(), | 2547 CSVFileWriter writer(path, model, |
2508 model->getChannelCount(), | 2548 ((QFileInfo(path).suffix() == "csv") ? |
2509 WavFileWriter::WriteToTemporary); | 2549 "," : "\t")); |
2510 writer.writeModel(model, selectionToWrite); | 2550 if (selectionToWrite) { |
2511 ok = writer.isOK(); | 2551 writer.writeSelection(selectionToWrite); |
2512 error = writer.getError(); | 2552 } else { |
2553 writer.write(); | |
2554 } | |
2555 ok = writer.isOK(); | |
2556 error = writer.getError(); | |
2557 } else { | |
2558 WavFileWriter writer(path, | |
2559 model->getSampleRate(), | |
2560 model->getChannelCount(), | |
2561 WavFileWriter::WriteToTemporary); | |
2562 writer.writeModel(model, selectionToWrite); | |
2563 ok = writer.isOK(); | |
2564 error = writer.getError(); | |
2565 } | |
2513 } | 2566 } |
2514 | 2567 |
2515 if (ok) { | 2568 if (ok) { |
2516 if (multiple) { | 2569 if (multiple) { |
2517 emit activity(tr("Export multiple audio files")); | 2570 emit activity(tr("Export multiple audio files")); |
2518 } else { | 2571 } else { |
2519 emit activity(tr("Export audio to \"%1\"").arg(path)); | 2572 emit activity(tr("Export audio to \"%1\"").arg(path)); |
2520 m_recentFiles.addFile(path); | 2573 m_recentFiles.addFile(path); |
2521 } | 2574 } |
2522 } else { | 2575 } else { |
2523 QMessageBox::critical(this, tr("Failed to write file"), error); | 2576 QMessageBox::critical(this, tr("Failed to write file"), error); |
2524 } | 2577 } |
2525 } | 2578 } |
2526 | 2579 |
2527 | 2580 |
2528 | 2581 |
3119 return; | 3172 return; |
3120 } | 3173 } |
3121 | 3174 |
3122 QSettings settings; | 3175 QSettings settings; |
3123 settings.beginGroup("MainWindow"); | 3176 settings.beginGroup("MainWindow"); |
3124 settings.setValue("size", size()); | 3177 settings.setValue("maximised", isMaximized()); |
3125 settings.setValue("position", pos()); | 3178 if (!isMaximized()) { |
3179 settings.setValue("size", size()); | |
3180 settings.setValue("position", pos()); | |
3181 } | |
3126 settings.endGroup(); | 3182 settings.endGroup(); |
3127 | 3183 |
3128 if (m_preferencesDialog && | 3184 if (m_preferencesDialog && |
3129 m_preferencesDialog->isVisible()) { | 3185 m_preferencesDialog->isVisible()) { |
3130 closeSession(); // otherwise we'll have to wait for prefs changes | 3186 closeSession(); // otherwise we'll have to wait for prefs changes |
4081 settings.setValue("labellercycle", cycle); | 4137 settings.setValue("labellercycle", cycle); |
4082 settings.endGroup(); | 4138 settings.endGroup(); |
4083 } | 4139 } |
4084 | 4140 |
4085 void | 4141 void |
4086 MainWindow::resetInstantsCounters() | 4142 MainWindow::setInstantsCounters() |
4087 { | 4143 { |
4088 LabelCounterInputDialog dialog(m_labeller, this); | 4144 LabelCounterInputDialog dialog(m_labeller, this); |
4089 dialog.setWindowTitle(tr("Reset Counters")); | 4145 dialog.setWindowTitle(tr("Reset Counters")); |
4090 dialog.exec(); | 4146 dialog.exec(); |
4147 } | |
4148 | |
4149 void | |
4150 MainWindow::resetInstantsCounters() | |
4151 { | |
4152 if (m_labeller) m_labeller->resetCounters(); | |
4091 } | 4153 } |
4092 | 4154 |
4093 void | 4155 void |
4094 MainWindow::modelGenerationFailed(QString transformName, QString message) | 4156 MainWindow::modelGenerationFailed(QString transformName, QString message) |
4095 { | 4157 { |