1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 20:34:39 +01:00

more accurate parsing of indices in CUEs (we now respect the FRAMES part)

+ incorporating arnaud's code comment in fileviewlist
This commit is contained in:
Paweł Bara 2011-02-15 22:26:56 +00:00
parent a2542f15db
commit 7f3f4f4107
6 changed files with 33 additions and 37 deletions

View File

@ -316,8 +316,9 @@ qint64 CueParser::IndexToMarker(const QString& index) const {
}
QStringList splitted = index_regexp.capturedTexts().mid(1, -1);
// TODO: use frames when #1166 is fixed
return (splitted.at(0).toLongLong() * 60 + splitted.at(1).toLongLong()) * kNsecPerSec;
qlonglong frames = splitted.at(0).toLongLong() * 60 * 75 + splitted.at(1).toLongLong() * 75 +
splitted.at(2).toLongLong();
return (frames * kNsecPerSec) / 75;
}
void CueParser::Save(const SongList &songs, QIODevice *device, const QDir &dir) const {

View File

@ -22,7 +22,6 @@
#include <QContextMenuEvent>
#include <QFileSystemModel>
#include <QMenu>
#include <QSet>
#include <QtDebug>
FileViewList::FileViewList(QWidget* parent)
@ -92,18 +91,10 @@ void FileViewList::AddToPlaylistSlot() {
void FileViewList::OpenInNewPlaylistSlot() {
MimeData* data = MimeDataFromSelection();
QSet<QString> filenames;
foreach(const QString& filename, FilenamesFromSelection()) {
filenames.insert(filename);
if(filenames.size() > 1) {
break;
}
}
QList<QString> filenames = FilenamesFromSelection();
// if just one file / folder selected - use it's path as the new playlist's name
if(filenames.size() == 1) {
data->name_for_new_playlist_ = filenames.toList()[0];
data->name_for_new_playlist_ = filenames[0];
// otherwise, use the current root path
} else {
data->name_for_new_playlist_ = static_cast<QFileSystemModel*>(model())->rootPath();

View File

@ -44,6 +44,10 @@ class CueParserTest : public ::testing::Test {
return true;
}
qlonglong to_nanosec(int minutes, int seconds, int frames) {
return (minutes * 60 * 75 + seconds * 75 + frames) * kNsecPerSec / 75;
}
CueParser parser_;
MockFileRefFactory taglib_;
};
@ -63,7 +67,7 @@ TEST_F(CueParserTest, ParsesASong) {
ASSERT_EQ("Zucchero", first_song.artist());
ASSERT_EQ("Zucchero himself", first_song.albumartist());
ASSERT_EQ("", first_song.album());
ASSERT_EQ(1 * kNsecPerSec, first_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(0, 1, 15), first_song.beginning_nanosec());
ASSERT_EQ(1, first_song.track());
ASSERT_EQ("CUEPATH", first_song.cue_path());
@ -87,7 +91,7 @@ TEST_F(CueParserTest, ParsesTwoSongs) {
ASSERT_EQ("Chocabeck", first_song.album());
ASSERT_EQ("Zucchero himself", first_song.artist());
ASSERT_EQ("Zucchero himself", first_song.albumartist());
ASSERT_EQ(1 * kNsecPerSec, first_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(0, 1, 0), first_song.beginning_nanosec());
ASSERT_EQ(second_song.beginning_nanosec() - first_song.beginning_nanosec(), first_song.length_nanosec());
ASSERT_EQ(1, first_song.track());
@ -95,7 +99,7 @@ TEST_F(CueParserTest, ParsesTwoSongs) {
ASSERT_EQ("Chocabeck", second_song.album());
ASSERT_EQ("Zucchero himself", second_song.artist());
ASSERT_EQ("Zucchero himself", second_song.albumartist());
ASSERT_EQ((5 * 60 + 3) * kNsecPerSec, second_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(5, 3, 68), second_song.beginning_nanosec());
ASSERT_EQ(2, second_song.track());
validate_songs(song_list);
@ -118,7 +122,7 @@ TEST_F(CueParserTest, SkipsBrokenSongs) {
ASSERT_EQ("Chocabeck", first_song.album());
ASSERT_EQ("Zucchero himself", first_song.artist());
ASSERT_EQ("Zucchero himself", first_song.albumartist());
ASSERT_EQ(1 * kNsecPerSec, first_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(0, 1, 0), first_song.beginning_nanosec());
// includes the broken song too; this entry will span from it's
// INDEX (beginning) to the end of the next correct song
ASSERT_EQ(second_song.beginning_nanosec() - first_song.beginning_nanosec(), first_song.length_nanosec());
@ -128,7 +132,7 @@ TEST_F(CueParserTest, SkipsBrokenSongs) {
ASSERT_EQ("Chocabeck", second_song.album());
ASSERT_EQ("Zucchero himself", second_song.artist());
ASSERT_EQ("Zucchero himself", second_song.albumartist());
ASSERT_EQ((5 * 60) * kNsecPerSec, second_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(5, 0, 0), second_song.beginning_nanosec());
ASSERT_EQ(2, second_song.track());
validate_songs(song_list);
@ -153,7 +157,7 @@ TEST_F(CueParserTest, UsesAllMetadataInformation) {
ASSERT_EQ("Zucchero", first_song.artist());
ASSERT_EQ("Zucchero himself", first_song.albumartist());
ASSERT_EQ("Some guy", first_song.composer());
ASSERT_EQ(1 * kNsecPerSec, first_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(0, 1, 0), first_song.beginning_nanosec());
ASSERT_EQ(second_song.beginning_nanosec() - first_song.beginning_nanosec(), first_song.length_nanosec());
ASSERT_EQ(1, first_song.track());
@ -163,7 +167,7 @@ TEST_F(CueParserTest, UsesAllMetadataInformation) {
ASSERT_EQ("Zucchero himself", second_song.artist());
ASSERT_EQ("Zucchero himself", second_song.albumartist());
ASSERT_EQ("Some other guy", second_song.composer());
ASSERT_EQ(2 * kNsecPerSec, second_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(0, 2, 0), second_song.beginning_nanosec());
ASSERT_EQ(2, second_song.track());
validate_songs(song_list);
@ -190,7 +194,7 @@ TEST_F(CueParserTest, AcceptsMultipleFileBasedCues) {
ASSERT_EQ("Artist One Album", first_song.album());
ASSERT_EQ("Artist One", first_song.artist());
ASSERT_EQ("Artist One", first_song.albumartist());
ASSERT_EQ(1 * kNsecPerSec, first_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(0, 1, 0), first_song.beginning_nanosec());
ASSERT_EQ(second_song.beginning_nanosec() - first_song.beginning_nanosec(), first_song.length_nanosec());
ASSERT_EQ(-1, first_song.track());
ASSERT_EQ("CUEPATH", first_song.cue_path());
@ -200,7 +204,7 @@ TEST_F(CueParserTest, AcceptsMultipleFileBasedCues) {
ASSERT_EQ("Artist One Album", second_song.album());
ASSERT_EQ("Artist One", second_song.artist());
ASSERT_EQ("Artist One", second_song.albumartist());
ASSERT_EQ((5 * 60 + 3) * kNsecPerSec, second_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(5, 3, 68), second_song.beginning_nanosec());
ASSERT_EQ(-1, second_song.track());
ASSERT_TRUE(third_song.filename().endsWith("files/longer_two_p1.mp3"));
@ -208,7 +212,7 @@ TEST_F(CueParserTest, AcceptsMultipleFileBasedCues) {
ASSERT_EQ("Artist Two Album", third_song.album());
ASSERT_EQ("Artist X", third_song.artist());
ASSERT_EQ("Artist Two", third_song.albumartist());
ASSERT_EQ(0, third_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(0, 0, 12), third_song.beginning_nanosec());
ASSERT_EQ(fourth_song.beginning_nanosec() - third_song.beginning_nanosec(), third_song.length_nanosec());
ASSERT_EQ(-1, third_song.track());
ASSERT_EQ("CUEPATH", third_song.cue_path());
@ -218,7 +222,7 @@ TEST_F(CueParserTest, AcceptsMultipleFileBasedCues) {
ASSERT_EQ("Artist Two Album", fourth_song.album());
ASSERT_EQ("Artist Two", fourth_song.artist());
ASSERT_EQ("Artist Two", fourth_song.albumartist());
ASSERT_EQ((4 * 60) * kNsecPerSec, fourth_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(4, 0, 13), fourth_song.beginning_nanosec());
ASSERT_EQ(-1, fourth_song.track());
ASSERT_TRUE(fifth_song.filename().endsWith("files/longer_two_p2.mp3"));
@ -226,7 +230,7 @@ TEST_F(CueParserTest, AcceptsMultipleFileBasedCues) {
ASSERT_EQ("Artist Two Album", fifth_song.album());
ASSERT_EQ("Artist Two", fifth_song.artist());
ASSERT_EQ("Artist Two", fifth_song.albumartist());
ASSERT_EQ(1 * kNsecPerSec, fifth_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(0, 1, 0), fifth_song.beginning_nanosec());
ASSERT_EQ(-1, fifth_song.track());
ASSERT_EQ("CUEPATH", fifth_song.cue_path());
@ -253,7 +257,7 @@ TEST_F(CueParserTest, SkipsBrokenSongsInMultipleFileBasedCues) {
ASSERT_EQ("Artist One", first_song.artist());
ASSERT_EQ("Artist One Album", first_song.album());
ASSERT_EQ("A1", first_song.title());
ASSERT_EQ(1 * kNsecPerSec, first_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(0, 1, 15), first_song.beginning_nanosec());
ASSERT_EQ(second_song.beginning_nanosec() - first_song.beginning_nanosec(), first_song.length_nanosec());
ASSERT_EQ(-1, first_song.track());
@ -261,7 +265,7 @@ TEST_F(CueParserTest, SkipsBrokenSongsInMultipleFileBasedCues) {
ASSERT_EQ("Artist One", second_song.artist());
ASSERT_EQ("Artist One Album", second_song.album());
ASSERT_EQ("A3", second_song.title());
ASSERT_EQ(60 * kNsecPerSec, second_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(1, 0, 16), second_song.beginning_nanosec());
ASSERT_EQ(-1, second_song.track());
// all B* songs are broken
@ -271,7 +275,7 @@ TEST_F(CueParserTest, SkipsBrokenSongsInMultipleFileBasedCues) {
ASSERT_EQ("Artist Three", third_song.artist());
ASSERT_EQ("Artist Three Album", third_song.album());
ASSERT_EQ("C1", third_song.title());
ASSERT_EQ(1 * kNsecPerSec, third_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(0, 1, 0), third_song.beginning_nanosec());
ASSERT_EQ(-1, third_song.track());
// D* - broken song at the beginning
@ -279,7 +283,7 @@ TEST_F(CueParserTest, SkipsBrokenSongsInMultipleFileBasedCues) {
ASSERT_EQ("Artist Four", fourth_song.artist());
ASSERT_EQ("Artist Four Album", fourth_song.album());
ASSERT_EQ("D2", fourth_song.title());
ASSERT_EQ(61 * kNsecPerSec, fourth_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(15, 55, 66), fourth_song.beginning_nanosec());
ASSERT_EQ(-1, fourth_song.track());
validate_songs(song_list);
@ -302,14 +306,14 @@ TEST_F(CueParserTest, SkipsDataFiles) {
ASSERT_EQ("Artist One", first_song.artist());
ASSERT_EQ("Artist One Album", first_song.album());
ASSERT_EQ("A1", first_song.title());
ASSERT_EQ(1 * kNsecPerSec, first_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(0, 1, 0), first_song.beginning_nanosec());
ASSERT_EQ(-1, first_song.track());
ASSERT_TRUE(second_song.filename().endsWith("file4.mp3"));
ASSERT_EQ("Artist Four", second_song.artist());
ASSERT_EQ("Artist Four Album", second_song.album());
ASSERT_EQ("D1", second_song.title());
ASSERT_EQ(61 * kNsecPerSec, second_song.beginning_nanosec());
ASSERT_EQ(to_nanosec(1, 1, 0), second_song.beginning_nanosec());
ASSERT_EQ(-1, second_song.track());
validate_songs(song_list);

View File

@ -13,10 +13,10 @@ TITLE "Artist Two Album"
TRACK 01 AUDIO
TITLE "A2P1Song1"
PERFORMER "Artist X"
INDEX 01 00:00:00
INDEX 01 00:00:12
TRACK 02 AUDIO
TITLE "A2P1Song2"
INDEX 01 04:00:00
INDEX 01 04:00:13
FILE files/longer_two_p2.mp3 WAVE
PERFORMER "Artist Two"
TITLE "Artist Two Album"

View File

@ -3,12 +3,12 @@ PERFORMER "Artist One"
TITLE "Artist One Album"
TRACK 01 AUDIO
TITLE "A1"
INDEX 01 00:01:00
INDEX 01 00:01:15
TRACK 02 AUDIO
TITLE "A2"
TRACK 03 AUDIO
TITLE "A3"
INDEX 01 01:00:00
INDEX 01 01:00:16
FILE file2.mp3 WAVE
PERFORMER "Artist Two"
TITLE "Artist Two Album"
@ -30,4 +30,4 @@ TITLE "Artist Four Album"
TITLE "D1"
TRACK 02 AUDIO
TITLE "D2"
INDEX 00 01:01:00
INDEX 00 15:55:66

View File

@ -3,4 +3,4 @@ FILE "file.mp3" WAVE
TRACK 01 AUDIO
TITLE "Un soffio caldo"
PERFORMER Zucchero
INDEX 01 00:01:00
INDEX 01 00:01:15