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"
|
2011-11-16 20:56:00 +01:00
|
|
|
#include "audio_marker_provider_keyframes.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;
|
|
|
|
|
|
|
|
/// Current sample position of this marker
|
|
|
|
int64_t position;
|
|
|
|
|
|
|
|
/// 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
|
2011-01-16 08:14:47 +01:00
|
|
|
int64_t GetPosition() const { return position; }
|
|
|
|
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
|
|
|
|
/// @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);
|
|
|
|
|
2011-11-18 23:56:45 +01:00
|
|
|
/// Implicit decay to the position of the marker
|
|
|
|
operator int64_t() const { return position; }
|
|
|
|
};
|
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 {
|
|
|
|
int64_t position;
|
|
|
|
Pen style;
|
|
|
|
FeetStyle feet;
|
|
|
|
|
|
|
|
public:
|
|
|
|
int64_t GetPosition() const { return position; }
|
|
|
|
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
|
|
|
|
|
|
|
InactiveLineMarker(int64_t position, bool start)
|
|
|
|
: 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
|
|
|
|
operator int64_t() const { return position; }
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
///
|
|
|
|
/// 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
|
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
|
|
|
|
2011-11-16 20:56:00 +01:00
|
|
|
/// Marker provider for video keyframes
|
|
|
|
AudioMarkerProviderKeyframes keyframes_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
|
|
|
|
/// @param sample New position of the marker
|
|
|
|
void SetMarker(AudioMarkerDialogueTiming *marker, int64_t sample);
|
|
|
|
|
2012-01-08 02:35:11 +01:00
|
|
|
/// Snap a position to a nearby marker, if any
|
|
|
|
/// @param position Position to snap
|
|
|
|
/// @param snap_range Maximum distance to snap in samples
|
|
|
|
int64_t SnapPosition(int64_t position, int64_t snap_range) const;
|
|
|
|
|
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;
|
2011-11-18 23:56:45 +01:00
|
|
|
void GetRenderingStyles(AudioRenderingStyleRanges &ranges) const;
|
2011-09-15 07:16:26 +02:00
|
|
|
void GetLabels(SampleRange const& range, std::vector<AudioLabel> &out) const { }
|
2011-01-16 08:14:47 +01:00
|
|
|
void Next();
|
|
|
|
void Prev();
|
|
|
|
void Commit();
|
|
|
|
void Revert();
|
|
|
|
bool IsNearbyMarker(int64_t sample, int sensitivity) const;
|
2012-01-08 02:35:11 +01:00
|
|
|
AudioMarker * OnLeftClick(int64_t sample, int sensitivity, int64_t snap_range);
|
|
|
|
AudioMarker * OnRightClick(int64_t sample, int sensitivity, int64_t snap_range);
|
|
|
|
void OnMarkerDrag(AudioMarker *marker, int64_t new_position, int64_t 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
|
|
|
|
void AudioMarkerDialogueTiming::SetPosition(int64_t new_position)
|
|
|
|
{
|
|
|
|
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")
|
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))
|
|
|
|
, audio_open_connection(c->audioController->AddAudioOpenListener(&AudioTimingControllerDialogue::Revert, 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-09-28 21:44:44 +02:00
|
|
|
assert(c->audioController != 0);
|
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)));
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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);
|
2010-12-08 04:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioTimingControllerDialogue::OnActiveLineChanged(AssDialogue *new_line)
|
|
|
|
{
|
2011-09-28 21:44:44 +02:00
|
|
|
if (context->audioController->IsAudioOpen())
|
2011-11-18 23:58:12 +01:00
|
|
|
{
|
2011-08-27 08:30:56 +02:00
|
|
|
Revert();
|
2011-11-18 23:58:12 +01:00
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2011-11-18 23:56:45 +01:00
|
|
|
return SampleRange(*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);
|
2011-11-18 23:58:12 +01:00
|
|
|
for (size_t i = 0; i < inactive_markers.size(); i += 2)
|
|
|
|
{
|
|
|
|
ranges.AddRange(inactive_markers[i], inactive_markers[i + 1], AudioStyle_Inactive);
|
|
|
|
}
|
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()
|
|
|
|
{
|
2011-11-18 23:56:45 +01:00
|
|
|
int new_start_ms = context->audioController->MillisecondsFromSamples(*GetLeftMarker());
|
|
|
|
int new_end_ms = context->audioController->MillisecondsFromSamples(*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();
|
2011-11-18 23:58:12 +01:00
|
|
|
active_markers[0].SetPosition(context->audioController->SamplesFromMilliseconds(new_end_ms));
|
|
|
|
active_markers[1].SetPosition(context->audioController->SamplesFromMilliseconds(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
|
|
|
{
|
2011-12-22 22:29:09 +01:00
|
|
|
active_markers[0].SetPosition(context->audioController->SamplesFromMilliseconds(line->Start));
|
|
|
|
active_markers[1].SetPosition(context->audioController->SamplesFromMilliseconds(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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
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-01-08 02:35:11 +01:00
|
|
|
AudioMarker * AudioTimingControllerDialogue::OnLeftClick(int64_t sample, int sensitivity, int64_t snap_range)
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
|
|
|
assert(sensitivity >= 0);
|
|
|
|
|
|
|
|
int64_t dist_l, dist_r;
|
|
|
|
|
|
|
|
AudioMarkerDialogueTiming *left = GetLeftMarker();
|
|
|
|
AudioMarkerDialogueTiming *right = GetRightMarker();
|
|
|
|
|
2011-11-18 23:56:45 +01:00
|
|
|
dist_l = tabs(*left - sample);
|
|
|
|
dist_r = tabs(*right - sample);
|
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-01-08 02:35:11 +01:00
|
|
|
SetMarker(left, SnapPosition(sample, 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-01-08 02:35:11 +01:00
|
|
|
SetMarker(left, SnapPosition(sample, snap_range));
|
2010-12-08 04:36:10 +01:00
|
|
|
return right;
|
|
|
|
}
|
|
|
|
|
2012-01-08 02:35:11 +01:00
|
|
|
AudioMarker * AudioTimingControllerDialogue::OnRightClick(int64_t sample, int sensitivity, int64_t snap_range)
|
2010-12-08 04:36:10 +01:00
|
|
|
{
|
|
|
|
AudioMarkerDialogueTiming *right = GetRightMarker();
|
2012-01-08 02:35:11 +01:00
|
|
|
SetMarker(right, SnapPosition(sample, snap_range));
|
2010-12-08 04:36:10 +01:00
|
|
|
return right;
|
|
|
|
}
|
|
|
|
|
2012-01-08 02:35:11 +01:00
|
|
|
void AudioTimingControllerDialogue::OnMarkerDrag(AudioMarker *marker, int64_t new_position, int64_t 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
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
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-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
|
|
|
inactive_markers.clear();
|
|
|
|
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
|
|
|
{
|
|
|
|
inactive_markers.clear();
|
|
|
|
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:
|
|
|
|
if (inactive_markers.empty())
|
|
|
|
return;
|
|
|
|
inactive_markers.clear();
|
|
|
|
}
|
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-01-08 02:35:11 +01:00
|
|
|
|
|
|
|
int64_t AudioTimingControllerDialogue::SnapPosition(int64_t position, int64_t snap_range) const
|
|
|
|
{
|
|
|
|
if (snap_range <= 0)
|
|
|
|
return position;
|
|
|
|
|
|
|
|
SampleRange snap_sample_range(position - snap_range, 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)->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-01-10 21:03:31 +01:00
|
|
|
inactive_markers.push_back(InactiveLineMarker(
|
|
|
|
context->audioController->SamplesFromMilliseconds(line->Start), true));
|
|
|
|
inactive_markers.push_back(InactiveLineMarker(
|
|
|
|
context->audioController->SamplesFromMilliseconds(line->End), false));
|
2012-01-10 02:16:39 +01:00
|
|
|
}
|