- const int64_t left_delta = left_sample_delta / samples_per_pixel;
- const int64_t right_delta = right_sample_delta / samples_per_pixel;
-
- // Only use closest left or right edge if they're close to the cursor
- if ((left_delta < right_delta) && (left_delta <= snap_distance_))
- nearest_sample = nearest_edges.front().first;
- if ((left_delta >= right_delta) && (right_delta <= snap_distance_))
- nearest_sample = nearest_edges.back().first;
- } else {
- // Determine nearest edge from all signals
+ // Check second edge if available
+ if (edges.size() == 2) {
+ // Note: -1 because this is usually the right edge and sample points are left-aligned
+ const int64_t second_sample_delta = abs(sample_num - edges.back().first - 1);
+ const int64_t second_delta = second_sample_delta / samples_per_pixel;