Significantly speed up marker snapping with large selections

This commit is contained in:
Thomas Goyne 2014-05-14 12:42:44 -07:00
parent fc662e0278
commit e593843da7
4 changed files with 15 additions and 25 deletions

View file

@ -37,7 +37,6 @@ public:
AudioMarkerKeyframe(Pen *style, int position) : style(style), position(position) { } AudioMarkerKeyframe(Pen *style, int position) : style(style), position(position) { }
int GetPosition() const override { return position; } int GetPosition() const override { return position; }
FeetStyle GetFeet() const override { return Feet_None; } FeetStyle GetFeet() const override { return Feet_None; }
bool CanSnap() const override { return true; }
wxPen GetStyle() const override { return *style; } wxPen GetStyle() const override { return *style; }
operator int() const { return position; } operator int() const { return position; }
}; };
@ -85,21 +84,14 @@ void AudioMarkerProviderKeyframes::GetMarkers(TimeRange const& range, AudioMarke
} }
class VideoPositionMarker final : public AudioMarker { class VideoPositionMarker final : public AudioMarker {
Pen style; Pen style{"Colour/Audio Display/Play Cursor"};
int position; int position = -1;
public: public:
VideoPositionMarker()
: style("Colour/Audio Display/Play Cursor")
, position(-1)
{
}
void SetPosition(int new_pos) { position = new_pos; } void SetPosition(int new_pos) { position = new_pos; }
int GetPosition() const override { return position; } int GetPosition() const override { return position; }
FeetStyle GetFeet() const override { return Feet_None; } FeetStyle GetFeet() const override { return Feet_None; }
bool CanSnap() const override { return true; }
wxPen GetStyle() const override { return style; } wxPen GetStyle() const override { return style; }
operator int() const { return position; } operator int() const { return position; }
}; };

View file

@ -65,15 +65,6 @@ public:
/// @brief Get the marker's feet style /// @brief Get the marker's feet style
/// @return The marker's feet style /// @return The marker's feet style
virtual FeetStyle GetFeet() const = 0; virtual FeetStyle GetFeet() const = 0;
/// @brief Retrieve whether this marker participates in snapping
/// @return True if this marker may snap to other snappable markers
///
/// If a marker being dragged returns true from this method, and another
/// marker which also returns true from this method is within range, the
/// marker being dragged will be positioned at the position of the other
/// marker if it is released while it is inside snapping range.
virtual bool CanSnap() const = 0;
}; };
typedef std::vector<const AudioMarker*> AudioMarkerVector; typedef std::vector<const AudioMarker*> AudioMarkerVector;
@ -181,7 +172,6 @@ class SecondsMarkerProvider final : public AudioMarkerProvider {
Marker(Pen *style) : style(style) { } Marker(Pen *style) : style(style) { }
int GetPosition() const override { return position; } int GetPosition() const override { return position; }
FeetStyle GetFeet() const override { return Feet_None; } FeetStyle GetFeet() const override { return Feet_None; }
bool CanSnap() const override { return false; }
wxPen GetStyle() const override; wxPen GetStyle() const override;
operator int() const { return position; } operator int() const { return position; }
}; };

View file

@ -77,7 +77,6 @@ public:
int GetPosition() const override { return position; } int GetPosition() const override { return position; }
wxPen GetStyle() const override { return *style; } wxPen GetStyle() const override { return *style; }
FeetStyle GetFeet() const override { return feet; } FeetStyle GetFeet() const override { return feet; }
bool CanSnap() const override { return true; }
/// Move the marker to a new position /// Move the marker to a new position
/// @param new_position The position to move the marker to, in milliseconds /// @param new_position The position to move the marker to, in milliseconds
@ -864,6 +863,11 @@ int AudioTimingControllerDialogue::SnapMarkers(int snap_range, std::vector<Audio
{ {
if (snap_range <= 0) return 0; if (snap_range <= 0) return 0;
std::vector<const DialogueTimingMarker *> inactive_markers;
inactive_markers.reserve(inactive_lines.size() * 2);
for (auto const& line : inactive_lines)
line.GetMarkers(&inactive_markers);
AudioMarkerVector potential_snaps; AudioMarkerVector potential_snaps;
int snap_distance = 0; int snap_distance = 0;
bool has_snapped = false; bool has_snapped = false;
@ -874,11 +878,16 @@ int AudioTimingControllerDialogue::SnapMarkers(int snap_range, std::vector<Audio
if (pos == prev) continue; if (pos == prev) continue;
potential_snaps.clear(); potential_snaps.clear();
GetMarkers(TimeRange(pos - snap_range, pos + snap_range), potential_snaps); TimeRange range(pos - snap_range, pos + snap_range);
keyframes_provider.GetMarkers(range, potential_snaps);
video_position_provider.GetMarkers(range, potential_snaps);
copy(
boost::lower_bound(inactive_markers, range.begin(), marker_ptr_cmp()),
boost::upper_bound(inactive_markers, range.end(), marker_ptr_cmp()),
back_inserter(potential_snaps));
for (auto marker : potential_snaps) for (auto marker : potential_snaps)
{ {
if (!marker->CanSnap() || boost::find(active, marker) != end(active)) continue;
auto dist = marker->GetPosition() - pos; auto dist = marker->GetPosition() - pos;
if (!has_snapped) if (!has_snapped)
snap_distance = dist; snap_distance = dist;

View file

@ -52,7 +52,6 @@ public:
int GetPosition() const override { return position; } int GetPosition() const override { return position; }
wxPen GetStyle() const override { return *pen; } wxPen GetStyle() const override { return *pen; }
FeetStyle GetFeet() const override { return style; } FeetStyle GetFeet() const override { return style; }
bool CanSnap() const override { return false; }
void Move(int new_pos) { position = new_pos; } void Move(int new_pos) { position = new_pos; }