Mercurial > hg > svapp
comparison audio/AudioCallbackRecordTarget.cpp @ 641:dfec6c96007d
Wire up modelAboutToBeDeleted which appears to have been missed earlier - fixing crash when timer fires after model deleted e.g. on app exit
author | Chris Cannam |
---|---|
date | Fri, 04 Jan 2019 15:23:53 +0000 |
parents | 5e0018969003 |
children | 92ad94dee103 |
comparison
equal
deleted
inserted
replaced
640:fffb78793ca7 | 641:dfec6c96007d |
---|---|
14 | 14 |
15 #include "AudioCallbackRecordTarget.h" | 15 #include "AudioCallbackRecordTarget.h" |
16 | 16 |
17 #include "base/ViewManagerBase.h" | 17 #include "base/ViewManagerBase.h" |
18 #include "base/RecordDirectory.h" | 18 #include "base/RecordDirectory.h" |
19 #include "base/Debug.h" | |
19 | 20 |
20 #include "data/model/WritableWaveFileModel.h" | 21 #include "data/model/WritableWaveFileModel.h" |
21 | 22 |
22 #include <QDir> | 23 #include <QDir> |
23 #include <QTimer> | 24 #include <QTimer> |
49 recreateBuffers(); | 50 recreateBuffers(); |
50 } | 51 } |
51 | 52 |
52 AudioCallbackRecordTarget::~AudioCallbackRecordTarget() | 53 AudioCallbackRecordTarget::~AudioCallbackRecordTarget() |
53 { | 54 { |
55 #ifdef DEBUG_AUDIO_CALLBACK_RECORD_TARGET | |
56 cerr << "AudioCallbackRecordTarget dtor" << endl; | |
57 #endif | |
58 | |
54 m_viewManager->setAudioRecordTarget(0); | 59 m_viewManager->setAudioRecordTarget(0); |
55 | 60 |
56 QMutexLocker locker(&m_bufPtrMutex); | 61 QMutexLocker locker(&m_bufPtrMutex); |
57 for (int c = 0; c < m_bufferCount; ++c) { | 62 for (int c = 0; c < m_bufferCount; ++c) { |
58 delete m_buffers[c]; | 63 delete m_buffers[c]; |
167 | 172 |
168 #ifdef DEBUG_AUDIO_CALLBACK_RECORD_TARGET | 173 #ifdef DEBUG_AUDIO_CALLBACK_RECORD_TARGET |
169 cerr << "AudioCallbackRecordTarget::updateModel: have " << nframes << " frames" << endl; | 174 cerr << "AudioCallbackRecordTarget::updateModel: have " << nframes << " frames" << endl; |
170 #endif | 175 #endif |
171 | 176 |
177 if (!m_model) { | |
178 #ifdef DEBUG_AUDIO_CALLBACK_RECORD_TARGET | |
179 cerr << "AudioCallbackRecordTarget::updateModel: have no model to update; I am hoping there is a good reason for this" << endl; | |
180 #endif | |
181 return; | |
182 } | |
183 | |
172 float **samples = new float *[m_recordChannelCount]; | 184 float **samples = new float *[m_recordChannelCount]; |
173 for (int c = 0; c < m_recordChannelCount; ++c) { | 185 for (int c = 0; c < m_recordChannelCount; ++c) { |
174 samples[c] = new float[nframes]; | 186 samples[c] = new float[nframes]; |
175 m_buffers[c]->read(samples[c], nframes); | 187 m_buffers[c]->read(samples[c], nframes); |
176 } | 188 } |
215 | 227 |
216 void | 228 void |
217 AudioCallbackRecordTarget::modelAboutToBeDeleted() | 229 AudioCallbackRecordTarget::modelAboutToBeDeleted() |
218 { | 230 { |
219 if (sender() == m_model) { | 231 if (sender() == m_model) { |
232 #ifdef DEBUG_AUDIO_CALLBACK_RECORD_TARGET | |
233 cerr << "AudioCallbackRecordTarget::modelAboutToBeDeleted: taking note" << endl; | |
234 #endif | |
220 m_model = 0; | 235 m_model = 0; |
221 m_recording = false; | 236 m_recording = false; |
237 } else { | |
238 SVCERR << "WARNING: AudioCallbackRecordTarget::modelAboutToBeDeleted: ths is not my model!" << endl; | |
222 } | 239 } |
223 } | 240 } |
224 | 241 |
225 WritableWaveFileModel * | 242 WritableWaveFileModel * |
226 AudioCallbackRecordTarget::startRecording() | 243 AudioCallbackRecordTarget::startRecording() |
261 delete m_model; | 278 delete m_model; |
262 m_model = 0; | 279 m_model = 0; |
263 return 0; | 280 return 0; |
264 } | 281 } |
265 | 282 |
283 connect(m_model, SIGNAL(aboutToBeDeleted()), | |
284 this, SLOT(modelAboutToBeDeleted())); | |
285 | |
266 m_model->setObjectName(label); | 286 m_model->setObjectName(label); |
267 m_recording = true; | 287 m_recording = true; |
268 | 288 |
269 emit recordStatusChanged(true); | 289 emit recordStatusChanged(true); |
270 | 290 |