a gadzillion changes all over the place. nothing is finished, but all is better than...
[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/plugin_insert.h"
40 #include "ardour/port_insert.h"
41 #include "ardour/processor.h"
42
43 #include "pbd/fastlog.h"
44
45 #include "plugin_interest.h"
46 #include "route_ui.h"
47 #include "io_selector.h"
48 #include "send_ui.h"
49 #include "enums.h"
50
51 class MotionController;
52 class PluginSelector;
53 class PluginUIWindow;
54 class RouteRedirectSelection;
55
56 namespace ARDOUR {
57         class Connection;
58         class IO;
59         class Insert;
60         class Plugin;
61         class PluginInsert;
62         class PortInsert;
63         class Route;
64         class Send;
65         class Session;
66 }
67
68 class ProcessorBox : public Gtk::HBox, public PluginInterestedObject
69 {
70   public:
71         ProcessorBox (ARDOUR::Placement, ARDOUR::Session&, PluginSelector &, RouteRedirectSelection &, bool owner_is_mixer = false);
72         ~ProcessorBox ();
73
74         void set_route (boost::shared_ptr<ARDOUR::Route>);
75         void set_width (Width);
76
77         void update();
78
79         void select_all_processors ();
80         void deselect_all_processors ();
81         void select_all_plugins ();
82         void select_all_inserts ();
83         void select_all_sends ();
84         
85         sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > ProcessorSelected;
86         sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > ProcessorUnselected;
87         
88         static void register_actions();
89
90   private:
91         boost::shared_ptr<ARDOUR::Route>  _route;
92         ARDOUR::Session &   _session;
93         bool                _owner_is_mixer;
94         bool                 ab_direction;
95         std::vector<sigc::connection> connections;
96
97         boost::shared_ptr<ARDOUR::Processor> _processor_being_created;
98
99         ARDOUR::Placement   _placement;
100
101         PluginSelector     & _plugin_selector;
102         RouteRedirectSelection  & _rr_selection;
103
104         void route_going_away ();
105
106         struct ModelColumns : public Gtk::TreeModel::ColumnRecord {
107             ModelColumns () {
108                     add (text);
109                     add (processor);
110                     add (color);
111             }
112             Gtk::TreeModelColumn<std::string>       text;
113             Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Processor> > processor;
114             Gtk::TreeModelColumn<Gdk::Color>        color;
115         };
116
117         ModelColumns columns;
118         Glib::RefPtr<Gtk::ListStore> model;
119         
120         void selection_changed ();
121
122         static bool get_colors;
123         static Gdk::Color* active_processor_color;
124         static Gdk::Color* inactive_processor_color;
125         
126         Gtk::EventBox          processor_eventbox;
127         Gtk::HBox              processor_hpacker;
128         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Processor> > processor_display;
129         Gtk::ScrolledWindow    processor_scroller;
130
131         void object_drop (const std::list<boost::shared_ptr<ARDOUR::Processor> >&, Gtk::TreeView*,
132                           Glib::RefPtr<Gdk::DragContext>& context);
133
134         Width _width;
135         
136         Gtk::Menu *send_action_menu;
137         void build_send_action_menu ();
138
139         void new_send ();
140         void show_send_controls ();
141
142         Gtk::Menu *processor_menu;
143         gint processor_menu_map_handler (GdkEventAny *ev);
144         Gtk::Menu * build_processor_menu ();
145         void build_processor_tooltip (Gtk::EventBox&, std::string);
146         void show_processor_menu (gint arg);
147
148         void choose_send ();
149         void send_io_finished (IOSelector::Result, boost::weak_ptr<ARDOUR::Processor>, IOSelectorWindow*);
150         void choose_return ();
151         void return_io_finished (IOSelector::Result, boost::weak_ptr<ARDOUR::Processor>, IOSelectorWindow*);
152         void choose_insert ();
153         void choose_plugin ();
154         void use_plugins (const SelectedPlugins&);
155
156         bool no_processor_redisplay;
157         bool ignore_delete;
158
159         bool processor_button_press_event (GdkEventButton *);
160         bool processor_button_release_event (GdkEventButton *);
161         void redisplay_processors ();
162         void add_processor_to_display (boost::weak_ptr<ARDOUR::Processor>);
163         void row_deleted (const Gtk::TreeModel::Path& path);
164         void show_processor_active (boost::weak_ptr<ARDOUR::Processor>);
165         void show_processor_name (boost::weak_ptr<ARDOUR::Processor>);
166         std::string processor_name (boost::weak_ptr<ARDOUR::Processor>);
167
168         void remove_processor_gui (boost::shared_ptr<ARDOUR::Processor>);
169
170         void processors_reordered (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&, int*);
171         void compute_processor_sort_keys ();
172         std::vector<sigc::connection> processor_active_connections;
173         std::vector<sigc::connection> processor_name_connections;
174         
175         bool processor_drag_in_progress;
176         void processor_drag_begin (GdkDragContext*);
177         void processor_drag_end (GdkDragContext*);
178         void all_processors_active(bool state);
179         void all_plugins_active(bool state);
180         void ab_plugins ();
181
182         void cut_processors ();
183         void copy_processors ();
184         void paste_processors ();
185         void delete_processors ();
186         void delete_dragged_processors (const std::list<boost::shared_ptr<ARDOUR::Processor> >&);
187         void clear_processors ();
188         void rename_processors ();
189
190         typedef std::vector<boost::shared_ptr<ARDOUR::Processor> > ProcSelection;
191
192         void for_selected_processors (void (ProcessorBox::*pmf)(boost::shared_ptr<ARDOUR::Processor>));
193         void get_selected_processors (ProcSelection&);
194
195         static Glib::RefPtr<Gtk::Action> paste_action;
196         void paste_processor_state (const XMLNodeList&);
197         
198         void activate_processor (boost::shared_ptr<ARDOUR::Processor>);
199         void deactivate_processor (boost::shared_ptr<ARDOUR::Processor>);
200         void edit_processor (boost::shared_ptr<ARDOUR::Processor>);
201         void hide_processor_editor (boost::shared_ptr<ARDOUR::Processor>);
202         void rename_processor (boost::shared_ptr<ARDOUR::Processor>);
203
204         gint idle_delete_processor (boost::weak_ptr<ARDOUR::Processor>);
205
206         void weird_plugin_dialog (ARDOUR::Plugin& p, ARDOUR::Route::ProcessorStreams streams, boost::shared_ptr<ARDOUR::IO> io);
207
208         static ProcessorBox* _current_processor_box;
209         static bool enter_box (GdkEventCrossing*, ProcessorBox*);
210         static bool leave_box (GdkEventCrossing*, ProcessorBox*);
211
212         static void rb_choose_plugin ();
213         static void rb_choose_insert ();
214         static void rb_choose_send ();
215         static void rb_choose_return ();
216         static void rb_clear ();
217         static void rb_cut ();
218         static void rb_copy ();
219         static void rb_paste ();
220         static void rb_delete ();
221         static void rb_rename ();
222         static void rb_select_all ();
223         static void rb_deselect_all ();
224         static void rb_activate ();
225         static void rb_deactivate ();
226         static void rb_activate_all ();
227         static void rb_deactivate_all ();
228         static void rb_ab_plugins ();
229         static void rb_edit ();
230         
231         void route_name_changed ();
232         std::string generate_processor_title (boost::shared_ptr<ARDOUR::PluginInsert> pi);
233 };
234
235 #endif /* __ardour_gtk_processor_box__ */