moved 2.1-staging to trunk @ rev 1765
[ardour.git] / gtk2_ardour / ghostregion.cc
1 /*
2     Copyright (C) 2000-2007 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 "simplerect.h"
21 #include "waveview.h"
22 #include "ghostregion.h"
23 #include "automation_time_axis.h"
24 #include "rgb_macros.h"
25
26 using namespace Editing;
27 using namespace ArdourCanvas;
28
29 GhostRegion::GhostRegion (AutomationTimeAxisView& atv, double initial_pos)
30         : trackview (atv)
31 {
32   //group = gnome_canvas_item_new (GNOME_CANVAS_GROUP(trackview.canvas_display),
33   //                         gnome_canvas_group_get_type(),
34   //                         "x", initial_pos,
35   //                         "y", 0.0,
36   //                         NULL);
37         group = new ArdourCanvas::Group (*trackview.canvas_display);
38         group->property_x() = initial_pos;
39         group->property_y() = 0.0;
40
41         base_rect = new ArdourCanvas::SimpleRect (*group);
42         base_rect->property_x1() = (double) 0.0;
43         base_rect->property_y1() = (double) 0.0;
44         base_rect->property_y2() = (double) trackview.height;
45         base_rect->property_outline_what() = (guint32) 0;
46         base_rect->property_outline_color_rgba() = color_map[cGhostTrackBaseOutline];
47         base_rect->property_fill_color_rgba() = color_map[cGhostTrackBaseFill];
48         group->lower_to_bottom ();
49
50         atv.add_ghost (this);
51 }
52
53 GhostRegion::~GhostRegion ()
54 {
55         GoingAway (this);
56         delete base_rect;
57         delete group;
58 }
59
60 void
61 GhostRegion::set_samples_per_unit (double spu)
62 {
63         for (vector<WaveView*>::iterator i = waves.begin(); i != waves.end(); ++i) {
64                 (*i)->property_samples_per_unit() = spu;
65         }               
66 }
67
68 void
69 GhostRegion::set_duration (double units)
70 {
71         base_rect->property_x2() = units;
72 }
73
74 void
75 GhostRegion::set_height ()
76 {
77         gdouble ht;
78         vector<WaveView*>::iterator i;
79         uint32_t n;
80
81         base_rect->property_y2() = (double) trackview.height;
82         ht = ((trackview.height) / (double) waves.size());
83         
84         for (n = 0, i = waves.begin(); i != waves.end(); ++i, ++n) {
85                 gdouble yoff = n * ht;
86                 (*i)->property_height() = ht;
87                 (*i)->property_y() = yoff;
88         }
89 }
90
91 void
92 GhostRegion::set_colors ()
93 {
94     for (uint32_t n=0; n < waves.size(); ++n) {
95         waves[n]->property_wave_color() = color_map[cGhostTrackWave];
96
97         waves[n]->property_clip_color() = color_map[cGhostTrackWaveClip];
98         waves[n]->property_zero_color() = color_map[cGhostTrackZeroLine];
99     }
100 }