From 4ee42dc455ce5015801a5db7a2b86a5a71a8ec25 Mon Sep 17 00:00:00 2001 From: Hans Baier Date: Sat, 5 Apr 2008 09:47:07 +0000 Subject: [PATCH] * Bugfix: resizing beginnings of MIDI regions did not work correctly (it shifted the region content right) * Bugfix: resizing ends of MIDI tracks did not hide noted beyond region boundaries (in the moment only all notes with note_on >= region end are hidden, their note offs still may exceed region boundaries, but so much for now.....) git-svn-id: svn://localhost/ardour2/branches/3.0@3219 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/midi_region_view.cc | 44 ++++++++++++++++----------------- libs/ardour/midi_region.cc | 13 ++++++++-- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 180a0a71fb..18704738e4 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -499,21 +499,11 @@ void MidiRegionView::region_resized (Change what_changed) { RegionView::region_resized(what_changed); - + if (what_changed & ARDOUR::PositionChanged) { - if (_enable_display) redisplay_model(); - - } else if (what_changed & Change (StartChanged)) { - - //cerr << "MIDI RV START CHANGED" << endl; - - } else if (what_changed & Change (LengthChanged)) { - - //cerr << "MIDI RV LENGTH CHANGED" << endl; - - } + } } void @@ -671,25 +661,36 @@ void MidiRegionView::add_note(const boost::shared_ptr note) { assert(note->time() >= 0); - //assert(note->time() < _region->length()); assert(midi_view()->note_mode() == Sustained || midi_view()->note_mode() == Percussive); - + + // dont display notes beyond the region bounds + if( + note->time() - _region->start() >= _region->length() || + note->time() < _region->start() + ) { + return; + } + ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group(); CanvasMidiEvent *event = 0; + const double x = trackview.editor.frame_to_pixel((nframes_t)note->time() - _region->start()); + if (midi_view()->note_mode() == Sustained) { //cerr << "MRV::add_note sustained " << note->note() << " @ " << note->time() // << " .. " << note->end_time() << endl; - + const double y1 = midi_stream_view()->note_to_y(note->note()); - + const double note_endpixel = + trackview.editor.frame_to_pixel((nframes_t)note->end_time() - _region->start()); + CanvasNote* ev_rect = new CanvasNote(*this, *group, note); - ev_rect->property_x1() = trackview.editor.frame_to_pixel((nframes_t)note->time()); + ev_rect->property_x1() = x; ev_rect->property_y1() = y1; if (note->duration() > 0) - ev_rect->property_x2() = trackview.editor.frame_to_pixel((nframes_t)(note->end_time())); + ev_rect->property_x2() = note_endpixel; else ev_rect->property_x2() = trackview.editor.frame_to_pixel(_region->length()); ev_rect->property_y2() = y1 + floor(midi_stream_view()->note_height()); @@ -724,7 +725,6 @@ MidiRegionView::add_note(const boost::shared_ptr note) // << " .. " << note->end_time() << endl; const double diamond_size = midi_stream_view()->note_height() / 2.0; - const double x = trackview.editor.frame_to_pixel((nframes_t)note->time()); const double y = midi_stream_view()->note_to_y(note->note()) + ((diamond_size-2) / 4.0); CanvasHit* ev_diamond = new CanvasHit(*this, *group, diamond_size); @@ -740,12 +740,12 @@ MidiRegionView::add_note(const boost::shared_ptr note) if(event) { Note *note = event->note().get(); - + if(_marked_for_selection.find(note) != _marked_for_selection.end()) { - note_selected(event, true); + note_selected(event, true); + } } } -} void MidiRegionView::delete_selection() diff --git a/libs/ardour/midi_region.cc b/libs/ardour/midi_region.cc index ababd41a8d..26eb0e5054 100644 --- a/libs/ardour/midi_region.cc +++ b/libs/ardour/midi_region.cc @@ -131,7 +131,7 @@ MidiRegion::master_read_at (MidiRingBuffer& out, nframes_t position, nframes_t d nframes_t MidiRegion::_read_at (const SourceList& srcs, MidiRingBuffer& dst, nframes_t position, nframes_t dur, uint32_t chan_n, NoteMode mode) const { - // cerr << _name << "._read_at(" << position << ") - " << _position << endl; + //cerr << _name << "._read_at(" << position << ") - " << _position << " duration: " << dur << endl; nframes_t internal_offset = 0; nframes_t src_offset = 0; @@ -171,7 +171,16 @@ MidiRegion::_read_at (const SourceList& srcs, MidiRingBuffer& dst, nframes_t pos boost::shared_ptr src = midi_source(chan_n); src->set_note_mode(mode); - if (src->midi_read (dst, _start + internal_offset, to_read, _position) != to_read) { + if (src->midi_read ( + // the destination buffer + dst, + // where to start reading in the region + _start + internal_offset, + // how many bytes + to_read, + // the offset in the output buffer + _position - _start + ) != to_read) { return 0; /* "read nothing" */ }