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