2010-12-08 04:36:10 +01:00
|
|
|
// Copyright (c) 2010, Niels Martin Hansen
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file audio_timing_dialogue.cpp
|
|
|
|
/// @brief Default timing mode for dialogue subtitles
|
|
|
|
/// @ingroup audio_ui
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef AGI_PRE
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <wx/pen.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ass_dialogue.h"
|
2010-12-08 09:10:00 +01:00
|
|
|
#include "ass_file.h"
|
|
|
|
#include "ass_time.h"
|
2010-12-08 04:36:10 +01:00
|
|
|
#include "audio_controller.h"
|
|
|
|
#include "audio_timing.h"
|
2011-07-15 06:04:13 +02:00
|
|
|
#include "main.h"
|
|
|
|
#include "selection_controller.h"
|
2010-12-08 04:36:10 +01:00
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
/// @class AudioMarkerDialogueTiming
|
|
|
|
/// @brief AudioMarker implementation for AudioTimingControllerDialogue
|
|
|
|
///
|
|
|
|
/// Audio marker intended to live in pairs of two, taking styles depending
|
|
|
|
/// on which marker in the pair is to the left and which is to the right.
|
|
|
|
class AudioMarkerDialogueTiming : public AudioMarker {
|
|
|
|
/// The other marker for the dialogue line's pair
|
|
|
|
AudioMarkerDialogueTiming *other;
|
|
|
|
|
|
|
|
/// Current sample position of this marker
|
|
|
|
int64_t position;
|
|
|
|
|
|
|
|
/// Draw style for the marker
|
|
|
|
wxPen style;
|
|
|
|
/// Foot style for the marker
|
|
|
|
FeetStyle feet;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// AudioMarker interface
|
2011-01-16 08:14:47 +01:00
|
|
|
int64_t GetPosition() const { return position; }
|
|
|
|
wxPen GetStyle() const { return style; }
|
|
|
|
FeetStyle GetFeet() const { return feet; }
|
|
|
|
bool CanSnap() const { return true; }
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Specific interface
|
|
|
|
|
|
|
|
/// @brief Move the marker to a new position
|
|
|
|
/// @param new_position The position to move the marker to, in audio samples
|
|
|
|
///
|
2010-12-08 09:10:00 +01:00
|
|
|
/// If the marker moves to the opposite side of the other marker in the pair,
|
2010-12-08 04:36:10 +01:00
|
|
|
/// the styles of the two markers will be changed to match the new start/end
|
|
|
|
/// relationship of them.
|
|
|
|
void SetPosition(int64_t new_position);
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief Constructor
|
|
|
|
///
|
|
|
|
/// Initialises the fields to default values.
|
|
|
|
AudioMarkerDialogueTiming();
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief Initialise a pair of dialogue markers to be a pair
|
|
|
|
/// @param marker1 The first marker in the pair to make
|
|
|
|
/// @param marker2 The second marker in the pair to make
|
|
|
|
///
|
2010-12-08 09:10:00 +01:00
|
|
|
/// This checks that the markers aren't already part of a pair, and then
|
|
|
|
/// sets their "other" field. Positions and styles aren't affected.
|
2010-12-08 04:36:10 +01:00
|
|
|
static void InitPair(AudioMarkerDialogueTiming *marker1, AudioMarkerDialogueTiming *marker2);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// @class AudioTimingControllerDialogue
|
|
|
|
/// @brief Default timing mode for dialogue subtitles
|
|
|
|
///
|
|
|
|
/// Displays a start and end marker for an active subtitle line, and allows
|
|
|
|
/// for those markers to be dragged. Dragging the start/end markers changes
|
|
|
|
/// the audio selection.
|
|
|
|
///
|
|
|
|
/// When the audio rendering code is expanded to support it, inactive lines
|
|
|
|
/// will also be shown as shaded lines that cannot be changed.
|
|
|
|
///
|
|
|
|
/// Another later expansion will be to affect the timing of multiple selected
|
|
|
|
/// lines at the same time, if they e.g. have end1==start2.
|
|
|
|
class AudioTimingControllerDialogue : public AudioTimingController, private SelectionListener<AssDialogue> {
|
|
|
|
/// Start and end markers for the active line
|
|
|
|
AudioMarkerDialogueTiming markers[2];
|
|
|
|
|
|
|
|
/// Has the timing been modified by the user?
|
2010-12-08 09:10:00 +01:00
|
|
|
/// If auto commit is enabled this will only be true very briefly following
|
|
|
|
/// changes
|
2010-12-08 04:36:10 +01:00
|
|
|
bool timing_modified;
|
|
|
|
|
2010-12-08 09:10:00 +01:00
|
|
|
/// Commit id for coalescing purposes when in auto commit mode
|
|
|
|
int commit_id;
|
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
/// Get the leftmost of the markers
|
|
|
|
AudioMarkerDialogueTiming *GetLeftMarker();
|
|
|
|
const AudioMarkerDialogueTiming *GetLeftMarker() const;
|
|
|
|
/// Get the rightmost of the markers
|
|
|
|
AudioMarkerDialogueTiming *GetRightMarker();
|
|
|
|
const AudioMarkerDialogueTiming *GetRightMarker() const;
|
|
|
|
|
|
|
|
/// The owning audio controller
|
|
|
|
AudioController *audio_controller;
|
|
|
|
|
|
|
|
/// Update the audio controller's selection
|
|
|
|
void UpdateSelection();
|
|
|
|
|
2010-12-08 09:10:00 +01:00
|
|
|
/// @brief Set the position of a marker and announce the change to the world
|
|
|
|
/// @param marker Marker to move
|
|
|
|
/// @param sample New position of the marker
|
|
|
|
void SetMarker(AudioMarkerDialogueTiming *marker, int64_t sample);
|
|
|
|
|
|
|
|
/// Autocommit option
|
|
|
|
const agi::OptionValue *auto_commit;
|
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
/// Selection controller managing the set of lines currently being timed
|
|
|
|
SelectionController<AssDialogue> *selection_controller;
|
|
|
|
|
2010-12-08 09:10:00 +01:00
|
|
|
agi::signal::Connection commit_slot;
|
2011-08-27 08:30:56 +02:00
|
|
|
agi::signal::Connection audio_open_slot;
|
2010-12-08 09:10:00 +01:00
|
|
|
|
|
|
|
/// @todo Dealing with the AssFile directly is probably not the best way to
|
|
|
|
/// handle committing, but anything better probably needs to wait for
|
|
|
|
/// the subtitle container work
|
|
|
|
AssFile *ass;
|
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
// SubtitleSelectionListener interface
|
2011-01-16 08:14:47 +01:00
|
|
|
void OnActiveLineChanged(AssDialogue *new_line);
|
|
|
|
void OnSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed);
|
2010-12-08 04:36:10 +01:00
|
|
|
|
2010-12-08 09:10:00 +01:00
|
|
|
// AssFile events
|
|
|
|
void OnFileChanged(int type);
|
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
public:
|
|
|
|
// AudioMarkerProvider interface
|
2011-01-16 08:14:47 +01:00
|
|
|
void GetMarkers(const SampleRange &range, AudioMarkerVector &out_markers) const;
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
// AudioTimingController interface
|
2011-01-16 08:14:47 +01:00
|
|
|
wxString GetWarningMessage() const;
|
|
|
|
SampleRange GetIdealVisibleSampleRange() const;
|
|
|
|
SampleRange GetPrimaryPlaybackRange() const;
|
|
|
|
bool HasLabels() const;
|
|
|
|
void Next();
|
|
|
|
void Prev();
|
|
|
|
void Commit();
|
|
|
|
void Revert();
|
|
|
|
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);
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Specific interface
|
|
|
|
|
|
|
|
/// @brief Constructor
|
2010-12-08 09:10:00 +01:00
|
|
|
AudioTimingControllerDialogue(AudioController *audio_controller, SelectionController<AssDialogue> *selection_controller, AssFile *ass);
|
2011-01-16 08:14:47 +01:00
|
|
|
~AudioTimingControllerDialogue();
|
2010-12-08 04:36:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-08 09:10:00 +01:00
|
|
|
AudioTimingController *CreateDialogueTimingController(AudioController *audio_controller, SelectionController<AssDialogue> *selection_controller, AssFile *ass)
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
2010-12-08 09:10:00 +01:00
|
|
|
return new AudioTimingControllerDialogue(audio_controller, selection_controller, ass);
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// AudioMarkerDialogueTiming
|
|
|
|
void AudioMarkerDialogueTiming::SetPosition(int64_t new_position)
|
|
|
|
{
|
|
|
|
position = new_position;
|
|
|
|
|
|
|
|
if (other)
|
|
|
|
{
|
|
|
|
/// @todo Make this depend on configuration
|
|
|
|
wxPen style_left = wxPen(*wxRED, 2);
|
|
|
|
wxPen style_right = wxPen(*wxBLUE, 2);
|
|
|
|
if (position < other->position)
|
|
|
|
{
|
|
|
|
feet = Feet_Right;
|
|
|
|
other->feet = Feet_Left;
|
|
|
|
style = style_left;
|
|
|
|
other->style = style_right;
|
|
|
|
}
|
|
|
|
else if (position > other->position)
|
|
|
|
{
|
|
|
|
feet = Feet_Left;
|
|
|
|
other->feet = Feet_Right;
|
|
|
|
style = style_right;
|
|
|
|
other->style = style_left;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AudioMarkerDialogueTiming::AudioMarkerDialogueTiming()
|
|
|
|
: other(0)
|
|
|
|
, position(0)
|
|
|
|
, style(*wxTRANSPARENT_PEN)
|
|
|
|
, feet(Feet_None)
|
|
|
|
{
|
|
|
|
// Nothing more to do
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AudioMarkerDialogueTiming::InitPair(AudioMarkerDialogueTiming *marker1, AudioMarkerDialogueTiming *marker2)
|
|
|
|
{
|
|
|
|
assert(marker1->other == 0);
|
|
|
|
assert(marker2->other == 0);
|
|
|
|
|
|
|
|
marker1->other = marker2;
|
|
|
|
marker2->other = marker1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// AudioTimingControllerDialogue
|
|
|
|
|
2010-12-08 09:10:00 +01:00
|
|
|
AudioTimingControllerDialogue::AudioTimingControllerDialogue(AudioController *audio_controller, SelectionController<AssDialogue> *selection_controller, AssFile *ass)
|
2010-12-08 04:36:10 +01:00
|
|
|
: timing_modified(false)
|
2010-12-08 09:10:00 +01:00
|
|
|
, commit_id(-1)
|
2010-12-08 04:36:10 +01:00
|
|
|
, audio_controller(audio_controller)
|
2011-07-16 07:01:36 +02:00
|
|
|
, auto_commit(OPT_GET("Audio/Auto/Commit"))
|
2010-12-08 04:36:10 +01:00
|
|
|
, selection_controller(selection_controller)
|
2011-07-16 07:01:36 +02:00
|
|
|
, ass(ass)
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
|
|
|
assert(audio_controller != 0);
|
|
|
|
|
|
|
|
AudioMarkerDialogueTiming::InitPair(&markers[0], &markers[1]);
|
|
|
|
|
2011-08-31 06:17:24 +02:00
|
|
|
if (audio_controller->IsAudioOpen())
|
|
|
|
Revert();
|
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
selection_controller->AddSelectionListener(this);
|
2010-12-08 09:10:00 +01:00
|
|
|
commit_slot = ass->AddCommitListener(&AudioTimingControllerDialogue::OnFileChanged, this);
|
2011-08-27 08:30:56 +02:00
|
|
|
audio_open_slot = audio_controller->AddAudioOpenListener(&AudioTimingControllerDialogue::Revert, this);
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AudioTimingControllerDialogue::~AudioTimingControllerDialogue()
|
|
|
|
{
|
|
|
|
selection_controller->RemoveSelectionListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AudioMarkerDialogueTiming *AudioTimingControllerDialogue::GetLeftMarker()
|
|
|
|
{
|
|
|
|
return markers[0].GetPosition() < markers[1].GetPosition() ? &markers[0] : &markers[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
const AudioMarkerDialogueTiming *AudioTimingControllerDialogue::GetLeftMarker() const
|
|
|
|
{
|
|
|
|
return markers[0].GetPosition() < markers[1].GetPosition() ? &markers[0] : &markers[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioMarkerDialogueTiming *AudioTimingControllerDialogue::GetRightMarker()
|
|
|
|
{
|
|
|
|
return markers[0].GetPosition() < markers[1].GetPosition() ? &markers[1] : &markers[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
const AudioMarkerDialogueTiming *AudioTimingControllerDialogue::GetRightMarker() const
|
|
|
|
{
|
|
|
|
return markers[0].GetPosition() < markers[1].GetPosition() ? &markers[1] : &markers[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-08 09:09:16 +01:00
|
|
|
void AudioTimingControllerDialogue::GetMarkers(const SampleRange &range, AudioMarkerVector &out_markers) const
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
|
|
|
if (range.contains(markers[0].GetPosition()))
|
|
|
|
out_markers.push_back(&markers[0]);
|
|
|
|
if (range.contains(markers[1].GetPosition()))
|
|
|
|
out_markers.push_back(&markers[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::OnActiveLineChanged(AssDialogue *new_line)
|
|
|
|
{
|
2011-08-27 08:30:56 +02:00
|
|
|
if (audio_controller->IsAudioOpen())
|
|
|
|
Revert();
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::OnSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed)
|
|
|
|
{
|
|
|
|
/// @todo Create new passive markers, perhaps
|
|
|
|
}
|
|
|
|
|
2010-12-08 09:10:00 +01:00
|
|
|
void AudioTimingControllerDialogue::OnFileChanged(int type) {
|
|
|
|
if (type == AssFile::COMMIT_UNDO || type == AssFile::COMMIT_FULL) return;
|
|
|
|
|
|
|
|
Revert();
|
|
|
|
}
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
wxString AudioTimingControllerDialogue::GetWarningMessage() const
|
|
|
|
{
|
|
|
|
// We have no warning messages currently, maybe add the old "Modified" message back later?
|
|
|
|
return wxString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-08 09:09:16 +01:00
|
|
|
SampleRange AudioTimingControllerDialogue::GetIdealVisibleSampleRange() const
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
|
|
|
return GetPrimaryPlaybackRange();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-08 09:09:16 +01:00
|
|
|
SampleRange AudioTimingControllerDialogue::GetPrimaryPlaybackRange() const
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
2010-12-08 09:09:16 +01:00
|
|
|
return SampleRange(
|
2010-12-08 04:36:10 +01:00
|
|
|
GetLeftMarker()->GetPosition(),
|
|
|
|
GetRightMarker()->GetPosition());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool AudioTimingControllerDialogue::HasLabels() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::Next()
|
|
|
|
{
|
|
|
|
selection_controller->NextLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::Prev()
|
|
|
|
{
|
|
|
|
selection_controller->PrevLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::Commit()
|
|
|
|
{
|
|
|
|
int new_start_ms = audio_controller->MillisecondsFromSamples(GetLeftMarker()->GetPosition());
|
|
|
|
int new_end_ms = audio_controller->MillisecondsFromSamples(GetRightMarker()->GetPosition());
|
|
|
|
|
2010-12-08 09:10:00 +01:00
|
|
|
// If auto committing is enabled, timing_modified will be true iif it is an
|
|
|
|
// auto commit, as there is never pending changes to commit when the button
|
|
|
|
// is clicked
|
|
|
|
bool user_triggered = !(timing_modified && auto_commit->GetBool());
|
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
// Store back new times
|
|
|
|
if (timing_modified)
|
|
|
|
{
|
|
|
|
Selection sel;
|
|
|
|
selection_controller->GetSelectedSet(sel);
|
|
|
|
for (Selection::iterator sub = sel.begin(); sub != sel.end(); ++sub)
|
|
|
|
{
|
|
|
|
(*sub)->Start.SetMS(new_start_ms);
|
|
|
|
(*sub)->End.SetMS(new_end_ms);
|
|
|
|
}
|
2010-12-08 09:10:00 +01:00
|
|
|
|
|
|
|
commit_slot.Block();
|
|
|
|
if (user_triggered)
|
|
|
|
{
|
|
|
|
ass->Commit(_("timing"), AssFile::COMMIT_TIMES);
|
|
|
|
commit_id = -1; // never coalesce with a manually triggered commit
|
|
|
|
}
|
|
|
|
else
|
|
|
|
commit_id = ass->Commit(_("timing"), AssFile::COMMIT_TIMES, commit_id);
|
|
|
|
|
|
|
|
commit_slot.Unblock();
|
2010-12-08 04:36:10 +01:00
|
|
|
timing_modified = false;
|
|
|
|
}
|
|
|
|
|
2010-12-08 09:10:00 +01:00
|
|
|
if (user_triggered && OPT_GET("Audio/Next Line on Commit")->GetBool())
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
2010-12-08 09:10:00 +01:00
|
|
|
/// @todo Old audio display created a new line if there was no next,
|
|
|
|
/// like the edit box, so maybe add a way to do that which both
|
|
|
|
/// this and the edit box can use
|
|
|
|
Next();
|
|
|
|
if (selection_controller->GetActiveLine()->End.GetMS() == 0) {
|
|
|
|
const int default_duration = OPT_GET("Timing/Default Duration")->GetInt();
|
|
|
|
markers[0].SetPosition(audio_controller->SamplesFromMilliseconds(new_end_ms));
|
|
|
|
markers[1].SetPosition(audio_controller->SamplesFromMilliseconds(new_end_ms + default_duration));
|
|
|
|
timing_modified = true;
|
|
|
|
UpdateSelection();
|
|
|
|
}
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::Revert()
|
|
|
|
{
|
2010-12-08 09:10:00 +01:00
|
|
|
if (AssDialogue *line = selection_controller->GetActiveLine())
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
|
|
|
AssTime new_start = line->Start;
|
|
|
|
AssTime new_end = line->End;
|
|
|
|
|
|
|
|
if (new_start.GetMS() != 0 || new_end.GetMS() != 0)
|
|
|
|
{
|
|
|
|
markers[0].SetPosition(audio_controller->SamplesFromMilliseconds(new_start.GetMS()));
|
|
|
|
markers[1].SetPosition(audio_controller->SamplesFromMilliseconds(new_end.GetMS()));
|
|
|
|
timing_modified = false;
|
|
|
|
UpdateSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool AudioTimingControllerDialogue::IsNearbyMarker(int64_t sample, int sensitivity) const
|
|
|
|
{
|
2010-12-08 09:09:16 +01:00
|
|
|
SampleRange range(sample-sensitivity, sample+sensitivity);
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
return range.contains(markers[0].GetPosition()) || range.contains(markers[1].GetPosition());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AudioMarker * AudioTimingControllerDialogue::OnLeftClick(int64_t sample, int sensitivity)
|
|
|
|
{
|
|
|
|
assert(sensitivity >= 0);
|
|
|
|
|
|
|
|
int64_t dist_l, dist_r;
|
|
|
|
|
|
|
|
AudioMarkerDialogueTiming *left = GetLeftMarker();
|
|
|
|
AudioMarkerDialogueTiming *right = GetRightMarker();
|
|
|
|
|
|
|
|
dist_l = tabs(left->GetPosition() - sample);
|
|
|
|
dist_r = tabs(right->GetPosition() - sample);
|
|
|
|
|
|
|
|
if (dist_l < dist_r && dist_l <= sensitivity)
|
|
|
|
{
|
|
|
|
// Clicked near the left marker:
|
|
|
|
// Insta-move it and start dragging it
|
2010-12-08 09:10:00 +01:00
|
|
|
SetMarker(left, sample);
|
2010-12-08 04:36:10 +01:00
|
|
|
return left;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dist_r < dist_l && dist_r <= sensitivity)
|
|
|
|
{
|
|
|
|
// Clicked near the right marker:
|
|
|
|
// Only drag it. For insta-move, the user must right-click.
|
|
|
|
return right;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clicked far from either marker:
|
|
|
|
// Insta-set the left marker to the clicked position and return the right as the dragged one,
|
|
|
|
// such that if the user does start dragging, he will create a new selection from scratch
|
2010-12-08 09:10:00 +01:00
|
|
|
SetMarker(left, sample);
|
2010-12-08 04:36:10 +01:00
|
|
|
return right;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AudioMarker * AudioTimingControllerDialogue::OnRightClick(int64_t sample, int sensitivity)
|
|
|
|
{
|
|
|
|
AudioMarkerDialogueTiming *right = GetRightMarker();
|
2010-12-08 09:10:00 +01:00
|
|
|
SetMarker(right, sample);
|
2010-12-08 04:36:10 +01:00
|
|
|
return right;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::OnMarkerDrag(AudioMarker *marker, int64_t new_position)
|
|
|
|
{
|
|
|
|
assert(marker == &markers[0] || marker == &markers[1]);
|
|
|
|
|
2010-12-08 09:10:00 +01:00
|
|
|
SetMarker(static_cast<AudioMarkerDialogueTiming*>(marker), new_position);
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::UpdateSelection()
|
|
|
|
{
|
2010-12-08 09:09:16 +01:00
|
|
|
AnnounceUpdatedPrimaryRange();
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
2010-12-08 09:10:00 +01:00
|
|
|
void AudioTimingControllerDialogue::SetMarker(AudioMarkerDialogueTiming *marker, int64_t sample)
|
|
|
|
{
|
|
|
|
marker->SetPosition(sample);
|
|
|
|
timing_modified = true;
|
|
|
|
if (auto_commit->GetBool()) Commit();
|
|
|
|
UpdateSelection();
|
|
|
|
}
|