mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
simplify CDImageLayout usage
This commit is contained in:
@@ -11,19 +11,10 @@ namespace CUETools.CDImage
|
|||||||
{
|
{
|
||||||
_start = start;
|
_start = start;
|
||||||
_index = index;
|
_index = index;
|
||||||
_length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CDTrackIndex(uint index, uint start, uint length)
|
|
||||||
{
|
|
||||||
_length = length;
|
|
||||||
_start = start;
|
|
||||||
_index = index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CDTrackIndex(CDTrackIndex src)
|
public CDTrackIndex(CDTrackIndex src)
|
||||||
{
|
{
|
||||||
_length = src._length;
|
|
||||||
_start = src._start;
|
_start = src._start;
|
||||||
_index = src._index;
|
_index = src._index;
|
||||||
}
|
}
|
||||||
@@ -40,18 +31,6 @@ namespace CUETools.CDImage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint Length
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _length;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_length = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public uint Index
|
public uint Index
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -68,7 +47,7 @@ namespace CUETools.CDImage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint _start, _length, _index;
|
uint _start, _index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CDTrack : ICloneable
|
public class CDTrack : ICloneable
|
||||||
@@ -80,8 +59,8 @@ namespace CUETools.CDImage
|
|||||||
_length = length;
|
_length = length;
|
||||||
_isAudio = isAudio;
|
_isAudio = isAudio;
|
||||||
_indexes = new List<CDTrackIndex>();
|
_indexes = new List<CDTrackIndex>();
|
||||||
_indexes.Add(new CDTrackIndex(0, start, 0));
|
_indexes.Add(new CDTrackIndex(0, start));
|
||||||
_indexes.Add(new CDTrackIndex(1, start, length));
|
_indexes.Add(new CDTrackIndex(1, start));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CDTrack(CDTrack src)
|
public CDTrack(CDTrack src)
|
||||||
@@ -180,7 +159,7 @@ namespace CUETools.CDImage
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _indexes[0].Length;
|
return _start - _indexes[0].Start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,6 +297,15 @@ namespace CUETools.CDImage
|
|||||||
_audioTracks++;
|
_audioTracks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public uint IndexLength(int iTrack, int iIndex)
|
||||||
|
{
|
||||||
|
if (iIndex < _tracks[iTrack - 1].LastIndex)
|
||||||
|
return _tracks[iTrack - 1][iIndex + 1].Start - _tracks[iTrack - 1][iIndex].Start;
|
||||||
|
if (iTrack < AudioTracks)
|
||||||
|
return _tracks[iTrack][0].Start - _tracks[iTrack - 1][iIndex].Start;
|
||||||
|
return _tracks[iTrack - 1].End + 1 - _tracks[iTrack - 1][iIndex].Start;
|
||||||
|
}
|
||||||
|
|
||||||
public static int TimeFromString(string s)
|
public static int TimeFromString(string s)
|
||||||
{
|
{
|
||||||
string[] n = s.Split(':');
|
string[] n = s.Split(':');
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace CUETools.Ripper.SCSI
|
|||||||
if (st != Device.CommandStatus.Success)
|
if (st != Device.CommandStatus.Success)
|
||||||
throw new Exception("GetSpeed failed: SCSI error");
|
throw new Exception("GetSpeed failed: SCSI error");
|
||||||
|
|
||||||
st = m_device.SetCdSpeed(Device.RotationalControl.CLVandNonPureCav, Device.OptimumSpeed, Device.OptimumSpeed);
|
st = m_device.SetCdSpeed(Device.RotationalControl.CLVandNonPureCav, 32767/*Device.OptimumSpeed*/, Device.OptimumSpeed);
|
||||||
if (st != Device.CommandStatus.Success)
|
if (st != Device.CommandStatus.Success)
|
||||||
throw new Exception("SetCdSpeed failed: SCSI error");
|
throw new Exception("SetCdSpeed failed: SCSI error");
|
||||||
|
|
||||||
@@ -121,6 +121,8 @@ namespace CUETools.Ripper.SCSI
|
|||||||
toc[iTrack + 1].StartSector - toc[iTrack].StartSector -
|
toc[iTrack + 1].StartSector - toc[iTrack].StartSector -
|
||||||
((toc[iTrack + 1].Control == 0 || iTrack + 1 == toc.Count - 1) ? 0U : 152U * 75U),
|
((toc[iTrack + 1].Control == 0 || iTrack + 1 == toc.Count - 1) ? 0U : 152U * 75U),
|
||||||
toc[iTrack].Control == 0));
|
toc[iTrack].Control == 0));
|
||||||
|
if (_toc[1].IsAudio)
|
||||||
|
_toc[1][0].Start = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,9 +164,7 @@ namespace CUETools.Ripper.SCSI
|
|||||||
_currentTrack = iTrack;
|
_currentTrack = iTrack;
|
||||||
_currentTrackActualStart = sector + iSector;
|
_currentTrackActualStart = sector + iSector;
|
||||||
_currentIndex = iIndex;
|
_currentIndex = iIndex;
|
||||||
if (_currentIndex == 1)
|
if (_currentIndex != 1 && _currentIndex != 0)
|
||||||
_toc[iTrack].AddIndex(new CDTrackIndex(1, _toc[iTrack].Start));
|
|
||||||
else if (_currentIndex != 0)
|
|
||||||
throw new Exception("invalid index");
|
throw new Exception("invalid index");
|
||||||
}
|
}
|
||||||
else if (iIndex != _currentIndex)
|
else if (iIndex != _currentIndex)
|
||||||
@@ -174,10 +174,10 @@ namespace CUETools.Ripper.SCSI
|
|||||||
_currentIndex = iIndex;
|
_currentIndex = iIndex;
|
||||||
if (_currentIndex == 1)
|
if (_currentIndex == 1)
|
||||||
{
|
{
|
||||||
int pregap = sector + iSector - _currentTrackActualStart;
|
uint pregap = (uint) (sector + iSector - _currentTrackActualStart);
|
||||||
_toc[iTrack].AddIndex(new CDTrackIndex(0, (uint)(_toc[iTrack].Start - pregap), (uint)pregap));
|
_toc[iTrack][0].Start = _toc[iTrack].Start - pregap;
|
||||||
_currentTrackActualStart = sector + iSector;
|
_currentTrackActualStart = sector + iSector;
|
||||||
}
|
} else
|
||||||
_toc[iTrack].AddIndex(new CDTrackIndex((uint)iIndex, (uint)(_toc[iTrack].Start + sector + iSector - _currentTrackActualStart)));
|
_toc[iTrack].AddIndex(new CDTrackIndex((uint)iIndex, (uint)(_toc[iTrack].Start + sector + iSector - _currentTrackActualStart)));
|
||||||
_currentIndex = iIndex;
|
_currentIndex = iIndex;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -796,18 +796,21 @@ namespace CUETools.Processor
|
|||||||
// Calculate the length of each index
|
// Calculate the length of each index
|
||||||
for (i = 0; i < indexes.Count - 1; i++)
|
for (i = 0; i < indexes.Count - 1; i++)
|
||||||
{
|
{
|
||||||
int length = indexes[i + 1].Time - indexes[i].Time;
|
if (indexes[i + 1].Time - indexes[i].Time < 0)
|
||||||
if (length < 0)
|
|
||||||
throw new Exception("Indexes must be in chronological order.");
|
throw new Exception("Indexes must be in chronological order.");
|
||||||
_toc[indexes[i].Track].AddIndex(new CDTrackIndex((uint)indexes[i].Index, (uint)indexes[i].Time, (uint)length));
|
if ((indexes[i+1].Track != indexes[i].Track || indexes[i+1].Index != indexes[i].Index + 1) &&
|
||||||
|
(indexes[i + 1].Track != indexes[i].Track + 1 || indexes[i].Index < 1 || indexes[i + 1].Index > 1))
|
||||||
|
throw new Exception("Indexes must be in chronological order.");
|
||||||
|
if (indexes[i].Index == 1 && (i == 0 || indexes[i - 1].Index != 0))
|
||||||
|
_toc[indexes[i].Track].AddIndex(new CDTrackIndex(0U, (uint)indexes[i].Time));
|
||||||
|
_toc[indexes[i].Track].AddIndex(new CDTrackIndex((uint)indexes[i].Index, (uint)indexes[i].Time));
|
||||||
|
//_toc[indexes[i].Track].AddIndex(new CDTrackIndex((uint)indexes[i].Index, (uint)indexes[i].Time, (uint)length));
|
||||||
}
|
}
|
||||||
// Calculate the length of each track
|
// Calculate the length of each track
|
||||||
for (i = 1; i <= TrackCount; i++)
|
for (int iTrack = 1; iTrack <= TrackCount; iTrack++)
|
||||||
{
|
{
|
||||||
if (_toc[i].LastIndex < 1)
|
_toc[iTrack].Start = _toc[iTrack][1].Start;
|
||||||
throw new Exception("Track must have an INDEX 01.");
|
_toc[iTrack].Length = (iTrack == TrackCount ? (uint)indexes[indexes.Count - 1].Time - _toc[iTrack].Start : _toc[iTrack + 1][1].Start - _toc[iTrack].Start);
|
||||||
_toc[i].Start = _toc[i][1].Start;
|
|
||||||
_toc[i].Length = (i == TrackCount ? (uint)indexes[indexes.Count - 1].Time - _toc[i].Start : _toc[i + 1][1].Start - _toc[i].Start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the audio filenames, generating generic names if necessary
|
// Store the audio filenames, generating generic names if necessary
|
||||||
@@ -1205,33 +1208,29 @@ namespace CUETools.Processor
|
|||||||
sw1.Close();
|
sw1.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(TextWriter sw, CUEStyle style) {
|
public void Write(TextWriter sw, CUEStyle style)
|
||||||
|
{
|
||||||
int i, iTrack, iIndex;
|
int i, iTrack, iIndex;
|
||||||
TrackInfo track;
|
bool htoaToFile = (style == CUEStyle.GapsAppended && _config.preserveHTOA && _toc.Pregap != 0);
|
||||||
bool htoaToFile = ((style == CUEStyle.GapsAppended) && _config.preserveHTOA &&
|
|
||||||
(_toc.Pregap != 0));
|
|
||||||
|
|
||||||
uint timeRelativeToFileStart = 0;
|
uint timeRelativeToFileStart = 0;
|
||||||
|
|
||||||
using (sw) {
|
using (sw)
|
||||||
|
{
|
||||||
if (_accurateRipId != null && _config.writeArTagsOnConvert)
|
if (_accurateRipId != null && _config.writeArTagsOnConvert)
|
||||||
WriteLine(sw, 0, "REM ACCURATERIPID " +
|
WriteLine(sw, 0, "REM ACCURATERIPID " + _accurateRipId);
|
||||||
_accurateRipId);
|
|
||||||
|
|
||||||
for (i = 0; i < _attributes.Count; i++) {
|
for (i = 0; i < _attributes.Count; i++)
|
||||||
WriteLine(sw, 0, _attributes[i]);
|
WriteLine(sw, 0, _attributes[i]);
|
||||||
}
|
|
||||||
|
|
||||||
if (style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) {
|
if (style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE)
|
||||||
WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _singleFilename));
|
WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _singleFilename));
|
||||||
}
|
|
||||||
if (htoaToFile) {
|
if (htoaToFile)
|
||||||
WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _htoaFilename));
|
WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _htoaFilename));
|
||||||
}
|
|
||||||
|
|
||||||
for (iTrack = 0; iTrack < TrackCount; iTrack++) {
|
|
||||||
track = _tracks[iTrack];
|
|
||||||
|
|
||||||
|
for (iTrack = 0; iTrack < TrackCount; iTrack++)
|
||||||
|
{
|
||||||
if ((style == CUEStyle.GapsPrepended) ||
|
if ((style == CUEStyle.GapsPrepended) ||
|
||||||
(style == CUEStyle.GapsLeftOut) ||
|
(style == CUEStyle.GapsLeftOut) ||
|
||||||
((style == CUEStyle.GapsAppended) &&
|
((style == CUEStyle.GapsAppended) &&
|
||||||
@@ -1242,30 +1241,30 @@ namespace CUETools.Processor
|
|||||||
}
|
}
|
||||||
|
|
||||||
WriteLine(sw, 1, String.Format("TRACK {0:00} AUDIO", iTrack + 1));
|
WriteLine(sw, 1, String.Format("TRACK {0:00} AUDIO", iTrack + 1));
|
||||||
for (i = 0; i < track.Attributes.Count; i++) {
|
for (i = 0; i < _tracks[iTrack].Attributes.Count; i++)
|
||||||
WriteLine(sw, 2, track.Attributes[i]);
|
WriteLine(sw, 2, _tracks[iTrack].Attributes[i]);
|
||||||
}
|
|
||||||
|
|
||||||
for (iIndex = 0; iIndex <= _toc[iTrack+1].LastIndex; iIndex++) {
|
if (_toc[iTrack + 1].Pregap != 0)
|
||||||
if (_toc[iTrack+1][iIndex].Length != 0) {
|
{
|
||||||
if ((iIndex == 0) &&
|
if (((style == CUEStyle.GapsLeftOut) ||
|
||||||
((style == CUEStyle.GapsLeftOut) ||
|
|
||||||
((style == CUEStyle.GapsAppended) && (iTrack == 0) && !htoaToFile) ||
|
((style == CUEStyle.GapsAppended) && (iTrack == 0) && !htoaToFile) ||
|
||||||
((style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) && (iTrack == 0) && _usePregapForFirstTrackInSingleFile)))
|
((style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) && (iTrack == 0) && _usePregapForFirstTrackInSingleFile)))
|
||||||
|
WriteLine(sw, 2, "PREGAP " + CDImageLayout.TimeToString(_toc[iTrack + 1].Pregap));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WriteLine(sw, 2, String.Format("INDEX 00 {0}", CDImageLayout.TimeToString(timeRelativeToFileStart)));
|
||||||
|
timeRelativeToFileStart += _toc[iTrack + 1].Pregap;
|
||||||
|
if (style == CUEStyle.GapsAppended)
|
||||||
{
|
{
|
||||||
WriteLine(sw, 2, "PREGAP " + CDImageLayout.TimeToString(_toc[iTrack + 1][iIndex].Length));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
WriteLine(sw, 2, String.Format( "INDEX {0:00} {1}", iIndex,
|
|
||||||
CDImageLayout.TimeToString(timeRelativeToFileStart)));
|
|
||||||
timeRelativeToFileStart += _toc[iTrack + 1][iIndex].Length;
|
|
||||||
|
|
||||||
if ((style == CUEStyle.GapsAppended) && (iIndex == 0)) {
|
|
||||||
WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _trackFilenames[iTrack]));
|
WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _trackFilenames[iTrack]));
|
||||||
timeRelativeToFileStart = 0;
|
timeRelativeToFileStart = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (iIndex = 1; iIndex <= _toc[iTrack+1].LastIndex; iIndex++)
|
||||||
|
{
|
||||||
|
WriteLine(sw, 2, String.Format( "INDEX {0:00} {1}", iIndex, CDImageLayout.TimeToString(timeRelativeToFileStart)));
|
||||||
|
timeRelativeToFileStart += _toc.IndexLength(iTrack + 1, iIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1913,7 +1912,7 @@ namespace CUETools.Processor
|
|||||||
|
|
||||||
for (iIndex = 0; iIndex <= _toc[iTrack+1].LastIndex; iIndex++) {
|
for (iIndex = 0; iIndex <= _toc[iTrack+1].LastIndex; iIndex++) {
|
||||||
uint trackPercent= 0, lastTrackPercent= 101;
|
uint trackPercent= 0, lastTrackPercent= 101;
|
||||||
uint samplesRemIndex = _toc[iTrack + 1][iIndex].Length * 588;
|
uint samplesRemIndex = _toc.IndexLength(iTrack + 1, iIndex) * 588;
|
||||||
|
|
||||||
if (iIndex == 1)
|
if (iIndex == 1)
|
||||||
{
|
{
|
||||||
@@ -1964,7 +1963,7 @@ namespace CUETools.Processor
|
|||||||
if (trackPercent != lastTrackPercent)
|
if (trackPercent != lastTrackPercent)
|
||||||
ShowProgress(String.Format("{2} track {0:00} ({1:00}%)...", iIndex > 0 ? iTrack + 1 : iTrack, trackPercent,
|
ShowProgress(String.Format("{2} track {0:00} ({1:00}%)...", iIndex > 0 ? iTrack + 1 : iTrack, trackPercent,
|
||||||
noOutput ? "Verifying" : "Writing"), trackPercent, diskPercent,
|
noOutput ? "Verifying" : "Writing"), trackPercent, diskPercent,
|
||||||
_isCD ? audioSource.Path + ": " + _tracks[iTrack].Title : audioSource.Path, discardOutput ? null : audioDest.Path);
|
_isCD ? string.Format("{0}: {1:00} - {2}", audioSource.Path, iTrack + 1, _tracks[iTrack].Title) : audioSource.Path, discardOutput ? null : audioDest.Path);
|
||||||
lastTrackPercent = trackPercent;
|
lastTrackPercent = trackPercent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2129,7 +2128,8 @@ namespace CUETools.Processor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] CalculateAudioFileLengths(CUEStyle style) {
|
private int[] CalculateAudioFileLengths(CUEStyle style)
|
||||||
|
{
|
||||||
int iTrack, iIndex, iFile;
|
int iTrack, iIndex, iFile;
|
||||||
TrackInfo track;
|
TrackInfo track;
|
||||||
int[] fileLengths;
|
int[] fileLengths;
|
||||||
@@ -2161,7 +2161,7 @@ namespace CUETools.Processor
|
|||||||
discardOutput = (style == CUEStyle.GapsLeftOut && iIndex == 0);
|
discardOutput = (style == CUEStyle.GapsLeftOut && iIndex == 0);
|
||||||
|
|
||||||
if (!discardOutput)
|
if (!discardOutput)
|
||||||
fileLengths[iFile] += (int) _toc[iTrack+1][iIndex].Length * 588;
|
fileLengths[iFile] += (int)_toc.IndexLength(iTrack + 1, iIndex) * 588;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user