2
* This file is part of SubLib.
3
* Copyright (C) 2005-2006 Pedro Castro
5
* SubLib is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* SubLib is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
/// <summary>Represents the frames of a subtitle.</summary>
25
/// <remarks><see cref="Frames" /> and <see cref="Times" /> always exist for any <see cref="Subtitle" />.
26
/// This class is automatically constructed when constructing a <see cref="Subtitle" />.</remarks>
28
private double start = 0;
29
private double end = 0;
30
private Subtitle subtitle = null;
33
/// <summary>The start frame.</summary>
34
/// <remarks>Upon setting the start frame, the start time (<see cref="Times.Start">Times.Start</see>) is also updated based on
35
/// the <see cref="SubtitleProperties.CurrentFrameRate" />.</remarks>
37
get { return (int)Math.Round(PreciseStart); }
40
subtitle.UpdateStartTimeFromFrames();
44
/// <summary>The end frame.</summary>
45
/// <remarks>Upon setting the end frame, the end time (<see cref="Times.End">Times.End</see>) is also updated based on
46
/// the <see cref="SubtitleProperties.CurrentFrameRate" />.</remarks>
48
get { return (int)Math.Round(PreciseEnd); }
51
subtitle.UpdateEndTimeFromFrames();
55
/// <summary>The duration, in frames.</summary>
56
/// <remarks>Setting the duration maintains the start frame and changes the end frame.
57
/// Upon setting the duration, the end time (<see cref="Times.End">Times.End</see>) is also updated based on
58
/// the <see cref="SubtitleProperties.CurrentFrameRate" />.</remarks>
60
get { return End - Start; }
61
set { End = Start + value; }
64
/// <summary>Shifts the subtitle with a specified amount of frames.</summary>
65
/// <param name="frames">The number of frames to shift the subtitle with, which can be positive or negative.</param>
66
public void Shift (int frames) {
67
PreciseStart += frames;
69
subtitle.UpdateTimesFromFrames();
73
public override string ToString() {
74
return Start + "->" + End;
77
/* Internal members */
79
internal Frames (Subtitle subtitle) {
80
this.subtitle = subtitle;
83
internal Frames (Subtitle subtitle, int start, int end) {
86
this.subtitle = subtitle;
89
/// <remarks>Doesn't update times.</remarks>
90
internal double PreciseStart {
92
set { start = value; }
95
/// <remarks>Doesn't update times.</remarks>
96
internal double PreciseEnd {
101
/// <remarks>Doesn't update times.</remarks>
102
internal double PreciseDuration {
103
get { return end - start; }
104
set { end = start + value; }
107
internal void Scale (double factor, int baseFrame) {
108
PreciseStart = baseFrame + ((PreciseStart - baseFrame) * factor);
109
PreciseEnd = baseFrame + ((PreciseEnd - baseFrame) * factor);
111
subtitle.UpdateTimesFromFrames();