Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions musly/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ compute_playlist(
std::vector<musly_trackid>& alltrackids,
std::vector<std::string>& tracks_files,
musly_trackid seed,
int k)
int k,
std::string outputmode)
{
k = std::min(k, (int)alltracks.size());
std::vector<int> artists_null; // disable artist filtering
Expand All @@ -519,7 +520,15 @@ compute_playlist(
std::ostringstream pl;
for (int i = 0; i < k; i++) {
int j = track_idx[i].first;
pl << tracks_files[j] << std::endl;

if (outputmode == "short") {
pl << tracks_files[j] << std::endl;
} else if (outputmode == "long") {
float d = track_idx[i].second;

pl << "track-id: " << j << ", track-distance: " << d
<< ", track-origin: " << tracks_files[j] << std::endl;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in principle! I think we should omit the track- prefixes, though. And track-origin could just become filename? And I'm a bit unsure if the track id is useful, since users do not have a way to set it anyway. Would you have a use case in mind?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should omit the track- prefixes, though. And track-origin could just become filename?

I thought about consistency with the 'list files' mode, but if there is no such need, I will remove track- prefixes and change track-origin to filename - it clearly indicates what it is and just looks better :-)

And I'm a bit unsure if the track id is useful, since users do not have a way to set it anyway. Would you have a use case in mind?

Thank you for pointing this out, I had doubts about adding it.
As above, I added this field to be consistent with file listing mode. I noticed that this is not a "real" track identifier, but I left it at MR to talk about it to make sure.

}
}

return pl.str();
Expand Down Expand Up @@ -903,8 +912,9 @@ main(int argc, char *argv[])
trackids[i] = i;
}
musly_trackid seed = std::distance(tracks_files.begin(), it);
std::string outputmode = po.get_option_str("o");
std::string pl = compute_playlist(tracks, trackids, tracks_files,
seed, k);
seed, k, outputmode);
if (pl == "") {
std::cerr << "Failed to compute similar tracks for given file."
<< std::endl;
Expand Down
8 changes: 7 additions & 1 deletion musly/programoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
programoptions::programoptions(int argc, char *argv[],
const std::vector<std::string>& methods) :
default_collection("collection.musly"),
default_outputmode("short"),
default_k(5),
default_debuglevel(0),
action(""),
Expand All @@ -36,6 +37,7 @@ programoptions::programoptions(int argc, char *argv[],
optionstr["k"] = kstr.str();
optionstr["e"] = "-1";
optionstr["f"] = "-1";
optionstr["o"] = default_outputmode;

// Build a CSV string with all methods available.
all_methods = methods[0];
Expand All @@ -46,7 +48,7 @@ programoptions::programoptions(int argc, char *argv[],
opterr = 0;
while (1) {

int c = getopt(argc, argv, "v:ihc:Jj:a:x:Ee:f:Nn:k:ldm:s:p:");
int c = getopt(argc, argv, "v:ihc:Jj:a:x:Ee:f:Nn:k:ldm:s:p:o:");
if (c == -1) {
break;
}
Expand Down Expand Up @@ -90,6 +92,7 @@ programoptions::programoptions(int argc, char *argv[],
case 'c':
case 'j':
case 'k':
case 'o':
case 'f':
if (optarg) {
std::string copt;
Expand Down Expand Up @@ -177,6 +180,9 @@ cout << " -k NUM set number of similar songs per item when computing" <<
<< " playlists ('-p'), sparse distance matrices ('-s')" << endl
<< " or when evaluating the collection ('-e')." << endl
<< " DEFAULT: " << default_k << endl;
cout << " -o MODE Set the output mode when printing a playlist ('-p') of" << endl
<< " the most similar tracks. Possible modes: 'short', 'long'." << endl
<< " DEFAULT: " << default_outputmode << endl;
Comment thread
iammordaty marked this conversation as resolved.
cout << " INITIALIZATION:" << endl;
cout << " -n MTH | -N initialize the collection (set with '-c') using the" << endl
<< " music similarity method MTH. Available methods:" << endl
Expand Down
1 change: 1 addition & 0 deletions musly/programoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class programoptions {

std::string all_methods;
std::string default_collection;
std::string default_outputmode;
int default_k;
int default_debuglevel;
std::string action;
Expand Down