2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 $Id: diskstream.h 579 2006-06-12 19:56:37Z essej $
21 #ifndef __ardour_midi_diskstream_h__
22 #define __ardour_midi_diskstream_h__
34 #include "pbd/fastlog.h"
35 #include "pbd/ringbufferNPT.h"
37 #include "ardour/ardour.h"
38 #include "ardour/diskstream.h"
39 #include "ardour/midi_buffer.h"
40 #include "ardour/utils.h"
41 #include "ardour/interpolation.h"
57 template<typename T> class MidiRingBuffer;
59 class LIBARDOUR_API MidiDiskstream : public Diskstream
62 MidiDiskstream (Session &, const std::string& name, Diskstream::Flag f = Recordable);
63 MidiDiskstream (Session &, const XMLNode&);
66 float playback_buffer_load() const;
67 float capture_buffer_load() const;
69 void flush_playback (framepos_t, framepos_t);
71 void set_record_enabled (bool yn);
72 void set_record_safe (bool yn);
74 void reset_tracker ();
75 void resolve_tracker (Evoral::EventSink<framepos_t>& buffer, framepos_t time);
77 boost::shared_ptr<MidiPlaylist> midi_playlist ();
79 int use_playlist (boost::shared_ptr<Playlist>);
80 int use_new_playlist ();
81 int use_copy_playlist ();
83 bool set_name (std::string const &);
84 bool set_write_source_name (const std::string& str);
87 XMLNode& get_state(void);
88 int set_state(const XMLNode&, int version);
90 void ensure_input_monitoring (bool);
92 boost::shared_ptr<SMFSource> write_source () { return _write_source; }
94 #ifdef XXX_OLD_DESTRUCTIVE_API_XXX
95 int set_destructive (bool yn); // doom!
98 void set_note_mode (NoteMode m);
100 /** Emitted when some MIDI data has been received for recording.
101 * Parameter is the source that it is destined for.
102 * A caller can get a copy of the data with get_gui_feed_buffer ()
104 PBD::Signal1<void, boost::weak_ptr<MidiSource> > DataRecorded;
106 boost::shared_ptr<MidiBuffer> get_gui_feed_buffer () const;
109 friend class Session;
112 /* the Session is the only point of access for these
113 because they require that the Session is "inactive"
114 while they are called.
117 void set_pending_overwrite(bool);
118 int overwrite_existing_buffers ();
119 void set_block_size (pframes_t);
120 int internal_playback_seek (framecnt_t distance);
121 int can_internal_playback_seek (framecnt_t distance);
122 std::string steal_write_source_name();
123 void reset_write_sources (bool, bool force = false);
124 void non_realtime_input_change ();
125 void non_realtime_locate (framepos_t location);
127 static void set_readahead_frames (framecnt_t frames_ahead) { midi_readahead = frames_ahead; }
130 friend class MidiTrack;
131 friend class Auditioner;
133 int seek (framepos_t which_sample, bool complete_refill = false);
134 int _do_refill_with_alloc (bool one_chunk_only);
135 int process (BufferSet&, framepos_t transport_frame, pframes_t nframes, framecnt_t &, bool need_diskstream);
136 frameoffset_t calculate_playback_distance (pframes_t nframes);
137 bool commit (framecnt_t nframes);
139 static framecnt_t midi_readahead;
142 void get_playback (MidiBuffer& dst, framecnt_t);
144 /* The two central butler operations */
145 int do_flush (RunContext context, bool force = false);
148 int read (framepos_t& start, framecnt_t cnt, bool reversed);
150 void finish_capture ();
151 void transport_stopped_wallclock (struct tm&, time_t, bool abort);
152 void transport_looped (framepos_t transport_frame);
156 int use_new_write_source (uint32_t n=0);
158 int find_and_use_playlist (const std::string&);
160 void allocate_temporary_buffers ();
162 int use_pending_capture_data (XMLNode& node);
164 void get_input_sources ();
165 void set_align_style_from_io();
167 /* fixed size buffers per instance of ardour for now (non-dynamic)
170 void adjust_playback_buffering () {}
171 void adjust_capture_buffering () {}
173 bool prep_record_enable ();
174 bool prep_record_disable ();
176 MidiRingBuffer<framepos_t>* _playback_buf;
177 MidiRingBuffer<framepos_t>* _capture_buf;
178 boost::weak_ptr<MidiPort> _source_port;
179 boost::shared_ptr<SMFSource> _write_source;
181 gint _frames_written_to_ringbuffer;
182 gint _frames_read_from_ringbuffer;
183 volatile gint _frames_pending_write;
184 volatile gint _num_captured_loops;
185 framepos_t _accumulated_capture_offset;
187 /** A buffer that we use to put newly-arrived MIDI data in for
188 the GUI to read (so that it can update itself).
190 MidiBuffer _gui_feed_buffer;
191 mutable Glib::Threads::Mutex _gui_feed_buffer_mutex;
193 CubicMidiInterpolation interpolation;
196 }; /* namespace ARDOUR */
198 #endif /* __ardour_midi_diskstream_h__ */