Skip to content

Commit

Permalink
add toc validate method
Browse files Browse the repository at this point in the history
  • Loading branch information
squawkcpp committed Aug 14, 2018
1 parent b7faa86 commit a6e8da3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
19 changes: 19 additions & 0 deletions av/discid/toc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,23 @@ time time::operator+ ( const time& rhs ) const {
const toc_time_t rhs_frames = calculate_frames ( rhs );
return time ( this_frames + rhs_frames );
}

bool valid ( const toc_t& t ) {

toc_time_t _last_sector = 0;

for ( auto& __t : t ) {
//check the sectors
if ( _last_sector == 0 || __t.start_sector >= _last_sector ) {

if ( __t.end_sector >= __t.start_sector ) {
_last_sector = __t.end_sector;

} else { return false; }

} else { return false; }
}

return true;
}
}//namespace discid.
6 changes: 6 additions & 0 deletions av/discid/toc.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ struct toc {
friend std::ostream& operator<< (
/** The target output stream. */ std::ostream& stream,
/** The toc to print */ toc& t );

static bool valid ( const toc& t );
};

typedef std::vector< toc > toc_t;
Expand Down Expand Up @@ -122,5 +124,9 @@ toc_t parse_file (
/** the path of the album. */ const std::string& path,
/** file playlengths in milliseconds. */ const std::vector< std::string > files );

/** @brief check if the toc is valid.
checks the sector and time values. */
bool valid ( const toc_t& toc ) ;

}//namespace discid
#endif // TOC_H
44 changes: 25 additions & 19 deletions samples/discinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,31 @@ int main ( int argc, char **argv ) {

//lookup from musicbrainz

if ( ! ( _errc = discid::mb (
_parsed_toc,
_mb_toc,
std::bind ( discid::match_album, _title, std::placeholders::_1 ) ) ) ) {
std::cout << "Musicbrainz result (cue|log): -----------------------------------------------------" << std::endl;
std::cout << _mb_toc << std::endl;
std::cout << "---------------------------------------------------------------------" << std::endl;

} else { std::cout << _errc.message() << std::endl; }

if ( ! ( _errc = discid::mb (
_file_toc,
_mb_toc,
std::bind ( discid::match_album, _title, std::placeholders::_1 ) ) ) ) {
std::cout << "Musicbrainz result (file): -----------------------------------------------------" << std::endl;
std::cout << _mb_toc << std::endl;
std::cout << "---------------------------------------------------------------------" << std::endl;

} else { std::cout << _errc.message() << std::endl; }
if ( discid::valid ( _parsed_toc ) ) {
if ( ! ( _errc = discid::mb (
_parsed_toc,
_mb_toc,
std::bind ( discid::match_album, _title, std::placeholders::_1 ) ) ) ) {
std::cout << "Musicbrainz result (cue|log): -----------------------------------------------------" << std::endl;
std::cout << _mb_toc << std::endl;
std::cout << "---------------------------------------------------------------------" << std::endl;

} else { std::cout << _errc.message() << std::endl; }

} else { std::cout << "parsed toc is not not valid." << std::endl; }

if ( discid::valid ( _file_toc ) ) {
if ( ! ( _errc = discid::mb (
_file_toc,
_mb_toc,
std::bind ( discid::match_album, _title, std::placeholders::_1 ) ) ) ) {
std::cout << "Musicbrainz result (file): -----------------------------------------------------" << std::endl;
std::cout << _mb_toc << std::endl;
std::cout << "---------------------------------------------------------------------" << std::endl;

} else { std::cout << _errc.message() << std::endl; }

} else { std::cout << "parsed toc is not not valid." << std::endl; }

//lookup from freedb

Expand Down

0 comments on commit a6e8da3

Please sign in to comment.