Fixed some valgrind errors from using uninitialized variables in
[ardour.git] / gtk2_ardour / streamview.cc
index dda5f0ef51b96d764aac73d3d5e90665b96c4dbe..bceaf09f99a5e21063e34ea26b5e6bf1da836842 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "streamview.h"
 #include "regionview.h"
+#include "taperegionview.h"
 #include "audio_time_axis.h"
 #include "canvas-waveview.h"
 #include "canvas-simplerect.h"
@@ -24,6 +25,7 @@
 #include "rgb_macros.h"
 #include "gui_thread.h"
 #include "utils.h"
+#include "color.h"
 
 using namespace ARDOUR;
 using namespace Editing;
@@ -46,31 +48,15 @@ StreamView::StreamView (AudioTimeAxisView& tv)
 
        /* set_position() will position the group */
 
-       //GTK2FIX -- how to get the group? is the canvas display really a group?
-       //canvas_group = gnome_canvas_item_new (GNOME_CANVAS_GROUP(_trackview.canvas_display),
-       //                          gnome_canvas_group_get_type (),
-       //                          NULL);
        canvas_group = new ArdourCanvas::Group(*_trackview.canvas_display);
 
-       //canvas_rect = gnome_canvas_item_new (GNOME_CANVAS_GROUP(canvas_group),
-       //                         gnome_canvas_simplerect_get_type(),
-       //                         "x1", 0.0,
-       //                         "y1", 0.0,
-       //                         "x2", 1000000.0,
-       //                         "y2", (double) tv.height,
-       //                         "outline_color_rgba", color_map[cAudioTrackOutline],
-       //                         /* outline ends and bottom */
-       //                         "outline_what", (guint32) (0x1|0x2|0x8),
-       //                         "fill_color_rgba", stream_base_color,
-       //      ]                  NULL);
        canvas_rect = new ArdourCanvas::SimpleRect (*canvas_group);
        canvas_rect->property_x1() = 0.0;
        canvas_rect->property_y1() = 0.0;
        canvas_rect->property_x2() = 1000000.0;
        canvas_rect->property_y2() = (double) tv.height;
        canvas_rect->property_outline_color_rgba() = color_map[cAudioTrackOutline];
-       /* outline ends and bottom */
-       canvas_rect->property_outline_what() = (guint32) (0x1|0x2|0x8);
+       canvas_rect->property_outline_what() = (guint32) (0x1|0x2|0x8);  // outline ends and bottom 
        canvas_rect->property_fill_color_rgba() = stream_base_color;
 
        canvas_rect->signal_event().connect (bind (mem_fun (_trackview.editor, &PublicEditor::canvas_stream_view_event), canvas_rect, &_trackview));
@@ -89,6 +75,8 @@ StreamView::StreamView (AudioTimeAxisView& tv)
        rec_active = false;
        use_rec_regions = tv.editor.show_waveforms_recording ();
        last_rec_peak_frame = 0;
+
+       ColorChanged.connect (mem_fun (*this, &StreamView::color_handler));
 }
 
 StreamView::~StreamView ()
@@ -222,15 +210,19 @@ StreamView::add_region_view_internal (Region *r, bool wait_for_waves)
                        return;
                }
        }
+       
+       switch (_trackview.audio_track()->mode()) {
+       case Normal:
+               region_view = new AudioRegionView (canvas_group, _trackview, *region, 
+                                                  _samples_per_unit, region_color);
+               break;
+       case Destructive:
+               region_view = new TapeAudioRegionView (canvas_group, _trackview, *region, 
+                                                      _samples_per_unit, region_color);
+               break;
+       }
 
-       region_view = new AudioRegionView (canvas_group,
-                                          _trackview,
-                                          *region,
-                                          _samples_per_unit,
-                                          _amplitude_above_axis, 
-                                          region_color, 
-                                          wait_for_waves);
-
+       region_view->init (_amplitude_above_axis, region_color, wait_for_waves);
        region_views.push_front (region_view);
        
        /* follow global waveform setting */
@@ -283,7 +275,7 @@ StreamView::remove_rec_region (Region *r)
 {
        ENSURE_GUI_THREAD(bind (mem_fun (*this, &StreamView::remove_rec_region), r));
        
-       if (!Gtkmm2ext::UI::instance()->caller_is_gui_thread()) {
+       if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {
                fatal << "region deleted from non-GUI thread!" << endmsg;
                /*NOTREACHED*/
        } 
@@ -543,6 +535,7 @@ StreamView::set_selected_regionviews (AudioRegionSelection& regions)
 {
        bool selected;
 
+       // cerr << _trackview.name() << " (selected = " << regions.size() << ")" << endl;
        for (list<AudioRegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
                
                selected = false;
@@ -553,6 +546,7 @@ StreamView::set_selected_regionviews (AudioRegionSelection& regions)
                        }
                }
                
+               // cerr << "\tregion " << (*i)->region.name() << " selected = " << selected << endl;
                (*i)->set_selected (selected, this);
        }
 }
@@ -624,11 +618,12 @@ StreamView::setup_rec_box ()
 
                // cerr << "\trolling\n";
 
-               if (!rec_active
-                   && _trackview.session().record_status() == Session::Recording
-                   && _trackview.get_diskstream()->record_enabled()) {
+               if (!rec_active && 
+                   _trackview.session().record_status() == Session::Recording && 
+                   _trackview.get_diskstream()->record_enabled()) {
+
+                       if (_trackview.audio_track()->mode() == Normal && use_rec_regions && rec_regions.size() == rec_rects.size()) {
 
-                       if (use_rec_regions && rec_regions.size() == rec_rects.size()) {
                                /* add a new region, but don't bother if they set use_rec_regions mid-record */
 
                                AudioRegion::SourceList sources;
@@ -670,7 +665,24 @@ StreamView::setup_rec_box ()
                        DiskStream& ds = at->disk_stream();
                        jack_nframes_t frame_pos = ds.current_capture_start ();
                        gdouble xstart = _trackview.editor.frame_to_pixel (frame_pos);
-                       gdouble xend = xstart;
+                       gdouble xend;
+                       uint32_t fill_color;
+
+                       switch (_trackview.audio_track()->mode()) {
+                       case Normal:
+                               xend = xstart;
+                               fill_color = color_map[cRecordingRectFill];
+                               break;
+
+                       case Destructive:
+                               xend = xstart + 2;
+                               fill_color = color_map[cRecordingRectFill];
+                               /* make the recording rect translucent to allow
+                                  the user to see the peak data coming in, etc.
+                               */
+                               fill_color = UINT_RGBA_CHANGE_A (fill_color, 120);
+                               break;
+                       }
                        
                        ArdourCanvas::SimpleRect * rec_rect = new Gnome::Canvas::SimpleRect (*canvas_group);
                        rec_rect->property_x1() = xstart;
@@ -678,7 +690,7 @@ StreamView::setup_rec_box ()
                        rec_rect->property_x2() = xend;
                        rec_rect->property_y2() = (double) _trackview.height - 1;
                        rec_rect->property_outline_color_rgba() = color_map[cRecordingRectOutline];
-                       rec_rect->property_fill_color_rgba() =  color_map[cRecordingRectFill];
+                       rec_rect->property_fill_color_rgba() = fill_color;
                        
                        RecBoxInfo recbox;
                        recbox.rectangle = rec_rect;
@@ -755,21 +767,32 @@ StreamView::setup_rec_box ()
 void
 StreamView::update_rec_box ()
 {
-       /* only update the last box */
        if (rec_active && rec_rects.size() > 0) {
+               /* only update the last box */
                RecBoxInfo & rect = rec_rects.back();
                jack_nframes_t at = _trackview.get_diskstream()->current_capture_end();
+               double xstart;
+               double xend;
+               
+               switch (_trackview.audio_track()->mode()) {
+               case Normal:
+                       rect.length = at - rect.start;
+                       xstart = _trackview.editor.frame_to_pixel (rect.start);
+                       xend = _trackview.editor.frame_to_pixel (at);
+                       break;
+                       
+               case Destructive:
+                       rect.length = 2;
+                       xstart = _trackview.editor.frame_to_pixel (_trackview.get_diskstream()->current_capture_start());
+                       xend = _trackview.editor.frame_to_pixel (at);
+                       break;
+               }
                
-               rect.length = at - rect.start;
-
-               gdouble xstart = _trackview.editor.frame_to_pixel ( rect.start );
-               gdouble xend = _trackview.editor.frame_to_pixel ( at );
-
                rect.rectangle->property_x1() = xstart;
                rect.rectangle->property_x2() = xend;
        }
 }
-
+       
 AudioRegionView*
 StreamView::find_view (const AudioRegion& region)
 {
@@ -929,3 +952,26 @@ StreamView::reveal_xfades_involving (AudioRegionView& rv)
                }
        }
 }
+
+void
+StreamView::color_handler (ColorID id, uint32_t val)
+{
+       switch (id) {
+       case cAudioTrackBase:
+               if (_trackview.is_audio_track()) {
+                       canvas_rect->property_fill_color_rgba() = val;
+               } 
+               break;
+       case cAudioBusBase:
+               if (!_trackview.is_audio_track()) {
+                       canvas_rect->property_fill_color_rgba() = val;
+               }
+               break;
+       case cAudioTrackOutline:
+               canvas_rect->property_outline_color_rgba() = val;
+               break;
+
+       default:
+               break;
+       }
+}