Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop span command #3

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Intermediates/*
Binaries/*
.vs/*
obj/*
bin/*
114 changes: 104 additions & 10 deletions CommandSupport/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,110 @@ public static string ConvertMetadataValueToString(object metadataValue)
return result;
}

/// <summary>
/// Updates (adds/edits) file-level metadata in an event file
/// </summary>
/// <param name="client">KStudioClient to use for accessing the event file</param>
/// <param name="fileName">Path to event file</param>
/// <param name="type">Type of metadata (Public or Personal)</param>
/// <param name="key">Key of metadata object to add/edit</param>
/// <param name="value">Value of metadata object to add/edit</param>
/// <returns>String which contains the updated contents of the target metadata object</returns>
public static string UpdateFileMetadata(KStudioClient client, string fileName, KStudioMetadataType type, string key, object value)
/// <summary>
/// Queries file-level metadata in an event file
/// </summary>
/// <param name="client">KStudioClient to use for accessing the event file</param>
/// <param name="fileName">Path to event file</param>
/// <param name="type">Type of metadata (Public or Personal)</param>
/// <param name="key">Key of metadata object to query</param>
/// <param name="value">Target metadata object value returned through an out parameter modifier</param>
/// <returns>String which contains the contents of the target metadata object</returns>
public static string QueryFileMetadata(KStudioClient client, string fileName, KStudioMetadataType type, string key,out object value)
{
value = null;

if (client == null)
{
throw new ArgumentNullException("client");
}

if (string.IsNullOrEmpty(fileName))
{
throw new ArgumentNullException("fileName");
}

string metadataText = string.Empty;

using (KStudioEventFile file = client.OpenEventFile(fileName))
{
KStudioMetadata metadata = file.GetMetadata(type);
if (!metadata.ContainsKey(key))
{
throw new KeyNotFoundException("key");
}
value = metadata[key];
metadataText = Metadata.GetMetadataAsText(metadata, type, string.Empty);
}

return metadataText;
}

/// <summary>
/// Queries stream-level metadata in an event file
/// </summary>
/// <param name="client">KStudioClient to use for accessing the event file</param>
/// <param name="fileName">Path to event file</param>
/// <param name="streamName">Name of stream which should contain the metadata</param>
/// <param name="type">Type of metadata to update (Public or Personal)</param>
/// <param name="key">Key of metadata object to query</param>
/// <param name="value">Target metadata object value returned through an out parameter modifier</param>
/// <returns>String which contains the contents of the target metadata object</returns>
public static string QueryStreamMetadata(KStudioClient client, string fileName, string streamName, KStudioMetadataType type, string key, out object value)
{
value = null;
if (client == null)
{
throw new ArgumentNullException("client");
}

if (string.IsNullOrEmpty(fileName))
{
throw new ArgumentNullException("fileName");
}

if (string.IsNullOrEmpty(streamName))
{
throw new ArgumentNullException("streamName");
}

string metadataText = string.Empty;

using (KStudioEventFile file = client.OpenEventFile(fileName))
{
// find the stream in the file and alter its metadata
Guid dataTypeId = StreamSupport.ConvertStreamStringToGuid(streamName);
if (dataTypeId == KStudioEventStreamDataTypeIds.Null)
{
throw new InvalidOperationException(Strings.ErrorNullStream);
}

KStudioEventStream stream = file.EventStreams.FirstOrDefault(s => s.DataTypeId == dataTypeId);
if (stream != null)
{
KStudioMetadata metadata = stream.GetMetadata(type);
if (!metadata.ContainsKey(key))
{
throw new KeyNotFoundException("key");
}
value = metadata[key];
metadataText = Metadata.GetMetadataAsText(metadata, type, stream.DataTypeName);
}
}

return metadataText;
}

/// <summary>
/// Updates (adds/edits) file-level metadata in an event file
/// </summary>
/// <param name="client">KStudioClient to use for accessing the event file</param>
/// <param name="fileName">Path to event file</param>
/// <param name="type">Type of metadata (Public or Personal)</param>
/// <param name="key">Key of metadata object to add/edit</param>
/// <param name="value">Value of metadata object to add/edit</param>
/// <returns>String which contains the updated contents of the target metadata object</returns>
public static string UpdateFileMetadata(KStudioClient client, string fileName, KStudioMetadataType type, string key, object value)
{
if (client == null)
{
Expand Down
74 changes: 73 additions & 1 deletion CommandSupport/Playback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,77 @@ private static void VerifyStreamsForPlayback(KStudioClient client, string filePa
}
}
}
}

public static void PlaybackClip(KStudioClient client, string filePath, List<string> streamNames, uint loopCount, TimeSpan startingRelativeTime, TimeSpan endingRelativeTime)
{
if (client == null)
{
throw new ArgumentNullException("client");
}

if (!client.IsServiceConnected)
{
throw new InvalidOperationException(Strings.ErrorNotConnected);
}

if (string.IsNullOrEmpty(filePath))
{
throw new ArgumentNullException("filePath");
}

KStudioPlayback playback = null;

// determine if all specified streams are valid for playback
if (streamNames.Count<string>() > 0)
{
HashSet<Guid> playbackDataTypeIds = StreamSupport.ConvertStreamsToPlaybackGuids(streamNames);
StreamSupport.VerifyStreamsForRecordAndPlayback(playbackDataTypeIds);
Playback.VerifyStreamsForPlayback(client, filePath, playbackDataTypeIds);

try
{
KStudioEventStreamSelectorCollection streams = StreamSupport.CreateStreamCollection(playbackDataTypeIds, false);
playback = client.CreatePlayback(filePath, streams);
}
catch (Exception)
{
//K4W supports uncompressed and compressed color, so if we get an error, try playing the other type
KStudioEventStreamSelectorCollection streams = StreamSupport.CreateStreamCollection(playbackDataTypeIds, true);
playback = client.CreatePlayback(filePath, streams);
}
}
else
{
playback = client.CreatePlayback(filePath);
}

// begin playback
using (playback)
{
playback.EndBehavior = KStudioPlaybackEndBehavior.Stop; // this is the default behavior
playback.Mode = KStudioPlaybackMode.TimingEnabled; // this is the default behavior
playback.LoopCount = loopCount;
if (startingRelativeTime != TimeSpan.MinValue)
{
playback.InPointByRelativeTime = startingRelativeTime;
}
if (endingRelativeTime != TimeSpan.MinValue)
{
playback.OutPointByRelativeTime = endingRelativeTime;
}

playback.Start();

while (playback.State == KStudioPlaybackState.Playing)
{
Thread.Sleep(500);
}

if (playback.State == KStudioPlaybackState.Error)
{
throw new InvalidOperationException(Strings.ErrorPlaybackFailed);
}
}
}
}
}
2 changes: 1 addition & 1 deletion KSUtil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KSUtil</RootNamespace>
<AssemblyName>KSUtil</AssemblyName>
<AssemblyName>KSUtilExtended</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand Down
Loading