+/** Add a MIDI note (with duration).
+ *
+ * This does no 'realtime' note resolution, notes from a MidiModel have a
+ * duration so they can be drawn in full immediately.
+ */
+void
+MidiRegionView::add_note (const MidiModel::Note& note)
+{
+ assert(note.start >= 0);
+ assert(note.start < _region->length());
+ //assert(note.start + note.duration < _region->length());
+
+ /*printf("Event, time = %f, size = %zu, data = ", ev.time, ev.size);
+ for (size_t i=0; i < ev.size; ++i) {
+ printf("%X ", ev.buffer[i]);
+ }
+ printf("\n\n");*/
+
+ MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(&trackview);
+ MidiStreamView* const view = mtv->midi_view();
+ ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group();
+
+ const uint8_t note_range = view->highest_note() - view->lowest_note() + 1;
+ const double footer_height = name_highlight->property_y2() - name_highlight->property_y1();
+ const double pixel_range = (trackview.height - footer_height - 5.0) / (double)note_range;
+
+ if (mtv->note_mode() == Note) {
+ const double y1 = trackview.height - (pixel_range * (note.note - view->lowest_note() + 1))
+ - footer_height - 3.0;
+
+ ArdourCanvas::SimpleRect * ev_rect = new Gnome::Canvas::SimpleRect(*group);
+ ev_rect->property_x1() = trackview.editor.frame_to_pixel((nframes_t)note.start);
+ ev_rect->property_y1() = y1;
+ ev_rect->property_x2() = trackview.editor.frame_to_pixel((nframes_t)(note.start + note.duration));
+ ev_rect->property_y2() = y1 + ceil(pixel_range);
+
+ ev_rect->property_fill_color_rgba() = 0xFFFFFF66;
+ ev_rect->property_outline_color_rgba() = 0xFFFFFFAA;
+ ev_rect->property_outline_what() = (guint32) 0xF; // all edges
+
+ ev_rect->show();
+ _events.push_back(ev_rect);
+
+ } else if (mtv->note_mode() == Percussion) {
+ const double x = trackview.editor.frame_to_pixel((nframes_t)note.start);
+ const double y = trackview.height - (pixel_range * (note.note - view->lowest_note() + 1))
+ - footer_height - 3.0;
+
+ Diamond* ev_diamond = new Diamond(*group, std::min(pixel_range, 5.0));
+ ev_diamond->move(x, y);
+ ev_diamond->show();
+ ev_diamond->property_outline_color_rgba() = 0xFFFFFFDD;
+ ev_diamond->property_fill_color_rgba() = 0xFFFFFF66;
+ _events.push_back(ev_diamond);
+ }
+}
+