Mercurial > hg > svgui
comparison view/ViewManager.cpp @ 1210:efc7586de499 3.0-integration
Wire up record monitoring
author | Chris Cannam |
---|---|
date | Wed, 04 Jan 2017 16:03:12 +0000 |
parents | f32828ea63d9 |
children | d25f1f99c6fa |
comparison
equal
deleted
inserted
replaced
1209:f7bb22999d2e | 1210:efc7586de499 |
---|---|
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(); |
162 #ifdef DEBUG_VIEW_MANAGER | 169 #ifdef DEBUG_VIEW_MANAGER |
163 cout << "ViewManager::getPlaybackFrame(playing) -> " << m_playbackFrame << endl; | 170 cout << "ViewManager::getPlaybackFrame(playing) -> " << m_playbackFrame << endl; |
164 #endif | 171 #endif |
165 } else { | 172 } else { |
178 #endif | 185 #endif |
179 if (f < 0) f = 0; | 186 if (f < 0) f = 0; |
180 if (m_playbackFrame != f) { | 187 if (m_playbackFrame != f) { |
181 m_playbackFrame = f; | 188 m_playbackFrame = f; |
182 emit playbackFrameChanged(f); | 189 emit playbackFrameChanged(f); |
183 if (m_playSource && m_playSource->isPlaying()) { | 190 if (isPlaying()) { |
184 m_playSource->play(f); | 191 m_playSource->play(f); |
185 } | 192 } |
186 } | 193 } |
187 } | 194 } |
188 | 195 |
515 } | 522 } |
516 m_playSource = source; | 523 m_playSource = source; |
517 } | 524 } |
518 | 525 |
519 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 | |
520 ViewManager::playStatusChanged(bool /* playing */) | 536 ViewManager::playStatusChanged(bool /* playing */) |
521 { | 537 { |
522 #ifdef DEBUG_VIEW_MANAGER | 538 #ifdef DEBUG_VIEW_MANAGER |
523 cerr << "ViewManager::playStatusChanged" << endl; | 539 cerr << "ViewManager::playStatusChanged" << endl; |
524 #endif | 540 #endif |
525 checkPlayStatus(); | 541 checkPlayStatus(); |
526 } | 542 } |
527 | 543 |
528 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 | |
529 ViewManager::checkPlayStatus() | 554 ViewManager::checkPlayStatus() |
530 { | 555 { |
531 if (m_playSource && m_playSource->isPlaying()) { | 556 if (isRecording()) { |
532 | 557 |
533 float left = 0, right = 0; | 558 float left = 0, right = 0; |
534 if (m_playSource->getOutputLevels(left, right)) { | 559 if (m_recordTarget->getInputLevels(left, right)) { |
535 if (left != m_lastLeft || right != m_lastRight) { | 560 if (left != m_lastLeft || right != m_lastRight) { |
536 emit outputLevelsChanged(left, right); | 561 emit monitoringLevelsChanged(left, right); |
537 m_lastLeft = left; | 562 m_lastLeft = left; |
538 m_lastRight = right; | 563 m_lastRight = right; |
539 } | 564 } |
540 } | 565 } |
541 | 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 | |
542 m_playbackFrame = m_playSource->getCurrentPlayingFrame(); | 588 m_playbackFrame = m_playSource->getCurrentPlayingFrame(); |
543 | 589 |
544 #ifdef DEBUG_VIEW_MANAGER | 590 #ifdef DEBUG_VIEW_MANAGER |
545 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; |
546 #endif | 592 #endif |
550 QTimer::singleShot(20, this, SLOT(checkPlayStatus())); | 596 QTimer::singleShot(20, this, SLOT(checkPlayStatus())); |
551 | 597 |
552 } else { | 598 } else { |
553 | 599 |
554 if (m_lastLeft != 0.0 || m_lastRight != 0.0) { | 600 if (m_lastLeft != 0.0 || m_lastRight != 0.0) { |
555 emit outputLevelsChanged(0.0, 0.0); | 601 emit monitoringLevelsChanged(0.0, 0.0); |
556 m_lastLeft = 0.0; | 602 m_lastLeft = 0.0; |
557 m_lastRight = 0.0; | 603 m_lastRight = 0.0; |
558 } | 604 } |
559 | 605 |
560 #ifdef DEBUG_VIEW_MANAGER | 606 #ifdef DEBUG_VIEW_MANAGER |
561 cerr << "ViewManager::checkPlayStatus: Not playing" << endl; | 607 cerr << "ViewManager::checkPlayStatus: Not playing or recording" << endl; |
562 #endif | 608 #endif |
563 } | 609 } |
564 } | 610 } |
565 | 611 |
566 bool | 612 bool |
567 ViewManager::isPlaying() const | 613 ViewManager::isPlaying() const |
568 { | 614 { |
569 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(); | |
570 } | 622 } |
571 | 623 |
572 void | 624 void |
573 ViewManager::viewCentreFrameChanged(sv_frame_t f, bool locked, | 625 ViewManager::viewCentreFrameChanged(sv_frame_t f, bool locked, |
574 PlaybackFollowMode mode) | 626 PlaybackFollowMode mode) |
605 { | 657 { |
606 #ifdef DEBUG_VIEW_MANAGER | 658 #ifdef DEBUG_VIEW_MANAGER |
607 cerr << "ViewManager::seek(" << f << ")" << endl; | 659 cerr << "ViewManager::seek(" << f << ")" << endl; |
608 #endif | 660 #endif |
609 | 661 |
610 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()) { | |
611 sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame(); | 671 sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame(); |
612 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); |
613 if (diff > 20000) { | 673 if (diff > 20000) { |
614 m_playbackFrame = f; | 674 m_playbackFrame = f; |
615 m_playSource->play(f); | 675 m_playSource->play(f); |
616 #ifdef DEBUG_VIEW_MANAGER | 676 #ifdef DEBUG_VIEW_MANAGER |
617 cerr << "ViewManager::considerSeek: reseeking from " << playFrame << " to " << f << endl; | 677 cerr << "ViewManager::seek: reseeking from " << playFrame << " to " << f << endl; |
618 #endif | 678 #endif |
619 emit playbackFrameChanged(f); | 679 emit playbackFrameChanged(f); |
620 } | 680 } |
621 } else { | 681 } else { |
622 if (m_playbackFrame != f) { | 682 if (m_playbackFrame != f) { |