This commit is contained in:
		
							parent
							
								
									2a8166a0c5
								
							
						
					
					
						commit
						d881ed69e2
					
				
					 33 changed files with 580 additions and 640 deletions
				
			
		| 
						 | 
				
			
			@ -2,22 +2,22 @@
 | 
			
		|||
using Plpext.Core.Interfaces;
 | 
			
		||||
using Plpext.Core.Models;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.AudioConverter
 | 
			
		||||
namespace Plpext.Core.AudioConverter;
 | 
			
		||||
 | 
			
		||||
public class MP3AudioConverter : IAudioConverter
 | 
			
		||||
{
 | 
			
		||||
    public class MP3AudioConverter : IAudioConverter
 | 
			
		||||
    {
 | 
			
		||||
    private readonly IMP3Parser _parser;
 | 
			
		||||
 | 
			
		||||
    public MP3AudioConverter(IMP3Parser parser)
 | 
			
		||||
    {
 | 
			
		||||
        _parser = parser;
 | 
			
		||||
    }
 | 
			
		||||
        public async Task<AudioFile> ConvertAudioAsync(ReadOnlyMemory<byte> file, CancellationToken cancellationToken)
 | 
			
		||||
    public async Task<AudioFile> ConvertAudioAsync(ReadOnlyMemory<byte> mp3Input, CancellationToken cancellationToken)
 | 
			
		||||
    {
 | 
			
		||||
            var baseFile = await _parser.ParseIntoMP3(file, cancellationToken);
 | 
			
		||||
        var baseFile = await _parser.ParseIntoMP3(mp3Input, cancellationToken);
 | 
			
		||||
        byte[] pcmData = null!;
 | 
			
		||||
            using var mp3Stream = new MP3Stream(new MemoryStream(baseFile.Data.ToArray()));
 | 
			
		||||
            using var pcmStream = new MemoryStream();
 | 
			
		||||
        await using var mp3Stream = new MP3Stream(new MemoryStream(baseFile.Data.ToArray()));
 | 
			
		||||
        await using var pcmStream = new MemoryStream();
 | 
			
		||||
        var buffer = new byte[4096];
 | 
			
		||||
        int bytesReturned = 1;
 | 
			
		||||
        int totalBytesRead = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -28,42 +28,38 @@ namespace Plpext.Core.AudioConverter
 | 
			
		|||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                        bytesReturned = await mp3Stream.ReadAsync(buffer, 0, buffer.Length);
 | 
			
		||||
                    bytesReturned = await mp3Stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken);
 | 
			
		||||
                }
 | 
			
		||||
                    catch (IndexOutOfRangeException ex)
 | 
			
		||||
                catch (IndexOutOfRangeException)
 | 
			
		||||
                {
 | 
			
		||||
                        Console.WriteLine($"{ex.Message}");
 | 
			
		||||
                        Console.WriteLine($"File reached a corrupted/non-compliant portion. Total bytes read: {totalBytesRead} | File: {baseFile.Name}");
 | 
			
		||||
                    //File reached a corrupted/non-compliant portion.
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                    catch (NullReferenceException ex)
 | 
			
		||||
                catch (NullReferenceException)
 | 
			
		||||
                {
 | 
			
		||||
                        Console.WriteLine($"{ex.Message}");
 | 
			
		||||
                        Console.WriteLine($"File reached a corrupted/non-compliant portion. Total bytes read: {totalBytesRead} | File: {baseFile.Name}");
 | 
			
		||||
                    //File reached a corrupted/non-compliant portion that caused MP3Sharp to throw a NRE.
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                totalBytesRead += bytesReturned;
 | 
			
		||||
                    await pcmStream.WriteAsync(buffer, 0, bytesReturned);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                Console.WriteLine("Exception details:");
 | 
			
		||||
                Console.WriteLine($"Message: {ex.Message}");
 | 
			
		||||
                Console.WriteLine($"StackTrace: {ex.StackTrace}");
 | 
			
		||||
                if (ex.InnerException != null)
 | 
			
		||||
                {
 | 
			
		||||
                    Console.WriteLine($"InnerException: {ex.InnerException.Message}");
 | 
			
		||||
                    Console.WriteLine($"InnerException StackTrace: {ex.InnerException.StackTrace}");
 | 
			
		||||
                }
 | 
			
		||||
                await pcmStream.WriteAsync(buffer, 0, bytesReturned, cancellationToken);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            pcmData = ResampleToMono(pcmStream.ToArray());
 | 
			
		||||
 | 
			
		||||
            var audioDuration = (double)(pcmData.Length / 2) / mp3Stream.Frequency;
 | 
			
		||||
 | 
			
		||||
            return new AudioFile() { Name = baseFile.Name, MP3Data = file, Data = pcmData, Duration = TimeSpan.FromSeconds(audioDuration), Format = AudioFormat.Mono16, Frequency = mp3Stream.Frequency };
 | 
			
		||||
            return new AudioFile() { Name = baseFile.Name, MP3Data = mp3Input, Data = pcmData, Duration = TimeSpan.FromSeconds(audioDuration), Format = AudioFormat.Mono16, Frequency = mp3Stream.Frequency };
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception)
 | 
			
		||||
        {
 | 
			
		||||
            //An exception here would be something new.
 | 
			
		||||
        }
 | 
			
		||||
        return new AudioFile() { Name = $"${baseFile.Name} failed extraction", Data = ReadOnlyMemory<byte>.Empty, MP3Data = ReadOnlyMemory<byte>.Empty, Duration = TimeSpan.FromSeconds(0), Format = AudioFormat.Unknown, Frequency = 0 };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* This is pretty cursed, but it works.
 | 
			
		||||
       I don't remember where I got it from the first time, though. I think LLMs weren't a thing yet.
 | 
			
		||||
    */
 | 
			
		||||
    private static byte[] ResampleToMono(Span<byte> data)
 | 
			
		||||
    {
 | 
			
		||||
        byte[] newData = new byte[data.Length / 2];
 | 
			
		||||
| 
						 | 
				
			
			@ -82,5 +78,4 @@ namespace Plpext.Core.AudioConverter
 | 
			
		|||
 | 
			
		||||
        return newData;
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,13 +1,6 @@
 | 
			
		|||
using OpenTK.Audio.OpenAL;
 | 
			
		||||
using Plpext.Core.Interfaces;
 | 
			
		||||
using Plpext.Core.Models;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Xml.Linq;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.AudioPlayer;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -41,13 +34,12 @@ public sealed class AudioPlayer : IAudioPlayer, IDisposable
 | 
			
		|||
 | 
			
		||||
            AL.BufferData(bufferId, ALFormat.Mono16, input.Data.Span, input.Frequency);
 | 
			
		||||
            AL.Source(sourceId, ALSourcei.Buffer, bufferId);
 | 
			
		||||
            if(autoStart)
 | 
			
		||||
            if (autoStart)
 | 
			
		||||
                return await Start();
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        catch (Exception)
 | 
			
		||||
        {
 | 
			
		||||
            Console.WriteLine($"init error: {ex}");
 | 
			
		||||
            await CleanupPlaybackResources();
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -63,7 +55,6 @@ public sealed class AudioPlayer : IAudioPlayer, IDisposable
 | 
			
		|||
            while (!cancellationToken.IsCancellationRequested)
 | 
			
		||||
            {
 | 
			
		||||
                var sourceState = (ALSourceState)AL.GetSource(_currentSourceId.Value, ALGetSourcei.SourceState);
 | 
			
		||||
                Console.WriteLine($"source state: {sourceState}");
 | 
			
		||||
                if (sourceState == ALSourceState.Stopped)
 | 
			
		||||
                    break;
 | 
			
		||||
                if (State != PlaybackState.Paused)
 | 
			
		||||
| 
						 | 
				
			
			@ -73,8 +64,6 @@ public sealed class AudioPlayer : IAudioPlayer, IDisposable
 | 
			
		|||
                        ((double)(_audioFile.Data.Length - (_audioFile.Data.Length - bytesPlayed)) / 2) / _audioFile.Frequency
 | 
			
		||||
                    );
 | 
			
		||||
 | 
			
		||||
                    Console.WriteLine($"Progress: {currentPosition.TotalSeconds:F2}s / {_audioFile.Duration.TotalSeconds:F2}s");
 | 
			
		||||
 | 
			
		||||
                    OnProgressUpdated?.Invoke(this, new()
 | 
			
		||||
                    {
 | 
			
		||||
                        CurrentPosition = currentPosition,
 | 
			
		||||
| 
						 | 
				
			
			@ -86,15 +75,14 @@ public sealed class AudioPlayer : IAudioPlayer, IDisposable
 | 
			
		|||
        }
 | 
			
		||||
        catch (OperationCanceledException)
 | 
			
		||||
        {
 | 
			
		||||
            Console.WriteLine("Playback cancelled");
 | 
			
		||||
            //An operation cancelled here is expected behavior.
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        catch (Exception)
 | 
			
		||||
        {
 | 
			
		||||
            Console.WriteLine($"Monitor error: {ex}");
 | 
			
		||||
            //There is little to be done if we get any other exception during monitoring. Finish up playback monitoring.
 | 
			
		||||
        }
 | 
			
		||||
        finally
 | 
			
		||||
        {
 | 
			
		||||
            Console.WriteLine("Monitor task ending");
 | 
			
		||||
            OnProgressUpdated?.Invoke(this, new()
 | 
			
		||||
            {
 | 
			
		||||
                CurrentPosition = _audioFile.Duration,
 | 
			
		||||
| 
						 | 
				
			
			@ -108,9 +96,9 @@ public sealed class AudioPlayer : IAudioPlayer, IDisposable
 | 
			
		|||
    {
 | 
			
		||||
        lock (_lock)
 | 
			
		||||
        {
 | 
			
		||||
            //If we try and start/resume playback without a proper source id or audio file, we can't go on.
 | 
			
		||||
            if (_currentSourceId == null || _audioFile == null)
 | 
			
		||||
            {
 | 
			
		||||
                Console.WriteLine("Cannot start - no source or audio file");
 | 
			
		||||
                return Task.FromResult(false);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -137,16 +125,13 @@ public sealed class AudioPlayer : IAudioPlayer, IDisposable
 | 
			
		|||
                State = PlaybackState.Playing;
 | 
			
		||||
                OnPlaybackStarted?.Invoke(this, new PlaybackStartedEventArgs { AudioFile = _audioFile });
 | 
			
		||||
 | 
			
		||||
                Console.WriteLine($"Rewind");
 | 
			
		||||
                AL.SourceRewind(_currentSourceId.Value);
 | 
			
		||||
                Console.WriteLine($"Play");
 | 
			
		||||
                AL.SourcePlay(_currentSourceId.Value);
 | 
			
		||||
                _playbackTask = Task.Run(() => MonitorPlaybackAsync(_playbackCts.Token));
 | 
			
		||||
                return Task.FromResult(true);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            catch (Exception)
 | 
			
		||||
            {
 | 
			
		||||
                Console.WriteLine($"Start error: {ex}");
 | 
			
		||||
                return Task.FromResult(false);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -177,7 +162,6 @@ public sealed class AudioPlayer : IAudioPlayer, IDisposable
 | 
			
		|||
 | 
			
		||||
    public void Stop()
 | 
			
		||||
    {
 | 
			
		||||
        Console.WriteLine($"STOP called");
 | 
			
		||||
        lock (_lock)
 | 
			
		||||
        {
 | 
			
		||||
            _playbackCts?.Cancel();
 | 
			
		||||
| 
						 | 
				
			
			@ -190,6 +174,7 @@ public sealed class AudioPlayer : IAudioPlayer, IDisposable
 | 
			
		|||
            _playbackCts?.Cancel();
 | 
			
		||||
            State = PlaybackState.Stopped;
 | 
			
		||||
        }
 | 
			
		||||
        if(_audioFile is not null)
 | 
			
		||||
            OnPlaybackStopped?.Invoke(this, new() { AudioFile = _audioFile });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -209,9 +194,9 @@ public sealed class AudioPlayer : IAudioPlayer, IDisposable
 | 
			
		|||
                _currentBufferId = null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        catch (Exception)
 | 
			
		||||
        {
 | 
			
		||||
            Console.WriteLine($"Error during cleanup: {ex}");
 | 
			
		||||
            //Things might be pretty broken at this point if this exception pops.
 | 
			
		||||
        }
 | 
			
		||||
        return Task.CompletedTask;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,27 +1,21 @@
 | 
			
		|||
using Plpext.Core.Interfaces;
 | 
			
		||||
using Plpext.Core.Models;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.FileStorage
 | 
			
		||||
namespace Plpext.Core.FileStorage;
 | 
			
		||||
 | 
			
		||||
public class DiskFileStorage : IFileStorage
 | 
			
		||||
{
 | 
			
		||||
    public class DiskFileStorage : IFileStorage
 | 
			
		||||
    {
 | 
			
		||||
    public async Task SaveFilesAsync(IEnumerable<MP3File> files, string targetPath)
 | 
			
		||||
    {
 | 
			
		||||
            HashSet<string> names = new HashSet<string>();
 | 
			
		||||
        HashSet<string> names = [];
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            if (!Directory.Exists(targetPath))
 | 
			
		||||
                Directory.CreateDirectory(targetPath);
 | 
			
		||||
        }
 | 
			
		||||
            catch (Exception e)
 | 
			
		||||
        catch (Exception)
 | 
			
		||||
        {
 | 
			
		||||
                Debug.WriteLine(e);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +26,10 @@ namespace Plpext.Core.FileStorage
 | 
			
		|||
            {
 | 
			
		||||
                await File.Create(Path.Combine(targetPath, $"{finalFileName}.mp3")).WriteAsync(file.Data);
 | 
			
		||||
            }
 | 
			
		||||
                catch (Exception e) { Debug.WriteLine(e); }
 | 
			
		||||
            catch (Exception)
 | 
			
		||||
            {
 | 
			
		||||
                //We can proceed with the next ones.
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    private static string TryAddName(HashSet<string> names, string newName)
 | 
			
		||||
| 
						 | 
				
			
			@ -41,5 +38,4 @@ namespace Plpext.Core.FileStorage
 | 
			
		|||
            return TryAddName(names, newName + "_");
 | 
			
		||||
        return newName;
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,4 @@
 | 
			
		|||
using Plpext.Core.Models;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.Interfaces;
 | 
			
		||||
public interface IAudioConverter
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,4 @@
 | 
			
		|||
using Plpext.Core.Models;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.Interfaces;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,14 +1,8 @@
 | 
			
		|||
using Plpext.Core.Models;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.Interfaces
 | 
			
		||||
namespace Plpext.Core.Interfaces;
 | 
			
		||||
 | 
			
		||||
public interface IFileStorage
 | 
			
		||||
{
 | 
			
		||||
    public interface IFileStorage
 | 
			
		||||
    {
 | 
			
		||||
    Task SaveFilesAsync(IEnumerable<MP3File> files, string targetPath);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,14 +1,8 @@
 | 
			
		|||
using Plpext.Core.Models;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.Interfaces
 | 
			
		||||
namespace Plpext.Core.Interfaces;
 | 
			
		||||
 | 
			
		||||
public interface IMP3Parser
 | 
			
		||||
{
 | 
			
		||||
    public interface IMP3Parser
 | 
			
		||||
    {
 | 
			
		||||
    Task<MP3File> ParseIntoMP3(ReadOnlyMemory<byte> data, CancellationToken cancellationToken);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,10 +1,4 @@
 | 
			
		|||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.Interfaces;
 | 
			
		||||
namespace Plpext.Core.Interfaces;
 | 
			
		||||
 | 
			
		||||
public interface IPackExtractor
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,21 +1,15 @@
 | 
			
		|||
using MP3Sharp;
 | 
			
		||||
using Plpext.Core.Interfaces;
 | 
			
		||||
using Plpext.Core.Interfaces;
 | 
			
		||||
using Plpext.Core.Models;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.MP3Parser
 | 
			
		||||
namespace Plpext.Core.MP3Parser;
 | 
			
		||||
 | 
			
		||||
public class MP3Parser : IMP3Parser
 | 
			
		||||
{
 | 
			
		||||
    public class MP3Parser : IMP3Parser
 | 
			
		||||
    {
 | 
			
		||||
    public Task<MP3File> ParseIntoMP3(ReadOnlyMemory<byte> data, CancellationToken cancellationToken)
 | 
			
		||||
    {
 | 
			
		||||
        var fileName = Encoding.Latin1.GetString(data.Slice(start: 24, length: 260).Span).Split('\0')[0].Normalize().Trim();
 | 
			
		||||
        var fileData = data[284..];
 | 
			
		||||
        return Task.FromResult(new MP3File() { Name = fileName, Data = fileData });
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,18 +1,11 @@
 | 
			
		|||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
namespace Plpext.Core.Models;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.Models
 | 
			
		||||
public record AudioFile
 | 
			
		||||
{
 | 
			
		||||
    public record AudioFile
 | 
			
		||||
    {
 | 
			
		||||
    public required string Name { get; init; }
 | 
			
		||||
    public ReadOnlyMemory<byte> MP3Data { get; init; } 
 | 
			
		||||
    public ReadOnlyMemory<byte> Data { get; init; }
 | 
			
		||||
    public TimeSpan Duration { get; init; }
 | 
			
		||||
    public AudioFormat Format { get; init; }
 | 
			
		||||
    public int Frequency { get; init; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,10 +1,4 @@
 | 
			
		|||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.Models;
 | 
			
		||||
namespace Plpext.Core.Models;
 | 
			
		||||
 | 
			
		||||
public enum AudioFormat
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,17 +1,11 @@
 | 
			
		|||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.Models;
 | 
			
		||||
namespace Plpext.Core.Models;
 | 
			
		||||
 | 
			
		||||
public class PlaybackStoppedEventArgs : EventArgs
 | 
			
		||||
{
 | 
			
		||||
    public AudioFile AudioFile { get; init; }
 | 
			
		||||
    public required AudioFile AudioFile { get; init; }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public class PlaybackStartedEventArgs : EventArgs
 | 
			
		||||
{
 | 
			
		||||
    public AudioFile AudioFile { get; init; }
 | 
			
		||||
    public required AudioFile AudioFile { get; init; }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,14 +1,7 @@
 | 
			
		|||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
namespace Plpext.Core.Models;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.Models
 | 
			
		||||
public record MP3File
 | 
			
		||||
{
 | 
			
		||||
    public record MP3File
 | 
			
		||||
    {
 | 
			
		||||
    public required string Name { get; init; }
 | 
			
		||||
    public ReadOnlyMemory<byte> Data { get; init; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,15 +1,8 @@
 | 
			
		|||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
namespace Plpext.Core.Models;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.Models
 | 
			
		||||
public record PlaybackProgress
 | 
			
		||||
{
 | 
			
		||||
    public record PlaybackProgress
 | 
			
		||||
    {
 | 
			
		||||
    public TimeSpan CurrentPosition { get; init; }
 | 
			
		||||
    public TimeSpan TotalDuration { get; init; }
 | 
			
		||||
    public double ProgressPercentage => TotalDuration.TotalSeconds > 0 ? (CurrentPosition.TotalSeconds / TotalDuration.TotalSeconds) * 100 : 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,10 +1,5 @@
 | 
			
		|||
using Plpext.Core.Interfaces;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.Core.PackExtractor
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -12,26 +7,18 @@ namespace Plpext.Core.PackExtractor
 | 
			
		|||
    {
 | 
			
		||||
        private static readonly byte[] filePattern = { 0x53, 0x4E, 0x44, 0x55, 0x00 };
 | 
			
		||||
        public async Task<IEnumerable<ReadOnlyMemory<byte>>> GetFileListAsync(string filePath, CancellationToken cancellationToken)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
        {
 | 
			
		||||
            ReadOnlyMemory<byte> file = await File.ReadAllBytesAsync(filePath, cancellationToken);
 | 
			
		||||
            var fileIndexes = FindFileIndexes(file.Span);
 | 
			
		||||
 | 
			
		||||
            var result = new List<ReadOnlyMemory<byte>>();
 | 
			
		||||
                for(int i = 0; i < fileIndexes.Count - 1; ++i)
 | 
			
		||||
            for (int i = 0; i < fileIndexes.Count - 1; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                var nextFile = file.Slice(start: fileIndexes[i], length: fileIndexes[i + 1] - fileIndexes[i]);
 | 
			
		||||
                result.Add(nextFile);
 | 
			
		||||
            }
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
            catch(Exception e)
 | 
			
		||||
            {
 | 
			
		||||
                Debug.WriteLine(e);
 | 
			
		||||
                throw;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static List<int> FindFileIndexes(ReadOnlySpan<byte> file)
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -54,8 +41,10 @@ namespace Plpext.Core.PackExtractor
 | 
			
		|||
                    idx += filePattern.Length;
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    idx += skipTable[file[idx + j]];
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            result.Add(file.Length - 1);
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,20 +1,21 @@
 | 
			
		|||
<Application xmlns="https://github.com/avaloniaui"
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
<Application
 | 
			
		||||
    x:Class="Plpext.UI.App"
 | 
			
		||||
    xmlns="https://github.com/avaloniaui"
 | 
			
		||||
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
    RequestedThemeVariant="Dark">
 | 
			
		||||
 | 
			
		||||
    <Application.Resources>
 | 
			
		||||
        <ResourceDictionary>
 | 
			
		||||
            <ResourceDictionary.MergedDictionaries>
 | 
			
		||||
                <ResourceInclude Source="avares://Plpext/Resources/Colors.axaml"/>
 | 
			
		||||
                <ResourceInclude Source="avares://Plpext/Controls/AudioPlayerControl.axaml"/>
 | 
			
		||||
                <ResourceInclude Source="avares://Plpext/Resources/Colors.axaml" />
 | 
			
		||||
                <ResourceInclude Source="avares://Plpext/Controls/AudioPlayerControl.axaml" />
 | 
			
		||||
            </ResourceDictionary.MergedDictionaries>
 | 
			
		||||
        </ResourceDictionary>
 | 
			
		||||
    </Application.Resources>
 | 
			
		||||
 | 
			
		||||
    <Application.Styles>
 | 
			
		||||
        <FluentTheme />
 | 
			
		||||
        <StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
 | 
			
		||||
        <StyleInclude Source="avares://Plpext/Styles/AudioPlayerControl.axaml"/>
 | 
			
		||||
        <StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml" />
 | 
			
		||||
        <StyleInclude Source="avares://Plpext/Styles/AudioPlayerControl.axaml" />
 | 
			
		||||
    </Application.Styles>
 | 
			
		||||
</Application>
 | 
			
		||||
| 
						 | 
				
			
			@ -2,16 +2,8 @@
 | 
			
		|||
    xmlns="https://github.com/avaloniaui"
 | 
			
		||||
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
    xmlns:controls="using:Plpext.UI"
 | 
			
		||||
    xmlns:vm="clr-namespace:Plpext.UI.ViewModels"
 | 
			
		||||
    xmlns:cv="clr-namespace:Plpext.UI.Controls.Converters">
 | 
			
		||||
 | 
			
		||||
    <!--
 | 
			
		||||
        Additional resources
 | 
			
		||||
        Using Control Themes:
 | 
			
		||||
        https://docs.avaloniaui.net/docs/basics/user-interface/styling/control-themes
 | 
			
		||||
        Using Theme Variants:
 | 
			
		||||
        https://docs.avaloniaui.net/docs/guides/styles-and-resources/how-to-use-theme-variants
 | 
			
		||||
    -->
 | 
			
		||||
    xmlns:cv="clr-namespace:Plpext.UI.Controls.Converters"
 | 
			
		||||
    xmlns:vm="clr-namespace:Plpext.UI.ViewModels">
 | 
			
		||||
 | 
			
		||||
    <Design.PreviewWith>
 | 
			
		||||
        <Border Padding="10" Background="Brown">
 | 
			
		||||
| 
						 | 
				
			
			@ -26,50 +18,79 @@
 | 
			
		|||
        </Border>
 | 
			
		||||
    </Design.PreviewWith>
 | 
			
		||||
 | 
			
		||||
    <ControlTheme x:Key="{x:Type controls:AudioPlayerControl}" TargetType="controls:AudioPlayerControl"
 | 
			
		||||
                  x:DataType="vm:AudioPlayerViewModel">
 | 
			
		||||
    <ControlTheme
 | 
			
		||||
        x:Key="{x:Type controls:AudioPlayerControl}"
 | 
			
		||||
        x:DataType="vm:AudioPlayerViewModel"
 | 
			
		||||
        TargetType="controls:AudioPlayerControl">
 | 
			
		||||
        <Setter Property="Template">
 | 
			
		||||
            <ControlTemplate>
 | 
			
		||||
                <Grid Name="ButtonGrid" ColumnDefinitions="*,*, Auto">
 | 
			
		||||
                    <Grid.Transitions>
 | 
			
		||||
                        <Transitions>
 | 
			
		||||
                            <ThicknessTransition Property="Margin" Duration="0:0:0.3" Easing="SineEaseInOut"/>
 | 
			
		||||
                            <ThicknessTransition
 | 
			
		||||
                                Easing="SineEaseInOut"
 | 
			
		||||
                                Property="Margin"
 | 
			
		||||
                                Duration="0:0:0.3" />
 | 
			
		||||
                        </Transitions>
 | 
			
		||||
                    </Grid.Transitions>
 | 
			
		||||
                    <Button Name="PlayButton" Grid.Column="0" IsEnabled="{TemplateBinding IsEnabled}" 
 | 
			
		||||
                            HorizontalAlignment="Center" Width="32" Height="32" 
 | 
			
		||||
                            Padding="6 6 6 6"
 | 
			
		||||
                    <Button
 | 
			
		||||
                        Name="PlayButton"
 | 
			
		||||
                        Grid.Column="0"
 | 
			
		||||
                        Width="32"
 | 
			
		||||
                        Height="32"
 | 
			
		||||
                        Padding="6,6,6,6"
 | 
			
		||||
                        HorizontalAlignment="Center"
 | 
			
		||||
                        Command="{TemplateBinding PlayCommand}"
 | 
			
		||||
                        CommandParameter="{TemplateBinding PlayCommandParameter}"
 | 
			
		||||
                        CornerRadius="12"
 | 
			
		||||
                        FontSize="{TemplateBinding FontSize}"
 | 
			
		||||
                            CommandParameter="{TemplateBinding PlayCommandParameter}" Command="{TemplateBinding PlayCommand}">
 | 
			
		||||
                        IsEnabled="{TemplateBinding IsEnabled}">
 | 
			
		||||
                        <Path Fill="{Binding $parent[Button].Foreground}">
 | 
			
		||||
                            <Path.Data>
 | 
			
		||||
                                <Binding Path="PlaybackState" 
 | 
			
		||||
                                         RelativeSource="{RelativeSource TemplatedParent}"
 | 
			
		||||
                                         Converter="{x:Static cv:PlaybackStateToPathConverter.Instance}"/>
 | 
			
		||||
                                <Binding
 | 
			
		||||
                                    Converter="{x:Static cv:PlaybackStateToPathConverter.Instance}"
 | 
			
		||||
                                    Path="PlaybackState"
 | 
			
		||||
                                    RelativeSource="{RelativeSource TemplatedParent}" />
 | 
			
		||||
                            </Path.Data>
 | 
			
		||||
                        </Path>
 | 
			
		||||
                    </Button>
 | 
			
		||||
                    <Button Name="StopButton" Grid.Column="1" IsEnabled="{TemplateBinding IsEnabled}" IsVisible="{TemplateBinding IsPlaying}" 
 | 
			
		||||
                            HorizontalAlignment="Center" Width="32" Height="32" 
 | 
			
		||||
                            Padding="6 6 6 6"
 | 
			
		||||
                    <Button
 | 
			
		||||
                        Name="StopButton"
 | 
			
		||||
                        Grid.Column="1"
 | 
			
		||||
                        Width="32"
 | 
			
		||||
                        Height="32"
 | 
			
		||||
                        Padding="6,6,6,6"
 | 
			
		||||
                        HorizontalAlignment="Center"
 | 
			
		||||
                        Command="{TemplateBinding StopCommand}"
 | 
			
		||||
                        CommandParameter="{TemplateBinding StopCommandParameter}"
 | 
			
		||||
                        CornerRadius="12"
 | 
			
		||||
                        FontSize="{TemplateBinding FontSize}"
 | 
			
		||||
                            CommandParameter="{TemplateBinding StopCommandParameter}" Command="{TemplateBinding StopCommand}">
 | 
			
		||||
                        IsEnabled="{TemplateBinding IsEnabled}"
 | 
			
		||||
                        IsVisible="{TemplateBinding IsPlaying}">
 | 
			
		||||
                        <Path Data="M2,2 H14 V14 H2 Z" Fill="{Binding $parent[Button].Foreground}" />
 | 
			
		||||
                    </Button>
 | 
			
		||||
                    <StackPanel Grid.Column="2" Name="ProgressPanel" Orientation="Vertical">
 | 
			
		||||
                    <StackPanel
 | 
			
		||||
                        Name="ProgressPanel"
 | 
			
		||||
                        Grid.Column="2"
 | 
			
		||||
                        Orientation="Vertical">
 | 
			
		||||
                        <StackPanel.Transitions>
 | 
			
		||||
                            <Transitions>
 | 
			
		||||
                                <DoubleTransition Property="Width" Duration="0:0:0.3" Easing="SineEaseInOut"/>
 | 
			
		||||
                                <DoubleTransition Property="Opacity" Duration="0:0:0.3"/>
 | 
			
		||||
                                <DoubleTransition
 | 
			
		||||
                                    Easing="SineEaseInOut"
 | 
			
		||||
                                    Property="Width"
 | 
			
		||||
                                    Duration="0:0:0.3" />
 | 
			
		||||
                                <DoubleTransition Property="Opacity" Duration="0:0:0.3" />
 | 
			
		||||
                            </Transitions>
 | 
			
		||||
                        </StackPanel.Transitions>
 | 
			
		||||
                        <ProgressBar Name="ProgressPanelBar" Value="{TemplateBinding Progress}" HorizontalAlignment="Left" CornerRadius="2"/>
 | 
			
		||||
                        <ProgressBar
 | 
			
		||||
                            Name="ProgressPanelBar"
 | 
			
		||||
                            HorizontalAlignment="Left"
 | 
			
		||||
                            CornerRadius="2"
 | 
			
		||||
                            Value="{TemplateBinding Progress}" />
 | 
			
		||||
                        <StackPanel Orientation="Horizontal">
 | 
			
		||||
                            <Label FontSize="{TemplateBinding FontSize}"  Content="{TemplateBinding CurrentDuration}"/>
 | 
			
		||||
                            <Label FontSize="{TemplateBinding FontSize}"  Content="/"/>
 | 
			
		||||
                            <Label FontSize="{TemplateBinding FontSize}"  Content="{TemplateBinding TotalDuration}"/>
 | 
			
		||||
                            <Label Content="{TemplateBinding CurrentDuration}" FontSize="{TemplateBinding FontSize}" />
 | 
			
		||||
                            <Label Content="/" FontSize="{TemplateBinding FontSize}" />
 | 
			
		||||
                            <Label Content="{TemplateBinding TotalDuration}" FontSize="{TemplateBinding FontSize}" />
 | 
			
		||||
                        </StackPanel>
 | 
			
		||||
                    </StackPanel>
 | 
			
		||||
                </Grid>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,10 +7,6 @@ using Plpext.Core.PackExtractor;
 | 
			
		|||
using Plpext.UI.ViewModels;
 | 
			
		||||
using Serilog;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Plpext.Core.AudioConverter;
 | 
			
		||||
using Plpext.Core.AudioPlayer;
 | 
			
		||||
using Plpext.UI.Services;
 | 
			
		||||
| 
						 | 
				
			
			@ -19,10 +15,10 @@ using Plpext.UI.Services.FileLoader;
 | 
			
		|||
using Plpext.UI.Services.PlatformStorage;
 | 
			
		||||
using Plpext.UI.Views;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.UI.DependencyInjection
 | 
			
		||||
namespace Plpext.UI.DependencyInjection;
 | 
			
		||||
 | 
			
		||||
public static class Container
 | 
			
		||||
{
 | 
			
		||||
    public static class Container
 | 
			
		||||
    {
 | 
			
		||||
    private static IServiceProvider? _container;
 | 
			
		||||
    public static IServiceProvider Services
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -42,8 +38,6 @@ namespace Plpext.UI.DependencyInjection
 | 
			
		|||
                services.AddSingleton<MainWindow>();
 | 
			
		||||
                services.AddSingleton<MainWindowViewModel>();
 | 
			
		||||
 | 
			
		||||
                    services.AddTransient<AudioPlayerViewModel>();
 | 
			
		||||
                    
 | 
			
		||||
                services.AddSingleton<AudioContext>();
 | 
			
		||||
                services.AddScoped<IAudioPlayer, AudioPlayer>();
 | 
			
		||||
                services.AddSingleton<IAudioConverter, MP3AudioConverter>();
 | 
			
		||||
| 
						 | 
				
			
			@ -59,5 +53,4 @@ namespace Plpext.UI.DependencyInjection
 | 
			
		|||
        _container = hostBuilder.Services;
 | 
			
		||||
        return _container;
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,10 +12,16 @@
 | 
			
		|||
    <PublishReadyToRun>true</PublishReadyToRun>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
 | 
			
		||||
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
 | 
			
		||||
    <RuntimeIdentifier>win-x86</RuntimeIdentifier>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
 | 
			
		||||
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Folder Include="Models\" />
 | 
			
		||||
    <AvaloniaResource Include="Assets\**" />
 | 
			
		||||
    <AvaloniaResource Remove="ViewModels\Mocks\**" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
| 
						 | 
				
			
			@ -45,15 +51,21 @@
 | 
			
		|||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Compile Remove="ViewModels\Mocks\MockAudioPlayerViewModel.cs" />
 | 
			
		||||
    <Compile Remove="publish\**" />
 | 
			
		||||
    <Compile Remove="Releases\**" />
 | 
			
		||||
    <Compile Remove="ViewModels\Mocks\**" />
 | 
			
		||||
    <Compile Remove="ViewLocator.cs" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <AvaloniaXaml Remove="publish\**" />
 | 
			
		||||
    <AvaloniaXaml Remove="Releases\**" />
 | 
			
		||||
    <AvaloniaXaml Remove="ViewModels\Mocks\**" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <EmbeddedResource Remove="publish\**" />
 | 
			
		||||
    <EmbeddedResource Remove="Releases\**" />
 | 
			
		||||
    <EmbeddedResource Remove="ViewModels\Mocks\**" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -62,13 +74,15 @@
 | 
			
		|||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <None Remove="publish\**" />
 | 
			
		||||
    <None Remove="Releases\**" />
 | 
			
		||||
    <None Remove="ViewModels\Mocks\**" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
 | 
			
		||||
  <ItemGroup Condition="'$(RuntimeIdentifier)' == 'win-x86'">
 | 
			
		||||
    <OpenAL32Dll Include="$(MSBuildProjectDirectory)\..\..\..\deps\win\x86\OpenAL32.dll" Condition="'$(RuntimeIdentifier)' == 'win-x86'" />
 | 
			
		||||
    <OpenAL32Dll Include="$(MSBuildProjectDirectory)\..\..\..\deps\win\x64\OpenAL32.dll" Condition="'$(RuntimeIdentifier)' == 'win-x64'" />
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <OpenAL32Dll Include="$(MSBuildProjectDirectory)\..\..\..\deps\win\x86\OpenAL32.dll" Condition="'$(RuntimeIdentifier)' == 'win-x86' or '$(PlatformTarget)' == 'x86'" />
 | 
			
		||||
    <OpenAL32Dll Include="$(MSBuildProjectDirectory)\..\..\..\deps\win\x64\OpenAL32.dll" Condition="'$(RuntimeIdentifier)' == 'win-x64' or '$(PlatformTarget)' == 'x64'" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <Copy SourceFiles="@(OpenAL32Dll)" DestinationFiles="$(OutputPath)\OpenAL32.dll" />
 | 
			
		||||
</Target>
 | 
			
		||||
| 
						 | 
				
			
			@ -78,6 +92,6 @@
 | 
			
		|||
    <OpenAL32Dll Include="$(MSBuildProjectDirectory)\..\..\..\deps\win\x86\OpenAL32.dll" Condition="'$(RuntimeIdentifier)' == 'win-x86'" />
 | 
			
		||||
    <OpenAL32Dll Include="$(MSBuildProjectDirectory)\..\..\..\deps\win\x64\OpenAL32.dll" Condition="'$(RuntimeIdentifier)' == 'win-x64'" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <Copy SourceFiles="@(OpenAL32Dll)" DestinationFiles="$(PublishDir)\OpenAL32.dll"/>
 | 
			
		||||
  <Copy SourceFiles="@(OpenAL32Dll)" DestinationFiles="$(PublishDir)\OpenAL32.dll" />
 | 
			
		||||
</Target>
 | 
			
		||||
</Project>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,10 +2,10 @@
 | 
			
		|||
using Avalonia;
 | 
			
		||||
using Velopack;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.UI
 | 
			
		||||
namespace Plpext.UI;
 | 
			
		||||
 | 
			
		||||
internal sealed class Program
 | 
			
		||||
{
 | 
			
		||||
    internal sealed class Program
 | 
			
		||||
    {
 | 
			
		||||
    // Initialization code. Don't use any Avalonia, third-party APIs or any
 | 
			
		||||
    // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
 | 
			
		||||
    // yet and stuff might break.
 | 
			
		||||
| 
						 | 
				
			
			@ -22,5 +22,4 @@ namespace Plpext.UI
 | 
			
		|||
            .UsePlatformDetect()
 | 
			
		||||
            .WithInterFont()
 | 
			
		||||
            .LogToTrace();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,6 @@ using System.Linq;
 | 
			
		|||
using System.Threading.Tasks;
 | 
			
		||||
using Plpext.Core.AudioPlayer;
 | 
			
		||||
using Plpext.Core.Interfaces;
 | 
			
		||||
using Plpext.Core.Models;
 | 
			
		||||
using Plpext.UI.ViewModels;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.UI.Services.FileLoader;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,6 @@
 | 
			
		|||
using Avalonia;
 | 
			
		||||
using Avalonia.Controls.ApplicationLifetimes;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Platform.Storage;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -21,7 +18,7 @@ namespace Plpext.UI.Services.PlatformStorage
 | 
			
		|||
            {
 | 
			
		||||
                AllowMultiple = false,
 | 
			
		||||
                Title = "Select Plus Library Pack",
 | 
			
		||||
                FileTypeFilter = [new ("Plus Library Pack"){Patterns = ["*.plp"]}],
 | 
			
		||||
                FileTypeFilter = [new("Plus Library Pack") { Patterns = ["*.plp"] }],
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            return filePath.Any() ? filePath[0].Path.AbsolutePath : string.Empty;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,37 +1,43 @@
 | 
			
		|||
<Styles xmlns="https://github.com/avaloniaui"
 | 
			
		||||
<Styles
 | 
			
		||||
    xmlns="https://github.com/avaloniaui"
 | 
			
		||||
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
    xmlns:c="clr-namespace:Plpext.UI"
 | 
			
		||||
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
    xmlns:vm="clr-namespace:Plpext.UI.ViewModels">
 | 
			
		||||
    <Design.PreviewWith>
 | 
			
		||||
        <Border Padding="20" Background="RoyalBlue" BorderBrush="Black" BorderThickness="1">
 | 
			
		||||
        <Border
 | 
			
		||||
            Padding="20"
 | 
			
		||||
            Background="RoyalBlue"
 | 
			
		||||
            BorderBrush="Black"
 | 
			
		||||
            BorderThickness="1">
 | 
			
		||||
            <StackPanel>
 | 
			
		||||
                <Border Background="Navy" BorderBrush="White" BorderThickness="1">
 | 
			
		||||
                <Border
 | 
			
		||||
                    Background="Navy"
 | 
			
		||||
                    BorderBrush="White"
 | 
			
		||||
                    BorderThickness="1">
 | 
			
		||||
                    <c:AudioPlayerControl
 | 
			
		||||
                        x:DataType="vm:AudioPlayerViewModel"
 | 
			
		||||
                        CurrentDuration="0:15"
 | 
			
		||||
                        IsPlaying="{Binding IsPlaying}"
 | 
			
		||||
                        PlayCommand="{Binding PlayCommand}"
 | 
			
		||||
                    StopCommand="{Binding StopCommand}"
 | 
			
		||||
                        PlaybackState="{Binding PlaybackState}"
 | 
			
		||||
                TotalDuration="0:22"
 | 
			
		||||
                CurrentDuration="0:15"
 | 
			
		||||
                        Progress="44.8"
 | 
			
		||||
                >
 | 
			
		||||
                        StopCommand="{Binding StopCommand}"
 | 
			
		||||
                        TotalDuration="0:22">
 | 
			
		||||
                        <c:AudioPlayerControl.DataContext>
 | 
			
		||||
                        <vm:AudioPlayerViewModel/>
 | 
			
		||||
                            <vm:AudioPlayerViewModel />
 | 
			
		||||
                        </c:AudioPlayerControl.DataContext>
 | 
			
		||||
                    </c:AudioPlayerControl>
 | 
			
		||||
                </Border>
 | 
			
		||||
                <c:AudioPlayerControl
 | 
			
		||||
                    x:DataType="vm:AudioPlayerViewModel"
 | 
			
		||||
                    CurrentDuration="15"
 | 
			
		||||
                    IsPlaying="True"
 | 
			
		||||
                    PlayCommand="{Binding PlayCommand}"
 | 
			
		||||
                    TotalDuration="22"
 | 
			
		||||
                    CurrentDuration="15"
 | 
			
		||||
                    Progress="44.8"
 | 
			
		||||
                >
 | 
			
		||||
                    TotalDuration="22">
 | 
			
		||||
                    <c:AudioPlayerControl.DataContext>
 | 
			
		||||
                        <vm:AudioPlayerViewModel/>
 | 
			
		||||
                        <vm:AudioPlayerViewModel />
 | 
			
		||||
                    </c:AudioPlayerControl.DataContext>
 | 
			
		||||
                </c:AudioPlayerControl>
 | 
			
		||||
            </StackPanel>
 | 
			
		||||
| 
						 | 
				
			
			@ -39,48 +45,48 @@
 | 
			
		|||
    </Design.PreviewWith>
 | 
			
		||||
 | 
			
		||||
    <Style Selector="c|AudioPlayerControl">
 | 
			
		||||
        <Setter Property="FontSize" Value="14"/>
 | 
			
		||||
        <Setter Property="Margin" Value="0,0,0,0"/>
 | 
			
		||||
        <Setter Property="Width" Value="176"></Setter>
 | 
			
		||||
        <Setter Property="Height" Value="36"></Setter>
 | 
			
		||||
        <Setter Property="FontSize" Value="14" />
 | 
			
		||||
        <Setter Property="Margin" Value="0,0,0,0" />
 | 
			
		||||
        <Setter Property="Width" Value="176" />
 | 
			
		||||
        <Setter Property="Height" Value="36" />
 | 
			
		||||
    </Style>
 | 
			
		||||
    <Style Selector="c|AudioPlayerControl Button">
 | 
			
		||||
        <Setter Property="Foreground" Value="{StaticResource SecondaryLightest}"/>
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource SecondaryDarkest}"/>
 | 
			
		||||
        <Setter Property="BorderThickness" Value="2"/>
 | 
			
		||||
        <Setter Property="BorderBrush" Value="{StaticResource SecondaryDark}"/>
 | 
			
		||||
        <Setter Property="Foreground" Value="{StaticResource SecondaryLightest}" />
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource SecondaryDarkest}" />
 | 
			
		||||
        <Setter Property="BorderThickness" Value="2" />
 | 
			
		||||
        <Setter Property="BorderBrush" Value="{StaticResource SecondaryDark}" />
 | 
			
		||||
    </Style>
 | 
			
		||||
    <Style Selector="c|AudioPlayerControl Button:pointerover">
 | 
			
		||||
        <Setter Property="Foreground" Value="{StaticResource SecondaryMiddle}"/>
 | 
			
		||||
        <Setter Property="Foreground" Value="{StaticResource SecondaryMiddle}" />
 | 
			
		||||
    </Style>
 | 
			
		||||
    <Style Selector="c|AudioPlayerControl Button:pointerover /template/ ContentPresenter">
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource SecondaryDark}"/>
 | 
			
		||||
        <Setter Property="BorderThickness" Value="2"/>
 | 
			
		||||
        <Setter Property="BorderBrush" Value="{StaticResource SecondaryDarkest}"/>
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource SecondaryDark}" />
 | 
			
		||||
        <Setter Property="BorderThickness" Value="2" />
 | 
			
		||||
        <Setter Property="BorderBrush" Value="{StaticResource SecondaryDarkest}" />
 | 
			
		||||
    </Style>
 | 
			
		||||
    <Style Selector="c|AudioPlayerControl[IsPlaying=False] /template/ Grid#ButtonGrid">
 | 
			
		||||
        <Setter Property="Margin" Value="142,0,-32,0"/>
 | 
			
		||||
        <Setter Property="Margin" Value="142,0,-32,0" />
 | 
			
		||||
    </Style>
 | 
			
		||||
    <Style Selector="c|AudioPlayerControl[IsPlaying=True] /template/ Grid#ButtonGrid">
 | 
			
		||||
        <Setter Property="Margin" Value="0,0,0,0"/>
 | 
			
		||||
        <Setter Property="Margin" Value="0,0,0,0" />
 | 
			
		||||
    </Style>
 | 
			
		||||
    <Style Selector="c|AudioPlayerControl[IsPlaying=False] /template/ StackPanel#ProgressPanel">
 | 
			
		||||
        <Setter Property="Width" Value="0"/>
 | 
			
		||||
        <Setter Property="Opacity" Value="0"/>
 | 
			
		||||
        <Setter Property="Width" Value="0" />
 | 
			
		||||
        <Setter Property="Opacity" Value="0" />
 | 
			
		||||
    </Style>
 | 
			
		||||
    <Style Selector="c|AudioPlayerControl[IsPlaying=True] /template/ StackPanel#ProgressPanel">
 | 
			
		||||
        <Setter Property="UseLayoutRounding" Value="True"/>
 | 
			
		||||
        <Setter Property="Opacity" Value="1"/>
 | 
			
		||||
        <Setter Property="Margin" Value="6,10,0,0"/>
 | 
			
		||||
        <Setter Property="VerticalAlignment" Value="Center"/>
 | 
			
		||||
        <Setter Property="UseLayoutRounding" Value="True" />
 | 
			
		||||
        <Setter Property="Opacity" Value="1" />
 | 
			
		||||
        <Setter Property="Margin" Value="6,10,0,0" />
 | 
			
		||||
        <Setter Property="VerticalAlignment" Value="Center" />
 | 
			
		||||
    </Style>
 | 
			
		||||
    <Style Selector="c|AudioPlayerControl[IsPlaying=False] /template/ ProgressBar:horizontal">
 | 
			
		||||
        <Setter Property="MinWidth" Value="0"/>
 | 
			
		||||
        <Setter Property="Width" Value="0"/>
 | 
			
		||||
        <Setter Property="MinWidth" Value="0" />
 | 
			
		||||
        <Setter Property="Width" Value="0" />
 | 
			
		||||
    </Style>
 | 
			
		||||
    <Style Selector="c|AudioPlayerControl[IsPlaying=True] /template/ ProgressBar:horizontal">
 | 
			
		||||
        <Setter Property="MinWidth" Value="0"/>
 | 
			
		||||
        <Setter Property="Width" Value="100"/>
 | 
			
		||||
        <Setter Property="MinWidth" Value="0" />
 | 
			
		||||
        <Setter Property="Width" Value="100" />
 | 
			
		||||
    </Style>
 | 
			
		||||
 | 
			
		||||
</Styles>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,15 +1,17 @@
 | 
			
		|||
<Styles xmlns="https://github.com/avaloniaui"
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 | 
			
		||||
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 | 
			
		||||
    <Design.PreviewWith>
 | 
			
		||||
        <Border Padding="20">
 | 
			
		||||
            <!-- Add Controls for Previewer Here -->
 | 
			
		||||
            <Border
 | 
			
		||||
                Width="100"
 | 
			
		||||
                Height="100"
 | 
			
		||||
                Classes="Section" />
 | 
			
		||||
        </Border>
 | 
			
		||||
    </Design.PreviewWith>
 | 
			
		||||
 | 
			
		||||
    <Style Selector="Border.Section">
 | 
			
		||||
        <Setter Property="BorderBrush" Value="{StaticResource PrimaryForeground}"/>
 | 
			
		||||
        <Setter Property="BorderThickness" Value="1"/>
 | 
			
		||||
        <Setter Property="BoxShadow" Value="0 0 1 1 Black"/>
 | 
			
		||||
        <Setter Property="CornerRadius" Value="1"/>
 | 
			
		||||
        <Setter Property="BorderBrush" Value="{StaticResource PrimaryForeground}" />
 | 
			
		||||
        <Setter Property="BorderThickness" Value="1" />
 | 
			
		||||
        <Setter Property="BoxShadow" Value="0 0 1 1 Black" />
 | 
			
		||||
        <Setter Property="CornerRadius" Value="1" />
 | 
			
		||||
    </Style>
 | 
			
		||||
</Styles>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,30 +1,32 @@
 | 
			
		|||
<Styles xmlns="https://github.com/avaloniaui"
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 | 
			
		||||
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 | 
			
		||||
    <Design.PreviewWith>
 | 
			
		||||
        <Border Padding="20">
 | 
			
		||||
            <StackPanel>
 | 
			
		||||
                <Button Classes="Primary" Content="Primary Button" />
 | 
			
		||||
                <Button IsEnabled="False" Classes="Primary" Content="Primary Button" />
 | 
			
		||||
            </StackPanel>            <!-- Add Controls for Previewer Here -->
 | 
			
		||||
                <Button
 | 
			
		||||
                    Classes="Primary"
 | 
			
		||||
                    Content="Primary Button"
 | 
			
		||||
                    IsEnabled="False" />
 | 
			
		||||
            </StackPanel>
 | 
			
		||||
        </Border>
 | 
			
		||||
    </Design.PreviewWith>
 | 
			
		||||
 | 
			
		||||
    <Style Selector="Button.Primary">
 | 
			
		||||
        <Setter Property="BorderThickness" Value="1"/>
 | 
			
		||||
        <Setter Property="BorderBrush" Value="{StaticResource SecondaryDarkestBrush}"/>
 | 
			
		||||
        <Setter Property="Padding" Value="8 12 8 12"/>
 | 
			
		||||
        <Setter Property="CornerRadius" Value="4"/>
 | 
			
		||||
        <Setter Property="Margin" Value="2"/>
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource SecondaryDark}"/>
 | 
			
		||||
        <Setter Property="Foreground" Value="{StaticResource SecondaryLightest}"/>
 | 
			
		||||
        <Setter Property="BorderThickness" Value="1" />
 | 
			
		||||
        <Setter Property="BorderBrush" Value="{StaticResource SecondaryDarkestBrush}" />
 | 
			
		||||
        <Setter Property="Padding" Value="8 12 8 12" />
 | 
			
		||||
        <Setter Property="CornerRadius" Value="4" />
 | 
			
		||||
        <Setter Property="Margin" Value="2" />
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource SecondaryDark}" />
 | 
			
		||||
        <Setter Property="Foreground" Value="{StaticResource SecondaryLightest}" />
 | 
			
		||||
    </Style>
 | 
			
		||||
    <Style Selector="Button.Primary:disabled /template/ ContentPresenter">
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource SecondaryDarkest}"/>
 | 
			
		||||
        <Setter Property="Foreground" Value="Gray"/>
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource SecondaryDarkest}" />
 | 
			
		||||
        <Setter Property="Foreground" Value="Gray" />
 | 
			
		||||
    </Style>
 | 
			
		||||
    <Style Selector="Button.Primary:pointerover /template/ ContentPresenter">
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource SecondaryLightest}"/>
 | 
			
		||||
        <Setter Property="Foreground" Value="{StaticResource SecondaryDarkest}"/>
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource SecondaryLightest}" />
 | 
			
		||||
        <Setter Property="Foreground" Value="{StaticResource SecondaryDarkest}" />
 | 
			
		||||
    </Style>
 | 
			
		||||
 | 
			
		||||
</Styles>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,15 +1,12 @@
 | 
			
		|||
<Styles xmlns="https://github.com/avaloniaui"
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 | 
			
		||||
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 | 
			
		||||
    <Design.PreviewWith>
 | 
			
		||||
        <Border Padding="20">
 | 
			
		||||
            <!-- Add Controls for Previewer Here -->
 | 
			
		||||
            <TextBox Classes="Primary"></TextBox>
 | 
			
		||||
            <TextBox Classes="Primary" />
 | 
			
		||||
        </Border>
 | 
			
		||||
    </Design.PreviewWith>
 | 
			
		||||
 | 
			
		||||
    <Style Selector="TextBox.Primary">
 | 
			
		||||
        <Setter Property="Height" Value="32"/>
 | 
			
		||||
        
 | 
			
		||||
        <Setter Property="Height" Value="32" />
 | 
			
		||||
    </Style>
 | 
			
		||||
 | 
			
		||||
</Styles>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,9 @@
 | 
			
		|||
    </Design.PreviewWith>
 | 
			
		||||
    
 | 
			
		||||
    <Style Selector="Window">
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource PrimaryBackground}"></Setter>
 | 
			
		||||
        <Setter Property="Background" Value="{StaticResource PrimaryBackground}"/>
 | 
			
		||||
        <Setter Property="CanResize" Value="False"/>
 | 
			
		||||
        <Setter Property="Width" Value="800"/>
 | 
			
		||||
        <Setter Property="Height" Value="450"/>
 | 
			
		||||
    </Style>
 | 
			
		||||
</Styles>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,17 +2,13 @@
 | 
			
		|||
using Plpext.Core.AudioPlayer;
 | 
			
		||||
using Plpext.Core.Models;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using CommunityToolkit.Mvvm.Input;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.UI.ViewModels
 | 
			
		||||
namespace Plpext.UI.ViewModels;
 | 
			
		||||
 | 
			
		||||
public partial class AudioPlayerViewModel : ViewModelBase, IDisposable
 | 
			
		||||
{
 | 
			
		||||
    public partial class AudioPlayerViewModel : ViewModelBase, IDisposable
 | 
			
		||||
    {
 | 
			
		||||
    private readonly AudioPlayer _audioPlayer = null!;
 | 
			
		||||
    private readonly AudioFile _audioFile = null!;
 | 
			
		||||
    private bool _firstExecution = true;
 | 
			
		||||
| 
						 | 
				
			
			@ -65,10 +61,12 @@ namespace Plpext.UI.ViewModels
 | 
			
		|||
    [ObservableProperty]
 | 
			
		||||
    private string _name = null!;
 | 
			
		||||
 | 
			
		||||
        [ObservableProperty] private PlaybackState _playbackState = PlaybackState.Stopped;
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    private PlaybackState _playbackState = PlaybackState.Stopped;
 | 
			
		||||
    
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    private double _progress;
 | 
			
		||||
    private bool disposedValue;
 | 
			
		||||
 | 
			
		||||
    [RelayCommand]
 | 
			
		||||
    private async Task Play()
 | 
			
		||||
| 
						 | 
				
			
			@ -109,12 +107,24 @@ namespace Plpext.UI.ViewModels
 | 
			
		|||
        return Task.CompletedTask;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public void Dispose()
 | 
			
		||||
    protected virtual void Dispose(bool disposing)
 | 
			
		||||
    {
 | 
			
		||||
        if (!disposedValue)
 | 
			
		||||
        {
 | 
			
		||||
            if (disposing)
 | 
			
		||||
            {
 | 
			
		||||
                _audioPlayer.OnPlaybackStopped -= OnPlaybackStopped;
 | 
			
		||||
                _audioPlayer.OnProgressUpdated -= OnProgressUpdated;
 | 
			
		||||
                _audioPlayer.Dispose();
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            disposedValue = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Dispose()
 | 
			
		||||
    {
 | 
			
		||||
        Dispose(disposing: true);
 | 
			
		||||
        GC.SuppressFinalize(this);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -18,7 +18,9 @@ public partial class MainWindowViewModel : ViewModelBase
 | 
			
		|||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public MainWindowViewModel(IPlatformStorageService platformStorageService, IFileLoaderService fileLoaderService,
 | 
			
		||||
    public MainWindowViewModel(
 | 
			
		||||
        IPlatformStorageService platformStorageService, 
 | 
			
		||||
        IFileLoaderService fileLoaderService,
 | 
			
		||||
        IConvertService convertService)
 | 
			
		||||
    {
 | 
			
		||||
        _fileLoaderService = fileLoaderService;
 | 
			
		||||
| 
						 | 
				
			
			@ -26,30 +28,43 @@ public partial class MainWindowViewModel : ViewModelBase
 | 
			
		|||
        _convertService = convertService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [ObservableProperty] [NotifyCanExecuteChangedFor(nameof(LoadFileCommand))]
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    [NotifyCanExecuteChangedFor(nameof(LoadFileCommand))]
 | 
			
		||||
    private string _originPath = null!;
 | 
			
		||||
 | 
			
		||||
    [ObservableProperty] [NotifyCanExecuteChangedFor(nameof(ConvertAllFilesCommand),nameof(ConvertSelectedFilesCommand))]
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    [NotifyCanExecuteChangedFor(nameof(ConvertAllFilesCommand), nameof(ConvertSelectedFilesCommand))]
 | 
			
		||||
    private string _targetPath = null!;
 | 
			
		||||
 | 
			
		||||
    [ObservableProperty] private int _totalFilesToExtract;
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    private int _totalFilesToExtract;
 | 
			
		||||
 | 
			
		||||
    [ObservableProperty] private int _filesReady;
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    private int _filesReady;
 | 
			
		||||
 | 
			
		||||
    [ObservableProperty] private string _progressBarText = null!;
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    private string _progressBarText = null!;
 | 
			
		||||
 | 
			
		||||
    [ObservableProperty] private double _progressBarValue;
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    private double _progressBarValue;
 | 
			
		||||
 | 
			
		||||
    [ObservableProperty] private bool _isProgressBarIndeterminate;
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    private bool _isProgressBarIndeterminate;
 | 
			
		||||
 | 
			
		||||
    [ObservableProperty] private string _progressBarDetails = null!;
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    private string _progressBarDetails = null!;
 | 
			
		||||
 | 
			
		||||
    [ObservableProperty] [NotifyCanExecuteChangedFor(nameof(ConvertAllFilesCommand), nameof(ConvertSelectedFilesCommand), nameof(LoadFileCommand))]
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    [NotifyCanExecuteChangedFor(nameof(ConvertAllFilesCommand), nameof(ConvertSelectedFilesCommand), nameof(LoadFileCommand))]
 | 
			
		||||
    private bool _showProgressBar;
 | 
			
		||||
 | 
			
		||||
    [ObservableProperty] [NotifyCanExecuteChangedFor(nameof(ConvertAllFilesCommand),nameof(ConvertSelectedFilesCommand))]
 | 
			
		||||
    [ObservableProperty]
 | 
			
		||||
    [NotifyCanExecuteChangedFor(nameof(ConvertAllFilesCommand), nameof(ConvertSelectedFilesCommand))]
 | 
			
		||||
    private ObservableCollection<AudioPlayerViewModel> _audioFiles = new();
 | 
			
		||||
 | 
			
		||||
    private bool CanLoadFile() => !string.IsNullOrEmpty(OriginPath) && !ShowProgressBar;
 | 
			
		||||
    private bool CanConvertAllFiles() => !string.IsNullOrEmpty(TargetPath) && AudioFiles.Any() && !ShowProgressBar;
 | 
			
		||||
    private bool CanConvertSelectFiles() => CanConvertAllFiles();
 | 
			
		||||
 | 
			
		||||
    [RelayCommand(CanExecute = nameof(CanLoadFile))]
 | 
			
		||||
    private async Task LoadFile()
 | 
			
		||||
| 
						 | 
				
			
			@ -79,9 +94,6 @@ public partial class MainWindowViewModel : ViewModelBase
 | 
			
		|||
        await Dispatcher.UIThread.InvokeAsync(() => ShowProgressBar = false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private bool CanLoadFile() => !string.IsNullOrEmpty(OriginPath) && !ShowProgressBar;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    [RelayCommand]
 | 
			
		||||
    private async Task SelectOriginPath()
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -108,10 +120,6 @@ public partial class MainWindowViewModel : ViewModelBase
 | 
			
		|||
        await Dispatcher.UIThread.InvokeAsync(() => ShowProgressBar = false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private bool CanConvertAllFiles() => !string.IsNullOrEmpty(TargetPath) && AudioFiles.Any() && !ShowProgressBar;
 | 
			
		||||
    private bool CanConvertSelectFiles() => CanConvertAllFiles();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    [RelayCommand(CanExecute = nameof(CanConvertSelectFiles))]
 | 
			
		||||
    private async Task ConvertSelectedFiles()
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,7 @@
 | 
			
		|||
using CommunityToolkit.Mvvm.ComponentModel;
 | 
			
		||||
 | 
			
		||||
namespace Plpext.UI.ViewModels
 | 
			
		||||
namespace Plpext.UI.ViewModels;
 | 
			
		||||
 | 
			
		||||
public class ViewModelBase : ObservableObject
 | 
			
		||||
{
 | 
			
		||||
    public class ViewModelBase : ObservableObject
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -9,8 +9,6 @@
 | 
			
		|||
    Title="Plpext"
 | 
			
		||||
    d:DesignHeight="450"
 | 
			
		||||
    d:DesignWidth="800"
 | 
			
		||||
    Width="800"
 | 
			
		||||
    Height="450"
 | 
			
		||||
    x:DataType="vm:MainWindowViewModel"
 | 
			
		||||
    Icon="/Assets/plpext.png"
 | 
			
		||||
    mc:Ignorable="d">
 | 
			
		||||
| 
						 | 
				
			
			@ -24,19 +22,17 @@
 | 
			
		|||
    </Window.Styles>
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <!--
 | 
			
		||||
            This only sets the DataContext for the previewer in an IDE,
 | 
			
		||||
            to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs)
 | 
			
		||||
        -->
 | 
			
		||||
        <vm:MainWindowViewModel />
 | 
			
		||||
    </Design.DataContext>
 | 
			
		||||
 | 
			
		||||
    <Grid
 | 
			
		||||
        Margin="16, 8, 16, 8"
 | 
			
		||||
        Margin="16,8,16,8"
 | 
			
		||||
        ColumnDefinitions="300,32,*"
 | 
			
		||||
        RowDefinitions="Auto,Auto,*">
 | 
			
		||||
        <Border Grid.Row="0"
 | 
			
		||||
                Grid.Column="0" Classes="Section">
 | 
			
		||||
        <Border
 | 
			
		||||
            Grid.Row="0"
 | 
			
		||||
            Grid.Column="0"
 | 
			
		||||
            Classes="Section">
 | 
			
		||||
 | 
			
		||||
            <StackPanel Orientation="Vertical">
 | 
			
		||||
                <Grid
 | 
			
		||||
| 
						 | 
				
			
			@ -44,8 +40,9 @@
 | 
			
		|||
                    ColumnDefinitions="*"
 | 
			
		||||
                    RowDefinitions="*, Auto, Auto">
 | 
			
		||||
                    <Label Grid.Row="0" Content="Select your .plp pack file:" />
 | 
			
		||||
                    <StackPanel Height="36"
 | 
			
		||||
                    <StackPanel
 | 
			
		||||
                        Grid.Row="1"
 | 
			
		||||
                        Height="36"
 | 
			
		||||
                        Orientation="Horizontal"
 | 
			
		||||
                        Spacing="2">
 | 
			
		||||
                        <TextBox
 | 
			
		||||
| 
						 | 
				
			
			@ -59,10 +56,10 @@
 | 
			
		|||
                        </Button>
 | 
			
		||||
                    </StackPanel>
 | 
			
		||||
                    <Button
 | 
			
		||||
                        Height="38"
 | 
			
		||||
                        Grid.Row="2"
 | 
			
		||||
                        Height="38"
 | 
			
		||||
                        Margin="0,4,0,0"
 | 
			
		||||
                        HorizontalAlignment="Right"
 | 
			
		||||
                        Margin="0 4 0 0"
 | 
			
		||||
                        Classes="Primary"
 | 
			
		||||
                        Command="{Binding LoadFileCommand}">
 | 
			
		||||
                        <TextBlock VerticalAlignment="Center">Load</TextBlock>
 | 
			
		||||
| 
						 | 
				
			
			@ -78,10 +75,10 @@
 | 
			
		|||
                        Grid.ColumnSpan="2"
 | 
			
		||||
                        Content="Select output folder:" />
 | 
			
		||||
                    <StackPanel
 | 
			
		||||
                        Height="36"
 | 
			
		||||
                        Grid.Row="1"
 | 
			
		||||
                        Grid.Column="0"
 | 
			
		||||
                        Grid.ColumnSpan="2"
 | 
			
		||||
                        Height="36"
 | 
			
		||||
                        Orientation="Horizontal"
 | 
			
		||||
                        Spacing="2">
 | 
			
		||||
                        <TextBox
 | 
			
		||||
| 
						 | 
				
			
			@ -94,19 +91,19 @@
 | 
			
		|||
                        </Button>
 | 
			
		||||
                    </StackPanel>
 | 
			
		||||
                    <Button
 | 
			
		||||
                        HorizontalAlignment="Left"
 | 
			
		||||
                        Height="38"
 | 
			
		||||
                        Grid.Row="2"
 | 
			
		||||
                        Grid.Column="0"
 | 
			
		||||
                        Height="38"
 | 
			
		||||
                        HorizontalAlignment="Left"
 | 
			
		||||
                        Classes="Primary"
 | 
			
		||||
                        Command="{Binding ConvertAllFilesCommand}">
 | 
			
		||||
                        <TextBlock VerticalAlignment="Center">Extract All</TextBlock>
 | 
			
		||||
                    </Button>
 | 
			
		||||
                    <Button
 | 
			
		||||
                        Height="38"
 | 
			
		||||
                        HorizontalAlignment="Right"
 | 
			
		||||
                        Grid.Row="2"
 | 
			
		||||
                        Grid.Column="1"
 | 
			
		||||
                        Height="38"
 | 
			
		||||
                        HorizontalAlignment="Right"
 | 
			
		||||
                        Classes="Primary"
 | 
			
		||||
                        Command="{Binding ConvertSelectedFilesCommand}">
 | 
			
		||||
                        <TextBlock VerticalAlignment="Center">Extract Selected</TextBlock>
 | 
			
		||||
| 
						 | 
				
			
			@ -117,12 +114,21 @@
 | 
			
		|||
 | 
			
		||||
        </Border>
 | 
			
		||||
        <Grid Grid.Row="2" Grid.Column="0">
 | 
			
		||||
            <StackPanel Orientation="Vertical" VerticalAlignment="Center" Height="60" IsVisible="{Binding ShowProgressBar}">
 | 
			
		||||
            <Label Content="{Binding ProgressBarText}"/>
 | 
			
		||||
            <StackPanel
 | 
			
		||||
                Height="60"
 | 
			
		||||
                VerticalAlignment="Center"
 | 
			
		||||
                IsVisible="{Binding ShowProgressBar}"
 | 
			
		||||
                Orientation="Vertical">
 | 
			
		||||
                <Label Content="{Binding ProgressBarText}" />
 | 
			
		||||
                <Border Classes="Section">
 | 
			
		||||
                    <ProgressBar Width="298" Orientation="Horizontal" Height="50" IsIndeterminate="{Binding IsProgressBarIndeterminate}" Value="{Binding ProgressBarValue}" />
 | 
			
		||||
                    <ProgressBar
 | 
			
		||||
                        Width="298"
 | 
			
		||||
                        Height="50"
 | 
			
		||||
                        IsIndeterminate="{Binding IsProgressBarIndeterminate}"
 | 
			
		||||
                        Orientation="Horizontal"
 | 
			
		||||
                        Value="{Binding ProgressBarValue}" />
 | 
			
		||||
                </Border>
 | 
			
		||||
            <Label Content="{Binding ProgressBarDetails}" HorizontalAlignment="Right"/>
 | 
			
		||||
                <Label HorizontalAlignment="Right" Content="{Binding ProgressBarDetails}" />
 | 
			
		||||
            </StackPanel>
 | 
			
		||||
        </Grid>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -136,23 +142,24 @@
 | 
			
		|||
                </StackPanel>
 | 
			
		||||
                <DataGrid
 | 
			
		||||
                    MaxHeight="410"
 | 
			
		||||
                    CanUserSortColumns="False"
 | 
			
		||||
                    CanUserResizeColumns="False"
 | 
			
		||||
                    CanUserReorderColumns="False"
 | 
			
		||||
                    AreRowDetailsFrozen="True"
 | 
			
		||||
                    HeadersVisibility="None"
 | 
			
		||||
                    AutoGenerateColumns="False"
 | 
			
		||||
                    VerticalScrollBarVisibility="Visible"
 | 
			
		||||
                    CanUserReorderColumns="False"
 | 
			
		||||
                    CanUserResizeColumns="False"
 | 
			
		||||
                    CanUserSortColumns="False"
 | 
			
		||||
                    HeadersVisibility="None"
 | 
			
		||||
                    IsReadOnly="False"
 | 
			
		||||
                    ItemsSource="{Binding AudioFiles}"
 | 
			
		||||
                    SelectionMode="Extended"
 | 
			
		||||
                    ItemsSource="{Binding AudioFiles}">
 | 
			
		||||
                    VerticalScrollBarVisibility="Visible">
 | 
			
		||||
                    <DataGrid.Columns>
 | 
			
		||||
                        <DataGridTemplateColumn Width="36">
 | 
			
		||||
                            <DataGridTemplateColumn.CellTemplate>
 | 
			
		||||
                                <DataTemplate>
 | 
			
		||||
                                    <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"
 | 
			
		||||
                                    <CheckBox
 | 
			
		||||
                                        HorizontalAlignment="Center"
 | 
			
		||||
                                              VerticalAlignment="Center" />
 | 
			
		||||
                                        VerticalAlignment="Center"
 | 
			
		||||
                                        IsChecked="{Binding IsSelected, Mode=TwoWay}" />
 | 
			
		||||
                                </DataTemplate>
 | 
			
		||||
                            </DataGridTemplateColumn.CellTemplate>
 | 
			
		||||
                        </DataGridTemplateColumn>
 | 
			
		||||
| 
						 | 
				
			
			@ -167,14 +174,14 @@
 | 
			
		|||
                            <DataGridTemplateColumn.CellTemplate>
 | 
			
		||||
                                <DataTemplate DataType="vm:AudioPlayerViewModel">
 | 
			
		||||
                                    <c:AudioPlayerControl
 | 
			
		||||
                                        Margin="0 0 16 0"
 | 
			
		||||
                                        Margin="0,0,16,0"
 | 
			
		||||
                                        CurrentDuration="{Binding CurrentDuration}"
 | 
			
		||||
                                        TotalDuration="{Binding TotalDuration}"
 | 
			
		||||
                                        PlayCommand="{Binding PlayCommand}"
 | 
			
		||||
                                        StopCommand="{Binding StopCommand}"
 | 
			
		||||
                                        IsPlaying="{Binding IsPlaying}"
 | 
			
		||||
                                        PlayCommand="{Binding PlayCommand}"
 | 
			
		||||
                                        PlaybackState="{Binding PlaybackState}"
 | 
			
		||||
                                        Progress="{Binding Progress}" />
 | 
			
		||||
                                        Progress="{Binding Progress}"
 | 
			
		||||
                                        StopCommand="{Binding StopCommand}"
 | 
			
		||||
                                        TotalDuration="{Binding TotalDuration}" />
 | 
			
		||||
                                </DataTemplate>
 | 
			
		||||
                            </DataGridTemplateColumn.CellTemplate>
 | 
			
		||||
                        </DataGridTemplateColumn>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +0,0 @@
 | 
			
		|||
{
 | 
			
		||||
    "version": "1.0.0",
 | 
			
		||||
    "executable": "Plpext.exe",
 | 
			
		||||
    "iconFile": "Assets/plpext.png",
 | 
			
		||||
    "splashImage": "Assets/plpext.png"
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -9,34 +9,24 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plpext.Core", "..\Plpext.Co
 | 
			
		|||
EndProject
 | 
			
		||||
Global
 | 
			
		||||
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 | 
			
		||||
		Debug|Any CPU = Debug|Any CPU
 | 
			
		||||
		Debug|x64 = Debug|x64
 | 
			
		||||
		Debug|x86 = Debug|x86
 | 
			
		||||
		Release|Any CPU = Release|Any CPU
 | 
			
		||||
		Release|x64 = Release|x64
 | 
			
		||||
		Release|x86 = Release|x86
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Debug|x64.ActiveCfg = Debug|x64
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Debug|x64.Build.0 = Debug|x64
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Debug|x86.ActiveCfg = Debug|x86
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Debug|x86.Build.0 = Debug|x86
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Release|x64.ActiveCfg = Release|x64
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Release|x64.Build.0 = Release|x64
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Release|x86.ActiveCfg = Release|x86
 | 
			
		||||
		{CEC79B8A-12B4-4649-B859-08051B00FA96}.Release|x86.Build.0 = Release|x86
 | 
			
		||||
		{2A0B3CBC-C79F-4B19-93AE-BCEEE44BDAD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{2A0B3CBC-C79F-4B19-93AE-BCEEE44BDAD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{2A0B3CBC-C79F-4B19-93AE-BCEEE44BDAD2}.Debug|x64.ActiveCfg = Debug|x64
 | 
			
		||||
		{2A0B3CBC-C79F-4B19-93AE-BCEEE44BDAD2}.Debug|x64.Build.0 = Debug|x64
 | 
			
		||||
		{2A0B3CBC-C79F-4B19-93AE-BCEEE44BDAD2}.Debug|x86.ActiveCfg = Debug|x86
 | 
			
		||||
		{2A0B3CBC-C79F-4B19-93AE-BCEEE44BDAD2}.Debug|x86.Build.0 = Debug|x86
 | 
			
		||||
		{2A0B3CBC-C79F-4B19-93AE-BCEEE44BDAD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{2A0B3CBC-C79F-4B19-93AE-BCEEE44BDAD2}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{2A0B3CBC-C79F-4B19-93AE-BCEEE44BDAD2}.Release|x64.ActiveCfg = Release|x64
 | 
			
		||||
		{2A0B3CBC-C79F-4B19-93AE-BCEEE44BDAD2}.Release|x64.Build.0 = Release|x64
 | 
			
		||||
		{2A0B3CBC-C79F-4B19-93AE-BCEEE44BDAD2}.Release|x86.ActiveCfg = Release|x86
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue