comparison src/MainWindow.cpp @ 6:ab5b3300ba1a

Add analyser, calculate some transforms when a file is loaded
author Chris Cannam
date Fri, 16 Nov 2012 17:14:46 +0000
parents c2a0d8666017
children b7b5eddfd2c7
comparison
equal deleted inserted replaced
5:c2a0d8666017 6:ab5b3300ba1a
14 */ 14 */
15 15
16 #include "../version.h" 16 #include "../version.h"
17 17
18 #include "MainWindow.h" 18 #include "MainWindow.h"
19 #include "Analyser.h"
20
19 #include "framework/Document.h" 21 #include "framework/Document.h"
20 22
21 #include "view/Pane.h" 23 #include "view/Pane.h"
22 #include "view/PaneStack.h" 24 #include "view/PaneStack.h"
23 #include "data/model/WaveFileModel.h" 25 #include "data/model/WaveFileModel.h"
112 114
113 settings.beginGroup("MainWindow"); 115 settings.beginGroup("MainWindow");
114 settings.setValue("showstatusbar", false); 116 settings.setValue("showstatusbar", false);
115 settings.endGroup(); 117 settings.endGroup();
116 118
117 m_viewManager->setAlignMode(true); 119 m_viewManager->setAlignMode(false);
118 m_viewManager->setPlaySoloMode(true); 120 m_viewManager->setPlaySoloMode(false);
119 m_viewManager->setToolMode(ViewManager::NavigateMode); 121 m_viewManager->setToolMode(ViewManager::NavigateMode);
120 m_viewManager->setZoomWheelsEnabled(false); 122 m_viewManager->setZoomWheelsEnabled(false);
121 m_viewManager->setIlluminateLocalFeatures(false); 123 m_viewManager->setIlluminateLocalFeatures(true);
122 m_viewManager->setShowWorkTitle(true); 124 m_viewManager->setShowWorkTitle(true);
125 m_viewManager->setShowCentreLine(false);
126 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
123 127
124 QFrame *frame = new QFrame; 128 QFrame *frame = new QFrame;
125 setCentralWidget(frame); 129 setCentralWidget(frame);
126 130
127 QGridLayout *layout = new QGridLayout; 131 QGridLayout *layout = new QGridLayout;
128 132
129 m_descriptionLabel = new QLabel;
130
131 QScrollArea *scroll = new QScrollArea(frame); 133 QScrollArea *scroll = new QScrollArea(frame);
132 scroll->setWidgetResizable(true); 134 scroll->setWidgetResizable(true);
133 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 135 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
134 scroll->setFrameShape(QFrame::NoFrame); 136 scroll->setFrameShape(QFrame::NoFrame);
135 137
138 // We have a pane stack: it comes with the territory. However, we
139 // have a fixed and known number of panes in it (e.g. 1) -- it
140 // isn't variable
136 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks); 141 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
137 scroll->setWidget(m_paneStack); 142 scroll->setWidget(m_paneStack);
138 143
139 m_overview = new Overview(frame); 144 m_overview = new Overview(frame);
140 m_overview->setViewManager(m_viewManager); 145 m_overview->setViewManager(m_viewManager);
141 m_overview->setFixedHeight(40); 146 m_overview->setFixedHeight(40);
142 #ifndef _WIN32 147 #ifndef _WIN32
143 // For some reason, the contents of the overview never appear if we 148 // For some reason, the contents of the overview never appear if we
145 // to track down the reason why. 150 // to track down the reason why.
146 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); 151 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
147 #endif 152 #endif
148 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)), 153 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
149 this, SLOT(contextHelpChanged(const QString &))); 154 this, SLOT(contextHelpChanged(const QString &)));
150 m_overview->hide();
151 155
152 m_panLayer = new WaveformLayer; 156 m_panLayer = new WaveformLayer;
153 m_panLayer->setChannelMode(WaveformLayer::MergeChannels); 157 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
154 m_panLayer->setAggressiveCacheing(true); 158 m_panLayer->setAggressiveCacheing(true);
155 m_overview->addLayer(m_panLayer); 159 m_overview->addLayer(m_panLayer);
182 this, SLOT(playSpeedChanged(int))); 186 this, SLOT(playSpeedChanged(int)));
183 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); 187 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
184 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); 188 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
185 189
186 layout->setSpacing(4); 190 layout->setSpacing(4);
187 layout->addWidget(scroll, 0, 0, 1, 6); 191 layout->addWidget(m_overview, 0, 1);
188 layout->addWidget(m_overview, 1, 1); 192 layout->addWidget(scroll, 1, 1);
189 layout->addWidget(m_fader, 1, 2);
190 layout->addWidget(m_playSpeed, 1, 3);
191
192 m_paneStack->setPropertyStackMinWidth
193 (m_fader->width() + m_playSpeed->width() +
194 layout->spacing() * 4);
195 193
196 layout->setColumnStretch(1, 10); 194 layout->setColumnStretch(1, 10);
197 195
198 frame->setLayout(layout); 196 frame->setLayout(layout);
199 197
201 setupToolbars(); 199 setupToolbars();
202 setupHelpMenu(); 200 setupHelpMenu();
203 201
204 statusBar(); 202 statusBar();
205 203
204 m_analyser = new Analyser();
205
206 newSession(); 206 newSession();
207 } 207 }
208 208
209 MainWindow::~MainWindow() 209 MainWindow::~MainWindow()
210 { 210 {
211 delete m_analyser;
211 delete m_keyReference; 212 delete m_keyReference;
212 Profiles::getInstance()->dump(); 213 Profiles::getInstance()->dump();
213 } 214 }
214 215
215 void 216 void
367 action->setStatusTip(tr("Zoom to show the whole file")); 368 action->setStatusTip(tr("Zoom to show the whole file"));
368 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit())); 369 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
369 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool))); 370 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
370 m_keyReference->registerShortcut(action); 371 m_keyReference->registerShortcut(action);
371 menu->addAction(action); 372 menu->addAction(action);
372
373 menu->addSeparator();
374
375 m_keyReference->setCategory(tr("Display Features"));
376
377 QActionGroup *overlayGroup = new QActionGroup(this);
378
379 action = new QAction(tr("Show &No Overlays"), this);
380 action->setShortcut(tr("0"));
381 action->setStatusTip(tr("Hide centre indicator, frame times, layer names and scale"));
382 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
383 action->setCheckable(true);
384 action->setChecked(false);
385 overlayGroup->addAction(action);
386 m_keyReference->registerShortcut(action);
387 menu->addAction(action);
388
389 action = new QAction(tr("Show &Minimal Overlays"), this);
390 action->setShortcut(tr("9"));
391 action->setStatusTip(tr("Show centre indicator only"));
392 connect(action, SIGNAL(triggered()), this, SLOT(showMinimalOverlays()));
393 action->setCheckable(true);
394 action->setChecked(false);
395 overlayGroup->addAction(action);
396 m_keyReference->registerShortcut(action);
397 menu->addAction(action);
398
399 action = new QAction(tr("Show &Standard Overlays"), this);
400 action->setShortcut(tr("8"));
401 action->setStatusTip(tr("Show centre indicator, frame times and scale"));
402 connect(action, SIGNAL(triggered()), this, SLOT(showStandardOverlays()));
403 action->setCheckable(true);
404 action->setChecked(true);
405 overlayGroup->addAction(action);
406 m_keyReference->registerShortcut(action);
407 menu->addAction(action);
408
409 action = new QAction(tr("Show &All Overlays"), this);
410 action->setShortcut(tr("7"));
411 action->setStatusTip(tr("Show all texts and scale"));
412 connect(action, SIGNAL(triggered()), this, SLOT(showAllOverlays()));
413 action->setCheckable(true);
414 action->setChecked(false);
415 overlayGroup->addAction(action);
416 m_keyReference->registerShortcut(action);
417 menu->addAction(action);
418
419 menu->addSeparator();
420
421 action = new QAction(tr("Show &Zoom Wheels"), this);
422 action->setShortcut(tr("Z"));
423 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
424 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
425 action->setCheckable(true);
426 action->setChecked(m_viewManager->getZoomWheelsEnabled());
427 m_keyReference->registerShortcut(action);
428 menu->addAction(action);
429
430 action = new QAction(tr("Show Property Bo&xes"), this);
431 action->setShortcut(tr("X"));
432 action->setStatusTip(tr("Show the layer property boxes at the side of the main window"));
433 connect(action, SIGNAL(triggered()), this, SLOT(togglePropertyBoxes()));
434 action->setCheckable(true);
435 action->setChecked(false); //!!!
436 m_keyReference->registerShortcut(action);
437 menu->addAction(action);
438
439 action = new QAction(tr("Show Status &Bar"), this);
440 action->setStatusTip(tr("Show context help information in the status bar at the bottom of the window"));
441 connect(action, SIGNAL(triggered()), this, SLOT(toggleStatusBar()));
442 action->setCheckable(true);
443 action->setChecked(true);
444 menu->addAction(action);
445
446 QSettings settings;
447 settings.beginGroup("MainWindow");
448 bool sb = settings.value("showstatusbar", true).toBool();
449 if (!sb) {
450 action->setChecked(false);
451 statusBar()->hide();
452 }
453 settings.endGroup();
454 } 373 }
455 374
456 void 375 void
457 MainWindow::setupHelpMenu() 376 MainWindow::setupHelpMenu()
458 { 377 {
559 tr("Fast Forward to End")); 478 tr("Fast Forward to End"));
560 ffwdEndAction->setShortcut(tr("End")); 479 ffwdEndAction->setShortcut(tr("End"));
561 ffwdEndAction->setStatusTip(tr("Fast-forward to the end")); 480 ffwdEndAction->setStatusTip(tr("Fast-forward to the end"));
562 connect(ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd())); 481 connect(ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
563 connect(this, SIGNAL(canPlay(bool)), ffwdEndAction, SLOT(setEnabled(bool))); 482 connect(this, SIGNAL(canPlay(bool)), ffwdEndAction, SLOT(setEnabled(bool)));
564 /* 483
565 toolbar = addToolBar(tr("Play Mode Toolbar")); 484 toolbar = addToolBar(tr("Play Mode Toolbar"));
566 485
567 QAction *psAction = toolbar->addAction(il.load("playselection"), 486 QAction *psAction = toolbar->addAction(il.load("playselection"),
568 tr("Constrain Playback to Selection")); 487 tr("Constrain Playback to Selection"));
569 psAction->setCheckable(true); 488 psAction->setCheckable(true);
584 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)), 503 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
585 plAction, SLOT(setChecked(bool))); 504 plAction, SLOT(setChecked(bool)));
586 connect(plAction, SIGNAL(triggered()), this, SLOT(playLoopToggled())); 505 connect(plAction, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
587 connect(this, SIGNAL(canPlay(bool)), plAction, SLOT(setEnabled(bool))); 506 connect(this, SIGNAL(canPlay(bool)), plAction, SLOT(setEnabled(bool)));
588 507
589 QAction *soAction = toolbar->addAction(il.load("solo"),
590 tr("Solo Current Pane"));
591 soAction->setCheckable(true);
592 soAction->setChecked(m_viewManager->getPlaySoloMode());
593 soAction->setShortcut(tr("o"));
594 soAction->setStatusTip(tr("Solo the current pane during playback"));
595 connect(m_viewManager, SIGNAL(playSoloModeChanged(bool)),
596 soAction, SLOT(setChecked(bool)));
597 connect(soAction, SIGNAL(triggered()), this, SLOT(playSoloToggled()));
598 connect(this, SIGNAL(canPlay(bool)), soAction, SLOT(setEnabled(bool)));
599
600 m_keyReference->registerShortcut(psAction); 508 m_keyReference->registerShortcut(psAction);
601 m_keyReference->registerShortcut(plAction); 509 m_keyReference->registerShortcut(plAction);
602 m_keyReference->registerShortcut(soAction);
603 */
604 m_keyReference->registerShortcut(playAction); 510 m_keyReference->registerShortcut(playAction);
605 m_keyReference->registerShortcut(m_rwdAction); 511 m_keyReference->registerShortcut(m_rwdAction);
606 m_keyReference->registerShortcut(m_ffwdAction); 512 m_keyReference->registerShortcut(m_ffwdAction);
607 m_keyReference->registerShortcut(rwdStartAction); 513 m_keyReference->registerShortcut(rwdStartAction);
608 m_keyReference->registerShortcut(ffwdEndAction); 514 m_keyReference->registerShortcut(ffwdEndAction);
609 515
610 /* 516 menu->addAction(playAction);
611 menu->addAction(psAction); 517 menu->addAction(psAction);
612 menu->addAction(plAction); 518 menu->addAction(plAction);
613 menu->addAction(soAction);
614 */
615 menu->addAction(playAction);
616 menu->addSeparator(); 519 menu->addSeparator();
617 menu->addAction(m_rwdAction); 520 menu->addAction(m_rwdAction);
618 menu->addAction(m_ffwdAction); 521 menu->addAction(m_ffwdAction);
619 menu->addSeparator(); 522 menu->addSeparator();
620 menu->addAction(rwdStartAction); 523 menu->addAction(rwdStartAction);
621 menu->addAction(ffwdEndAction); 524 menu->addAction(ffwdEndAction);
622 menu->addSeparator(); 525 menu->addSeparator();
623 526
624 m_rightButtonPlaybackMenu->addAction(playAction); 527 m_rightButtonPlaybackMenu->addAction(playAction);
625 /*
626 m_rightButtonPlaybackMenu->addAction(psAction); 528 m_rightButtonPlaybackMenu->addAction(psAction);
627 m_rightButtonPlaybackMenu->addAction(plAction); 529 m_rightButtonPlaybackMenu->addAction(plAction);
628 m_rightButtonPlaybackMenu->addAction(soAction);
629 */
630 m_rightButtonPlaybackMenu->addSeparator(); 530 m_rightButtonPlaybackMenu->addSeparator();
631 m_rightButtonPlaybackMenu->addAction(m_rwdAction); 531 m_rightButtonPlaybackMenu->addAction(m_rwdAction);
632 m_rightButtonPlaybackMenu->addAction(m_ffwdAction); 532 m_rightButtonPlaybackMenu->addAction(m_ffwdAction);
633 m_rightButtonPlaybackMenu->addSeparator(); 533 m_rightButtonPlaybackMenu->addSeparator();
634 m_rightButtonPlaybackMenu->addAction(rwdStartAction); 534 m_rightButtonPlaybackMenu->addAction(rwdStartAction);
658 m_keyReference->registerShortcut(normalAction); 558 m_keyReference->registerShortcut(normalAction);
659 559
660 m_rightButtonPlaybackMenu->addAction(fastAction); 560 m_rightButtonPlaybackMenu->addAction(fastAction);
661 m_rightButtonPlaybackMenu->addAction(slowAction); 561 m_rightButtonPlaybackMenu->addAction(slowAction);
662 m_rightButtonPlaybackMenu->addAction(normalAction); 562 m_rightButtonPlaybackMenu->addAction(normalAction);
663 /* 563
664 toolbar = addToolBar(tr("Edit Toolbar")); 564 toolbar = addToolBar(tr("Playback Controls"));
665 CommandHistory::getInstance()->registerToolbar(toolbar); 565 toolbar->addWidget(m_playSpeed);
666 */ 566 toolbar->addWidget(m_fader);
667 567
668 Pane::registerShortcuts(*m_keyReference); 568 Pane::registerShortcuts(*m_keyReference);
669 } 569 }
670 570
671 void 571 void
723 } 623 }
724 624
725 void 625 void
726 MainWindow::updateDescriptionLabel() 626 MainWindow::updateDescriptionLabel()
727 { 627 {
728 if (!getMainModel()) { 628 // Nothing, we don't have one
729 m_descriptionLabel->setText(tr("No audio file loaded."));
730 return;
731 }
732
733 QString description;
734
735 size_t ssr = getMainModel()->getSampleRate();
736 size_t tsr = ssr;
737 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
738
739 if (ssr != tsr) {
740 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
741 } else {
742 description = QString("%1Hz").arg(ssr);
743 }
744
745 description = QString("%1 - %2")
746 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
747 .toText(false).c_str())
748 .arg(description);
749
750 m_descriptionLabel->setText(description);
751 } 629 }
752 630
753 void 631 void
754 MainWindow::documentModified() 632 MainWindow::documentModified()
755 { 633 {
774 Pane *pane = m_paneStack->addPane(); 652 Pane *pane = m_paneStack->addPane();
775 653
776 connect(pane, SIGNAL(contextHelpChanged(const QString &)), 654 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
777 this, SLOT(contextHelpChanged(const QString &))); 655 this, SLOT(contextHelpChanged(const QString &)));
778 656
779 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform); 657 // Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
780 m_document->addLayerToView(pane, waveform); 658 // m_document->addLayerToView(pane, waveform);
781 659
782 m_overview->registerView(pane); 660 m_overview->registerView(pane);
783 661
784 CommandHistory::getInstance()->clear(); 662 CommandHistory::getInstance()->clear();
785 CommandHistory::getInstance()->documentSaved(); 663 CommandHistory::getInstance()->documentSaved();
916 } 794 }
917 795
918 void 796 void
919 MainWindow::paneAdded(Pane *pane) 797 MainWindow::paneAdded(Pane *pane)
920 { 798 {
921 pane->setPlaybackFollow(PlaybackScrollContinuous); 799 pane->setPlaybackFollow(PlaybackScrollPage);
922 m_paneStack->sizePanesEqually(); 800 m_paneStack->sizePanesEqually();
923 if (m_overview) m_overview->registerView(pane); 801 if (m_overview) m_overview->registerView(pane);
924 } 802 }
925 803
926 void 804 void
978 void 856 void
979 MainWindow::configureNewPane(Pane *pane) 857 MainWindow::configureNewPane(Pane *pane)
980 { 858 {
981 std::cerr << "MainWindow::configureNewPane(" << pane << ")" << std::endl; 859 std::cerr << "MainWindow::configureNewPane(" << pane << ")" << std::endl;
982 860
983 if (!pane) return; 861 if (!pane) {
984 862 pane = m_paneStack->addPane();
985 Layer *waveformLayer = 0; 863 }
986 864
987 for (int i = 0; i < pane->getLayerCount(); ++i) { 865 m_analyser->newFileLoaded(m_document, getMainModel(), m_paneStack, pane);
988 Layer *layer = pane->getLayer(i);
989 if (!layer) continue;
990 if (qobject_cast<WaveformLayer *>(layer)) waveformLayer = layer;
991 if (qobject_cast<TimeValueLayer *>(layer)) return;
992 }
993 if (!waveformLayer) return;
994
995 waveformLayer->setObjectName(tr("Waveform"));
996
997 zoomToFit();
998 } 866 }
999 867
1000 void 868 void
1001 MainWindow::closeEvent(QCloseEvent *e) 869 MainWindow::closeEvent(QCloseEvent *e)
1002 { 870 {
1347 std::cerr << "A dense time-value model (such as an audio file) has been loaded" << std::endl; 1215 std::cerr << "A dense time-value model (such as an audio file) has been loaded" << std::endl;
1348 } 1216 }
1349 } 1217 }
1350 1218
1351 void 1219 void
1352 MainWindow::modelReady()
1353 {
1354 QObject *s = sender();
1355 std::cerr << "MainWindow::modelReady(" << s << ")" << std::endl;
1356 }
1357
1358 void
1359 MainWindow::modelAboutToBeDeleted(Model *model) 1220 MainWindow::modelAboutToBeDeleted(Model *model)
1360 { 1221 {
1361 MainWindowBase::modelAboutToBeDeleted(model); 1222 MainWindowBase::modelAboutToBeDeleted(model);
1362 } 1223 }
1363 1224