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"
|
2011-11-18 23:56:45 +01:00
|
|
|
#include "audio_renderer.h"
|
2010-12-08 04:36:10 +01:00
|
|
|
#include "audio_timing.h"
|
2011-09-28 21:44:44 +02:00
|
|
|
#include "include/aegisub/context.h"
|
2011-07-15 06:04:13 +02:00
|
|
|
#include "main.h"
|
2011-10-19 06:19:01 +02:00
|
|
|
#include "pen.h"
|
2011-07-15 06:04:13 +02:00
|
|
|
#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;
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
/// Current ms position of this marker
|
|
|
|
int position;
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
/// Draw style for the marker
|
|
|
|
wxPen style;
|
|
|
|
/// Foot style for the marker
|
|
|
|
FeetStyle feet;
|
|
|
|
|
2011-10-19 06:19:01 +02:00
|
|
|
/// Draw style for the left marker
|
|
|
|
Pen style_left;
|
|
|
|
/// Draw style for the right marker
|
|
|
|
Pen style_right;
|
|
|
|
|
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
public:
|
|
|
|
// AudioMarker interface
|
2012-02-02 00:58:58 +01:00
|
|
|
int GetPosition() const { return position; }
|
2011-01-16 08:14:47 +01:00
|
|
|
wxPen GetStyle() const { return style; }
|
|
|
|
FeetStyle GetFeet() const { return feet; }
|
2012-01-08 02:35:11 +01:00
|
|
|
bool CanSnap() const { return false; }
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Specific interface
|
|
|
|
|
|
|
|
/// @brief Move the marker to a new position
|
2012-02-02 00:58:58 +01:00
|
|
|
/// @param new_position The position to move the marker to, in milliseconds
|
2010-12-08 04:36:10 +01:00
|
|
|
///
|
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.
|
2012-02-02 00:58:58 +01:00
|
|
|
void SetPosition(int new_position);
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
/// @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);
|
|
|
|
|
2011-11-18 23:56:45 +01:00
|
|
|
/// Implicit decay to the position of the marker
|
2012-02-02 00:58:58 +01:00
|
|
|
operator int() const { return position; }
|
2011-11-18 23:56:45 +01:00
|
|
|
};
|
2010-12-08 04:36:10 +01:00
|
|
|
|
2011-11-18 23:58:12 +01:00
|
|
|
/// @class InactiveLineMarker
|
|
|
|
/// @brief Markers for the beginning and ends of inactive lines
|
|
|
|
class InactiveLineMarker : public AudioMarker {
|
2012-02-02 00:58:58 +01:00
|
|
|
int position;
|
2011-11-18 23:58:12 +01:00
|
|
|
Pen style;
|
|
|
|
FeetStyle feet;
|
|
|
|
|
|
|
|
public:
|
2012-02-02 00:58:58 +01:00
|
|
|
int GetPosition() const { return position; }
|
2011-11-18 23:58:12 +01:00
|
|
|
wxPen GetStyle() const { return style; }
|
|
|
|
FeetStyle GetFeet() const { return feet; }
|
2011-12-27 19:46:20 +01:00
|
|
|
bool CanSnap() const { return true; }
|
2011-11-18 23:58:12 +01:00
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
InactiveLineMarker(int position, bool start)
|
2011-11-18 23:58:12 +01:00
|
|
|
: position(position)
|
|
|
|
, style("Colour/Audio Display/Line Boundary Inactive Line", "Audio/Line Boundaries Thickness")
|
|
|
|
, feet(start ? Feet_Right : Feet_Left)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Implicit decay to the position of the marker
|
2012-02-02 00:58:58 +01:00
|
|
|
operator int() const { return position; }
|
2011-11-18 23:58:12 +01:00
|
|
|
};
|
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
/// @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.
|
|
|
|
///
|
|
|
|
/// 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
|
2011-11-18 23:58:12 +01:00
|
|
|
AudioMarkerDialogueTiming active_markers[2];
|
|
|
|
|
|
|
|
/// Markers for inactive lines
|
|
|
|
std::vector<InactiveLineMarker> inactive_markers;
|
2010-12-08 04:36:10 +01:00
|
|
|
|
2012-02-02 00:59:23 +01:00
|
|
|
/// Time ranges with inactive lines
|
|
|
|
std::vector<std::pair<int, int> > inactive_ranges;
|
|
|
|
|
2011-11-16 20:56:00 +01:00
|
|
|
/// Marker provider for video keyframes
|
|
|
|
AudioMarkerProviderKeyframes keyframes_provider;
|
|
|
|
|
2012-02-02 00:59:12 +01:00
|
|
|
/// Marker provider for video playback position
|
|
|
|
VideoPositionMarkerProvider video_position_provider;
|
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
/// 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;
|
|
|
|
|
2011-11-18 23:58:12 +01:00
|
|
|
/// The owning project context
|
|
|
|
agi::Context *context;
|
|
|
|
|
|
|
|
/// Autocommit option
|
|
|
|
const agi::OptionValue *auto_commit;
|
|
|
|
const agi::OptionValue *inactive_line_mode;
|
2012-01-10 21:03:31 +01:00
|
|
|
const agi::OptionValue *inactive_line_comments;
|
2011-11-18 23:58:12 +01:00
|
|
|
|
|
|
|
agi::signal::Connection commit_connection;
|
|
|
|
agi::signal::Connection audio_open_connection;
|
|
|
|
agi::signal::Connection inactive_line_mode_connection;
|
2012-01-10 21:03:31 +01:00
|
|
|
agi::signal::Connection inactive_line_comment_connection;
|
2011-11-18 23:58:12 +01:00
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
/// Get the leftmost of the markers
|
|
|
|
AudioMarkerDialogueTiming *GetLeftMarker();
|
|
|
|
const AudioMarkerDialogueTiming *GetLeftMarker() const;
|
2011-11-18 23:58:12 +01:00
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
/// Get the rightmost of the markers
|
|
|
|
AudioMarkerDialogueTiming *GetRightMarker();
|
|
|
|
const AudioMarkerDialogueTiming *GetRightMarker() const;
|
|
|
|
|
|
|
|
/// Update the audio controller's selection
|
|
|
|
void UpdateSelection();
|
|
|
|
|
2011-11-18 23:58:12 +01:00
|
|
|
/// Regenerate markers for inactive lines
|
|
|
|
void RegenerateInactiveLines();
|
|
|
|
|
2012-01-10 02:16:39 +01:00
|
|
|
/// Add the inactive line markers for a single line
|
|
|
|
/// @param line Line to add markers for. May be NULL.
|
|
|
|
void AddInactiveMarkers(AssDialogue *line);
|
|
|
|
|
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
|
2012-02-02 00:58:58 +01:00
|
|
|
/// @param ms New position of the marker
|
|
|
|
void SetMarker(AudioMarkerDialogueTiming *marker, int ms);
|
2010-12-08 09:10:00 +01:00
|
|
|
|
2012-01-08 02:35:11 +01:00
|
|
|
/// Snap a position to a nearby marker, if any
|
|
|
|
/// @param position Position to snap
|
2012-02-02 00:58:58 +01:00
|
|
|
/// @param snap_range Maximum distance to snap in milliseconds
|
|
|
|
int SnapPosition(int position, int snap_range) const;
|
2012-01-08 02:35:11 +01:00
|
|
|
|
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
|
2012-02-02 00:58:58 +01:00
|
|
|
void GetMarkers(const TimeRange &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;
|
2012-02-02 00:58:58 +01:00
|
|
|
TimeRange GetIdealVisibleTimeRange() const;
|
|
|
|
TimeRange GetPrimaryPlaybackRange() const;
|
2011-11-18 23:56:45 +01:00
|
|
|
void GetRenderingStyles(AudioRenderingStyleRanges &ranges) const;
|
2012-02-02 00:58:58 +01:00
|
|
|
void GetLabels(TimeRange const& range, std::vector<AudioLabel> &out) const { }
|
2011-01-16 08:14:47 +01:00
|
|
|
void Next();
|
|
|
|
void Prev();
|
|
|
|
void Commit();
|
|
|
|
void Revert();
|
2012-02-02 00:58:58 +01:00
|
|
|
bool IsNearbyMarker(int ms, int sensitivity) const;
|
|
|
|
AudioMarker * OnLeftClick(int ms, int sensitivity, int snap_range);
|
|
|
|
AudioMarker * OnRightClick(int ms, int sensitivity, int snap_range);
|
|
|
|
void OnMarkerDrag(AudioMarker *marker, int new_position, int snap_range);
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Specific interface
|
|
|
|
|
|
|
|
/// @brief Constructor
|
2011-09-28 21:44:44 +02:00
|
|
|
AudioTimingControllerDialogue(agi::Context *c);
|
2011-01-16 08:14:47 +01:00
|
|
|
~AudioTimingControllerDialogue();
|
2010-12-08 04:36:10 +01:00
|
|
|
};
|
|
|
|
|
2011-09-28 21:44:44 +02:00
|
|
|
AudioTimingController *CreateDialogueTimingController(agi::Context *c)
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
2011-09-28 21:44:44 +02:00
|
|
|
return new AudioTimingControllerDialogue(c);
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// AudioMarkerDialogueTiming
|
2012-02-02 00:58:58 +01:00
|
|
|
void AudioMarkerDialogueTiming::SetPosition(int new_position)
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
|
|
|
position = new_position;
|
|
|
|
|
|
|
|
if (other)
|
|
|
|
{
|
|
|
|
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)
|
2011-10-19 06:19:01 +02:00
|
|
|
, style_left("Colour/Audio Display/Line boundary Start", "Audio/Line Boundaries Thickness")
|
|
|
|
, style_right("Colour/Audio Display/Line boundary End", "Audio/Line Boundaries Thickness")
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
|
|
|
// 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
|
|
|
|
|
2011-09-28 21:44:44 +02:00
|
|
|
AudioTimingControllerDialogue::AudioTimingControllerDialogue(agi::Context *c)
|
2011-11-16 20:56:09 +01:00
|
|
|
: keyframes_provider(c, "Audio/Display/Draw/Keyframes in Dialogue Mode")
|
2012-02-02 00:59:12 +01:00
|
|
|
, video_position_provider(c)
|
2011-11-16 20:56:00 +01:00
|
|
|
, timing_modified(false)
|
2010-12-08 09:10:00 +01:00
|
|
|
, commit_id(-1)
|
2011-09-28 21:44:44 +02:00
|
|
|
, context(c)
|
2011-07-16 07:01:36 +02:00
|
|
|
, auto_commit(OPT_GET("Audio/Auto/Commit"))
|
2011-11-18 23:58:12 +01:00
|
|
|
, inactive_line_mode(OPT_GET("Audio/Inactive Lines Display Mode"))
|
2012-01-10 21:03:31 +01:00
|
|
|
, inactive_line_comments(OPT_GET("Audio/Display/Draw/Inactive Comments"))
|
2011-11-18 23:58:12 +01:00
|
|
|
, commit_connection(c->ass->AddCommitListener(&AudioTimingControllerDialogue::OnFileChanged, this))
|
|
|
|
, inactive_line_mode_connection(OPT_SUB("Audio/Inactive Lines Display Mode", &AudioTimingControllerDialogue::RegenerateInactiveLines, this))
|
2012-01-10 21:03:31 +01:00
|
|
|
, inactive_line_comment_connection(OPT_SUB("Audio/Display/Draw/Inactive Comments", &AudioTimingControllerDialogue::RegenerateInactiveLines, this))
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
2011-11-18 23:58:12 +01:00
|
|
|
AudioMarkerDialogueTiming::InitPair(&active_markers[0], &active_markers[1]);
|
2010-12-08 04:36:10 +01:00
|
|
|
|
2011-09-28 21:44:44 +02:00
|
|
|
c->selectionController->AddSelectionListener(this);
|
2011-11-16 20:56:00 +01:00
|
|
|
keyframes_provider.AddMarkerMovedListener(std::tr1::bind(std::tr1::ref(AnnounceMarkerMoved)));
|
2012-02-02 00:59:12 +01:00
|
|
|
video_position_provider.AddMarkerMovedListener(std::tr1::bind(std::tr1::ref(AnnounceMarkerMoved)));
|
2011-11-18 23:58:22 +01:00
|
|
|
|
|
|
|
Revert();
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AudioTimingControllerDialogue::~AudioTimingControllerDialogue()
|
|
|
|
{
|
2011-09-28 21:44:44 +02:00
|
|
|
context->selectionController->RemoveSelectionListener(this);
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioMarkerDialogueTiming *AudioTimingControllerDialogue::GetLeftMarker()
|
|
|
|
{
|
2011-11-18 23:58:12 +01:00
|
|
|
return active_markers[0] < active_markers[1] ? &active_markers[0] : &active_markers[1];
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const AudioMarkerDialogueTiming *AudioTimingControllerDialogue::GetLeftMarker() const
|
|
|
|
{
|
2011-11-18 23:58:12 +01:00
|
|
|
return &std::min(active_markers[0], active_markers[1]);
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioMarkerDialogueTiming *AudioTimingControllerDialogue::GetRightMarker()
|
|
|
|
{
|
2011-11-18 23:58:12 +01:00
|
|
|
return active_markers[0] < active_markers[1] ? &active_markers[1] : &active_markers[0];
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const AudioMarkerDialogueTiming *AudioTimingControllerDialogue::GetRightMarker() const
|
|
|
|
{
|
2011-11-18 23:58:12 +01:00
|
|
|
return &std::max(active_markers[0], active_markers[1]);
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
void AudioTimingControllerDialogue::GetMarkers(const TimeRange &range, AudioMarkerVector &out_markers) const
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
2012-01-08 02:35:25 +01:00
|
|
|
// The order matters here; later markers are painted on top of earlier
|
|
|
|
// markers, so the markers that we want to end up on top need to appear last
|
2011-11-18 23:58:12 +01:00
|
|
|
|
|
|
|
// Copy inactive line markers in the range
|
|
|
|
std::vector<InactiveLineMarker>::const_iterator
|
|
|
|
a = lower_bound(inactive_markers.begin(), inactive_markers.end(), range.begin()),
|
|
|
|
b = upper_bound(inactive_markers.begin(), inactive_markers.end(), range.end());
|
|
|
|
|
|
|
|
for (; a != b; ++a)
|
|
|
|
out_markers.push_back(&*a);
|
|
|
|
|
|
|
|
if (range.contains(active_markers[0]))
|
|
|
|
out_markers.push_back(&active_markers[0]);
|
|
|
|
if (range.contains(active_markers[1]))
|
|
|
|
out_markers.push_back(&active_markers[1]);
|
2012-01-08 02:35:25 +01:00
|
|
|
|
|
|
|
keyframes_provider.GetMarkers(range, out_markers);
|
2012-02-02 00:59:12 +01:00
|
|
|
video_position_provider.GetMarkers(range, out_markers);
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::OnActiveLineChanged(AssDialogue *new_line)
|
|
|
|
{
|
2012-02-02 00:58:58 +01:00
|
|
|
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) {
|
2011-09-15 07:16:32 +02:00
|
|
|
if (type & AssFile::COMMIT_DIAG_TIME)
|
|
|
|
{
|
|
|
|
Revert();
|
2011-11-18 23:58:12 +01:00
|
|
|
}
|
|
|
|
else if (type & AssFile::COMMIT_DIAG_ADDREM)
|
|
|
|
{
|
|
|
|
RegenerateInactiveLines();
|
2011-09-15 07:16:32 +02:00
|
|
|
}
|
2010-12-08 09:10:00 +01:00
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
TimeRange AudioTimingControllerDialogue::GetIdealVisibleTimeRange() const
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
|
|
|
return GetPrimaryPlaybackRange();
|
|
|
|
}
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
TimeRange AudioTimingControllerDialogue::GetPrimaryPlaybackRange() const
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
2012-02-02 00:58:58 +01:00
|
|
|
return TimeRange(*GetLeftMarker(), *GetRightMarker());
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
2011-11-18 23:56:45 +01:00
|
|
|
void AudioTimingControllerDialogue::GetRenderingStyles(AudioRenderingStyleRanges &ranges) const
|
|
|
|
{
|
|
|
|
ranges.AddRange(*GetLeftMarker(), *GetRightMarker(), AudioStyle_Selected);
|
2012-02-02 00:59:23 +01:00
|
|
|
for (size_t i = 0; i < inactive_ranges.size(); ++i)
|
2011-11-18 23:58:12 +01:00
|
|
|
{
|
2012-02-02 00:59:23 +01:00
|
|
|
ranges.AddRange(inactive_ranges[i].first, inactive_ranges[i].second, AudioStyle_Inactive);
|
2011-11-18 23:58:12 +01:00
|
|
|
}
|
2011-11-18 23:56:45 +01:00
|
|
|
}
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::Next()
|
|
|
|
{
|
2011-09-28 21:44:44 +02:00
|
|
|
context->selectionController->NextLine();
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::Prev()
|
|
|
|
{
|
2011-09-28 21:44:44 +02:00
|
|
|
context->selectionController->PrevLine();
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::Commit()
|
|
|
|
{
|
2012-02-02 00:58:58 +01:00
|
|
|
int new_start_ms = *GetLeftMarker();
|
|
|
|
int new_end_ms = *GetRightMarker();
|
2010-12-08 04:36:10 +01:00
|
|
|
|
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;
|
2011-09-28 21:44:44 +02:00
|
|
|
context->selectionController->GetSelectedSet(sel);
|
2010-12-08 04:36:10 +01:00
|
|
|
for (Selection::iterator sub = sel.begin(); sub != sel.end(); ++sub)
|
|
|
|
{
|
2011-12-22 22:28:51 +01:00
|
|
|
(*sub)->Start = new_start_ms;
|
|
|
|
(*sub)->End = new_end_ms;
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
2010-12-08 09:10:00 +01:00
|
|
|
|
2011-11-18 23:58:12 +01:00
|
|
|
commit_connection.Block();
|
2010-12-08 09:10:00 +01:00
|
|
|
if (user_triggered)
|
|
|
|
{
|
2011-09-28 21:44:44 +02:00
|
|
|
context->ass->Commit(_("timing"), AssFile::COMMIT_DIAG_TIME);
|
2010-12-08 09:10:00 +01:00
|
|
|
commit_id = -1; // never coalesce with a manually triggered commit
|
|
|
|
}
|
|
|
|
else
|
2011-09-28 21:44:44 +02:00
|
|
|
commit_id = context->ass->Commit(_("timing"), AssFile::COMMIT_DIAG_TIME, commit_id, context->selectionController->GetActiveLine());
|
2010-12-08 09:10:00 +01:00
|
|
|
|
2011-11-18 23:58:12 +01:00
|
|
|
commit_connection.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();
|
2011-12-22 22:28:51 +01:00
|
|
|
if (context->selectionController->GetActiveLine()->End == 0) {
|
2010-12-08 09:10:00 +01:00
|
|
|
const int default_duration = OPT_GET("Timing/Default Duration")->GetInt();
|
2012-02-02 00:58:58 +01:00
|
|
|
active_markers[0].SetPosition(new_end_ms);
|
|
|
|
active_markers[1].SetPosition(new_end_ms + default_duration);
|
2010-12-08 09:10:00 +01:00
|
|
|
timing_modified = true;
|
|
|
|
UpdateSelection();
|
|
|
|
}
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::Revert()
|
|
|
|
{
|
2011-09-28 21:44:44 +02:00
|
|
|
if (AssDialogue *line = context->selectionController->GetActiveLine())
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
2011-12-22 22:29:09 +01:00
|
|
|
if (line->Start != 0 || line->End != 0)
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
2012-02-02 00:58:58 +01:00
|
|
|
active_markers[0].SetPosition(line->Start);
|
|
|
|
active_markers[1].SetPosition(line->End);
|
2010-12-08 04:36:10 +01:00
|
|
|
timing_modified = false;
|
2012-01-10 21:03:31 +01:00
|
|
|
AnnounceUpdatedPrimaryRange();
|
|
|
|
if (inactive_line_mode->GetInt() == 0)
|
2012-01-12 23:32:28 +01:00
|
|
|
AnnounceUpdatedStyleRanges();
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-10 21:03:31 +01:00
|
|
|
RegenerateInactiveLines();
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
bool AudioTimingControllerDialogue::IsNearbyMarker(int ms, int sensitivity) const
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
2012-02-02 00:58:58 +01:00
|
|
|
TimeRange range(ms-sensitivity, ms+sensitivity);
|
2010-12-08 04:36:10 +01:00
|
|
|
|
2011-11-18 23:58:12 +01:00
|
|
|
return range.contains(active_markers[0]) || range.contains(active_markers[1]);
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
AudioMarker * AudioTimingControllerDialogue::OnLeftClick(int ms, int sensitivity, int snap_range)
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
|
|
|
assert(sensitivity >= 0);
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
int dist_l, dist_r;
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
AudioMarkerDialogueTiming *left = GetLeftMarker();
|
|
|
|
AudioMarkerDialogueTiming *right = GetRightMarker();
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
dist_l = tabs(*left - ms);
|
|
|
|
dist_r = tabs(*right - ms);
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
if (dist_l < dist_r && dist_l <= sensitivity)
|
|
|
|
{
|
|
|
|
// Clicked near the left marker:
|
|
|
|
// Insta-move it and start dragging it
|
2012-02-02 00:58:58 +01:00
|
|
|
SetMarker(left, SnapPosition(ms, snap_range));
|
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
|
2012-02-02 00:58:58 +01:00
|
|
|
SetMarker(left, SnapPosition(ms, snap_range));
|
2010-12-08 04:36:10 +01:00
|
|
|
return right;
|
|
|
|
}
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
AudioMarker * AudioTimingControllerDialogue::OnRightClick(int ms, int sensitivity, int snap_range)
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
|
|
|
AudioMarkerDialogueTiming *right = GetRightMarker();
|
2012-02-02 00:58:58 +01:00
|
|
|
SetMarker(right, SnapPosition(ms, snap_range));
|
2010-12-08 04:36:10 +01:00
|
|
|
return right;
|
|
|
|
}
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
void AudioTimingControllerDialogue::OnMarkerDrag(AudioMarker *marker, int new_position, int snap_range)
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
2011-11-18 23:58:12 +01:00
|
|
|
assert(marker == &active_markers[0] || marker == &active_markers[1]);
|
2012-01-08 02:35:04 +01:00
|
|
|
|
2012-01-08 02:35:11 +01:00
|
|
|
SetMarker(static_cast<AudioMarkerDialogueTiming*>(marker), SnapPosition(new_position, snap_range));
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::UpdateSelection()
|
|
|
|
{
|
2010-12-08 09:09:16 +01:00
|
|
|
AnnounceUpdatedPrimaryRange();
|
2011-11-18 23:56:45 +01:00
|
|
|
AnnounceUpdatedStyleRanges();
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
void AudioTimingControllerDialogue::SetMarker(AudioMarkerDialogueTiming *marker, int ms)
|
2010-12-08 09:10:00 +01:00
|
|
|
{
|
2012-02-02 00:58:58 +01:00
|
|
|
marker->SetPosition(ms);
|
2010-12-08 09:10:00 +01:00
|
|
|
timing_modified = true;
|
|
|
|
if (auto_commit->GetBool()) Commit();
|
|
|
|
UpdateSelection();
|
2012-02-02 23:57:53 +01:00
|
|
|
AnnounceMarkerMoved();
|
2010-12-08 09:10:00 +01:00
|
|
|
}
|
2011-11-18 23:58:12 +01:00
|
|
|
|
2012-01-10 21:03:31 +01:00
|
|
|
static bool noncomment_dialogue(AssEntry *e)
|
|
|
|
{
|
|
|
|
if (AssDialogue *diag = dynamic_cast<AssDialogue*>(e))
|
|
|
|
return !diag->Comment;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool dialogue(AssEntry *e)
|
|
|
|
{
|
|
|
|
return !!dynamic_cast<AssDialogue*>(e);
|
|
|
|
}
|
|
|
|
|
2011-11-18 23:58:12 +01:00
|
|
|
void AudioTimingControllerDialogue::RegenerateInactiveLines()
|
|
|
|
{
|
2012-01-10 21:03:31 +01:00
|
|
|
bool (*predicate)(AssEntry*) = inactive_line_comments->GetBool() ? dialogue : noncomment_dialogue;
|
|
|
|
|
2012-02-02 00:59:23 +01:00
|
|
|
bool was_empty = inactive_markers.empty();
|
|
|
|
inactive_markers.clear();
|
|
|
|
inactive_ranges.clear();
|
|
|
|
|
2012-01-10 02:16:39 +01:00
|
|
|
switch (int mode = inactive_line_mode->GetInt())
|
2011-11-18 23:58:12 +01:00
|
|
|
{
|
2012-01-10 02:16:39 +01:00
|
|
|
case 1: // Previous line only
|
|
|
|
case 2: // Previous and next lines
|
2011-11-18 23:58:12 +01:00
|
|
|
if (AssDialogue *line = context->selectionController->GetActiveLine())
|
|
|
|
{
|
2012-01-10 02:16:39 +01:00
|
|
|
std::list<AssEntry*>::iterator current_line =
|
|
|
|
find(context->ass->Line.begin(), context->ass->Line.end(), line);
|
|
|
|
|
|
|
|
std::list<AssEntry*>::iterator prev = current_line;
|
2012-01-10 21:03:31 +01:00
|
|
|
while (--prev != context->ass->Line.begin() && !predicate(*prev)) ;
|
2012-01-13 21:59:48 +01:00
|
|
|
if (prev != context->ass->Line.begin())
|
|
|
|
AddInactiveMarkers(static_cast<AssDialogue*>(*prev));
|
2012-01-10 02:16:39 +01:00
|
|
|
|
|
|
|
if (mode == 2)
|
2011-11-18 23:58:12 +01:00
|
|
|
{
|
2012-01-10 02:16:39 +01:00
|
|
|
std::list<AssEntry*>::iterator next =
|
2012-01-10 21:03:31 +01:00
|
|
|
find_if(++current_line, context->ass->Line.end(), predicate);
|
2012-01-10 02:16:39 +01:00
|
|
|
if (next != context->ass->Line.end())
|
2012-01-10 21:03:31 +01:00
|
|
|
AddInactiveMarkers(static_cast<AssDialogue*>(*next));
|
2011-11-18 23:58:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-01-10 02:16:39 +01:00
|
|
|
case 3: // All inactive lines
|
2011-11-18 23:58:12 +01:00
|
|
|
{
|
|
|
|
AssDialogue *active_line = context->selectionController->GetActiveLine();
|
|
|
|
for (std::list<AssEntry*>::const_iterator it = context->ass->Line.begin(); it != context->ass->Line.end(); ++it)
|
|
|
|
{
|
2012-01-10 21:03:31 +01:00
|
|
|
if (*it != active_line && predicate(*it))
|
|
|
|
AddInactiveMarkers(static_cast<AssDialogue*>(*it));
|
2011-11-18 23:58:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2012-02-02 00:59:23 +01:00
|
|
|
if (was_empty)
|
2011-11-18 23:58:12 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-01-10 02:16:39 +01:00
|
|
|
|
|
|
|
sort(inactive_markers.begin(), inactive_markers.end());
|
2011-11-18 23:58:12 +01:00
|
|
|
AnnounceUpdatedStyleRanges();
|
2012-02-02 23:57:53 +01:00
|
|
|
AnnounceMarkerMoved();
|
2011-11-18 23:58:12 +01:00
|
|
|
}
|
2012-01-08 02:35:11 +01:00
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
int AudioTimingControllerDialogue::SnapPosition(int position, int snap_range) const
|
2012-01-08 02:35:11 +01:00
|
|
|
{
|
|
|
|
if (snap_range <= 0)
|
|
|
|
return position;
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
TimeRange snap_time_range(position - snap_range, position + snap_range);
|
2012-01-08 02:35:11 +01:00
|
|
|
const AudioMarker *snap_marker = 0;
|
|
|
|
AudioMarkerVector potential_snaps;
|
2012-02-02 00:58:58 +01:00
|
|
|
GetMarkers(snap_time_range, potential_snaps);
|
2012-01-08 02:35:11 +01:00
|
|
|
for (AudioMarkerVector::iterator mi = potential_snaps.begin(); mi != potential_snaps.end(); ++mi)
|
|
|
|
{
|
|
|
|
if ((*mi)->CanSnap())
|
|
|
|
{
|
|
|
|
if (!snap_marker)
|
|
|
|
snap_marker = *mi;
|
|
|
|
else if (tabs((*mi)->GetPosition() - position) < tabs(snap_marker->GetPosition() - position))
|
|
|
|
snap_marker = *mi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (snap_marker)
|
|
|
|
return snap_marker->GetPosition();
|
|
|
|
return position;
|
|
|
|
}
|
2012-01-10 02:16:39 +01:00
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::AddInactiveMarkers(AssDialogue *line)
|
|
|
|
{
|
2012-02-02 00:58:58 +01:00
|
|
|
inactive_markers.push_back(InactiveLineMarker(line->Start, true));
|
|
|
|
inactive_markers.push_back(InactiveLineMarker(line->End, false));
|
2012-02-02 00:59:23 +01:00
|
|
|
inactive_ranges.push_back(std::pair<int, int>(line->Start, line->End));
|
2012-01-10 02:16:39 +01:00
|
|
|
}
|