forked from mia/Aegisub
Significantly speed up marker snapping with large selections
This commit is contained in:
parent
fc662e0278
commit
e593843da7
4 changed files with 15 additions and 25 deletions
|
@ -37,7 +37,6 @@ public:
|
|||
AudioMarkerKeyframe(Pen *style, int position) : style(style), position(position) { }
|
||||
int GetPosition() const override { return position; }
|
||||
FeetStyle GetFeet() const override { return Feet_None; }
|
||||
bool CanSnap() const override { return true; }
|
||||
wxPen GetStyle() const override { return *style; }
|
||||
operator int() const { return position; }
|
||||
};
|
||||
|
@ -85,21 +84,14 @@ void AudioMarkerProviderKeyframes::GetMarkers(TimeRange const& range, AudioMarke
|
|||
}
|
||||
|
||||
class VideoPositionMarker final : public AudioMarker {
|
||||
Pen style;
|
||||
int position;
|
||||
Pen style{"Colour/Audio Display/Play Cursor"};
|
||||
int position = -1;
|
||||
|
||||
public:
|
||||
VideoPositionMarker()
|
||||
: style("Colour/Audio Display/Play Cursor")
|
||||
, position(-1)
|
||||
{
|
||||
}
|
||||
|
||||
void SetPosition(int new_pos) { position = new_pos; }
|
||||
|
||||
int GetPosition() const override { return position; }
|
||||
FeetStyle GetFeet() const override { return Feet_None; }
|
||||
bool CanSnap() const override { return true; }
|
||||
wxPen GetStyle() const override { return style; }
|
||||
operator int() const { return position; }
|
||||
};
|
||||
|
|
|
@ -65,15 +65,6 @@ public:
|
|||
/// @brief Get the marker's feet style
|
||||
/// @return The marker's feet style
|
||||
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;
|
||||
|
@ -181,7 +172,6 @@ class SecondsMarkerProvider final : public AudioMarkerProvider {
|
|||
Marker(Pen *style) : style(style) { }
|
||||
int GetPosition() const override { return position; }
|
||||
FeetStyle GetFeet() const override { return Feet_None; }
|
||||
bool CanSnap() const override { return false; }
|
||||
wxPen GetStyle() const override;
|
||||
operator int() const { return position; }
|
||||
};
|
||||
|
|
|
@ -77,7 +77,6 @@ public:
|
|||
int GetPosition() const override { return position; }
|
||||
wxPen GetStyle() const override { return *style; }
|
||||
FeetStyle GetFeet() const override { return feet; }
|
||||
bool CanSnap() const override { return true; }
|
||||
|
||||
/// Move the marker to a new position
|
||||
/// @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;
|
||||
|
||||
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;
|
||||
int snap_distance = 0;
|
||||
bool has_snapped = false;
|
||||
|
@ -874,11 +878,16 @@ int AudioTimingControllerDialogue::SnapMarkers(int snap_range, std::vector<Audio
|
|||
if (pos == prev) continue;
|
||||
|
||||
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)
|
||||
{
|
||||
if (!marker->CanSnap() || boost::find(active, marker) != end(active)) continue;
|
||||
|
||||
auto dist = marker->GetPosition() - pos;
|
||||
if (!has_snapped)
|
||||
snap_distance = dist;
|
||||
|
|
|
@ -52,7 +52,6 @@ public:
|
|||
int GetPosition() const override { return position; }
|
||||
wxPen GetStyle() const override { return *pen; }
|
||||
FeetStyle GetFeet() const override { return style; }
|
||||
bool CanSnap() const override { return false; }
|
||||
|
||||
void Move(int new_pos) { position = new_pos; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue