mirror of
https://github.com/aaru-dps/RedBookPlayer.git
synced 2025-12-16 19:24:41 +00:00
Port only distinct new feature work
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.CommonTypes.Structs;
|
||||
using Aaru.Decoders.CD;
|
||||
using Aaru.Helpers;
|
||||
using CSCore.Codecs.WAV;
|
||||
using ReactiveUI;
|
||||
using static Aaru.Decoders.CD.FullTOC;
|
||||
|
||||
@@ -69,7 +71,8 @@ namespace RedBookPlayer.Models.Discs
|
||||
SetTrackFlags(track);
|
||||
|
||||
// If the track is playable, just return
|
||||
if(TrackType == TrackType.Audio || DataPlayback != DataPlayback.Skip)
|
||||
if((TrackType == TrackType.Audio || DataPlayback != DataPlayback.Skip)
|
||||
&& (SessionHandling == SessionHandling.AllSessions || track.TrackSession == 1))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -102,6 +105,7 @@ namespace RedBookPlayer.Models.Discs
|
||||
|
||||
TotalIndexes = cachedTrack.Indexes.Keys.Max();
|
||||
CurrentTrackIndex = cachedTrack.Indexes.Keys.Min();
|
||||
CurrentTrackSession = cachedTrack.TrackSession;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +139,13 @@ namespace RedBookPlayer.Models.Discs
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ushort CurrentTrackSession
|
||||
{
|
||||
get => _currentTrackSession;
|
||||
protected set => this.RaiseAndSetIfChanged(ref _currentTrackSession, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ulong CurrentSector
|
||||
{
|
||||
@@ -229,6 +240,11 @@ namespace RedBookPlayer.Models.Discs
|
||||
/// </summary>
|
||||
public bool LoadHiddenTracks { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates how tracks on different session should be handled
|
||||
/// </summary>
|
||||
public SessionHandling SessionHandling { get; set; } = SessionHandling.AllSessions;
|
||||
|
||||
private bool _quadChannel;
|
||||
private bool _isDataTrack;
|
||||
private bool _copyAllowed;
|
||||
@@ -248,6 +264,11 @@ namespace RedBookPlayer.Models.Discs
|
||||
/// </summary>
|
||||
private ushort _currentTrackIndex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Current track session
|
||||
/// </summary>
|
||||
private ushort _currentTrackSession = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Current sector number
|
||||
/// </summary>
|
||||
@@ -274,6 +295,7 @@ namespace RedBookPlayer.Models.Discs
|
||||
DataPlayback = options.DataPlayback;
|
||||
_generateMissingToc = options.GenerateMissingToc;
|
||||
LoadHiddenTracks = options.LoadHiddenTracks;
|
||||
SessionHandling = options.SessionHandling;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -417,6 +439,44 @@ namespace RedBookPlayer.Models.Discs
|
||||
|
||||
#region Helpers
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void ExtractTrackToWav(uint trackNumber, string outputDirectory)
|
||||
{
|
||||
if(_image == null)
|
||||
return;
|
||||
|
||||
// Get the track with that value, if possible
|
||||
Track track = _image.Tracks.FirstOrDefault(t => t.TrackSequence == trackNumber);
|
||||
|
||||
// If the track isn't valid, we can't do anything
|
||||
if(track == null || track.TrackType != TrackType.Audio)
|
||||
return;
|
||||
|
||||
// Read in the track data to a buffer
|
||||
uint length = (uint)(track.TrackEndSector - track.TrackStartSector);
|
||||
byte[] buffer = _image.ReadSectors(track.TrackStartSector, length);
|
||||
|
||||
// Build the WAV output
|
||||
string filename = Path.Combine(outputDirectory, $"Track {trackNumber.ToString().PadLeft(2, '0')}.wav");
|
||||
using(WaveWriter waveWriter = new WaveWriter(filename, new CSCore.WaveFormat()))
|
||||
{
|
||||
// Write out to the file
|
||||
waveWriter.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void ExtractAllTracksToWav(string outputDirectory)
|
||||
{
|
||||
if(_image == null)
|
||||
return;
|
||||
|
||||
foreach(Track track in _image.Tracks)
|
||||
{
|
||||
ExtractTrackToWav(track.TrackSequence, outputDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void LoadTrack(int trackNumber)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user