remove debugging message
[ardour.git] / gtk2_ardour / audio_region_view.cc
index c7bb048945d107711e60a62a351060a357ce65e9..ac0d317a13a14e5f3fe2186555c487c3ccb46020 100644 (file)
@@ -15,7 +15,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #include <cmath>
@@ -90,14 +89,37 @@ AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView
 {
 }
 
+
+AudioRegionView::AudioRegionView (const AudioRegionView& other)
+       : RegionView (other)
+       , zero_line(0)
+       , fade_in_shape(0)
+       , fade_out_shape(0)
+       , fade_in_handle(0)
+       , fade_out_handle(0)
+       , gain_line(0)
+       , _amplitude_above_axis(1.0)
+       , _flags(0)
+       , fade_color(0)
+
+{
+       Gdk::Color c;
+       int r,g,b,a;
+
+       UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
+       c.set_rgb_p (r/255.0, g/255.0, b/255.0);
+       
+       init (c, false);
+}
+
 void
 AudioRegionView::init (Gdk::Color& basic_color, bool wfd)
 {
        // FIXME: Some redundancy here with RegionView::init.  Need to figure out
        // where order is important and where it isn't...
        
-       RegionView::init(basic_color, wfd);
-
+       RegionView::init(basic_color, false);
+       
        XMLNode *node;
 
        _amplitude_above_axis = 1.0;
@@ -249,19 +271,6 @@ AudioRegionView::fade_out_changed ()
 {
        reset_fade_out_shape ();
 }
-
-void
-AudioRegionView::set_fade_in_active (bool yn)
-{
-       audio_region()->set_fade_in_active (yn);
-}
-
-void
-AudioRegionView::set_fade_out_active (bool yn)
-{
-       audio_region()->set_fade_out_active (yn);
-}
-
 void
 AudioRegionView::fade_in_active_changed ()
 {
@@ -620,13 +629,16 @@ AudioRegionView::set_samples_per_unit (gdouble spu)
 {
        RegionView::set_samples_per_unit (spu);
 
-       for (uint32_t n=0; n < waves.size(); ++n) {
-               waves[n]->property_samples_per_unit() = spu;
+       if (_flags & WaveformVisible) {
+               for (uint32_t n=0; n < waves.size(); ++n) {
+                       waves[n]->property_samples_per_unit() = spu;
+               }
        }
 
        if (gain_line) {
                gain_line->reset ();
        }
+
        reset_fade_shapes ();
 }
 
@@ -666,6 +678,9 @@ AudioRegionView::set_colors ()
                } else {
                        waves[n]->property_wave_color() = color_map[cWaveForm];
                }
+
+               waves[n]->property_clip_color() = color_map[cWaveFormClip];
+               waves[n]->property_zero_color() = color_map[cZeroLine];
        }
 }
 
@@ -679,8 +694,8 @@ AudioRegionView::show_region_editor ()
                // trackview.editor.ensure_float (*editor);
        } 
 
-       editor->show_all ();
-       editor->get_window()->raise();
+       editor->present ();
+       editor->show_all();
 }
 
 void
@@ -689,6 +704,10 @@ AudioRegionView::set_waveform_visible (bool yn)
        if (((_flags & WaveformVisible) != yn)) {
                if (yn) {
                        for (uint32_t n=0; n < waves.size(); ++n) {
+                               /* make sure the zoom level is correct, since we don't update
+                                  this when waveforms are hidden.
+                               */
+                               waves[n]->property_samples_per_unit() = samples_per_unit;
                                waves[n]->show();
                        }
                        _flags |= WaveformVisible;
@@ -736,8 +755,6 @@ AudioRegionView::set_envelope_visible (bool yn)
 void
 AudioRegionView::create_waves ()
 {
-       bool create_zero_line = true;
-
        RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
 
        if (!atv.get_diskstream()) {
@@ -750,7 +767,7 @@ AudioRegionView::create_waves ()
        for (uint32_t n = 0; n < nchans; ++n) {
                tmp_waves.push_back (0);
        }
-       
+
        for (uint32_t n = 0; n < nchans; ++n) {
                
                if (n >= audio_region()->n_channels()) {
@@ -763,23 +780,11 @@ AudioRegionView::create_waves ()
                        if (audio_region()->source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
                                create_one_wave (n, true);
                        } else {
-                               create_zero_line = false;
                        }
                } else {
                        create_one_wave (n, true);
                }
        }
-
-       if (create_zero_line) {
-               if (zero_line) {
-                       delete zero_line;
-               }
-               zero_line = new ArdourCanvas::SimpleLine (*group);
-               zero_line->property_x1() = (gdouble) 1.0;
-               zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
-               zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
-               manage_zero_line ();
-       }
 }
 
 void
@@ -814,7 +819,11 @@ AudioRegionView::create_one_wave (uint32_t which, bool direct)
        wave->property_samples_per_unit() =  samples_per_unit;
        wave->property_amplitude_above_axis() =  _amplitude_above_axis;
        wave->property_wave_color() = _region->muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm];
+       wave->property_clip_color() = color_map[cWaveFormClip];
+       wave->property_zero_color() = color_map[cZeroLine];
        wave->property_region_start() = _region->start();
+       wave->property_rectified() = (bool) (_flags & WaveformRectified);
+       wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
 
        if (!(_flags & WaveformVisible)) {
                wave->hide();
@@ -839,7 +848,7 @@ AudioRegionView::create_one_wave (uint32_t which, bool direct)
                        break;
                }
        }
-       
+
        if (n == nwaves && waves.empty()) {
                /* all waves are ready */
                tmp_waves.resize(nwaves);
@@ -847,6 +856,10 @@ AudioRegionView::create_one_wave (uint32_t which, bool direct)
                waves = tmp_waves;
                tmp_waves.clear ();
 
+               /* all waves created, don't hook into peaks ready anymore */
+               data_ready_connection.disconnect ();            
+
+               if(0)
                if (!zero_line) {
                        zero_line = new ArdourCanvas::SimpleLine (*group);
                        zero_line->property_x1() = (gdouble) 1.0;
@@ -861,11 +874,6 @@ void
 AudioRegionView::peaks_ready_handler (uint32_t which)
 {
        Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
-
-       if (!waves.empty()) {
-               /* all waves created, don't hook into peaks ready anymore */
-               data_ready_connection.disconnect ();            
-       }
 }
 
 void
@@ -931,6 +939,8 @@ AudioRegionView::store_flags()
 
        node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
        node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
+       node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
+       node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
 
        _region->add_extra_xml (*node);
 }
@@ -951,6 +961,18 @@ AudioRegionView::set_flags (XMLNode* node)
                        _flags |= EnvelopeVisible;
                }
        }
+
+       if ((prop = node->property ("waveform-rectified")) != 0) {
+               if (prop->value() == "yes") {
+                       _flags |= WaveformRectified;
+               }
+       }
+
+       if ((prop = node->property ("waveform-logscaled")) != 0) {
+               if (prop->value() == "yes") {
+                       _flags |= WaveformLogScaled;
+               }
+       }
 }
        
 void
@@ -990,9 +1012,30 @@ AudioRegionView::set_waveform_shape (WaveformShape shape)
                } else {
                        _flags &= ~WaveformRectified;
                }
+               store_flags ();
+       }
+}
+
+void
+AudioRegionView::set_waveform_scale (WaveformScale scale)
+{
+       bool yn = (scale == LogWaveform);
+
+       if (yn != (bool) (_flags & WaveformLogScaled)) {
+               for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
+                       (*wave)->property_logscaled() = yn;
+               }
+
+               if (yn) {
+                       _flags |= WaveformLogScaled;
+               } else {
+                       _flags &= ~WaveformLogScaled;
+               }
+               store_flags ();
        }
 }
 
+
 GhostRegion*
 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
 {
@@ -1024,6 +1067,8 @@ AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
                wave->property_samples_per_unit() =  samples_per_unit;
                wave->property_amplitude_above_axis() =  _amplitude_above_axis;
                wave->property_wave_color() = color_map[cGhostTrackWave];
+               wave->property_clip_color() = color_map[cGhostTrackWaveClip];
+               wave->property_zero_color() = color_map[cGhostTrackZeroLine];
                wave->property_region_start() = _region->start();
 
                ghost->waves.push_back(wave);
@@ -1108,6 +1153,8 @@ AudioRegionView::color_handler (ColorID id, uint32_t val)
        switch (id) {
        case cMutedWaveForm:
        case cWaveForm:
+       case cWaveFormClip:
+       case cZeroLine:
                set_colors ();
                break;
 
@@ -1115,15 +1162,6 @@ AudioRegionView::color_handler (ColorID id, uint32_t val)
        case cGainLine:
                envelope_active_changed();
                break;
-               
-       case cZeroLine:
-               if (zero_line) {
-                       zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
-               }
-               break;
-
-       case cGhostTrackWave:
-               break;
 
        default:
                break;