daff50dfe7b57ffa9d2233bf0ce9864142725183
[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/dndvbox.h>
34 #include <gtkmm2ext/pixfader.h>
35
36 #include "pbd/stateful.h"
37
38 #include "ardour/types.h"
39 #include "ardour/ardour.h"
40 #include "ardour/plugin_insert.h"
41 #include "ardour/port_insert.h"
42 #include "ardour/processor.h"
43 #include "ardour/route.h"
44
45 #include "pbd/fastlog.h"
46
47 #include "plugin_interest.h"
48 #include "io_selector.h"
49 #include "send_ui.h"
50 #include "enums.h"
51
52 class MotionController;
53 class PluginSelector;
54 class PluginUIWindow;
55 class RouteRedirectSelection;
56 class MixerStrip;
57
58 namespace ARDOUR {
59         class Connection;
60         class IO;
61         class Insert;
62         class Plugin;
63         class PluginInsert;
64         class PortInsert;
65         class Route;
66         class Send;
67         class Session;
68 }
69
70 class ProcessorEntry : public Gtkmm2ext::DnDVBoxChild, public sigc::trackable
71 {
72 public:
73         ProcessorEntry (boost::shared_ptr<ARDOUR::Processor>, Width);
74
75         Gtk::EventBox& action_widget ();
76         Gtk::Widget& widget ();
77         std::string drag_text () const;
78         boost::shared_ptr<ARDOUR::Processor> processor () const;
79         void set_enum_width (Width);
80         virtual void set_pixel_width (int) {}
81
82 protected:
83         
84         Gtk::VBox _vbox;
85         
86 private:
87
88         void active_toggled ();
89         void processor_active_changed ();
90         void processor_name_changed ();
91         std::string name () const;
92         
93         Gtk::EventBox _event_box;
94         Gtk::Label _name;
95         Gtk::HBox _hbox;
96         Gtk::CheckButton _active;
97         boost::shared_ptr<ARDOUR::Processor> _processor;
98         Width _width;
99 };
100
101 class SendProcessorEntry : public ProcessorEntry
102 {
103 public:
104         SendProcessorEntry (boost::shared_ptr<ARDOUR::Send>, Width);
105
106         static void setup_slider_pix ();
107
108         void set_enum_width (Width, int);
109         void set_pixel_width (int);
110
111 private:
112         void show_gain ();
113         void gain_adjusted ();
114         
115         boost::shared_ptr<ARDOUR::Send> _send;
116         Gtk::Adjustment _adjustment;
117         Gtkmm2ext::HSliderController _fader;
118         bool _ignore_gain_change;
119         
120         static Glib::RefPtr<Gdk::Pixbuf> _slider;
121 };
122
123 class ProcessorBox : public Gtk::HBox, public PluginInterestedObject
124 {
125   public:
126         ProcessorBox (ARDOUR::Session&, sigc::slot<PluginSelector*> get_plugin_selector,
127                         RouteRedirectSelection&, MixerStrip* parent, bool owner_is_mixer = false);
128         ~ProcessorBox ();
129
130         void set_route (boost::shared_ptr<ARDOUR::Route>);
131         void set_width (Width);
132
133         void update();
134
135         void select_all_processors ();
136         void deselect_all_processors ();
137         void select_all_plugins ();
138         void select_all_inserts ();
139         void select_all_sends ();
140
141         sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > ProcessorSelected;
142         sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > ProcessorUnselected;
143
144         static void register_actions();
145
146   private:
147         boost::shared_ptr<ARDOUR::Route>  _route;
148         ARDOUR::Session &   _session;
149         MixerStrip*         _parent_strip; // null if in RouteParamsUI
150         bool                _owner_is_mixer;
151         bool                 ab_direction;
152         std::vector<sigc::connection> connections;
153
154         sigc::slot<PluginSelector*> _get_plugin_selector;
155
156         boost::shared_ptr<ARDOUR::Processor> _processor_being_created;
157
158         ARDOUR::Placement _placement;
159
160         RouteRedirectSelection& _rr_selection;
161
162         void route_going_away ();
163
164         void selection_changed ();
165
166         Gtk::EventBox          processor_eventbox;
167         Gtk::HBox              processor_hpacker;
168         Gtkmm2ext::DnDVBox<ProcessorEntry> processor_display;
169         Gtk::ScrolledWindow    processor_scroller;
170
171         void object_drop (Gtkmm2ext::DnDVBox<ProcessorEntry> *, ProcessorEntry *, Glib::RefPtr<Gdk::DragContext> const &);
172
173         Width _width;
174
175         Gtk::Menu *send_action_menu;
176         void build_send_action_menu ();
177
178         void new_send ();
179         void show_send_controls ();
180
181         Gtk::Menu *processor_menu;
182         gint processor_menu_map_handler (GdkEventAny *ev);
183         Gtk::Menu * build_processor_menu ();
184         void build_processor_tooltip (Gtk::EventBox&, std::string);
185         void show_processor_menu (gint arg);
186         Gtk::Menu* build_possible_aux_menu();
187
188         void choose_aux (boost::weak_ptr<ARDOUR::Route>);
189         void choose_send ();
190         void send_io_finished (IOSelector::Result, boost::weak_ptr<ARDOUR::Processor>, IOSelectorWindow*);
191         void return_io_finished (IOSelector::Result, boost::weak_ptr<ARDOUR::Processor>, IOSelectorWindow*);
192         void choose_insert ();
193         void choose_plugin ();
194         void use_plugins (const SelectedPlugins&);
195
196         bool no_processor_redisplay;
197
198         bool enter_notify (GdkEventCrossing *ev);
199         bool leave_notify (GdkEventCrossing *ev);
200         bool processor_key_press_event (GdkEventKey *);
201         bool processor_key_release_event (GdkEventKey *);
202         bool processor_button_press_event (GdkEventButton *, ProcessorEntry *);
203         bool processor_button_release_event (GdkEventButton *, ProcessorEntry *);
204         void redisplay_processors ();
205         void add_processor_to_display (boost::weak_ptr<ARDOUR::Processor>);
206         void reordered ();
207         void route_processors_changed (ARDOUR::RouteProcessorChange);
208
209         void remove_processor_gui (boost::shared_ptr<ARDOUR::Processor>);
210
211         void processors_reordered (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&, int*);
212         void compute_processor_sort_keys ();
213
214         void all_processors_active(bool state);
215         void all_plugins_active(bool state);
216         void ab_plugins ();
217
218         typedef std::vector<boost::shared_ptr<ARDOUR::Processor> > ProcSelection;
219
220         void cut_processors (const ProcSelection&);
221         void cut_processors ();
222         void copy_processors (const ProcSelection&);
223         void copy_processors ();
224         void delete_processors (const ProcSelection&);
225         void delete_processors ();
226         void paste_processors ();
227         void paste_processors (boost::shared_ptr<ARDOUR::Processor> before);
228
229         void delete_dragged_processors (const std::list<boost::shared_ptr<ARDOUR::Processor> >&);
230         void clear_processors ();
231         void clear_processors (ARDOUR::Placement);
232         void rename_processors ();
233
234         void for_selected_processors (void (ProcessorBox::*pmf)(boost::shared_ptr<ARDOUR::Processor>));
235         void get_selected_processors (ProcSelection&);
236
237         static Glib::RefPtr<Gtk::Action> paste_action;
238         void paste_processor_state (const XMLNodeList&, boost::shared_ptr<ARDOUR::Processor>);
239
240         void activate_processor (boost::shared_ptr<ARDOUR::Processor>);
241         void deactivate_processor (boost::shared_ptr<ARDOUR::Processor>);
242         void edit_processor (boost::shared_ptr<ARDOUR::Processor>);
243         void hide_processor_editor (boost::shared_ptr<ARDOUR::Processor>);
244         void rename_processor (boost::shared_ptr<ARDOUR::Processor>);
245
246         gint idle_delete_processor (boost::weak_ptr<ARDOUR::Processor>);
247
248         void weird_plugin_dialog (ARDOUR::Plugin& p, ARDOUR::Route::ProcessorStreams streams);
249         void on_size_allocate (Gtk::Allocation &);
250
251         static ProcessorBox* _current_processor_box;
252
253         static void rb_choose_aux (boost::weak_ptr<ARDOUR::Route>);
254         static void rb_choose_plugin ();
255         static void rb_choose_insert ();
256         static void rb_choose_send ();
257         static void rb_clear ();
258         static void rb_clear_pre ();
259         static void rb_clear_post ();
260         static void rb_cut ();
261         static void rb_copy ();
262         static void rb_paste ();
263         static void rb_delete ();
264         static void rb_rename ();
265         static void rb_select_all ();
266         static void rb_deselect_all ();
267         static void rb_activate_all ();
268         static void rb_deactivate_all ();
269         static void rb_ab_plugins ();
270         static void rb_edit ();
271
272         void route_name_changed ();
273         std::string generate_processor_title (boost::shared_ptr<ARDOUR::PluginInsert> pi);
274 };
275
276 #endif /* __ardour_gtk_processor_box__ */