From bc40f9abe3dfdd58095b1849a07571c02ec8de50 Mon Sep 17 00:00:00 2001 From: michalcourson Date: Thu, 26 Feb 2026 15:48:41 -0500 Subject: [PATCH] socket set up properly --- .../metadata_manager.cpython-313.pyc | Bin 10438 -> 10424 bytes audio-service/src/metadata_manager.py | 2 +- audio-service/src/routes/settings.py | 3 +- stream_deck_plugin/ClipTrimDotNet.sln | 6 - .../ClipTrimDotNet/Client/ClipMetadata.cs | 11 +- .../ClipTrimDotNet/Client/ClipTrimClient.cs | 35 +- .../Client/CollectionMetaData.cs | 6 +- .../ClipTrimDotNet/ClipTrimDotNet.csproj | 12 +- .../ClipTrimDotNet/GlobalSettings.cs | 7 +- stream_deck_plugin/ClipTrimDotNet/Player.cs | 7 +- .../ClipTrimDotNet/ProfileSwitcher.cs | 36 +- stream_deck_plugin/ClipTrimDotNet/Program.cs | 1 + .../ClipTrimDotNet/WavPlayer.cs | 398 +++++++++--------- .../ClipTrimDotNet/package.json | 4 +- 14 files changed, 267 insertions(+), 261 deletions(-) diff --git a/audio-service/src/__pycache__/metadata_manager.cpython-313.pyc b/audio-service/src/__pycache__/metadata_manager.cpython-313.pyc index b39a2683b63b4afa50f8965c98b5b7b9e745d82a..010768b12a013ad1c9278deae926792e0280f9f1 100644 GIT binary patch delta 96 zcmV-m0H6QHQMgeJ^9>CO00000jb)x`(y-MpKp&BlTqCrT6(rOF(37AbJd-9Rd;~hw3_g>qB_9VC1i>2`LmRWvCG`RU CBp;dp delta 111 zcmV-#0FeKCO00000>r9?$;;{|%AOXaa(FZ%TJs}qX0UndB0~nKSA{GWy z2vq|x0h5IyK>-PqKp&Blxf2tUYa^ira!3FG0Fw+P)B)9#;Uu^TOu#D8GfmVCPLrJ_ R9|sr&!5bPw9katF^#bI_BwGLg diff --git a/audio-service/src/metadata_manager.py b/audio-service/src/metadata_manager.py index 4282271..92d9d0b 100644 --- a/audio-service/src/metadata_manager.py +++ b/audio-service/src/metadata_manager.py @@ -95,7 +95,7 @@ class MetaDataManager: collection["clips"] = new_order if not self.socket is None: - self.socket.emit('collection_updated', {'collection': collection}) + self.socket.emit('collection_updated', collection) self.save_metadata() def save_metadata(self): diff --git a/audio-service/src/routes/settings.py b/audio-service/src/routes/settings.py index 0d153ab..d44d2e9 100644 --- a/audio-service/src/routes/settings.py +++ b/audio-service/src/routes/settings.py @@ -28,4 +28,5 @@ def set_all_settings(): SettingsManager().set_settings(name, value) return jsonify({'status': 'success', 'settings': settings}) except ValueError as e: - return jsonify({'status': 'error', 'message': str(e)}), 400 \ No newline at end of file + return jsonify({'status': 'error', 'message': str(e)}), 400 + \ No newline at end of file diff --git a/stream_deck_plugin/ClipTrimDotNet.sln b/stream_deck_plugin/ClipTrimDotNet.sln index d062cda..a71fcb9 100644 --- a/stream_deck_plugin/ClipTrimDotNet.sln +++ b/stream_deck_plugin/ClipTrimDotNet.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 17.8.34330.188 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClipTrimDotNet", "ClipTrimDotNet\ClipTrimDotNet.csproj", "{4635D874-69C0-4010-BE46-77EF92EB1553}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientTest", "ClientTest\ClientTest.csproj", "{245B4C42-D83B-4381-8B79-ECC11238CD88}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,10 +15,6 @@ Global {4635D874-69C0-4010-BE46-77EF92EB1553}.Debug|Any CPU.Build.0 = Debug|Any CPU {4635D874-69C0-4010-BE46-77EF92EB1553}.Release|Any CPU.ActiveCfg = Release|Any CPU {4635D874-69C0-4010-BE46-77EF92EB1553}.Release|Any CPU.Build.0 = Release|Any CPU - {245B4C42-D83B-4381-8B79-ECC11238CD88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {245B4C42-D83B-4381-8B79-ECC11238CD88}.Debug|Any CPU.Build.0 = Debug|Any CPU - {245B4C42-D83B-4381-8B79-ECC11238CD88}.Release|Any CPU.ActiveCfg = Release|Any CPU - {245B4C42-D83B-4381-8B79-ECC11238CD88}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/stream_deck_plugin/ClipTrimDotNet/Client/ClipMetadata.cs b/stream_deck_plugin/ClipTrimDotNet/Client/ClipMetadata.cs index 53b5aac..4960061 100644 --- a/stream_deck_plugin/ClipTrimDotNet/Client/ClipMetadata.cs +++ b/stream_deck_plugin/ClipTrimDotNet/Client/ClipMetadata.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Text.Json.Serialization; namespace ClipTrimDotNet.Client { @@ -18,27 +19,35 @@ namespace ClipTrimDotNet.Client public class ClipMetadata { [JsonProperty(PropertyName = "filename")] + [JsonPropertyName("filename")] + public string Filename { get; set; } [JsonProperty(PropertyName = "name")] + [JsonPropertyName("name")] public string Name { get; set; } [JsonProperty(PropertyName = "volume")] + [JsonPropertyName("volume")] public double Volume { get; set; } = 1.0; [JsonProperty(PropertyName = "startTime")] + [JsonPropertyName("startTime")] public double StartTime { get; set; } = 0.0; [JsonProperty(PropertyName = "endTime")] + [JsonPropertyName("endTime")] public double EndTime { get; set; } = 0.0; [JsonProperty(PropertyName = "playbackType")] - [JsonConverter(typeof(StringEnumConverter))] + [Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(JsonStringEnumConverter))] + [JsonPropertyName("playbackType")] public PlaybackType PlaybackType { get; set; } = PlaybackType.playStop; } } diff --git a/stream_deck_plugin/ClipTrimDotNet/Client/ClipTrimClient.cs b/stream_deck_plugin/ClipTrimDotNet/Client/ClipTrimClient.cs index 44370f1..c5580fb 100644 --- a/stream_deck_plugin/ClipTrimDotNet/Client/ClipTrimClient.cs +++ b/stream_deck_plugin/ClipTrimDotNet/Client/ClipTrimClient.cs @@ -38,6 +38,7 @@ namespace ClipTrimDotNet.Client // BaseAddress = new Uri("http://localhost:5010/"), // Timeout = TimeSpan.FromSeconds(10) //}; + Logger.Instance.LogMessage(TracingLevel.INFO, $"Starting ClipTrimClient on port {PortNumber}"); socket = new SocketIO(new Uri($"http://localhost:5010/")); socket.Options.AutoUpgrade = false; socket.Options.ConnectionTimeout = TimeSpan.FromSeconds(10); @@ -46,11 +47,14 @@ namespace ClipTrimDotNet.Client { try { - Collections = JsonConvert.DeserializeObject>(ctx.RawText); + var response = ctx.GetValue>(0); + Logger.Instance.LogMessage(TracingLevel.INFO, $"full_data event {JsonConvert.SerializeObject(response)}"); + Collections = response!; + //Logger.Instance.LogMessage(TracingLevel.INFO, $"Collections {JsonConvert.SerializeObject(Collections)}"); } - catch + catch (Exception ex) { - + Logger.Instance.LogMessage(TracingLevel.INFO, $"full_data error {ex.ToString()}"); } return Task.CompletedTask; }); @@ -58,18 +62,19 @@ namespace ClipTrimDotNet.Client { try { - var collection = JsonConvert.DeserializeObject(ctx.RawText); - int index = Collections.FindIndex(x => x.Id == collection.Id); - if(index != -1) + var response = ctx.GetValue(0)!; + Logger.Instance.LogMessage(TracingLevel.INFO, $"collection_updated event {JsonConvert.SerializeObject(response)}"); + int index = Collections.FindIndex(x => x.Id == response.Id); + if (index != -1) { - Collections[index] = collection; + Collections[index] = response; } } catch { } - + return Task.CompletedTask; }); @@ -89,7 +94,7 @@ namespace ClipTrimDotNet.Client //} public List Collections { get; private set; } = new List(); - public CollectionMetaData? SelectedCollection { get; private set; } + public int SelectedCollection { get; private set; } = -1; public int PageIndex { get; private set; } = 0; //private async Task GetMetadata() //{ @@ -120,21 +125,21 @@ namespace ClipTrimDotNet.Client public void SetSelectedCollectionByName(string name) { - var collection = Collections.FirstOrDefault(x => x.Name == name); - if (collection != null) + SelectedCollection = Collections.FindIndex(x => x.Name == name); + if (SelectedCollection != -1) { - SelectedCollection = collection; PageIndex = 0; } } public ClipMetadata? GetClipByPagedIndex(int index) { - if (SelectedCollection == null) return null; + if (SelectedCollection == -1) return null; int clipIndex = PageIndex * 10 + index; - if (clipIndex >= 0 && clipIndex < SelectedCollection.Clips.Count) + var collection = Collections[SelectedCollection]; + if (clipIndex >= 0 && clipIndex < collection.Clips.Count) { - return SelectedCollection.Clips[clipIndex]; + return collection.Clips[clipIndex]; } return null; } diff --git a/stream_deck_plugin/ClipTrimDotNet/Client/CollectionMetaData.cs b/stream_deck_plugin/ClipTrimDotNet/Client/CollectionMetaData.cs index f2769b7..1060ecd 100644 --- a/stream_deck_plugin/ClipTrimDotNet/Client/CollectionMetaData.cs +++ b/stream_deck_plugin/ClipTrimDotNet/Client/CollectionMetaData.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json.Serialization; using System.Threading.Tasks; namespace ClipTrimDotNet.Client @@ -10,14 +11,17 @@ namespace ClipTrimDotNet.Client public class CollectionMetaData { [JsonProperty(PropertyName = "name")] + [JsonPropertyName("name")] public string Name { get; set; } [JsonProperty(PropertyName = "clips")] + [JsonPropertyName("clips")] public List Clips { get; set; } = new List(); - [JsonProperty(PropertyName = "id")] + [JsonProperty(PropertyName = "id")] + [JsonPropertyName("id")] public int Id { get; set; } } } diff --git a/stream_deck_plugin/ClipTrimDotNet/ClipTrimDotNet.csproj b/stream_deck_plugin/ClipTrimDotNet/ClipTrimDotNet.csproj index 602281f..8d7cd41 100644 --- a/stream_deck_plugin/ClipTrimDotNet/ClipTrimDotNet.csproj +++ b/stream_deck_plugin/ClipTrimDotNet/ClipTrimDotNet.csproj @@ -1,8 +1,9 @@  - net8.0 + net8.0-windows + false Exe - 8 + 10 enable enable npm run stop @@ -28,13 +29,6 @@ - - - - - - - diff --git a/stream_deck_plugin/ClipTrimDotNet/GlobalSettings.cs b/stream_deck_plugin/ClipTrimDotNet/GlobalSettings.cs index 07c3646..c9d73ad 100644 --- a/stream_deck_plugin/ClipTrimDotNet/GlobalSettings.cs +++ b/stream_deck_plugin/ClipTrimDotNet/GlobalSettings.cs @@ -7,7 +7,6 @@ using System.Text; using System.Threading.Tasks; using BarRaider.SdTools.Wrappers; using Newtonsoft.Json.Linq; -using NAudio.MediaFoundation; namespace ClipTrimDotNet { @@ -90,18 +89,18 @@ namespace ClipTrimDotNet { return new FileEntry(); } - Logger.Instance.LogMessage(TracingLevel.INFO, "fetched file settings " + filename + JsonConvert.SerializeObject(file)); + //Logger.Instance.LogMessage(TracingLevel.INFO, "fetched file settings " + filename + JsonConvert.SerializeObject(file)); return file; } public void SetFileOptionsCurrentProfile(string filename, FileEntry file) { - Logger.Instance.LogMessage(TracingLevel.INFO, "SetFileOptionsCurrentProfile "); + //Logger.Instance.LogMessage(TracingLevel.INFO, "SetFileOptionsCurrentProfile "); if (!Collections.TryGetValue(ProfileName, out CollectionEntry collection)) { return; } - Logger.Instance.LogMessage(TracingLevel.INFO, "SetFileOptionsCurrentProfile 2"); + //Logger.Instance.LogMessage(TracingLevel.INFO, "SetFileOptionsCurrentProfile 2"); //collection.Files[filename] = file; Collections[ProfileName].Files[filename] = file; } diff --git a/stream_deck_plugin/ClipTrimDotNet/Player.cs b/stream_deck_plugin/ClipTrimDotNet/Player.cs index 5e6254e..03cc755 100644 --- a/stream_deck_plugin/ClipTrimDotNet/Player.cs +++ b/stream_deck_plugin/ClipTrimDotNet/Player.cs @@ -1,7 +1,6 @@ using BarRaider.SdTools; using BarRaider.SdTools.Wrappers; using ClipTrimDotNet.Client; -using NAudio.CoreAudioApi.Interfaces; using System.Text.Json.Serialization; using Newtonsoft.Json.Linq; using System; @@ -83,7 +82,8 @@ namespace ClipTrimDotNet //if (settings == null || GlobalSettings.Instance.ProfileName ==null) return; metadata = ClipTrimClient.Instance.GetClipByPagedIndex(GetIndex()); await Connection.SetTitleAsync($"{metadata?.Name ?? ""}"); - + //Logger.Instance.LogMessage(TracingLevel.INFO, $"Set title to {metadata?.Name ?? ""}"); + return; //var files = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(GlobalSettings.Instance.BasePath), GlobalSettings.Instance.ProfileName), "*.wav", SearchOption.TopDirectoryOnly) @@ -151,13 +151,14 @@ namespace ClipTrimDotNet } + public override void OnTick() { CheckFile(); } public override async void ReceivedSettings(ReceivedSettingsPayload payload) { - Logger.Instance.LogMessage(TracingLevel.INFO, "Player rec settings"); + //Logger.Instance.LogMessage(TracingLevel.INFO, "Player rec settings"); Tools.AutoPopulateSettings(settings, payload.Settings); GlobalSettings.Instance.SetFileOptionsCurrentProfile(settings.Path, new FileEntry() { Playtype = settings.PlayType, Volume = settings.Volume }); await Connection.SetGlobalSettingsAsync(JObject.FromObject(GlobalSettings.Instance)); diff --git a/stream_deck_plugin/ClipTrimDotNet/ProfileSwitcher.cs b/stream_deck_plugin/ClipTrimDotNet/ProfileSwitcher.cs index e22e515..3b802af 100644 --- a/stream_deck_plugin/ClipTrimDotNet/ProfileSwitcher.cs +++ b/stream_deck_plugin/ClipTrimDotNet/ProfileSwitcher.cs @@ -1,8 +1,6 @@ using BarRaider.SdTools; using BarRaider.SdTools.Wrappers; using ClipTrimDotNet.Client; -using NAudio.CoreAudioApi.Interfaces; -using NAudio.Wave; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -61,7 +59,7 @@ namespace ClipTrimDotNet private async void SetTitle() { - await Connection.SetTitleAsync(settings.ProfileName + " A"); + await Connection.SetTitleAsync(settings.ProfileName + " B"); } private async void Connection_OnSendToPlugin(object sender, SDEventReceivedEventArgs e) @@ -79,21 +77,21 @@ namespace ClipTrimDotNet //Logger.Instance.LogMessage(TracingLevel.INFO, "get profiles return " + JsonConvert.SerializeObject(obj)); await Connection.SendToPropertyInspectorAsync(obj); } - if (e.Event.Payload["event"].ToString() == "getOutputDevices") - { - List devices = new List(); - for (int n = -1; n < WaveOut.DeviceCount; n++) - { - var caps = WaveOut.GetCapabilities(n); - devices.Add(caps); - } - var items = devices.Select(x => new DataSourceItem { label = x.ProductName, value = x.ProductName }); - var obj = new JObject(); - obj["event"] = "getOutputDevices"; - obj["items"] = JArray.FromObject(items); - //Logger.Instance.LogMessage(TracingLevel.INFO, "get devices return " + JsonConvert.SerializeObject(obj)); - await Connection.SendToPropertyInspectorAsync(obj); - } + //if (e.Event.Payload["event"].ToString() == "getOutputDevices") + //{ + // List devices = new List(); + // for (int n = -1; n < WaveOut.DeviceCount; n++) + // { + // var caps = WaveOut.GetCapabilities(n); + // devices.Add(caps); + // } + // var items = devices.Select(x => new DataSourceItem { label = x.ProductName, value = x.ProductName }); + // var obj = new JObject(); + // obj["event"] = "getOutputDevices"; + // obj["items"] = JArray.FromObject(items); + // //Logger.Instance.LogMessage(TracingLevel.INFO, "get devices return " + JsonConvert.SerializeObject(obj)); + // await Connection.SendToPropertyInspectorAsync(obj); + //} } @@ -114,7 +112,7 @@ namespace ClipTrimDotNet //Logger.Instance.LogMessage(TracingLevel.INFO, JsonConvert.SerializeObject(GlobalSettings.Instance)); ClipTrimClient.Instance.SetSelectedCollectionByName(settings.ProfileName); GlobalSettings.Instance.SetCurrentProfile(settings.ProfileName); - Logger.Instance.LogMessage(TracingLevel.INFO, JsonConvert.SerializeObject(GlobalSettings.Instance)); + //Logger.Instance.LogMessage(TracingLevel.INFO, JsonConvert.SerializeObject(GlobalSettings.Instance)); await Connection.SetGlobalSettingsAsync(JObject.FromObject(GlobalSettings.Instance)); await Connection.SwitchProfileAsync("ClipTrim"); diff --git a/stream_deck_plugin/ClipTrimDotNet/Program.cs b/stream_deck_plugin/ClipTrimDotNet/Program.cs index 9b01e28..370df29 100644 --- a/stream_deck_plugin/ClipTrimDotNet/Program.cs +++ b/stream_deck_plugin/ClipTrimDotNet/Program.cs @@ -13,6 +13,7 @@ namespace ClipTrimDotNet { // Uncomment this line of code to allow for debugging //while (!System.Diagnostics.Debugger.IsAttached) { System.Threading.Thread.Sleep(100); } + Client.ClipTrimClient.Instance.PortNumber = 5010; SDWrapper.Run(args); } } diff --git a/stream_deck_plugin/ClipTrimDotNet/WavPlayer.cs b/stream_deck_plugin/ClipTrimDotNet/WavPlayer.cs index 68036b6..5c1f7ec 100644 --- a/stream_deck_plugin/ClipTrimDotNet/WavPlayer.cs +++ b/stream_deck_plugin/ClipTrimDotNet/WavPlayer.cs @@ -1,225 +1,225 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.ServiceModel.Security; -using System.Threading.Tasks; -using BarRaider.SdTools; -using NAudio.Wave; -using NAudio.Wave.SampleProviders; -using Newtonsoft.Json; +//using System; +//using System.Collections.Concurrent; +//using System.Collections.Generic; +//using System.Linq; +//using System.ServiceModel.Security; +//using System.Threading.Tasks; +//using BarRaider.SdTools; +//using NAudio.Wave; +//using NAudio.Wave.SampleProviders; +//using Newtonsoft.Json; -class CachedSound -{ - public byte[] AudioData { get; private set; } - public WaveFormat WaveFormat { get; private set; } - public CachedSound(string audioFileName) - { - using (var audioFileReader = new AudioFileReader(audioFileName)) - { - // TODO: could add resampling in here if required - WaveFormat = audioFileReader.WaveFormat; - var wholeFile = new List((int)(audioFileReader.Length)); - var readBuffer = new byte[audioFileReader.WaveFormat.SampleRate * audioFileReader.WaveFormat.Channels*4]; - int samplesRead; - while ((samplesRead = audioFileReader.Read(readBuffer, 0, readBuffer.Length)) > 0) - { - wholeFile.AddRange(readBuffer.Take(samplesRead)); - } - AudioData = wholeFile.ToArray(); - } - //Logger.Instance.LogMessage(TracingLevel.INFO, $"AudioData Length {AudioData.Length}"); +//class CachedSound +//{ +// public byte[] AudioData { get; private set; } +// public WaveFormat WaveFormat { get; private set; } +// public CachedSound(string audioFileName) +// { +// using (var audioFileReader = new AudioFileReader(audioFileName)) +// { +// // TODO: could add resampling in here if required +// WaveFormat = audioFileReader.WaveFormat; +// var wholeFile = new List((int)(audioFileReader.Length)); +// var readBuffer = new byte[audioFileReader.WaveFormat.SampleRate * audioFileReader.WaveFormat.Channels*4]; +// int samplesRead; +// while ((samplesRead = audioFileReader.Read(readBuffer, 0, readBuffer.Length)) > 0) +// { +// wholeFile.AddRange(readBuffer.Take(samplesRead)); +// } +// AudioData = wholeFile.ToArray(); +// } +// //Logger.Instance.LogMessage(TracingLevel.INFO, $"AudioData Length {AudioData.Length}"); - } -} -class CachedSoundSampleProvider : IWaveProvider -{ - private readonly CachedSound cachedSound; - private long position; +// } +//} +//class CachedSoundSampleProvider : IWaveProvider +//{ +// private readonly CachedSound cachedSound; +// private long position; - ~CachedSoundSampleProvider() { - //Logger.Instance.LogMessage(TracingLevel.INFO, $"Cache destructor"); - } +// ~CachedSoundSampleProvider() { +// //Logger.Instance.LogMessage(TracingLevel.INFO, $"Cache destructor"); +// } - public CachedSoundSampleProvider(CachedSound cachedSound) - { - this.cachedSound = cachedSound; - position = 0; - } +// public CachedSoundSampleProvider(CachedSound cachedSound) +// { +// this.cachedSound = cachedSound; +// position = 0; +// } - public int Read(byte[] buffer, int offset, int count) - { - //Logger.Instance.LogMessage(TracingLevel.INFO, $"Read1 byte"); - var availableSamples = cachedSound.AudioData.Length - position; - var samplesToCopy = Math.Min(availableSamples, count); - try - { - //Logger.Instance.LogMessage(TracingLevel.INFO, $"{cachedSound.AudioData.GetType()} {buffer.GetType()}"); - Array.Copy(cachedSound.AudioData, position, buffer, offset, samplesToCopy); - } - catch (Exception ex) - { - //Logger.Instance.LogMessage(TracingLevel.INFO, $"{ex.ToString()}"); - } - //Logger.Instance.LogMessage(TracingLevel.INFO, $"Read3"); - position += samplesToCopy; - //Logger.Instance.LogMessage(TracingLevel.INFO, $"Sending {samplesToCopy} samples"); - return (int)samplesToCopy; - } +// public int Read(byte[] buffer, int offset, int count) +// { +// //Logger.Instance.LogMessage(TracingLevel.INFO, $"Read1 byte"); +// var availableSamples = cachedSound.AudioData.Length - position; +// var samplesToCopy = Math.Min(availableSamples, count); +// try +// { +// //Logger.Instance.LogMessage(TracingLevel.INFO, $"{cachedSound.AudioData.GetType()} {buffer.GetType()}"); +// Array.Copy(cachedSound.AudioData, position, buffer, offset, samplesToCopy); +// } +// catch (Exception ex) +// { +// //Logger.Instance.LogMessage(TracingLevel.INFO, $"{ex.ToString()}"); +// } +// //Logger.Instance.LogMessage(TracingLevel.INFO, $"Read3"); +// position += samplesToCopy; +// //Logger.Instance.LogMessage(TracingLevel.INFO, $"Sending {samplesToCopy} samples"); +// return (int)samplesToCopy; +// } - public WaveFormat WaveFormat => cachedSound.WaveFormat; -} +// public WaveFormat WaveFormat => cachedSound.WaveFormat; +//} -public class WavPlayer -{ - private static WavPlayer? instance; - public static WavPlayer Instance - { - get - { - instance ??= new WavPlayer(); - return instance; - } +//public class WavPlayer +//{ +// private static WavPlayer? instance; +// public static WavPlayer Instance +// { +// get +// { +// instance ??= new WavPlayer(); +// return instance; +// } - } - public enum PlayMode - { - PlayOverlap, - PlayStop - } +// } +// public enum PlayMode +// { +// PlayOverlap, +// PlayStop +// } - private readonly ConcurrentDictionary>> _activePlayers; +// private readonly ConcurrentDictionary>> _activePlayers; - public WavPlayer() - { - _activePlayers = new ConcurrentDictionary>>(); - } +// public WavPlayer() +// { +// _activePlayers = new ConcurrentDictionary>>(); +// } - public void Play(string filePath, string id, double volume, PlayMode mode) - { - if (string.IsNullOrWhiteSpace(filePath)) - throw new ArgumentException("File path cannot be null or empty.", nameof(filePath)); +// public void Play(string filePath, string id, double volume, PlayMode mode) +// { +// if (string.IsNullOrWhiteSpace(filePath)) +// throw new ArgumentException("File path cannot be null or empty.", nameof(filePath)); - if (mode == PlayMode.PlayOverlap) - { - PlayWithOverlap(filePath, id, volume); - } - else if (mode == PlayMode.PlayStop) - { - PlayWithStop(filePath, id, volume); - } - else - { - throw new ArgumentOutOfRangeException(nameof(mode), "Invalid play mode specified."); - } - } +// if (mode == PlayMode.PlayOverlap) +// { +// PlayWithOverlap(filePath, id, volume); +// } +// else if (mode == PlayMode.PlayStop) +// { +// PlayWithStop(filePath, id, volume); +// } +// else +// { +// throw new ArgumentOutOfRangeException(nameof(mode), "Invalid play mode specified."); +// } +// } - private void PlayWithOverlap(string filePath, string id, double volume) - { +// private void PlayWithOverlap(string filePath, string id, double volume) +// { - try - { - //Logger.Instance.LogMessage(TracingLevel.INFO, "Play overlap"); - var player = CreatePlayer(filePath, id); +// try +// { +// //Logger.Instance.LogMessage(TracingLevel.INFO, "Play overlap"); +// var player = CreatePlayer(filePath, id); - if (!_activePlayers.ContainsKey(filePath)) - { - _activePlayers[filePath] = new List>(); - } +// if (!_activePlayers.ContainsKey(filePath)) +// { +// _activePlayers[filePath] = new List>(); +// } - _activePlayers[filePath].Add(player); - player.Item1.Volume = (float)volume; - player.Item1.Play(); - } - catch(Exception ex) - { - //Logger.Instance.LogMessage(TracingLevel.INFO, ex.ToString()); - } +// _activePlayers[filePath].Add(player); +// player.Item1.Volume = (float)volume; +// player.Item1.Play(); +// } +// catch(Exception ex) +// { +// //Logger.Instance.LogMessage(TracingLevel.INFO, ex.ToString()); +// } - //var playersToDispose = _activePlayers[filePath].Where(x => x.Item1.PlaybackState == PlaybackState.Stopped).ToList(); - //foreach (var p in playersToDispose) - //{ - // p.Item1.Stop(); - // p.Item1.Dispose(); - //} - //_activePlayers[filePath].RemoveAll(x => x.Item1.PlaybackState == PlaybackState.Stopped); - } +// //var playersToDispose = _activePlayers[filePath].Where(x => x.Item1.PlaybackState == PlaybackState.Stopped).ToList(); +// //foreach (var p in playersToDispose) +// //{ +// // p.Item1.Stop(); +// // p.Item1.Dispose(); +// //} +// //_activePlayers[filePath].RemoveAll(x => x.Item1.PlaybackState == PlaybackState.Stopped); +// } - private void PlayWithStop(string filePath, string id, double volume) - { - if (_activePlayers.TryGetValue(filePath, out var players)) - { +// private void PlayWithStop(string filePath, string id, double volume) +// { +// if (_activePlayers.TryGetValue(filePath, out var players)) +// { - // Stop and dispose all current players for this file - if (players.Any(x => x.Item1.PlaybackState == PlaybackState.Playing)) - { - var playersToDispose = players.ToList(); - foreach (var player in playersToDispose) - { - player.Item1.Stop(); - player.Item1.Dispose(); - } - } - else - { - PlayWithOverlap(filePath, id, volume); - } +// // Stop and dispose all current players for this file +// if (players.Any(x => x.Item1.PlaybackState == PlaybackState.Playing)) +// { +// var playersToDispose = players.ToList(); +// foreach (var player in playersToDispose) +// { +// player.Item1.Stop(); +// player.Item1.Dispose(); +// } +// } +// else +// { +// PlayWithOverlap(filePath, id, volume); +// } - } - else - { - // Start a new player - PlayWithOverlap(filePath, id, volume); - } +// } +// else +// { +// // Start a new player +// PlayWithOverlap(filePath, id, volume); +// } - _activePlayers[filePath].RemoveAll(x => x.Item1.PlaybackState == PlaybackState.Stopped); - } +// _activePlayers[filePath].RemoveAll(x => x.Item1.PlaybackState == PlaybackState.Stopped); +// } - private Tuple CreatePlayer(string filePath, string name) - { - var reader = new CachedSoundSampleProvider(new CachedSound(filePath)); - //var reader = new AudioFileReader(filePath); - int number = -1; - for (int i = 0; i < WaveOut.DeviceCount; ++i) - { - if (WaveOut.GetCapabilities(i).ProductName == name) - { - number = i; - } - } - var player = new WaveOutEvent() { DeviceNumber = number }; - player.Init(reader); - return new Tuple(player, reader); - } +// private Tuple CreatePlayer(string filePath, string name) +// { +// var reader = new CachedSoundSampleProvider(new CachedSound(filePath)); +// //var reader = new AudioFileReader(filePath); +// int number = -1; +// for (int i = 0; i < WaveOut.DeviceCount; ++i) +// { +// if (WaveOut.GetCapabilities(i).ProductName == name) +// { +// number = i; +// } +// } +// var player = new WaveOutEvent() { DeviceNumber = number }; +// player.Init(reader); +// return new Tuple(player, reader); +// } - private void CleanupPlayer(string filePath) - { - if (_activePlayers.TryGetValue(filePath, out var players)) - { - var playersToDispose = players.ToList(); - foreach (var p in playersToDispose) - { - p.Item1.Stop(); - p.Item1.Dispose(); - } - } - _activePlayers[filePath].RemoveAll(x => x.Item1.PlaybackState == PlaybackState.Stopped); +// private void CleanupPlayer(string filePath) +// { +// if (_activePlayers.TryGetValue(filePath, out var players)) +// { +// var playersToDispose = players.ToList(); +// foreach (var p in playersToDispose) +// { +// p.Item1.Stop(); +// p.Item1.Dispose(); +// } +// } +// _activePlayers[filePath].RemoveAll(x => x.Item1.PlaybackState == PlaybackState.Stopped); - } +// } - public void StopAll() - { - foreach (var players in _activePlayers.Values) - { - var playersToDispose = players.ToList(); - foreach (var player in playersToDispose) - { - player.Item1.Stop(); - player.Item1.Dispose(); - } - players.Clear(); - } +// public void StopAll() +// { +// foreach (var players in _activePlayers.Values) +// { +// var playersToDispose = players.ToList(); +// foreach (var player in playersToDispose) +// { +// player.Item1.Stop(); +// player.Item1.Dispose(); +// } +// players.Clear(); +// } - _activePlayers.Clear(); - } -} +// _activePlayers.Clear(); +// } +//} diff --git a/stream_deck_plugin/ClipTrimDotNet/package.json b/stream_deck_plugin/ClipTrimDotNet/package.json index c55417b..3ab40ee 100644 --- a/stream_deck_plugin/ClipTrimDotNet/package.json +++ b/stream_deck_plugin/ClipTrimDotNet/package.json @@ -1,12 +1,12 @@ { "scripts": { "stop": "streamdeck stop com.michal-courson.cliptrim", - "copy": "@powershell robocopy bin/Debug/ClipTrimDotNet.sdPlugin bin/Debug/com.michal-courson.cliptrim.sdPlugin", + "copy": "@powershell robocopy bin/Debug/ClipTrimDotNet.sdPlugin bin/Debug/com.michal-courson.cliptrim.sdPlugin/net8.0-windows", "link": "streamdeck link bin/Debug/com.michal-courson.cliptrim.sdPlugin", "restart": "streamdeck restart com.michal-courson.cliptrim", "start": "npm run link && npm run restart", "all": "npm run stop && npm run copy && npm run link && npm run restart", - "pack": "streamdeck pack bin/Debug/com.michal-courson.cliptrim.sdPlugin/" + "pack": "streamdeck pack bin/Debug/com.michal-courson.cliptrim.sdPlugin/net8.0-windows/" }, "devDependencies": { "shx": "^0.3.4"