some C++-ification of GnomeCanvasBlah
[ardour.git] / gtk2_ardour / regionview.h
1 /*
2     Copyright (C) 2001-2004 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 #ifndef __gtk_ardour_region_view_h__
22 #define __gtk_ardour_region_view_h__
23
24 #include <vector>
25 #include <gtkmm.h>
26 #include <libgnomecanvasmm/libgnomecanvasmm.h>
27 #include <libgnomecanvasmm/polygon.h>
28 #include <sigc++/signal.h>
29 #include <ardour/region.h>
30
31 #include "time_axis_view_item.h"
32 #include "automation_line.h"
33 #include "enums.h"
34 #include "canvas-waveview.h"
35
36 namespace ARDOUR {
37         class AudioRegion;
38         class PeakData;
39 };
40
41 class AudioTimeAxisView;
42 class AudioRegionGainLine;
43 class AudioRegionEditor;
44 class GhostRegion;
45 class AutomationTimeAxisView;
46
47 class AudioRegionView : public TimeAxisViewItem
48 {
49   public:
50   AudioRegionView (Gnome::Canvas::Group *, 
51                      AudioTimeAxisView&,
52                      ARDOUR::AudioRegion&,
53                      double initial_samples_per_unit,
54                      double amplitude_above_axis,
55                      Gdk::Color& base_color,
56                      bool wait_for_waves);
57     ~AudioRegionView ();
58
59     ARDOUR::AudioRegion& region;  // ok, let 'em have it
60     bool is_valid() const { return valid; }
61     void set_valid (bool yn) { valid = yn; }
62
63     std::string get_item_name();
64     void set_height (double);
65     void set_samples_per_unit (double);
66     bool set_duration (jack_nframes_t, void*);
67
68     void set_amplitude_above_axis (gdouble spp);
69
70     void move (double xdelta, double ydelta);
71
72     void raise ();
73     void raise_to_top ();
74     void lower ();
75     void lower_to_bottom ();
76
77     bool set_position(jack_nframes_t pos, void* src, double* delta = 0);
78     
79     void temporarily_hide_envelope (); // dangerous
80     void unhide_envelope (); // dangerous
81
82     void set_envelope_visible (bool);
83     void set_waveform_visible (bool yn);
84     void set_waveform_shape (WaveformShape);
85
86     bool waveform_rectified() const { return _flags & WaveformRectified; }
87     bool waveform_visible() const { return _flags & WaveformVisible; }
88     bool envelope_visible() const { return _flags & EnvelopeVisible; }
89     
90     void show_region_editor ();
91     void hide_region_editor();
92
93     void add_gain_point_event (Gnome::Canvas::Item *item, GdkEvent *event);
94     void remove_gain_point_event (Gnome::Canvas::Item *item, GdkEvent *event);
95
96     AudioRegionGainLine* get_gain_line() const { return gain_line; }
97
98     void region_changed (ARDOUR::Change);
99     void envelope_active_changed ();
100
101     static sigc::signal<void,AudioRegionView*> AudioRegionViewGoingAway;
102     sigc::signal<void> GoingAway;
103
104     GhostRegion* add_ghost (AutomationTimeAxisView&);
105     void remove_ghost (GhostRegion*);
106
107     void reset_fade_in_shape_width (jack_nframes_t);
108     void reset_fade_out_shape_width (jack_nframes_t);
109     void set_fade_in_active (bool);
110     void set_fade_out_active (bool);
111
112     uint32_t get_fill_color ();
113
114     virtual void entered ();
115     virtual void exited ();
116
117   private:
118     enum Flags {
119             EnvelopeVisible = 0x1,
120             WaveformVisible = 0x4,
121             WaveformRectified = 0x8
122     };
123
124     vector<GnomeCanvasItem *> waves; /* waveviews */
125     vector<GnomeCanvasItem *> tmp_waves; /* see ::create_waves()*/
126     Gnome::Canvas::Polygon* sync_mark; /* polgyon for sync position */
127     Gnome::Canvas::Text* no_wave_msg; /* text */
128     Gnome::Canvas::Line* zero_line; /* simpleline */
129     Gnome::Canvas::Polygon* fade_in_shape; /* polygon */
130     Gnome::Canvas::Polygon* fade_out_shape; /* polygon */
131     Gnome::Canvas::SimpleRect* fade_in_handle; /* simplerect */
132     Gnome::Canvas::SimpleRect* fade_out_handle; /* simplerect */
133
134     AudioRegionGainLine* gain_line;
135     AudioRegionEditor *editor;
136
137     vector<ControlPoint *> control_points;
138     double _amplitude_above_axis;
139     double current_visible_sync_position;
140
141     uint32_t _flags;
142     uint32_t fade_color;
143     bool     valid; /* see StreamView::redisplay_diskstream() */
144     double _pixel_width;
145     double _height;
146     bool    in_destructor;
147     bool    wait_for_waves;
148
149     void reset_fade_shapes ();
150     void reset_fade_in_shape ();
151     void reset_fade_out_shape ();
152     void fade_in_changed ();
153     void fade_out_changed ();
154     void fade_in_active_changed ();
155     void fade_out_active_changed ();
156
157     void region_resized (ARDOUR::Change);
158     void region_moved (void *);
159     void region_muted ();
160     void region_locked ();
161     void region_opacity ();
162     void region_layered ();
163     void region_renamed ();
164     void region_sync_changed ();
165     void region_scale_amplitude_changed ();
166
167     static gint _lock_toggle (Gnome::Canvas::Item*, GdkEvent*, void*);
168     void lock_toggle ();
169
170     void create_waves ();
171     void create_one_wave (uint32_t, bool);
172     void manage_zero_line ();
173     void peaks_ready_handler (uint32_t);
174     void reset_name (gdouble width);
175     void set_flags (XMLNode *);
176     void store_flags ();
177
178     void set_colors ();
179     void compute_colors (Gdk::Color&);
180     void set_frame_color ();
181     void reset_width_dependent_items (double pixel_width);
182     void set_waveview_data_src();
183
184     vector<GnomeCanvasWaveViewCache*> wave_caches;
185     vector<GhostRegion*> ghosts;
186 };
187
188 #endif /* __gtk_ardour_region_view_h__ */