rework MIDI [processor|plugin] chain
[ardour.git] / libs / ardour / ardour / processor.h
1 /*
2     Copyright (C) 2009-2010 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_processor_h__
21 #define __ardour_processor_h__
22
23 #include <vector>
24 #include <string>
25 #include <exception>
26
27 #include "pbd/statefuldestructible.h"
28
29 #include "ardour/ardour.h"
30 #include "ardour/buffer_set.h"
31 #include "ardour/latent.h"
32 #include "ardour/session_object.h"
33 #include "ardour/types.h"
34 #include "ardour/automatable.h"
35
36 class XMLNode;
37
38 namespace ARDOUR {
39
40 class Session;
41 class Route;
42
43 /** A mixer strip element - plugin, send, meter, etc */
44 class Processor : public SessionObject, public Automatable, public Latent
45 {
46   public:
47         static const std::string state_node_name;
48
49         Processor(Session&, const std::string& name);
50         Processor (const Processor& other);
51
52         virtual ~Processor() { }
53
54         virtual std::string display_name() const { return SessionObject::name(); }
55
56         virtual bool display_to_user() const { return _display_to_user; }
57         virtual void set_display_to_user (bool);
58
59         bool active () const { return _pending_active; }
60
61         virtual bool does_routing() const { return false; }
62
63         bool get_next_ab_is_active () const { return _next_ab_is_active; }
64         void set_next_ab_is_active (bool yn) { _next_ab_is_active = yn; }
65
66         virtual framecnt_t signal_latency() const { return 0; }
67
68         virtual int set_block_size (pframes_t /*nframes*/) { return 0; }
69         virtual bool requires_fixed_sized_buffers() const { return false; }
70
71         /** @param result_required true if, on return from this method, @a bufs is required to contain valid data;
72          *  if false, the method need not bother writing to @a bufs if it doesn't want to.
73          */
74         virtual void run (BufferSet& /*bufs*/, framepos_t /*start_frame*/, framepos_t /*end_frame*/, pframes_t /*nframes*/, bool /*result_required*/) {}
75         virtual void silence (framecnt_t /*nframes*/) {}
76
77         virtual void activate ()   { _pending_active = true; ActiveChanged(); }
78         virtual void deactivate () { _pending_active = false; ActiveChanged(); }
79         virtual void flush() {}
80
81         virtual bool configure_io (ChanCount in, ChanCount out);
82
83         /* Derived classes should override these, or processor appears as an in-place pass-through */
84
85         virtual bool can_support_io_configuration (const ChanCount& in, ChanCount& out) = 0;
86         virtual ChanCount input_streams () const { return _configured_input; }
87         virtual ChanCount output_streams() const { return _configured_output; }
88
89         virtual void realtime_handle_transport_stopped () {}
90         virtual void realtime_locate () {}
91
92         /* most processors won't care about this, but plugins that
93            receive MIDI or similar data from an input source that
94            may suddenly go "quiet" because of monitoring changes
95            need to know about it.
96         */
97         virtual void monitoring_changed() {}
98
99         /* note: derived classes should implement state(), NOT get_state(), to allow
100            us to merge C++ inheritance and XML lack-of-inheritance reasonably
101            smoothly.
102          */
103
104         virtual XMLNode& state (bool full);
105         XMLNode& get_state (void);
106         int set_state (const XMLNode&, int version);
107
108         void set_pre_fader (bool);
109
110         PBD::Signal0<void>                     ActiveChanged;
111         PBD::Signal2<void,ChanCount,ChanCount> ConfigurationChanged;
112
113         void  set_ui (void*);
114         void* get_ui () const { return _ui_pointer; }
115
116 protected:
117         virtual int set_state_2X (const XMLNode&, int version);
118
119         int       _pending_active;
120         bool      _active;
121         bool      _next_ab_is_active;
122         bool      _configured;
123         ChanCount _configured_input;
124         ChanCount _configured_output;
125         bool      _display_to_user;
126         bool      _pre_fader; ///< true if this processor is currently placed before the Amp, otherwise false
127         void*     _ui_pointer;
128 };
129
130 } // namespace ARDOUR
131
132 #endif /* __ardour_processor_h__ */