comparison main/MainWindow.cpp @ 189:26397b84e6a2

* Add labelling option for instants inserted through tapping (closes FR#1674184) Needs some refinement still, but it's almost functionally complete
author Chris Cannam
date Mon, 08 Oct 2007 14:44:38 +0000
parents f3191ab6d564
children 89a41f3d24d1
comparison
equal deleted inserted replaced
188:4c5bfe0f8502 189:26397b84e6a2
22 #include "view/Pane.h" 22 #include "view/Pane.h"
23 #include "view/PaneStack.h" 23 #include "view/PaneStack.h"
24 #include "data/model/WaveFileModel.h" 24 #include "data/model/WaveFileModel.h"
25 #include "data/model/SparseOneDimensionalModel.h" 25 #include "data/model/SparseOneDimensionalModel.h"
26 #include "data/model/NoteModel.h" 26 #include "data/model/NoteModel.h"
27 #include "data/model/Labeller.h"
27 #include "view/ViewManager.h" 28 #include "view/ViewManager.h"
28 #include "base/Preferences.h" 29 #include "base/Preferences.h"
29 #include "layer/WaveformLayer.h" 30 #include "layer/WaveformLayer.h"
30 #include "layer/TimeRulerLayer.h" 31 #include "layer/TimeRulerLayer.h"
31 #include "layer/TimeInstantLayer.h" 32 #include "layer/TimeInstantLayer.h"
139 m_ffwdAction(0), 140 m_ffwdAction(0),
140 m_rwdAction(0), 141 m_rwdAction(0),
141 m_documentModified(false), 142 m_documentModified(false),
142 m_openingAudioFile(false), 143 m_openingAudioFile(false),
143 m_abandoning(false), 144 m_abandoning(false),
145 m_labeller(0),
144 m_preferencesDialog(0), 146 m_preferencesDialog(0),
145 m_layerTreeView(0), 147 m_layerTreeView(0),
146 m_keyReference(new KeyReference()) 148 m_keyReference(new KeyReference())
147 { 149 {
148 setWindowTitle(tr("Sonic Visualiser")); 150 setWindowTitle(tr("Sonic Visualiser"));
336 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC())); 338 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
337 QTimer *oscTimer = new QTimer(this); 339 QTimer *oscTimer = new QTimer(this);
338 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC())); 340 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
339 oscTimer->start(1000); 341 oscTimer->start(1000);
340 } 342 }
343
344 Labeller::ValueType labellerType = Labeller::ValueFromTwoLevelCounter;
345 settings.beginGroup("MainWindow");
346 labellerType = (Labeller::ValueType)
347 settings.value("labellertype", (int)labellerType).toInt();
348 int cycle = settings.value("labellercycle", 4).toInt();
349 settings.endGroup();
350
351 m_labeller = new Labeller(labellerType);
352 m_labeller->setCounterCycleSize(cycle);
341 353
342 setupMenus(); 354 setupMenus();
343 setupToolbars(); 355 setupToolbars();
344 setupHelpMenu(); 356 setupHelpMenu();
345 357
732 action->setShortcut(tr("Shift+Enter")); 744 action->setShortcut(tr("Shift+Enter"));
733 action->setStatusTip(tr("Insert new time instants at the start and end of the current selected regions, in a new layer if necessary")); 745 action->setStatusTip(tr("Insert new time instants at the start and end of the current selected regions, in a new layer if necessary"));
734 connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries())); 746 connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries()));
735 connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool))); 747 connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool)));
736 m_keyReference->registerShortcut(action); 748 m_keyReference->registerShortcut(action);
749 menu->addAction(action);
750
751 QMenu *numberingMenu = menu->addMenu(tr("Set Instant Numbering"));
752 QActionGroup *numberingGroup = new QActionGroup(this);
753
754 Labeller::TypeNameMap types = m_labeller->getTypeNames();
755 for (Labeller::TypeNameMap::iterator i = types.begin(); i != types.end(); ++i) {
756 if (i->first == Labeller::ValueFromLabel) continue;
757 action = new QAction(i->second, this);
758 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsNumbering()));
759 action->setCheckable(true);
760 action->setChecked(m_labeller->getType() == i->first);
761 numberingGroup->addAction(action);
762 numberingMenu->addAction(action);
763 m_numberingActions[action] = (int)i->first;
764 }
765
766 QMenu *cycleMenu = menu->addMenu(tr("Set Instant Counter Cycle"));
767 QActionGroup *cycleGroup = new QActionGroup(this);
768
769 int cycles[] = { 2, 3, 4, 5, 6, 7, 8, 10, 12, 16 };
770 for (int i = 0; i < sizeof(cycles)/sizeof(cycles[0]); ++i) {
771 action = new QAction(QString("%1").arg(cycles[i]), this);
772 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsCounterCycle()));
773 action->setCheckable(true);
774 action->setChecked(cycles[i] == m_labeller->getCounterCycleSize());
775 cycleGroup->addAction(action);
776 cycleMenu->addAction(action);
777 }
778
779 action = new QAction(tr("Re-Number Selected Instants"), this);
780 action->setStatusTip(tr("Re-number the selected instants using the current labelling scheme"));
781 connect(action, SIGNAL(triggered()), this, SLOT(renumberInstants()));
782 connect(this, SIGNAL(canRenumberInstants(bool)), action, SLOT(setEnabled(bool)));
783 // m_keyReference->registerShortcut(action);
737 menu->addAction(action); 784 menu->addAction(action);
738 } 785 }
739 786
740 void 787 void
741 MainWindow::setupViewMenu() 788 MainWindow::setupViewMenu()
1894 emit canFfwd(true); 1941 emit canFfwd(true);
1895 emit canRewind(true); 1942 emit canRewind(true);
1896 emit canPaste(haveCurrentEditableLayer && haveClipboardContents); 1943 emit canPaste(haveCurrentEditableLayer && haveClipboardContents);
1897 emit canInsertInstant(haveCurrentPane); 1944 emit canInsertInstant(haveCurrentPane);
1898 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection); 1945 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
1946 emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection);
1899 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection); 1947 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
1900 emit canClearSelection(haveSelection); 1948 emit canClearSelection(haveSelection);
1901 emit canEditSelection(haveSelection && haveCurrentEditableLayer); 1949 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
1902 emit canSave(m_sessionFile != "" && m_documentModified); 1950 emit canSave(m_sessionFile != "" && m_documentModified);
1903 1951
2340 Model *model = layer->getModel(); 2388 Model *model = layer->getModel();
2341 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *> 2389 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
2342 (model); 2390 (model);
2343 2391
2344 if (sodm) { 2392 if (sodm) {
2345 SparseOneDimensionalModel::Point point 2393 SparseOneDimensionalModel::Point point(frame, "");
2346 (frame, QString("%1").arg(sodm->getPointCount() + 1)); 2394
2347 CommandHistory::getInstance()->addCommand 2395 SparseOneDimensionalModel::Point prevPoint(0);
2348 (new SparseOneDimensionalModel::AddPointCommand(sodm, point, 2396 bool havePrevPoint = false;
2349 tr("Add Points")), 2397
2350 true, true); // bundled 2398 SparseOneDimensionalModel::EditCommand *command =
2351 } 2399 new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point"));
2352 } 2400
2401 if (m_labeller->actingOnPrevPoint()) {
2402
2403 SparseOneDimensionalModel::PointList prevPoints =
2404 sodm->getPreviousPoints(frame);
2405
2406 if (!prevPoints.empty()) {
2407 prevPoint = *prevPoints.begin();
2408 havePrevPoint = true;
2409 }
2410 }
2411
2412 if (m_labeller) {
2413
2414 m_labeller->setSampleRate(sodm->getSampleRate());
2415
2416 if (havePrevPoint) {
2417 command->deletePoint(prevPoint);
2418 }
2419
2420 m_labeller->label<SparseOneDimensionalModel::Point>
2421 (point, havePrevPoint ? &prevPoint : 0);
2422
2423 if (havePrevPoint) {
2424 command->addPoint(prevPoint);
2425 }
2426 }
2427
2428 command->addPoint(point);
2429
2430 command->setName(tr("Add Point at %1 s")
2431 .arg(RealTime::frame2RealTime
2432 (frame,
2433 sodm->getSampleRate())
2434 .toText(false).c_str()));
2435
2436 command->finish();
2437 }
2438 }
2439 }
2440
2441 void
2442 MainWindow::setInstantsNumbering()
2443 {
2444 QAction *a = dynamic_cast<QAction *>(sender());
2445 if (!a) return;
2446
2447 int type = m_numberingActions[a];
2448
2449 if (m_labeller) m_labeller->setType(Labeller::ValueType(type));
2450
2451 QSettings settings;
2452 settings.beginGroup("MainWindow");
2453 settings.setValue("labellertype", type);
2454 settings.endGroup();
2455 }
2456
2457 void
2458 MainWindow::setInstantsCounterCycle()
2459 {
2460 QAction *a = dynamic_cast<QAction *>(sender());
2461 if (!a) return;
2462
2463 int cycle = a->text().toInt();
2464 if (cycle == 0) return;
2465
2466 if (m_labeller) m_labeller->setCounterCycleSize(cycle);
2467
2468
2469 QSettings settings;
2470 settings.beginGroup("MainWindow");
2471 settings.setValue("labellercycle", cycle);
2472 settings.endGroup();
2473 }
2474
2475 void
2476 MainWindow::renumberInstants()
2477 {
2478 Pane *pane = m_paneStack->getCurrentPane();
2479 if (!pane) return;
2480
2481 Layer *layer = dynamic_cast<TimeInstantLayer *>(pane->getSelectedLayer());
2482 if (!layer) return;
2483
2484 MultiSelection ms(m_viewManager->getSelection());
2485
2486 Model *model = layer->getModel();
2487 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
2488 (model);
2489 if (!sodm) return;
2490
2491 if (!m_labeller) return;
2492
2493 Labeller labeller(*m_labeller);
2494 labeller.setSampleRate(sodm->getSampleRate());
2495
2496 // This uses a command
2497
2498 labeller.labelAll<SparseOneDimensionalModel::Point>(*sodm, &ms);
2353 } 2499 }
2354 2500
2355 void 2501 void
2356 MainWindow::importAudio() 2502 MainWindow::importAudio()
2357 { 2503 {