remove all unit-based methods from (Public)Editor; rationalize Editor::event_frame() to clearly identify whether the passed-in GdkEvent has window units or canvas units (the latter will be true for all events that are handled by the canvas and then passed to Editor

This commit is contained in:
Paul Davis 2013-04-12 11:09:49 -04:00
parent fcb423f3f6
commit ecfd2a7455
17 changed files with 130 additions and 162 deletions

View file

@ -243,7 +243,7 @@ AutomationLine::modify_point_y (ControlPoint& cp, double y)
y = min (1.0, y); y = min (1.0, y);
y = _height - (y * _height); y = _height - (y * _height);
double const x = trackview.editor().frame_to_unit_unrounded (_time_converter->to((*cp.model())->when) - _offset); double const x = trackview.editor().frame_to_pixel_unrounded (_time_converter->to((*cp.model())->when) - _offset);
trackview.editor().session()->begin_reversible_command (_("automation event move")); trackview.editor().session()->begin_reversible_command (_("automation event move"));
trackview.editor().session()->add_command ( trackview.editor().session()->add_command (
@ -739,10 +739,10 @@ AutomationLine::sync_model_with_view_point (ControlPoint& cp)
/* if xval has not changed, set it directly from the model to avoid rounding errors */ /* if xval has not changed, set it directly from the model to avoid rounding errors */
if (view_x == trackview.editor().frame_to_unit_unrounded (_time_converter->to ((*cp.model())->when)) - _offset) { if (view_x == trackview.editor().frame_to_pixel_unrounded (_time_converter->to ((*cp.model())->when)) - _offset) {
view_x = (*cp.model())->when - _offset; view_x = (*cp.model())->when - _offset;
} else { } else {
view_x = trackview.editor().unit_to_frame (view_x); view_x = trackview.editor().pixel_to_frame (view_x);
view_x = _time_converter->from (view_x + _offset); view_x = _time_converter->from (view_x + _offset);
} }
@ -760,7 +760,7 @@ AutomationLine::control_points_adjacent (double xval, uint32_t & before, uint32_
ControlPoint *acp = 0; ControlPoint *acp = 0;
double unit_xval; double unit_xval;
unit_xval = trackview.editor().frame_to_unit_unrounded (xval); unit_xval = trackview.editor().frame_to_pixel_unrounded (xval);
for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) { for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
@ -947,7 +947,7 @@ AutomationLine::reset_callback (const Evoral::ControlList& events)
* zoom and scroll into account). * zoom and scroll into account).
*/ */
tx = trackview.editor().frame_to_unit_unrounded (tx); tx = trackview.editor().frame_to_pixel_unrounded (tx);
/* convert from canonical view height (0..1.0) to actual /* convert from canonical view height (0..1.0) to actual
* height coordinates (using X11's top-left rooted system) * height coordinates (using X11's top-left rooted system)

View file

@ -2833,12 +2833,12 @@ Editor::snap_to_internal (framepos_t& start, int32_t direction, bool for_mark)
case SnapMagnetic: case SnapMagnetic:
if (presnap > start) { if (presnap > start) {
if (presnap > (start + unit_to_frame(snap_threshold))) { if (presnap > (start + pixel_to_frame(snap_threshold))) {
start = presnap; start = presnap;
} }
} else if (presnap < start) { } else if (presnap < start) {
if (presnap < (start - unit_to_frame(snap_threshold))) { if (presnap < (start - pixel_to_frame(snap_threshold))) {
start = presnap; start = presnap;
} }
} }
@ -4400,7 +4400,7 @@ Editor::get_preferred_edit_position (bool ignore_playhead, bool from_context_men
EditPoint ep = _edit_point; EditPoint ep = _edit_point;
if (from_context_menu && (ep == EditAtMouse)) { if (from_context_menu && (ep == EditAtMouse)) {
return event_frame (&context_click_event, 0, 0); return window_event_frame (&context_click_event, 0, 0);
} }
if (entered_marker) { if (entered_marker) {

View file

@ -220,24 +220,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
void separate_regions_using_location (ARDOUR::Location&); void separate_regions_using_location (ARDOUR::Location&);
void transition_to_rolling (bool forward); void transition_to_rolling (bool forward);
/* undo related */
framepos_t unit_to_frame (double unit) const {
return (framepos_t) rint (unit * frames_per_pixel);
}
double frame_to_unit (framepos_t frame) const {
return rint ((double) frame / (double) frames_per_pixel);
}
double frame_to_unit_unrounded (framepos_t frame) const {
return frame / frames_per_pixel;
}
double frame_to_unit (double frame) const {
return rint (frame / frames_per_pixel);
}
/* NOTE: these functions assume that the "pixel" coordinate is /* NOTE: these functions assume that the "pixel" coordinate is
the result of using the world->canvas affine transform on a the result of using the world->canvas affine transform on a
world coordinate. These coordinates already take into world coordinate. These coordinates already take into
@ -260,8 +242,12 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
} }
} }
gulong frame_to_pixel (framepos_t frame) const { double frame_to_pixel (framepos_t frame) const {
return (gulong) rint (frame / frames_per_pixel); return rint (frame / frames_per_pixel);
}
double frame_to_pixel_unrounded (framepos_t frame) const {
return frame / frames_per_pixel;
} }
void flush_canvas (); void flush_canvas ();
@ -1885,7 +1871,15 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
void duplicate_range (bool with_dialog); void duplicate_range (bool with_dialog);
framepos_t event_frame (GdkEvent const *, double* px = 0, double* py = 0) const; /** computes the timeline frame (sample) of an event whose coordinates
* are in canvas units (pixels, scroll offset included).
*/
framepos_t canvas_event_frame (GdkEvent const *, double* px = 0, double* py = 0) const;
/** computes the timeline frame (sample) of an event whose coordinates
* are in window units (pixels, no scroll offset).
*/
framepos_t window_event_frame (GdkEvent const *, double* px = 0, double* py = 0) const;
/* returns false if mouse pointer is not in track or marker canvas /* returns false if mouse pointer is not in track or marker canvas
*/ */

View file

@ -422,8 +422,6 @@ Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
vector<string> paths; vector<string> paths;
GdkEvent ev; GdkEvent ev;
framepos_t frame; framepos_t frame;
double wx;
double wy;
double cy; double cy;
if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) { if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
@ -431,13 +429,11 @@ Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
/* D-n-D coordinates are window-relative, so convert to "world" coordinates /* D-n-D coordinates are window-relative, so convert to "world" coordinates
*/ */
_track_canvas_viewport->window_to_canvas (x, y, wx, wy);
ev.type = GDK_BUTTON_RELEASE; ev.type = GDK_BUTTON_RELEASE;
ev.button.x = wx; ev.button.x = x;
ev.button.y = wy; ev.button.y = y;
frame = event_frame (&ev, 0, &cy); frame = window_event_frame (&ev, 0, &cy);
snap_to (frame); snap_to (frame);
@ -916,7 +912,7 @@ Editor::update_canvas_now ()
double double
Editor::horizontal_position () const Editor::horizontal_position () const
{ {
return frame_to_unit (leftmost_frame); return frame_to_pixel (leftmost_frame);
} }
void void

View file

@ -1003,8 +1003,6 @@ Editor::canvas_note_event (GdkEvent *event, ArdourCanvas::Item* item)
bool bool
Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const& context, int x, int y, guint time) Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const& context, int x, int y, guint time)
{ {
ArdourCanvas::Coord wx;
ArdourCanvas::Coord wy;
boost::shared_ptr<Region> region; boost::shared_ptr<Region> region;
boost::shared_ptr<Region> region_copy; boost::shared_ptr<Region> region_copy;
RouteTimeAxisView* rtav; RouteTimeAxisView* rtav;
@ -1018,15 +1016,13 @@ Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const& context,
return false; return false;
} }
_track_canvas_viewport->window_to_canvas (x, y, wx, wy);
event.type = GDK_MOTION_NOTIFY; event.type = GDK_MOTION_NOTIFY;
event.button.x = wx; event.button.x = x;
event.button.y = wy; event.button.y = y;
/* assume we're dragging with button 1 */ /* assume we're dragging with button 1 */
event.motion.state = Gdk::BUTTON1_MASK; event.motion.state = Gdk::BUTTON1_MASK;
(void) event_frame (&event, &px, &py); (void) window_event_frame (&event, &px, &py);
std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (py); std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (py);
bool can_drop = false; bool can_drop = false;
@ -1096,8 +1092,6 @@ Editor::drop_regions (const Glib::RefPtr<Gdk::DragContext>& /*context*/,
const SelectionData& /*data*/, const SelectionData& /*data*/,
guint /*info*/, guint /*time*/) guint /*info*/, guint /*time*/)
{ {
double wx;
double wy;
boost::shared_ptr<Region> region; boost::shared_ptr<Region> region;
boost::shared_ptr<Region> region_copy; boost::shared_ptr<Region> region_copy;
RouteTimeAxisView* rtav; RouteTimeAxisView* rtav;
@ -1105,15 +1099,13 @@ Editor::drop_regions (const Glib::RefPtr<Gdk::DragContext>& /*context*/,
double px; double px;
double py; double py;
_track_canvas_viewport->window_to_canvas (x, y, wx, wy);
event.type = GDK_MOTION_NOTIFY; event.type = GDK_MOTION_NOTIFY;
event.button.x = wx; event.button.x = x;
event.button.y = wy; event.button.y = y;
/* assume we're dragging with button 1 */ /* assume we're dragging with button 1 */
event.motion.state = Gdk::BUTTON1_MASK; event.motion.state = Gdk::BUTTON1_MASK;
framepos_t const pos = event_frame (&event, &px, &py); framepos_t const pos = window_event_frame (&event, &px, &py);
std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (py); std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (py);

View file

@ -67,7 +67,7 @@ EditorCursor::set_position (framepos_t frame)
{ {
PositionChanged (frame); PositionChanged (frame);
double const new_pos = _editor.frame_to_unit (frame); double const new_pos = _editor.frame_to_pixel (frame);
if (new_pos != _time_bars_canvas_item.x ()) { if (new_pos != _time_bars_canvas_item.x ()) {
_time_bars_canvas_item.set_x (new_pos); _time_bars_canvas_item.set_x (new_pos);

View file

@ -127,7 +127,7 @@ DragManager::start_grab (GdkEvent* e, Gdk::Cursor* c)
_old_follow_playhead = _editor->follow_playhead (); _old_follow_playhead = _editor->follow_playhead ();
_editor->set_follow_playhead (false); _editor->set_follow_playhead (false);
_current_pointer_frame = _editor->event_frame (e, &_current_pointer_x, &_current_pointer_y); _current_pointer_frame = _editor->canvas_event_frame (e, &_current_pointer_x, &_current_pointer_y);
for (list<Drag*>::const_iterator i = _drags.begin(); i != _drags.end(); ++i) { for (list<Drag*>::const_iterator i = _drags.begin(); i != _drags.end(); ++i) {
(*i)->start_grab (e, c); (*i)->start_grab (e, c);
@ -165,7 +165,7 @@ DragManager::motion_handler (GdkEvent* e, bool from_autoscroll)
{ {
bool r = false; bool r = false;
_current_pointer_frame = _editor->event_frame (e, &_current_pointer_x, &_current_pointer_y); _current_pointer_frame = _editor->canvas_event_frame (e, &_current_pointer_x, &_current_pointer_y);
for (list<Drag*>::iterator i = _drags.begin(); i != _drags.end(); ++i) { for (list<Drag*>::iterator i = _drags.begin(); i != _drags.end(); ++i) {
bool const t = (*i)->motion_handler (e, from_autoscroll); bool const t = (*i)->motion_handler (e, from_autoscroll);
@ -232,7 +232,7 @@ Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
_y_constrained = false; _y_constrained = false;
} }
_raw_grab_frame = _editor->event_frame (event, &_grab_x, &_grab_y); _raw_grab_frame = _editor->canvas_event_frame (event, &_grab_x, &_grab_y);
setup_pointer_frame_offset (); setup_pointer_frame_offset ();
_grab_frame = adjusted_frame (_raw_grab_frame, event); _grab_frame = adjusted_frame (_raw_grab_frame, event);
_last_pointer_frame = _grab_frame; _last_pointer_frame = _grab_frame;
@ -1896,7 +1896,7 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
boost::shared_ptr<AudioRegion> ar (arv->audio_region()); boost::shared_ptr<AudioRegion> ar (arv->audio_region());
distance = _drags->current_pointer_x() - grab_x(); distance = _drags->current_pointer_x() - grab_x();
len = ar->fade_in()->back()->when; len = ar->fade_in()->back()->when;
new_length = len - _editor->unit_to_frame (distance); new_length = len - _editor->pixel_to_frame (distance);
new_length = ar->verify_xfade_bounds (new_length, true /*START*/ ); new_length = ar->verify_xfade_bounds (new_length, true /*START*/ );
arv->reset_fade_in_shape_width (ar, new_length); //the grey shape arv->reset_fade_in_shape_width (ar, new_length); //the grey shape
} }
@ -1916,7 +1916,7 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
boost::shared_ptr<AudioRegion> ar (arv->audio_region()); boost::shared_ptr<AudioRegion> ar (arv->audio_region());
distance = grab_x() - _drags->current_pointer_x(); distance = grab_x() - _drags->current_pointer_x();
len = ar->fade_out()->back()->when; len = ar->fade_out()->back()->when;
new_length = len - _editor->unit_to_frame (distance); new_length = len - _editor->pixel_to_frame (distance);
new_length = ar->verify_xfade_bounds (new_length, false /*END*/ ); new_length = ar->verify_xfade_bounds (new_length, false /*END*/ );
arv->reset_fade_out_shape_width (ar, new_length); //the grey shape arv->reset_fade_out_shape_width (ar, new_length); //the grey shape
} }
@ -1990,7 +1990,7 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred)
boost::shared_ptr<AudioRegion> ar (arv->audio_region()); boost::shared_ptr<AudioRegion> ar (arv->audio_region());
distance = _drags->current_pointer_x() - grab_x(); distance = _drags->current_pointer_x() - grab_x();
len = ar->fade_in()->back()->when; len = ar->fade_in()->back()->when;
new_length = len - _editor->unit_to_frame (distance); new_length = len - _editor->pixel_to_frame (distance);
new_length = ar->verify_xfade_bounds (new_length, true /*START*/ ); new_length = ar->verify_xfade_bounds (new_length, true /*START*/ );
ar->set_fade_in_length(new_length); ar->set_fade_in_length(new_length);
} }
@ -2007,7 +2007,7 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred)
boost::shared_ptr<AudioRegion> ar (arv->audio_region()); boost::shared_ptr<AudioRegion> ar (arv->audio_region());
distance = _drags->current_pointer_x() - grab_x(); distance = _drags->current_pointer_x() - grab_x();
len = ar->fade_out()->back()->when; len = ar->fade_out()->back()->when;
new_length = len - _editor->unit_to_frame (distance); new_length = len - _editor->pixel_to_frame (distance);
new_length = ar->verify_xfade_bounds (new_length, false /*END*/ ); new_length = ar->verify_xfade_bounds (new_length, false /*END*/ );
ar->set_fade_out_length(new_length); ar->set_fade_out_length(new_length);
} }
@ -2387,7 +2387,7 @@ CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
_grab_zoom = _editor->frames_per_pixel; _grab_zoom = _editor->frames_per_pixel;
framepos_t where = _editor->event_frame (event, 0, 0); framepos_t where = _editor->canvas_event_frame (event, 0, 0);
_editor->snap_to_with_modifier (where, event); _editor->snap_to_with_modifier (where, event);
_editor->_dragging_playhead = true; _editor->_dragging_playhead = true;
@ -3140,7 +3140,7 @@ ControlPointDrag::motion (GdkEvent* event, bool)
cy = max (0.0, cy); cy = max (0.0, cy);
cy = min ((double) _point->line().height(), cy); cy = min ((double) _point->line().height(), cy);
framepos_t cx_frames = _editor->unit_to_frame (cx); framepos_t cx_frames = _editor->pixel_to_frame (cx);
if (!_x_constrained) { if (!_x_constrained) {
_editor->snap_to_with_modifier (cx_frames, event); _editor->snap_to_with_modifier (cx_frames, event);
@ -3150,7 +3150,7 @@ ControlPointDrag::motion (GdkEvent* event, bool)
float const fraction = 1.0 - (cy / _point->line().height()); float const fraction = 1.0 - (cy / _point->line().height());
_point->line().drag_motion (_editor->frame_to_unit_unrounded (cx_frames), fraction, false, _pushing, _final_index); _point->line().drag_motion (_editor->frame_to_pixel_unrounded (cx_frames), fraction, false, _pushing, _final_index);
_editor->verbose_cursor()->set_text (_point->line().get_verbose_cursor_string (fraction)); _editor->verbose_cursor()->set_text (_point->line().get_verbose_cursor_string (fraction));
} }
@ -4279,7 +4279,7 @@ frameoffset_t
NoteDrag::total_dx () const NoteDrag::total_dx () const
{ {
/* dx in frames */ /* dx in frames */
frameoffset_t const dx = _editor->unit_to_frame (_drags->current_pointer_x() - grab_x()); frameoffset_t const dx = _editor->pixel_to_frame (_drags->current_pointer_x() - grab_x());
/* primary note time */ /* primary note time */
frameoffset_t const n = _region->source_beats_to_absolute_frames (_primary->note()->time ()); frameoffset_t const n = _region->source_beats_to_absolute_frames (_primary->note()->time ());
@ -4319,7 +4319,7 @@ NoteDrag::motion (GdkEvent *, bool)
int8_t const dy = total_dy (); int8_t const dy = total_dy ();
/* Now work out what we have to do to the note canvas items to set this new drag delta */ /* Now work out what we have to do to the note canvas items to set this new drag delta */
double const tdx = _editor->frame_to_unit (dx) - _cumulative_dx; double const tdx = _editor->frame_to_pixel (dx) - _cumulative_dx;
double const tdy = -dy * _note_height - _cumulative_dy; double const tdy = -dy * _note_height - _cumulative_dy;
if (tdx || tdy) { if (tdx || tdy) {
@ -4641,7 +4641,7 @@ PatchChangeDrag::motion (GdkEvent* ev, bool)
f = min (f, r->last_frame ()); f = min (f, r->last_frame ());
framecnt_t const dxf = f - grab_frame(); // permitted dx in frames framecnt_t const dxf = f - grab_frame(); // permitted dx in frames
double const dxu = _editor->frame_to_unit (dxf); // permitted fx in units double const dxu = _editor->frame_to_pixel (dxf); // permitted fx in units
_patch_change->move (ArdourCanvas::Duple (dxu - _cumulative_dx, 0)); _patch_change->move (ArdourCanvas::Duple (dxu - _cumulative_dx, 0));
_cumulative_dx = dxu; _cumulative_dx = dxu;
} }
@ -4905,7 +4905,7 @@ CrossfadeEdgeDrag::motion (GdkEvent*, bool)
/* how long should it be ? */ /* how long should it be ? */
new_length = len + _editor->unit_to_frame (distance); new_length = len + _editor->pixel_to_frame (distance);
/* now check with the region that this is legal */ /* now check with the region that this is legal */
@ -4935,7 +4935,7 @@ CrossfadeEdgeDrag::finished (GdkEvent*, bool)
len = ar->fade_out()->back()->when; len = ar->fade_out()->back()->when;
} }
new_length = ar->verify_xfade_bounds (len + _editor->unit_to_frame (distance), start); new_length = ar->verify_xfade_bounds (len + _editor->pixel_to_frame (distance), start);
_editor->begin_reversible_command ("xfade trim"); _editor->begin_reversible_command ("xfade trim");
ar->playlist()->clear_owned_changes (); ar->playlist()->clear_owned_changes ();

View file

@ -491,7 +491,7 @@ Editor::markerview_drag_motion_callback(ArdourCanvas::Item*, GdkEvent* event)
framepos_t pending_region_position ; framepos_t pending_region_position ;
framepos_t pointer_frame ; framepos_t pointer_frame ;
pointer_frame = event_frame(event, &cx, &cy) ; pointer_frame = canvas_event_frame(event, &cx, &cy) ;
snap_to(pointer_frame) ; snap_to(pointer_frame) ;
@ -539,7 +539,7 @@ Editor::imageframe_drag_motion_callback(ArdourCanvas::Item*, GdkEvent* event)
framepos_t pending_region_position; framepos_t pending_region_position;
framepos_t pointer_frame; framepos_t pointer_frame;
pointer_frame = event_frame(event, &cx, &cy) ; pointer_frame = canvas_event_frame(event, &cx, &cy) ;
snap_to(pointer_frame) ; snap_to(pointer_frame) ;
@ -676,7 +676,7 @@ Editor::imageframe_start_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent*
framepos_t start = 0 ; framepos_t start = 0 ;
framepos_t end = 0 ; framepos_t end = 0 ;
framepos_t pointer_frame = event_frame(event) ; framepos_t pointer_frame = canvas_event_frame(event) ;
// chekc th eposition of the item is not locked // chekc th eposition of the item is not locked
if(!ifv->get_position_locked()) { if(!ifv->get_position_locked()) {
@ -765,7 +765,7 @@ Editor::imageframe_end_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* ev
framepos_t start = 0 ; framepos_t start = 0 ;
framepos_t end = 0 ; framepos_t end = 0 ;
framepos_t pointer_frame = event_frame(event) ; framepos_t pointer_frame = canvas_event_frame(event) ;
framepos_t new_dur_val = 0 ; framepos_t new_dur_val = 0 ;
snap_to(pointer_frame) ; snap_to(pointer_frame) ;
@ -890,7 +890,7 @@ Editor::markerview_start_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent*
framepos_t start = 0 ; framepos_t start = 0 ;
framepos_t end = 0 ; framepos_t end = 0 ;
framepos_t pointer_frame = event_frame(event) ; framepos_t pointer_frame = canvas_event_frame(event) ;
// chekc th eposition of the item is not locked // chekc th eposition of the item is not locked
if(!mv->get_position_locked()) if(!mv->get_position_locked())
@ -982,7 +982,7 @@ Editor::markerview_end_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* ev
framepos_t start = 0 ; framepos_t start = 0 ;
framepos_t end = 0 ; framepos_t end = 0 ;
framepos_t pointer_frame = event_frame(event) ; framepos_t pointer_frame = canvas_event_frame(event) ;
framepos_t new_dur_val = 0 ; framepos_t new_dur_val = 0 ;
snap_to(pointer_frame) ; snap_to(pointer_frame) ;

View file

@ -102,86 +102,81 @@ Editor::mouse_frame (framepos_t& where, bool& in_track_canvas) const
} }
int x, y; int x, y;
double wx, wy; Glib::RefPtr<Gdk::Window> canvas_window = const_cast<Editor*>(this)->_track_canvas->get_window();
Gdk::ModifierType mask;
Glib::RefPtr<Gdk::Window> canvas_window = const_cast<Editor*>(this)->_track_canvas_viewport->get_window();
Glib::RefPtr<const Gdk::Window> pointer_window;
if (!canvas_window) { if (!canvas_window) {
return false; return false;
} }
pointer_window = canvas_window->get_pointer (x, y, mask); Glib::RefPtr<const Gdk::Window> pointer_window = Gdk::Display::get_default()->get_window_at_pointer (x, y);
if (pointer_window == _track_canvas->get_window()) { if (!pointer_window) {
wx = x; return false;
wy = y; }
in_track_canvas = true;
} else { if (pointer_window != canvas_window && pointer_window != _time_bars_canvas->get_window()) {
in_track_canvas = false; in_track_canvas = false;
return false; return false;
} }
in_track_canvas = true;
GdkEvent event; GdkEvent event;
event.type = GDK_BUTTON_RELEASE; event.type = GDK_BUTTON_RELEASE;
event.button.x = wx; event.button.x = x;
event.button.y = wy; event.button.y = y;
where = window_event_frame (&event, 0, 0);
where = event_frame (&event, 0, 0);
return true; return true;
} }
framepos_t framepos_t
Editor::event_frame (GdkEvent const * event, double* pcx, double* pcy) const Editor::window_event_frame (GdkEvent const * event, double* pcx, double* pcy) const
{ {
using ArdourCanvas::Duple; double x;
Duple d; double y;
double cx, cy;
if (pcx == 0) { if (!gdk_event_get_coords (event, &x, &y)) {
pcx = &cx; return 0;
}
if (pcy == 0) {
pcy = &cy;
} }
*pcx = 0; /* event coordinates are in window units, so convert to canvas
*pcy = 0; * (i.e. account for scrolling)
/* The event coordinates will be window coordinates and we need canvas
* coordinates (units are pixels as with the window, but scrolling is taken into account)
*/ */
switch (event->type) { ArdourCanvas::Duple d = _track_canvas->window_to_canvas (ArdourCanvas::Duple (x, y));
case GDK_BUTTON_RELEASE:
case GDK_BUTTON_PRESS: if (pcx) {
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
d = _track_canvas->window_to_canvas (Duple (event->button.x, event->button.y));
*pcx = d.x; *pcx = d.x;
}
if (pcy) {
*pcy = d.y; *pcy = d.y;
break; }
case GDK_MOTION_NOTIFY:
d = _track_canvas->window_to_canvas (Duple (event->motion.x, event->motion.y)); return pixel_to_frame (d.x);
*pcx = d.x; }
*pcy = d.y;
break; framepos_t
case GDK_ENTER_NOTIFY: Editor::canvas_event_frame (GdkEvent const * event, double* pcx, double* pcy) const
case GDK_LEAVE_NOTIFY: {
d = _track_canvas->window_to_canvas (Duple (event->crossing.x, event->crossing.y)); double x;
*pcx = d.x; double y;
*pcy = d.y;
break; /* event coordinates are already in canvas units */
case GDK_KEY_PRESS:
case GDK_KEY_RELEASE: if (!gdk_event_get_coords (event, &x, &y)) {
// need to get pointer for this to work cerr << "!NO c COORDS for event type " << event->type << endl;
// d = _track_canvas->window_to_canvas (Duple (event->key.x, event->key.y)); return 0;
*pcx = 0; }
*pcy = 0;
break; if (pcx) {
default: *pcx = x;
warning << string_compose (_("Editor::event_frame() used on unhandled event type %1"), event->type) << endmsg; }
break;
if (pcy) {
*pcy = y;
} }
/* note that pixel_to_frame() never returns less than zero, so even if the pixel /* note that pixel_to_frame() never returns less than zero, so even if the pixel
@ -189,7 +184,7 @@ Editor::event_frame (GdkEvent const * event, double* pcx, double* pcy) const
the frame location is always positive. the frame location is always positive.
*/ */
return pixel_to_frame (*pcx); return pixel_to_frame (x);
} }
Gdk::Cursor* Gdk::Cursor*
@ -1086,7 +1081,7 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
_drags->set (new RegionCreateDrag (this, item, parent), event); _drags->set (new RegionCreateDrag (this, item, parent), event);
} else { } else {
/* See if there's a region before the click that we can extend, and extend it if so */ /* See if there's a region before the click that we can extend, and extend it if so */
framepos_t const t = event_frame (event); framepos_t const t = canvas_event_frame (event);
boost::shared_ptr<Region> prev = pl->find_next_region (t, End, -1); boost::shared_ptr<Region> prev = pl->find_next_region (t, End, -1);
if (!prev) { if (!prev) {
_drags->set (new RegionCreateDrag (this, item, parent), event); _drags->set (new RegionCreateDrag (this, item, parent), event);
@ -1124,7 +1119,7 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
boost::shared_ptr<Playlist> pl = t->playlist (); boost::shared_ptr<Playlist> pl = t->playlist ();
if (pl) { if (pl) {
boost::shared_ptr<Region> r = pl->top_region_at (event_frame (event)); boost::shared_ptr<Region> r = pl->top_region_at (canvas_event_frame (event));
if (r) { if (r) {
RegionView* rv = rtv->view()->find_view (r); RegionView* rv = rtv->view()->find_view (r);
clicked_selection = select_range (rv->region()->position(), clicked_selection = select_range (rv->region()->position(),
@ -1316,9 +1311,9 @@ Editor::button_press_handler_2 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
case MouseZoom: case MouseZoom:
if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
temporal_zoom_to_frame (false, event_frame (event)); temporal_zoom_to_frame (false, canvas_event_frame (event));
} else { } else {
temporal_zoom_to_frame (true, event_frame(event)); temporal_zoom_to_frame (true, canvas_event_frame(event));
} }
return true; return true;
break; break;
@ -1411,7 +1406,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
//not rolling, range mode click + join_play_range : locate the PH here //not rolling, range mode click + join_play_range : locate the PH here
if ( !_drags->active () && !_session->transport_rolling() && ( effective_mouse_mode() == MouseRange ) && Config->get_always_play_range() ) { if ( !_drags->active () && !_session->transport_rolling() && ( effective_mouse_mode() == MouseRange ) && Config->get_always_play_range() ) {
framepos_t where = event_frame (event, 0, 0); framepos_t where = canvas_event_frame (event, 0, 0);
snap_to(where); snap_to(where);
_session->request_locate (where, false); _session->request_locate (where, false);
} }
@ -1460,7 +1455,7 @@ Editor::button_release_dispatch (GdkEventButton* ev)
bool bool
Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type) Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type)
{ {
framepos_t where = event_frame (event, 0, 0); framepos_t where = canvas_event_frame (event, 0, 0);
AutomationTimeAxisView* atv = 0; AutomationTimeAxisView* atv = 0;
if (pre_press_cursor) { if (pre_press_cursor) {

View file

@ -1964,20 +1964,17 @@ Editor::unhide_ranges ()
void void
Editor::insert_region_list_drag (boost::shared_ptr<Region> region, int x, int y) Editor::insert_region_list_drag (boost::shared_ptr<Region> region, int x, int y)
{ {
double wx, wy;
double cx, cy; double cx, cy;
framepos_t where; framepos_t where;
RouteTimeAxisView *rtv = 0; RouteTimeAxisView *rtv = 0;
boost::shared_ptr<Playlist> playlist; boost::shared_ptr<Playlist> playlist;
_track_canvas_viewport->window_to_canvas (x, y, wx, wy);
GdkEvent event; GdkEvent event;
event.type = GDK_BUTTON_RELEASE; event.type = GDK_BUTTON_RELEASE;
event.button.x = wx; event.button.x = x;
event.button.y = wy; event.button.y = y;
where = event_frame (&event, &cx, &cy); where = window_event_frame (&event, &cx, &cy);
if (where < leftmost_frame || where > leftmost_frame + current_page_frames()) { if (where < leftmost_frame || where > leftmost_frame + current_page_frames()) {
/* clearly outside canvas area */ /* clearly outside canvas area */
@ -2009,19 +2006,16 @@ Editor::insert_region_list_drag (boost::shared_ptr<Region> region, int x, int y)
void void
Editor::insert_route_list_drag (boost::shared_ptr<Route> route, int x, int y) Editor::insert_route_list_drag (boost::shared_ptr<Route> route, int x, int y)
{ {
double wx, wy;
double cx, cy; double cx, cy;
RouteTimeAxisView *dest_rtv = 0; RouteTimeAxisView *dest_rtv = 0;
RouteTimeAxisView *source_rtv = 0; RouteTimeAxisView *source_rtv = 0;
_track_canvas_viewport->window_to_canvas (x, y, wx, wy);
GdkEvent event; GdkEvent event;
event.type = GDK_BUTTON_RELEASE; event.type = GDK_BUTTON_RELEASE;
event.button.x = wx; event.button.x = x;
event.button.y = wy; event.button.y = y;
event_frame (&event, &cx, &cy); window_event_frame (&event, &cx, &cy);
std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (cy); std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (cy);
if (tv.first == 0) { if (tv.first == 0) {

View file

@ -778,7 +778,7 @@ EditorSummary::set_editor_x (pair<double, double> x)
double const nx = ( double const nx = (
((x.second - x.first) / _x_scale) / ((x.second - x.first) / _x_scale) /
_editor->frame_to_unit (_editor->current_page_frames()) _editor->frame_to_pixel (_editor->current_page_frames())
); );
if (nx != _editor->get_current_zoom ()) { if (nx != _editor->get_current_zoom ()) {

View file

@ -58,8 +58,8 @@ Editor::update_video_timeline (bool flush)
#if DEBUG #if DEBUG
framepos_t rightmost_frame = leftmost_frame + current_page_frames(); framepos_t rightmost_frame = leftmost_frame + current_page_frames();
std::cout << "VIDEO SCROLL: " << leftmost_frame << " -- " << rightmost_frame << std::endl; std::cout << "VIDEO SCROLL: " << leftmost_frame << " -- " << rightmost_frame << std::endl;
std::cout << "SCROLL UNITS: " << frame_to_unit(leftmost_frame) << " -- " << frame_to_unit(rightmost_frame) std::cout << "SCROLL UNITS: " << frame_to_pixel(leftmost_frame) << " -- " << frame_to_pixel(rightmost_frame)
<< " = " << frame_to_unit(rightmost_frame) - frame_to_unit(leftmost_frame) << " = " << frame_to_pixel(rightmost_frame) - frame_to_pixel(leftmost_frame)
<< std::endl; << std::endl;
#endif #endif

View file

@ -234,7 +234,7 @@ Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, con
} }
frame_position = frame; frame_position = frame;
unit_position = editor.frame_to_unit (frame); unit_position = editor.frame_to_pixel (frame);
unit_position -= _shift; unit_position -= _shift;
group = new ArdourCanvas::Group (&parent, ArdourCanvas::Duple (unit_position, 0)); group = new ArdourCanvas::Group (&parent, ArdourCanvas::Duple (unit_position, 0));
@ -429,7 +429,7 @@ Marker::setup_name_display ()
void void
Marker::set_position (framepos_t frame) Marker::set_position (framepos_t frame)
{ {
unit_position = editor.frame_to_unit (frame) - _shift; unit_position = editor.frame_to_pixel (frame) - _shift;
group->set_x_position (unit_position); group->set_x_position (unit_position);
frame_position = frame; frame_position = frame;
} }

View file

@ -198,12 +198,9 @@ class PublicEditor : public Gtk::Window, public PBD::StatefulDestructible {
virtual void separate_region_from_selection () = 0; virtual void separate_region_from_selection () = 0;
virtual void transition_to_rolling (bool fwd) = 0; virtual void transition_to_rolling (bool fwd) = 0;
virtual framepos_t unit_to_frame (double unit) const = 0;
virtual double frame_to_unit (framepos_t frame) const = 0;
virtual double frame_to_unit (double frame) const = 0;
virtual double frame_to_unit_unrounded (framepos_t frame) const = 0;
virtual framepos_t pixel_to_frame (double pixel) const = 0; virtual framepos_t pixel_to_frame (double pixel) const = 0;
virtual gulong frame_to_pixel (framepos_t frame) const = 0; virtual double frame_to_pixel (framepos_t frame) const = 0;
virtual double frame_to_pixel_unrounded (framepos_t frame) const = 0;
virtual Selection& get_selection () const = 0; virtual Selection& get_selection () const = 0;
virtual Selection& get_cut_buffer () const = 0; virtual Selection& get_cut_buffer () const = 0;
virtual void track_mixer_selection () = 0; virtual void track_mixer_selection () = 0;

View file

@ -856,8 +856,8 @@ TimeAxisView::show_selection (TimeSelection& ts)
rect = get_selection_rect ((*i).id); rect = get_selection_rect ((*i).id);
x1 = _editor.frame_to_unit (start); x1 = _editor.frame_to_pixel (start);
x2 = _editor.frame_to_unit (start + cnt - 1); x2 = _editor.frame_to_pixel (start + cnt - 1);
y2 = current_height(); y2 = current_height();
rect->rect->set (ArdourCanvas::Rect (x1, 1, x2, y2)); rect->rect->set (ArdourCanvas::Rect (x1, 1, x2, y2));

View file

@ -56,7 +56,7 @@ VideoImageFrame::VideoImageFrame (PublicEditor& ed, ArdourCanvas::Group& parent,
printf("New VideoImageFrame (%ix%i) %s - %s\n", w, h, vsurl.c_str(), vfn.c_str()); printf("New VideoImageFrame (%ix%i) %s - %s\n", w, h, vsurl.c_str(), vfn.c_str());
#endif #endif
unit_position = editor.frame_to_unit (frame_position); unit_position = editor.frame_to_pixel (frame_position);
group = new ArdourCanvas::Group (_parent, ArdourCanvas::Duple(unit_position, 1.0)); group = new ArdourCanvas::Group (_parent, ArdourCanvas::Duple(unit_position, 1.0));
img_pixbuf = new ArdourCanvas::Pixbuf(group); img_pixbuf = new ArdourCanvas::Pixbuf(group);
@ -85,7 +85,7 @@ VideoImageFrame::~VideoImageFrame ()
void void
VideoImageFrame::set_position (framepos_t frame) VideoImageFrame::set_position (framepos_t frame)
{ {
double new_unit_position = editor.frame_to_unit (frame); double new_unit_position = editor.frame_to_pixel (frame);
group->move (ArdourCanvas::Duple (new_unit_position - unit_position, 0.0)); group->move (ArdourCanvas::Duple (new_unit_position - unit_position, 0.0));
frame_position = frame; frame_position = frame;
unit_position = new_unit_position; unit_position = new_unit_position;

View file

@ -302,7 +302,7 @@ VideoTimeLine::update_video_timeline()
if (_session->timecode_frames_per_second() == 0 ) return; if (_session->timecode_frames_per_second() == 0 ) return;
} }
double frames_per_unit = editor->unit_to_frame(1.0); double frames_per_unit = editor->pixel_to_frame(1.0);
framepos_t leftmost_frame = editor->leftmost_position(); framepos_t leftmost_frame = editor->leftmost_position();
/* Outline: /* Outline: