Skip to content

Commit

Permalink
fix Scramble offset
Browse files Browse the repository at this point in the history
  • Loading branch information
delthas committed Apr 15, 2018
1 parent 2cacba7 commit e5aa208
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Datamosh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.2.0
// Version: 1.2.1
//

using System;
Expand Down
Binary file added Datamosh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Datamosh14.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.2.0
// Version: 1.2.1
//

using System;
Expand All @@ -16,7 +16,7 @@
using System.Windows.Forms;
using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;
using Sony.Vegas;
using ScriptPortal.Vegas;

namespace VegasDatamosh {
public class EntryPoint {
Expand Down
2 changes: 1 addition & 1 deletion Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.2.0
// Version: 1.2.1
//

using System;
Expand Down
Binary file added Layer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Layer14.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.2.0
// Version: 1.2.1
//

using System;
Expand All @@ -17,7 +17,7 @@
using System.Windows.Forms.VisualStyles;
using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;
using Sony.Vegas;
using ScriptPortal.Vegas;

namespace VegasLayering {
public class EntryPoint {
Expand Down
2 changes: 1 addition & 1 deletion Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.2.0
// Version: 1.2.1
//

using System;
Expand Down
Binary file added Render.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Render14.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.2.0
// Version: 1.2.1
//

using System;
Expand All @@ -16,7 +16,7 @@
using System.Windows.Forms;
using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;
using Sony.Vegas;
using ScriptPortal.Vegas;

namespace VegasRender {
public class EntryPoint {
Expand Down
111 changes: 111 additions & 0 deletions Scramble.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Sony Vegas (<=13) script to scramble clips/events
// quickly and automatically.
//
// Author: delthas
// Date: 2018-04-15
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.2.1
//

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using Sony.Vegas;

namespace VegasScramble {
public class EntryPoint {
private static readonly Random Random = new Random();

public void FromVegas(Vegas vegas) {
var events = vegas.Project.Tracks
.SelectMany(track => track.Events)
.Where(t => t.Selected)
.GroupBy(
t => new {
StartFrameCount = t.Start.FrameCount,
LengthFrameCount = t.Length.FrameCount
})
.Select(grp => grp.ToList())
.ToList();

var prompt = new Form {
Width = 500,
Height = 110,
Text = "Scrambling Parameters"
};
var textLabel = new Label {Left = 10, Top = 10, Text = "Scramble size"};
var inputBox = new NumericUpDown {
Left = 200,
Top = 10,
Width = 200,
Minimum = 1,
Maximum = 1000000000,
Text = ""
};
var confirmation = new Button {Text = "OK", Left = 200, Width = 100, Top = 40};
confirmation.Click += (sender, e) => {
prompt.DialogResult = DialogResult.OK;
prompt.Close();
};
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.Controls.Add(inputBox);
inputBox.Select();
prompt.AcceptButton = confirmation;
if (prompt.ShowDialog() != DialogResult.OK) {
return;
}

var size = (int) inputBox.Value;

if (size <= 0) {
MessageBox.Show("Scrambling size must be > 0!");
return;
}

try {
foreach (var e in events) {
var order = new List<int>();
var startFrameCount = e[0].Start.FrameCount;
var endFrameCount = e[0].End.FrameCount;
var n = (int) (endFrameCount - startFrameCount);
var l = n / size;
if(l == 0) continue;
if (n % size != 0) {
++l;
}
for (var i = 0; i < l; i++) {
order.Add(i);
}


for (var i = 0; i < l - 1; i++) {
var k = i + 1 + Random.Next(l - i - 1);
var v = order[k];
order[k] = order[i];
order[i] = v;
}

foreach (var evt in e) {
int offset;
for (var i = l - 1; i > 0; i--) {
var other = evt.Split(Timecode.FromFrames(i * size));
offset = order[i] > order[l - 1] ? -(size - n % size) : 0;
other.Start = Timecode.FromFrames(startFrameCount + offset + order[i] * size);
}
offset = order[0] > order[l - 1] ? -(size - n % size) : 0;
evt.Start = Timecode.FromFrames(startFrameCount + offset + order[0] * size);
}
}
}
catch (Exception e) {
MessageBox.Show("Unexpected exception: " + e.Message);
Debug.WriteLine(e);
}
}
}
}
7 changes: 7 additions & 0 deletions Scramble.cs.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ScriptSettings>
<AssemblyReference>System.dll</AssemblyReference>
<AssemblyReference>System.Core.dll</AssemblyReference>
<CompilerOptions>-debug -D:DEBUG</CompilerOptions>
<IconFile>Scramble.png</IconFile>
</ScriptSettings>
Binary file added Scramble.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions Scramble14.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// MAGIX Vegas (>=14) script to scramble clips/events
// quickly and automatically.
//
// Author: delthas
// Date: 2018-04-15
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.2.1
//

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using ScriptPortal.Vegas;

namespace VegasScramble {
public class EntryPoint {
private static readonly Random Random = new Random();

public void FromVegas(Vegas vegas) {
var events = vegas.Project.Tracks
.SelectMany(track => track.Events)
.Where(t => t.Selected)
.GroupBy(
t => new {
StartFrameCount = t.Start.FrameCount,
LengthFrameCount = t.Length.FrameCount
})
.Select(grp => grp.ToList())
.ToList();

var prompt = new Form {
Width = 500,
Height = 110,
Text = "Scrambling Parameters"
};
var textLabel = new Label {Left = 10, Top = 10, Text = "Scramble size"};
var inputBox = new NumericUpDown {
Left = 200,
Top = 10,
Width = 200,
Minimum = 1,
Maximum = 1000000000,
Text = ""
};
var confirmation = new Button {Text = "OK", Left = 200, Width = 100, Top = 40};
confirmation.Click += (sender, e) => {
prompt.DialogResult = DialogResult.OK;
prompt.Close();
};
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.Controls.Add(inputBox);
inputBox.Select();
prompt.AcceptButton = confirmation;
if (prompt.ShowDialog() != DialogResult.OK) {
return;
}

var size = (int) inputBox.Value;

if (size <= 0) {
MessageBox.Show("Scrambling size must be > 0!");
return;
}

try {
foreach (var e in events) {
var order = new List<int>();
var startFrameCount = e[0].Start.FrameCount;
var endFrameCount = e[0].End.FrameCount;
var n = (int) (endFrameCount - startFrameCount);
var l = n / size;
if(l == 0) continue;
if (n % size != 0) {
++l;
}
for (var i = 0; i < l; i++) {
order.Add(i);
}


for (var i = 0; i < l - 1; i++) {
var k = i + 1 + Random.Next(l - i - 1);
var v = order[k];
order[k] = order[i];
order[i] = v;
}

foreach (var evt in e) {
int offset;
for (var i = l - 1; i > 0; i--) {
var other = evt.Split(Timecode.FromFrames(i * size));
offset = order[i] > order[l - 1] ? -(size - n % size) : 0;
other.Start = Timecode.FromFrames(startFrameCount + offset + order[i] * size);
}
offset = order[0] > order[l - 1] ? -(size - n % size) : 0;
evt.Start = Timecode.FromFrames(startFrameCount + offset + order[0] * size);
}
}
}
catch (Exception e) {
MessageBox.Show("Unexpected exception: " + e.Message);
Debug.WriteLine(e);
}
}
}
}
7 changes: 7 additions & 0 deletions Scramble14.cs.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ScriptSettings>
<AssemblyReference>System.dll</AssemblyReference>
<AssemblyReference>System.Core.dll</AssemblyReference>
<CompilerOptions>-debug -D:DEBUG</CompilerOptions>
<IconFile>Scramble.png</IconFile>
</ScriptSettings>

0 comments on commit e5aa208

Please sign in to comment.