comparison framework/MainWindowBase.cpp @ 564:07e111dd5902 levelpanwidget

Merge from branch 3.0-integration
author Chris Cannam
date Wed, 14 Dec 2016 14:28:41 +0000
parents 7b115a6505b8
children 1cc23cee4ebf 58354f2934ec
comparison
equal deleted inserted replaced
545:fcac6c6b8deb 564:07e111dd5902
74 #include "data/midi/MIDIInput.h" 74 #include "data/midi/MIDIInput.h"
75 75
76 #include <bqaudioio/SystemPlaybackTarget.h> 76 #include <bqaudioio/SystemPlaybackTarget.h>
77 #include <bqaudioio/SystemAudioIO.h> 77 #include <bqaudioio/SystemAudioIO.h>
78 #include <bqaudioio/AudioFactory.h> 78 #include <bqaudioio/AudioFactory.h>
79 #include <bqaudioio/ResamplerWrapper.h>
79 80
80 #include <QApplication> 81 #include <QApplication>
81 #include <QMessageBox> 82 #include <QMessageBox>
82 #include <QGridLayout> 83 #include <QGridLayout>
83 #include <QLabel> 84 #include <QLabel>
139 m_viewManager(0), 140 m_viewManager(0),
140 m_timeRulerLayer(0), 141 m_timeRulerLayer(0),
141 m_soundOptions(options), 142 m_soundOptions(options),
142 m_playSource(0), 143 m_playSource(0),
143 m_recordTarget(0), 144 m_recordTarget(0),
145 m_resamplerWrapper(0),
144 m_playTarget(0), 146 m_playTarget(0),
145 m_audioIO(0), 147 m_audioIO(0),
146 m_oscQueue(0), 148 m_oscQueue(0),
147 m_oscQueueStarter(0), 149 m_oscQueueStarter(0),
148 m_midiInput(0), 150 m_midiInput(0),
238 this, SLOT(recordDurationChanged(sv_frame_t, sv_samplerate_t))); 240 this, SLOT(recordDurationChanged(sv_frame_t, sv_samplerate_t)));
239 } 241 }
240 242
241 connect(m_playSource, SIGNAL(sampleRateMismatch(sv_samplerate_t, sv_samplerate_t, bool)), 243 connect(m_playSource, SIGNAL(sampleRateMismatch(sv_samplerate_t, sv_samplerate_t, bool)),
242 this, SLOT(sampleRateMismatch(sv_samplerate_t, sv_samplerate_t, bool))); 244 this, SLOT(sampleRateMismatch(sv_samplerate_t, sv_samplerate_t, bool)));
245 connect(m_playSource, SIGNAL(channelCountIncreased()),
246 this, SLOT(recreateAudioIO()));
243 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()), 247 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
244 this, SLOT(audioOverloadPluginDisabled())); 248 this, SLOT(audioOverloadPluginDisabled()));
245 connect(m_playSource, SIGNAL(audioTimeStretchMultiChannelDisabled()), 249 connect(m_playSource, SIGNAL(audioTimeStretchMultiChannelDisabled()),
246 this, SLOT(audioTimeStretchMultiChannelDisabled())); 250 this, SLOT(audioTimeStretchMultiChannelDisabled()));
247 251
291 // We have to delete the breakfastquay::SystemPlaybackTarget or 295 // We have to delete the breakfastquay::SystemPlaybackTarget or
292 // breakfastquay::SystemAudioIO object (whichever we have -- it 296 // breakfastquay::SystemAudioIO object (whichever we have -- it
293 // depends on whether we handle recording or not) before we delete 297 // depends on whether we handle recording or not) before we delete
294 // the ApplicationPlaybackSource and ApplicationRecordTarget that 298 // the ApplicationPlaybackSource and ApplicationRecordTarget that
295 // they refer to. 299 // they refer to.
296 300
297 // First prevent this trying to call target. 301 deleteAudioIO();
298 if (m_playSource) m_playSource->setSystemPlaybackTarget(0);
299
300 // Then delete the breakfastquay::System object.
301 // Only one of these two exists!
302 delete m_audioIO;
303 delete m_playTarget;
304 302
305 // Then delete the Application objects. 303 // Then delete the Application objects.
306 delete m_playSource; 304 delete m_playSource;
307 delete m_recordTarget; 305 delete m_recordTarget;
308 306
1397 sv_samplerate_t rate = 0; 1395 sv_samplerate_t rate = 0;
1398 1396
1399 if (Preferences::getInstance()->getFixedSampleRate() != 0) { 1397 if (Preferences::getInstance()->getFixedSampleRate() != 0) {
1400 rate = Preferences::getInstance()->getFixedSampleRate(); 1398 rate = Preferences::getInstance()->getFixedSampleRate();
1401 } else if (Preferences::getInstance()->getResampleOnLoad()) { 1399 } else if (Preferences::getInstance()->getResampleOnLoad()) {
1402 rate = m_playSource->getSourceSampleRate(); 1400 if (getMainModel()) {
1401 rate = getMainModel()->getSampleRate();
1402 }
1403 } 1403 }
1404 1404
1405 ReadOnlyWaveFileModel *newModel = new ReadOnlyWaveFileModel(source, rate); 1405 ReadOnlyWaveFileModel *newModel = new ReadOnlyWaveFileModel(source, rate);
1406 1406
1407 if (!newModel->isOK()) { 1407 if (!newModel->isOK()) {
2156 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash())); 2156 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
2157 2157
2158 if (getMainModel()) { 2158 if (getMainModel()) {
2159 rate = getMainModel()->getSampleRate(); 2159 rate = getMainModel()->getSampleRate();
2160 } else if (Preferences::getInstance()->getResampleOnLoad()) { 2160 } else if (Preferences::getInstance()->getResampleOnLoad()) {
2161 rate = m_playSource->getSourceSampleRate(); 2161 if (getMainModel()) {
2162 rate = getMainModel()->getSampleRate();
2163 }
2162 } 2164 }
2163 2165
2164 RDFImporter importer 2166 RDFImporter importer
2165 (QUrl::fromLocalFile(source.getLocalFilename()).toString(), rate); 2167 (QUrl::fromLocalFile(source.getLocalFilename()).toString(), rate);
2166 2168
2298 { 2300 {
2299 if (m_playTarget || m_audioIO) return; 2301 if (m_playTarget || m_audioIO) return;
2300 2302
2301 if (!(m_soundOptions & WithAudioOutput)) return; 2303 if (!(m_soundOptions & WithAudioOutput)) return;
2302 2304
2303 //!!! how to handle preferences
2304 /*
2305 QSettings settings; 2305 QSettings settings;
2306 settings.beginGroup("Preferences"); 2306 settings.beginGroup("Preferences");
2307 QString targetName = settings.value("audio-target", "").toString(); 2307 QString implementation = settings.value
2308 ("audio-target", "").toString();
2309 QString suffix;
2310 if (implementation != "") suffix = "-" + implementation;
2311 QString recordDevice = settings.value
2312 ("audio-record-device" + suffix, "").toString();
2313 QString playbackDevice = settings.value
2314 ("audio-playback-device" + suffix, "").toString();
2308 settings.endGroup(); 2315 settings.endGroup();
2309 AudioTargetFactory *factory = AudioTargetFactory::getInstance(); 2316
2310 2317 if (implementation == "auto") {
2311 factory->setDefaultCallbackTarget(targetName); 2318 implementation = "";
2312 */ 2319 }
2313 2320
2321 breakfastquay::AudioFactory::Preference preference;
2322 preference.implementation = implementation.toStdString();
2323 preference.recordDevice = recordDevice.toStdString();
2324 preference.playbackDevice = playbackDevice.toStdString();
2325
2326 SVCERR << "createAudioIO: Preferred implementation = \""
2327 << preference.implementation << "\"" << endl;
2328 SVCERR << "createAudioIO: Preferred playback device = \""
2329 << preference.playbackDevice << "\"" << endl;
2330 SVCERR << "createAudioIO: Preferred record device = \""
2331 << preference.recordDevice << "\"" << endl;
2332
2333 if (!m_resamplerWrapper) {
2334 m_resamplerWrapper = new breakfastquay::ResamplerWrapper(m_playSource);
2335 m_playSource->setResamplerWrapper(m_resamplerWrapper);
2336 }
2337
2314 if (m_soundOptions & WithAudioInput) { 2338 if (m_soundOptions & WithAudioInput) {
2315 m_audioIO = breakfastquay::AudioFactory:: 2339 m_audioIO = breakfastquay::AudioFactory::
2316 createCallbackIO(m_recordTarget, m_playSource); 2340 createCallbackIO(m_recordTarget, m_resamplerWrapper, preference);
2317 if (m_audioIO) { 2341 if (m_audioIO) {
2318 m_audioIO->suspend(); // start in suspended state 2342 m_audioIO->suspend(); // start in suspended state
2319 m_playSource->setSystemPlaybackTarget(m_audioIO); 2343 m_playSource->setSystemPlaybackTarget(m_audioIO);
2320 } 2344 }
2321 } else { 2345 } else {
2322 m_playTarget = breakfastquay::AudioFactory:: 2346 m_playTarget = breakfastquay::AudioFactory::
2323 createCallbackPlayTarget(m_playSource); 2347 createCallbackPlayTarget(m_resamplerWrapper, preference);
2324 if (m_playTarget) { 2348 if (m_playTarget) {
2325 m_playTarget->suspend(); // start in suspended state 2349 m_playTarget->suspend(); // start in suspended state
2326 m_playSource->setSystemPlaybackTarget(m_playTarget); 2350 m_playSource->setSystemPlaybackTarget(m_playTarget);
2327 } 2351 }
2328 } 2352 }
2329 2353
2330 if (!m_playTarget && !m_audioIO) { 2354 if (!m_playTarget && !m_audioIO) {
2331 emit hideSplash(); 2355 emit hideSplash();
2332 2356 if (implementation == "") {
2333 // if (factory->isAutoCallbackTarget(targetName)) {
2334 QMessageBox::warning 2357 QMessageBox::warning
2335 (this, tr("Couldn't open audio device"), 2358 (this, tr("Couldn't open audio device"),
2336 tr("<b>No audio available</b><p>Could not open an audio device for playback.<p>Automatic audio device detection failed. Audio playback will not be available during this session.</p>"), 2359 tr("<b>No audio available</b><p>Could not open an audio device for playback.<p>Automatic audio device detection failed. Audio playback will not be available during this session.</p>"),
2337 QMessageBox::Ok); 2360 QMessageBox::Ok);
2338 /*
2339 } else { 2361 } else {
2340 QMessageBox::warning 2362 QMessageBox::warning
2341 (this, tr("Couldn't open audio device"), 2363 (this, tr("Couldn't open audio device"),
2342 tr("<b>No audio available</b><p>Failed to open your preferred audio device (\"%1\").<p>Audio playback will not be available during this session.</p>") 2364 tr("<b>No audio available</b><p>Failed to open your preferred audio device (\"%1\").<p>Audio playback will not be available during this session.</p>")
2343 .arg(factory->getCallbackTargetDescription(targetName)), 2365 .arg(breakfastquay::AudioFactory::
2366 getImplementationDescription(implementation.toStdString())
2367 .c_str()),
2344 QMessageBox::Ok); 2368 QMessageBox::Ok);
2345 } 2369 }
2346 */ 2370 }
2347 return; 2371 }
2348 } 2372
2373 void
2374 MainWindowBase::deleteAudioIO()
2375 {
2376 // First prevent this trying to call target.
2377 if (m_playSource) {
2378 m_playSource->setSystemPlaybackTarget(0);
2379 m_playSource->setResamplerWrapper(0);
2380 }
2381
2382 // Then delete the breakfastquay::System object.
2383 // Only one of these two exists!
2384 delete m_audioIO;
2385 delete m_playTarget;
2386
2387 // And the breakfastquay resampler wrapper. We need to
2388 // delete/recreate this if the channel count changes, which is one
2389 // of the use cases for recreateAudioIO() calling this
2390 delete m_resamplerWrapper;
2391
2392 m_audioIO = 0;
2393 m_playTarget = 0;
2394 m_resamplerWrapper = 0;
2395 }
2396
2397 void
2398 MainWindowBase::recreateAudioIO()
2399 {
2400 deleteAudioIO();
2401 createAudioIO();
2349 } 2402 }
2350 2403
2351 WaveFileModel * 2404 WaveFileModel *
2352 MainWindowBase::getMainModel() 2405 MainWindowBase::getMainModel()
2353 { 2406 {
2824 if (action) action->setChecked(false); 2877 if (action) action->setChecked(false);
2825 return; 2878 return;
2826 } 2879 }
2827 } 2880 }
2828 2881
2882 if (m_viewManager) m_viewManager->setGlobalCentreFrame(0);
2883
2829 m_audioIO->resume(); 2884 m_audioIO->resume();
2830 2885
2831 WritableWaveFileModel *model = m_recordTarget->startRecording(); 2886 WritableWaveFileModel *model = m_recordTarget->startRecording();
2832 if (!model) { 2887 if (!model) {
2833 cerr << "ERROR: MainWindowBase::record: Recording failed" << endl; 2888 cerr << "ERROR: MainWindowBase::record: Recording failed" << endl;