comparison data/model/AggregateWaveModel.cpp @ 1389:770f80d9ccee

Invalidate an aggregate model when one of its components announces it's about to be deleted
author Chris Cannam
date Mon, 27 Feb 2017 15:43:30 +0000
parents 54af1e21705c
children 1a572937ed8c
comparison
equal deleted inserted replaced
1388:246876022b35 1389:770f80d9ccee
23 23
24 PowerOfSqrtTwoZoomConstraint 24 PowerOfSqrtTwoZoomConstraint
25 AggregateWaveModel::m_zoomConstraint; 25 AggregateWaveModel::m_zoomConstraint;
26 26
27 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) : 27 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) :
28 m_components(channelSpecs) 28 m_components(channelSpecs),
29 m_invalidated(false)
29 { 30 {
30 for (ChannelSpecList::const_iterator i = channelSpecs.begin(); 31 for (ChannelSpecList::const_iterator i = channelSpecs.begin();
31 i != channelSpecs.end(); ++i) { 32 i != channelSpecs.end(); ++i) {
33
34 connect(i->model, SIGNAL(aboutToBeDeleted()),
35 this, SLOT(componentModelAboutToBeDeleted()));
36
32 if (i->model->getSampleRate() != 37 if (i->model->getSampleRate() !=
33 channelSpecs.begin()->model->getSampleRate()) { 38 channelSpecs.begin()->model->getSampleRate()) {
34 SVDEBUG << "AggregateWaveModel::AggregateWaveModel: WARNING: Component models do not all have the same sample rate" << endl; 39 SVDEBUG << "AggregateWaveModel::AggregateWaveModel: WARNING: Component models do not all have the same sample rate" << endl;
35 break; 40 break;
36 } 41 }
39 44
40 AggregateWaveModel::~AggregateWaveModel() 45 AggregateWaveModel::~AggregateWaveModel()
41 { 46 {
42 } 47 }
43 48
49 void
50 AggregateWaveModel::componentModelAboutToBeDeleted()
51 {
52 SVDEBUG << "AggregateWaveModel::componentModelAboutToBeDeleted: invalidating"
53 << endl;
54 m_components.clear();
55 m_invalidated = true;
56 }
57
44 bool 58 bool
45 AggregateWaveModel::isOK() const 59 AggregateWaveModel::isOK() const
46 { 60 {
61 if (m_invalidated) {
62 return false;
63 }
47 for (ChannelSpecList::const_iterator i = m_components.begin(); 64 for (ChannelSpecList::const_iterator i = m_components.begin();
48 i != m_components.end(); ++i) { 65 i != m_components.end(); ++i) {
49 if (!i->model->isOK()) return false; 66 if (!i->model->isOK()) {
67 return false;
68 }
50 } 69 }
51 return true; 70 return true;
52 } 71 }
53 72
54 bool 73 bool
55 AggregateWaveModel::isReady(int *completion) const 74 AggregateWaveModel::isReady(int *completion) const
56 { 75 {
57 if (completion) *completion = 100; 76 if (completion) *completion = 100;
77
58 bool ready = true; 78 bool ready = true;
59 for (ChannelSpecList::const_iterator i = m_components.begin(); 79 for (ChannelSpecList::const_iterator i = m_components.begin();
60 i != m_components.end(); ++i) { 80 i != m_components.end(); ++i) {
61 int completionHere = 100; 81 int completionHere = 100;
62 if (!i->model->isReady(&completionHere)) ready = false; 82 if (!i->model->isReady(&completionHere)) ready = false;
69 89
70 sv_frame_t 90 sv_frame_t
71 AggregateWaveModel::getFrameCount() const 91 AggregateWaveModel::getFrameCount() const
72 { 92 {
73 sv_frame_t count = 0; 93 sv_frame_t count = 0;
74
75 for (ChannelSpecList::const_iterator i = m_components.begin(); 94 for (ChannelSpecList::const_iterator i = m_components.begin();
76 i != m_components.end(); ++i) { 95 i != m_components.end(); ++i) {
77 sv_frame_t thisCount = i->model->getEndFrame() - i->model->getStartFrame(); 96 sv_frame_t thisCount =
97 i->model->getEndFrame() - i->model->getStartFrame();
78 if (thisCount > count) count = thisCount; 98 if (thisCount > count) count = thisCount;
79 } 99 }
80
81 return count; 100 return count;
82 } 101 }
83 102
84 int 103 int
85 AggregateWaveModel::getChannelCount() const 104 AggregateWaveModel::getChannelCount() const