remove UUIDs as implemention of PBD::ID, use static counter (not finished - counter...
[ardour.git] / gtk2_ardour / streamview.cc
index bd6f984315c92e14068234be45a34eb76514eeb9..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 "crossfade_view.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)
@@ -45,35 +50,18 @@ 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 Gnome::Canvas::Group(GNOME_CANVAS_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 Gnome::Canvas::SimpleRect (*canvas_group);
-       canvas_rect->set_property ("x1", 0.0);
-       canvas_rect->set_property ("y1", 0.0);
-       canvas_rect->set_property ("x2", 1000000.0);
-       canvas_rect->set_property ("y2", (double) tv.height);
-       canvas_rect->set_property ("outline_color_rgba", color_map[cAudioTrackOutline]);
-       /* outline ends and bottom */
-       canvas_rect->set_property ("outline_what", (guint32) (0x1|0x2|0x8));
-       canvas_rect->set_property ("fill_color_rgba", stream_base_color);
-
-       gtk_signal_connect (GTK_OBJECT(canvas_rect), "event",
-                           (GtkSignalFunc) PublicEditor::canvas_stream_view_event, &_trackview);
+       canvas_group = new ArdourCanvas::Group(*_trackview.canvas_display);
+
+       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];
+       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));
 
        _samples_per_unit = _trackview.editor.get_current_zoom();
        _amplitude_above_axis = 1.0;
@@ -82,20 +70,21 @@ StreamView::StreamView (AudioTimeAxisView& tv)
                _trackview.audio_track()->diskstream_changed.connect (mem_fun (*this, &StreamView::diskstream_changed));
                _trackview.session().TransportStateChange.connect (mem_fun (*this, &StreamView::transport_changed));
                _trackview.get_diskstream()->record_enable_changed.connect (mem_fun (*this, &StreamView::rec_enable_changed));
-               _trackview.session().RecordEnabled.connect (mem_fun (*this, &StreamView::sess_rec_enable_changed));
-               _trackview.session().RecordDisabled.connect (mem_fun (*this, &StreamView::sess_rec_enable_changed));
+               _trackview.session().RecordStateChanged.connect (mem_fun (*this, &StreamView::sess_rec_enable_changed));
        } 
 
        rec_updating = false;
        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 ()
 {
        undisplay_diskstream ();
-       gtk_object_destroy (GTK_OBJECT(canvas_group));
+       delete canvas_group;
 }
 
 void
@@ -110,8 +99,8 @@ int
 StreamView::set_position (gdouble x, gdouble y)
 
 {
-       canvas_group->set_property ("x", x);
-       canvas_group->set_property ("y", y);
+       canvas_group->property_x() = x;
+       canvas_group->property_y() = y;
        return 0;
 }
 
@@ -124,7 +113,7 @@ StreamView::set_height (gdouble h)
                return -1;
        }
 
-       gtk_object_set (GTK_OBJECT(canvas_rect), "y2", h, NULL);
+       canvas_rect->property_y2() = h;
 
        for (AudioRegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
                (*i)->set_height (h);
@@ -136,7 +125,7 @@ StreamView::set_height (gdouble h)
 
        for (vector<RecBoxInfo>::iterator i = rec_rects.begin(); i != rec_rects.end(); ++i) {
                RecBoxInfo &recbox = (*i);
-               gtk_object_set (GTK_OBJECT( recbox.rectangle ), "y2", h - 1, NULL);
+               recbox.rectangle->property_y2() = h - 1.0;
        }
 
        return 0;
@@ -167,8 +156,8 @@ StreamView::set_samples_per_unit (gdouble spp)
                gdouble xstart = _trackview.editor.frame_to_pixel ( recbox.start );
                gdouble xend = _trackview.editor.frame_to_pixel ( recbox.start + recbox.length );
 
-               recbox.rectangle->set_property ("x1", xstart);
-               recbox.rectangle->set_property ("x2", xend);
+               recbox.rectangle->property_x1() = xstart;
+               recbox.rectangle->property_x2() = xend;
        }
 
        return 0;
@@ -223,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 */
@@ -284,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*/
        } 
@@ -306,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;
        }
@@ -319,7 +313,7 @@ StreamView::undisplay_diskstream ()
 }
 
 void
-StreamView::display_diskstream (DiskStream *ds)
+StreamView::display_diskstream (AudioDiskstream *ds)
 {
        playlist_change_connection.disconnect();
        playlist_changed (ds);
@@ -345,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));
 
@@ -447,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);
        }
@@ -470,7 +465,7 @@ StreamView::redisplay_diskstream ()
                if (!(*i)->is_valid()) {
                        delete *i;
                        region_views.erase (i);
-               }
+               } 
 
                i = tmp;
        }
@@ -498,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 {
@@ -542,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;
@@ -552,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);
        }
 }
 
@@ -623,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;
@@ -638,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))); 
@@ -666,18 +664,35 @@ 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;
+                       }
                        
-                       Gnome::Canvas::SimpleRect * rec_rect = new Gnome::Canvas::SimpleRect (*canvas_group);
-                       rec_rect->set_property ("x1", xstart);
-                       rec_rect->set_property ("y1", 1.0);
-                       rec_rect->set_property ("x2", xend);
-                       rec_rect->set_property ("y2", (double) _trackview.height - 1);
-                       rec_rect->set_property ("outline_color_rgba", color_map[cRecordingRectOutline]);
-                       rec_rect->set_property ("fill_color_rgba",  color_map[cRecordingRectFill]);
+                       ArdourCanvas::SimpleRect * rec_rect = new Gnome::Canvas::SimpleRect (*canvas_group);
+                       rec_rect->property_x1() = xstart;
+                       rec_rect->property_y1() = 1.0;
+                       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() = fill_color;
                        
                        RecBoxInfo recbox;
                        recbox.rectangle = rec_rect;
@@ -741,7 +756,7 @@ StreamView::setup_rec_box ()
                        /* transport stopped, clear boxes */
                        for (vector<RecBoxInfo>::iterator iter=rec_rects.begin(); iter != rec_rects.end(); ++iter) {
                                RecBoxInfo &rect = (*iter);
-                               gtk_object_destroy (GTK_OBJECT(rect.rectangle));
+                               delete rect.rectangle;
                        }
                        
                        rec_rects.clear();
@@ -754,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;
                
-               rect.length = at - rect.start;
-
-               gdouble xstart = _trackview.editor.frame_to_pixel ( rect.start );
-               gdouble xend = _trackview.editor.frame_to_pixel ( at );
-
-               rect.rectangle->set_property ("x1", xstart);
-               rect.rectangle->set_property ("x2", 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.rectangle->property_x1() = xstart;
+               rect.rectangle->property_x2() = xend;
        }
 }
-
+       
 AudioRegionView*
 StreamView::find_view (const AudioRegion& region)
 {
@@ -830,7 +856,7 @@ StreamView::update_rec_regions ()
                        tmp = iter;
                        ++tmp;
 
-                       if ((GTK_OBJECT_FLAGS(GTK_OBJECT(rec_rects[n].rectangle)) & GNOME_CANVAS_ITEM_VISIBLE) == 0) {
+                       if (!canvas_item_visible (rec_rects[n].rectangle)) {
                                /* rect already hidden, this region is done */
                                iter = tmp;
                                continue;
@@ -858,9 +884,9 @@ StreamView::update_rec_regions ()
                                                }
 
                                                /* also update rect */
-                                               Gnome::Canvas::Item * rect = rec_rects[n].rectangle;
+                                               ArdourCanvas::SimpleRect * rect = rec_rects[n].rectangle;
                                                gdouble xend = _trackview.editor.frame_to_pixel (region->position() + region->length());
-                                               rect->set_property ("x2", xend);
+                                               rect->property_x2() = xend;
                                        }
                                }
 
@@ -883,7 +909,7 @@ StreamView::update_rec_regions ()
                                                }
                                                
                                                /* also hide rect */
-                                               Gnome::Canvas::Item * rect = rec_rects[n].rectangle;
+                                               ArdourCanvas::Item * rect = rec_rects[n].rectangle;
                                                rect->hide();
 
                                        }
@@ -928,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;
+       }
+}