comparison data/model/WritableWaveFileModel.cpp @ 188:f86b74d1b143

* Simplify maker names in plugin menu * Make sure derived models have a name (based on the transform) * Don't start deriving a model from a derived model until the derived model is ready * Tidy up completion management in writable wave file model * Make writable models save/reload correctly from session file (i.e. regenerating from the original transform) * Same for dense 3d models -- don't save the data, just the transform details * Add a comment describing the SV file format
author Chris Cannam
date Fri, 13 Oct 2006 12:51:05 +0000
parents 89b05b679dc3
children 91fdc752e540
comparison
equal deleted inserted replaced
187:89b05b679dc3 188:f86b74d1b143
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
31 WritableWaveFileModel::WritableWaveFileModel(size_t sampleRate, 30 WritableWaveFileModel::WritableWaveFileModel(size_t sampleRate,
32 size_t channels, 31 size_t channels,
33 QString path) : 32 QString path) :
34 m_model(0), 33 m_model(0),
35 m_writer(0), 34 m_writer(0),
36 m_reader(0), 35 m_reader(0),
37 m_sampleRate(sampleRate), 36 m_sampleRate(sampleRate),
38 m_channels(channels), 37 m_channels(channels),
39 m_frameCount(0) 38 m_frameCount(0),
39 m_completion(0)
40 { 40 {
41 if (path.isEmpty()) { 41 if (path.isEmpty()) {
42 try { 42 try {
43 QDir dir(TempDirectory::getInstance()->getPath()); 43 QDir dir(TempDirectory::getInstance()->getPath());
44 path = dir.filePath(QString("written_%1.wav") 44 path = dir.filePath(QString("written_%1.wav")
109 } 109 }
110 110
111 return true; 111 return true;
112 } 112 }
113 113
114 void
115 WritableWaveFileModel::sync()
116 {
117 //!!! use setCompletion instead
118 if (m_reader) m_reader->updateDone();
119 }
120
121 bool 114 bool
122 WritableWaveFileModel::isOK() const 115 WritableWaveFileModel::isOK() const
123 { 116 {
124 bool ok = (m_writer && m_writer->isOK()); 117 bool ok = (m_writer && m_writer->isOK());
125 std::cerr << "WritableWaveFileModel::isOK(): ok = " << ok << std::endl; 118 // std::cerr << "WritableWaveFileModel::isOK(): ok = " << ok << std::endl;
126 return ok; 119 return ok;
127 } 120 }
128 121
129 bool 122 bool
130 WritableWaveFileModel::isReady(int *completion) const 123 WritableWaveFileModel::isReady(int *completion) const
131 { 124 {
132 bool ready = (m_model && m_model->isReady(completion)); 125 if (completion) *completion = m_completion;
133 std::cerr << "WritableWaveFileModel::isReady(): ready = " << ready << ", completion = " << (completion ? *completion : -1) << std::endl; 126 return (m_completion == 100);
134 return ready; 127 }
128
129 void
130 WritableWaveFileModel::setCompletion(int completion)
131 {
132 m_completion = completion;
133 if (completion == 100) {
134 if (m_reader) m_reader->updateDone();
135 }
135 } 136 }
136 137
137 size_t 138 size_t
138 WritableWaveFileModel::getFrameCount() const 139 WritableWaveFileModel::getFrameCount() const
139 { 140 {
140 std::cerr << "WritableWaveFileModel::getFrameCount: count = " << m_frameCount << std::endl; 141 // std::cerr << "WritableWaveFileModel::getFrameCount: count = " << m_frameCount << std::endl;
141 return m_frameCount; 142 return m_frameCount;
142 } 143 }
143 144
144 Model * 145 Model *
145 WritableWaveFileModel::clone() const 146 WritableWaveFileModel::clone() const
146 { 147 {
147 assert(0); //!!! 148 assert(0); //!!!
149 return 0;
148 } 150 }
149 151
150 size_t 152 size_t
151 WritableWaveFileModel::getValues(int channel, size_t start, size_t end, 153 WritableWaveFileModel::getValues(int channel, size_t start, size_t end,
152 float *buffer) const 154 float *buffer) const
183 void 185 void
184 WritableWaveFileModel::toXml(QTextStream &out, 186 WritableWaveFileModel::toXml(QTextStream &out,
185 QString indent, 187 QString indent,
186 QString extraAttributes) const 188 QString extraAttributes) const
187 { 189 {
188 //!!! need to indicate that some models are not saved but must be 190 // We don't actually write the data to XML. We just write a brief
189 //regenerated -- same goes for those very large dense 3d models 191 // description of the model. Any code that uses this class is
190 192 // going to need to be aware that it will have to make separate
191 assert(0); //!!! 193 // arrangements for the audio file itself.
194
195 Model::toXml
196 (out, indent,
197 QString("type=\"writablewavefile\" file=\"%1\" channels=\"%2\" %3")
198 .arg(m_writer->getPath()).arg(m_model->getChannelCount()).arg(extraAttributes));
192 } 199 }
193 200
194 QString 201 QString
195 WritableWaveFileModel::toXmlString(QString indent, 202 WritableWaveFileModel::toXmlString(QString indent,
196 QString extraAttributes) const 203 QString extraAttributes) const
197 { 204 {
198 assert(0); //!!! 205 // As above.
199 return ""; 206
200 } 207 return Model::toXmlString
201 208 (indent,
209 QString("type=\"writablewavefile\" file=\"%1\" channels=\"%2\" %3")
210 .arg(m_writer->getPath()).arg(m_model->getChannelCount()).arg(extraAttributes));
211 }
212