Fix install path problems (s/ardour2/ardour3).
[ardour.git] / gtk2_ardour / midi_region_view.cc
index a16da1448fd71c14b82ae0d8b6bce5043f7faafe..0ac2dfc43afe5b7cc430e39be33e09318bd2816f 100644 (file)
@@ -152,6 +152,7 @@ MidiRegionView::canvas_event(GdkEvent* ev)
        
        switch (ev->type) {
        case GDK_KEY_PRESS:
+               cout << "KEY" << endl;
                if (ev->key.keyval == GDK_Delete && !delete_mod) {
                        delete_mod = true;
                        original_mode = trackview.editor.current_midi_edit_mode();
@@ -362,7 +363,7 @@ MidiRegionView::create_note_at(double x, double y, double dur)
        //double dur = m.frames_per_bar(t, trackview.session().frame_rate()) / m.beats_per_bar();
 
        // Add a 1 beat long note (for now)
-       const boost::shared_ptr<Note> new_note(new Note(stamp, dur, (uint8_t)note, 0x40));
+       const boost::shared_ptr<Note> new_note(new Note(0, stamp, dur, (uint8_t)note, 0x40));
        
        view->update_bounds(new_note->note());
 
@@ -380,6 +381,14 @@ MidiRegionView::clear_events()
        for (std::vector<CanvasMidiEvent*>::iterator i = _events.begin(); i != _events.end(); ++i)
                delete *i;
        
+       MidiGhostRegion* gr;
+
+       for(vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
+               if((gr = dynamic_cast<MidiGhostRegion*>(*g)) != 0) {
+                       gr->clear_events();
+               }
+       }
+
        _events.clear();
 }
 
@@ -505,11 +514,23 @@ MidiRegionView::set_y_position_and_height (double y, double h)
                for (std::vector<CanvasMidiEvent*>::const_iterator i = _events.begin(); i != _events.end(); ++i) {
                        CanvasNote* note = dynamic_cast<CanvasNote*>(*i);
                        if (note && note->note()) {
-                               const double y1 = midi_stream_view()->note_to_y(note->note()->note());
-                               const double y2 = y1 + floor(midi_stream_view()->note_height());
-
-                               note->property_y1() = y1;
-                               note->property_y2() = y2;
+                               if(note->note()->note() < midi_stream_view()->lowest_note() ||
+                                  note->note()->note() > midi_stream_view()->highest_note()) {
+                                       if(canvas_item_visible(note)) {
+                                               note->hide();
+                                       }
+                               }
+                               else {
+                                       const double y1 = midi_stream_view()->note_to_y(note->note()->note());
+                                       const double y2 = y1 + floor(midi_stream_view()->note_height());
+                                       
+                                       if(!canvas_item_visible(note)) {
+                                               note->show();
+                                       }
+
+                                       note->property_y1() = y1;
+                                       note->property_y2() = y2;
+                               }
                        }
                }
                
@@ -522,18 +543,37 @@ MidiRegionView::set_y_position_and_height (double y, double h)
 }
 
 GhostRegion*
-MidiRegionView::add_ghost (AutomationTimeAxisView& atv)
+MidiRegionView::add_ghost (TimeAxisView& tv)
 {
        RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
+       CanvasNote* note;
        assert(rtv);
 
        double unit_position = _region->position () / samples_per_unit;
-       GhostRegion* ghost = new GhostRegion (atv, unit_position);
+       MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*>(&tv);
+       MidiGhostRegion* ghost;
+
+       if(mtv && mtv->midi_view()) {
+               /* if ghost is inserted into midi track, use a dedicated midi ghost canvas group.
+                  this is because it's nice to have midi notes on top of the note lines and
+                  audio waveforms under it.
+                */
+               ghost = new MidiGhostRegion (*mtv->midi_view(), trackview, unit_position);
+       }
+       else {
+               ghost = new MidiGhostRegion (tv, trackview, unit_position);
+       }
 
        ghost->set_height ();
        ghost->set_duration (_region->length() / samples_per_unit);
        ghosts.push_back (ghost);
 
+       for (std::vector<CanvasMidiEvent*>::iterator i = _events.begin(); i != _events.end(); ++i) {
+               if((note = dynamic_cast<CanvasNote*>(*i)) != 0) {
+                       ghost->add_note(note);
+               }
+       }
+
        ghost->GoingAway.connect (mem_fun(*this, &MidiRegionView::remove_ghost));
 
        return ghost;
@@ -638,6 +678,14 @@ MidiRegionView::add_note(const boost::shared_ptr<Note> note)
                ev_rect->show();
                _events.push_back(ev_rect);
 
+               MidiGhostRegion* gr;
+               
+               for(vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
+                       if((gr = dynamic_cast<MidiGhostRegion*>(*g)) != 0) {
+                               gr->add_note(ev_rect);
+                       }
+               }
+
        } else if (midi_view()->note_mode() == Percussive) {
                
                //cerr << "MRV::add_note percussive " << note->note() << " @ " << note->time()