MIDI branch becomes trunk
[ardour.git] / libs / ardour / ardour / redirect.h
1 /*
2     Copyright (C) 2001 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 */
19
20 #ifndef __ardour_redirect_h__
21 #define __ardour_redirect_h__
22
23 #include <string>
24 #include <vector>
25 #include <set>
26 #include <map>
27 #include <boost/shared_ptr.hpp>
28 #include <sigc++/signal.h>
29
30 #include <glibmm/thread.h>
31
32 #include <pbd/undo.h>
33
34 #include <ardour/ardour.h>
35 #include <ardour/io.h>
36 #include <ardour/automation_event.h>
37
38 using std::map;
39 using std::set;
40 using std::string;
41 using std::vector;
42
43 class XMLNode;
44
45 namespace ARDOUR {
46
47 class Session;
48
49 class Redirect : public IO
50 {
51   public:
52         static const string state_node_name;
53
54         Redirect (Session&, const string& name, Placement,
55                   int input_min = -1, int input_max = -1, int output_min = -1, int output_max = -1);
56         Redirect (const Redirect&);
57         virtual ~Redirect ();
58
59         static boost::shared_ptr<Redirect> clone (boost::shared_ptr<const Redirect>);
60
61         bool active () const { return _active; }
62         void set_active (bool yn, void *src);
63
64         virtual ChanCount output_streams() const { return n_outputs(); }
65         virtual ChanCount input_streams () const { return n_inputs(); }
66         virtual ChanCount natural_output_streams() const { return n_outputs(); }
67         virtual ChanCount natural_input_streams () const { return n_inputs(); }
68
69         uint32_t sort_key() const { return _sort_key; }
70         void set_sort_key (uint32_t key);
71
72         Placement placement() const { return _placement; }
73         void set_placement (Placement, void *src);
74
75         virtual void run (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset) = 0;
76         virtual void activate () = 0;
77         virtual void deactivate () = 0;
78         virtual nframes_t latency() { return 0; }
79
80         virtual void set_block_size (nframes_t nframes) {}
81
82         sigc::signal<void,Redirect*,void*> active_changed;
83         sigc::signal<void,Redirect*,void*> placement_changed;
84         sigc::signal<void,Redirect*,bool>  AutomationPlaybackChanged;
85         sigc::signal<void,Redirect*,uint32_t> AutomationChanged;
86
87         static sigc::signal<void,Redirect*> RedirectCreated;
88         
89         XMLNode& state (bool full);
90         XMLNode& get_state (void);
91         int set_state (const XMLNode&);
92
93         void *get_gui () const { return _gui; }
94         void  set_gui (void *p) { _gui = p; }
95
96         virtual string describe_parameter (uint32_t which);
97         virtual float default_parameter_value (uint32_t which) {
98                 return 1.0f;
99         }
100
101         void what_has_automation (set<uint32_t>&) const;
102         void what_has_visible_automation (set<uint32_t>&) const;
103         const set<uint32_t>& what_can_be_automated () const { return can_automate_list; }
104
105         void mark_automation_visible (uint32_t, bool);
106         
107         AutomationList& automation_list (uint32_t);
108         bool find_next_event (nframes_t, nframes_t, ControlEvent&) const;
109
110         virtual void transport_stopped (nframes_t frame) {};
111         
112   protected:
113         /* children may use this stuff as they see fit */
114
115         map<uint32_t,AutomationList*> parameter_automation;
116         set<uint32_t> visible_parameter_automation;
117
118         mutable Glib::Mutex _automation_lock;
119
120         void can_automate (uint32_t);
121         set<uint32_t> can_automate_list;
122
123         virtual void automation_list_creation_callback (uint32_t, AutomationList&) {}
124
125         int set_automation_state (const XMLNode&);
126         XMLNode& get_automation_state ();
127         
128   private:
129         bool _active;
130         Placement _placement;
131         uint32_t _sort_key;
132         void* _gui;  /* generic, we don't know or care what this is */
133
134         int old_set_automation_state (const XMLNode&);
135         int load_automation (std::string path);
136 };
137
138 } // namespace ARDOUR
139
140 #endif /* __ardour_redirect_h__ */