-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwaveformutils.cpp
More file actions
126 lines (107 loc) · 3.06 KB
/
waveformutils.cpp
File metadata and controls
126 lines (107 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "waveformview.h"
bool WaveformViewport::findFocusingSubtitle(int CursorPosMs, RangeList &RL, int ToleranceFromBorder, int PositionTolerance)
{
FocusingMode NewFocusMode = FocusNone;
int NewFocusedTime = -1;
bool Result = false;
if(ToleranceFromBorder < 1) ToleranceFromBorder = 1;
auto it = RL.first_at(CursorPosMs, PositionTolerance);
while(it != RL.end_search())
{
if(checkRangeForFocusing(it->Time, CursorPosMs, ToleranceFromBorder, NewFocusMode, NewFocusedTime))
{
Result = true;
break;
}
++it;
}
if(NewFocusMode != FocusNone)
{
setCursor(Qt::SizeHorCursor);
FocusMode = NewFocusMode;
OldFocusedSubtitle = FocusedSubtitle;
FocusedTimeMs = NewFocusedTime;
if(it->Time != Selection)
{
FocusedSubtitle = it;
}
else if(SData.hasSelected())
{
FocusedSubtitle = SData.selectedSubtitle();
}
else
{
// This should be unreachable, I guess
FocusedSubtitle = SData.end();
}
}
if(FocusedSubtitle != OldFocusedSubtitle)
{
if(hasFocusedSubtitle() && FocusMode != FocusNone)
{
// TODO
}
update();
}
return Result;
}
int WaveformViewport::findSnappingPoint(int PosMs, RangeList &RL)
{
constexpr int SNAPPING_DISTANCE_PIXEL = 8;
int Candidate = -1;
int SnappingDistanceTime = pixelToRelTime(SNAPPING_DISTANCE_PIXEL);
if(MinimumBlankMs > 0)
{
if(Info1.exists())
{
Candidate = Info1.getSnappingPoint(MinimumBlankMs);
if(std::abs(Candidate - PosMs) <= SnappingDistanceTime)
{
return Candidate;
}
}
if(Info2.exists())
{
Candidate = Info2.getSnappingPoint(MinimumBlankMs);
if(std::abs(Candidate - PosMs) <= SnappingDistanceTime)
{
return Candidate;
}
}
}
// TODO: Add SceneChanges
return -1;
}
int WaveformViewport::findCorrectedSnappingPoint(int PosMs, RangeList &RL)
{
int Result = findSnappingPoint(PosMs, RL);
if(Result == -1)
{
return -1;
}
// Do a correction, if there are antioverlapping infos
if(MinSelTime != -1 && Result < MinSelTime)
Result = MinSelTime;
if(MaxSelTime != -1 && Result > MaxSelTime)
Result = MaxSelTime;
return Result;
}
bool WaveformViewport::checkRangeForFocusing(Range &R, int CursorPosMs, int ToleranceFromBorder, FocusingMode &NewMode, int &NewFocusTime)
{
if(R.duration() / ToleranceFromBorder > 2)
{
if(std::abs(CursorPosMs - R.StartTime) < ToleranceFromBorder)
{
NewMode = FocusBegin;
NewFocusTime = R.StartTime;
return true;
}
else if(std::abs(CursorPosMs - R.EndTime) < ToleranceFromBorder)
{
NewMode = FocusEnd;
NewFocusTime = R.EndTime;
return true;
}
}
return false;
}