Move Diskstream ownership to Track, so that Session no longer holds lists of Diskstre...
[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
31 #include "tape_region_view.h"
32 #include "audio_time_axis.h"
33 #include "gui_thread.h"
34
35 #include "i18n.h"
36
37 using namespace ARDOUR;
38 using namespace PBD;
39 using namespace Editing;
40 using namespace ArdourCanvas;
41
42 const TimeAxisViewItem::Visibility TapeAudioRegionView::default_tape_visibility
43         = TimeAxisViewItem::Visibility (
44                 TimeAxisViewItem::ShowNameHighlight |
45                 TimeAxisViewItem::ShowNameText |
46                 TimeAxisViewItem::ShowFrame |
47                 TimeAxisViewItem::HideFrameRight |
48                 TimeAxisViewItem::FullWidthNameHighlight);
49
50 TapeAudioRegionView::TapeAudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv,
51                                           boost::shared_ptr<AudioRegion> r,
52                                           double spu,
53                                           Gdk::Color const & basic_color)
54
55         : AudioRegionView (parent, tv, r, spu, basic_color, false,
56                            TimeAxisViewItem::Visibility ((r->position() != 0) ? default_tape_visibility :
57                                                          TimeAxisViewItem::Visibility (default_tape_visibility|TimeAxisViewItem::HideFrameLeft)))
58 {
59 }
60
61 void
62 TapeAudioRegionView::init (Gdk::Color const & basic_color, bool /*wfw*/)
63 {
64         /* never wait for data: always just create the waves, connect once and then
65            we'll update whenever we need to.
66         */
67
68         AudioRegionView::init(basic_color, false);
69
70         /* every time the wave data changes and peaks are ready, redraw */
71
72         for (uint32_t n = 0; n < audio_region()->n_channels(); ++n) {
73                 audio_region()->audio_source(n)->PeaksReady.connect (*this, invalidator (*this), boost::bind (&TapeAudioRegionView::update, this, n), gui_context());
74         }
75
76 }
77
78 TapeAudioRegionView::~TapeAudioRegionView()
79 {
80 }
81
82 void
83 TapeAudioRegionView::update (uint32_t n)
84 {
85         /* check that all waves are build and ready */
86
87         if (!tmp_waves.empty()) {
88                 return;
89         }
90
91         ENSURE_GUI_THREAD (*this, &TapeAudioRegionView::update, n)
92
93         /* this triggers a cache invalidation and redraw in the waveview */
94
95         waves[n]->property_data_src() = _region.get();
96 }
97
98 void
99 TapeAudioRegionView::set_frame_color ()
100 {
101         fill_opacity = 255;
102         AudioRegionView::set_frame_color ();
103 }