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