remove UUIDs as implemention of PBD::ID, use static counter (not finished - counter...
[ardour.git] / gtk2_ardour / streamview.cc
index e661b5d49c6fd4e33f854fd128159966e7590594..a60e0d59e78fd9c474b49c7d19f4621052981ed4 100644 (file)
@@ -6,13 +6,15 @@
 
 #include <ardour/audioplaylist.h>
 #include <ardour/audioregion.h>
-#include <ardour/diskstream.h>
+#include <ardour/audiosource.h>
+#include <ardour/audio_diskstream.h>
 #include <ardour/audio_track.h>
 #include <ardour/playlist_templates.h>
 #include <ardour/source.h>
 
 #include "streamview.h"
 #include "regionview.h"
+#include "taperegionview.h"
 #include "audio_time_axis.h"
 #include "canvas-waveview.h"
 #include "canvas-simplerect.h"
 #include "rgb_macros.h"
 #include "gui_thread.h"
 #include "utils.h"
+#include "color.h"
 
 using namespace ARDOUR;
+using namespace PBD;
 using namespace Editing;
 
 StreamView::StreamView (AudioTimeAxisView& tv)
@@ -46,31 +50,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 +77,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 +212,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 +277,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*/
        } 
@@ -305,6 +299,7 @@ StreamView::remove_rec_region (Region *r)
 void
 StreamView::undisplay_diskstream ()
 {
+       
        for (AudioRegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
                delete *i;
        }
@@ -318,7 +313,7 @@ StreamView::undisplay_diskstream ()
 }
 
 void
-StreamView::display_diskstream (DiskStream *ds)
+StreamView::display_diskstream (AudioDiskstream *ds)
 {
        playlist_change_connection.disconnect();
        playlist_changed (ds);
@@ -344,7 +339,7 @@ StreamView::playlist_modified ()
 }
 
 void
-StreamView::playlist_changed (DiskStream *ds)
+StreamView::playlist_changed (AudioDiskstream *ds)
 {
        ENSURE_GUI_THREAD (bind (mem_fun (*this, &StreamView::playlist_changed), ds));
 
@@ -446,6 +441,7 @@ StreamView::redisplay_diskstream ()
        list<AudioRegionView *>::iterator i, tmp;
        list<CrossfadeView*>::iterator xi, tmpx;
 
+       
        for (i = region_views.begin(); i != region_views.end(); ++i) {
                (*i)->set_valid (false);
        }
@@ -497,7 +493,7 @@ StreamView::diskstream_changed (void *src_ignored)
        AudioTrack *at;
 
        if ((at = _trackview.audio_track()) != 0) {
-               DiskStream& ds = at->disk_stream();
+               AudioDiskstream& ds = at->disk_stream();
                /* XXX grrr: when will SigC++ allow me to bind references? */
                Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun (*this, &StreamView::display_diskstream), &ds));
        } else {
@@ -541,6 +537,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;
@@ -551,7 +548,8 @@ StreamView::set_selected_regionviews (AudioRegionSelection& regions)
                        }
                }
                
-               (*i)->set_selected (selected, this);
+               // cerr << "\tregion " << (*i)->region.name() << " selected = " << selected << endl;
+               (*i)->set_selected (selected);
        }
 }
 
@@ -622,11 +620,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;
@@ -637,7 +636,7 @@ StreamView::setup_rec_box ()
                                peak_ready_connections.clear();
                                        
                                for (uint32_t n=0; n < _trackview.get_diskstream()->n_channels(); ++n) {
-                                       Source *src = (Source *) _trackview.get_diskstream()->write_source (n);
+                                       AudioSource *src = (AudioSource *) _trackview.get_diskstream()->write_source (n);
                                        if (src) {
                                                sources.push_back (src);
                                                peak_ready_connections.push_back (src->PeakRangeReady.connect (bind (mem_fun (*this, &StreamView::rec_peak_range_ready), src))); 
@@ -665,10 +664,27 @@ StreamView::setup_rec_box ()
                        AudioTrack* at;
 
                        at = _trackview.audio_track(); /* we know what it is already */
-                       DiskStream& ds = at->disk_stream();
+                       AudioDiskstream& 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;
@@ -676,7 +692,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;
@@ -753,21 +769,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)
 {
@@ -927,3 +954,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;
+       }
+}