ardour
midi_diskstream.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18  $Id: diskstream.h 579 2006-06-12 19:56:37Z essej $
19 */
20 
21 #ifndef __ardour_midi_diskstream_h__
22 #define __ardour_midi_diskstream_h__
23 
24 
25 #include <cmath>
26 #include <cassert>
27 #include <string>
28 #include <queue>
29 #include <map>
30 #include <vector>
31 
32 #include <time.h>
33 
34 #include "pbd/fastlog.h"
35 #include "pbd/ringbufferNPT.h"
36 
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"
42 
43 struct tm;
44 
45 namespace ARDOUR {
46 
47 class IO;
48 class MidiEngine;
49 class MidiPlaylist;
50 class MidiPort;
51 class MidiRingbuffer;
52 class MidiSource;
53 class SMFSource;
54 class Send;
55 class Session;
56 
57 template<typename T> class MidiRingBuffer;
58 
60 {
61  public:
62  MidiDiskstream (Session &, const std::string& name, Diskstream::Flag f = Recordable);
63  MidiDiskstream (Session &, const XMLNode&);
64  ~MidiDiskstream();
65 
66  float playback_buffer_load() const;
67  float capture_buffer_load() const;
68 
69  void get_playback (MidiBuffer& dst, framecnt_t);
70  void flush_playback (framepos_t, framepos_t);
71 
72  void set_record_enabled (bool yn);
73 
74  void reset_tracker ();
75  void resolve_tracker (Evoral::EventSink<framepos_t>& buffer, framepos_t time);
76 
77  boost::shared_ptr<MidiPlaylist> midi_playlist ();
78 
79  int use_playlist (boost::shared_ptr<Playlist>);
80  int use_new_playlist ();
81  int use_copy_playlist ();
82 
83  bool set_name (std::string const &);
84  bool set_write_source_name (const std::string& str);
85 
86  /* stateful */
87  XMLNode& get_state(void);
88  int set_state(const XMLNode&, int version);
89 
90  void ensure_input_monitoring (bool);
91 
92  boost::shared_ptr<SMFSource> write_source () { return _write_source; }
93 
94  int set_destructive (bool yn); // doom!
95 
96  void set_note_mode (NoteMode m);
97 
102  PBD::Signal1<void, boost::weak_ptr<MidiSource> > DataRecorded;
103 
104  boost::shared_ptr<MidiBuffer> get_gui_feed_buffer () const;
105 
106  protected:
107  friend class Session;
108  friend class Butler;
109 
110  /* the Session is the only point of access for these
111  because they require that the Session is "inactive"
112  while they are called.
113  */
114 
115  void set_pending_overwrite(bool);
116  int overwrite_existing_buffers ();
117  void set_block_size (pframes_t);
118  int internal_playback_seek (framecnt_t distance);
119  int can_internal_playback_seek (framecnt_t distance);
120  std::string steal_write_source_name();
121  void reset_write_sources (bool, bool force = false);
122  void non_realtime_input_change ();
123  void non_realtime_locate (framepos_t location);
124 
125  static void set_readahead_frames (framecnt_t frames_ahead) { midi_readahead = frames_ahead; }
126 
127  protected:
128  friend class MidiTrack;
129  friend class Auditioner;
130  int seek (framepos_t which_sample, bool complete_refill = false);
131 
132  int process (BufferSet&, framepos_t transport_frame, pframes_t nframes, framecnt_t &, bool need_diskstream);
133 
134  frameoffset_t calculate_playback_distance (pframes_t nframes);
135  bool commit (framecnt_t nframes);
136 
138 
139  private:
140 
141  /* The two central butler operations */
142  int do_flush (RunContext context, bool force = false);
143  int do_refill ();
144 
145  int do_refill_with_alloc();
146 
147  int read (framepos_t& start, framecnt_t cnt, bool reversed);
148 
149  void finish_capture ();
150  void transport_stopped_wallclock (struct tm&, time_t, bool abort);
151  void transport_looped (framepos_t transport_frame);
152 
153  void init ();
154 
155  int use_new_write_source (uint32_t n=0);
156 
157  int find_and_use_playlist (const std::string&);
158 
159  void allocate_temporary_buffers ();
160 
161  int use_pending_capture_data (XMLNode& node);
162 
163  void get_input_sources ();
164  void set_align_style_from_io();
165 
166  /* fixed size buffers per instance of ardour for now (non-dynamic)
167  */
168 
171 
172  bool prep_record_enable ();
173  bool prep_record_disable ();
174 
182  volatile gint _frames_pending_write;
183  volatile gint _num_captured_loops;
185 
190  mutable Glib::Threads::Mutex _gui_feed_buffer_mutex;
191 
193 };
194 
195 }; /* namespace ARDOUR */
196 
197 #endif /* __ardour_midi_diskstream_h__ */
NoteMode
Definition: types.h:204
volatile gint _frames_pending_write
MidiRingBuffer< framepos_t > * _capture_buf
uint32_t pframes_t
Definition: types.h:61
tuple f
Definition: signals.py:35
boost::weak_ptr< MidiPort > _source_port
RunContext
Definition: types.h:492
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
boost::shared_ptr< SMFSource > write_source()
PBD::Signal1< void, boost::weak_ptr< MidiSource > > DataRecorded
Glib::Threads::Mutex _gui_feed_buffer_mutex
MidiRingBuffer< framepos_t > * _playback_buf
CubicMidiInterpolation interpolation
int64_t framecnt_t
Definition: types.h:76
Definition: amp.h:29
static void set_readahead_frames(framecnt_t frames_ahead)
int64_t framepos_t
Definition: types.h:66
int64_t frameoffset_t
Definition: types.h:71
framepos_t _accumulated_capture_offset
#define LIBARDOUR_API
const char * name
Definition: xml++.h:95
static framecnt_t midi_readahead
boost::shared_ptr< SMFSource > _write_source
LIBARDOUR_API bool init(bool with_vst, bool try_optimization, const char *localedir)
Definition: globals.cc:376
volatile gint _num_captured_loops