Skip to content

Commit

Permalink
Added the ability to change output mode when printing a playlist of s…
Browse files Browse the repository at this point in the history
…imilar tracks
  • Loading branch information
iammordaty committed Nov 7, 2019
1 parent 7a0c6a9 commit f5932bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
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;
}
}

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 ('-k') of" << endl
<< " the most similar tracks. Possible modes: 'short', 'long'." << endl
<< " DEFAULT: " << default_outputmode << endl;
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

0 comments on commit f5932bc

Please sign in to comment.