0cf50b87e635ad32da248ed9c48810c1695f3c43
[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     $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 "tape_region_view.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 PBD;
42 using namespace Editing;
43 using namespace ArdourCanvas;
44
45 const TimeAxisViewItem::Visibility TapeAudioRegionView::default_tape_visibility
46         = TimeAxisViewItem::Visibility (
47                 TimeAxisViewItem::ShowNameHighlight |
48                 TimeAxisViewItem::ShowFrame |
49                 TimeAxisViewItem::HideFrameRight |
50                 TimeAxisViewItem::FullWidthNameHighlight);
51
52 TapeAudioRegionView::TapeAudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, 
53                                           boost::shared_ptr<AudioRegion> r, 
54                                           double spu, 
55                                           Gdk::Color& basic_color)
56
57         : AudioRegionView (parent, tv, r, spu, basic_color, 
58                            TimeAxisViewItem::Visibility ((r->position() != 0) ? default_tape_visibility : 
59                                                          TimeAxisViewItem::Visibility (default_tape_visibility|TimeAxisViewItem::HideFrameLeft)))
60 {
61 }
62
63 void
64 TapeAudioRegionView::init (Gdk::Color& basic_color, bool wfw)
65 {
66         AudioRegionView::init(basic_color, wfw);
67
68         /* every time the wave data changes and peaks are ready, redraw */
69         
70         for (uint32_t n = 0; n < audio_region()->n_channels(); ++n) {
71                 audio_region()->source(n)->PeaksReady.connect (bind (mem_fun(*this, &TapeAudioRegionView::update), n));
72         }
73         
74 }
75
76 TapeAudioRegionView::~TapeAudioRegionView()
77 {
78 }
79
80 void
81 TapeAudioRegionView::update (uint32_t n)
82 {
83         /* check that all waves are build and ready */
84
85         if (!tmp_waves.empty()) {
86                 return;
87         }
88
89         ENSURE_GUI_THREAD (bind (mem_fun(*this, &TapeAudioRegionView::update), n));
90
91         /* this triggers a cache invalidation and redraw in the waveview */
92
93         waves[n]->property_data_src() = _region.get();
94 }
95
96 void
97 TapeAudioRegionView::set_frame_color ()
98 {
99         fill_opacity = 255;
100         TimeAxisViewItem::set_frame_color ();
101 }