Skip to content

Commit

Permalink
OscQuery Megacommit (Early release approved by Momo)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaciStardust committed Dec 15, 2022
1 parent a86cac2 commit 3ce8f57
Show file tree
Hide file tree
Showing 29 changed files with 699 additions and 156 deletions.
69 changes: 50 additions & 19 deletions OscMultitool/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,27 @@ public static void SaveConfig()
#endregion

#region Utility
public static int MinMax(int value, int min, int max)
=> Math.Max(Math.Min(max, value), min);
public static float MinMax(float value, float min, float max)
=> Math.Max(Math.Min(max, value), min);
/// <summary>
/// A combination of floor and ceil for comparables
/// </summary>
/// <typeparam name="T">Type to compare</typeparam>
/// <param name="value">Value to compare</param>
/// <param name="min">Minimum value</param>
/// <param name="max">Maximum value</param>
/// <returns>Value, if within bounds. Min, if value smaller than min. Max, if value larger than max. If max is smaller than min, min has priority</returns>
public static T MinMax<T>(T value, T min, T max) where T : IComparable
{
if (value.CompareTo(min) < 0)
return min;
if (value.CompareTo(max) > 0)
return max;
return value;
}

public static string GetVersion()
{
var assembly = System.Reflection.Assembly.GetEntryAssembly();
return "v." + (assembly != null ? FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion : "Version Unknown");
var assembly = Assembly.GetEntryAssembly();
return "v." + (assembly != null ? FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion : "???");
}

/// <summary>
Expand Down Expand Up @@ -128,7 +140,6 @@ private static ConfigModel GetDefaultConfig()

return config;
}

#endregion

#region Models
Expand All @@ -150,21 +161,28 @@ public class ConfigModel
/// </summary>
public class ConfigOscModel
{
//Routing
public string Ip { get; set; } = "127.0.0.1";
public int Port { get; set; } = 9000;
public int PortListen { get; set; } = 9001;
public string AddressManualMute { get; set; } = "/avatar/parameters/ToolMute";
public string AddressManualSkipSpeech { get; set; } = "/avatar/parameters/ToolSkipSpeech";
public string AddressManualSkipBox { get; set; } = "/avatar/parameters/ToolSkipBox";
public List<OscRoutingFilterModel> RoutingFilters { get; set; } = new();

//Addresses
public string AddressManualMute { get; set; } = "/avatar/parameters/ToolMute";
public string AddressManualSkipSpeech { get; set; } = "/avatar/parameters/ToolSkipSpeech";
public string AddressManualSkipBox { get; set; } = "/avatar/parameters/ToolSkipBox";
public string AddressEnableReplacements { get; set; } = "/avatar/parameters/ToolEnableReplacements";
public string AddressEnableTextbox { get; set; } = "/avatar/parameters/ToolEnableBox";
public string AddressEnableTts { get; set; } = "/avatar/parameters/ToolEnableTts";
public string AddressEnableAutoMute { get; set; } = "/avatar/parameters/ToolEnableAutoMute";
public string AddressEnableTextbox { get; set; } = "/avatar/parameters/ToolEnableBox";
public string AddressEnableTts { get; set; } = "/avatar/parameters/ToolEnableTts";
public string AddressEnableAutoMute { get; set; } = "/avatar/parameters/ToolEnableAutoMute";
public string AddressListeningIndicator { get; set; } = "/avatar/parameters/MicListening";
public string AddressAddTextbox { get; set; } = "/hoscy/message";
public string AddressAddTts { get; set; } = "/hoscy/tts";
public string AddressAddNotification { get; set; } = "/hoscy/notification";
public List<OscRoutingFilterModel> RoutingFilters { get; set; } = new();
public string AddressAddTextbox { get; set; } = "/hoscy/message";
public string AddressAddTts { get; set; } = "/hoscy/tts";
public string AddressAddNotification { get; set; } = "/hoscy/notification";

//Counters
public bool ShowCounterNotifications { get; set; } = false;
public List<CounterModel> Counters { get; set; } = new();
}

/// <summary>
Expand Down Expand Up @@ -225,6 +243,7 @@ public int VoskTimeout
/// </summary>
public class ConfigTextboxModel
{
//Timeout, Maxlen
public int MaxLength
{
get { return _maxLength; }
Expand Down Expand Up @@ -252,6 +271,8 @@ public int DefaultTimeout
}
private int _defaultTimeout = 5000;
public bool DynamicTimeout { get; set; } = true;

//Notification
public bool AutomaticClearNotification { get; set; } = true;
public bool AutomaticClearMessage { get; set; } = false;
public bool UseIndicatorWithoutBox { get; set; } = false;
Expand All @@ -262,7 +283,6 @@ public int DefaultTimeout
public bool MediaShowStatus { get; set; } = false;
public string MediaPlayingVerb { get; set; } = "Playing";
public bool MediaAddAlbum { get; set; } = false;

}

/// <summary>
Expand Down Expand Up @@ -298,9 +318,10 @@ public int TranslationMaxTextLength
public string AzureSpeechLanguage { get; set; } = string.Empty;
public string AzureCustomEndpointSpeech { get; set; } = string.Empty;
public string AzureCustomEndpointRecognition { get; set; } = string.Empty;
public string AzureVoice { get; set; } = string.Empty;
public string AzureVoiceCurrent { get; set; } = string.Empty;
public List<string> AzurePhrases { get; set; } = new();
public List<string> AzureRecognitionLanguages { get; set; } = new();
public Dictionary<string, string> AzureVoices { get; set; } = new(); //todo: implement

//Usage
public bool TranslateTts { get; set; } = false;
Expand Down Expand Up @@ -437,6 +458,16 @@ public bool IsValid()
&& !string.IsNullOrWhiteSpace(JsonData)
&& !string.IsNullOrWhiteSpace(ResultField);
}

public class CounterModel
{
public string Name { get; set; } = "Unnamed Counter";
public string Parameter { get; set; } = "Parameter";
public uint Count { get; set; } = 0;

public override string ToString()
=> $"{Name}: {Count}";
}
#endregion
}
}
25 changes: 20 additions & 5 deletions OscMultitool/Hoscy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\hoscy_circle.ico</ApplicationIcon>
<Platforms>AnyCPU;x64</Platforms>
<AssemblyVersion>0.4.1</AssemblyVersion>
<FileVersion>0.4.1</FileVersion>
<AssemblyVersion>0.5</AssemblyVersion>
<FileVersion>0.5</FileVersion>
<RepositoryUrl>https://github.com/PaciStardust/HOSCY</RepositoryUrl>
<PackageProjectUrl>https://github.com/PaciStardust/HOSCY</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand All @@ -32,23 +32,31 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CognitiveServices.Speech" Version="1.24.1" />
<PackageReference Include="MeaMod.DNS" Version="1.0.70" />
<PackageReference Include="Microsoft.CognitiveServices.Speech" Version="1.24.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="NAudio" Version="2.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2" />
<PackageReference Include="System.Speech" Version="7.0.0-rc.2.22472.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="System.Speech" Version="7.0.0" />
<PackageReference Include="Vosk" Version="0.3.38" />
</ItemGroup>

<ItemGroup>
<Reference Include="CoreOSC">
<HintPath>Resources\CoreOsc\CoreOSC.dll</HintPath>
</Reference>
<Reference Include="vrc-oscquery-lib">
<HintPath>Resources\OscQuery\vrc-oscquery-lib.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<Compile Update="Ui\Windows\ModifyApiPresetsWindow.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Ui\Windows\ModifyCountersWindow.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Ui\Windows\ModifyReplacementsWindow.xaml.cs">
<SubType>Code</SubType>
</Compile>
Expand Down Expand Up @@ -78,6 +86,13 @@
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Ui\Windows\DisplayListWindow.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
<Page Update="Ui\Windows\ModifyCountersWindow.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Ui\Windows\ModifyReplacementsWindow.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
Expand Down
52 changes: 49 additions & 3 deletions OscMultitool/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Hoscy.Ui;
using Hoscy.Ui.Windows;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -162,13 +163,16 @@ public static void Error(string message, bool notify = true, [CallerFilePath] st
/// <param name="title">Title of window</param>
/// <param name="subtitle">Text above notification</param>
/// <param name="notification">Contents of notification box</param>
public static void OpenNotificationWindow(string title, string subtitle, string notification)
public static void OpenNotificationWindow(string title, string subtitle, string notification, bool locking = false)
{
Application.Current.Dispatcher.Invoke(() =>
{
var window = new NotificationWindow(title, subtitle, notification);
window.SetDarkMode(true);
window.ShowDialog();
if (locking)
window.ShowDialog();
else
window.Show();
});
}
#endregion
Expand All @@ -177,7 +181,7 @@ public static void OpenNotificationWindow(string title, string subtitle, string
/// <summary>
/// Logging message class
/// </summary>
public struct LogMessage
public readonly struct LogMessage
{
public static int MaxSeverityLength => 8;
public string SourceFile { get; private init; }
Expand Down Expand Up @@ -220,6 +224,48 @@ private static string Pad(string value, int len)
}
}

/// <summary>
/// The only reason this exists is so I can log OSCQuery
/// </summary>
public class LoggerProxy<T> : ILogger<T>
{
#nullable disable
public IDisposable BeginScope<TState>(TState state)
{
throw new NotImplementedException();
}
#nullable enable

public bool IsEnabled(LogLevel logLevel)
=> true;

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
string? message = state?.ToString();
if (string.IsNullOrWhiteSpace(message))
return;

switch(logLevel)
{
case LogLevel.Information:
Logger.Info(message);
return;
case LogLevel.Warning:
Logger.Warning(message);
return;
case LogLevel.Error:
Logger.Error(message);
return;
case LogLevel.Critical:
Logger.Error(message);
return;

default:
Logger.Debug(message);
return;
}
}
}
public enum LogSeverity
{
Error,
Expand Down
21 changes: 21 additions & 0 deletions OscMultitool/Resources/OscQuery/License.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 VRChat Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file not shown.
4 changes: 4 additions & 0 deletions OscMultitool/Services/Api/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public bool LoadPreset(Config.ApiPresetModel preset)
return true;
}

#region Sending
private async Task<string?> Send(HttpContent content)
{
if (_preset == null || !_preset.IsValid())
Expand Down Expand Up @@ -69,7 +70,9 @@ public bool LoadPreset(Config.ApiPresetModel preset)

return await Send(new StringContent(jsonOut, Encoding.UTF8, "application/json"));
}
#endregion

#region Utils
private void AddHeaders(HttpContent content)
{
if (_preset == null)
Expand All @@ -90,5 +93,6 @@ public void Clear()

private static string ReplaceToken(string text, string token, string value)
=> text.Replace(token, value);
#endregion
}
}
2 changes: 1 addition & 1 deletion OscMultitool/Services/Api/HoscyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static async Task CheckForUpdatesInternal()
Logger.Warning($"New version available (Latest is {newVer})");

var notifText = $"Current: {currVer}\nLatest: {newVer}{(string.IsNullOrWhiteSpace(newBody) ? string.Empty : $"\n\n{newBody}")}";
Logger.OpenNotificationWindow("New version available", "A new version of HOSCY is available", notifText);
Logger.OpenNotificationWindow("New version available", "A new version of HOSCY is available", notifText, true);
}
else
Logger.Info("HOSCY is up to date");
Expand Down
20 changes: 2 additions & 18 deletions OscMultitool/Services/Api/Media.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,6 @@ private async static Task UpdateCurrentlyPlayingMedia(GlobalSystemMediaTransport
return sb.ToString();
}

private static string? CreateDetailedMediaString()
{
StringBuilder sb = new(CreateCurrentMediaString());

if (sb.Length == 0 || _nowPlaying == null)
return null;

if (!Config.Textbox.MediaAddAlbum && !string.IsNullOrWhiteSpace(_nowPlaying.AlbumTitle))
sb.Append($"on '{_nowPlaying.AlbumTitle}'");

if (_nowPlaying.Genres.Count > 0)
sb.Append($" ({string.Join(", ", _nowPlaying.Genres)})");

return sb.ToString();
}

private static void SetNotification(string text)
=> Textbox.Notify(text, NotificationType.Media);
#endregion
Expand Down Expand Up @@ -232,10 +216,10 @@ private async static Task HandleMediaCommand(MediaCommandType command)
return;

case MediaCommandType.Info:
var playing = CreateDetailedMediaString();
var playing = CreateCurrentMediaString();
if (string.IsNullOrWhiteSpace(playing))
return;
SetNotification(playing);
SetNotification($"{Config.Textbox.MediaPlayingVerb} {playing}");
return;

default: return;
Expand Down
12 changes: 5 additions & 7 deletions OscMultitool/Services/Api/Synthesizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ static Synthesizer()
/// </summary>
public static void ReloadClient()
{
if (_synth != null)
{
_synth.Dispose();
_synth = null;
}
_synth?.Dispose();
_synth = null;

SpeechSynthesizer? synth = null;

Logger.PInfo("Performing reload of Azure Synthesizer");
Expand All @@ -36,8 +34,8 @@ public static void ReloadClient()
if (!string.IsNullOrWhiteSpace(Config.Api.AzureCustomEndpointSpeech))
speechCfg.EndpointId = Config.Api.AzureCustomEndpointSpeech;

if (!string.IsNullOrWhiteSpace(Config.Api.AzureVoice))
speechCfg.SpeechSynthesisVoiceName = Config.Api.AzureVoice;
if (!string.IsNullOrWhiteSpace(Config.Api.AzureVoiceCurrent))
speechCfg.SpeechSynthesisVoiceName = Config.Api.AzureVoiceCurrent;

if (!string.IsNullOrWhiteSpace(Config.Api.AzureSpeechLanguage))
speechCfg.SpeechSynthesisLanguage = Config.Api.AzureSpeechLanguage;
Expand Down
Loading

0 comments on commit 3ce8f57

Please sign in to comment.