Mercurial > hg > svcore
comparison data/model/WritableWaveFileModel.cpp @ 187:89b05b679dc3
* Fixes to update logic in writable wave file model
author | Chris Cannam |
---|---|
date | Thu, 12 Oct 2006 16:10:49 +0000 |
parents | bd1260261412 |
children | f86b74d1b143 |
comparison
equal
deleted
inserted
replaced
186:06ad01f3e553 | 187:89b05b679dc3 |
---|---|
24 #include <QDir> | 24 #include <QDir> |
25 | 25 |
26 #include <cassert> | 26 #include <cassert> |
27 #include <iostream> | 27 #include <iostream> |
28 | 28 |
29 //!!! This class needs completing. | |
30 | |
29 WritableWaveFileModel::WritableWaveFileModel(size_t sampleRate, | 31 WritableWaveFileModel::WritableWaveFileModel(size_t sampleRate, |
30 size_t channels, | 32 size_t channels, |
31 QString path) : | 33 QString path) : |
32 m_model(0), | 34 m_model(0), |
33 m_writer(0), | 35 m_writer(0), |
52 std::cerr << "WritableWaveFileModel: Error in creating WAV file writer: " << m_writer->getError().toStdString() << std::endl; | 54 std::cerr << "WritableWaveFileModel: Error in creating WAV file writer: " << m_writer->getError().toStdString() << std::endl; |
53 delete m_writer; | 55 delete m_writer; |
54 m_writer = 0; | 56 m_writer = 0; |
55 return; | 57 return; |
56 } | 58 } |
59 | |
60 m_reader = new WavFileReader(m_writer->getPath(), true); | |
61 if (!m_reader->getError().isEmpty()) { | |
62 std::cerr << "WritableWaveFileModel: Error in creating wave file reader" << std::endl; | |
63 delete m_reader; | |
64 m_reader = 0; | |
65 return; | |
66 } | |
67 | |
68 m_model = new WaveFileModel(m_writer->getPath(), m_reader); | |
69 if (!m_model->isOK()) { | |
70 std::cerr << "WritableWaveFileModel: Error in creating wave file model" << std::endl; | |
71 delete m_model; | |
72 m_model = 0; | |
73 delete m_reader; | |
74 m_reader = 0; | |
75 return; | |
76 } | |
77 | |
78 connect(m_model, SLOT(modelChanged()), this, SIGNAL(modelChanged())); | |
79 connect(m_model, SLOT(modelChanged(size_t, size_t)), | |
80 this, SIGNAL(modelChanged(size_t, size_t))); | |
57 } | 81 } |
58 | 82 |
59 WritableWaveFileModel::~WritableWaveFileModel() | 83 WritableWaveFileModel::~WritableWaveFileModel() |
60 { | 84 { |
61 delete m_model; | 85 delete m_model; |
73 return false; | 97 return false; |
74 } | 98 } |
75 | 99 |
76 m_frameCount += count; | 100 m_frameCount += count; |
77 | 101 |
78 if (!m_model) { | |
79 | |
80 m_reader = new WavFileReader(m_writer->getPath(), true); | |
81 if (!m_reader->getError().isEmpty()) { | |
82 std::cerr << "WritableWaveFileModel: Error in creating wave file reader" << std::endl; | |
83 delete m_reader; | |
84 m_reader = 0; | |
85 return false; | |
86 } | |
87 | |
88 m_model = new WaveFileModel(m_writer->getPath(), m_reader); | |
89 if (!m_model->isOK()) { | |
90 std::cerr << "WritableWaveFileModel: Error in creating wave file model" << std::endl; | |
91 delete m_model; | |
92 m_model = 0; | |
93 delete m_reader; | |
94 m_reader = 0; | |
95 return false; | |
96 } | |
97 } | |
98 | |
99 static int updateCounter = 0; | 102 static int updateCounter = 0; |
100 if (++updateCounter == 100) { | 103 |
104 if (m_reader && m_reader->getChannelCount() == 0) { | |
105 m_reader->updateFrameCount(); | |
106 } else if (++updateCounter == 100) { | |
101 if (m_reader) m_reader->updateFrameCount(); | 107 if (m_reader) m_reader->updateFrameCount(); |
102 updateCounter = 0; | 108 updateCounter = 0; |
103 } | 109 } |
104 | 110 |
105 return true; | 111 return true; |
113 } | 119 } |
114 | 120 |
115 bool | 121 bool |
116 WritableWaveFileModel::isOK() const | 122 WritableWaveFileModel::isOK() const |
117 { | 123 { |
118 bool ok = (m_model && m_model->isOK()); | 124 bool ok = (m_writer && m_writer->isOK()); |
119 std::cerr << "WritableWaveFileModel::isOK(): ok = " << ok << std::endl; | 125 std::cerr << "WritableWaveFileModel::isOK(): ok = " << ok << std::endl; |
120 return ok; | 126 return ok; |
121 } | 127 } |
122 | 128 |
123 bool | 129 bool |
143 | 149 |
144 size_t | 150 size_t |
145 WritableWaveFileModel::getValues(int channel, size_t start, size_t end, | 151 WritableWaveFileModel::getValues(int channel, size_t start, size_t end, |
146 float *buffer) const | 152 float *buffer) const |
147 { | 153 { |
148 if (!m_model) return 0; | 154 if (!m_model || m_model->getChannelCount() == 0) return 0; |
149 return m_model->getValues(channel, start, end, buffer); | 155 return m_model->getValues(channel, start, end, buffer); |
150 } | 156 } |
151 | 157 |
152 size_t | 158 size_t |
153 WritableWaveFileModel::getValues(int channel, size_t start, size_t end, | 159 WritableWaveFileModel::getValues(int channel, size_t start, size_t end, |
154 double *buffer) const | 160 double *buffer) const |
155 { | 161 { |
156 if (!m_model) return 0; | 162 if (!m_model || m_model->getChannelCount() == 0) return 0; |
157 // std::cerr << "WritableWaveFileModel::getValues(" << channel << ", " | 163 // std::cerr << "WritableWaveFileModel::getValues(" << channel << ", " |
158 // << start << ", " << end << "): calling model" << std::endl; | 164 // << start << ", " << end << "): calling model" << std::endl; |
159 return m_model->getValues(channel, start, end, buffer); | 165 return m_model->getValues(channel, start, end, buffer); |
160 } | 166 } |
161 | 167 |
162 WritableWaveFileModel::RangeBlock | 168 WritableWaveFileModel::RangeBlock |
163 WritableWaveFileModel::getRanges(size_t channel, size_t start, size_t end, | 169 WritableWaveFileModel::getRanges(size_t channel, size_t start, size_t end, |
164 size_t &blockSize) const | 170 size_t &blockSize) const |
165 { | 171 { |
166 if (!m_model) return RangeBlock(); | 172 if (!m_model || m_model->getChannelCount() == 0) return RangeBlock(); |
167 return m_model->getRanges(channel, start, end, blockSize); | 173 return m_model->getRanges(channel, start, end, blockSize); |
168 } | 174 } |
169 | 175 |
170 WritableWaveFileModel::Range | 176 WritableWaveFileModel::Range |
171 WritableWaveFileModel::getRange(size_t channel, size_t start, size_t end) const | 177 WritableWaveFileModel::getRange(size_t channel, size_t start, size_t end) const |
172 { | 178 { |
173 if (!m_model) return Range(); | 179 if (!m_model || m_model->getChannelCount() == 0) return Range(); |
174 return m_model->getRange(channel, start, end); | 180 return m_model->getRange(channel, start, end); |
175 } | 181 } |
176 | 182 |
177 void | 183 void |
178 WritableWaveFileModel::toXml(QTextStream &out, | 184 WritableWaveFileModel::toXml(QTextStream &out, |
179 QString indent, | 185 QString indent, |
180 QString extraAttributes) const | 186 QString extraAttributes) const |
181 { | 187 { |
188 //!!! need to indicate that some models are not saved but must be | |
189 //regenerated -- same goes for those very large dense 3d models | |
190 | |
182 assert(0); //!!! | 191 assert(0); //!!! |
183 } | 192 } |
184 | 193 |
185 QString | 194 QString |
186 WritableWaveFileModel::toXmlString(QString indent, | 195 WritableWaveFileModel::toXmlString(QString indent, |