mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-12 17:46:34 +01:00
Fix note dragging.
git-svn-id: svn://localhost/ardour2/branches/3.0@5049 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
6c93b8c44f
commit
006d3a9f46
2 changed files with 20 additions and 25 deletions
|
|
@ -419,12 +419,12 @@ MidiRegionView::create_note_at(double x, double y, double length)
|
||||||
assert(note <= 127.0);
|
assert(note <= 127.0);
|
||||||
|
|
||||||
// Start of note in frames relative to region start
|
// Start of note in frames relative to region start
|
||||||
nframes64_t start_frames = snap_to_frame(trackview.editor().pixel_to_frame(x));
|
nframes64_t start_frames = snap_frame_to_frame(trackview.editor().pixel_to_frame(x));
|
||||||
assert(start_frames >= 0);
|
assert(start_frames >= 0);
|
||||||
|
|
||||||
// Snap length
|
// Snap length
|
||||||
length = frames_to_beats(
|
length = frames_to_beats(
|
||||||
snap_to_frame(start_frames + beats_to_frames(length)) - start_frames);
|
snap_frame_to_frame(start_frames + beats_to_frames(length)) - start_frames);
|
||||||
|
|
||||||
const boost::shared_ptr<NoteType> new_note(new NoteType(0,
|
const boost::shared_ptr<NoteType> new_note(new NoteType(0,
|
||||||
frames_to_beats(start_frames + _region->start()), length,
|
frames_to_beats(start_frames + _region->start()), length,
|
||||||
|
|
@ -1319,12 +1319,11 @@ MidiRegionView::note_dropped(CanvasNoteEvent* ev, double dt, uint8_t dnote)
|
||||||
|
|
||||||
const boost::shared_ptr<NoteType> copy(new NoteType(*(*i)->note().get()));
|
const boost::shared_ptr<NoteType> copy(new NoteType(*(*i)->note().get()));
|
||||||
|
|
||||||
// we need to snap here again in nframes64_t in order to be sample accurate
|
nframes64_t start_frames = beats_to_frames((*i)->note()->time());
|
||||||
double start_frames = snap_to_frame(beats_to_frames((*i)->note()->time()) + dt);
|
if (dt >= 0) {
|
||||||
|
start_frames += snap_frame_to_frame(trackview.editor().pixel_to_frame(dt));
|
||||||
// keep notes inside region if dragged beyond left region bound
|
} else {
|
||||||
if (start_frames < _region->start()) {
|
start_frames -= snap_frame_to_frame(trackview.editor().pixel_to_frame(-dt));
|
||||||
start_frames = _region->start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
copy->set_time(frames_to_beats(start_frames));
|
copy->set_time(frames_to_beats(start_frames));
|
||||||
|
|
@ -1362,7 +1361,7 @@ MidiRegionView::note_dropped(CanvasNoteEvent* ev, double dt, uint8_t dnote)
|
||||||
}
|
}
|
||||||
|
|
||||||
nframes64_t
|
nframes64_t
|
||||||
MidiRegionView::snap_to_frame(double x)
|
MidiRegionView::snap_pixel_to_frame(double x)
|
||||||
{
|
{
|
||||||
PublicEditor& editor = trackview.editor();
|
PublicEditor& editor = trackview.editor();
|
||||||
// x is region relative, convert it to global absolute frames
|
// x is region relative, convert it to global absolute frames
|
||||||
|
|
@ -1372,22 +1371,19 @@ MidiRegionView::snap_to_frame(double x)
|
||||||
}
|
}
|
||||||
|
|
||||||
nframes64_t
|
nframes64_t
|
||||||
MidiRegionView::snap_to_frame(nframes64_t x)
|
MidiRegionView::snap_frame_to_frame(nframes64_t x)
|
||||||
{
|
{
|
||||||
PublicEditor& editor = trackview.editor();
|
PublicEditor& editor = trackview.editor();
|
||||||
// x is region relative
|
// x is region relative, convert it to global absolute frames
|
||||||
// convert x to global frame
|
|
||||||
nframes64_t frame = x + _region->position();
|
nframes64_t frame = x + _region->position();
|
||||||
editor.snap_to(frame);
|
editor.snap_to(frame);
|
||||||
// convert event_frame back to local coordinates relative to position
|
return frame - _region->position(); // convert back to region relative
|
||||||
frame -= _region->position();
|
|
||||||
return frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
MidiRegionView::snap_to_pixel(double x)
|
MidiRegionView::snap_to_pixel(double x)
|
||||||
{
|
{
|
||||||
return (double) trackview.editor().frame_to_pixel(snap_to_frame(x));
|
return (double) trackview.editor().frame_to_pixel(snap_pixel_to_frame(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
|
|
@ -1502,7 +1498,7 @@ MidiRegionView::commit_resizing(CanvasNote::NoteEnd note_end, double event_x, bo
|
||||||
|
|
||||||
// because snapping works on world coordinates we have to transform current_x
|
// because snapping works on world coordinates we have to transform current_x
|
||||||
// to world coordinates before snapping and transform it back afterwards
|
// to world coordinates before snapping and transform it back afterwards
|
||||||
nframes64_t current_frame = snap_to_frame(current_x);
|
nframes64_t current_frame = snap_pixel_to_frame(current_x);
|
||||||
// transform to region start relative
|
// transform to region start relative
|
||||||
current_frame += _region->start();
|
current_frame += _region->start();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ class MidiRegionView : public RegionView
|
||||||
size_t selection_size() { return _selection.size(); }
|
size_t selection_size() { return _selection.size(); }
|
||||||
|
|
||||||
void move_selection(double dx, double dy);
|
void move_selection(double dx, double dy);
|
||||||
void note_dropped(ArdourCanvas::CanvasNoteEvent* ev, double d_frames, uint8_t d_note);
|
void note_dropped(ArdourCanvas::CanvasNoteEvent* ev, double d_pixels, uint8_t d_note);
|
||||||
|
|
||||||
/** Return true iff the note is within the currently visible range */
|
/** Return true iff the note is within the currently visible range */
|
||||||
bool note_in_visible_range(const boost::shared_ptr<NoteType> note) const;
|
bool note_in_visible_range(const boost::shared_ptr<NoteType> note) const;
|
||||||
|
|
@ -230,7 +230,6 @@ class MidiRegionView : public RegionView
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Snap a region relative pixel coordinate to pixel units.
|
/** Snap a region relative pixel coordinate to pixel units.
|
||||||
* for pixel units (double) instead of nframes64_t
|
|
||||||
* @param x a pixel coordinate relative to region start
|
* @param x a pixel coordinate relative to region start
|
||||||
* @return the snapped pixel coordinate relative to region start
|
* @return the snapped pixel coordinate relative to region start
|
||||||
*/
|
*/
|
||||||
|
|
@ -240,13 +239,13 @@ class MidiRegionView : public RegionView
|
||||||
* @param x a pixel coordinate relative to region start
|
* @param x a pixel coordinate relative to region start
|
||||||
* @return the snapped nframes64_t coordinate relative to region start
|
* @return the snapped nframes64_t coordinate relative to region start
|
||||||
*/
|
*/
|
||||||
nframes64_t snap_to_frame(double x);
|
nframes64_t snap_pixel_to_frame(double x);
|
||||||
|
|
||||||
/** Snap a region relative frame coordinate to frame units.
|
/** Snap a region relative frame coordinate to frame units.
|
||||||
* @param x a pixel coordinate relative to region start
|
* @param x a pixel coordinate relative to region start
|
||||||
* @return the snapped nframes64_t coordinate relative to region start
|
* @return the snapped nframes64_t coordinate relative to region start
|
||||||
*/
|
*/
|
||||||
nframes64_t snap_to_frame(nframes64_t x);
|
nframes64_t snap_frame_to_frame(nframes64_t x);
|
||||||
|
|
||||||
/** Convert a timestamp in beats to frames (both relative to region start) */
|
/** Convert a timestamp in beats to frames (both relative to region start) */
|
||||||
nframes64_t beats_to_frames(double beats) const;
|
nframes64_t beats_to_frames(double beats) const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue