#ifndef __ardour_disk_reader_h__
#define __ardour_disk_reader_h__
+#include "pbd/i18n.h"
+
#include "ardour/disk_io.h"
+#include "ardour/midi_buffer.h"
namespace ARDOUR
{
class Playlist;
class AudioPlaylist;
class MidiPlaylist;
+template<typename T> class MidiRingBuffer;
class LIBARDOUR_API DiskReader : public DiskIOProcessor
{
- public:
+public:
DiskReader (Session&, std::string const & name, DiskIOProcessor::Flag f = DiskIOProcessor::Flag (0));
~DiskReader ();
bool set_name (std::string const & str);
+ std::string display_name() const { return std::string (_("player")); }
- static framecnt_t chunk_frames() { return _chunk_frames; }
- static framecnt_t default_chunk_frames ();
- static void set_chunk_frames (framecnt_t n) { _chunk_frames = n; }
+ static samplecnt_t chunk_samples() { return _chunk_samples; }
+ static samplecnt_t default_chunk_samples ();
+ static void set_chunk_samples (samplecnt_t n) { _chunk_samples = n; }
- void run (BufferSet& /*bufs*/, framepos_t /*start_frame*/, framepos_t /*end_frame*/, double speed, pframes_t /*nframes*/, bool /*result_required*/);
- void silence (framecnt_t /*nframes*/, framepos_t /*start_frame*/);
- bool configure_io (ChanCount in, ChanCount out);
- bool can_support_io_configuration (const ChanCount& in, ChanCount& out) = 0;
- ChanCount input_streams () const;
- ChanCount output_streams() const;
+ void run (BufferSet& /*bufs*/, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, double speed, pframes_t /*nframes*/, bool /*result_required*/);
void realtime_handle_transport_stopped ();
void realtime_locate ();
+ int overwrite_existing_buffers ();
+ void set_pending_overwrite (bool yn);
- framecnt_t roll_delay() const { return _roll_delay; }
- void set_roll_delay (framecnt_t);
-
- virtual XMLNode& state (bool full);
int set_state (const XMLNode&, int version);
- boost::shared_ptr<Playlist> playlist();
- boost::shared_ptr<Playlist> get_playlist (DataType);
- boost::shared_ptr<MidiPlaylist> midi_playlist();
- boost::shared_ptr<AudioPlaylist> audio_playlist();
-
- virtual void playlist_modified ();
- virtual int use_playlist (boost::shared_ptr<Playlist>);
- virtual int use_new_playlist () = 0;
- virtual int use_copy_playlist () = 0;
-
- PBD::Signal0<void> PlaylistChanged;
PBD::Signal0<void> AlignmentStyleChanged;
float buffer_load() const;
- void move_processor_automation (boost::weak_ptr<Processor>, std::list<Evoral::RangeMove<framepos_t> > const &);
+ void move_processor_automation (boost::weak_ptr<Processor>, std::list<Evoral::RangeMove<samplepos_t> > const &);
+
+ /* called by the Butler in a non-realtime context */
+
+ int do_refill () {
+ return refill (_mixdown_buffer, _gain_buffer, 0);
+ }
/** For non-butler contexts (allocates temporary working buffers)
*
* must inherit the virtual method that we call which does NOT
* have a default argument, to avoid complications with inheritance
*/
- int do_refill_with_alloc(bool partial_fill = true) {
+ int do_refill_with_alloc (bool partial_fill = true) {
return _do_refill_with_alloc (partial_fill);
}
bool pending_overwrite () const { return _pending_overwrite; }
- virtual int find_and_use_playlist (std::string const &) = 0;
+ // Working buffers for do_refill (butler thread)
+ static void allocate_working_buffers();
+ static void free_working_buffers();
+
+ void adjust_buffering ();
+
+ int can_internal_playback_seek (samplecnt_t distance);
+ int internal_playback_seek (samplecnt_t distance);
+ int seek (samplepos_t sample, bool complete_refill = false);
+
+ static PBD::Signal0<void> Underrun;
+
+ void playlist_modified ();
+ void reset_tracker ();
- protected:
- virtual int do_refill () = 0;
+ bool declick_in_progress () const {
+ return _declick_gain != 0; // declick-out
+ }
+
+ static void set_midi_readahead_samples (samplecnt_t samples_ahead) { midi_readahead = samples_ahead; }
+
+ static void set_no_disk_output (bool yn);
+ static bool no_disk_output() { return _no_disk_output; }
+
+protected:
+ friend class Track;
+ friend class MidiTrack;
+
+ struct ReaderChannelInfo : public DiskIOProcessor::ChannelInfo {
+ ReaderChannelInfo (samplecnt_t buffer_size)
+ : DiskIOProcessor::ChannelInfo (buffer_size)
+ {
+ resize (buffer_size);
+ }
+ void resize (samplecnt_t);
+ };
+
+ XMLNode& state ();
- boost::shared_ptr<Playlist> _playlist;
+ void resolve_tracker (Evoral::EventSink<samplepos_t>& buffer, samplepos_t time);
- virtual void playlist_changed (const PBD::PropertyChange&);
- virtual void playlist_deleted (boost::weak_ptr<Playlist>);
- virtual void playlist_ranges_moved (std::list< Evoral::RangeMove<framepos_t> > const &, bool);
+ void playlist_changed (const PBD::PropertyChange&);
+ int use_playlist (DataType, boost::shared_ptr<Playlist>);
+ void playlist_ranges_moved (std::list< Evoral::RangeMove<samplepos_t> > const &, bool);
- private:
- typedef std::map<DataType,boost::shared_ptr<Playlist> > Playlists;
+ int add_channel_to (boost::shared_ptr<ChannelList>, uint32_t how_many);
- /** The number of frames by which this diskstream's output should be delayed
- with respect to the transport frame. This is used for latency compensation.
+private:
+ /** The number of samples by which this diskstream's output should be delayed
+ with respect to the transport sample. This is used for latency compensation.
*/
- framecnt_t _roll_delay;
- Playlists _playlists;
- framepos_t overwrite_frame;
+ samplepos_t overwrite_sample;
off_t overwrite_offset;
bool _pending_overwrite;
bool overwrite_queued;
IOChange input_change_pending;
- framecnt_t wrap_buffer_size;
- framecnt_t speed_buffer_size;
- framepos_t file_frame;
- framepos_t playback_sample;
+ samplepos_t file_sample[DataType::num_types];
+
+ gain_t _declick_gain;
+
+ int _do_refill_with_alloc (bool partial_fill);
+
+ static samplecnt_t _chunk_samples;
+ static samplecnt_t midi_readahead;
+ static bool _no_disk_output;
+
+ int audio_read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer,
+ samplepos_t& start, samplecnt_t cnt,
+ int channel, bool reversed);
+ int midi_read (samplepos_t& start, samplecnt_t cnt, bool reversed);
+
+ static Sample* _mixdown_buffer;
+ static gain_t* _gain_buffer;
- PBD::ScopedConnectionList playlist_connections;
+ int refill (Sample* mixdown_buffer, float* gain_buffer, samplecnt_t fill_level);
+ int refill_audio (Sample *mixdown_buffer, float *gain_buffer, samplecnt_t fill_level);
+ int refill_midi ();
- virtual int _do_refill_with_alloc (bool partial_fill);
+ sampleoffset_t calculate_playback_distance (pframes_t);
- static framecnt_t _chunk_frames;
+ void get_midi_playback (MidiBuffer& dst, samplepos_t start_sample, samplepos_t end_sample, MonitorState, BufferSet&, double speed, samplecnt_t distance);
};
} // namespace