2 * Copyright (C) 2007-2014 David Robillard <d@drobilla.net>
3 * Copyright (C) 2007-2018 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2008-2012 Carl Hetherington <carl@carlh.net>
5 * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
6 * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
7 * Copyright (C) 2017 Johannes Mueller <github@johannes-mueller.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #ifndef __ardour_gtk_processor_box__
25 #define __ardour_gtk_processor_box__
30 #include <boost/function.hpp>
32 #include <gtkmm/box.h>
33 #include <gtkmm/eventbox.h>
34 #include <gtkmm/menu.h>
35 #include <gtkmm/scrolledwindow.h>
37 #include "gtkmm2ext/bindings.h"
38 #include "gtkmm2ext/dndtreeview.h"
39 #include "gtkmm2ext/dndvbox.h"
40 #include "gtkmm2ext/persistent_tooltip.h"
42 #include "pbd/stateful.h"
43 #include "pbd/signals.h"
45 #include "ardour/types.h"
46 #include "ardour/ardour.h"
47 #include "ardour/plugin_insert.h"
48 #include "ardour/luaproc.h"
49 #include "ardour/port_insert.h"
50 #include "ardour/processor.h"
51 #include "ardour/route.h"
52 #include "ardour/session_handle.h"
54 #include "pbd/fastlog.h"
56 #include "widgets/ardour_button.h"
57 #include "widgets/ardour_fader.h"
58 #include "widgets/slider_controller.h"
60 #include "plugin_interest.h"
61 #include "plugin_display.h"
62 #include "io_selector.h"
65 #include "window_manager.h"
67 class MotionController;
70 class ProcessorSelection;
86 class ProcessorWindowProxy : public WM::ProxyBase
89 ProcessorWindowProxy (std::string const &, ProcessorBox *, boost::weak_ptr<ARDOUR::Processor>);
90 ~ProcessorWindowProxy();
92 Gtk::Window* get (bool create = false);
94 boost::weak_ptr<ARDOUR::Processor> processor () const {
98 ARDOUR::SessionHandlePtr* session_handle();
99 void show_the_right_window (bool show_not_toggle = false);
100 void set_custom_ui_mode(bool use_custom) { want_custom = use_custom; }
102 int set_state (const XMLNode&, int);
103 XMLNode& get_state ();
106 ProcessorBox* _processor_box;
107 boost::weak_ptr<ARDOUR::Processor> _processor;
111 void processor_going_away ();
112 PBD::ScopedConnection going_away_connection;
113 PBD::ScopedConnectionList gui_connections;
117 class PluginPinWindowProxy : public WM::ProxyBase
120 PluginPinWindowProxy (std::string const &, boost::weak_ptr<ARDOUR::Processor>);
121 ~PluginPinWindowProxy();
123 Gtk::Window* get (bool create = false);
124 ARDOUR::SessionHandlePtr* session_handle();
127 boost::weak_ptr<ARDOUR::Processor> _processor;
129 void processor_going_away ();
130 PBD::ScopedConnection going_away_connection;
135 class ProcessorEntry : public Gtkmm2ext::DnDVBoxChild, public sigc::trackable
138 ProcessorEntry (ProcessorBox *, boost::shared_ptr<ARDOUR::Processor>, Width);
141 Gtk::EventBox& action_widget ();
142 Gtk::Widget& widget ();
143 std::string drag_text () const;
144 void set_visual_state (Gtkmm2ext::VisualState, bool);
146 bool is_selectable() const {return _selectable;}
147 void set_selectable(bool s) { _selectable = s; }
149 bool drag_data_get (Glib::RefPtr<Gdk::DragContext> const, Gtk::SelectionData &);
150 bool can_copy_state (Gtkmm2ext::DnDVBoxChild*) const;
158 void set_position (Position, uint32_t);
159 bool unknown_processor () const { return _unknown_processor; } ;
160 boost::shared_ptr<ARDOUR::Processor> processor () const;
161 void set_enum_width (Width);
163 /** Hide any widgets that should be hidden */
164 virtual void hide_things ();
166 void toggle_inline_display_visibility ();
167 void show_all_controls ();
168 void hide_all_controls ();
169 void add_control_state (XMLNode *) const;
170 void set_control_state (XMLNode const *);
171 std::string state_id () const;
172 Gtk::Menu* build_controls_menu ();
173 Gtk::Menu* build_send_options_menu ();
176 ArdourWidgets::ArdourButton _button;
179 uint32_t _position_num;
180 ProcessorBox* _parent;
182 virtual void setup_visuals ();
186 bool _unknown_processor;
187 void led_clicked(GdkEventButton *);
188 void processor_active_changed ();
189 void processor_property_changed (const PBD::PropertyChange&);
190 void processor_configuration_changed (const ARDOUR::ChanCount in, const ARDOUR::ChanCount out);
191 std::string name (Width) const;
192 void setup_tooltip ();
194 boost::shared_ptr<ARDOUR::Processor> _processor;
196 PBD::ScopedConnection active_connection;
197 PBD::ScopedConnection name_connection;
198 PBD::ScopedConnection config_connection;
199 ARDOUR::PluginPresetPtr _plugin_preset_pointer;
201 class Control : public sigc::trackable {
203 Control (boost::shared_ptr<ARDOUR::AutomationControl>, std::string const &);
206 void set_visible (bool);
207 void add_state (XMLNode *) const;
208 void set_state (XMLNode const *);
211 bool visible () const {
215 std::string name () const {
222 void slider_adjusted ();
223 void button_clicked ();
224 void button_clicked_event (GdkEventButton *);
225 void control_changed ();
226 void control_automation_state_changed ();
227 std::string state_id () const;
233 boost::weak_ptr<ARDOUR::AutomationControl> _control;
234 /* things for a slider */
235 Gtk::Adjustment _adjustment;
236 ArdourWidgets::HSliderController _slider;
237 Gtkmm2ext::PersistentTooltip _slider_persistant_tooltip;
238 /* things for a button */
239 ArdourWidgets::ArdourButton _button;
240 bool _ignore_ui_adjustment;
241 PBD::ScopedConnectionList _connections;
246 std::list<Control*> _controls;
248 void toggle_control_visibility (Control *);
249 void toggle_panner_link ();
250 void toggle_allow_feedback ();
252 class PluginInlineDisplay : public PluginDisplay {
254 PluginInlineDisplay(ProcessorEntry&, boost::shared_ptr<ARDOUR::Plugin>, uint32_t max_height = 80);
255 ~PluginInlineDisplay() {}
257 void on_size_request (Gtk::Requisition* req);
258 bool on_button_press_event (GdkEventButton *ev);
259 void update_height_alloc (uint32_t inline_height);
261 void display_frame (cairo_t* cr, double w, double h);
263 ProcessorEntry& _entry;
265 const uint32_t _given_max_height;
268 class LuaPluginDisplay : public PluginInlineDisplay {
270 LuaPluginDisplay(ProcessorEntry&, boost::shared_ptr<ARDOUR::LuaProc>, uint32_t max_height = 80);
273 virtual uint32_t render_inline (cairo_t *, uint32_t width);
275 boost::shared_ptr<ARDOUR::LuaProc> _luaproc;
277 luabridge::LuaRef * _lua_render_inline;
280 class PortIcon : public Gtk::DrawingArea {
282 PortIcon(bool input);
283 void set_ports(ARDOUR::ChanCount const ports) { _ports = ports; }
285 bool on_expose_event (GdkEventExpose *);
287 ARDOUR::ChanCount _ports;
290 class RoutingIcon : public Gtk::DrawingArea {
292 RoutingIcon(bool inputrouting = true);
294 const ARDOUR::ChanCount&,
295 const ARDOUR::ChanCount&,
296 const ARDOUR::ChanCount&,
297 const ARDOUR::ChanCount&,
298 const ARDOUR::ChanMapping&,
299 const ARDOUR::ChanMapping&,
300 const ARDOUR::ChanMapping&);
302 const ARDOUR::ChanCount&,
303 const ARDOUR::ChanCount&,
304 const ARDOUR::ChanMapping&,
305 const ARDOUR::ChanMapping&);
308 const ARDOUR::ChanCount&,
309 const ARDOUR::ChanCount&,
310 const ARDOUR::ChanMapping&,
311 const ARDOUR::ChanMapping&);
313 void set_terminal (bool b);
315 void copy_state (const RoutingIcon& other) {
318 _sources = other._sources;
319 _sinks = other._sinks;
320 _in_map = other._in_map;
321 _out_map = other._out_map;
322 _thru_map = other._thru_map;
323 _f_out = other._f_out;
324 _f_out_map = other._f_out_map;
325 _f_thru_map = other._f_thru_map;
326 _f_sources = other._f_sources;
328 _i_in_map = other._i_in_map;
329 _i_thru_map = other._i_thru_map;
330 _i_sinks = other._i_sinks;
331 _fed_by = other._fed_by;
332 _feeding = other._feeding;
335 void unset_fed_by () { _fed_by = false ; }
336 void unset_feeding () { _feeding = false ; }
337 bool in_identity () const;
338 bool out_identity () const;
339 bool can_coalesce () const;
341 static double pin_x_pos (uint32_t, double, uint32_t, uint32_t, bool);
342 static void draw_connection (cairo_t*, double, double, double, double, bool, bool dashed = false);
343 static void draw_gnd (cairo_t*, double, double, double, bool);
344 static void draw_sidechain (cairo_t*, double, double, double, bool);
345 static void draw_thru_src (cairo_t*, double, double, double, bool);
346 static void draw_thru_sink (cairo_t*, double, double, double, bool);
349 bool on_expose_event (GdkEventExpose *);
350 void expose_input_map (cairo_t*, const double, const double);
351 void expose_coalesced_input_map (cairo_t*, const double, const double);
352 void expose_output_map (cairo_t*, const double, const double);
354 ARDOUR::ChanCount _in;
355 ARDOUR::ChanCount _out;
356 ARDOUR::ChanCount _sources;
357 ARDOUR::ChanCount _sinks;
358 ARDOUR::ChanMapping _in_map;
359 ARDOUR::ChanMapping _out_map;
360 ARDOUR::ChanMapping _thru_map;
361 ARDOUR::ChanCount _f_out;
362 ARDOUR::ChanMapping _f_out_map;
363 ARDOUR::ChanMapping _f_thru_map;
364 ARDOUR::ChanCount _f_sources;
365 ARDOUR::ChanCount _i_in;
366 ARDOUR::ChanMapping _i_in_map;
367 ARDOUR::ChanMapping _i_thru_map;
368 ARDOUR::ChanCount _i_sinks;
377 PortIcon output_icon;
378 RoutingIcon routing_icon; // sits on top of every processor (input routing)
379 RoutingIcon output_routing_icon; // only used by last processor in the chain
382 PluginDisplay *_plugin_display ;
385 class PluginInsertProcessorEntry : public ProcessorEntry
388 PluginInsertProcessorEntry (ProcessorBox *, boost::shared_ptr<ARDOUR::PluginInsert>, Width);
393 void iomap_changed ();
394 boost::shared_ptr<ARDOUR::PluginInsert> _plugin_insert;
396 PBD::ScopedConnectionList _iomap_connection;
399 class ProcessorBox : public Gtk::HBox, public PluginInterestedObject, public ARDOUR::SessionHandlePtr
402 enum ProcessorOperation {
408 ProcessorsSelectNone,
409 ProcessorsToggleActive,
413 ProcessorBox (ARDOUR::Session*, boost::function<PluginSelector*()> get_plugin_selector,
414 ProcessorSelection&, MixerStrip* parent, bool owner_is_mixer = false);
417 void set_route (boost::shared_ptr<ARDOUR::Route>);
418 void set_width (Width);
420 bool processor_operation (ProcessorOperation);
422 void select_all_processors ();
423 void deselect_all_processors ();
424 void select_all_plugins ();
425 void select_all_inserts ();
426 void select_all_sends ();
428 void all_visible_processors_active(bool state);
429 void setup_routing_feeds ();
433 bool edit_aux_send(boost::shared_ptr<ARDOUR::Processor>);
435 /* Everything except a WindowProxy object should use this to get the window */
436 Gtk::Window* get_processor_ui (boost::shared_ptr<ARDOUR::Processor>) const;
438 /* a WindowProxy object can use this */
439 Gtk::Window* get_editor_window (boost::shared_ptr<ARDOUR::Processor>, bool);
440 Gtk::Window* get_generic_editor_window (boost::shared_ptr<ARDOUR::Processor>);
442 void manage_pins (boost::shared_ptr<ARDOUR::Processor>);
443 void edit_processor (boost::shared_ptr<ARDOUR::Processor>);
444 void generic_edit_processor (boost::shared_ptr<ARDOUR::Processor>);
446 void update_gui_object_state (ProcessorEntry *);
448 sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > ProcessorSelected;
449 sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > ProcessorUnselected;
451 static Glib::RefPtr<Gtk::ActionGroup> processor_box_actions;
452 static Gtkmm2ext::Bindings* bindings;
453 static void register_actions();
455 typedef std::vector<boost::shared_ptr<ARDOUR::Processor> > ProcSelection;
457 static ProcSelection current_processor_selection ()
460 if (_current_processor_box) {
461 _current_processor_box->get_selected_processors (ps);
467 static bool show_all_processors;
471 /* prevent copy construction */
472 ProcessorBox (ProcessorBox const &);
474 boost::shared_ptr<ARDOUR::Route> _route;
475 MixerStrip* _parent_strip; // null if in RouteParamsUI
476 bool _owner_is_mixer;
478 PBD::ScopedConnectionList _mixer_strip_connections;
479 PBD::ScopedConnectionList _route_connections;
481 boost::function<PluginSelector*()> _get_plugin_selector;
483 boost::shared_ptr<ARDOUR::Processor> _processor_being_created;
485 /** Index at which to place a new plugin (based on where the menu was opened), or -1 to
486 * put at the end of the plugin list.
490 ProcessorSelection& _p_selection;
492 static void load_bindings ();
494 void route_going_away ();
496 bool is_editor_mixer_strip() const;
498 Gtkmm2ext::DnDVBox<ProcessorEntry> processor_display;
499 Gtk::ScrolledWindow processor_scroller;
501 boost::shared_ptr<ARDOUR::Processor> find_drop_position (ProcessorEntry* position);
503 void _drop_plugin_preset (Gtk::SelectionData const &, ARDOUR::Route::ProcessorList &);
504 void _drop_plugin (Gtk::SelectionData const &, ARDOUR::Route::ProcessorList &);
506 void plugin_drop (Gtk::SelectionData const &, ProcessorEntry* position, Glib::RefPtr<Gdk::DragContext> const & context);
507 void object_drop (Gtkmm2ext::DnDVBox<ProcessorEntry> *, ProcessorEntry *, Glib::RefPtr<Gdk::DragContext> const &);
510 bool _redisplay_pending;
512 Gtk::Menu *processor_menu;
513 gint processor_menu_map_handler (GdkEventAny *ev);
514 Gtk::Menu * build_processor_menu ();
515 void show_processor_menu (int);
516 Gtk::Menu* build_possible_aux_menu();
517 Gtk::Menu* build_possible_listener_menu();
518 Gtk::Menu* build_possible_remove_listener_menu();
520 void choose_aux (boost::weak_ptr<ARDOUR::Route>);
521 void remove_aux (boost::weak_ptr<ARDOUR::Route>);
523 void send_io_finished (IOSelector::Result, boost::weak_ptr<ARDOUR::Processor>, IOSelectorWindow*);
524 void return_io_finished (IOSelector::Result, boost::weak_ptr<ARDOUR::Processor>, IOSelectorWindow*);
525 void choose_insert ();
526 void choose_plugin ();
527 bool use_plugins (const SelectedPlugins&);
529 bool no_processor_redisplay;
531 bool enter_notify (GdkEventCrossing *ev);
532 bool leave_notify (GdkEventCrossing *ev);
533 bool processor_button_press_event (GdkEventButton *, ProcessorEntry *);
534 bool processor_button_release_event (GdkEventButton *, ProcessorEntry *);
535 void redisplay_processors ();
536 void add_processor_to_display (boost::weak_ptr<ARDOUR::Processor>);
538 void report_failed_reorder ();
539 void route_processors_changed (ARDOUR::RouteProcessorChange);
540 void processor_menu_unmapped ();
542 void processors_reordered (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&, int*);
543 void compute_processor_sort_keys ();
547 void cut_processors (const ProcSelection&);
548 void copy_processors (const ProcSelection&);
549 void delete_processors (const ProcSelection&);
550 void paste_processors ();
551 void paste_processors (boost::shared_ptr<ARDOUR::Processor> before);
553 void delete_dragged_processors (const std::list<boost::shared_ptr<ARDOUR::Processor> >&);
554 void clear_processors ();
555 void clear_processors (ARDOUR::Placement);
556 void rename_processors ();
558 void for_selected_processors (void (ProcessorBox::*pmf)(boost::shared_ptr<ARDOUR::Processor>));
559 void get_selected_processors (ProcSelection&) const;
561 void set_disk_io_position (ARDOUR::DiskIOPoint);
563 bool can_cut() const;
564 bool stub_processor_selected() const;
566 static Glib::RefPtr<Gtk::Action> cut_action;
567 static Glib::RefPtr<Gtk::Action> copy_action;
568 static Glib::RefPtr<Gtk::Action> paste_action;
569 static Glib::RefPtr<Gtk::Action> rename_action;
570 static Glib::RefPtr<Gtk::Action> delete_action;
571 static Glib::RefPtr<Gtk::Action> backspace_action;
572 static Glib::RefPtr<Gtk::Action> manage_pins_action;
573 static Glib::RefPtr<Gtk::Action> disk_io_action;
574 static Glib::RefPtr<Gtk::Action> edit_action;
575 static Glib::RefPtr<Gtk::Action> edit_generic_action;
576 void paste_processor_state (const XMLNodeList&, boost::shared_ptr<ARDOUR::Processor>);
578 void hide_processor_editor (boost::shared_ptr<ARDOUR::Processor>);
579 void rename_processor (boost::shared_ptr<ARDOUR::Processor>);
581 gint idle_delete_processor (boost::weak_ptr<ARDOUR::Processor>);
583 void weird_plugin_dialog (ARDOUR::Plugin& p, ARDOUR::Route::ProcessorStreams streams);
585 void setup_entry_positions ();
587 static ProcessorBox* _current_processor_box;
589 static void rb_choose_aux (boost::weak_ptr<ARDOUR::Route>);
590 static void rb_remove_aux (boost::weak_ptr<ARDOUR::Route>);
591 static void rb_choose_plugin ();
592 static void rb_choose_insert ();
593 static void rb_choose_send ();
594 static void rb_clear ();
595 static void rb_clear_pre ();
596 static void rb_clear_post ();
597 static void rb_cut ();
598 static void rb_copy ();
599 static void rb_paste ();
600 static void rb_delete ();
601 static void rb_rename ();
602 static void rb_select_all ();
603 static void rb_deselect_all ();
604 static void rb_activate_all ();
605 static void rb_deactivate_all ();
606 static void rb_ab_plugins ();
607 static void rb_manage_pins ();
608 static void rb_set_disk_io_position (ARDOUR::DiskIOPoint);
609 static void rb_edit ();
610 static void rb_edit_generic ();
612 void route_property_changed (const PBD::PropertyChange&);
613 std::string generate_processor_title (boost::shared_ptr<ARDOUR::PluginInsert> pi);
615 //typedef std::list<ProcessorWindowProxy*> ProcessorWindowProxies;
616 //ProcessorWindowProxies _processor_window_info;
618 ProcessorWindowProxy* find_window_proxy (boost::shared_ptr<ARDOUR::Processor>) const;
620 void set_processor_ui (boost::shared_ptr<ARDOUR::Processor>, Gtk::Window *);
621 void maybe_add_processor_to_ui_list (boost::weak_ptr<ARDOUR::Processor>);
622 void maybe_add_processor_pin_mgr (boost::weak_ptr<ARDOUR::Processor>);
624 bool one_processor_can_be_edited ();
625 bool processor_can_be_edited (boost::shared_ptr<ARDOUR::Processor>);
627 void mixer_strip_delivery_changed (boost::weak_ptr<ARDOUR::Delivery>);
629 XMLNode* entry_gui_object_state (ProcessorEntry *);
630 PBD::ScopedConnection amp_config_connection;
632 static bool _ignore_disk_io_change;
635 #endif /* __ardour_gtk_processor_box__ */