1 /* 2 Copyright (C) 2006-2007 Remon Sijrier 3 4 This file is part of Traverso 5 6 Traverso is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 20 */ 21 22 #ifndef READSOURCE_H 23 #define READSOURCE_H 24 25 #include "AudioSource.h" 26 27 #include <QDomDocument> 28 29 30 class ResampleAudioReader; 31 class AudioClip; 32 struct BufferStatus; 33 class DecodeBuffer; 34 class DiskIO; 35 36 class ReadSource : public AudioSource 37 { 38 Q_OBJECT 39 public : 40 ReadSource(const QDomNode node); 41 ReadSource(const QString& dir, const QString& name); 42 ReadSource(const QString& dir, const QString& name, int channelCount); 43 ReadSource(); // For creating a 0-channel, silent ReadSource 44 ~ReadSource(); 45 46 enum ReadSourceError { 47 COULD_NOT_OPEN_FILE = -1, 48 INVALID_CHANNEL_COUNT = -2, 49 ZERO_CHANNELS = -3, 50 FILE_DOES_NOT_EXIST = -4 51 }; 52 53 ReadSource* deep_copy(); 54 55 int set_state( const QDomNode& node ); 56 QDomNode get_state(QDomDocument doc); 57 58 int rb_read(audio_sample_t** dest, TimeRef& start, nframes_t cnt); 59 void rb_seek_to_file_position(TimeRef& position); 60 61 int file_read(DecodeBuffer* buffer, const TimeRef& start, nframes_t cnt) const; 62 int file_read(DecodeBuffer* buffer, nframes_t start, nframes_t cnt); 63 64 int init(); get_error()65 int get_error() const {return m_error;} 66 QString get_error_string() const; 67 int set_file(const QString& filename); 68 void set_active(bool active); 69 70 void set_audio_clip(AudioClip* clip); 71 void set_diskio(DiskIO* diskio); 72 nframes_t get_nframes() const; 73 int get_file_rate() const; get_output_rate()74 int get_output_rate() const {return m_outputRate;} get_length()75 const TimeRef& get_length() const {return m_length;} 76 77 void sync(DecodeBuffer* buffer); 78 void process_ringbuffer(DecodeBuffer* buffer, bool seeking=false); 79 void prepare_rt_buffers(); 80 BufferStatus* get_buffer_status(); 81 82 void set_output_rate(int rate); 83 84 85 private: 86 ResampleAudioReader* m_audioReader; 87 AudioClip* m_clip; 88 DiskIO* m_diskio; 89 int m_refcount; 90 int m_error; 91 bool m_silent; 92 TimeRef m_rbFileReadPos; 93 TimeRef m_rbRelativeFileReadPos; 94 TimeRef m_syncPos; 95 volatile size_t m_rbReady; 96 volatile size_t m_needSync; 97 volatile size_t m_active; 98 volatile size_t m_wasActivated; 99 volatile size_t m_bufferUnderRunDetected; 100 bool m_syncInProgress; 101 102 mutable TimeRef m_length; 103 QString m_decodertype; 104 int m_outputRate; 105 106 BufferStatus* m_bufferstatus; 107 ref()108 int ref() { return m_refcount++;} 109 110 void private_init(); 111 void start_resync(TimeRef& position); 112 void finish_resync(); 113 int rb_file_read(DecodeBuffer* buffer, nframes_t cnt); 114 115 friend class ResourcesManager; 116 friend class ProjectConverter; 117 118 signals: 119 void stateChanged(); 120 }; 121 122 #endif 123