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_playlist.h"
40 #include "ardour/midi_ring_buffer.h"
41 #include "ardour/utils.h"
55 class MidiDiskstream : public Diskstream
58 MidiDiskstream (Session &, const string& name, Diskstream::Flag f = Recordable);
59 MidiDiskstream (Session &, const XMLNode&);
62 float playback_buffer_load() const;
63 float capture_buffer_load() const;
65 void get_playback(MidiBuffer& dst, framepos_t start, framepos_t end);
67 void set_record_enabled (bool yn);
69 boost::shared_ptr<MidiPlaylist> midi_playlist () { return boost::dynamic_pointer_cast<MidiPlaylist>(_playlist); }
71 int use_playlist (boost::shared_ptr<Playlist>);
72 int use_new_playlist ();
73 int use_copy_playlist ();
76 XMLNode& get_state(void);
77 int set_state(const XMLNode&, int version);
79 void monitor_input (bool);
81 boost::shared_ptr<SMFSource> write_source () { return _write_source; }
83 int set_destructive (bool yn); // doom!
85 void set_note_mode (NoteMode m);
87 uint16_t get_channel_mask() {
88 uint16_t playback_mask = _playback_buf->get_channel_mask();
90 uint16_t capture_mask = _capture_buf->get_channel_mask();
91 assert(playback_mask == capture_mask);
96 void set_channel_mode(ChannelMode mode, uint16_t mask) {
97 _playback_buf->set_channel_mode(mode, mask);
98 _capture_buf->set_channel_mode(mode, mask);
101 ChannelMode get_channel_mode() {
102 ChannelMode playback_mode = _playback_buf->get_channel_mode();
104 ChannelMode capture_mode = _capture_buf->get_channel_mode();
105 assert(playback_mode == capture_mode);
107 return playback_mode;
110 /** Emitted when some MIDI data has been received for recording.
111 * First parameter is the data.
112 * Second parameter is the source that it is destined for.
114 PBD::Signal2<void, boost::shared_ptr<MidiBuffer>, boost::weak_ptr<MidiSource> > DataRecorded;
117 friend class Session;
120 /* the Session is the only point of access for these
121 because they require that the Session is "inactive"
122 while they are called.
125 void set_pending_overwrite(bool);
126 int overwrite_existing_buffers ();
127 void set_block_size (pframes_t);
128 int internal_playback_seek (framecnt_t distance);
129 int can_internal_playback_seek (framecnt_t distance);
130 int rename_write_sources ();
131 std::list<boost::shared_ptr<Source> > steal_write_sources();
132 void reset_write_sources (bool, bool force = false);
133 void non_realtime_input_change ();
134 void non_realtime_locate (framepos_t location);
136 static void set_readahead_frames (framecnt_t frames_ahead) { midi_readahead = frames_ahead; }
139 int seek (framepos_t which_sample, bool complete_refill = false);
142 friend class MidiTrack;
144 int process (framepos_t transport_frame, pframes_t nframes, bool can_record, bool rec_monitors_input, bool& need_butler);
145 bool commit (framecnt_t nframes);
146 static framecnt_t midi_readahead;
150 /* The two central butler operations */
151 int do_flush (RunContext context, bool force = false);
154 int do_refill_with_alloc();
156 int read (framepos_t& start, framecnt_t cnt, bool reversed);
158 void finish_capture (bool rec_monitors_input);
159 void transport_stopped_wallclock (struct tm&, time_t, bool abort);
160 void transport_looped (framepos_t transport_frame);
164 int use_new_write_source (uint32_t n=0);
166 int find_and_use_playlist (const string&);
168 void allocate_temporary_buffers ();
170 int use_pending_capture_data (XMLNode& node);
172 void get_input_sources ();
173 void set_align_style_from_io();
175 /* fixed size buffers per instance of ardour for now (non-dynamic)
178 void adjust_playback_buffering () {}
179 void adjust_capture_buffering () {}
181 void engage_record_enable ();
182 void disengage_record_enable ();
184 MidiRingBuffer<framepos_t>* _playback_buf;
185 MidiRingBuffer<framepos_t>* _capture_buf;
186 MidiPort* _source_port;
187 boost::shared_ptr<SMFSource> _write_source;
188 framepos_t _last_flush_frame;
190 volatile gint _frames_written_to_ringbuffer;
191 volatile gint _frames_read_from_ringbuffer;
194 }; /* namespace ARDOUR */
196 #endif /* __ardour_midi_diskstream_h__ */