c81d4e576190533133487167963f31cf79defd1b
[ardour.git] / libs / ardour / ardour / insert.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$
19 */
20
21 #ifndef __ardour_insert_h__
22 #define __ardour_insert_h__
23
24 #include <vector>
25 #include <string>
26 #include <exception>
27
28 #include <sigc++/signal.h>
29 #include <ardour/ardour.h>
30 #include <ardour/redirect.h>
31 #include <ardour/plugin_state.h>
32 #include <ardour/types.h>
33
34 class XMLNode;
35
36 namespace MIDI {
37         class Port;
38 }
39
40 namespace ARDOUR {
41
42 class Session;
43 class Route;
44 class Plugin;
45
46 class Insert : public Redirect
47 {
48   public:
49         Insert(Session& s, Placement p);
50         Insert(Session& s, string name, Placement p);
51
52         Insert(Session& s, Placement p, int imin, int imax, int omin, int omax);
53         
54         virtual ~Insert() { }
55
56         virtual void run (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset) = 0;
57         virtual void activate () {}
58         virtual void deactivate () {}
59
60         virtual int32_t can_support_input_configuration (int32_t in) const = 0;
61         virtual int32_t configure_io (int32_t magic, int32_t in, int32_t out) = 0;
62         virtual int32_t compute_output_streams (int32_t cnt) const = 0;
63 };
64
65 class PortInsert : public Insert 
66 {
67   public:
68         PortInsert (Session&, Placement);
69         PortInsert (Session&, const XMLNode&);
70         PortInsert (const PortInsert&);
71         ~PortInsert ();
72
73         XMLNode& state(bool full);
74         XMLNode& get_state(void);
75         int set_state(const XMLNode&);
76
77         void init ();
78         void run (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset);
79
80         jack_nframes_t latency();
81         
82         uint32_t output_streams() const;
83         uint32_t input_streams() const;
84
85         int32_t can_support_input_configuration (int32_t) const;
86         int32_t configure_io (int32_t magic, int32_t in, int32_t out);
87         int32_t compute_output_streams (int32_t cnt) const;
88 };
89
90 struct PluginInsertState : public RedirectState
91 {
92     PluginInsertState (std::string why) 
93             : RedirectState (why) {}
94     ~PluginInsertState() {}
95
96     PluginState plugin_state;
97 };
98
99 class PluginInsert : public Insert
100 {
101   public:
102         PluginInsert (Session&, boost::shared_ptr<Plugin>, Placement);
103         PluginInsert (Session&, const XMLNode&);
104         PluginInsert (const PluginInsert&);
105         ~PluginInsert ();
106
107         static const string port_automation_node_name;
108         
109         XMLNode& state(bool);
110         XMLNode& get_state(void);
111         int set_state(const XMLNode&);
112
113         StateManager::State* state_factory (std::string why) const;
114         Change restore_state (StateManager::State&);
115
116         void run (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset);
117         void silence (jack_nframes_t nframes, jack_nframes_t offset);
118         void activate ();
119         void deactivate ();
120
121         void set_block_size (jack_nframes_t nframes);
122
123         uint32_t output_streams() const;
124         uint32_t input_streams() const;
125         uint32_t natural_output_streams() const;
126         uint32_t natural_input_streams() const;
127
128         int      set_count (uint32_t num);
129         uint32_t get_count () const { return _plugins.size(); }
130
131         int32_t can_support_input_configuration (int32_t) const;
132         int32_t configure_io (int32_t magic, int32_t in, int32_t out);
133         int32_t compute_output_streams (int32_t cnt) const;
134
135         bool is_generator() const;
136
137         void set_parameter (uint32_t port, float val);
138
139         AutoState get_port_automation_state (uint32_t port);
140         void set_port_automation_state (uint32_t port, AutoState);
141         void protect_automation ();
142
143         float default_parameter_value (uint32_t which);
144
145         boost::shared_ptr<Plugin> plugin(uint32_t num=0) const {
146                 if (num < _plugins.size()) { 
147                         return _plugins[num];
148                 } else {
149                         return _plugins[0]; // we always have one
150                 }
151         }
152
153         PluginType type ();
154
155         string describe_parameter (uint32_t);
156
157         jack_nframes_t latency();
158
159         void transport_stopped (jack_nframes_t now);
160         void automation_snapshot (jack_nframes_t now);
161
162   protected:
163         void store_state (PluginInsertState&) const;
164
165   private:
166
167         void parameter_changed (uint32_t, float);
168         
169         vector<boost::shared_ptr<Plugin> > _plugins;
170         void automation_run (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset);
171         void connect_and_run (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset, bool with_auto, jack_nframes_t now = 0);
172
173         void init ();
174         void set_automatable ();
175         void auto_state_changed (uint32_t which);
176         void automation_list_creation_callback (uint32_t, AutomationList&);
177
178         boost::shared_ptr<Plugin> plugin_factory (boost::shared_ptr<Plugin>);
179 };
180
181 } // namespace ARDOUR
182
183 #endif /* __ardour_insert_h__ */