Merge with 2.0-ongoing R3071.
[ardour.git] / gtk2_ardour / tape_region_view.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 */
19
20 #include <cmath>
21 #include <algorithm>
22
23 #include <gtkmm.h>
24
25 #include <gtkmm2ext/gtk_ui.h>
26
27 #include <ardour/playlist.h>
28 #include <ardour/audioregion.h>
29 #include <ardour/audiosource.h>
30 #include <ardour/audio_diskstream.h>
31
32 #include "tape_region_view.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 PBD;
41 using namespace Editing;
42 using namespace ArdourCanvas;
43
44 const TimeAxisViewItem::Visibility TapeAudioRegionView::default_tape_visibility
45         = TimeAxisViewItem::Visibility (
46                 TimeAxisViewItem::ShowNameHighlight |
47                 TimeAxisViewItem::ShowFrame |
48                 TimeAxisViewItem::HideFrameRight |
49                 TimeAxisViewItem::FullWidthNameHighlight);
50
51 TapeAudioRegionView::TapeAudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, 
52                                           boost::shared_ptr<AudioRegion> r, 
53                                           double spu, 
54                                           Gdk::Color& basic_color)
55
56         : AudioRegionView (parent, tv, r, spu, basic_color, 
57                            TimeAxisViewItem::Visibility ((r->position() != 0) ? default_tape_visibility : 
58                                                          TimeAxisViewItem::Visibility (default_tape_visibility|TimeAxisViewItem::HideFrameLeft)))
59 {
60 }
61
62 void
63 TapeAudioRegionView::init (Gdk::Color& basic_color, bool wfw)
64 {
65         /* never wait for data: always just create the waves, connect once and then
66            we'll update whenever we need to.
67         */
68
69         AudioRegionView::init(basic_color, false);
70
71         /* every time the wave data changes and peaks are ready, redraw */
72         
73         for (uint32_t n = 0; n < audio_region()->n_channels(); ++n) {
74                 audio_region()->audio_source(n)->PeaksReady.connect (bind (mem_fun(*this, &TapeAudioRegionView::update), n));
75         }
76         
77 }
78
79 TapeAudioRegionView::~TapeAudioRegionView()
80 {
81 }
82
83 void
84 TapeAudioRegionView::update (uint32_t n)
85 {
86         /* check that all waves are build and ready */
87
88         if (!tmp_waves.empty()) {
89                 return;
90         }
91
92         ENSURE_GUI_THREAD (bind (mem_fun(*this, &TapeAudioRegionView::update), n));
93
94         /* this triggers a cache invalidation and redraw in the waveview */
95
96         waves[n]->property_data_src() = _region.get();
97 }
98
99 void
100 TapeAudioRegionView::set_frame_color ()
101 {
102         fill_opacity = 255;
103         AudioRegionView::set_frame_color ();
104 }