2006-03-04 Tim Mayberry <mojofunk@gmail.com>
[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
26 #include <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 "waveview.h"
35 #include "canvas.h"
36 #include "color.h"
37
38 namespace ARDOUR {
39         class AudioRegion;
40         class PeakData;
41 };
42
43 class AudioTimeAxisView;
44 class AudioRegionGainLine;
45 class AudioRegionEditor;
46 class GhostRegion;
47 class AutomationTimeAxisView;
48
49 class AudioRegionView : public TimeAxisViewItem
50 {
51   public:
52         AudioRegionView (ArdourCanvas::Group *, 
53                          AudioTimeAxisView&,
54                          ARDOUR::AudioRegion&,
55                          double initial_samples_per_unit,
56                          Gdk::Color& basic_color);
57
58         ~AudioRegionView ();
59         
60         virtual void init (double amplitude_above_axis, Gdk::Color& base_color, bool wait_for_waves);
61     
62     ARDOUR::AudioRegion& region;  // ok, let 'em have it
63     bool is_valid() const { return valid; }
64     void set_valid (bool yn) { valid = yn; }
65
66     std::string get_item_name();
67     void set_height (double);
68     void set_samples_per_unit (double);
69     bool set_duration (jack_nframes_t, void*);
70
71     void set_amplitude_above_axis (gdouble spp);
72
73     void move (double xdelta, double ydelta);
74
75     void raise ();
76     void raise_to_top ();
77     void lower ();
78     void lower_to_bottom ();
79
80     bool set_position(jack_nframes_t pos, void* src, double* delta = 0);
81     
82     void temporarily_hide_envelope (); // dangerous
83     void unhide_envelope (); // dangerous
84
85     void set_envelope_visible (bool);
86     void set_waveform_visible (bool yn);
87     void set_waveform_shape (WaveformShape);
88
89     bool waveform_rectified() const { return _flags & WaveformRectified; }
90     bool waveform_visible() const { return _flags & WaveformVisible; }
91     bool envelope_visible() const { return _flags & EnvelopeVisible; }
92     
93     void show_region_editor ();
94     void hide_region_editor();
95
96     void add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
97     void remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
98
99     AudioRegionGainLine* get_gain_line() const { return gain_line; }
100
101     void region_changed (ARDOUR::Change);
102     void envelope_active_changed ();
103
104     static sigc::signal<void,AudioRegionView*> AudioRegionViewGoingAway;
105     sigc::signal<void> GoingAway;
106
107     GhostRegion* add_ghost (AutomationTimeAxisView&);
108     void remove_ghost (GhostRegion*);
109
110     void reset_fade_in_shape_width (jack_nframes_t);
111     void reset_fade_out_shape_width (jack_nframes_t);
112     void set_fade_in_active (bool);
113     void set_fade_out_active (bool);
114
115     uint32_t get_fill_color ();
116
117     virtual void entered ();
118     virtual void exited ();
119
120   protected:
121
122     /* this constructor allows derived types
123        to specify their visibility requirements
124        to the TimeAxisViewItem parent class
125     */
126     
127     AudioRegionView (ArdourCanvas::Group *, 
128                      AudioTimeAxisView&,
129                      ARDOUR::AudioRegion&,
130                      double initial_samples_per_unit,
131                      Gdk::Color& basic_color,
132                      TimeAxisViewItem::Visibility);
133     
134     enum Flags {
135             EnvelopeVisible = 0x1,
136             WaveformVisible = 0x4,
137             WaveformRectified = 0x8
138     };
139
140     vector<ArdourCanvas::WaveView *> waves; /* waveviews */
141     vector<ArdourCanvas::WaveView *> tmp_waves; /* see ::create_waves()*/
142     ArdourCanvas::Polygon* sync_mark; /* polgyon for sync position */
143     ArdourCanvas::Text* no_wave_msg; /* text */
144     ArdourCanvas::SimpleLine* zero_line; /* simpleline */
145     ArdourCanvas::Polygon* fade_in_shape; /* polygon */
146     ArdourCanvas::Polygon* fade_out_shape; /* polygon */
147     ArdourCanvas::SimpleRect* fade_in_handle; /* simplerect */
148     ArdourCanvas::SimpleRect* fade_out_handle; /* simplerect */
149
150     AudioRegionGainLine* gain_line;
151     AudioRegionEditor *editor;
152
153     vector<ControlPoint *> control_points;
154     double _amplitude_above_axis;
155     double current_visible_sync_position;
156
157     uint32_t _flags;
158     uint32_t fade_color;
159     bool     valid; /* see StreamView::redisplay_diskstream() */
160     double _pixel_width;
161     double _height;
162     bool    in_destructor;
163     bool    wait_for_waves;
164     sigc::connection peaks_ready_connection;
165
166     void reset_fade_shapes ();
167     void reset_fade_in_shape ();
168     void reset_fade_out_shape ();
169     void fade_in_changed ();
170     void fade_out_changed ();
171     void fade_in_active_changed ();
172     void fade_out_active_changed ();
173
174     void region_resized (ARDOUR::Change);
175     void region_moved (void *);
176     void region_muted ();
177     void region_locked ();
178     void region_opacity ();
179     void region_layered ();
180     void region_renamed ();
181     void region_sync_changed ();
182     void region_scale_amplitude_changed ();
183
184     static gint _lock_toggle (ArdourCanvas::Item*, GdkEvent*, void*);
185     void lock_toggle ();
186
187     void create_waves ();
188     void create_one_wave (uint32_t, bool);
189     void manage_zero_line ();
190     void peaks_ready_handler (uint32_t);
191     void reset_name (gdouble width);
192     void set_flags (XMLNode *);
193     void store_flags ();
194
195     void set_colors ();
196     void compute_colors (Gdk::Color&);
197     virtual void set_frame_color ();
198     void reset_width_dependent_items (double pixel_width);
199     void set_waveview_data_src();
200
201     vector<GnomeCanvasWaveViewCache*> wave_caches;
202     vector<GhostRegion*> ghosts;
203     
204     void color_handler (ColorID, uint32_t);
205 };
206
207 #endif /* __gtk_ardour_region_view_h__ */