Mercurial > hg > svgui
comparison view/ViewManager.cpp @ 1216:dc2af6616c83
Merge from branch 3.0-integration
author | Chris Cannam |
---|---|
date | Fri, 13 Jan 2017 10:29:50 +0000 |
parents | efc7586de499 |
children | d25f1f99c6fa |
comparison
equal
deleted
inserted
replaced
1048:e8102ff5573b | 1216:dc2af6616c83 |
---|---|
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()) { |
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()) { | |
161 m_playbackFrame = m_playSource->getCurrentPlayingFrame(); | 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 |
487 } | 504 } |
488 return 0; | 505 return 0; |
489 } | 506 } |
490 | 507 |
491 sv_samplerate_t | 508 sv_samplerate_t |
492 ViewManager::getOutputSampleRate() const | 509 ViewManager::getDeviceSampleRate() const |
493 { | 510 { |
494 if (m_playSource) { | 511 if (m_playSource) { |
495 return m_playSource->getTargetSampleRate(); | 512 return m_playSource->getDeviceSampleRate(); |
496 } | 513 } |
497 return 0; | 514 return 0; |
498 } | 515 } |
499 | 516 |
500 void | 517 void |
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 |
567 m_playbackFrame = m_recordTarget->getRecordDuration(); | |
568 | |
569 #ifdef DEBUG_VIEW_MANAGER | |
570 cerr << "ViewManager::checkPlayStatus: Recording, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl; | |
571 #endif | |
572 | |
573 emit playbackFrameChanged(m_playbackFrame); | |
574 | |
575 QTimer::singleShot(500, this, SLOT(checkPlayStatus())); | |
576 | |
577 } else if (isPlaying()) { | |
578 | |
579 float left = 0, right = 0; | |
580 if (m_playSource->getOutputLevels(left, right)) { | |
581 if (left != m_lastLeft || right != m_lastRight) { | |
582 emit monitoringLevelsChanged(left, right); | |
583 m_lastLeft = left; | |
584 m_lastRight = right; | |
585 } | |
586 } | |
587 | |
532 m_playbackFrame = m_playSource->getCurrentPlayingFrame(); | 588 m_playbackFrame = m_playSource->getCurrentPlayingFrame(); |
533 | 589 |
534 #ifdef DEBUG_VIEW_MANAGER | 590 #ifdef DEBUG_VIEW_MANAGER |
535 cerr << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl; | 591 cerr << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl; |
536 #endif | 592 #endif |
540 QTimer::singleShot(20, this, SLOT(checkPlayStatus())); | 596 QTimer::singleShot(20, this, SLOT(checkPlayStatus())); |
541 | 597 |
542 } else { | 598 } else { |
543 | 599 |
544 if (m_lastLeft != 0.0 || m_lastRight != 0.0) { | 600 if (m_lastLeft != 0.0 || m_lastRight != 0.0) { |
545 emit outputLevelsChanged(0.0, 0.0); | 601 emit monitoringLevelsChanged(0.0, 0.0); |
546 m_lastLeft = 0.0; | 602 m_lastLeft = 0.0; |
547 m_lastRight = 0.0; | 603 m_lastRight = 0.0; |
548 } | 604 } |
549 | 605 |
550 #ifdef DEBUG_VIEW_MANAGER | 606 #ifdef DEBUG_VIEW_MANAGER |
551 cerr << "ViewManager::checkPlayStatus: Not playing" << endl; | 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()) { |
663 // ignore | |
664 #ifdef DEBUG_VIEW_MANAGER | |
665 cerr << "ViewManager::seek: Ignoring during recording" << endl; | |
666 #endif | |
667 return; | |
668 } | |
669 | |
670 if (isPlaying()) { | |
601 sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame(); | 671 sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame(); |
602 sv_frame_t diff = std::max(f, playFrame) - std::min(f, playFrame); | 672 sv_frame_t diff = std::max(f, playFrame) - std::min(f, playFrame); |
603 if (diff > 20000) { | 673 if (diff > 20000) { |
604 m_playbackFrame = f; | 674 m_playbackFrame = f; |
605 m_playSource->play(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) { |
739 int scaled = int(pixels * ratio + 0.5); | 809 int scaled = int(pixels * ratio + 0.5); |
740 // cerr << "scaledSize: " << pixels << " -> " << scaled << " at ratio " << ratio << endl; | 810 // cerr << "scaledSize: " << pixels << " -> " << scaled << " at ratio " << ratio << endl; |
741 if (pixels != 0 && scaled == 0) scaled = 1; | 811 if (pixels != 0 && scaled == 0) scaled = 1; |
742 return scaled; | 812 return scaled; |
743 } | 813 } |
814 |