comparison data/model/WaveFileModel.cpp @ 316:3a6725f285d6

* Make RemoteFile far more pervasive, and use it for local files as well so that we can handle both transparently. Make it shallow copy with reference counting, so it can be used by value without having to worry about the cache file lifetime. Use RemoteFile for MainWindow file-open functions, etc
author Chris Cannam
date Thu, 18 Oct 2007 15:31:20 +0000
parents 70a232b1f12a
children c324d410b096
comparison
equal deleted inserted replaced
315:96ef9746c560 316:3a6725f285d6
37 using std::endl; 37 using std::endl;
38 38
39 PowerOfSqrtTwoZoomConstraint 39 PowerOfSqrtTwoZoomConstraint
40 WaveFileModel::m_zoomConstraint; 40 WaveFileModel::m_zoomConstraint;
41 41
42 WaveFileModel::WaveFileModel(QString path, size_t targetRate) : 42 WaveFileModel::WaveFileModel(RemoteFile source, size_t targetRate) :
43 m_path(path), 43 m_source(source),
44 m_path(source.getLocation()),
44 m_myReader(true), 45 m_myReader(true),
45 m_startFrame(0), 46 m_startFrame(0),
46 m_fillThread(0), 47 m_fillThread(0),
47 m_updateTimer(0), 48 m_updateTimer(0),
48 m_lastFillExtent(0), 49 m_lastFillExtent(0),
49 m_exiting(false) 50 m_exiting(false)
50 { 51 {
51 m_reader = AudioFileReaderFactory::createReader(path, targetRate); 52 m_source.waitForData();
52 if (m_reader) std::cerr << "WaveFileModel::WaveFileModel: reader rate: " << m_reader->getSampleRate() << std::endl; 53 if (m_source.isOK()) {
54 m_reader = AudioFileReaderFactory::createReader(m_source, targetRate);
55 if (m_reader) {
56 std::cerr << "WaveFileModel::WaveFileModel: reader rate: "
57 << m_reader->getSampleRate() << std::endl;
58 }
59 }
53 if (m_reader) setObjectName(m_reader->getTitle()); 60 if (m_reader) setObjectName(m_reader->getTitle());
54 if (objectName() == "") setObjectName(QFileInfo(path).fileName()); 61 if (objectName() == "") setObjectName(QFileInfo(m_path).fileName());
55 if (isOK()) fillCache(); 62 if (isOK()) fillCache();
56 } 63 }
57 64
58 WaveFileModel::WaveFileModel(QString path, QString originalLocation, size_t targetRate) : 65 WaveFileModel::WaveFileModel(RemoteFile source, AudioFileReader *reader) :
59 m_path(originalLocation), 66 m_source(source),
60 m_myReader(true), 67 m_path(source.getLocation()),
61 m_startFrame(0),
62 m_fillThread(0),
63 m_updateTimer(0),
64 m_lastFillExtent(0),
65 m_exiting(false)
66 {
67 m_reader = AudioFileReaderFactory::createReader(path, targetRate);
68 if (m_reader) std::cerr << "WaveFileModel::WaveFileModel: reader rate: " << m_reader->getSampleRate() << std::endl;
69 if (m_reader) setObjectName(m_reader->getTitle());
70 if (objectName() == "") setObjectName(QFileInfo(originalLocation).fileName());
71 if (isOK()) fillCache();
72 }
73
74 WaveFileModel::WaveFileModel(QString path, AudioFileReader *reader) :
75 m_path(path),
76 m_myReader(false), 68 m_myReader(false),
77 m_startFrame(0), 69 m_startFrame(0),
78 m_fillThread(0), 70 m_fillThread(0),
79 m_updateTimer(0), 71 m_updateTimer(0),
80 m_lastFillExtent(0), 72 m_lastFillExtent(0),
81 m_exiting(false) 73 m_exiting(false)
82 { 74 {
83 m_reader = reader; 75 m_reader = reader;
84 if (m_reader) setObjectName(m_reader->getTitle()); 76 if (m_reader) setObjectName(m_reader->getTitle());
85 if (objectName() == "") setObjectName(QFileInfo(path).fileName()); 77 if (objectName() == "") setObjectName(QFileInfo(m_path).fileName());
86 fillCache(); 78 fillCache();
87 } 79 }
88 80
89 WaveFileModel::~WaveFileModel() 81 WaveFileModel::~WaveFileModel()
90 { 82 {
129 } 121 }
130 122
131 Model * 123 Model *
132 WaveFileModel::clone() const 124 WaveFileModel::clone() const
133 { 125 {
134 WaveFileModel *model = new WaveFileModel(m_path); 126 WaveFileModel *model = new WaveFileModel(m_source);
135 return model; 127 return model;
136 } 128 }
137 129
138 size_t 130 size_t
139 WaveFileModel::getFrameCount() const 131 WaveFileModel::getFrameCount() const