start of migration
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
using BarRaider.SdTools;
|
||||
using BarRaider.SdTools.Wrappers;
|
||||
using ClipTrimDotNet.Client;
|
||||
using NAudio.CoreAudioApi.Interfaces;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@ -18,9 +19,8 @@ namespace ClipTrimDotNet
|
||||
public class Player : KeypadBase
|
||||
{
|
||||
|
||||
private TitleParameters? titleParameters = null;
|
||||
private string userTitle;
|
||||
private static int counter = 0;
|
||||
private ClipMetadata? metadata;
|
||||
private KeyCoordinates coordinates;
|
||||
private class PluginSettings
|
||||
{
|
||||
public static PluginSettings CreateDefaultSettings()
|
||||
@ -62,6 +62,7 @@ namespace ClipTrimDotNet
|
||||
{
|
||||
this.settings = payload.Settings.ToObject<PluginSettings>();
|
||||
}
|
||||
this.coordinates = payload.Coordinates;
|
||||
GlobalSettingsManager.Instance.RequestGlobalSettings();
|
||||
CheckFile();
|
||||
}
|
||||
@ -71,34 +72,43 @@ namespace ClipTrimDotNet
|
||||
Tools.AutoPopulateSettings(GlobalSettings.Instance, e.Settings);
|
||||
}
|
||||
|
||||
public int GetIndex()
|
||||
{
|
||||
return Math.Max((coordinates.Row - 1) * 5 + coordinates.Column, 0);
|
||||
}
|
||||
|
||||
private async void CheckFile()
|
||||
{
|
||||
|
||||
if (settings == null || GlobalSettings.Instance.BasePath == null || GlobalSettings.Instance.ProfileName ==null) return;
|
||||
//if (settings == null || GlobalSettings.Instance.ProfileName ==null) return;
|
||||
metadata = ClipTrimClient.Instance.GetClipByPagedIndex(GetIndex());
|
||||
await Connection.SetTitleAsync($"{metadata?.Name ?? ""}");
|
||||
|
||||
return;
|
||||
|
||||
var files = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(GlobalSettings.Instance.BasePath), GlobalSettings.Instance.ProfileName), "*.wav", SearchOption.TopDirectoryOnly)
|
||||
.OrderBy(file => File.GetCreationTime(file))
|
||||
.ToArray();
|
||||
int? i = this.settings.Index;
|
||||
string new_path = "";
|
||||
if (i != null && i >= 0 && i < files.Length)
|
||||
{
|
||||
new_path = files[i ?? 0];
|
||||
}
|
||||
//var files = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(GlobalSettings.Instance.BasePath), GlobalSettings.Instance.ProfileName), "*.wav", SearchOption.TopDirectoryOnly)
|
||||
// .OrderBy(file => File.GetCreationTime(file))
|
||||
// .ToArray();
|
||||
//int? i = this.settings.Index;
|
||||
//string new_path = "";
|
||||
//if (i != null && i >= 0 && i < files.Length)
|
||||
//{
|
||||
// new_path = files[i ?? 0];
|
||||
//}
|
||||
|
||||
|
||||
await Connection.SetTitleAsync(Path.GetFileNameWithoutExtension(new_path));
|
||||
if (new_path != settings.Path)
|
||||
{
|
||||
settings.Path = new_path;
|
||||
if(new_path != "")
|
||||
{
|
||||
FileEntry opts = GlobalSettings.Instance.GetFileOptionsInCurrentProfile(new_path);
|
||||
settings.Volume = opts.Volume;
|
||||
settings.PlayType = opts.Playtype;
|
||||
}
|
||||
await SaveSettings();
|
||||
}
|
||||
//await Connection.SetTitleAsync(Path.GetFileNameWithoutExtension(new_path));
|
||||
//if (new_path != settings.Path)
|
||||
//{
|
||||
// settings.Path = new_path;
|
||||
// if(new_path != "")
|
||||
// {
|
||||
// FileEntry opts = GlobalSettings.Instance.GetFileOptionsInCurrentProfile(new_path);
|
||||
// settings.Volume = opts.Volume;
|
||||
// settings.PlayType = opts.Playtype;
|
||||
// }
|
||||
// await SaveSettings();
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
@ -109,8 +119,8 @@ namespace ClipTrimDotNet
|
||||
|
||||
private void Connection_OnTitleParametersDidChange(object sender, SDEventReceivedEventArgs<BarRaider.SdTools.Events.TitleParametersDidChange> e)
|
||||
{
|
||||
titleParameters = e.Event?.Payload?.TitleParameters;
|
||||
userTitle = e.Event?.Payload?.Title;
|
||||
//titleParameters = e.Event?.Payload?.TitleParameters;
|
||||
//userTitle = e.Event?.Payload?.Title;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
@ -124,15 +134,16 @@ namespace ClipTrimDotNet
|
||||
{
|
||||
//Logger.Instance.LogMessage(TracingLevel.INFO, "Key Pressedd");
|
||||
Tools.AutoPopulateSettings(settings, payload.Settings);
|
||||
// Logger.Instance.LogMessage(TracingLevel.INFO, JsonConvert.SerializeObject(settings));
|
||||
try
|
||||
{
|
||||
WavPlayer.Instance.Play(settings.Path, GlobalSettings.Instance.OutputDevice, settings.Volume, settings.PlayType == "Play/Overlap" ? WavPlayer.PlayMode.PlayOverlap : WavPlayer.PlayMode.PlayStop);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Logger.Instance.LogMessage(TracingLevel.INFO, JsonConvert.SerializeObject(settings));
|
||||
ClipTrimClient.Instance.PlayClip(metadata);
|
||||
//try
|
||||
//{
|
||||
// WavPlayer.Instance.Play(settings.Path, GlobalSettings.Instance.OutputDevice, settings.Volume, settings.PlayType == "Play/Overlap" ? WavPlayer.PlayMode.PlayOverlap : WavPlayer.PlayMode.PlayStop);
|
||||
//}
|
||||
//catch
|
||||
//{
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user