next 2 modifiers
[ardour.git] / gtk2_ardour / midi_streamview.cc
index a1e1269468ada724f5c7b2829b42bcc66293ac67..e91a1c683dc0ff7545bc41705abbd982894656e7 100644 (file)
@@ -52,6 +52,7 @@
 
 using namespace std;
 using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
 using namespace PBD;
 using namespace Editing;
 
@@ -68,14 +69,14 @@ MidiStreamView::MidiStreamView (MidiTimeAxisView& tv)
        , _updates_suspended (false)
 {
        /* use a group dedicated to MIDI underlays. Audio underlays are not in this group. */
-       midi_underlay_group = new ArdourCanvas::Group (_canvas_group);
+       midi_underlay_group = new ArdourCanvas::Container (_canvas_group);
        midi_underlay_group->lower_to_bottom();
 
        /* put the note lines in the timeaxisview's group, so it
           can be put below ghost regions from MIDI underlays
        */
-       _note_lines = new ArdourCanvas::LineSet (_canvas_group);
-
+       _note_lines = new ArdourCanvas::LineSet (_canvas_group, ArdourCanvas::LineSet::Horizontal);
+       
        _note_lines->Event.connect(
                sigc::bind(sigc::mem_fun(_trackview.editor(),
                                         &PublicEditor::canvas_stream_view_event),
@@ -110,7 +111,7 @@ MidiStreamView::create_region_view (boost::shared_ptr<Region> r, bool /*wfd*/, b
        RegionView* region_view = new MidiRegionView (_canvas_group, _trackview, region,
                                                      _samples_per_pixel, region_color);
 
-       region_view->init (region_color, false);
+       region_view->init (false);
 
        return region_view;
 }
@@ -175,19 +176,28 @@ MidiStreamView::display_region(MidiRegionView* region_view, bool load_model)
        }
 
        region_view->enable_display (true);
+       region_view->set_height (child_height());
 
        boost::shared_ptr<MidiSource> source(region_view->midi_region()->midi_source(0));
+       if (!source) {
+               error << _("attempt to display MIDI region with no source") << endmsg;
+               return;
+       }
 
        if (load_model) {
                source->load_model();
        }
 
+       if (!source->model()) {
+               error << _("attempt to display MIDI region with no model") << endmsg;
+               return;
+       }
+
        _range_dirty = update_data_note_range(
                source->model()->lowest_note(),
                source->model()->highest_note());
 
        // Display region contents
-       region_view->set_height (child_height());
        region_view->display_model(source->model());
 }
 
@@ -273,7 +283,8 @@ void
 MidiStreamView::update_contents_height ()
 {
        StreamView::update_contents_height();
-       _note_lines->set_height (child_height ());
+
+       _note_lines->set_extent (ArdourCanvas::COORD_MAX);
 
        apply_note_range (lowest_note(), highest_note(), true);
 }
@@ -286,7 +297,7 @@ MidiStreamView::draw_note_lines()
        }
 
        double y;
-       double prev_y = 0;
+       double prev_y = .5;
        uint32_t color;
 
        _note_lines->clear();
@@ -300,15 +311,17 @@ MidiStreamView::draw_note_lines()
         * coordinate system in which y=0 is at the top
         */
 
-       for (int i = highest_note(); i >= lowest_note(); --i) {
+       for (int i = highest_note() + 1; i >= lowest_note(); --i) {
 
-               y = note_to_y (i);
+               y = floor(note_to_y (i)) + .5;
 
                /* this is the line actually corresponding to the division
                 * between notes
                 */
 
-               _note_lines->add (y, 1.0, ARDOUR_UI::config()->get_canvasvar_PianoRollBlackOutline());
+               if (i <= highest_note()) {
+                       _note_lines->add (y, 1.0, ARDOUR_UI::config()->color ("piano roll black outline"));
+               }
 
                /* now add a thicker line/bar which covers the entire vertical
                 * height of this note.
@@ -320,17 +333,17 @@ MidiStreamView::draw_note_lines()
                case 6:
                case 8:
                case 10:
-                       color = ARDOUR_UI::config()->get_canvasvar_PianoRollBlack();
+                       color = ARDOUR_UI::config()->color_mod ("piano roll black", "piano roll black");
                        break;
                default:
-                       color = ARDOUR_UI::config()->get_canvasvar_PianoRollWhite();
+                       color = ARDOUR_UI::config()->color_mod ("piano roll white", "piano roll white");
                        break;
                }
 
                double h = y - prev_y;
                double mid = y + (h/2.0);
                                
-               if (height > 1.0) {
+               if (height > 1.0) { // XXX ? should that not be h >= 1 ?
                        _note_lines->add (mid, h, color);
                }
 
@@ -498,11 +511,11 @@ MidiStreamView::setup_rec_box ()
                        gdouble const xend = xstart;
                        uint32_t fill_color;
 
-                       fill_color = ARDOUR_UI::config()->get_canvasvar_RecordingRect();
+                       fill_color = ARDOUR_UI::config()->color ("recording rect");
 
                        ArdourCanvas::Rectangle * rec_rect = new ArdourCanvas::Rectangle (_canvas_group);
                        rec_rect->set (ArdourCanvas::Rect (xstart, 1, xend, _trackview.current_height() - 1));
-                       rec_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_RecordingRect());
+                       rec_rect->set_outline_color (ARDOUR_UI::config()->color ("recording rect"));
                        rec_rect->set_fill_color (fill_color);
                        rec_rect->lower_to_bottom();
 
@@ -575,9 +588,9 @@ MidiStreamView::color_handler ()
        draw_note_lines ();
 
        if (_trackview.is_midi_track()) {
-               canvas_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_MidiTrackBase());
+               canvas_rect->set_fill_color (ARDOUR_UI::config()->color_mod ("midi track base", "midi track base"));
        } else {
-               canvas_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_MidiBusBase());
+               canvas_rect->set_fill_color (ARDOUR_UI::config()->color ("midi bus base"));
        }
 }