Merge libs/ardour and gtk2_ardour with 2.0-ongoing R2837.
[ardour.git] / gtk2_ardour / processor_box.h
1 /*
2     Copyright (C) 2004 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_gtk_processor_box__
21 #define __ardour_gtk_processor_box__
22
23 #include <vector>
24
25 #include <cmath>
26 #include <gtkmm/box.h>
27 #include <gtkmm/eventbox.h>
28 #include <gtkmm/menu.h>
29 #include <gtkmm/scrolledwindow.h>
30 #include <gtkmm2ext/dndtreeview.h>
31 #include <gtkmm2ext/auto_spin.h>
32 #include <gtkmm2ext/click_box.h>
33 #include <gtkmm2ext/dndtreeview.h>
34
35 #include <pbd/stateful.h>
36
37 #include <ardour/types.h>
38 #include <ardour/ardour.h>
39 #include <ardour/io.h>
40 #include <ardour/processor.h>
41 #include <ardour/io_processor.h>
42
43 #include <pbd/fastlog.h>
44
45 #include "route_ui.h"
46 #include "io_selector.h"
47 #include "enums.h"
48
49 class MotionController;
50 class PluginSelector;
51 class PluginUIWindow;
52 class RouteRedirectSelection;
53 class SendUIWindow;
54
55 namespace ARDOUR {
56         class Bundle;
57         class Processor;
58         class Plugin;
59         class PluginInsert;
60         class PortInsert;
61         class Route;
62         class Send;
63         class Session;
64 }
65
66
67 class ProcessorBox : public Gtk::HBox
68 {
69   public:
70         ProcessorBox (ARDOUR::Placement, ARDOUR::Session&, 
71                      boost::shared_ptr<ARDOUR::Route>, PluginSelector &, RouteRedirectSelection &, bool owner_is_mixer = false);
72         ~ProcessorBox ();
73
74         void set_width (Width);
75
76         void update();
77
78         void select_all_processors ();
79         void deselect_all_processors ();
80         void select_all_plugins ();
81         void select_all_sends ();
82         
83         sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > InsertSelected;
84         sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > InsertUnselected;
85         
86         static void register_actions();
87
88   protected:
89         void set_stuff_from_route ();
90
91   private:
92         boost::shared_ptr<ARDOUR::Route>  _route;
93         ARDOUR::Session &   _session;
94         bool                _owner_is_mixer;
95         bool                 ab_direction;
96
97         ARDOUR::Placement   _placement;
98
99         PluginSelector     & _plugin_selector;
100         RouteRedirectSelection  & _rr_selection;
101
102         void route_going_away ();
103
104         struct ModelColumns : public Gtk::TreeModel::ColumnRecord {
105             ModelColumns () {
106                     add (text);
107                     add (processor);
108                     add (color);
109             }
110             Gtk::TreeModelColumn<std::string>                           text;
111             Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Processor> > processor;
112             Gtk::TreeModelColumn<Gdk::Color>                            color;
113         };
114
115         ModelColumns columns;
116         Glib::RefPtr<Gtk::ListStore> model;
117         
118         void selection_changed ();
119
120         static bool get_colors;
121         static Gdk::Color* active_processor_color;
122         static Gdk::Color* inactive_processor_color;
123         
124         Gtk::EventBox          processor_eventbox;
125         //Gtk::HBox              processor_hpacker;
126         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Processor> > processor_display;
127         Gtk::ScrolledWindow    processor_scroller;
128
129         void object_drop (std::string type, uint32_t cnt, const boost::shared_ptr<ARDOUR::Processor>*);
130
131         Width _width;
132         
133         Gtk::Menu *send_action_menu;
134         void build_send_action_menu ();
135
136         void new_send ();
137         void show_send_controls ();
138
139         Gtk::Menu *processor_menu;
140         gint processor_menu_map_handler (GdkEventAny *ev);
141         Gtk::Menu * build_processor_menu ();
142         void build_processor_tooltip (Gtk::EventBox&, string);
143         void show_processor_menu (gint arg);
144
145         void choose_send ();
146         bool send_io_finished (GdkEventAny*,boost::shared_ptr<ARDOUR::Send>, SendUIWindow*);
147         void choose_processor ();
148         void choose_plugin ();
149         void processor_plugin_chosen (boost::shared_ptr<ARDOUR::Plugin>);
150
151         bool no_processor_redisplay;
152         bool ignore_delete;
153
154         bool processor_button_press_event (GdkEventButton *);
155         bool processor_button_release_event (GdkEventButton *);
156         void redisplay_processors ();
157         void add_processor_to_display (boost::shared_ptr<ARDOUR::Processor>);
158         void row_deleted (const Gtk::TreeModel::Path& path);
159         void show_processor_active (boost::weak_ptr<ARDOUR::Processor>);
160         void show_processor_name (boost::weak_ptr<ARDOUR::Processor>);
161         string processor_name (boost::weak_ptr<ARDOUR::Processor>);
162
163         void remove_processor_gui (boost::shared_ptr<ARDOUR::Processor>);
164
165         void processors_reordered (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&, int*);
166         void compute_processor_sort_keys ();
167         vector<sigc::connection> processor_active_connections;
168         vector<sigc::connection> processor_name_connections;
169         
170         bool processor_drag_in_progress;
171         void processor_drag_begin (GdkDragContext*);
172         void processor_drag_end (GdkDragContext*);
173         void all_processors_active(bool state);
174         void all_plugins_active(bool state);
175         void ab_plugins ();
176
177         void cut_processors ();
178         void copy_processors ();
179         void paste_processors ();
180         void delete_processors ();
181         void clear_processors ();
182         void clone_processors ();
183         void rename_processors ();
184
185         void for_selected_processors (void (ProcessorBox::*pmf)(boost::shared_ptr<ARDOUR::Processor>));
186         void get_selected_processors (vector<boost::shared_ptr<ARDOUR::Processor> >&);
187
188         static Glib::RefPtr<Gtk::Action> paste_action;
189         void paste_processor_list (std::list<boost::shared_ptr<ARDOUR::Processor> >& processors);
190         void paste_processor_state (const XMLNode&);
191         
192         void activate_processor (boost::shared_ptr<ARDOUR::Processor>);
193         void deactivate_processor (boost::shared_ptr<ARDOUR::Processor>);
194         void edit_processor (boost::shared_ptr<ARDOUR::Processor>);
195         void hide_processor_editor (boost::shared_ptr<ARDOUR::Processor>);
196         void rename_processor (boost::shared_ptr<ARDOUR::Processor>);
197
198         gint idle_delete_processor (boost::weak_ptr<ARDOUR::Processor>);
199
200         void weird_plugin_dialog (ARDOUR::Plugin& p, ARDOUR::Route::ProcessorStreams streams, boost::shared_ptr<ARDOUR::IO> io);
201
202         static ProcessorBox* _current_processor_box;
203         static bool enter_box (GdkEventCrossing*, ProcessorBox*);
204         static bool leave_box (GdkEventCrossing*, ProcessorBox*);
205
206         static void rb_choose_plugin ();
207         static void rb_choose_processor ();
208         static void rb_choose_send ();
209         static void rb_clear ();
210         static void rb_cut ();
211         static void rb_copy ();
212         static void rb_paste ();
213         static void rb_delete ();
214         static void rb_rename ();
215         static void rb_select_all ();
216         static void rb_deselect_all ();
217         static void rb_activate ();
218         static void rb_deactivate ();
219         static void rb_activate_all ();
220         static void rb_deactivate_all ();
221         static void rb_edit ();
222         static void rb_ab_plugins ();
223         static void rb_deactivate_plugins ();
224         
225         void route_name_changed (PluginUIWindow* plugin_ui, boost::weak_ptr<ARDOUR::PluginInsert> pi);
226         std::string generate_processor_title (boost::shared_ptr<ARDOUR::PluginInsert> pi);
227 };
228
229 #endif /* __ardour_gtk_processor_box__ */