diff 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
line wrap: on
line diff
--- 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));
 }