comparison framework/MainWindowBase.cpp @ 487:66b92c188cbd recording

Suspend/resume audio device when not in use to save battery (only implemented for PulseAudioIO so far)
author Chris Cannam
date Wed, 16 Sep 2015 15:16:54 +0100
parents 3dbc964f5907
children 6eb28350050d 111e976f9ed4 cd9dec2f47e8
comparison
equal deleted inserted replaced
486:3dbc964f5907 487:66b92c188cbd
2198 */ 2198 */
2199 2199
2200 if (m_soundOptions & WithAudioInput) { 2200 if (m_soundOptions & WithAudioInput) {
2201 m_audioIO = breakfastquay::AudioFactory:: 2201 m_audioIO = breakfastquay::AudioFactory::
2202 createCallbackIO(m_recordTarget, m_playSource); 2202 createCallbackIO(m_recordTarget, m_playSource);
2203 m_audioIO->suspend(); // start in suspended state
2203 m_playSource->setSystemPlaybackTarget(m_audioIO); 2204 m_playSource->setSystemPlaybackTarget(m_audioIO);
2204 } else { 2205 } else {
2205 m_playTarget = breakfastquay::AudioFactory:: 2206 m_playTarget = breakfastquay::AudioFactory::
2206 createCallbackPlayTarget(m_playSource); 2207 createCallbackPlayTarget(m_playSource);
2207 m_playSource->setSystemPlaybackTarget(m_playTarget); 2208 m_playSource->setSystemPlaybackTarget(m_playTarget);
2659 if (m_recordTarget->isRecording() || m_playSource->isPlaying()) { 2660 if (m_recordTarget->isRecording() || m_playSource->isPlaying()) {
2660 stop(); 2661 stop();
2661 QAction *action = qobject_cast<QAction *>(sender()); 2662 QAction *action = qobject_cast<QAction *>(sender());
2662 if (action) action->setChecked(false); 2663 if (action) action->setChecked(false);
2663 } else { 2664 } else {
2665 if (m_audioIO) m_audioIO->resume();
2664 playbackFrameChanged(m_viewManager->getPlaybackFrame()); 2666 playbackFrameChanged(m_viewManager->getPlaybackFrame());
2665 m_playSource->play(m_viewManager->getPlaybackFrame()); 2667 m_playSource->play(m_viewManager->getPlaybackFrame());
2666 } 2668 }
2667 } 2669 }
2668 2670
2689 } 2691 }
2690 2692
2691 if (m_audioRecordMode == RecordReplaceSession) { 2693 if (m_audioRecordMode == RecordReplaceSession) {
2692 if (!checkSaveModified()) return; 2694 if (!checkSaveModified()) return;
2693 } 2695 }
2694 2696
2697 if (m_audioIO) m_audioIO->resume();
2698
2695 WritableWaveFileModel *model = m_recordTarget->startRecording(); 2699 WritableWaveFileModel *model = m_recordTarget->startRecording();
2696 if (!model) { 2700 if (!model) {
2697 cerr << "ERROR: MainWindowBase::record: Recording failed" << endl; 2701 cerr << "ERROR: MainWindowBase::record: Recording failed" << endl;
2698 //!!! report 2702 //!!! report
2699 return; 2703 return;
2703 m_recordTarget->stopRecording(); 2707 m_recordTarget->stopRecording();
2704 delete model; 2708 delete model;
2705 //!!! ??? 2709 //!!! ???
2706 return; 2710 return;
2707 } 2711 }
2708 2712
2709 PlayParameterRepository::getInstance()->addPlayable(model); 2713 PlayParameterRepository::getInstance()->addPlayable(model);
2710 2714
2711 if (m_audioRecordMode == RecordReplaceSession || !getMainModel()) { 2715 if (m_audioRecordMode == RecordReplaceSession || !getMainModel()) {
2712 2716
2713 //!!! duplication with openAudio here 2717 //!!! duplication with openAudio here
3021 emit audioFileLoaded(); 3025 emit audioFileLoaded();
3022 } 3026 }
3023 3027
3024 m_playSource->stop(); 3028 m_playSource->stop();
3025 3029
3030 if (m_audioIO) m_audioIO->suspend();
3031
3026 if (m_paneStack && m_paneStack->getCurrentPane()) { 3032 if (m_paneStack && m_paneStack->getCurrentPane()) {
3027 updateVisibleRangeDisplay(m_paneStack->getCurrentPane()); 3033 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
3028 } else { 3034 } else {
3029 m_myStatusMessage = ""; 3035 m_myStatusMessage = "";
3030 getStatusLabel()->setText(""); 3036 getStatusLabel()->setText("");