add last backwards-compatible version

This commit is contained in:
2021-12-14 00:33:46 -07:00
parent 68b10d413b
commit b0dd3f07f3
335 changed files with 4746 additions and 19627 deletions

View File

@@ -6,7 +6,6 @@
namespace {
PFC_DECLARE_EXCEPTION(exception_cue,pfc::exception,"Invalid cuesheet");
PFC_DECLARE_EXCEPTION(exception_cue_tracktype, exception_cue, "Not an audio track")
}
static bool is_numeric(char c) {return c>='0' && c<='9';}
@@ -32,9 +31,7 @@ static void validate_file_type(const char * p_type,t_size p_type_length) {
stricmp_utf8_ex(p_type,p_type_length,"APE",pfc_infinite) != 0 &&
stricmp_utf8_ex(p_type,p_type_length,"FLAC",pfc_infinite) != 0 &&
stricmp_utf8_ex(p_type,p_type_length,"WV",pfc_infinite) != 0 &&
stricmp_utf8_ex(p_type,p_type_length,"WAVPACK",pfc_infinite) != 0 &&
// BINARY
stricmp_utf8_ex(p_type,p_type_length,"BINARY",pfc_infinite) != 0
stricmp_utf8_ex(p_type,p_type_length,"WAVPACK",pfc_infinite) != 0
)
pfc::throw_exception_with_message< exception_cue >(PFC_string_formatter() << "expected WAVE, MP3 or AIFF, got : \"" << pfc::string_part(p_type,p_type_length) << "\"");
}
@@ -137,17 +134,15 @@ namespace {
{
validate_file_type(p_type,p_type_length);
m_file.set_string(p_file,p_file_length);
m_fileType.set_string(p_type, p_type_length);
}
void on_track(unsigned p_index,const char * p_type,t_size p_type_length)
{
finalize_track(); // finalize previous track
m_trackIsAudio = stricmp_utf8_ex(p_type,p_type_length,"audio",pfc_infinite) == 0;
if (stricmp_utf8_ex(p_type,p_type_length,"audio",pfc_infinite)) pfc::throw_exception_with_message<exception_cue>("only tracks of type AUDIO supported");
//if (p_index != m_track + 1) throw exception_cue("cuesheet tracks out of order");
if (m_track != 0) finalize_track();
if (m_file.is_empty()) pfc::throw_exception_with_message<exception_cue>("declaring a track with no file set");
m_trackfile = m_file;
m_trackFileType = m_fileType;
m_track = p_index;
}
@@ -176,40 +171,38 @@ namespace {
void finalize()
{
finalize_track(); // finalize last track
if (m_track != 0)
{
finalize_track();
m_track = 0;
}
}
private:
void finalize_track()
{
if ( m_track != 0 && m_trackIsAudio ) {
if (!m_index1_set) pfc::throw_exception_with_message< exception_cue > ("INDEX 01 not set");
if (!m_index0_set) m_index_list.m_positions[0] = m_index_list.m_positions[1] - m_pregap;
if (!m_index_list.is_valid()) pfc::throw_exception_with_message< exception_cue > ("invalid index list");
cue_parser::t_cue_entry_list::iterator iter;
iter = m_out.insert_last();
if (m_trackfile.is_empty()) pfc::throw_exception_with_message< exception_cue > ("track has no file assigned");
iter->m_file = m_trackfile;
iter->m_fileType = m_trackFileType;
iter->m_track_number = m_track;
iter->m_indexes = m_index_list;
}
if (!m_index1_set) pfc::throw_exception_with_message< exception_cue > ("INDEX 01 not set");
if (!m_index0_set) m_index_list.m_positions[0] = m_index_list.m_positions[1] - m_pregap;
if (!m_index_list.is_valid()) pfc::throw_exception_with_message< exception_cue > ("invalid index list");
cue_parser::t_cue_entry_list::iterator iter;
iter = m_out.insert_last();
if (m_trackfile.is_empty()) pfc::throw_exception_with_message< exception_cue > ("track has no file assigned");
iter->m_file = m_trackfile;
iter->m_track_number = m_track;
iter->m_indexes = m_index_list;
m_index_list.reset();
m_index0_set = false;
m_index1_set = false;
m_pregap = 0;
m_track = 0; m_trackIsAudio = false;
}
bool m_index0_set,m_index1_set;
t_cuesheet_index_list m_index_list;
double m_pregap;
unsigned m_track;
bool m_trackIsAudio = false;
pfc::string8 m_file,m_fileType,m_trackfile,m_trackFileType;
pfc::string8 m_file,m_trackfile;
cue_parser::t_cue_entry_list & m_out;
};
@@ -225,7 +218,7 @@ namespace {
if (p_index == 0) pfc::throw_exception_with_message< exception_cue > ("invalid TRACK index");
if (p_index == m_wanted_track)
{
if (stricmp_utf8_ex(p_type,p_type_length,"audio",pfc_infinite)) throw exception_cue_tracktype();
if (stricmp_utf8_ex(p_type,p_type_length,"audio",pfc_infinite)) pfc::throw_exception_with_message< exception_cue > ("only tracks of type AUDIO supported");
}
m_track = p_index;
m_totaltracks++;
@@ -387,17 +380,6 @@ namespace {
};
static pfc::string_part_ref cue_line_argument( const char * base, size_t length ) {
const char * end = base + length;
while(base < end && is_spacing(base[0]) ) ++base;
while(base < end && is_spacing(end[-1]) ) --end;
if ( base + 1 < end ) {
if ( base[0] == '\"' && end[-1] == '\"' ) {
++base; --end;
}
}
return pfc::string_part(base, end-base);
}
static void g_parse_cue_line(const char * p_line,t_size p_line_length,cue_parser_callback & p_callback)
{
@@ -518,18 +500,66 @@ static void g_parse_cue_line(const char * p_line,t_size p_line_length,cue_parser
}
else if (!stricmp_utf8_ex(p_line,ptr,"title",pfc_infinite))
{
auto arg = cue_line_argument(p_line+ptr, p_line_length-ptr);
if ( arg.m_len > 0 ) p_callback.on_title( arg.m_ptr, arg.m_len );
while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++;
if (ptr == p_line_length) pfc::throw_exception_with_message< exception_cue > ("invalid TITLE syntax");
if (p_line[ptr] == '\"')
{
ptr++;
t_size base = ptr;
while(ptr < p_line_length && p_line[ptr] != '\"') ptr++;
if (ptr == p_line_length) pfc::throw_exception_with_message< exception_cue > ("invalid TITLE syntax");
t_size length = ptr-base;
ptr++;
while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++;
if (ptr != p_line_length) pfc::throw_exception_with_message< exception_cue > ("invalid TITLE syntax");
p_callback.on_title(p_line+base,length);
}
else
{
p_callback.on_title(p_line+ptr,p_line_length-ptr);
}
}
else if (!stricmp_utf8_ex(p_line,ptr,"performer",pfc_infinite))
{
auto arg = cue_line_argument(p_line + ptr, p_line_length - ptr);
if (arg.m_len > 0) p_callback.on_performer(arg.m_ptr, arg.m_len);
while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++;
if (ptr == p_line_length) pfc::throw_exception_with_message< exception_cue > ("invalid PERFORMER syntax");
if (p_line[ptr] == '\"')
{
ptr++;
t_size base = ptr;
while(ptr < p_line_length && p_line[ptr] != '\"') ptr++;
if (ptr == p_line_length) pfc::throw_exception_with_message< exception_cue > ("invalid PERFORMER syntax");
t_size length = ptr-base;
ptr++;
while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++;
if (ptr != p_line_length) pfc::throw_exception_with_message< exception_cue > ("invalid PERFORMER syntax");
p_callback.on_performer(p_line+base,length);
}
else
{
p_callback.on_performer(p_line+ptr,p_line_length-ptr);
}
}
else if (!stricmp_utf8_ex(p_line,ptr,"songwriter",pfc_infinite))
{
auto arg = cue_line_argument(p_line + ptr, p_line_length - ptr);
if (arg.m_len > 0) p_callback.on_songwriter(arg.m_ptr, arg.m_len);
while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++;
if (ptr == p_line_length) pfc::throw_exception_with_message< exception_cue > ("invalid SONGWRITER syntax");
if (p_line[ptr] == '\"')
{
ptr++;
t_size base = ptr;
while(ptr < p_line_length && p_line[ptr] != '\"') ptr++;
if (ptr == p_line_length) pfc::throw_exception_with_message< exception_cue > ("invalid SONGWRITER syntax");
t_size length = ptr-base;
ptr++;
while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++;
if (ptr != p_line_length) pfc::throw_exception_with_message< exception_cue > ("invalid SONGWRITER syntax");
p_callback.on_songwriter(p_line+base,length);
}
else
{
p_callback.on_songwriter(p_line+ptr,p_line_length-ptr);
}
}
else if (!stricmp_utf8_ex(p_line,ptr,"isrc",pfc_infinite))
{
@@ -640,20 +670,15 @@ namespace {
void on_file(const char * p_file,t_size p_file_length,const char * p_type,t_size p_type_length) {
validate_file_type(p_type,p_type_length);
m_file.set_string(p_file,p_file_length);
m_fileType.set_string(p_type, p_type_length);
}
void on_track(unsigned p_index,const char * p_type,t_size p_type_length)
{
finalize_track();
m_trackType.set_string( p_type, p_type_length );
if (stricmp_utf8_ex(p_type,p_type_length,"audio",pfc_infinite)) pfc::throw_exception_with_message< exception_cue > ("only tracks of type AUDIO supported");
//if (p_index != m_track + 1) throw exception_cue("cuesheet tracks out of order",0);
if (m_track != 0) finalize_track();
if (m_file.is_empty()) pfc::throw_exception_with_message< exception_cue > ("declaring a track with no file set");
m_trackfile = m_file;
m_trackFileType = m_fileType;
m_track = p_index;
}
@@ -682,7 +707,11 @@ namespace {
void on_comment(const char * p_comment,t_size p_comment_length) {}
void finalize()
{
finalize_track();
if (m_track != 0)
{
finalize_track();
m_track = 0;
}
}
void on_flags(const char * p_flags,t_size p_flags_length) {
m_flags.set_string(p_flags,p_flags_length);
@@ -690,34 +719,28 @@ namespace {
private:
void finalize_track()
{
if ( m_track != 0 ) {
if (m_track < 1 || m_track > maximumCueTrackNumber) pfc::throw_exception_with_message< exception_cue > ("track number out of range");
if (!m_index1_set) pfc::throw_exception_with_message< exception_cue > ("INDEX 01 not set");
if (!m_index0_set) m_indexes.m_positions[0] = m_indexes.m_positions[1] - m_pregap;
if (!m_indexes.is_valid()) pfc::throw_exception_with_message< exception_cue > ("invalid index list");
if (m_track < 1 || m_track > maximumCueTrackNumber) pfc::throw_exception_with_message< exception_cue > ("track number out of range");
if (!m_index1_set) pfc::throw_exception_with_message< exception_cue > ("INDEX 01 not set");
if (!m_index0_set) m_indexes.m_positions[0] = m_indexes.m_positions[1] - m_pregap;
if (!m_indexes.is_valid()) pfc::throw_exception_with_message< exception_cue > ("invalid index list");
cue_creator::t_entry_list::iterator iter;
iter = m_out.insert_last();
iter->m_track_number = m_track;
iter->m_file = m_trackfile;
iter->m_fileType = m_trackFileType;
iter->m_index_list = m_indexes;
iter->m_flags = m_flags;
iter->m_trackType = m_trackType;
}
cue_creator::t_entry_list::iterator iter;
iter = m_out.insert_last();
iter->m_track_number = m_track;
iter->m_file = m_trackfile;
iter->m_index_list = m_indexes;
iter->m_flags = m_flags;
m_pregap = 0;
m_indexes.reset();
m_index0_set = m_index1_set = false;
m_flags.reset();
m_trackType.reset();
}
bool m_index0_set,m_index1_set;
double m_pregap;
unsigned m_track;
bool m_trackIsAudio = false;
cue_creator::t_entry_list & m_out;
pfc::string8 m_file, m_fileType,m_trackfile, m_trackFileType, m_flags, m_trackType;
pfc::string8 m_file,m_trackfile,m_flags;
t_cuesheet_index_list m_indexes;
};
}
@@ -732,12 +755,11 @@ void cue_parser::parse_full(const char * p_cuesheet,cue_creator::t_entry_list &
{
cue_creator::t_entry_list::iterator iter;
for(iter=p_out.first();iter.is_valid();++iter) {
if ( iter->isTrackAudio() ) {
cue_parser_callback_retrieveinfo callback(iter->m_infos,iter->m_track_number);
g_parse_cue(p_cuesheet,callback);
callback.finalize();
}
for(iter=p_out.first();iter.is_valid();++iter)
{
cue_parser_callback_retrieveinfo callback(iter->m_infos,iter->m_track_number);
g_parse_cue(p_cuesheet,callback);
callback.finalize();
}
}
} catch(exception_cue const & e) {