Actually added the code mentioned in my last commit. Whoops.
[ardour.git] / libs / ardour / ardour / midi_diskstream.h
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 #include <sigc++/signal.h>
25
26 #include <cmath>
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
38 #include <ardour/ardour.h>
39 #include <ardour/configuration.h>
40 #include <ardour/session.h>
41 #include <ardour/route_group.h>
42 #include <ardour/route.h>
43 #include <ardour/port.h>
44 #include <ardour/utils.h>
45 #include <ardour/diskstream.h>
46 #include <ardour/midi_playlist.h>
47 struct tm;
48
49 namespace ARDOUR {
50
51 class MidiEngine;
52 class Send;
53 class Session;
54 class MidiPlaylist;
55 class SMFSource;
56 class IO;
57
58 class MidiDiskstream : public Diskstream
59 {       
60   public:
61         MidiDiskstream (Session &, const string& name, Diskstream::Flag f = Recordable);
62         MidiDiskstream (Session &, const XMLNode&);
63
64         void set_io (ARDOUR::IO& io);
65
66         MidiDiskstream& ref() { _refcnt++; return *this; }
67         //void unref() { if (_refcnt) _refcnt--; if (_refcnt == 0) delete this; }
68         //uint32_t refcnt() const { return _refcnt; }
69
70         float playback_buffer_load() const;
71         float capture_buffer_load() const;
72
73         //void set_align_style (AlignStyle);
74         //void set_persistent_align_style (AlignStyle);
75
76         void set_record_enabled (bool yn, void *src);
77         //void set_speed (double);
78
79         int use_playlist (Playlist *);
80         int use_new_playlist ();
81         int use_copy_playlist ();
82
83         void start_scrub (jack_nframes_t where) {} // FIXME?
84         void end_scrub () {} // FIXME?
85
86         Playlist *playlist () { return _playlist; }
87
88         static sigc::signal<void,list<SMFSource*>*> DeleteSources;
89
90         /* stateful */
91
92         XMLNode& get_state(void);
93         int set_state(const XMLNode& node);
94
95         void monitor_input (bool);
96
97         //void handle_input_change (IOChange, void *src);
98
99   protected:
100         friend class Session;
101
102         /* the Session is the only point of access for these
103            because they require that the Session is "inactive"
104            while they are called.
105         */
106
107         void set_pending_overwrite(bool);
108         int  overwrite_existing_buffers ();
109         void reverse_scrub_buffer (bool to_forward) {} // FIXME?
110         void set_block_size (jack_nframes_t);
111         int  internal_playback_seek (jack_nframes_t distance);
112         int  can_internal_playback_seek (jack_nframes_t distance);
113         int  rename_write_sources ();
114         void reset_write_sources (bool, bool force = false);
115         void non_realtime_input_change ();
116
117         uint32_t read_data_count() const { return _read_data_count; }
118         uint32_t write_data_count() const { return _write_data_count; }
119
120   protected:
121         friend class Auditioner;
122         int  seek (jack_nframes_t which_sample, bool complete_refill = false);
123
124   protected:
125         friend class MidiTrack;
126
127         int  process (jack_nframes_t transport_frame, jack_nframes_t nframes, jack_nframes_t offset, bool can_record, bool rec_monitors_input);
128         bool commit  (jack_nframes_t nframes);
129
130   private:
131
132         /* use unref() to destroy a diskstream */
133         ~MidiDiskstream();
134
135         MidiPlaylist* _playlist;
136
137         /* the two central butler operations */
138
139         int do_flush (char * workbuf, bool force = false);
140         int do_refill (RawMidi *mixdown_buffer, float *gain_buffer, char *workbuf);
141         
142         virtual int non_realtime_do_refill() { return do_refill(0, 0, 0); }
143
144         int read (RawMidi* buf, RawMidi* mixdown_buffer, char * workbuf, jack_nframes_t& start, jack_nframes_t cnt, bool reversed);
145
146         /* XXX fix this redundancy ... */
147
148         //void playlist_changed (Change);
149         //void playlist_modified ();
150         void playlist_deleted (Playlist*);
151         void session_controls_changed (Session::ControlType) {} // FIXME?
152
153         void finish_capture (bool rec_monitors_input);
154         void clean_up_capture (struct tm&, time_t, bool abort) {} // FIXME?
155         void transport_stopped (struct tm&, time_t, bool abort);
156
157         struct CaptureInfo {
158             uint32_t start;
159             uint32_t frames;
160         };
161
162         void init (Diskstream::Flag);
163
164         int use_new_write_source (uint32_t n=0);
165         int use_new_fade_source (uint32_t n=0) { return 0; } // FIXME?
166
167         int find_and_use_playlist (const string&);
168
169         void allocate_temporary_buffers ();
170
171         int  create_input_port () { return 0; } // FIXME?
172         int  connect_input_port () { return 0; } // FIXME?
173         int  seek_unlocked (jack_nframes_t which_sample) { return 0; } // FIXME?
174
175         int ports_created () { return 0; } // FIXME?
176
177         //bool realtime_set_speed (double, bool global_change);
178         void non_realtime_set_speed ();
179
180         int use_pending_capture_data (XMLNode& node);
181
182         void get_input_sources ();
183         void check_record_status (jack_nframes_t transport_frame, jack_nframes_t nframes, bool can_record);
184         void set_align_style_from_io();
185         void setup_destructive_playlist ();
186         void use_destructive_playlist ();
187         
188         std::list<Region*>      _last_capture_regions;
189         std::vector<SMFSource*> _capturing_sources;
190 };
191
192 }; /* namespace ARDOUR */
193
194 #endif /* __ardour_midi_diskstream_h__ */