Tweak colouring in the processor list.
[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 <cmath>
24 #include <vector>
25
26 #include <boost/function.hpp>
27
28 #include <gtkmm/box.h>
29 #include <gtkmm/eventbox.h>
30 #include <gtkmm/menu.h>
31 #include <gtkmm/scrolledwindow.h>
32 #include "gtkmm2ext/dndtreeview.h"
33 #include "gtkmm2ext/auto_spin.h"
34 #include "gtkmm2ext/click_box.h"
35 #include "gtkmm2ext/dndvbox.h"
36 #include "gtkmm2ext/pixfader.h"
37
38 #include "pbd/stateful.h"
39 #include "pbd/signals.h"
40
41 #include "ardour/types.h"
42 #include "ardour/ardour.h"
43 #include "ardour/plugin_insert.h"
44 #include "ardour/port_insert.h"
45 #include "ardour/processor.h"
46 #include "ardour/route.h"
47 #include "ardour/session_handle.h"
48
49 #include "pbd/fastlog.h"
50
51 #include "plugin_interest.h"
52 #include "io_selector.h"
53 #include "send_ui.h"
54 #include "enums.h"
55 #include "window_proxy.h"
56
57 class MotionController;
58 class PluginSelector;
59 class PluginUIWindow;
60 class RouteRedirectSelection;
61 class MixerStrip;
62
63 namespace ARDOUR {
64         class Connection;
65         class IO;
66         class Insert;
67         class Plugin;
68         class PluginInsert;
69         class PortInsert;
70         class Route;
71         class Send;
72         class Session;
73 }
74
75 class ProcessorBox;
76
77 /** A WindowProxy for Processor UI windows; it knows how to ask a ProcessorBox
78  *  to create a UI window for a particular processor.
79  */
80 class ProcessorWindowProxy : public WindowProxy<Gtk::Window>
81 {
82 public:
83         ProcessorWindowProxy (std::string const &, XMLNode const *, ProcessorBox *, boost::weak_ptr<ARDOUR::Processor>);
84
85         void show ();
86         bool rc_configured () const {
87                 return false;
88         }
89
90         boost::weak_ptr<ARDOUR::Processor> processor () const {
91                 return _processor;
92         }
93
94         bool marked;
95
96 private:
97         ProcessorBox* _processor_box;
98         boost::weak_ptr<ARDOUR::Processor> _processor;
99 };
100
101 class ProcessorEntry : public Gtkmm2ext::DnDVBoxChild, public sigc::trackable
102 {
103 public:
104         ProcessorEntry (boost::shared_ptr<ARDOUR::Processor>, Width);
105
106         Gtk::EventBox& action_widget ();
107         Gtk::Widget& widget ();
108         std::string drag_text () const;
109         void set_visual_state (Gtk::StateType);
110
111         enum Position {
112                 PreFader,
113                 Fader,
114                 PostFader
115         };
116         
117         void set_position (Position);
118         boost::shared_ptr<ARDOUR::Processor> processor () const;
119         void set_enum_width (Width);
120         virtual void set_pixel_width (int) {}
121
122 protected:
123         
124         Gtk::VBox _vbox;
125         
126 private:
127
128         void active_toggled ();
129         void processor_active_changed ();
130         void processor_property_changed (const PBD::PropertyChange&);
131         std::string name () const;
132         void setup_visuals ();
133
134         Gtk::Frame _frame;
135         Gtk::EventBox _event_box;
136         Gtk::Label _name;
137         Gtk::HBox _hbox;
138         Gtk::CheckButton _active;
139         boost::shared_ptr<ARDOUR::Processor> _processor;
140         Width _width;
141         Gtk::StateType _visual_state;
142         Position _position;
143         PBD::ScopedConnection active_connection;
144         PBD::ScopedConnection name_connection;
145 };
146
147 class SendProcessorEntry : public ProcessorEntry
148 {
149 public:
150         SendProcessorEntry (boost::shared_ptr<ARDOUR::Send>, Width);
151
152         static void setup_slider_pix ();
153
154         void set_enum_width (Width, int);
155         void set_pixel_width (int);
156
157 private:
158         void show_gain ();
159         void gain_adjusted ();
160         
161         boost::shared_ptr<ARDOUR::Send> _send;
162         Gtk::Adjustment _adjustment;
163         Gtkmm2ext::HSliderController _fader;
164         bool _ignore_gain_change;
165         PBD::ScopedConnection send_gain_connection;
166
167         static Glib::RefPtr<Gdk::Pixbuf> _slider;
168 };
169
170 class ProcessorBox : public Gtk::HBox, public PluginInterestedObject, public ARDOUR::SessionHandlePtr
171 {
172   public:
173         ProcessorBox (ARDOUR::Session*, boost::function<PluginSelector*()> get_plugin_selector,
174                       RouteRedirectSelection&, MixerStrip* parent, bool owner_is_mixer = false);
175         ~ProcessorBox ();
176
177         void set_route (boost::shared_ptr<ARDOUR::Route>);
178         void set_width (Width);
179
180         void update();
181
182         void select_all_processors ();
183         void deselect_all_processors ();
184         void select_all_plugins ();
185         void select_all_inserts ();
186         void select_all_sends ();
187
188         Gtk::Window* get_processor_ui (boost::shared_ptr<ARDOUR::Processor>) const;
189         void toggle_edit_processor (boost::shared_ptr<ARDOUR::Processor>);
190         
191         sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > ProcessorSelected;
192         sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > ProcessorUnselected;
193
194         static void register_actions();
195
196   private:
197
198         /* prevent copy construction */
199         ProcessorBox (ProcessorBox const &);
200         
201         boost::shared_ptr<ARDOUR::Route>  _route;
202         MixerStrip*         _parent_strip; // null if in RouteParamsUI
203         bool                _owner_is_mixer;
204         bool                 ab_direction;
205         PBD::ScopedConnectionList _mixer_strip_connections;
206         PBD::ScopedConnectionList _route_connections;
207
208         boost::function<PluginSelector*()> _get_plugin_selector;
209
210         boost::shared_ptr<ARDOUR::Processor> _processor_being_created;
211
212         ARDOUR::Placement _placement;
213
214         RouteRedirectSelection& _rr_selection;
215
216         void route_going_away ();
217
218         void selection_changed ();
219
220         Gtk::EventBox          processor_eventbox;
221         Gtk::HBox              processor_hpacker;
222         Gtkmm2ext::DnDVBox<ProcessorEntry> processor_display;
223         Gtk::ScrolledWindow    processor_scroller;
224
225         void object_drop (Gtkmm2ext::DnDVBox<ProcessorEntry> *, ProcessorEntry *, Glib::RefPtr<Gdk::DragContext> const &);
226
227         Width _width;
228
229         Gtk::Menu *send_action_menu;
230         void build_send_action_menu ();
231
232         void new_send ();
233         void show_send_controls ();
234
235         Gtk::Menu *processor_menu;
236         gint processor_menu_map_handler (GdkEventAny *ev);
237         Gtk::Menu * build_processor_menu ();
238         void build_processor_tooltip (Gtk::EventBox&, std::string);
239         void show_processor_menu (gint arg);
240         Gtk::Menu* build_possible_aux_menu();
241
242         void choose_aux (boost::weak_ptr<ARDOUR::Route>);
243         void choose_send ();
244         void send_io_finished (IOSelector::Result, boost::weak_ptr<ARDOUR::Processor>, IOSelectorWindow*);
245         void return_io_finished (IOSelector::Result, boost::weak_ptr<ARDOUR::Processor>, IOSelectorWindow*);
246         void choose_insert ();
247         void choose_plugin ();
248         bool use_plugins (const SelectedPlugins&);
249
250         bool no_processor_redisplay;
251
252         bool enter_notify (GdkEventCrossing *ev);
253         bool leave_notify (GdkEventCrossing *ev);
254         bool processor_key_press_event (GdkEventKey *);
255         bool processor_key_release_event (GdkEventKey *);
256         bool processor_button_press_event (GdkEventButton *, ProcessorEntry *);
257         bool processor_button_release_event (GdkEventButton *, ProcessorEntry *);
258         void redisplay_processors ();
259         void add_processor_to_display (boost::weak_ptr<ARDOUR::Processor>);
260         void reordered ();
261         void report_failed_reorder ();
262         void route_processors_changed (ARDOUR::RouteProcessorChange);
263
264         void processors_reordered (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&, int*);
265         void compute_processor_sort_keys ();
266
267         void all_processors_active(bool state);
268         void all_plugins_active(bool state);
269         void ab_plugins ();
270
271         typedef std::vector<boost::shared_ptr<ARDOUR::Processor> > ProcSelection;
272
273         void cut_processors (const ProcSelection&);
274         void cut_processors ();
275         void copy_processors (const ProcSelection&);
276         void copy_processors ();
277         void delete_processors (const ProcSelection&);
278         void delete_processors ();
279         void paste_processors ();
280         void paste_processors (boost::shared_ptr<ARDOUR::Processor> before);
281
282         void delete_dragged_processors (const std::list<boost::shared_ptr<ARDOUR::Processor> >&);
283         void clear_processors ();
284         void clear_processors (ARDOUR::Placement);
285         void rename_processors ();
286
287         void for_selected_processors (void (ProcessorBox::*pmf)(boost::shared_ptr<ARDOUR::Processor>));
288         void get_selected_processors (ProcSelection&) const;
289
290         bool can_cut() const;
291
292         static Glib::RefPtr<Gtk::Action> cut_action;
293         static Glib::RefPtr<Gtk::Action> paste_action;
294         static Glib::RefPtr<Gtk::Action> rename_action;
295         static Glib::RefPtr<Gtk::Action> edit_action;
296         void paste_processor_state (const XMLNodeList&, boost::shared_ptr<ARDOUR::Processor>);
297
298         void activate_processor (boost::shared_ptr<ARDOUR::Processor>);
299         void deactivate_processor (boost::shared_ptr<ARDOUR::Processor>);
300         void hide_processor_editor (boost::shared_ptr<ARDOUR::Processor>);
301         void rename_processor (boost::shared_ptr<ARDOUR::Processor>);
302
303         gint idle_delete_processor (boost::weak_ptr<ARDOUR::Processor>);
304
305         void weird_plugin_dialog (ARDOUR::Plugin& p, ARDOUR::Route::ProcessorStreams streams);
306         void on_size_allocate (Gtk::Allocation &);
307
308         void setup_entry_positions ();
309         
310         static ProcessorBox* _current_processor_box;
311
312         static void rb_choose_aux (boost::weak_ptr<ARDOUR::Route>);
313         static void rb_choose_plugin ();
314         static void rb_choose_insert ();
315         static void rb_choose_send ();
316         static void rb_clear ();
317         static void rb_clear_pre ();
318         static void rb_clear_post ();
319         static void rb_cut ();
320         static void rb_copy ();
321         static void rb_paste ();
322         static void rb_delete ();
323         static void rb_rename ();
324         static void rb_select_all ();
325         static void rb_deselect_all ();
326         static void rb_activate_all ();
327         static void rb_deactivate_all ();
328         static void rb_ab_plugins ();
329         static void rb_edit ();
330
331         void route_property_changed (const PBD::PropertyChange&);
332         std::string generate_processor_title (boost::shared_ptr<ARDOUR::PluginInsert> pi);
333
334         std::list<ProcessorWindowProxy*> _processor_window_proxies;
335         void set_processor_ui (boost::shared_ptr<ARDOUR::Processor>, Gtk::Window *);
336         void maybe_add_processor_to_ui_list (boost::weak_ptr<ARDOUR::Processor>);
337
338         bool one_processor_can_be_edited ();
339         bool processor_can_be_edited (boost::shared_ptr<ARDOUR::Processor>);
340
341         void mixer_strip_delivery_changed (boost::weak_ptr<ARDOUR::Delivery>);
342 };
343
344 #endif /* __ardour_gtk_processor_box__ */