Mercurial > hg > svcore
changeset 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 | 0703252c9fe8 |
files | data/fileio/WavFileReader.cpp data/model/WaveFileModel.cpp data/model/WritableWaveFileModel.cpp data/model/WritableWaveFileModel.h |
diffstat | 4 files changed, 55 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/data/fileio/WavFileReader.cpp Thu Oct 12 16:10:49 2006 +0000 +++ b/data/fileio/WavFileReader.cpp Fri Oct 13 12:51:05 2006 +0000 @@ -81,7 +81,7 @@ } } - std::cerr << "WavFileReader::updateFrameCount: now " << m_fileInfo.frames << std::endl; +// std::cerr << "WavFileReader::updateFrameCount: now " << m_fileInfo.frames << std::endl; m_frameCount = m_fileInfo.frames;
--- a/data/model/WaveFileModel.cpp Thu Oct 12 16:10:49 2006 +0000 +++ b/data/model/WaveFileModel.cpp Fri Oct 13 12:51:05 2006 +0000 @@ -82,7 +82,7 @@ bool ready = (isOK() && (m_fillThread == 0)); double c = double(m_lastFillExtent) / double(getEndFrame() - getStartFrame()); if (completion) *completion = int(c * 100.0 + 0.01); - std::cerr << "WaveFileModel::isReady(): ready = " << ready << ", completion = " << (completion ? *completion : -1) << std::endl; +// std::cerr << "WaveFileModel::isReady(): ready = " << ready << ", completion = " << (completion ? *completion : -1) << std::endl; return ready; } @@ -371,14 +371,18 @@ WaveFileModel::fillCache() { m_mutex.lock(); + m_updateTimer = new QTimer(this); connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(fillTimerTimedOut())); m_updateTimer->start(100); + m_fillThread = new RangeCacheFillThread(*this); connect(m_fillThread, SIGNAL(finished()), this, SLOT(cacheFilled())); + m_mutex.unlock(); m_fillThread->start(); - std::cerr << "WaveFileModel::fillCache: started fill thread" << std::endl; + +// std::cerr << "WaveFileModel::fillCache: started fill thread" << std::endl; } void @@ -386,13 +390,13 @@ { if (m_fillThread) { size_t fillExtent = m_fillThread->getFillExtent(); - cerr << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; +// cerr << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; if (fillExtent > m_lastFillExtent) { emit modelChanged(m_lastFillExtent, fillExtent); m_lastFillExtent = fillExtent; } } else { - cerr << "WaveFileModel::fillTimerTimedOut: no thread" << std::endl; +// cerr << "WaveFileModel::fillTimerTimedOut: no thread" << std::endl; emit modelChanged(); } } @@ -407,7 +411,7 @@ m_updateTimer = 0; m_mutex.unlock(); emit modelChanged(); - cerr << "WaveFileModel::cacheFilled" << endl; +// cerr << "WaveFileModel::cacheFilled" << endl; } void @@ -429,7 +433,7 @@ if (updating) { while (channels == 0 && !m_model.m_exiting) { - std::cerr << "WaveFileModel::fill: Waiting for channels..." << std::endl; +// std::cerr << "WaveFileModel::fill: Waiting for channels..." << std::endl; sleep(1); channels = m_model.getChannelCount(); } @@ -446,7 +450,7 @@ updating = m_model.m_reader->isUpdating(); m_frameCount = m_model.getFrameCount(); - std::cerr << "WaveFileModel::fill: frame = " << frame << ", count = " << m_frameCount << std::endl; +// std::cerr << "WaveFileModel::fill: frame = " << frame << ", count = " << m_frameCount << std::endl; while (frame < m_frameCount) { @@ -527,9 +531,9 @@ m_fillExtent = m_frameCount; - for (size_t ct = 0; ct < 2; ++ct) { - cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl; - } +// for (size_t ct = 0; ct < 2; ++ct) { +// cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl; +// } } void
--- a/data/model/WritableWaveFileModel.cpp Thu Oct 12 16:10:49 2006 +0000 +++ b/data/model/WritableWaveFileModel.cpp Fri Oct 13 12:51:05 2006 +0000 @@ -26,7 +26,6 @@ #include <cassert> #include <iostream> -//!!! This class needs completing. WritableWaveFileModel::WritableWaveFileModel(size_t sampleRate, size_t channels, @@ -36,7 +35,8 @@ m_reader(0), m_sampleRate(sampleRate), m_channels(channels), - m_frameCount(0) + m_frameCount(0), + m_completion(0) { if (path.isEmpty()) { try { @@ -111,33 +111,34 @@ return true; } -void -WritableWaveFileModel::sync() -{ - //!!! use setCompletion instead - if (m_reader) m_reader->updateDone(); -} - bool WritableWaveFileModel::isOK() const { bool ok = (m_writer && m_writer->isOK()); - std::cerr << "WritableWaveFileModel::isOK(): ok = " << ok << std::endl; +// std::cerr << "WritableWaveFileModel::isOK(): ok = " << ok << std::endl; return ok; } bool WritableWaveFileModel::isReady(int *completion) const { - bool ready = (m_model && m_model->isReady(completion)); - std::cerr << "WritableWaveFileModel::isReady(): ready = " << ready << ", completion = " << (completion ? *completion : -1) << std::endl; - return ready; + if (completion) *completion = m_completion; + return (m_completion == 100); +} + +void +WritableWaveFileModel::setCompletion(int completion) +{ + m_completion = completion; + if (completion == 100) { + if (m_reader) m_reader->updateDone(); + } } size_t WritableWaveFileModel::getFrameCount() const { - std::cerr << "WritableWaveFileModel::getFrameCount: count = " << m_frameCount << std::endl; +// std::cerr << "WritableWaveFileModel::getFrameCount: count = " << m_frameCount << std::endl; return m_frameCount; } @@ -145,6 +146,7 @@ WritableWaveFileModel::clone() const { assert(0); //!!! + return 0; } size_t @@ -185,17 +187,26 @@ QString indent, QString extraAttributes) const { - //!!! need to indicate that some models are not saved but must be - //regenerated -- same goes for those very large dense 3d models + // We don't actually write the data to XML. We just write a brief + // description of the model. Any code that uses this class is + // going to need to be aware that it will have to make separate + // arrangements for the audio file itself. - assert(0); //!!! + Model::toXml + (out, indent, + QString("type=\"writablewavefile\" file=\"%1\" channels=\"%2\" %3") + .arg(m_writer->getPath()).arg(m_model->getChannelCount()).arg(extraAttributes)); } QString WritableWaveFileModel::toXmlString(QString indent, QString extraAttributes) const { - assert(0); //!!! - return ""; + // As above. + + return Model::toXmlString + (indent, + QString("type=\"writablewavefile\" file=\"%1\" channels=\"%2\" %3") + .arg(m_writer->getPath()).arg(m_model->getChannelCount()).arg(extraAttributes)); }
--- a/data/model/WritableWaveFileModel.h Thu Oct 12 16:10:49 2006 +0000 +++ b/data/model/WritableWaveFileModel.h Fri Oct 13 12:51:05 2006 +0000 @@ -29,12 +29,20 @@ WritableWaveFileModel(size_t sampleRate, size_t channels, QString path = ""); ~WritableWaveFileModel(); + /** + * Call addSamples to append a block of samples to the end of the + * file. Caller should also call setCompletion to update the + * progress of this file, if it has a known end point, and should + * call setCompletion(100) when the file has been written. + */ virtual bool addSamples(float **samples, size_t count); - virtual void sync(); bool isOK() const; bool isReady(int *) const; + virtual void setCompletion(int completion); // percentage + virtual int getCompletion() const { return m_completion; } + const ZoomConstraint *getZoomConstraint() const { static PowerOfSqrtTwoZoomConstraint zc; return &zc; @@ -77,6 +85,7 @@ size_t m_sampleRate; size_t m_channels; size_t m_frameCount; + int m_completion; }; #endif