2008-11-28 22:13:06 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2008-11-30 03:04:05 +00:00
|
|
|
using System.Security.Cryptography;
|
2008-11-28 22:13:06 +00:00
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace CUETools.CDImage
|
|
|
|
|
{
|
|
|
|
|
public class CDTrackIndex
|
|
|
|
|
{
|
|
|
|
|
public CDTrackIndex(uint index, uint start)
|
|
|
|
|
{
|
|
|
|
|
_start = start;
|
|
|
|
|
_index = index;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 23:49:04 +00:00
|
|
|
public CDTrackIndex(CDTrackIndex src)
|
|
|
|
|
{
|
|
|
|
|
_start = src._start;
|
|
|
|
|
_index = src._index;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 22:13:06 +00:00
|
|
|
public uint Start
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _start;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_start = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint Index
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string MSF
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return CDImageLayout.TimeToString(_start);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-01 16:28:23 +00:00
|
|
|
uint _start, _index;
|
2008-11-28 22:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-28 23:49:04 +00:00
|
|
|
public class CDTrack : ICloneable
|
2008-11-28 22:13:06 +00:00
|
|
|
{
|
2008-12-06 05:44:14 +00:00
|
|
|
public CDTrack(uint number, uint start, uint length, bool isAudio, bool preEmpasis)
|
2008-11-28 22:13:06 +00:00
|
|
|
{
|
|
|
|
|
_number = number;
|
|
|
|
|
_start = start;
|
|
|
|
|
_length = length;
|
|
|
|
|
_isAudio = isAudio;
|
2008-12-06 05:44:14 +00:00
|
|
|
_preEmphasis = preEmpasis;
|
2008-11-28 22:13:06 +00:00
|
|
|
_indexes = new List<CDTrackIndex>();
|
2008-12-01 16:28:23 +00:00
|
|
|
_indexes.Add(new CDTrackIndex(0, start));
|
|
|
|
|
_indexes.Add(new CDTrackIndex(1, start));
|
2008-11-28 22:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-28 23:49:04 +00:00
|
|
|
public CDTrack(CDTrack src)
|
|
|
|
|
{
|
|
|
|
|
_number = src._number;
|
|
|
|
|
_start = src._start;
|
|
|
|
|
_length = src._length;
|
|
|
|
|
_isAudio = src._isAudio;
|
2008-12-06 05:44:14 +00:00
|
|
|
_preEmphasis = src._preEmphasis;
|
2008-11-28 23:49:04 +00:00
|
|
|
_indexes = new List<CDTrackIndex>();
|
|
|
|
|
for (int i = 0; i < src._indexes.Count; i++)
|
|
|
|
|
_indexes.Add(new CDTrackIndex(src._indexes[i]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Clone()
|
|
|
|
|
{
|
|
|
|
|
return new CDTrack(this);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 22:13:06 +00:00
|
|
|
public uint Start
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _start;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_start = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string StartMSF
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return CDImageLayout.TimeToString(_start);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint Length
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _length;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_length = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string LengthMSF
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return CDImageLayout.TimeToString(_length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ISRC
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _isrc;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_isrc = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint End
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _start + _length - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string EndMSF
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return CDImageLayout.TimeToString(End);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint Number
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _number;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint Pregap
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2008-12-01 16:28:23 +00:00
|
|
|
return _start - _indexes[0].Start;
|
2008-11-28 22:13:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CDTrackIndex this[int key]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _indexes[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint LastIndex
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return (uint) _indexes.Count - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsAudio
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _isAudio;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-06 05:44:14 +00:00
|
|
|
public bool PreEmphasis
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _preEmphasis;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_preEmphasis = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-10 06:48:38 +00:00
|
|
|
public bool DCP
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _dcp;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_dcp = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 22:13:06 +00:00
|
|
|
public void AddIndex(CDTrackIndex index)
|
|
|
|
|
{
|
2008-11-30 23:47:13 +00:00
|
|
|
if (index.Index < 2)
|
|
|
|
|
_indexes[(int)index.Index] = index;
|
2008-11-28 22:13:06 +00:00
|
|
|
else
|
|
|
|
|
_indexes.Add(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IList<CDTrackIndex> _indexes;
|
|
|
|
|
string _isrc;
|
|
|
|
|
bool _isAudio;
|
2008-12-10 06:48:38 +00:00
|
|
|
bool _preEmphasis, _dcp;
|
2008-11-28 22:13:06 +00:00
|
|
|
uint _start;
|
|
|
|
|
uint _length;
|
|
|
|
|
uint _number;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 23:49:04 +00:00
|
|
|
public class CDImageLayout : ICloneable
|
2008-11-28 22:13:06 +00:00
|
|
|
{
|
2008-11-30 00:03:49 +00:00
|
|
|
public CDImageLayout()
|
2008-11-28 22:13:06 +00:00
|
|
|
{
|
|
|
|
|
_tracks = new List<CDTrack>();
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 23:49:04 +00:00
|
|
|
public CDImageLayout(CDImageLayout src)
|
|
|
|
|
{
|
|
|
|
|
_catalog = src._catalog;
|
|
|
|
|
_audioTracks = src._audioTracks;
|
2009-01-28 04:53:13 +00:00
|
|
|
_firstAudio = src._firstAudio;
|
2008-11-28 23:49:04 +00:00
|
|
|
_tracks = new List<CDTrack>();
|
|
|
|
|
for (int i = 0; i < src.TrackCount; i++)
|
|
|
|
|
_tracks.Add(new CDTrack(src._tracks[i]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Clone()
|
|
|
|
|
{
|
|
|
|
|
return new CDImageLayout(this);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 22:13:06 +00:00
|
|
|
public uint Length
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2008-11-30 00:03:49 +00:00
|
|
|
return TrackCount > 0 ? _tracks[TrackCount - 1].End + 1U : 0U;
|
2008-11-28 22:13:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CDTrack this[int key]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _tracks[key - 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int TrackCount
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _tracks.Count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint Pregap
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _tracks[0].Pregap;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint AudioTracks
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2009-01-28 04:53:13 +00:00
|
|
|
return (uint) _audioTracks;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int FirstAudio
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _firstAudio + 1;
|
2008-11-28 22:13:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-01 20:24:16 +00:00
|
|
|
public uint AudioLength
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2009-01-28 04:53:13 +00:00
|
|
|
return AudioTracks > 0 ? _tracks[_firstAudio + _audioTracks - 1].End + 1U - _tracks[_firstAudio].Start + _tracks[_firstAudio].Pregap : 0U;
|
2008-12-01 20:24:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-30 03:04:05 +00:00
|
|
|
public string Catalog
|
2008-11-28 22:13:06 +00:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _catalog;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_catalog = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-30 03:04:05 +00:00
|
|
|
public string MusicBrainzId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
StringBuilder mbSB = new StringBuilder();
|
|
|
|
|
mbSB.AppendFormat("{0:X2}{1:X2}{2:X8}", 1, AudioTracks, _tracks[(int)AudioTracks-1].End + 1 + 150);
|
|
|
|
|
for (int iTrack = 0; iTrack < AudioTracks; iTrack++)
|
|
|
|
|
mbSB.AppendFormat("{0:X8}", _tracks[iTrack].Start + 150);
|
|
|
|
|
mbSB.Append(new string('0', (99 - (int)AudioTracks) * 8));
|
|
|
|
|
byte[] hashBytes = (new SHA1CryptoServiceProvider()).ComputeHash(Encoding.ASCII.GetBytes(mbSB.ToString()));
|
|
|
|
|
return Convert.ToBase64String(hashBytes).Replace('+', '.').Replace('/', '_').Replace('=', '-');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 22:13:06 +00:00
|
|
|
public void AddTrack(CDTrack track)
|
|
|
|
|
{
|
|
|
|
|
_tracks.Add(track);
|
|
|
|
|
if (track.IsAudio)
|
2009-01-28 04:53:13 +00:00
|
|
|
{
|
2008-11-28 22:13:06 +00:00
|
|
|
_audioTracks++;
|
2009-01-28 04:53:13 +00:00
|
|
|
if (!_tracks[_firstAudio].IsAudio)
|
|
|
|
|
_firstAudio = _tracks.Count - 1;
|
|
|
|
|
}
|
2008-11-28 22:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-01 16:28:23 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 22:13:06 +00:00
|
|
|
public static int TimeFromString(string s)
|
|
|
|
|
{
|
|
|
|
|
string[] n = s.Split(':');
|
|
|
|
|
if (n.Length != 3)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Invalid timestamp.");
|
|
|
|
|
}
|
|
|
|
|
int min, sec, frame;
|
|
|
|
|
|
|
|
|
|
min = Int32.Parse(n[0]);
|
|
|
|
|
sec = Int32.Parse(n[1]);
|
|
|
|
|
frame = Int32.Parse(n[2]);
|
|
|
|
|
|
|
|
|
|
return frame + (sec * 75) + (min * 60 * 75);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string TimeToString(uint t)
|
|
|
|
|
{
|
|
|
|
|
uint min, sec, frame;
|
|
|
|
|
|
|
|
|
|
frame = t % 75;
|
|
|
|
|
t /= 75;
|
|
|
|
|
sec = t % 60;
|
|
|
|
|
t /= 60;
|
|
|
|
|
min = t;
|
|
|
|
|
|
|
|
|
|
return String.Format("{0:00}:{1:00}:{2:00}", min, sec, frame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string _catalog;
|
|
|
|
|
IList<CDTrack> _tracks;
|
2009-01-28 04:53:13 +00:00
|
|
|
int _audioTracks;
|
|
|
|
|
int _firstAudio;
|
2008-11-28 22:13:06 +00:00
|
|
|
}
|
|
|
|
|
}
|