fix keyboard event handling for host-provided plugin GUIs
[ardour2.git] / gtk2_ardour / crossfade_view.cc
blob5e27bf958fca7bd62dc5e84f41cffdbafa21f1d8
1 /*
2 Copyright (C) 2003 Paul Davis
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.
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.
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.
20 #include <algorithm>
22 #include <ardour/region.h>
23 #include <gtkmm2ext/doi.h>
25 #include "canvas-simplerect.h"
26 #include "canvas-curve.h"
27 #include "crossfade_view.h"
28 #include "rgb_macros.h"
29 #include "audio_time_axis.h"
30 #include "public_editor.h"
31 #include "audio_region_view.h"
32 #include "utils.h"
33 #include "canvas_impl.h"
34 #include "ardour_ui.h"
36 using namespace sigc;
37 using namespace ARDOUR;
38 using namespace PBD;
39 using namespace Editing;
40 using namespace Gnome;
41 using namespace Canvas;
43 sigc::signal<void,CrossfadeView*> CrossfadeView::GoingAway;
45 CrossfadeView::CrossfadeView (ArdourCanvas::Group *parent,
46 RouteTimeAxisView &tv,
47 boost::shared_ptr<Crossfade> xf,
48 double spu,
49 Gdk::Color& basic_color,
50 AudioRegionView& lview,
51 AudioRegionView& rview)
54 : TimeAxisViewItem ("xfade" /*xf.name()*/, *parent, tv, spu, basic_color, xf->position(),
55 xf->length(), false, TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowFrame)),
56 crossfade (xf),
57 left_view (lview),
58 right_view (rview)
61 _valid = true;
62 _visible = true;
64 fade_in = new Line (*group);
65 fade_in->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_CrossfadeLine.get();
66 fade_in->property_width_pixels() = 1;
68 fade_out = new Line (*group);
69 fade_out->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_CrossfadeLine.get();
70 fade_out->property_width_pixels() = 1;
72 set_height (get_time_axis_view().current_height());
74 /* no frame around the xfade or overlap rects */
76 frame->property_outline_what() = 0;
78 /* never show the vestigial frame */
80 vestigial_frame->hide();
81 show_vestigial = false;
83 group->signal_event().connect (bind (mem_fun (tv.editor, &PublicEditor::canvas_crossfade_view_event), group, this));
85 crossfade_changed (Change (~0));
87 crossfade->StateChanged.connect (mem_fun(*this, &CrossfadeView::crossfade_changed));
88 ColorsChanged.connect (mem_fun (*this, &CrossfadeView::color_handler));
91 CrossfadeView::~CrossfadeView ()
93 GoingAway (this) ; /* EMIT_SIGNAL */
96 void
97 CrossfadeView::reset_width_dependent_items (double pixel_width)
99 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
101 active_changed ();
103 if (pixel_width < 5) {
104 fade_in->hide();
105 fade_out->hide();
109 void
110 CrossfadeView::set_height (double height)
112 if (height <= TimeAxisView::hSmaller) {
113 TimeAxisViewItem::set_height (height - 3);
114 } else {
115 TimeAxisViewItem::set_height (height - NAME_HIGHLIGHT_SIZE - 3 );
118 redraw_curves ();
121 void
122 CrossfadeView::crossfade_changed (Change what_changed)
124 bool need_redraw_curves = false;
126 if (what_changed & BoundsChanged) {
127 set_position (crossfade->position(), this);
128 set_duration (crossfade->length(), this);
129 need_redraw_curves = true;
132 if (what_changed & Crossfade::FollowOverlapChanged) {
133 need_redraw_curves = true;
136 if (what_changed & Crossfade::ActiveChanged) {
137 /* calls redraw_curves */
138 active_changed ();
139 } else if (need_redraw_curves) {
140 redraw_curves ();
144 void
145 CrossfadeView::redraw_curves ()
147 Points* points;
148 int32_t npoints;
149 float* vec;
150 double h;
152 if (!crossfade->following_overlap()) {
153 /* curves should not be visible */
154 fade_in->hide ();
155 fade_out->hide ();
156 return;
160 At "height - 3.0" the bottom of the crossfade touches the name highlight or the bottom of the track (if the
161 track is either Small or Smaller.
163 double tav_height = get_time_axis_view().current_height();
164 if (tav_height == TimeAxisView::hSmaller ||
165 tav_height == TimeAxisView::hSmall) {
166 h = tav_height - 3.0;
167 } else {
168 h = tav_height - NAME_HIGHLIGHT_SIZE - 3.0;
171 if (h < 0) {
172 /* no space allocated yet */
173 return;
176 npoints = get_time_axis_view().editor.frame_to_pixel (crossfade->length());
177 // npoints = std::min (gdk_screen_width(), npoints);
179 if (!_visible || !crossfade->active() || npoints < 3) {
180 fade_in->hide();
181 fade_out->hide();
182 return;
183 } else {
184 fade_in->show();
185 fade_out->show();
188 points = get_canvas_points ("xfade edit redraw", npoints);
189 vec = new float[npoints];
191 crossfade->fade_in().get_vector (0, crossfade->length(), vec, npoints);
193 for (int i = 0, pci = 0; i < npoints; ++i) {
194 Art::Point &p = (*points)[pci++];
195 p.set_x(i);
196 p.set_y(2.0 + h - (h * vec[i]));
198 fade_in->property_points() = *points;
200 crossfade->fade_out().get_vector (0, crossfade->length(), vec, npoints);
201 for (int i = 0, pci = 0; i < npoints; ++i) {
202 Art::Point &p = (*points)[pci++];
203 p.set_x(i);
204 p.set_y(2.0 + h - (h * vec[i]));
206 fade_out->property_points() = *points;
208 delete [] vec;
210 delete points;
212 /* XXX this is ugly, but it will have to wait till Crossfades are reimplented
213 as regions. This puts crossfade views on top of a track, above all regions.
216 group->raise_to_top();
219 void
220 CrossfadeView::active_changed ()
222 if (crossfade->active()) {
223 frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ActiveCrossfade.get();
224 } else {
225 frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_InactiveCrossfade.get();
228 redraw_curves ();
231 void
232 CrossfadeView::color_handler ()
234 active_changed ();
237 void
238 CrossfadeView::set_valid (bool yn)
240 _valid = yn;
243 AudioRegionView&
244 CrossfadeView::upper_regionview () const
246 if (left_view.region()->layer() > right_view.region()->layer()) {
247 return left_view;
248 } else {
249 return right_view;
253 void
254 CrossfadeView::show ()
256 group->show();
257 _visible = true;
260 void
261 CrossfadeView::hide ()
263 group->hide();
264 _visible = false;
267 void
268 CrossfadeView::fake_hide ()
270 group->hide();