Merged with trunk R1283.
[ardour.git] / gtk2_ardour / redirect_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     $Id$
19 */
20
21 #ifndef __ardour_gtk_redirect_box__
22 #define __ardour_gtk_redirect_box__
23
24 #include <vector>
25
26 #include <cmath>
27 #include <gtkmm/box.h>
28 #include <gtkmm/eventbox.h>
29 #include <gtkmm/menu.h>
30 #include <gtkmm/scrolledwindow.h>
31 #include <gtkmm2ext/dndtreeview.h>
32 #include <gtkmm2ext/auto_spin.h>
33 #include <gtkmm2ext/click_box.h>
34 #include <gtkmm2ext/dndtreeview.h>
35
36 #include <pbd/stateful.h>
37
38 #include <ardour/types.h>
39 #include <ardour/ardour.h>
40 #include <ardour/io.h>
41 #include <ardour/insert.h>
42 #include <ardour/redirect.h>
43
44 #include <pbd/fastlog.h>
45
46 #include "route_ui.h"
47 #include "io_selector.h"
48 #include "enums.h"
49
50 class MotionController;
51 class PluginSelector;
52 class PluginUIWindow;
53 class RouteRedirectSelection;
54
55 namespace ARDOUR {
56         class Connection;
57         class Insert;
58         class Plugin;
59         class PluginInsert;
60         class PortInsert;
61         class Route;
62         class Send;
63         class Session;
64 }
65
66 class RedirectBox : public Gtk::HBox
67 {
68   public:
69         RedirectBox (ARDOUR::Placement, ARDOUR::Session&, 
70                      boost::shared_ptr<ARDOUR::Route>, PluginSelector &, RouteRedirectSelection &, bool owner_is_mixer = false);
71         ~RedirectBox ();
72
73         void set_width (Width);
74
75         void update();
76
77         void select_all_redirects ();
78         void deselect_all_redirects ();
79         void select_all_plugins ();
80         void select_all_inserts ();
81         void select_all_sends ();
82         
83         sigc::signal<void,boost::shared_ptr<ARDOUR::Redirect> > RedirectSelected;
84         sigc::signal<void,boost::shared_ptr<ARDOUR::Redirect> > RedirectUnselected;
85         
86         static void register_actions();
87
88   protected:
89         void set_stuff_from_route ();
90
91   private:
92         boost::shared_ptr<ARDOUR::Route>  _route;
93         ARDOUR::Session &   _session;
94         bool                _owner_is_mixer;
95
96         ARDOUR::Placement   _placement;
97
98         PluginSelector     & _plugin_selector;
99         RouteRedirectSelection  & _rr_selection;
100
101         void route_going_away ();
102
103         struct ModelColumns : public Gtk::TreeModel::ColumnRecord {
104             ModelColumns () {
105                     add (text);
106                     add (redirect);
107                     add (color);
108             }
109             Gtk::TreeModelColumn<std::string>       text;
110             Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Redirect> > redirect;
111             Gtk::TreeModelColumn<Gdk::Color>        color;
112         };
113
114         ModelColumns columns;
115         Glib::RefPtr<Gtk::ListStore> model;
116         
117         void selection_changed ();
118
119         static bool get_colors;
120         static Gdk::Color* active_redirect_color;
121         static Gdk::Color* inactive_redirect_color;
122         
123         Gtk::EventBox          redirect_eventbox;
124         Gtk::HBox              redirect_hpacker;
125         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Redirect> > redirect_display;
126         Gtk::ScrolledWindow    redirect_scroller;
127
128         void object_drop (std::string type, uint32_t cnt, const boost::shared_ptr<ARDOUR::Redirect>*);
129
130         Width _width;
131         
132         Gtk::Menu *send_action_menu;
133         void build_send_action_menu ();
134
135         void new_send ();
136         void show_send_controls ();
137
138         Gtk::Menu *redirect_menu;
139         gint redirect_menu_map_handler (GdkEventAny *ev);
140         Gtk::Menu * build_redirect_menu ();
141         void build_redirect_tooltip (Gtk::EventBox&, string);
142         void show_redirect_menu (gint arg);
143
144         void choose_send ();
145         void send_io_finished (IOSelector::Result, boost::weak_ptr<ARDOUR::Redirect>, IOSelectorWindow*);
146         void choose_insert ();
147         void choose_plugin ();
148         void insert_plugin_chosen (boost::shared_ptr<ARDOUR::Plugin>);
149
150         bool no_redirect_redisplay;
151         bool ignore_delete;
152
153         bool redirect_button_press_event (GdkEventButton *);
154         bool redirect_button_release_event (GdkEventButton *);
155         void redisplay_redirects (void* src);
156         void add_redirect_to_display (boost::shared_ptr<ARDOUR::Redirect>);
157         void row_deleted (const Gtk::TreeModel::Path& path);
158         void show_redirect_active_r (ARDOUR::Redirect*, void *, boost::weak_ptr<ARDOUR::Redirect>);
159         void show_redirect_active (boost::weak_ptr<ARDOUR::Redirect>);
160         void show_redirect_name (void* src, boost::weak_ptr<ARDOUR::Redirect>);
161         string redirect_name (boost::weak_ptr<ARDOUR::Redirect>);
162
163         void remove_redirect_gui (boost::shared_ptr<ARDOUR::Redirect>);
164
165         void redirects_reordered (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&, int*);
166         void compute_redirect_sort_keys ();
167         vector<sigc::connection> redirect_active_connections;
168         vector<sigc::connection> redirect_name_connections;
169         
170         bool redirect_drag_in_progress;
171         void redirect_drag_begin (GdkDragContext*);
172         void redirect_drag_end (GdkDragContext*);
173         void all_redirects_active(bool state);
174
175         void cut_redirects ();
176         void copy_redirects ();
177         void paste_redirects ();
178         void clear_redirects ();
179         void clone_redirects ();
180         void rename_redirects ();
181
182         void for_selected_redirects (void (RedirectBox::*pmf)(boost::shared_ptr<ARDOUR::Redirect>));
183         void get_selected_redirects (vector<boost::shared_ptr<ARDOUR::Redirect> >&);
184
185         static Glib::RefPtr<Gtk::Action> paste_action;
186         void paste_redirect_list (std::list<boost::shared_ptr<ARDOUR::Redirect> >& redirects);
187         
188         void activate_redirect (boost::shared_ptr<ARDOUR::Redirect>);
189         void deactivate_redirect (boost::shared_ptr<ARDOUR::Redirect>);
190         void cut_redirect (boost::shared_ptr<ARDOUR::Redirect>);
191         void copy_redirect (boost::shared_ptr<ARDOUR::Redirect>);
192         void edit_redirect (boost::shared_ptr<ARDOUR::Redirect>);
193         void hide_redirect_editor (boost::shared_ptr<ARDOUR::Redirect>);
194         void rename_redirect (boost::shared_ptr<ARDOUR::Redirect>);
195
196         gint idle_delete_redirect (boost::weak_ptr<ARDOUR::Redirect>);
197
198         void wierd_plugin_dialog (ARDOUR::Plugin& p, uint32_t streams, boost::shared_ptr<ARDOUR::IO> io);
199
200         static RedirectBox* _current_redirect_box;
201         static bool enter_box (GdkEventCrossing*, RedirectBox*);
202         static bool leave_box (GdkEventCrossing*, RedirectBox*);
203
204         static void rb_choose_plugin ();
205         static void rb_choose_insert ();
206         static void rb_choose_send ();
207         static void rb_clear ();
208         static void rb_cut ();
209         static void rb_copy ();
210         static void rb_paste ();
211         static void rb_rename ();
212         static void rb_select_all ();
213         static void rb_deselect_all ();
214         static void rb_activate ();
215         static void rb_deactivate ();
216         static void rb_activate_all ();
217         static void rb_deactivate_all ();
218         static void rb_edit ();
219         
220         void route_name_changed (void* src, PluginUIWindow* plugin_ui, boost::weak_ptr<ARDOUR::PluginInsert> pi);
221         std::string generate_redirect_title (boost::shared_ptr<ARDOUR::PluginInsert> pi);
222 };
223
224 #endif /* __ardour_gtk_redirect_box__ */