diff options
author | nick_m <mainsbridge@gmail.com> | 2015-10-30 21:14:16 +1100 |
---|---|---|
committer | nick_m <mainsbridge@gmail.com> | 2015-10-30 21:14:16 +1100 |
commit | 5e7c7e52bd482dbdf8629b284781543975672766 (patch) | |
tree | d4e19484417b2525cfcbc25ca4101711d5a8240b /gtk2_ardour/audio_region_view.cc | |
parent | 6d98ccf9014ff287827b12e8f845cd0aea2f8837 (diff) |
Use automation line's frame of reference for y position.
- removes the need for 'pixel hunting' wrt NAME_HIGHLIGHT_SIZE.
- new control points generated by clicking on a line are placed
where the verbose canvas cursor says they are.
Diffstat (limited to 'gtk2_ardour/audio_region_view.cc')
-rw-r--r-- | gtk2_ardour/audio_region_view.cc | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/gtk2_ardour/audio_region_view.cc b/gtk2_ardour/audio_region_view.cc index d3a82dba12..148f99f4c9 100644 --- a/gtk2_ardour/audio_region_view.cc +++ b/gtk2_ardour/audio_region_view.cc @@ -1309,18 +1309,32 @@ AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev, b return; } - double x, y; + uint32_t before_p, after_p; + double mx = ev->button.x; + double my = ev->button.y; + + item->canvas_to_item (mx, my); + + framecnt_t const frame_within_region = (framecnt_t) floor (mx * samples_per_pixel); + + if (!gain_line->control_points_adjacent (frame_within_region, before_p, after_p)) { + /* no adjacent points */ + return; + } + + /*y is in item frame */ + double const bx = gain_line->nth (before_p)->get_x(); + double const ax = gain_line->nth (after_p)->get_x(); + double const click_ratio = (ax - mx) / (ax - bx); + + double y = ((gain_line->nth (before_p)->get_y() * click_ratio) + (gain_line->nth (after_p)->get_y() * (1 - click_ratio))); /* don't create points that can't be seen */ update_envelope_visibility (); - x = ev->button.x; - y = ev->button.y; - - item->canvas_to_item (x, y); framepos_t rpos = region ()->position (); - framepos_t fx = trackview.editor().pixel_to_sample (x) + rpos; + framepos_t fx = trackview.editor().pixel_to_sample (mx) + rpos; trackview.editor ().snap_to_with_modifier (fx, ev); fx -= rpos; @@ -1330,11 +1344,11 @@ AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev, b /* compute vertical fractional position */ - y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE)); + y = 1.0 - (y / (gain_line->height())); /* map using gain line */ - gain_line->view_to_model_coord (x, y); + gain_line->view_to_model_coord (mx, y); /* XXX STATEFUL: can't convert to stateful diff until we can represent automation data with it. |