183 lines
5.4 KiB
C#
183 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using DccToolToTempoBlasterPlugin;
|
|
using Sony.Vegas;
|
|
using UAF.Remoting;
|
|
|
|
namespace VegasToTempoBlasterPlugin
|
|
{
|
|
|
|
/// <summary>
|
|
/// Handles operations for community mashups.
|
|
/// </summary>
|
|
public class CommunityMashupPluginHandler
|
|
{
|
|
|
|
#region Attributes
|
|
|
|
private readonly DccToTempoBlasterPlugin _plugin;
|
|
private readonly Vegas _vegas;
|
|
private bool _sendCommunityMashupData;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
public CommunityMashupPluginHandler(DccToTempoBlasterPlugin plugin, Vegas vegas)
|
|
{
|
|
_plugin = plugin;
|
|
_vegas = vegas;
|
|
_sendCommunityMashupData = false;
|
|
|
|
_plugin.RegisterHandler("GetCommunityMashup", BeginSendCommunityMashupData);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public
|
|
|
|
/// <summary>
|
|
/// Ticks current instance. Checks if the handler should send Community Mashup data.
|
|
/// </summary>
|
|
public void Tick()
|
|
{
|
|
if (_sendCommunityMashupData)
|
|
{
|
|
SendCommunityMashupData();
|
|
_sendCommunityMashupData = false;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private
|
|
|
|
/// <summary>
|
|
/// Sends community mashup data to client.
|
|
/// </summary>
|
|
private void SendCommunityMashupData()
|
|
{
|
|
var tracksList = _vegas.Project.Tracks.Where(x => x.IsVideo() && x.IsValid()).ToArray();
|
|
var dataList = new List<VideoEventData>();
|
|
|
|
foreach (var track in tracksList)
|
|
foreach (var videoEvent in track.Events.Where(x => x.IsVideo() && x.IsValid() && IsVideoMedia(x.ActiveTake.MediaPath)))
|
|
dataList.Add(new VideoEventData(videoEvent.ActiveTake.MediaPath, videoEvent.Start.ToMilliseconds(), videoEvent.End.ToMilliseconds()));
|
|
|
|
// Create the data to send.
|
|
var blob = new Blob();
|
|
blob.Push(dataList.Count);
|
|
foreach (var data in dataList)
|
|
{
|
|
blob.Push(data.PlayerName);
|
|
blob.Push(data.AvatarId);
|
|
blob.Push(data.CountryId);
|
|
blob.Push(data.Start);
|
|
blob.Push(data.End);
|
|
}
|
|
|
|
_plugin.Send(new UAF.Remoting.Message("SendCommunityMashup", blob));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Flags main thread to send CMU Data.
|
|
/// </summary>
|
|
/// <param name="blob">Content of the message. (unused)</param>
|
|
private void BeginSendCommunityMashupData(IBlob blob)
|
|
{
|
|
_sendCommunityMashupData = true;
|
|
}
|
|
|
|
private bool IsVideoMedia(string mediaPath)
|
|
{
|
|
return mediaPath.EndsWith(".mov", StringComparison.InvariantCultureIgnoreCase) ||
|
|
mediaPath.EndsWith(".mp4", StringComparison.InvariantCultureIgnoreCase) ||
|
|
mediaPath.EndsWith(".webm", StringComparison.InvariantCultureIgnoreCase) ||
|
|
mediaPath.EndsWith(".wmv", StringComparison.InvariantCultureIgnoreCase);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Nested
|
|
|
|
/// <summary>
|
|
/// Data container for video events.
|
|
/// </summary>
|
|
private class VideoEventData
|
|
{
|
|
|
|
/// <summary>
|
|
/// Start time of the event (in milliseconds).
|
|
/// </summary>
|
|
public double Start { get; private set; }
|
|
|
|
/// <summary>
|
|
/// End time of the event (in milliseconds).
|
|
/// </summary>
|
|
public double End { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Path to the video.
|
|
/// </summary>
|
|
public string VideoPath { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Name of the file to the video.
|
|
/// </summary>
|
|
public string VideoFilename
|
|
{
|
|
get { return VideoPath.Split('/').Last().Split('\\').Last(); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Name of the player.
|
|
/// </summary>
|
|
public string PlayerName { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Id of the player avatar.
|
|
/// </summary>
|
|
public ulong AvatarId { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Id of the country selected by the player.
|
|
/// </summary>
|
|
public string CountryId { get; private set; }
|
|
|
|
public VideoEventData(string videoPath, double start, double end)
|
|
{
|
|
VideoPath = videoPath;
|
|
Start = start;
|
|
End = end;
|
|
|
|
ParseData();
|
|
}
|
|
|
|
private void ParseData()
|
|
{
|
|
// First removing the extension.
|
|
var filename = VideoFilename;
|
|
var extensionIndex = filename.LastIndexOf('.');
|
|
if (extensionIndex != -1)
|
|
filename = filename.Substring(0, extensionIndex);
|
|
|
|
// Now parsing the data.
|
|
var data = filename.Split('_');
|
|
ulong avatarId;
|
|
|
|
PlayerName = data[3];
|
|
ulong.TryParse(data[4], out avatarId);
|
|
AvatarId = avatarId;
|
|
CountryId = data[1];
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|