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