Merge big changes (mostly Controllable) from trunk
[ardour.git] / libs / ardour / ardour / midi_source.h
1 /*
2     Copyright (C) 2006 Paul Davis 
3         Written by Dave Robillard, 2006
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __ardour_midi_source_h__
21 #define __ardour_midi_source_h__
22
23 #include <string>
24
25 #include <time.h>
26
27 #include <glibmm/thread.h>
28
29 #include <sigc++/signal.h>
30
31 #include <ardour/source.h>
32 #include <ardour/ardour.h>
33 #include <pbd/stateful.h>
34 #include <pbd/xml++.h>
35
36 using std::string;
37
38 namespace ARDOUR {
39
40 /** Source for raw MIDI data */
41 class MidiSource : public Source
42 {
43   public:
44         MidiSource (string name);
45         MidiSource (const XMLNode&);
46         virtual ~MidiSource ();
47
48         /* returns the number of items in this `midi_source' */
49
50         // Applicable to MIDI?  With what unit? [DR]
51         virtual jack_nframes_t length() const {
52                 return _length;
53         }
54
55         virtual jack_nframes_t read (unsigned char *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
56         virtual jack_nframes_t write (unsigned char *src, jack_nframes_t cnt, char * workbuf);
57
58         virtual void mark_for_remove() = 0;
59         virtual void mark_streaming_write_completed () {}
60
61         void set_captured_for (string str) { _captured_for = str; }
62         string captured_for() const { return _captured_for; }
63
64         uint32_t read_data_count() const { return _read_data_count; }
65         uint32_t write_data_count() const { return _write_data_count; }
66
67         static sigc::signal<void,MidiSource*> MidiSourceCreated;
68                
69         mutable sigc::signal<void>  PeaksReady;
70         mutable sigc::signal<void,jack_nframes_t,jack_nframes_t>  PeakRangeReady;
71         
72         XMLNode& get_state ();
73         int set_state (const XMLNode&);
74
75   protected:
76         jack_nframes_t   _length;
77         string           _captured_for;
78
79         mutable uint32_t _read_data_count;  // modified in read()
80         mutable uint32_t _write_data_count; // modified in write()
81
82         virtual jack_nframes_t read_unlocked (unsigned char *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const = 0;
83         virtual jack_nframes_t write_unlocked (unsigned char *dst, jack_nframes_t cnt, char * workbuf) = 0;
84         
85         void update_length (jack_nframes_t pos, jack_nframes_t cnt);
86
87   private:
88         bool file_changed (string path);
89 };
90
91 }
92
93 #endif /* __ardour_midi_source_h__ */