comparison view/ViewManager.cpp @ 1324:13d9b422f7fe zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:31 +0100
parents 61418c112281
children 646e713a4632
comparison
equal deleted inserted replaced
1183:57d192e26331 1324:13d9b422f7fe
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "ViewManager.h" 16 #include "ViewManager.h"
17 #include "base/AudioPlaySource.h" 17 #include "base/AudioPlaySource.h"
18 #include "base/AudioRecordTarget.h"
18 #include "base/RealTime.h" 19 #include "base/RealTime.h"
19 #include "data/model/Model.h" 20 #include "data/model/Model.h"
20 #include "widgets/CommandHistory.h" 21 #include "widgets/CommandHistory.h"
21 #include "View.h" 22 #include "View.h"
22 #include "Overview.h" 23 #include "Overview.h"
28 29
29 //#define DEBUG_VIEW_MANAGER 1 30 //#define DEBUG_VIEW_MANAGER 1
30 31
31 ViewManager::ViewManager() : 32 ViewManager::ViewManager() :
32 m_playSource(0), 33 m_playSource(0),
34 m_recordTarget(0),
33 m_globalCentreFrame(0), 35 m_globalCentreFrame(0),
34 m_globalZoom(1024), 36 m_globalZoom(1024),
35 m_playbackFrame(0), 37 m_playbackFrame(0),
36 m_playbackModel(0), 38 m_playbackModel(0),
37 m_mainModelSampleRate(0), 39 m_mainModelSampleRate(0),
155 } 157 }
156 158
157 sv_frame_t 159 sv_frame_t
158 ViewManager::getPlaybackFrame() const 160 ViewManager::getPlaybackFrame() const
159 { 161 {
160 if (m_playSource && m_playSource->isPlaying()) { 162 if (isRecording()) {
161 m_playbackFrame = m_playSource->getCurrentPlayingFrame(); 163 m_playbackFrame = m_recordTarget->getRecordDuration();
164 #ifdef DEBUG_VIEW_MANAGER
165 cout << "ViewManager::getPlaybackFrame(recording) -> " << m_playbackFrame << endl;
166 #endif
167 } else if (isPlaying()) {
168 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
169 #ifdef DEBUG_VIEW_MANAGER
170 cout << "ViewManager::getPlaybackFrame(playing) -> " << m_playbackFrame << endl;
171 #endif
172 } else {
173 #ifdef DEBUG_VIEW_MANAGER
174 cout << "ViewManager::getPlaybackFrame(not playing) -> " << m_playbackFrame << endl;
175 #endif
162 } 176 }
163 return m_playbackFrame; 177 return m_playbackFrame;
164 } 178 }
165 179
166 void 180 void
167 ViewManager::setPlaybackFrame(sv_frame_t f) 181 ViewManager::setPlaybackFrame(sv_frame_t f)
168 { 182 {
183 #ifdef DEBUG_VIEW_MANAGER
184 cerr << "ViewManager::setPlaybackFrame(" << f << ")" << endl;
185 #endif
169 if (f < 0) f = 0; 186 if (f < 0) f = 0;
170 if (m_playbackFrame != f) { 187 if (m_playbackFrame != f) {
171 m_playbackFrame = f; 188 m_playbackFrame = f;
172 emit playbackFrameChanged(f); 189 emit playbackFrameChanged(f);
173 if (m_playSource && m_playSource->isPlaying()) { 190 if (isPlaying()) {
174 m_playSource->play(f); 191 m_playSource->play(f);
175 } 192 }
176 } 193 }
177 } 194 }
178 195
179 Model * 196 Model *
180 ViewManager::getPlaybackModel() const 197 ViewManager::getPlaybackModel() const
340 { 357 {
341 emit selectionChanged(); 358 emit selectionChanged();
342 } 359 }
343 360
344 ViewManager::SetSelectionCommand::SetSelectionCommand(ViewManager *vm, 361 ViewManager::SetSelectionCommand::SetSelectionCommand(ViewManager *vm,
345 const MultiSelection &ms) : 362 const MultiSelection &ms) :
346 m_vm(vm), 363 m_vm(vm),
347 m_oldSelection(vm->m_selections), 364 m_oldSelection(vm->m_selections),
348 m_newSelection(ms) 365 m_newSelection(ms)
349 { 366 {
350 } 367 }
490 507
491 sv_samplerate_t 508 sv_samplerate_t
492 ViewManager::getDeviceSampleRate() const 509 ViewManager::getDeviceSampleRate() const
493 { 510 {
494 if (m_playSource) { 511 if (m_playSource) {
495 return m_playSource->getDeviceSampleRate(); 512 return m_playSource->getDeviceSampleRate();
496 } 513 }
497 return 0; 514 return 0;
498 } 515 }
499 516
500 void 517 void
501 ViewManager::setAudioPlaySource(AudioPlaySource *source) 518 ViewManager::setAudioPlaySource(AudioPlaySource *source)
502 { 519 {
503 if (!m_playSource) { 520 if (!m_playSource) {
504 QTimer::singleShot(100, this, SLOT(checkPlayStatus())); 521 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
505 } 522 }
506 m_playSource = source; 523 m_playSource = source;
507 } 524 }
508 525
509 void 526 void
527 ViewManager::setAudioRecordTarget(AudioRecordTarget *target)
528 {
529 if (!m_recordTarget) {
530 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
531 }
532 m_recordTarget = target;
533 }
534
535 void
510 ViewManager::playStatusChanged(bool /* playing */) 536 ViewManager::playStatusChanged(bool /* playing */)
511 { 537 {
512 #ifdef DEBUG_VIEW_MANAGER 538 #ifdef DEBUG_VIEW_MANAGER
513 cerr << "ViewManager::playStatusChanged" << endl; 539 cerr << "ViewManager::playStatusChanged" << endl;
514 #endif 540 #endif
515 checkPlayStatus(); 541 checkPlayStatus();
516 } 542 }
517 543
518 void 544 void
545 ViewManager::recordStatusChanged(bool /* recording */)
546 {
547 #ifdef DEBUG_VIEW_MANAGER
548 cerr << "ViewManager::recordStatusChanged" << endl;
549 #endif
550 checkPlayStatus();
551 }
552
553 void
519 ViewManager::checkPlayStatus() 554 ViewManager::checkPlayStatus()
520 { 555 {
521 if (m_playSource && m_playSource->isPlaying()) { 556 if (isRecording()) {
522 557
523 float left = 0, right = 0; 558 float left = 0, right = 0;
524 if (m_playSource->getOutputLevels(left, right)) { 559 if (m_recordTarget->getInputLevels(left, right)) {
525 if (left != m_lastLeft || right != m_lastRight) { 560 if (left != m_lastLeft || right != m_lastRight) {
526 emit outputLevelsChanged(left, right); 561 emit monitoringLevelsChanged(left, right);
527 m_lastLeft = left; 562 m_lastLeft = left;
528 m_lastRight = right; 563 m_lastRight = right;
529 } 564 }
530 } 565 }
531 566
532 m_playbackFrame = m_playSource->getCurrentPlayingFrame(); 567 m_playbackFrame = m_recordTarget->getRecordDuration();
533 568
534 #ifdef DEBUG_VIEW_MANAGER 569 #ifdef DEBUG_VIEW_MANAGER
535 cerr << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl; 570 cerr << "ViewManager::checkPlayStatus: Recording, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
536 #endif 571 #endif
537 572
538 emit playbackFrameChanged(m_playbackFrame); 573 emit playbackFrameChanged(m_playbackFrame);
539 574
540 QTimer::singleShot(20, this, SLOT(checkPlayStatus())); 575 QTimer::singleShot(500, this, SLOT(checkPlayStatus()));
541 576
542 } else { 577 } else if (isPlaying()) {
543 578
544 if (m_lastLeft != 0.0 || m_lastRight != 0.0) { 579 float left = 0, right = 0;
545 emit outputLevelsChanged(0.0, 0.0); 580 if (m_playSource->getOutputLevels(left, right)) {
546 m_lastLeft = 0.0; 581 if (left != m_lastLeft || right != m_lastRight) {
547 m_lastRight = 0.0; 582 emit monitoringLevelsChanged(left, right);
548 } 583 m_lastLeft = left;
549 584 m_lastRight = right;
550 #ifdef DEBUG_VIEW_MANAGER 585 }
551 cerr << "ViewManager::checkPlayStatus: Not playing" << endl; 586 }
587
588 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
589
590 #ifdef DEBUG_VIEW_MANAGER
591 cerr << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
592 #endif
593
594 emit playbackFrameChanged(m_playbackFrame);
595
596 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
597
598 } else {
599
600 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
601 emit monitoringLevelsChanged(0.0, 0.0);
602 m_lastLeft = 0.0;
603 m_lastRight = 0.0;
604 }
605
606 #ifdef DEBUG_VIEW_MANAGER
607 cerr << "ViewManager::checkPlayStatus: Not playing or recording" << endl;
552 #endif 608 #endif
553 } 609 }
554 } 610 }
555 611
556 bool 612 bool
557 ViewManager::isPlaying() const 613 ViewManager::isPlaying() const
558 { 614 {
559 return m_playSource && m_playSource->isPlaying(); 615 return m_playSource && m_playSource->isPlaying();
616 }
617
618 bool
619 ViewManager::isRecording() const
620 {
621 return m_recordTarget && m_recordTarget->isRecording();
560 } 622 }
561 623
562 void 624 void
563 ViewManager::viewCentreFrameChanged(sv_frame_t f, bool locked, 625 ViewManager::viewCentreFrameChanged(sv_frame_t f, bool locked,
564 PlaybackFollowMode mode) 626 PlaybackFollowMode mode)
595 { 657 {
596 #ifdef DEBUG_VIEW_MANAGER 658 #ifdef DEBUG_VIEW_MANAGER
597 cerr << "ViewManager::seek(" << f << ")" << endl; 659 cerr << "ViewManager::seek(" << f << ")" << endl;
598 #endif 660 #endif
599 661
600 if (m_playSource && m_playSource->isPlaying()) { 662 if (isRecording()) {
601 sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame(); 663 // ignore
602 sv_frame_t diff = std::max(f, playFrame) - std::min(f, playFrame); 664 #ifdef DEBUG_VIEW_MANAGER
603 if (diff > 20000) { 665 cerr << "ViewManager::seek: Ignoring during recording" << endl;
604 m_playbackFrame = f; 666 #endif
605 m_playSource->play(f); 667 return;
668 }
669
670 if (isPlaying()) {
671 sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame();
672 sv_frame_t diff = std::max(f, playFrame) - std::min(f, playFrame);
673 if (diff > 20000) {
674 m_playbackFrame = f;
675 m_playSource->play(f);
606 #ifdef DEBUG_VIEW_MANAGER 676 #ifdef DEBUG_VIEW_MANAGER
607 cerr << "ViewManager::considerSeek: reseeking from " << playFrame << " to " << f << endl; 677 cerr << "ViewManager::seek: reseeking from " << playFrame << " to " << f << endl;
608 #endif 678 #endif
609 emit playbackFrameChanged(f); 679 emit playbackFrameChanged(f);
610 } 680 }
611 } else { 681 } else {
612 if (m_playbackFrame != f) { 682 if (m_playbackFrame != f) {
613 m_playbackFrame = f; 683 m_playbackFrame = f;
614 emit playbackFrameChanged(f); 684 emit playbackFrameChanged(f);
615 } 685 }
627 } 697 }
628 698
629 //!!! emit zoomLevelChanged(); 699 //!!! emit zoomLevelChanged();
630 700
631 if (locked) { 701 if (locked) {
632 m_globalZoom = z; 702 m_globalZoom = z;
633 } 703 }
634 704
635 #ifdef DEBUG_VIEW_MANAGER 705 #ifdef DEBUG_VIEW_MANAGER
636 cerr << "ViewManager::viewZoomLevelChanged(" << v << ", " << z << ", " << locked << ")" << endl; 706 cerr << "ViewManager::viewZoomLevelChanged(" << v << ", " << z << ", " << locked << ")" << endl;
637 #endif 707 #endif
732 #else 802 #else
733 baseEm = 15.0; 803 baseEm = 15.0;
734 #endif 804 #endif
735 double em = QFontMetrics(QFont()).height(); 805 double em = QFontMetrics(QFont()).height();
736 ratio = em / baseEm; 806 ratio = em / baseEm;
807
808 SVDEBUG << "ViewManager::scalePixelSize: ratio is " << ratio
809 << " (em = " << em << ")" << endl;
737 } 810 }
738 811
739 int scaled = int(pixels * ratio + 0.5); 812 int scaled = int(pixels * ratio + 0.5);
740 // cerr << "scaledSize: " << pixels << " -> " << scaled << " at ratio " << ratio << endl; 813 // SVDEBUG << "scaledSize: " << pixels << " -> " << scaled << " at ratio " << ratio << endl;
741 if (pixels != 0 && scaled == 0) scaled = 1; 814 if (pixels != 0 && scaled == 0) scaled = 1;
742 return scaled; 815 return scaled;
743 } 816 }
744 817