Port level meters to trunk
[ardour.git] / gtk2_ardour / editor_audiotrack.cc
1 /*
2     Copyright (C) 2000-2007 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 <ardour/location.h>
21 #include <ardour/audio_diskstream.h>
22
23 #include "ardour_ui.h"
24 #include "editor.h"
25 #include "editing.h"
26 #include "audio_time_axis.h"
27 #include "route_time_axis.h"
28 #include "audio_region_view.h"
29 #include "selection.h"
30
31 #include "i18n.h"
32
33 using namespace ARDOUR;
34 using namespace PBD;
35
36 void
37 Editor::set_loop_from_selection (bool play)
38 {
39         if (session == 0 || selection->time.empty()) {
40                 return;
41         }
42
43         nframes_t start = selection->time[clicked_selection].start;
44         nframes_t end = selection->time[clicked_selection].end;
45         
46         set_loop_range (start, end,  _("set loop range from selection"));
47
48         if (play) {
49                 session->request_play_loop (true);
50                 session->request_locate (start, true);
51         }
52 }
53
54 void
55 Editor::set_punch_from_selection ()
56 {
57         if (session == 0 || selection->time.empty()) {
58                 return;
59         }
60
61         nframes_t start = selection->time[clicked_selection].start;
62         nframes_t end = selection->time[clicked_selection].end;
63         
64         set_punch_range (start, end,  _("set punch range from selection"));
65 }
66
67 void
68 Editor::set_show_waveforms (bool yn)
69 {
70         AudioTimeAxisView* atv;
71
72         if (_show_waveforms != yn) {
73                 _show_waveforms = yn;
74                 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
75                         if ((atv = dynamic_cast<AudioTimeAxisView*>(*i)) != 0) {
76                                 atv->set_show_waveforms (yn);
77                         }
78                 }
79         }
80 }
81
82 void
83 Editor::set_show_waveforms_recording (bool yn)
84 {
85         AudioTimeAxisView* atv;
86
87         if (_show_waveforms_recording != yn) {
88                 _show_waveforms_recording = yn;
89                 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
90                         if ((atv = dynamic_cast<AudioTimeAxisView*>(*i)) != 0) {
91                                 atv->set_show_waveforms_recording (yn);
92                         }
93                 }
94         }
95 }
96
97 gint
98 Editor::start_updating ()
99 {
100         RouteTimeAxisView* rtv;
101
102         //cerr << "Editor::start_updating () called" << endl;//DEBUG
103         if (is_mapped() && session) {
104                 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
105                         if ((rtv = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
106                                 rtv->reset_meter ();
107                         }
108                 }
109         }
110
111         if (!meters_running) {
112                 fast_screen_update_connection = ARDOUR_UI::SuperRapidScreenUpdate.connect (mem_fun(*this, &Editor::fast_update_strips));
113                 meters_running = true;
114         }
115     return 0;
116 }
117
118 gint
119 Editor::stop_updating ()
120 {
121         RouteTimeAxisView* rtv;
122         
123         meters_running = false;
124         fast_screen_update_connection.disconnect();
125         //cerr << "Editor::stop_updating () called" << endl;//DEBUG
126         if (is_mapped() && session) {
127                 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
128                         if ((rtv = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
129                                 rtv->hide_meter ();
130                         }
131                 }
132         }
133
134     return 0;
135 }
136
137 void
138 Editor::toggle_meter_updating()
139 {
140         if (Config->get_show_track_meters()) {
141                 start_updating();
142         } else {
143                 stop_updating ();
144         }
145 }
146
147 void
148 Editor::fast_update_strips ()
149 {
150         RouteTimeAxisView* rtv;
151
152         if (is_mapped() && session) {
153                 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
154                         if ((rtv = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
155                                 rtv->fast_update ();
156                         }
157                 }
158         }
159 }
160