|
1 | 1 | package de.saar.coli.arranger; |
2 | 2 |
|
| 3 | +import com.beust.jcommander.JCommander; |
| 4 | +import com.beust.jcommander.Parameter; |
3 | 5 | import com.google.common.collect.ArrayListMultimap; |
4 | 6 | import com.google.common.collect.ListMultimap; |
5 | 7 | import de.saar.coli.arranger.abc.AbcParser; |
@@ -29,13 +31,25 @@ public Arrange(Config config) { |
29 | 31 |
|
30 | 32 | public static void main(String[] args) throws IOException, AbcParser.AbcParsingException { |
31 | 33 | Config config = Config.read(new InputStreamReader(Arrange.class.getResourceAsStream("/config.yaml"))); |
32 | | - Score score = new AbcParser().read(new FileReader("down_our_way.abc")); |
| 34 | + Args arguments = new Args(); |
| 35 | + JCommander jc = JCommander.newBuilder().addObject(arguments).build(); |
| 36 | + jc.parse(args); |
| 37 | + |
| 38 | + if(arguments.help) { |
| 39 | + jc.usage(); |
| 40 | + System.exit(0); |
| 41 | + } |
| 42 | + |
| 43 | + System.out.printf("Reading melody and chords from: %s\n", arguments.inputFilename); |
| 44 | + System.out.printf("Writing arrangement to: %s\n\n", arguments.outputFilename); |
| 45 | + |
| 46 | + Score score = new AbcParser().read(new FileReader(arguments.inputFilename)); |
33 | 47 |
|
34 | 48 | Arrange arranger = new Arrange(config); |
35 | 49 | Score bestArrangedScore = arranger.arrange(score); |
36 | 50 |
|
37 | 51 | AbcWriter abcw = new AbcWriter(); |
38 | | - FileWriter fw = new FileWriter("arranged.abc"); |
| 52 | + FileWriter fw = new FileWriter(arguments.outputFilename); |
39 | 53 | abcw.write(bestArrangedScore, fw); |
40 | 54 | fw.flush(); |
41 | 55 | fw.close(); |
@@ -108,7 +122,7 @@ private Score arrange(Score score) { |
108 | 122 | List<Map.Entry<Item, Integer>> sortedEntries = new ArrayList<>(bestScores.entrySet()); |
109 | 123 | Collections.sort(sortedEntries, Comparator.comparing(Map.Entry::getValue)); |
110 | 124 | Map.Entry<Item, Integer> bestGoalItem = sortedEntries.get(sortedEntries.size() - 1); |
111 | | - System.out.printf("Best arrangement has score %d\n", bestGoalItem.getValue()); |
| 125 | + System.out.printf("Best arrangement has score %d.\n", bestGoalItem.getValue()); |
112 | 126 |
|
113 | 127 | Score bestArrangedScore = extractBestScore(bestGoalItem.getKey(), backpointers, score); |
114 | 128 | return bestArrangedScore; |
@@ -321,4 +335,16 @@ public int hashCode() { |
321 | 335 | return Arrays.hashCode(x); |
322 | 336 | } |
323 | 337 | } |
| 338 | + |
| 339 | + public static class Args { |
| 340 | + @Parameter(description = "Name of the input file (*.abc).", required = true) |
| 341 | + private String inputFilename = null; |
| 342 | + |
| 343 | + @Parameter(names = {"--output", "-o"}, description="Name of the output file (*.abc).") |
| 344 | + private String outputFilename = "arranged.abc"; |
| 345 | + |
| 346 | + @Parameter(names = "--help", description="Display usage instructions.", help = true) |
| 347 | + private boolean help; |
| 348 | + |
| 349 | + } |
324 | 350 | } |
0 commit comments