Merged with trunk R1705.
[ardour.git] / gtk2_ardour / ghostregion.cc
1 #include "simplerect.h"
2 #include "waveview.h"
3 #include "ghostregion.h"
4 #include "automation_time_axis.h"
5 #include "rgb_macros.h"
6
7 using namespace Editing;
8 using namespace ArdourCanvas;
9
10 GhostRegion::GhostRegion (AutomationTimeAxisView& atv, double initial_pos)
11         : trackview (atv)
12 {
13   //group = gnome_canvas_item_new (GNOME_CANVAS_GROUP(trackview.canvas_display),
14   //                         gnome_canvas_group_get_type(),
15   //                         "x", initial_pos,
16   //                         "y", 0.0,
17   //                         NULL);
18         group = new ArdourCanvas::Group (*trackview.canvas_display);
19         group->property_x() = initial_pos;
20         group->property_y() = 0.0;
21
22         base_rect = new ArdourCanvas::SimpleRect (*group);
23         base_rect->property_x1() = (double) 0.0;
24         base_rect->property_y1() = (double) 0.0;
25         base_rect->property_y2() = (double) trackview.height;
26         base_rect->property_outline_what() = (guint32) 0;
27         base_rect->property_outline_color_rgba() = color_map[cGhostTrackBaseOutline];
28         base_rect->property_fill_color_rgba() = color_map[cGhostTrackBaseFill];
29         group->lower_to_bottom ();
30
31         atv.add_ghost (this);
32 }
33
34 GhostRegion::~GhostRegion ()
35 {
36         GoingAway (this);
37         delete base_rect;
38         delete group;
39 }
40
41 void
42 GhostRegion::set_samples_per_unit (double spu)
43 {
44         for (vector<WaveView*>::iterator i = waves.begin(); i != waves.end(); ++i) {
45                 (*i)->property_samples_per_unit() = spu;
46         }               
47 }
48
49 void
50 GhostRegion::set_duration (double units)
51 {
52         base_rect->property_x2() = units;
53 }
54
55 void
56 GhostRegion::set_height ()
57 {
58         gdouble ht;
59         vector<WaveView*>::iterator i;
60         uint32_t n;
61
62         base_rect->property_y2() = (double) trackview.height;
63         ht = ((trackview.height) / (double) waves.size());
64         
65         for (n = 0, i = waves.begin(); i != waves.end(); ++i, ++n) {
66                 gdouble yoff = n * ht;
67                 (*i)->property_height() = ht;
68                 (*i)->property_y() = yoff;
69         }
70 }
71
72 void
73 GhostRegion::set_colors ()
74 {
75     for (uint32_t n=0; n < waves.size(); ++n) {
76         waves[n]->property_wave_color() = color_map[cGhostTrackWave];
77
78         waves[n]->property_clip_color() = color_map[cGhostTrackWaveClip];
79         waves[n]->property_zero_color() = color_map[cGhostTrackZeroLine];
80     }
81 }