Flesh out RDFF documentation.
[ardour.git] / gtk2_ardour / midi_streamview.cc
index ef625f0a1c277065be0769bda4da6bfe6b07e2ff..b79a6dc6d0a61940f533bb5b80b8df69f959592f 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "ardour_ui.h"
 #include "canvas-simplerect.h"
+#include "global_signals.h"
 #include "gui_thread.h"
 #include "lineset.h"
 #include "midi_region_view.h"
@@ -171,6 +172,12 @@ MidiStreamView::add_region_view_internal (boost::shared_ptr<Region> r, bool wfd,
 
        region_views.push_front (region_view);
 
+        if (_trackview.editor().internal_editing()) {
+                region_view->hide_rect ();
+        } else {
+                region_view->show_rect ();
+        }
+
        /* display events and find note range */
        display_region (region_view, wfd);
 
@@ -185,8 +192,9 @@ MidiStreamView::add_region_view_internal (boost::shared_ptr<Region> r, bool wfd,
 void
 MidiStreamView::display_region(MidiRegionView* region_view, bool load_model)
 {
-       if ( ! region_view)
+       if (!region_view) {
                return;
+        }
 
        region_view->enable_display(true);
 
@@ -201,7 +209,7 @@ MidiStreamView::display_region(MidiRegionView* region_view, bool load_model)
                        source->model()->highest_note());
 
        // Display region contents
-       region_view->set_height(height);
+       region_view->set_height (child_height());
        region_view->display_model(source->model());
 }
 
@@ -294,7 +302,7 @@ void
 MidiStreamView::update_contents_height ()
 {
        StreamView::update_contents_height();
-       _note_lines->property_y2() = height;
+       _note_lines->property_y2() = child_height ();
 
         apply_note_range (lowest_note(), highest_note(), true);
 }
@@ -312,7 +320,7 @@ MidiStreamView::draw_note_lines()
 
        _note_lines->clear();
        
-       if(height < 140){
+       if (child_height() < 140){
                return;
        }
 
@@ -364,13 +372,13 @@ MidiStreamView::apply_note_range(uint8_t lowest, uint8_t highest, bool to_region
        _highest_note = highest;
        _lowest_note = lowest;
        
-       int range = _highest_note - _lowest_note;  
-       int pixels_per_note = floor (height/range);
+       int const range = _highest_note - _lowest_note;  
+       int const pixels_per_note = floor (child_height () / range);
        
        /* do not grow note height beyond 10 pixels */
        if (pixels_per_note > 10) {
                
-               int available_note_range = floor ((height)/10);
+               int const available_note_range = floor (child_height() / 10);
                int additional_notes = available_note_range - range;
                
                /* distribute additional notes to higher and lower ranges, clamp at 0 and 127 */
@@ -436,7 +444,7 @@ MidiStreamView::setup_rec_box ()
 
                                // handle multi
 
-                               nframes_t start = 0;
+                               framepos_t start = 0;
                                if (rec_regions.size() > 0) {
                                        start = rec_regions.back().first->start()
                                                        + _trackview.track()->get_captured_frames(rec_regions.size()-1);
@@ -451,6 +459,19 @@ MidiStreamView::setup_rec_box ()
                                
                                plist.add (ARDOUR::Properties::start, start);
                                plist.add (ARDOUR::Properties::length, 1);
+                               /* Just above we're setting this nascent region's length to 1.  I think this
+                                  is so that the RegionView gets created with a non-zero width, as apparently
+                                  creating a RegionView with a zero width causes it never to be displayed
+                                  (there is a warning in TimeAxisViewItem::init about this).  However, we
+                                  must also set length_beats to something non-zero, otherwise the frame length
+                                  of 1 causes length_beats to be set to some small quantity << 1.  Then
+                                  when the position is set up below, this length_beats is used to recompute
+                                  length using BeatsFramesConverter::to, which is slightly innacurate for small
+                                  beats values because it converts floating point beats to bars, beats and
+                                  integer ticks.  The upshot of which being that length gets set back to 0,
+                                  meaning no region view is ever seen, meaning no MIDI notes during record (#3820).
+                               */
+                               plist.add (ARDOUR::Properties::length_beats, 1);
                                plist.add (ARDOUR::Properties::name, string());
                                plist.add (ARDOUR::Properties::layer, 0);
 
@@ -469,6 +490,8 @@ MidiStreamView::setup_rec_box ()
                                // rec regions are destroyed in setup_rec_box
 
                                /* we add the region later */
+
+                               setup_new_rec_layer_time (region);
                        }
 
                        /* start a new rec box */
@@ -611,3 +634,18 @@ MidiStreamView::update_rec_box ()
        MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (rec_regions.back().second);
        mrv->extend_active_notes ();
 }
+
+uint8_t
+MidiStreamView::y_to_note (double y) const
+{
+       int const n = ((contents_height() - y - 1) / contents_height() * (double)contents_note_range())
+               + lowest_note();
+
+       if (n < 0) {
+               return 0;
+       } else if (n > 127) {
+               return 127;
+       }
+       
+       return n;
+}