155a1095c1ef4b9c5be6ca1ad92f826e6cc2dde2
[ardour.git] / gtk2_ardour / return_ui.cc
1 /*
2     Copyright (C) 2002 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 #include <gtkmm2ext/doi.h>
21
22 #include "ardour/amp.h"
23 #include "ardour/io.h"
24 #include "ardour/return.h"
25
26 #include "utils.h"
27 #include "return_ui.h"
28 #include "io_selector.h"
29 #include "ardour_ui.h"
30 #include "gui_thread.h"
31
32 using namespace std;
33 using namespace ARDOUR;
34 using namespace PBD;
35
36 ReturnUI::ReturnUI (boost::shared_ptr<Return> r, Session& se)
37         : _return (r)
38         , _session (se)
39         , _gpm (se)
40 {
41         _gpm.set_controls (boost::shared_ptr<Route>(), r->meter(), r->amp()->gain_control(), r->amp());
42
43         _hbox.pack_start (_gpm, true, true);
44         set_name ("ReturnUIFrame");
45         
46         _vbox.set_spacing (5);
47         _vbox.set_border_width (5);
48
49         _vbox.pack_start (_hbox, false, false, false);
50
51         io = manage (new IOSelector (se, r->output()));
52         
53         pack_start (_vbox, false, false);
54
55         pack_start (*io, true, true);
56
57         show_all ();
58
59         _return->set_metering (true);
60         _return->input()->changed.connect (mem_fun (*this, &ReturnUI::ins_changed));
61         
62         _gpm.setup_meters ();
63         _gpm.set_fader_name ("ReturnUIFrame");
64         
65         // screen_update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect (mem_fun (*this, &ReturnUI::update));
66         fast_screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (mem_fun (*this, &ReturnUI::fast_update));
67 }
68
69 ReturnUI::~ReturnUI ()
70 {
71         _return->set_metering (false);
72
73         /* XXX not clear that we need to do this */
74
75         screen_update_connection.disconnect();
76         fast_screen_update_connection.disconnect();
77 }
78
79 void
80 ReturnUI::ins_changed (IOChange change, void* ignored)
81 {
82         ENSURE_GUI_THREAD(bind (mem_fun (*this, &ReturnUI::ins_changed), change, ignored));
83         if (change & ConfigurationChanged) {
84                 _gpm.setup_meters ();
85         }
86 }
87
88 void
89 ReturnUI::update ()
90 {
91 }
92
93 void
94 ReturnUI::fast_update ()
95 {
96         if (Config->get_meter_falloff() > 0.0f) {
97                 _gpm.update_meters ();
98         }
99 }
100         
101 ReturnUIWindow::ReturnUIWindow (boost::shared_ptr<Return> s, Session& ss)
102         : ArdourDialog (string("Ardour: return ") + s->name())
103 {
104         ui = new ReturnUI (s, ss);
105
106         hpacker.pack_start (*ui, true, true);
107
108         get_vbox()->set_border_width (5);
109         get_vbox()->pack_start (hpacker);
110
111         set_name ("ReturnUIWindow");
112         
113         going_away_connection = s->GoingAway.connect (mem_fun (*this, &ReturnUIWindow::return_going_away));
114         signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this)));
115 }
116
117 ReturnUIWindow::~ReturnUIWindow ()
118 {
119         delete ui;
120 }
121
122 void
123 ReturnUIWindow::return_going_away ()
124 {
125         ENSURE_GUI_THREAD (mem_fun (*this, &ReturnUIWindow::return_going_away));
126         delete_when_idle (this);
127         going_away_connection.disconnect ();
128 }
129