Skip to content

Commit

Permalink
Added Support for VRP Scripts, [num 7] will toggle SBS mode
Browse files Browse the repository at this point in the history
  • Loading branch information
FredTungsten committed Jul 24, 2017
1 parent 9a0c554 commit d53c799
Show file tree
Hide file tree
Showing 17 changed files with 302 additions and 46 deletions.
2 changes: 1 addition & 1 deletion ScriptPlayer/ScriptPlayer.Shared/ButtplugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task<bool> Connect()

return true;
}
catch(Exception e)
catch(Exception)
{
_client = null;
return false;
Expand Down
2 changes: 1 addition & 1 deletion ScriptPlayer/ScriptPlayer.Shared/ColorSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void TakeSample(TimeSpan timestamp)

Color average = SampleCondition.GetAverageColor(rgbPixels);

if (!_colorsByTime.Any(i => i.Item1 == timestamp))
if (_colorsByTime.All(i => i.Item1 != timestamp))
{
_colorsByTime.Add(new Tuple<TimeSpan, Color>(timestamp, average));

Expand Down
4 changes: 2 additions & 2 deletions ScriptPlayer/ScriptPlayer.Shared/Controls/BeatBar2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ protected override void OnRender(DrawingContext drawingContext)
IEnumerable<double> relativeBeatPositions =
absoluteBeatPositions.Select(b => (b - timeFrom).Divide(timeTo - timeFrom));

const double safeSpace = 30;
double y = ActualHeight / 2.0;
//const double safeSpace = 30;
//double y = ActualHeight / 2.0;

//DrawLine(drawingContext, Colors.Red, new Point(-safeSpace, y),
// new Point(ActualWidth + safeSpace, y));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public double PositionChangesPerSecond
set { SetValue(PositionChangesPerSecondProperty, value); }
}

private double _targetPosition;
private double _targetSpeed;
//private double _targetPosition;
//private double _targetSpeed;

public LaunchSimulator()
{
Expand Down
26 changes: 24 additions & 2 deletions ScriptPlayer/ScriptPlayer.Shared/Controls/SeekBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ static SeekBar()
BackgroundProperty.OverrideMetadata(typeof(SeekBar), new FrameworkPropertyMetadata(Brushes.Black, FrameworkPropertyMetadataOptions.AffectsRender));
}

public static readonly DependencyProperty OverlayProperty = DependencyProperty.Register(
"Overlay", typeof(Brush), typeof(SeekBar), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));

public Brush Overlay
{
get { return (Brush) GetValue(OverlayProperty); }
set { SetValue(OverlayProperty, value); }
}

public static readonly DependencyProperty OverlayOpacityProperty = DependencyProperty.Register(
"OverlayOpacity", typeof(Brush), typeof(SeekBar), new FrameworkPropertyMetadata(Brushes.Black, FrameworkPropertyMetadataOptions.AffectsRender));

public Brush OverlayOpacity
{
get { return (Brush) GetValue(OverlayOpacityProperty); }
set { SetValue(OverlayOpacityProperty, value); }
}

public static readonly DependencyProperty ProgressProperty = DependencyProperty.Register(
"Progress", typeof(TimeSpan), typeof(SeekBar), new PropertyMetadata(default(TimeSpan), OnVisualPropertyChanged));
Expand Down Expand Up @@ -83,15 +100,20 @@ protected override void OnRender(DrawingContext dc)

dc.PushClip(new RectangleGeometry(rect));

dc.DrawRectangle(Brushes.Black, null, rect);
dc.DrawRectangle(Background, null, rect);
dc.PushOpacityMask(OverlayOpacity);

dc.DrawRectangle(Overlay, null, rect);

dc.Pop();

if (Duration == TimeSpan.Zero) return;

double linePosition = Progress.Divide(Duration) * ActualWidth;

dc.DrawRectangle(new LinearGradientBrush(HeatMapGenerator.GradientsSmoothFromColors(0.5, Color.FromArgb(0,0,0,0), Color.FromArgb(150,0,0,0), Color.FromArgb(0, 0, 0, 0)), new Point(0,0), new Point(1,0)), null, new Rect(linePosition-10,0,20, ActualHeight));
//dc.DrawRectangle(new LinearGradientBrush(HeatMapGenerator.GradientsSmoothFromColors(0.5, Color.FromArgb(0,0,0,0), Color.FromArgb(150,0,0,0), Color.FromArgb(0, 0, 0, 0)), new Point(0,0), new Point(1,0)), null, new Rect(linePosition-10,0,20, ActualHeight));

dc.DrawLine(new Pen(Brushes.Black, 3), new Point(linePosition, 0), new Point(linePosition, ActualHeight));
dc.DrawLine(new Pen(Brushes.White, 1), new Point(linePosition,0), new Point(linePosition, ActualHeight));

dc.Pop();
Expand Down
48 changes: 45 additions & 3 deletions ScriptPlayer/ScriptPlayer.Shared/Controls/VideoPlayer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;

namespace ScriptPlayer.Shared
{
Expand Down Expand Up @@ -160,6 +159,8 @@ public TimeSpan Duration
set { SetValue(DurationProperty, value); }
}

protected Resolution ActualResolution { get; set; }

public static readonly DependencyProperty TimeSourceProperty = DependencyProperty.Register(
"TimeSource", typeof(TimeSource), typeof(VideoPlayer), new PropertyMetadata(default(TimeSource)));

Expand Down Expand Up @@ -189,6 +190,18 @@ public Brush VideoBrush

private double _scale;
private Point _offset;
private bool _sideBySide;

public bool SideBySide
{
get { return _sideBySide; }
set
{
_sideBySide = value;
UpdateVideoBrush();
UpdateResolution();
}
}

public RelayCommand PlayCommand { get; }
public RelayCommand PauseCommand { get; }
Expand Down Expand Up @@ -267,7 +280,30 @@ private void InitializePlayer()
TimeSource = new MediaPlayerTimeSource(_player,
new DispatcherClock(Dispatcher, TimeSpan.FromMilliseconds(10)));

VideoBrush = new DrawingBrush(new VideoDrawing { Player = _player, Rect = new Rect(0, 0, 1, 1) }) { Stretch = Stretch.Fill };
UpdateVideoBrush();
}

private void UpdateVideoBrush()
{
if (_player == null)
return;

Rect rect = new Rect(0, 0, 1, 1);

if(SideBySide)
rect = new Rect(0,0,0.5,1);

VideoBrush = new DrawingBrush(
new VideoDrawing
{
Player = _player,
Rect = rect,

})
{
Stretch = Stretch.Fill,
Viewbox = rect
};
}

private void PlayerOnMediaEnded(object sender, EventArgs eventArgs)
Expand All @@ -279,10 +315,16 @@ private void PlayerOnMediaEnded(object sender, EventArgs eventArgs)
private void PlayerOnMediaOpened(object sender, EventArgs e)
{
Duration = _player.NaturalDuration.TimeSpan;
Resolution = new Resolution(_player.NaturalVideoWidth, _player.NaturalVideoHeight);
ActualResolution = new Resolution(_player.NaturalVideoWidth, _player.NaturalVideoHeight);
UpdateResolution();
OnMediaOpened();
}

private void UpdateResolution()
{
Resolution = !SideBySide ? ActualResolution : new Resolution(ActualResolution.Horizontal / 2, ActualResolution.Vertical);
}

private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 1)
Expand Down
4 changes: 2 additions & 2 deletions ScriptPlayer/ScriptPlayer.Shared/FrameCaptureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ public TimeSpan FrameIndexToTimeSpan(long frameIndex)
return roundedTimeSpan;

//Even Int64 isn't enought ....
long timeSpanTicksMs = (frameIndex * DurationNumerator * (TimeSpan.TicksPerSecond / TimeSpan.TicksPerMillisecond) ) / (TotalFramesInVideo * DurationDenominator);
/*long timeSpanTicksMs = (frameIndex * DurationNumerator * (TimeSpan.TicksPerSecond / TimeSpan.TicksPerMillisecond) ) / (TotalFramesInVideo * DurationDenominator);
TimeSpan timestamp = TimeSpan.FromTicks(timeSpanTicksMs * TimeSpan.TicksPerMillisecond);
if (Math.Abs((timestamp - roundedTimeSpan).TotalSeconds) > 0.1)
{
Debug.Write("oO!");
}
return timestamp;
return timestamp;*/
}
}
}
2 changes: 2 additions & 0 deletions ScriptPlayer/ScriptPlayer.Shared/ScriptPlayer.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<Compile Include="RepeatingScriptActions.cs" />
<Compile Include="SampleAnalyser.cs" />
<Compile Include="Scripts\BeatsToFunScriptConverter.cs" />
<Compile Include="Scripts\IniReader.cs" />
<Compile Include="Scripts\ScriptActionEventArgs.cs" />
<Compile Include="Scripts\ScriptFileFormat.cs" />
<Compile Include="Scripts\ScriptFileFormatCollection.cs" />
Expand All @@ -160,6 +161,7 @@
<Compile Include="Scripts\ScriptAction.cs" />
<Compile Include="Converters\StringToVersionConverter.cs" />
<Compile Include="Scripts\ScriptLoaderManager.cs" />
<Compile Include="Scripts\VirtualRealPornScriptReader.cs" />
<Compile Include="Scripts\VorzeScriptAction.cs" />
<Compile Include="Scripts\VorzeScriptLoader.cs" />
<Compile Include="Sounds\SoundResources.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public enum ConversionMode

public static class BeatsToFunScriptConverter
{


public static List<FunScriptAction> Convert(IEnumerable<TimeSpan> timestamps, ConversionMode mode)
{
var beats = timestamps.ToList();
Expand Down
109 changes: 109 additions & 0 deletions ScriptPlayer/ScriptPlayer.Shared/Scripts/IniReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace ScriptPlayer.Shared.Scripts
{
public class IniFile
{
public List<IniCategory> Categories { get; set; }

public IniFile()
{
Categories = new List<IniCategory>();
}

public static IniFile FromFile(string path)
{
using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
return FromStream(stream);
}

public static IniFile FromStream(Stream stream)
{
IniFile result = new IniFile();
IniCategory currentCategory = null;

using (StreamReader reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
if (string.IsNullOrWhiteSpace(line))
continue;

line = line.Trim();

if (line.StartsWith("["))
{
int to = line.IndexOf("]", StringComparison.Ordinal);
string name = line.Substring(1, to - 1);
currentCategory = new IniCategory { Name = name };
result.Categories.Add(currentCategory);
}
else if (currentCategory == null)
{
Debug.WriteLine("Uncategorized Entry: " + line);
}
else
{
int equalSign = line.IndexOf("=", StringComparison.Ordinal);
if (equalSign < 0)
{
Debug.WriteLine("Can't parse line: " + line);
}
else
{
string name = line.Substring(0, equalSign);
string value = line.Substring(equalSign + 1);
currentCategory.Entries.Add(new IniEntry
{
Name = name,
Value = value
});
}
}
}
}

return result;
}

public IniCategory this[string name]
{
get
{
return Categories.FirstOrDefault(
e => String.Equals(e.Name, name, StringComparison.InvariantCultureIgnoreCase));
}
}
}

public class IniCategory
{
public IniEntry this[string name]
{
get
{
return Entries.FirstOrDefault(
e => String.Equals(e.Name, name, StringComparison.InvariantCultureIgnoreCase));
}
}

public string Name { get; set; }
public List<IniEntry> Entries { get; set; }

public IniCategory()
{
Entries = new List<IniEntry>();
}
}

public class IniEntry
{
public string Name { get; set; }
public string Value { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ namespace ScriptPlayer.Shared.Scripts
{
public class ScriptFileFormatCollection
{
private List<ScriptFileFormat> _list;
private readonly List<ScriptFileFormat> _list;
private bool _includeAll;
private bool _includeAny;

public ScriptFileFormat GetFormat(int selectedIndex, string filename)
public ScriptFileFormat[] GetFormats(int selectedIndex, string filename)
{
string extension = Path.GetExtension(filename).TrimStart('.').ToLower();

if ((_includeAll && selectedIndex == 0) || (selectedIndex < 0))
return GetFormatByExtension(extension);
return GetFormatsByExtension(extension);

if(_includeAll)
selectedIndex--;

if(selectedIndex >= _list.Count)
throw new ArgumentException("A ScriptFileFormat with the specified selectedIndex does not exist!", nameof(selectedIndex));

return _list[selectedIndex];
return new[]{_list[selectedIndex]};
}

private ScriptFileFormat GetFormatByExtension(string extension)
private ScriptFileFormat[] GetFormatsByExtension(string extension)
{
return _list.FirstOrDefault(f => f.Extensions.Contains(extension, StringComparer.OrdinalIgnoreCase));
return _list.Where(f => f.Extensions.Contains(extension, StringComparer.OrdinalIgnoreCase)).ToArray();
}

public string BuildFilter(bool includeAll)
Expand Down
3 changes: 3 additions & 0 deletions ScriptPlayer/ScriptPlayer.Shared/Scripts/ScriptLoader.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;

namespace ScriptPlayer.Shared.Scripts
{
public abstract class ScriptLoader
{
protected CultureInfo Culture = CultureInfo.InvariantCulture;

public abstract List<ScriptAction> Load(Stream stream);

public abstract List<ScriptFileFormat> GetSupportedFormats();
Expand Down
Loading

0 comments on commit d53c799

Please sign in to comment.