comparison data/model/WritableWaveFileModel.cpp @ 258:96a6dd889c68

* Fix #1706924 updates not happening on derived waveform generation
author Chris Cannam
date Mon, 30 Apr 2007 09:07:42 +0000
parents 185454896a76
children 20028c634494
comparison
equal deleted inserted replaced
257:46398ab6ff58 258:96a6dd889c68
24 #include <QDir> 24 #include <QDir>
25 25
26 #include <cassert> 26 #include <cassert>
27 #include <iostream> 27 #include <iostream>
28 28
29 //#define DEBUG_WRITABLE_WAVE_FILE_MODEL 1
29 30
30 WritableWaveFileModel::WritableWaveFileModel(size_t sampleRate, 31 WritableWaveFileModel::WritableWaveFileModel(size_t sampleRate,
31 size_t channels, 32 size_t channels,
32 QString path) : 33 QString path) :
33 m_model(0), 34 m_model(0),
73 delete m_reader; 74 delete m_reader;
74 m_reader = 0; 75 m_reader = 0;
75 return; 76 return;
76 } 77 }
77 78
78 connect(m_model, SLOT(modelChanged()), this, SIGNAL(modelChanged())); 79 connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
79 connect(m_model, SLOT(modelChanged(size_t, size_t)), 80 connect(m_model, SIGNAL(modelChanged(size_t, size_t)),
80 this, SIGNAL(modelChanged(size_t, size_t))); 81 this, SIGNAL(modelChanged(size_t, size_t)));
81 } 82 }
82 83
83 WritableWaveFileModel::~WritableWaveFileModel() 84 WritableWaveFileModel::~WritableWaveFileModel()
84 { 85 {
90 bool 91 bool
91 WritableWaveFileModel::addSamples(float **samples, size_t count) 92 WritableWaveFileModel::addSamples(float **samples, size_t count)
92 { 93 {
93 if (!m_writer) return false; 94 if (!m_writer) return false;
94 95
96 #ifdef DEBUG_WRITABLE_WAVE_FILE_MODEL
97 // std::cerr << "WritableWaveFileModel::addSamples(" << count << ")" << std::endl;
98 #endif
99
95 if (!m_writer->writeSamples(samples, count)) { 100 if (!m_writer->writeSamples(samples, count)) {
96 std::cerr << "ERROR: WritableWaveFileModel::addSamples: writer failed: " << m_writer->getError().toStdString() << std::endl; 101 std::cerr << "ERROR: WritableWaveFileModel::addSamples: writer failed: " << m_writer->getError().toStdString() << std::endl;
97 return false; 102 return false;
98 } 103 }
99 104
100 m_frameCount += count; 105 m_frameCount += count;
101 106
102 static int updateCounter = 0; 107 static int updateCounter = 0;
103 108
104 if (m_reader && m_reader->getChannelCount() == 0) { 109 if (m_reader && m_reader->getChannelCount() == 0) {
110 #ifdef DEBUG_WRITABLE_WAVE_FILE_MODEL
111 std::cerr << "WritableWaveFileModel::addSamples(" << count << "): calling updateFrameCount (initial)" << std::endl;
112 #endif
105 m_reader->updateFrameCount(); 113 m_reader->updateFrameCount();
106 } else if (++updateCounter == 100) { 114 } else if (++updateCounter == 100) {
115 #ifdef DEBUG_WRITABLE_WAVE_FILE_MODEL
116 std::cerr << "WritableWaveFileModel::addSamples(" << count << "): calling updateFrameCount (periodic)" << std::endl;
117 #endif
107 if (m_reader) m_reader->updateFrameCount(); 118 if (m_reader) m_reader->updateFrameCount();
108 updateCounter = 0; 119 updateCounter = 0;
109 } 120 }
110 121
111 return true; 122 return true;