Mercurial > hg > svapp
comparison framework/MainWindowBase.cpp @ 586:5f488e1868cc
If we can't open a record device, fall back to playback-only mode
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2017 10:16:40 +0000 |
parents | 0bb2ec333d3b |
children | 77d33ed8e753 |
comparison
equal
deleted
inserted
replaced
585:050c7b5bd11c | 586:5f488e1868cc |
---|---|
631 emit canEditLayer(haveCurrentEditableLayer); | 631 emit canEditLayer(haveCurrentEditableLayer); |
632 emit canEditLayerTabular(haveCurrentEditableLayer || haveTabularLayer); | 632 emit canEditLayerTabular(haveCurrentEditableLayer || haveTabularLayer); |
633 emit canMeasureLayer(haveCurrentLayer); | 633 emit canMeasureLayer(haveCurrentLayer); |
634 emit canSelect(haveMainModel && haveCurrentPane); | 634 emit canSelect(haveMainModel && haveCurrentPane); |
635 emit canPlay(haveMainModel && havePlayTarget); | 635 emit canPlay(haveMainModel && havePlayTarget); |
636 emit canRecord(m_recordTarget != 0); | |
637 emit canFfwd(haveMainModel); | 636 emit canFfwd(haveMainModel); |
638 emit canRewind(haveMainModel); | 637 emit canRewind(haveMainModel); |
639 emit canPaste(haveClipboardContents); | 638 emit canPaste(haveClipboardContents); |
640 emit canInsertInstant(haveCurrentPane); | 639 emit canInsertInstant(haveCurrentPane); |
641 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection); | 640 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection); |
650 emit canSaveAs(haveMainModel); | 649 emit canSaveAs(haveMainModel); |
651 emit canSelectPreviousPane(havePrevPane); | 650 emit canSelectPreviousPane(havePrevPane); |
652 emit canSelectNextPane(haveNextPane); | 651 emit canSelectNextPane(haveNextPane); |
653 emit canSelectPreviousLayer(havePrevLayer); | 652 emit canSelectPreviousLayer(havePrevLayer); |
654 emit canSelectNextLayer(haveNextLayer); | 653 emit canSelectNextLayer(haveNextLayer); |
654 | |
655 // This is quite subtle -- whereas we can play back only if a | |
656 // system play target or I/O exists, we can record even if no | |
657 // record source (i.e. audioIO) exists because we can record into | |
658 // an empty session before the audio device has been | |
659 // opened. However, if there is no record *target* then recording | |
660 // was actively disabled (flag not set in m_soundOptions). And if | |
661 // we have a play target instead of an audioIO, then we must have | |
662 // tried to open the device but failed to find any capture source. | |
663 bool recordDisabled = (m_recordTarget == nullptr); | |
664 bool recordDeviceFailed = (m_playTarget != nullptr && m_audioIO == nullptr); | |
665 emit canRecord(!recordDisabled && !recordDeviceFailed); | |
655 } | 666 } |
656 | 667 |
657 void | 668 void |
658 MainWindowBase::documentModified() | 669 MainWindowBase::documentModified() |
659 { | 670 { |
2374 createCallbackIO(m_recordTarget, m_resamplerWrapper, | 2385 createCallbackIO(m_recordTarget, m_resamplerWrapper, |
2375 preference, errorString); | 2386 preference, errorString); |
2376 if (m_audioIO) { | 2387 if (m_audioIO) { |
2377 m_audioIO->suspend(); // start in suspended state | 2388 m_audioIO->suspend(); // start in suspended state |
2378 m_playSource->setSystemPlaybackTarget(m_audioIO); | 2389 m_playSource->setSystemPlaybackTarget(m_audioIO); |
2379 } | 2390 } else { |
2380 } else { | 2391 // Failed to create audio I/O; this may just mean there is |
2392 // no record device, so fall through to see what happens | |
2393 // next. We only report complete failure if we end up with | |
2394 // neither m_audioIO nor m_playTarget. | |
2395 } | |
2396 } | |
2397 | |
2398 if (!m_audioIO) { | |
2381 m_playTarget = breakfastquay::AudioFactory:: | 2399 m_playTarget = breakfastquay::AudioFactory:: |
2382 createCallbackPlayTarget(m_resamplerWrapper, | 2400 createCallbackPlayTarget(m_resamplerWrapper, |
2383 preference, errorString); | 2401 preference, errorString); |
2384 if (m_playTarget) { | 2402 if (m_playTarget) { |
2385 m_playTarget->suspend(); // start in suspended state | 2403 m_playTarget->suspend(); // start in suspended state |
2922 } | 2940 } |
2923 | 2941 |
2924 void | 2942 void |
2925 MainWindowBase::record() | 2943 MainWindowBase::record() |
2926 { | 2944 { |
2945 QAction *action = qobject_cast<QAction *>(sender()); | |
2946 | |
2927 if (!(m_soundOptions & WithAudioInput)) { | 2947 if (!(m_soundOptions & WithAudioInput)) { |
2948 if (action) action->setChecked(false); | |
2928 return; | 2949 return; |
2929 } | 2950 } |
2930 | 2951 |
2931 if (!m_recordTarget) { | 2952 if (!m_recordTarget) { |
2932 //!!! report | 2953 if (action) action->setChecked(false); |
2933 return; | 2954 return; |
2934 } | 2955 } |
2935 | 2956 |
2936 if (!m_audioIO) { | 2957 if (!m_audioIO) { |
2937 cerr << "MainWindowBase::record: about to create audio IO" << endl; | 2958 cerr << "MainWindowBase::record: about to create audio IO" << endl; |
2938 createAudioIO(); | 2959 createAudioIO(); |
2939 } | 2960 } |
2940 | 2961 |
2941 if (!m_audioIO) { | 2962 if (!m_audioIO) { |
2942 // don't need to report this, createAudioIO already should have | 2963 if (!m_playTarget) { |
2943 return; | 2964 // Don't need to report this, createAudioIO should have |
2965 if (action) action->setChecked(false); | |
2966 return; | |
2967 } else { | |
2968 // Need to report this: if the play target exists instead | |
2969 // of the audio IO, then that means we failed to open a | |
2970 // capture device. The record control should be disabled | |
2971 // in that situation, so if it happens here, that must | |
2972 // mean this is the first time we ever tried to open the | |
2973 // audio device, hence the need to report the problem here | |
2974 QMessageBox::critical | |
2975 (this, tr("No record device available"), | |
2976 tr("<b>No record device available</b><p>Failed to find or open an audio device for recording. Only playback will be available.</p>")); | |
2977 if (action) action->setChecked(false); | |
2978 updateMenuStates(); | |
2979 return; | |
2980 } | |
2944 } | 2981 } |
2945 | 2982 |
2946 if (m_recordTarget->isRecording()) { | 2983 if (m_recordTarget->isRecording()) { |
2947 stop(); | 2984 stop(); |
2948 return; | 2985 return; |
2949 } | 2986 } |
2950 | |
2951 QAction *action = qobject_cast<QAction *>(sender()); | |
2952 | 2987 |
2953 if (m_audioRecordMode == RecordReplaceSession) { | 2988 if (m_audioRecordMode == RecordReplaceSession) { |
2954 if (!checkSaveModified()) { | 2989 if (!checkSaveModified()) { |
2955 if (action) action->setChecked(false); | 2990 if (action) action->setChecked(false); |
2956 return; | 2991 return; |
2957 } | 2992 } |
2958 } | 2993 } |
2959 | 2994 |
2960 if (m_viewManager) m_viewManager->setGlobalCentreFrame(0); | 2995 if (m_viewManager) m_viewManager->setGlobalCentreFrame(0); |
2961 | 2996 |
2962 cerr << "MainWindowBase::record: about to resume" << endl; | 2997 SVDEBUG << "MainWindowBase::record: about to resume" << endl; |
2963 m_audioIO->resume(); | 2998 m_audioIO->resume(); |
2964 | 2999 |
2965 WritableWaveFileModel *model = m_recordTarget->startRecording(); | 3000 WritableWaveFileModel *model = m_recordTarget->startRecording(); |
2966 if (!model) { | 3001 if (!model) { |
2967 cerr << "ERROR: MainWindowBase::record: Recording failed" << endl; | 3002 SVCERR << "ERROR: MainWindowBase::record: Recording failed" << endl; |
2968 //!!! report | 3003 QMessageBox::critical |
3004 (this, tr("Recording failed"), | |
3005 tr("<b>Recording failed</b><p>Failed to switch to record mode (some internal problem?)</p>")); | |
2969 if (action) action->setChecked(false); | 3006 if (action) action->setChecked(false); |
2970 return; | 3007 return; |
2971 } | 3008 } |
2972 | 3009 |
2973 if (!model->isOK()) { | 3010 if (!model->isOK()) { |
2974 m_recordTarget->stopRecording(); | 3011 m_recordTarget->stopRecording(); |
2975 m_audioIO->suspend(); | 3012 m_audioIO->suspend(); |
3013 if (action) action->setChecked(false); | |
2976 delete model; | 3014 delete model; |
2977 return; | 3015 return; |
2978 } | 3016 } |
2979 | 3017 |
2980 PlayParameterRepository::getInstance()->addPlayable(model); | 3018 PlayParameterRepository::getInstance()->addPlayable(model); |