Skip to content

Commit

Permalink
Enhanced UI and Data Handling Updates
Browse files Browse the repository at this point in the history
- Updated App.xaml.cs to enhance initialization with MediaLink styles and Soundpad Module integration for better user feedback.
- Simplified DataController.cs by removing redundant MediaLink settings and added JSON status list updating for improved data handling.
- Enhanced customization with new MediaLink style management in DataController.cs, including seekbar styles.
- Improved media content handling in OSCController.cs with `System.Windows.Media` namespace inclusion and progress bar customization.
- Added `MediaLinkStyle` class in MediaLinkModule.cs for better style property encapsulation.
- Updated OpenAI API usage in OpenAIModule.cs and WhisperModule.cs with `CreateTranscriptionTextAsync`.
- Incremented project version to 0.8.895 in MagicChatbox.csproj and introduced a new UI icon.
- Updated package references in MagicChatbox.csproj for compatibility and feature enhancements.
- UI enhancements with new ComboBox and Button for seekbar style selection and creation, and dynamic UI element visibility based on the `DisableMediaLink` property.
- Added detailed seekbar customization options and new settings for media information display.
- Implemented ViewModel updates for dynamic seekbar style management and streamlined media link settings handling.
- General UI layout improvements and code cleanup for better maintainability and user experience.
  • Loading branch information
BoiHanny committed Jun 19, 2024
1 parent 89ab90d commit 7f71314
Show file tree
Hide file tree
Showing 12 changed files with 674 additions and 245 deletions.
3 changes: 3 additions & 0 deletions vrcosc-magicchatbox/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ private async Task InitializeComponentsWithProgress(StartUp loadingWindow)
loadingWindow.UpdateProgress("Turbocharging MediaLink engines... Fast & Furious: Data Drift!", 95);
ApplicationMediaController = new MediaLinkModule(ViewModel.Instance.IntgrScanMediaLink);

loadingWindow.UpdateProgress("Loading MediaLink styles... Fashion show, here we come!", 96);
await Task.Run(() => DataController.LoadAndSaveMediaLinkStyles());

loadingWindow.UpdateProgress("Initializing Soundpad Module... Let's get this party started!", 96);
await Task.Run(() => DataController.soundpadModule = new SoundpadModule(1500));
}
Expand Down
191 changes: 182 additions & 9 deletions vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,6 @@ public static void LoadComponentStats()
{ "MediaSession_AutoSwitch", (typeof(bool), "MediaLink") },
{ "DisableMediaLink", (typeof(bool), "MediaLink") },
{ "MediaLinkTimeSeekStyle", (typeof(MediaLinkTimeSeekbar), "MediaLink") },
{ "MediaLinkDisplayTime", (typeof(bool), "MediaLink") },
{ "MediaLinkProgressBarLength", (typeof(int), "MediaLink") },
{ "MediaLinkFilledCharacter", (typeof(string), "MediaLink") },
{ "MediaLinkMiddleCharacter", (typeof(string), "MediaLink") },
{ "MediaLinkNonFilledCharacter", (typeof(string), "MediaLink") },
{ "MediaLinkTimePrefix", (typeof(string), "MediaLink") },
{ "MediaLinkTimeSuffix", (typeof(string), "MediaLink") },
{ "MediaLinkShowTimeInSuperscript", (typeof(bool), "MediaLink") },
{ "MediaLinkProgressBarOnTop", (typeof(bool), "MediaLink") },
{ "AutoDowngradeSeekbar", (typeof(bool), "MediaLink") },

{ "ScanningInterval", (typeof(double), "Scanning") },
Expand Down Expand Up @@ -738,6 +729,8 @@ public static void LoadStatusList()
}
}



private static void UpdateStatusListFromJson(string json)
{
if (string.IsNullOrWhiteSpace(json) || json.Trim().Equals("null", StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -1009,6 +1002,186 @@ public static void SaveChatList()
}
}

private const string MediaLinkStylesFileName = "MediaLinkStyles.json";

private static string GetMediaLinkStylesFilePath()
{
return Path.Combine(ViewModel.Instance.DataPath, MediaLinkStylesFileName);
}


public static void LoadAndSaveMediaLinkStyles(bool save = false)
{
try
{
if (save)
{
SaveMediaLinkStyles();
}
else
{
LoadMediaLinkStyles();
}
}
catch (Exception ex)
{
Logging.WriteException(ex, MSGBox: false);
}
}

public static void AddNewSeekbarStyle()
{
// Extract custom styles (those that are not system defaults)
ObservableCollection<MediaLinkStyle> customStyles = new ObservableCollection<MediaLinkStyle>(
ViewModel.Instance.MediaLinkSeekbarStyles.Where(s => !s.SystemDefault));

// Find the highest ID among custom styles
int highestID = customStyles.Any() ? customStyles.Max(s => s.ID) : 99;

// Generate the next available ID starting from 100
int nextAvailableID = highestID + 1;

// Ensure the next ID is at least 100
if (nextAvailableID < 100)
{
nextAvailableID = 100;
}

// Create a new style with the next available ID
MediaLinkStyle newStyle = new MediaLinkStyle
{
ID = nextAvailableID,
ProgressBarLength = 8,
SystemDefault = false
};

// Add the new style to the collection
ViewModel.Instance.MediaLinkSeekbarStyles.Add(newStyle);

// Select the new style
ViewModel.Instance.SelectedMediaLinkSeekbarStyle = newStyle;

// Optionally save the updated styles
SaveMediaLinkStyles();

Logging.WriteInfo($"New media link style with ID {nextAvailableID} added.");
}


private static void LoadMediaLinkStyles()
{
// Load default styles first
ViewModel.Instance.MediaLinkSeekbarStyles = DefaultMediaLinkStyles();
Logging.WriteInfo("Default media link styles loaded.");

string filePath = GetMediaLinkStylesFilePath();

if (File.Exists(filePath))
{
try
{
string jsonData = File.ReadAllText(filePath);
var data = JsonConvert.DeserializeObject<MediaLinkStylesData>(jsonData);

if (data?.CustomStyles != null)
{
foreach (var style in data.CustomStyles)
{
// Avoid adding duplicates
if (!ViewModel.Instance.MediaLinkSeekbarStyles.Any(s => s.ID == style.ID))
{
ViewModel.Instance.MediaLinkSeekbarStyles.Add(style);
}
}
Logging.WriteInfo("Custom media link styles loaded.");
}

if (data?.SelectedStyleId != null)
{
var selectedStyle = ViewModel.Instance.MediaLinkSeekbarStyles.FirstOrDefault(s => s.ID == data.SelectedStyleId);
if (selectedStyle != null)
{
ViewModel.Instance.SelectedMediaLinkSeekbarStyle = selectedStyle;
Logging.WriteInfo("Selected media link style loaded.");
}
else
{
ViewModel.Instance.SelectedMediaLinkSeekbarStyle = ViewModel.Instance.MediaLinkSeekbarStyles.FirstOrDefault();
Logging.WriteInfo("Selected media link style not found in the loaded styles.");
}
}
}
catch (Exception ex)
{
ViewModel.Instance.SelectedMediaLinkSeekbarStyle = ViewModel.Instance.MediaLinkSeekbarStyles.FirstOrDefault();
Logging.WriteException(ex, MSGBox: false);
}
}
else
{
Logging.WriteInfo($"Custom media link styles file '{filePath}' not found.");
ViewModel.Instance.SelectedMediaLinkSeekbarStyle = ViewModel.Instance.MediaLinkSeekbarStyles.FirstOrDefault();
}
}

private static void SaveMediaLinkStyles()
{
try
{
// Ensure the data directory exists
if (CreateIfMissing(ViewModel.Instance.DataPath))
{
string filePath = GetMediaLinkStylesFilePath();

// Get all the styles that are not system default
ObservableCollection<MediaLinkStyle> nonSystemMediaLinkStyles = new ObservableCollection<MediaLinkStyle>(
ViewModel.Instance.MediaLinkSeekbarStyles.Where(s => !s.SystemDefault));

var data = new MediaLinkStylesData
{
CustomStyles = nonSystemMediaLinkStyles,
SelectedStyleId = ViewModel.Instance.SelectedMediaLinkSeekbarStyle?.ID
};

var jsonData = JsonConvert.SerializeObject(data);
File.WriteAllText(filePath, jsonData);

Logging.WriteInfo("Custom media link styles and selected style saved.");
}
}
catch (Exception ex)
{
Logging.WriteException(ex, MSGBox: false);
}
}

private class MediaLinkStylesData
{
public ObservableCollection<MediaLinkStyle> CustomStyles { get; set; }
public int? SelectedStyleId { get; set; }
}

public static ObservableCollection<MediaLinkStyle> DefaultMediaLinkStyles()
{
return new ObservableCollection<MediaLinkStyle>
{
new MediaLinkStyle
{
ID = 1,
ProgressBarLength = 8,
DisplayTime = true,
ShowTimeInSuperscript = true,
FilledCharacter = "",
MiddleCharacter = "",
NonFilledCharacter = "",
TimePrefix = "",
TimeSuffix = "",
SystemDefault = true
},
};
}


public static void SaveMediaSessions()
{
try
Expand Down
62 changes: 41 additions & 21 deletions vrcosc-magicchatbox/Classes/DataAndSecurity/OSCController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Media;
using vrcosc_magicchatbox.DataAndSecurity;
using vrcosc_magicchatbox.ViewModels;
using vrcosc_magicchatbox.ViewModels.Models;
Expand Down Expand Up @@ -188,14 +189,15 @@ private static string CreateTimeStamp(string x, MediaSessionInfo mediaSession, M

double percentage = fullTime.TotalSeconds == 0 ? 0 : (currentTime.TotalSeconds / fullTime.TotalSeconds) * 100;
int availableSpace = 140 - CalculateOSCMsgLength(uncomplete, x);
var selectedStyle = ViewModel.Instance.SelectedMediaLinkSeekbarStyle;

switch (style)
{
case MediaLinkTimeSeekbar.NumbersAndSeekBar:
string progressBarContent = CreateProgressBar(percentage, mediaSession, ViewModel.Instance.MediaLinkDisplayTime);
if (!string.IsNullOrWhiteSpace(progressBarContent) && CalculateOSCMsgLength(uncomplete, x + "\n" + progressBarContent) <= 140)
string progressBarContent = CreateProgressBar(percentage, mediaSession, selectedStyle);
if (!string.IsNullOrWhiteSpace(progressBarContent) && CalculateOSCMsgLength(uncomplete, x + "\n" + progressBarContent) <= 144)
{
return ViewModel.Instance.MediaLinkProgressBarOnTop ? progressBarContent + "\n" + x : x + "\n" + progressBarContent;
return ViewModel.Instance.SelectedMediaLinkSeekbarStyle.ProgressBarOnTop ? progressBarContent + "\n" + x : x + "\n" + progressBarContent;
}
else if (ViewModel.Instance.AutoDowngradeSeekbar)
{
Expand All @@ -205,7 +207,7 @@ private static string CreateTimeStamp(string x, MediaSessionInfo mediaSession, M

case MediaLinkTimeSeekbar.SmallNumbers:
string smallNumbersContent = $"{DataController.TransformToSuperscript(FormatTimeSpan(currentTime))} l {DataController.TransformToSuperscript(FormatTimeSpan(fullTime))}";
if (CalculateOSCMsgLength(uncomplete, x + smallNumbersContent) <= 140)
if (CalculateOSCMsgLength(uncomplete, x + smallNumbersContent) <= 144)
{
return x + " " + smallNumbersContent;
}
Expand All @@ -223,27 +225,29 @@ private static string CreateTimeStamp(string x, MediaSessionInfo mediaSession, M
return x;
}




private static string CreateProgressBar(double percentage, MediaSessionInfo mediaSession, bool includeTime)
private static string CreateProgressBar(double percentage, MediaSessionInfo mediaSession, MediaLinkStyle style)
{
try
{
int totalBlocks = ViewModel.Instance.MediaLinkProgressBarLength;
// Ensure characters are not empty or null before accessing
if (string.IsNullOrEmpty(style.FilledCharacter) ||
string.IsNullOrEmpty(style.MiddleCharacter) ||
string.IsNullOrEmpty(style.NonFilledCharacter))
{
return string.Empty;
}

int totalBlocks = style.ProgressBarLength;

string currentTime = includeTime && ViewModel.Instance.MediaLinkShowTimeInSuperscript
string currentTime = style.DisplayTime && style.ShowTimeInSuperscript
? DataController.TransformToSuperscript(FormatTimeSpan(mediaSession.CurrentTime))
: FormatTimeSpan(mediaSession.CurrentTime);

string fullTime = includeTime && ViewModel.Instance.MediaLinkShowTimeInSuperscript
string fullTime = style.DisplayTime && style.ShowTimeInSuperscript
? DataController.TransformToSuperscript(FormatTimeSpan(mediaSession.FullTime))
: FormatTimeSpan(mediaSession.FullTime);

string timePrefix = ViewModel.Instance.MediaLinkTimePrefix;
string timeSuffix = ViewModel.Instance.MediaLinkTimeSuffix;

if (ViewModel.Instance.MediaLinkDisplayTime && totalBlocks > 0)
if (style.DisplayTime && totalBlocks > 0)
{
int timeStringLength = currentTime.Length + fullTime.Length + 1;

Expand All @@ -254,21 +258,36 @@ private static string CreateProgressBar(double percentage, MediaSessionInfo medi
}

int filledBlocks = (int)(percentage / (100.0 / totalBlocks));
char filledChar = ViewModel.Instance.MediaLinkFilledCharacter.ToCharArray()[0];
char middleChar = ViewModel.Instance.MediaLinkMiddleCharacter.ToCharArray()[0];
char nonFilledChar = ViewModel.Instance.MediaLinkNonFilledCharacter.ToCharArray()[0];
char filledChar = style.FilledCharacter[0];
char middleChar = style.MiddleCharacter[0];
char nonFilledChar = style.NonFilledCharacter[0];

string filledBar = new string(filledChar, filledBlocks);
string emptyBar = new string(nonFilledChar, totalBlocks - filledBlocks);
string progressBar = filledBar + middleChar + emptyBar;

return includeTime ? $"{timePrefix}{currentTime} {progressBar} {fullTime}{timeSuffix}" : progressBar;
if (style.TimePreSuffixOnTheInside)
{

if (string.IsNullOrWhiteSpace(style.TimePrefix) || string.IsNullOrWhiteSpace(style.TimeSuffix))
{
return $"{currentTime} {progressBar} {fullTime}";
}
else
{
return $"{currentTime}{style.TimePrefix}{progressBar}{style.TimeSuffix}{fullTime}";
}
}
else
{
return style.DisplayTime ? $"{style.TimePrefix}{currentTime} {progressBar} {fullTime}{style.TimeSuffix}" : progressBar;
}
}
catch (Exception)
catch (Exception ex)
{
Logging.WriteException(ex, MSGBox: false);
return string.Empty;
}

}


Expand All @@ -277,6 +296,7 @@ private static string CreateProgressBar(double percentage, MediaSessionInfo medi




// this function will build the spotify status message to be sent to VRChat and add it to the list of strings if the total length of the list is less than 144 characters
public static void AddSpotifyStatus(List<string> Uncomplete)
{
Expand Down
9 changes: 6 additions & 3 deletions vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public ModelTypeInfoAttribute(string modelType)

public enum IntelliGPTModel
{
[Description("gpt-4o"), ModelTypeInfo("Chat")]
gpt4o,

[Description("gpt-4"), ModelTypeInfo("Chat")]
gpt4,

Expand Down Expand Up @@ -153,7 +156,7 @@ public partial class IntelliChatModuleSettings : ObservableObject
private IntelliGPTModel performSpellingCheckModel = IntelliGPTModel.gpt3_5_turbo;

[ObservableProperty]
private IntelliGPTModel generateConversationStarterModel = IntelliGPTModel.gpt4_turbo;
private IntelliGPTModel generateConversationStarterModel = IntelliGPTModel.gpt4o;

[ObservableProperty]
private IntelliGPTModel performLanguageTranslationModel = IntelliGPTModel.gpt3_5_turbo;
Expand All @@ -162,10 +165,10 @@ public partial class IntelliChatModuleSettings : ObservableObject
private IntelliGPTModel performShortenTextModel = IntelliGPTModel.gpt3_5_turbo;

[ObservableProperty]
private IntelliGPTModel performBeautifySentenceModel = IntelliGPTModel.gpt4_turbo;
private IntelliGPTModel performBeautifySentenceModel = IntelliGPTModel.gpt4o;

[ObservableProperty]
private IntelliGPTModel performTextCompletionModel = IntelliGPTModel.gpt4_turbo;
private IntelliGPTModel performTextCompletionModel = IntelliGPTModel.gpt4o;

[ObservableProperty]
private IntelliGPTModel performModerationCheckModel = IntelliGPTModel.Moderation_Latest;
Expand Down
Loading

0 comments on commit 7f71314

Please sign in to comment.