19276223ef1f4ebf87a21281d241681ceb468b70
[ardour.git] / gtk2_ardour / taperegionview.cc
1 /*
2     Copyright (C) 2006 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 #include <cmath>
22 #include <algorithm>
23
24 #include <gtkmm.h>
25
26 #include <gtkmm2ext/gtk_ui.h>
27
28 #include <ardour/playlist.h>
29 #include <ardour/audioregion.h>
30 #include <ardour/diskstream.h>
31
32 #include "taperegionview.h"
33 #include "audio_time_axis.h"
34 #include "gui_thread.h"
35
36 #include "i18n.h"
37
38 using namespace sigc;
39 using namespace ARDOUR;
40 using namespace Editing;
41 using namespace ArdourCanvas;
42
43 TapeAudioRegionView::TapeAudioRegionView (ArdourCanvas::Group *parent, AudioTimeAxisView &tv, 
44                                           AudioRegion& r, 
45                                           double spu, 
46                                           Gdk::Color& basic_color)
47
48         : AudioRegionView (parent, tv, r, spu, basic_color, 
49                            TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameHighlight|
50                                                          TimeAxisViewItem::ShowFrame|
51                                                          TimeAxisViewItem::HideFrameLR|
52                                                          TimeAxisViewItem::FullWidthNameHighlight))
53 {
54 }
55
56 void
57 TapeAudioRegionView::init (double amplitude_above_axis, Gdk::Color& basic_color, bool wfw)
58 {
59         XMLNode *node;
60
61         editor = 0;
62         valid = true;
63         in_destructor = false;
64         _amplitude_above_axis = amplitude_above_axis;
65         zero_line = 0;
66         wait_for_waves = wfw;
67         _height = 0;
68
69         _flags = 0;
70
71         if ((node = region.extra_xml ("GUI")) != 0) {
72                 set_flags (node);
73         } else {
74                 _flags = WaveformVisible;
75                 store_flags ();
76         }
77
78         fade_in_handle = 0;
79         fade_out_handle = 0;
80         gain_line = 0;
81         sync_mark = 0;
82
83         compute_colors (basic_color);
84
85         create_waves ();
86
87         name_highlight->set_data ("regionview", this);
88
89         reset_width_dependent_items ((double) region.length() / samples_per_unit);
90
91         set_height (trackview.height);
92
93         region_muted ();
94         region_resized (BoundsChanged);
95         set_waveview_data_src();
96         region_locked ();
97
98         /* no events, no state changes */
99
100         set_colors ();
101
102         // ColorChanged.connect (mem_fun (*this, &AudioRegionView::color_handler));
103
104         /* every time the wave data changes and peaks are ready, redraw */
105
106         
107         for (uint32_t n = 0; n < region.n_channels(); ++n) {
108                 region.source(n).PeaksReady.connect (bind (mem_fun(*this, &TapeAudioRegionView::update), n));
109         }
110         
111 }
112
113 TapeAudioRegionView::~TapeAudioRegionView()
114 {
115 }
116
117 void
118 TapeAudioRegionView::update (uint32_t n)
119 {
120         /* check that all waves are build and ready */
121
122         if (!tmp_waves.empty()) {
123                 return;
124         }
125
126         ENSURE_GUI_THREAD (bind (mem_fun(*this, &TapeAudioRegionView::update), n));
127
128         /* this triggers a cache invalidation and redraw in the waveview */
129
130         waves[n]->property_data_src() = &region;
131 }
132
133 void
134 TapeAudioRegionView::set_frame_color ()
135 {
136         fill_opacity = 255;
137         TimeAxisViewItem::set_frame_color ();
138 }