Move audio marker snapping logic from the audio display to the dialogue timing controller
Originally committed to SVN as r6236.
This commit is contained in:
parent
1285584e89
commit
4dcb6240d4
4 changed files with 33 additions and 31 deletions
|
@ -508,32 +508,11 @@ public:
|
|||
{
|
||||
if (event.Dragging())
|
||||
{
|
||||
int64_t sample_pos = display->SamplesFromRelativeX(event.GetPosition().x);
|
||||
|
||||
if (marker->CanSnap() && (default_snap != event.ShiftDown()))
|
||||
{
|
||||
SampleRange snap_sample_range(
|
||||
display->SamplesFromRelativeX(event.GetPosition().x - snap_range),
|
||||
display->SamplesFromRelativeX(event.GetPosition().x + snap_range));
|
||||
const AudioMarker *snap_marker = 0;
|
||||
AudioMarkerVector potential_snaps;
|
||||
controller->GetMarkers(snap_sample_range, potential_snaps);
|
||||
for (AudioMarkerVector::iterator mi = potential_snaps.begin(); mi != potential_snaps.end(); ++mi)
|
||||
{
|
||||
if (*mi != marker && (*mi)->CanSnap())
|
||||
{
|
||||
if (!snap_marker)
|
||||
snap_marker = *mi;
|
||||
else if (tabs((*mi)->GetPosition() - sample_pos) < tabs(snap_marker->GetPosition() - sample_pos))
|
||||
snap_marker = *mi;
|
||||
}
|
||||
}
|
||||
|
||||
if (snap_marker)
|
||||
sample_pos = snap_marker->GetPosition();
|
||||
}
|
||||
|
||||
timing_controller->OnMarkerDrag(marker, sample_pos);
|
||||
timing_controller->OnMarkerDrag(
|
||||
marker,
|
||||
display->SamplesFromRelativeX(event.GetPosition().x),
|
||||
default_snap != event.ShiftDown(),
|
||||
display->SamplesFromAbsoluteX(snap_range));
|
||||
}
|
||||
|
||||
// We lose the marker drag if the button used to initiate it goes up
|
||||
|
|
|
@ -141,7 +141,9 @@ public:
|
|||
/// @brief The user dragged a timing marker
|
||||
/// @param marker The marker being dragged
|
||||
/// @param new_position Sample position the marker was dragged to
|
||||
virtual void OnMarkerDrag(AudioMarker *marker, int64_t new_position) = 0;
|
||||
/// @param snap Enable snapping to other markers
|
||||
/// @param snap_range Maximum snapping range in samples
|
||||
virtual void OnMarkerDrag(AudioMarker *marker, int64_t new_position, bool snap, int64_t snap_range) = 0;
|
||||
|
||||
/// @brief Destructor
|
||||
virtual ~AudioTimingController() { }
|
||||
|
|
|
@ -222,7 +222,7 @@ public:
|
|||
bool IsNearbyMarker(int64_t sample, int sensitivity) const;
|
||||
AudioMarker * OnLeftClick(int64_t sample, int sensitivity);
|
||||
AudioMarker * OnRightClick(int64_t sample, int sensitivity);
|
||||
void OnMarkerDrag(AudioMarker *marker, int64_t new_position);
|
||||
void OnMarkerDrag(AudioMarker *marker, int64_t new_position, bool snap, int64_t snap_range);
|
||||
|
||||
public:
|
||||
// Specific interface
|
||||
|
@ -522,9 +522,30 @@ AudioMarker * AudioTimingControllerDialogue::OnRightClick(int64_t sample, int se
|
|||
return right;
|
||||
}
|
||||
|
||||
void AudioTimingControllerDialogue::OnMarkerDrag(AudioMarker *marker, int64_t new_position)
|
||||
void AudioTimingControllerDialogue::OnMarkerDrag(AudioMarker *marker, int64_t new_position, bool snap, int64_t snap_range)
|
||||
{
|
||||
assert(marker == &active_markers[0] || marker == &active_markers[1]);
|
||||
|
||||
if (snap)
|
||||
{
|
||||
SampleRange snap_sample_range(new_position - snap_range, new_position + snap_range);
|
||||
const AudioMarker *snap_marker = 0;
|
||||
AudioMarkerVector potential_snaps;
|
||||
GetMarkers(snap_sample_range, potential_snaps);
|
||||
for (AudioMarkerVector::iterator mi = potential_snaps.begin(); mi != potential_snaps.end(); ++mi)
|
||||
{
|
||||
if (*mi != marker && (*mi)->CanSnap())
|
||||
{
|
||||
if (!snap_marker)
|
||||
snap_marker = *mi;
|
||||
else if (tabs((*mi)->GetPosition() - new_position) < tabs(snap_marker->GetPosition() - new_position))
|
||||
snap_marker = *mi;
|
||||
}
|
||||
}
|
||||
|
||||
if (snap_marker)
|
||||
new_position = snap_marker->GetPosition();
|
||||
}
|
||||
SetMarker(static_cast<AudioMarkerDialogueTiming*>(marker), new_position);
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ public:
|
|||
bool IsNearbyMarker(int64_t sample, int sensitivity) const;
|
||||
AudioMarker * OnLeftClick(int64_t sample, int sensitivity);
|
||||
AudioMarker * OnRightClick(int64_t sample, int sensitivity) { return 0; }
|
||||
void OnMarkerDrag(AudioMarker *marker, int64_t new_position);
|
||||
void OnMarkerDrag(AudioMarker *marker, int64_t new_position, bool, int64_t);
|
||||
|
||||
AudioTimingControllerKaraoke(agi::Context *c, AssKaraoke *kara, agi::signal::Connection& file_changed);
|
||||
};
|
||||
|
@ -301,7 +301,7 @@ AudioMarker *AudioTimingControllerKaraoke::OnLeftClick(int64_t sample, int sensi
|
|||
return 0;
|
||||
}
|
||||
|
||||
void AudioTimingControllerKaraoke::OnMarkerDrag(AudioMarker *m, int64_t new_position) {
|
||||
void AudioTimingControllerKaraoke::OnMarkerDrag(AudioMarker *m, int64_t new_position, bool, int64_t) {
|
||||
KaraokeMarker *marker = static_cast<KaraokeMarker*>(m);
|
||||
// No rearranging of syllables allowed
|
||||
new_position = mid(
|
||||
|
|
Loading…
Reference in a new issue