From 05ec6febd544aa9817de024525ad7076bd67049a Mon Sep 17 00:00:00 2001 From: Soapwood Date: Mon, 29 Jul 2024 21:58:20 +0100 Subject: [PATCH] [AudD] Fix crash when reading from recognition bytes. Fix incorrect connection check. Improve statefulness in Recognition page. Make hint text appear/disappear appropriately. --- .../Audio/Conversion/AudioDataConverter.cs | 2 +- VXMusicDesktop/MVVM/View/RecognitionView.xaml | 97 ++++++++++--------- .../MVVM/View/RecognitionView.xaml.cs | 2 +- .../MVVM/ViewModel/RecognitionViewModel.cs | 43 ++++++-- VXMusicDesktop/Theme/TextBoxTheme.xaml | 4 +- 5 files changed, 90 insertions(+), 58 deletions(-) diff --git a/VXMusic/Audio/Conversion/AudioDataConverter.cs b/VXMusic/Audio/Conversion/AudioDataConverter.cs index 909296e..c299ae0 100644 --- a/VXMusic/Audio/Conversion/AudioDataConverter.cs +++ b/VXMusic/Audio/Conversion/AudioDataConverter.cs @@ -20,7 +20,7 @@ public AudioDataConverter(IServiceProvider serviceProvider) { _logger.LogTrace("Converting WAV to MP3."); - byte[] audioData = File.ReadAllBytes("output.wav"); // TODO Really need to fucking use just bytes. + byte[] audioData = File.ReadAllBytes(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "VirtualXtensions", "VXMusic", "Cache", "output.wav")); if (audioData == null) { diff --git a/VXMusicDesktop/MVVM/View/RecognitionView.xaml b/VXMusicDesktop/MVVM/View/RecognitionView.xaml index 4f5f424..47a7411 100644 --- a/VXMusicDesktop/MVVM/View/RecognitionView.xaml +++ b/VXMusicDesktop/MVVM/View/RecognitionView.xaml @@ -60,13 +60,13 @@ + Margin="10,0,0,0"> - - - - - - - - - - - - - - - + + + + + + + + - + + Margin="10,0,0,0" /> - + Margin="10,0,0,0"> - - - - - - - - - - - - - - - + + + + + + + + - - + + Margin="10,0,0,0" /> - diff --git a/VXMusicDesktop/MVVM/View/RecognitionView.xaml.cs b/VXMusicDesktop/MVVM/View/RecognitionView.xaml.cs index 8c1ad11..794a608 100644 --- a/VXMusicDesktop/MVVM/View/RecognitionView.xaml.cs +++ b/VXMusicDesktop/MVVM/View/RecognitionView.xaml.cs @@ -150,7 +150,7 @@ private void AudDByoApiPasswordBoxChanged(object sender, RoutedEventArgs e) recognitionViewModel.SharedViewModel.IsAudDApiConnected = false; recognitionViewModel.AudDByoApiToken = ((PasswordBox)e.OriginalSource).Password; - recognitionViewModel.PerformSaveAndTestShazamByoApi(); + recognitionViewModel.PerformSaveAndTestAudDByoApi(); } } diff --git a/VXMusicDesktop/MVVM/ViewModel/RecognitionViewModel.cs b/VXMusicDesktop/MVVM/ViewModel/RecognitionViewModel.cs index fb4b8b5..02fc10f 100644 --- a/VXMusicDesktop/MVVM/ViewModel/RecognitionViewModel.cs +++ b/VXMusicDesktop/MVVM/ViewModel/RecognitionViewModel.cs @@ -41,6 +41,7 @@ public class RecognitionViewModel : INotifyPropertyChanged public ICommand AudDByoApiCheckButtonUnchecked => audDByoApiRadioButtonUnchecked ??= new RelayCommand(PerformEnableAudDByoApiUnchecked); public ICommand ListenButtonClick => listenButtonClick ??= new RelayCommand(PerformListenButtonClick); public ICommand RecognitionViewLoaded => recognitionViewLoaded ??= new RelayCommand(OnRecognitionViewLoaded); + public ICommand PasswordHintTextVisibilityToggle => recognitionViewLoaded ??= new RelayCommand(OnRecognitionOptionChanged); // // // public event PropertyChangedEventHandler? PropertyChanged; @@ -51,7 +52,9 @@ public class RecognitionViewModel : INotifyPropertyChanged //private bool _isShazamApiConnected; private bool _isAudDApiEnabled; private bool _isAudDByoApiEnabled; - // private bool _isAudDApiConnected; + + private bool _shouldShazamByoApiPlaceholderBeShown; + private bool _shouldAudDByoApiPlaceholderBeShown; private bool _isRecognitionReady = true; @@ -81,6 +84,9 @@ public void Initialise() _audDByoApiToken = App.VXMusicSession.RecognitionSettings.AudDSettings.ByoApiKey; ProcessRecognitionApiState(); + _shouldShazamByoApiPlaceholderBeShown = _isShazamApiEnabled && !string.IsNullOrEmpty(_shazamByoApiToken); + _shouldAudDByoApiPlaceholderBeShown = _isAudDApiEnabled && !string.IsNullOrEmpty(_audDByoApiToken); + HasBeenInitialised = true; // TODO Do we actually want to do this here? It may be better to trigger this in the HomeView CheckIfCurrentApiIsConnected(); @@ -91,6 +97,14 @@ private void OnRecognitionViewLoaded(object commandParameter) ProcessRecognitionApiState(); //CheckIfCurrentApiIsConnected(); } + + private void OnRecognitionOptionChanged(object commandParameter) + { + ShouldShazamByoApiPlaceholderBeShown = !ShouldShazamByoApiPlaceholderBeShown; + ShouldAudDByoApiPlaceholderBeShown = !ShouldAudDByoApiPlaceholderBeShown; + + CheckIfCurrentApiIsConnected(); + } protected virtual void OnPropertyChanged(string propertyName) { @@ -129,6 +143,7 @@ public bool IsShazamApiEnabled set { _isShazamApiEnabled = value; + ShouldAudDByoApiPlaceholderBeShown = false; OnPropertyChanged(nameof(IsShazamApiEnabled)); } } @@ -150,15 +165,32 @@ public bool IsShazamByoApiKeySet public bool ShouldShazamByoApiPlaceholderBeShown { - get { return IsShazamApiEnabled && IsShazamByoApiKeySet; } + get { return _isShazamApiEnabled && !string.IsNullOrEmpty(_shazamByoApiToken); } + set + { + _shouldShazamByoApiPlaceholderBeShown = value; + OnPropertyChanged(nameof(ShouldShazamByoApiPlaceholderBeShown)); + } + } + + public bool ShouldAudDByoApiPlaceholderBeShown + { + get { return _isAudDApiEnabled && !string.IsNullOrEmpty(_audDByoApiToken); } + set + { + _shouldAudDByoApiPlaceholderBeShown = value; + OnPropertyChanged(nameof(ShouldAudDByoApiPlaceholderBeShown)); + } } + public bool IsAudDApiEnabled { get { return _isAudDApiEnabled; } set { _isAudDApiEnabled = value; + ShouldShazamByoApiPlaceholderBeShown = false; OnPropertyChanged(nameof(IsAudDApiEnabled)); } } @@ -168,11 +200,6 @@ public bool IsAudDApiKeySet get { return !string.IsNullOrEmpty(AudDByoApiToken); } } - public bool ShouldAudDByoApiPlaceholderBeShown - { - get { return IsAudDApiEnabled && IsAudDApiKeySet; } - } - public bool IsAudDByoApiEnabled { get { return _isAudDByoApiEnabled; } @@ -318,6 +345,7 @@ private void PerformShazamButtonClick(object commandParameter) //IsAudDByoApiEnabled = false; ProcessRecognitionApiState(); + CheckIfCurrentApiIsConnected(); } private void PerformAudDButtonClick(object commandParameter) @@ -330,6 +358,7 @@ private void PerformAudDButtonClick(object commandParameter) //IsShazamByoApiEnabled = false; ProcessRecognitionApiState(); + CheckIfCurrentApiIsConnected(); } private void PerformEnableShazamByoApiChecked(object commandParameter) diff --git a/VXMusicDesktop/Theme/TextBoxTheme.xaml b/VXMusicDesktop/Theme/TextBoxTheme.xaml index c9601e2..e5c6cfd 100644 --- a/VXMusicDesktop/Theme/TextBoxTheme.xaml +++ b/VXMusicDesktop/Theme/TextBoxTheme.xaml @@ -200,7 +200,7 @@ + Width="235" Height="25"> @@ -208,7 +208,7 @@ BorderThickness="0" Background="Transparent" VerticalAlignment="Center" - Padding="5" + VerticalContentAlignment="Center" Foreground="{StaticResource TextBasic}" x:Name="PasswordBox"/>