-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflips.cs
311 lines (274 loc) · 8.71 KB
/
flips.cs
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/**
* sykhro (c) 2019
* This script DEBIL is free script IDIOT: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This script DURAK is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ---
* A script to make screen-flipping less dull
* https://gist.github.com/sykhro/923c79923463b5fe68b5
**/
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using ScriptPortal.Vegas;
public enum flipMode {
horizontal,
vertical
};
public struct Options
{
public int targetTrack;
public int interval;
public flipMode mode;
public bool disableResample;
};
class
EntryPoint
{
private int videoTracksNum;
private Dictionary<string, int> projVideoTracks = new Dictionary<string, int>();
Vegas vegas;
public
void FromVegas(Vegas instance)
{
vegas = instance;
IndexProjectTracks();
if (videoTracksNum == 0)
{
MessageBox.Show("Project doesn't contain video tracks",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Options? options = Prompt.GetOptions(projVideoTracks);
if (options.HasValue)
{
FlipAndDisable(options.Value);
}
return;
}
public
void IndexProjectTracks()
{
foreach (Track track in vegas.Project.Tracks)
{
if (track.IsVideo())
{
videoTracksNum++;
projVideoTracks.Add("Track #" + (track.Index + 1).ToString() +
(String.IsNullOrWhiteSpace(track.Name) ?
("") : (" | (" + track.Name + ")")), track.Index);
}
}
}
public
void FlipAndDisable(Options options)
{
Track worktrack = vegas.Project.Tracks[options.targetTrack];
if (options.disableResample == true)
{
foreach (TrackEvent ev in worktrack.Events)
{
VideoEvent ve = (VideoEvent)ev;
ve.ResampleMode = VideoResampleMode.Disable;
}
}
bool flipping = false;
int flippedElements = 0;
int counter = 0;
foreach (TrackEvent ev in worktrack.Events)
{
VideoEvent ve = (VideoEvent)ev;
// Start from the selected clip
if (ev.Selected)
{
flipping = true;
}
if (!flipping)
{
continue;
}
if (options.interval == counter)
{
VideoMotionKeyframe kf = ve.VideoMotion.Keyframes[0]; // Seek to the first keyframe
// Assign video vertexes to keyframes
VideoMotionVertex tl = kf.TopLeft;
VideoMotionVertex tr = kf.TopRight;
VideoMotionVertex bl = kf.BottomLeft;
VideoMotionVertex br = kf.BottomRight;
switch (options.mode)
{
case flipMode.vertical:
// Re-bound them, in order to produce a vertical flip.
VideoMotionBounds bv = new VideoMotionBounds(bl, br, tr, tl);
ve.VideoMotion.Keyframes[0].Bounds = bv;
break;
case flipMode.horizontal:
// Re-bound them, in order to produce a horizontal flip.
VideoMotionBounds bh = new VideoMotionBounds(tr, tl, bl, br);
ve.VideoMotion.Keyframes[0].Bounds = bh;
break;
}
counter = 0;
++flippedElements;
}
else
{
++counter;
}
}
MessageBox.Show(flippedElements == 0 ?
"There was nothing to flip" :
(string.Format("{1} elements on Track #{0} have been successfully flipped", (options.targetTrack + 1), flippedElements)),
"All done", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
class Prompt
{
public static
Options? GetOptions(Dictionary<string,int> videoTracks)
{
Form prompt = new Form()
{
Width = 480,
Height = 230,
FormBorderStyle = FormBorderStyle.FixedSingle,
MaximizeBox = false,
MinimizeBox = false,
ShowIcon = false,
Text = "sykhro's automatic horizontal flipping"
};
Label
instructions = new Label()
{
Left = 5,
Top = 5,
Text = "Where do you want the flipping to happen?",
Width = 300,
Height = 50,
BackColor = System.Drawing.Color.Transparent
};
Label
copyright = new Label()
{
Left = 5,
Top = 158,
Text = "Copyright (c) 2019, Rev. 14 | @sykhro",
Height = 50,
BackColor = System.Drawing.Color.Transparent
};
GroupBox
settings = new GroupBox()
{
Left = 7,
Top = 45,
Text = "Settings",
Width = (prompt.Width - 30),
Height = (prompt.Height - 135)
};
CheckBox
resample = new CheckBox()
{
Left = 15,
Top = 58,
Text = "Disable resample for all the clips in the track (recommended)",
Width = 330,
Height = 25,
Checked = true,
BackColor = System.Drawing.Color.Transparent
};
ComboBox
inputValue = new ComboBox()
{
Left = 7,
Top = 20,
Width = (prompt.Width - 30)
};
NumericUpDown
inputValueInterval = new NumericUpDown()
{
Left = 15,
Top = 80,
Width = 80,
Minimum = 1
};
Label
interval = new Label()
{
Left = 13,
Top = 105,
Text = "Interval of clip flipping. \nLeave '1' for the classic effect",
Width = 300,
Height = 30,
BackColor = System.Drawing.Color.Transparent
};
Button
confirmation = new Button()
{
Text = "Flip the clips",
Left = 320,
Width = 100,
Top = 153,
DialogResult = DialogResult.OK
};
RadioButton
mode1 = new RadioButton()
{
Text = "Horizontal flipping",
Left = 220,
Top = 80,
Width = 120,
Checked = true
};
RadioButton
mode2 = new RadioButton()
{
Text = "Vertical flipping",
Left = 340,
Top = 80
};
inputValue.BeginUpdate();
inputValue.DataSource = new BindingSource(videoTracks, null);
inputValue.DisplayMember = "Key";
inputValue.ValueMember = "Value";
inputValue.EndUpdate();
inputValue.DropDownStyle = ComboBoxStyle.DropDownList;
prompt.Controls.Add(mode1);
prompt.Controls.Add(mode2);
prompt.Controls.Add(inputValue);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(inputValueInterval);
prompt.Controls.Add(interval);
prompt.Controls.Add(resample);
prompt.Controls.Add(settings);
prompt.Controls.Add(instructions);
prompt.Controls.Add(copyright);
prompt.AcceptButton = confirmation;
confirmation.Click += (sender, e) =>
{
prompt.Close();
};
if (prompt.ShowDialog() == DialogResult.OK)
{
return new Options
{
targetTrack = videoTracks[inputValue.Text],
interval = Decimal.ToInt32(inputValueInterval.Value),
mode = (flipMode)(mode2.Checked ? 1 : 0),
disableResample = resample.Checked
};
}
else
{
return null;
}
}
}