@Test public void shouldDetermineIfValidMelody(){ String invalidA = "11^113*113*113*415*713*713*713*315*0000-0000-0000-0000-4260-4261-4261-4261-4260-4261-5160-5161-3160-3161-3161-3161+3260-3261-3261-3261-3261-3261-3261-3261-1250-1251-3260-3261-1250-1251-2150-2151+0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000#4000000000000000000000000000#00##0#000#00000000000000000000000000000000000000009"; String invalidB = "11^113*113*113*415*713*713*713*315*0000-0000-0000-0000-7250-7251-7251-7251-7251-7251-7251-7251-1150-1151-1151-1151+7250-7251-7251-7251-7251-7251-7250-7251-6250-6251-6251-6251-5150-5151-5151-5151+5150-5151-5151-5151-5151-5151-5151-5151-7150-7151-7151-7151-7151-7151-2150-2151##000000000-0-0-0#000000000000000000000000000000000000000000000000000000000000000"; String invalidC = "11^113*113*113*415*713*713*713*315*5140-5141-5141-5141-5141-5141-5141-5141-0000-0000-0000-0000-0000-0000-0000-0000+0000-0000-0000-0000+0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000#100000-000-0000000000000000000000000000000000000000000000000000##000000000000000000000000000000000000000000000000000000000000000000000000000"; ChordMelodyDecoder chordMelodyDecoder = new ChordMelodyDecoder(new Config(false)); Assert.assertFalse(chordMelodyDecoder.INVALID.equalsIgnoreCase(chordMelodyDecoder.extractValidMelody(validA))); Assert.assertFalse(chordMelodyDecoder.INVALID.equalsIgnoreCase(chordMelodyDecoder.extractValidMelody(validB))); Assert.assertTrue(chordMelodyDecoder.INVALID.equalsIgnoreCase(chordMelodyDecoder.extractValidMelody(invalidA))); Assert.assertTrue(chordMelodyDecoder.INVALID.equalsIgnoreCase(chordMelodyDecoder.extractValidMelody(invalidB))); Assert.assertTrue(chordMelodyDecoder.INVALID.equalsIgnoreCase(chordMelodyDecoder.extractValidMelody(invalidC))); }
public String extractValidMelody(String seq) { if (seq.length() < 354) { return INVALID; } if (seq.length() > 354) { seq = seq.substring(0, 354); } if (StringUtils.countMatches(seq, "^") != 1) { return INVALID; } if (StringUtils.countMatches(seq, "*") != 8) { return INVALID; } if (StringUtils.countMatches(seq, "+") != 3) { return INVALID; } if (StringUtils.countMatches(seq, "-") != 60) { return INVALID; } String prefix = seq.substring(3, 35); String[] chords = prefix.split("\\*"); if (chords.length != 8) { return INVALID; } for (String chord : chords) { if (chord.length() != 3) { return INVALID; } } String suffix = seq.substring(35, seq.length()); String[] bars = suffix.split("\\+"); for (String bar : bars) { String[] barNotes = bar.split("-"); if (barNotes.length != 16) { return INVALID; } for (String note : barNotes) { if (note.length() != 4) { return INVALID; } } } return seq; }
ChordMelodyDecoder { public String extractValidMelody(String seq) { if (seq.length() < 354) { return INVALID; } if (seq.length() > 354) { seq = seq.substring(0, 354); } if (StringUtils.countMatches(seq, "^") != 1) { return INVALID; } if (StringUtils.countMatches(seq, "*") != 8) { return INVALID; } if (StringUtils.countMatches(seq, "+") != 3) { return INVALID; } if (StringUtils.countMatches(seq, "-") != 60) { return INVALID; } String prefix = seq.substring(3, 35); String[] chords = prefix.split("\\*"); if (chords.length != 8) { return INVALID; } for (String chord : chords) { if (chord.length() != 3) { return INVALID; } } String suffix = seq.substring(35, seq.length()); String[] bars = suffix.split("\\+"); for (String bar : bars) { String[] barNotes = bar.split("-"); if (barNotes.length != 16) { return INVALID; } for (String note : barNotes) { if (note.length() != 4) { return INVALID; } } } return seq; } }
ChordMelodyDecoder { public String extractValidMelody(String seq) { if (seq.length() < 354) { return INVALID; } if (seq.length() > 354) { seq = seq.substring(0, 354); } if (StringUtils.countMatches(seq, "^") != 1) { return INVALID; } if (StringUtils.countMatches(seq, "*") != 8) { return INVALID; } if (StringUtils.countMatches(seq, "+") != 3) { return INVALID; } if (StringUtils.countMatches(seq, "-") != 60) { return INVALID; } String prefix = seq.substring(3, 35); String[] chords = prefix.split("\\*"); if (chords.length != 8) { return INVALID; } for (String chord : chords) { if (chord.length() != 3) { return INVALID; } } String suffix = seq.substring(35, seq.length()); String[] bars = suffix.split("\\+"); for (String bar : bars) { String[] barNotes = bar.split("-"); if (barNotes.length != 16) { return INVALID; } for (String note : barNotes) { if (note.length() != 4) { return INVALID; } } } return seq; } ChordMelodyDecoder(Config config); }
ChordMelodyDecoder { public String extractValidMelody(String seq) { if (seq.length() < 354) { return INVALID; } if (seq.length() > 354) { seq = seq.substring(0, 354); } if (StringUtils.countMatches(seq, "^") != 1) { return INVALID; } if (StringUtils.countMatches(seq, "*") != 8) { return INVALID; } if (StringUtils.countMatches(seq, "+") != 3) { return INVALID; } if (StringUtils.countMatches(seq, "-") != 60) { return INVALID; } String prefix = seq.substring(3, 35); String[] chords = prefix.split("\\*"); if (chords.length != 8) { return INVALID; } for (String chord : chords) { if (chord.length() != 3) { return INVALID; } } String suffix = seq.substring(35, seq.length()); String[] bars = suffix.split("\\+"); for (String bar : bars) { String[] barNotes = bar.split("-"); if (barNotes.length != 16) { return INVALID; } for (String note : barNotes) { if (note.length() != 4) { return INVALID; } } } return seq; } ChordMelodyDecoder(Config config); String extractValidChords(String seq); List<String> extractChordPredictionToArray(String chordPrediction); String extractValidMelody(String seq); String decodeChords(String encoded); String decodeBassline(String encoded); String getJChordName(String encodedChord); String getChordType(String chordCode); String decodeMelody(String encoded, String key); String extractDuration(int duration); String getNoteName(String encoded); String encodeNoteName(String encoded); String encodeChordType(String chordType); String getKey(String encoded); }
ChordMelodyDecoder { public String extractValidMelody(String seq) { if (seq.length() < 354) { return INVALID; } if (seq.length() > 354) { seq = seq.substring(0, 354); } if (StringUtils.countMatches(seq, "^") != 1) { return INVALID; } if (StringUtils.countMatches(seq, "*") != 8) { return INVALID; } if (StringUtils.countMatches(seq, "+") != 3) { return INVALID; } if (StringUtils.countMatches(seq, "-") != 60) { return INVALID; } String prefix = seq.substring(3, 35); String[] chords = prefix.split("\\*"); if (chords.length != 8) { return INVALID; } for (String chord : chords) { if (chord.length() != 3) { return INVALID; } } String suffix = seq.substring(35, seq.length()); String[] bars = suffix.split("\\+"); for (String bar : bars) { String[] barNotes = bar.split("-"); if (barNotes.length != 16) { return INVALID; } for (String note : barNotes) { if (note.length() != 4) { return INVALID; } } } return seq; } ChordMelodyDecoder(Config config); String extractValidChords(String seq); List<String> extractChordPredictionToArray(String chordPrediction); String extractValidMelody(String seq); String decodeChords(String encoded); String decodeBassline(String encoded); String getJChordName(String encodedChord); String getChordType(String chordCode); String decodeMelody(String encoded, String key); String extractDuration(int duration); String getNoteName(String encoded); String encodeNoteName(String encoded); String encodeChordType(String chordType); String getKey(String encoded); static String INVALID; }