comparison framework/MainWindowBase.cpp @ 475:f93820d36cb0 recording

Start stubbing in audio record
author Chris Cannam
date Tue, 18 Aug 2015 14:04:47 +0100
parents 56acd9368532
children 411e019474e5
comparison
equal deleted inserted replaced
474:fdce8a452b19 475:f93820d36cb0
14 */ 14 */
15 15
16 #include "MainWindowBase.h" 16 #include "MainWindowBase.h"
17 #include "Document.h" 17 #include "Document.h"
18 18
19
20 #include "view/Pane.h" 19 #include "view/Pane.h"
21 #include "view/PaneStack.h" 20 #include "view/PaneStack.h"
22 #include "data/model/WaveFileModel.h" 21 #include "data/model/WaveFileModel.h"
23 #include "data/model/SparseOneDimensionalModel.h" 22 #include "data/model/SparseOneDimensionalModel.h"
24 #include "data/model/NoteModel.h" 23 #include "data/model/NoteModel.h"
46 #include "widgets/CSVFormatDialog.h" 45 #include "widgets/CSVFormatDialog.h"
47 #include "widgets/ModelDataTableDialog.h" 46 #include "widgets/ModelDataTableDialog.h"
48 #include "widgets/InteractiveFileFinder.h" 47 #include "widgets/InteractiveFileFinder.h"
49 48
50 #include "audio/AudioCallbackPlaySource.h" 49 #include "audio/AudioCallbackPlaySource.h"
50 #include "audio/AudioRecordTarget.h"
51 #include "audio/PlaySpeedRangeMapper.h" 51 #include "audio/PlaySpeedRangeMapper.h"
52
52 #include "data/fileio/DataFileReaderFactory.h" 53 #include "data/fileio/DataFileReaderFactory.h"
53 #include "data/fileio/PlaylistFileReader.h" 54 #include "data/fileio/PlaylistFileReader.h"
54 #include "data/fileio/WavFileWriter.h" 55 #include "data/fileio/WavFileWriter.h"
55 #include "data/fileio/MIDIFileWriter.h" 56 #include "data/fileio/MIDIFileWriter.h"
56 #include "data/fileio/BZipFileDevice.h" 57 #include "data/fileio/BZipFileDevice.h"
72 73
73 #include "data/osc/OSCQueue.h" 74 #include "data/osc/OSCQueue.h"
74 #include "data/midi/MIDIInput.h" 75 #include "data/midi/MIDIInput.h"
75 76
76 #include <bqaudioio/SystemPlaybackTarget.h> 77 #include <bqaudioio/SystemPlaybackTarget.h>
78 #include <bqaudioio/SystemAudioIO.h>
77 #include <bqaudioio/AudioFactory.h> 79 #include <bqaudioio/AudioFactory.h>
78 80
79 #include <QApplication> 81 #include <QApplication>
80 #include <QMessageBox> 82 #include <QMessageBox>
81 #include <QGridLayout> 83 #include <QGridLayout>
130 return 0; 132 return 0;
131 } 133 }
132 #undef Window 134 #undef Window
133 #endif 135 #endif
134 136
135 MainWindowBase::MainWindowBase(bool withAudioOutput, 137 MainWindowBase::MainWindowBase(SoundOptions options) :
136 bool withMIDIInput) :
137 m_document(0), 138 m_document(0),
138 m_paneStack(0), 139 m_paneStack(0),
139 m_viewManager(0), 140 m_viewManager(0),
140 m_timeRulerLayer(0), 141 m_timeRulerLayer(0),
141 m_audioOutput(withAudioOutput), 142 m_soundOptions(options),
142 m_playSource(0), 143 m_playSource(0),
144 m_recordTarget(0),
143 m_playTarget(0), 145 m_playTarget(0),
146 m_audioIO(0),
144 m_oscQueue(0), 147 m_oscQueue(0),
145 m_oscQueueStarter(0), 148 m_oscQueueStarter(0),
146 m_midiInput(0), 149 m_midiInput(0),
147 m_recentFiles("RecentFiles", 20), 150 m_recentFiles("RecentFiles", 20),
148 m_recentTransforms("RecentTransforms", 20), 151 m_recentTransforms("RecentTransforms", 20),
156 m_statusLabel(0), 159 m_statusLabel(0),
157 m_menuShortcutMapper(0) 160 m_menuShortcutMapper(0)
158 { 161 {
159 Profiler profiler("MainWindowBase::MainWindowBase"); 162 Profiler profiler("MainWindowBase::MainWindowBase");
160 163
164 if (options & WithAudioInput) {
165 if (!(options & WithAudioOutput)) {
166 cerr << "WARNING: MainWindowBase: WithAudioInput requires WithAudioOutput -- recording will not work" << endl;
167 }
168 }
169
161 qRegisterMetaType<sv_frame_t>("sv_frame_t"); 170 qRegisterMetaType<sv_frame_t>("sv_frame_t");
162 qRegisterMetaType<sv_samplerate_t>("sv_samplerate_t"); 171 qRegisterMetaType<sv_samplerate_t>("sv_samplerate_t");
163 172
164 #ifdef Q_WS_X11 173 #ifdef Q_WS_X11
165 XSetErrorHandler(handle_x11_error); 174 XSetErrorHandler(handle_x11_error);
217 connect(m_paneStack, SIGNAL(paneDeleteButtonClicked(Pane *)), 226 connect(m_paneStack, SIGNAL(paneDeleteButtonClicked(Pane *)),
218 this, SLOT(paneDeleteButtonClicked(Pane *))); 227 this, SLOT(paneDeleteButtonClicked(Pane *)));
219 228
220 m_playSource = new AudioCallbackPlaySource(m_viewManager, 229 m_playSource = new AudioCallbackPlaySource(m_viewManager,
221 QApplication::applicationName()); 230 QApplication::applicationName());
231 if (m_soundOptions & WithAudioInput) {
232 m_recordTarget = new AudioRecordTarget(m_viewManager,
233 QApplication::applicationName());
234 }
222 235
223 connect(m_playSource, SIGNAL(sampleRateMismatch(sv_samplerate_t, sv_samplerate_t, bool)), 236 connect(m_playSource, SIGNAL(sampleRateMismatch(sv_samplerate_t, sv_samplerate_t, bool)),
224 this, SLOT(sampleRateMismatch(sv_samplerate_t, sv_samplerate_t, bool))); 237 this, SLOT(sampleRateMismatch(sv_samplerate_t, sv_samplerate_t, bool)));
225 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()), 238 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
226 this, SLOT(audioOverloadPluginDisabled())); 239 this, SLOT(audioOverloadPluginDisabled()));
257 settings.endGroup(); 270 settings.endGroup();
258 271
259 m_labeller = new Labeller(labellerType); 272 m_labeller = new Labeller(labellerType);
260 m_labeller->setCounterCycleSize(cycle); 273 m_labeller->setCounterCycleSize(cycle);
261 274
262 if (withMIDIInput) { 275 if (m_soundOptions & WithMIDIInput) {
263 m_midiInput = new MIDIInput(QApplication::applicationName(), this); 276 m_midiInput = new MIDIInput(QApplication::applicationName(), this);
264 } 277 }
265 278
266 QTimer::singleShot(1500, this, SIGNAL(hideSplash())); 279 QTimer::singleShot(1500, this, SIGNAL(hideSplash()));
267 } 280 }
269 MainWindowBase::~MainWindowBase() 282 MainWindowBase::~MainWindowBase()
270 { 283 {
271 SVDEBUG << "MainWindowBase::~MainWindowBase" << endl; 284 SVDEBUG << "MainWindowBase::~MainWindowBase" << endl;
272 delete m_playTarget; 285 delete m_playTarget;
273 delete m_playSource; 286 delete m_playSource;
287 delete m_audioIO;
288 delete m_recordTarget;
274 delete m_viewManager; 289 delete m_viewManager;
275 delete m_oscQueue; 290 delete m_oscQueue;
276 delete m_oscQueueStarter; 291 delete m_oscQueueStarter;
277 delete m_midiInput; 292 delete m_midiInput;
278 Profiles::getInstance()->dump(); 293 Profiles::getInstance()->dump();
550 (haveCurrentPane && 565 (haveCurrentPane &&
551 (currentLayer != 0)); 566 (currentLayer != 0));
552 bool haveMainModel = 567 bool haveMainModel =
553 (getMainModel() != 0); 568 (getMainModel() != 0);
554 bool havePlayTarget = 569 bool havePlayTarget =
555 (m_playTarget != 0); 570 (m_playTarget != 0 || m_audioIO != 0);
571 bool haveRecordSource =
572 (m_audioIO != 0);
556 bool haveSelection = 573 bool haveSelection =
557 (m_viewManager && 574 (m_viewManager &&
558 !m_viewManager->getSelections().empty()); 575 !m_viewManager->getSelections().empty());
559 bool haveCurrentEditableLayer = 576 bool haveCurrentEditableLayer =
560 (haveCurrentLayer && 577 (haveCurrentLayer &&
595 emit canEditLayer(haveCurrentEditableLayer); 612 emit canEditLayer(haveCurrentEditableLayer);
596 emit canEditLayerTabular(haveCurrentEditableLayer || haveTabularLayer); 613 emit canEditLayerTabular(haveCurrentEditableLayer || haveTabularLayer);
597 emit canMeasureLayer(haveCurrentLayer); 614 emit canMeasureLayer(haveCurrentLayer);
598 emit canSelect(haveMainModel && haveCurrentPane); 615 emit canSelect(haveMainModel && haveCurrentPane);
599 emit canPlay(haveMainModel && havePlayTarget); 616 emit canPlay(haveMainModel && havePlayTarget);
617 emit canRecord(haveRecordSource);
600 emit canFfwd(haveMainModel); 618 emit canFfwd(haveMainModel);
601 emit canRewind(haveMainModel); 619 emit canRewind(haveMainModel);
602 emit canPaste(haveClipboardContents); 620 emit canPaste(haveClipboardContents);
603 emit canInsertInstant(haveCurrentPane); 621 emit canInsertInstant(haveCurrentPane);
604 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection); 622 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
2158 m_recentFiles.addFile(source.getLocation()); 2176 m_recentFiles.addFile(source.getLocation());
2159 return FileOpenSucceeded; 2177 return FileOpenSucceeded;
2160 } 2178 }
2161 2179
2162 void 2180 void
2163 MainWindowBase::createPlayTarget() 2181 MainWindowBase::createAudioIO()
2164 { 2182 {
2165 if (m_playTarget) return; 2183 if (m_playTarget || m_audioIO) return;
2184
2185 if (!(m_soundOptions & WithAudioOutput)) return;
2166 2186
2167 //!!! how to handle preferences 2187 //!!! how to handle preferences
2168 /* 2188 /*
2169 QSettings settings; 2189 QSettings settings;
2170 settings.beginGroup("Preferences"); 2190 settings.beginGroup("Preferences");
2172 settings.endGroup(); 2192 settings.endGroup();
2173 AudioTargetFactory *factory = AudioTargetFactory::getInstance(); 2193 AudioTargetFactory *factory = AudioTargetFactory::getInstance();
2174 2194
2175 factory->setDefaultCallbackTarget(targetName); 2195 factory->setDefaultCallbackTarget(targetName);
2176 */ 2196 */
2177 2197
2178 m_playTarget = 2198 if (m_soundOptions & WithAudioInput) {
2179 breakfastquay::AudioFactory::createCallbackPlayTarget(m_playSource); 2199 m_audioIO = breakfastquay::AudioFactory::
2180 2200 createCallbackIO(m_recordTarget, m_playSource);
2181 m_playSource->setSystemPlaybackTarget(m_playTarget); 2201 m_playSource->setSystemPlaybackTarget(m_audioIO);
2182 2202 } else {
2183 if (!m_playTarget) { 2203 m_playTarget = breakfastquay::AudioFactory::
2204 createCallbackPlayTarget(m_playSource);
2205 m_playSource->setSystemPlaybackTarget(m_playTarget);
2206 }
2207
2208 if (!m_playTarget && !m_audioIO) {
2184 emit hideSplash(); 2209 emit hideSplash();
2185 2210
2186 // if (factory->isAutoCallbackTarget(targetName)) { 2211 // if (factory->isAutoCallbackTarget(targetName)) {
2187 QMessageBox::warning 2212 QMessageBox::warning
2188 (this, tr("Couldn't open audio device"), 2213 (this, tr("Couldn't open audio device"),
2195 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>") 2220 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>")
2196 .arg(factory->getCallbackTargetDescription(targetName)), 2221 .arg(factory->getCallbackTargetDescription(targetName)),
2197 QMessageBox::Ok); 2222 QMessageBox::Ok);
2198 } 2223 }
2199 */ 2224 */
2225 return;
2200 } 2226 }
2201 } 2227 }
2202 2228
2203 WaveFileModel * 2229 WaveFileModel *
2204 MainWindowBase::getMainModel() 2230 MainWindowBase::getMainModel()
3332 MainWindowBase::mainModelChanged(WaveFileModel *model) 3358 MainWindowBase::mainModelChanged(WaveFileModel *model)
3333 { 3359 {
3334 // SVDEBUG << "MainWindowBase::mainModelChanged(" << model << ")" << endl; 3360 // SVDEBUG << "MainWindowBase::mainModelChanged(" << model << ")" << endl;
3335 updateDescriptionLabel(); 3361 updateDescriptionLabel();
3336 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate()); 3362 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
3337 if (model && !m_playTarget && m_audioOutput) { 3363 if (model && !(m_playTarget || m_audioIO) &&
3338 createPlayTarget(); 3364 (m_soundOptions & WithAudioOutput)) {
3365 createAudioIO();
3339 } 3366 }
3340 } 3367 }
3341 3368
3342 void 3369 void
3343 MainWindowBase::modelAboutToBeDeleted(Model *model) 3370 MainWindowBase::modelAboutToBeDeleted(Model *model)