@Test public void shouldFindCorrectMatchLengthAndOffset() { BachChorale bOne = new BachChorale(); bOne.setChord("emin7"); BachChorale bTwo = new BachChorale(); bTwo.setChord("emin"); BachChorale bThree = new BachChorale(); bThree.setChord("cmaj"); BachChorale bFour = new BachChorale(); bFour.setChord("dmin"); BachChorale bFive = new BachChorale(); bFive.setChord("cmaj"); HarmonyExtraction hOne = new HarmonyExtraction(); hOne.setChordname("cmaj"); HarmonyExtraction hTwo = new HarmonyExtraction(); hTwo.setChordname("dmin"); HarmonyExtraction hThree = new HarmonyExtraction(); hThree.setChordname("emin"); HarmonyExtraction hFour = new HarmonyExtraction(); hFour.setChordname("emin"); HarmonyExtraction hFive = new HarmonyExtraction(); hFive.setChordname("cmaj"); HarmonyExtraction hSix = new HarmonyExtraction(); hSix.setChordname("cmaj"); HarmonyExtraction hSeven = new HarmonyExtraction(); hSeven.setChordname("bbdom7"); List<BachChorale> bachChoralesDb = Arrays.asList(bOne, bTwo, bThree, bFour, bFive); List<HarmonyExtraction> extractions = Arrays.asList(hOne, hTwo, hThree, hFour, hFive, hSix, hSeven); List<BachChorale> matchingBachChorales = setMelodicSynthEvent.createMatchingChorales(bachChoralesDb, extractions); assertThat(matchingBachChorales).hasSize(7); assertThat(matchingBachChorales.get(0).getChord()).isEqualTo(bThree.getChord()); assertThat(matchingBachChorales.get(1).getChord()).isEqualTo(bFour.getChord()); assertThat(matchingBachChorales.get(2).getChord()).isEqualTo(bTwo.getChord()); assertThat(matchingBachChorales.get(3).getChord()).isEqualTo(bTwo.getChord()); assertThat(matchingBachChorales.get(4).getChord()).isEqualTo(bThree.getChord()); assertThat(matchingBachChorales.get(5).getChord()).isEqualTo(bThree.getChord()); assertThat(matchingBachChorales.get(6)).isNull(); }
public List<BachChorale> createMatchingChorales(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions) { List<BachChorale> matchingChorales = new ArrayList<>(); List<HarmonyExtraction> remainingExtractions = harmonyExtractions; while (matchingChorales.size() < harmonyExtractions.size()){ LongestMatchResponse longestMatch = getLongestMatch(bachChorales, remainingExtractions); if(longestMatch.getMatch().isEmpty()){ longestMatch.addMatchingChord(null); matchingChorales.add(null); }else { matchingChorales.addAll(longestMatch.getMatch()); } remainingExtractions = remainingExtractions.subList(longestMatch.getMatch().size(), remainingExtractions.size()); } return matchingChorales; }
SetMelodicSynthEvent implements IEventChain { public List<BachChorale> createMatchingChorales(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions) { List<BachChorale> matchingChorales = new ArrayList<>(); List<HarmonyExtraction> remainingExtractions = harmonyExtractions; while (matchingChorales.size() < harmonyExtractions.size()){ LongestMatchResponse longestMatch = getLongestMatch(bachChorales, remainingExtractions); if(longestMatch.getMatch().isEmpty()){ longestMatch.addMatchingChord(null); matchingChorales.add(null); }else { matchingChorales.addAll(longestMatch.getMatch()); } remainingExtractions = remainingExtractions.subList(longestMatch.getMatch().size(), remainingExtractions.size()); } return matchingChorales; } }
SetMelodicSynthEvent implements IEventChain { public List<BachChorale> createMatchingChorales(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions) { List<BachChorale> matchingChorales = new ArrayList<>(); List<HarmonyExtraction> remainingExtractions = harmonyExtractions; while (matchingChorales.size() < harmonyExtractions.size()){ LongestMatchResponse longestMatch = getLongestMatch(bachChorales, remainingExtractions); if(longestMatch.getMatch().isEmpty()){ longestMatch.addMatchingChord(null); matchingChorales.add(null); }else { matchingChorales.addAll(longestMatch.getMatch()); } remainingExtractions = remainingExtractions.subList(longestMatch.getMatch().size(), remainingExtractions.size()); } return matchingChorales; } @Autowired  SetMelodicSynthEvent(MelodyGenerator melodydGenerator, MelodicExtractor melodicExtractor, IBachChoraleDal bachChoraleDal); }
SetMelodicSynthEvent implements IEventChain { public List<BachChorale> createMatchingChorales(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions) { List<BachChorale> matchingChorales = new ArrayList<>(); List<HarmonyExtraction> remainingExtractions = harmonyExtractions; while (matchingChorales.size() < harmonyExtractions.size()){ LongestMatchResponse longestMatch = getLongestMatch(bachChorales, remainingExtractions); if(longestMatch.getMatch().isEmpty()){ longestMatch.addMatchingChord(null); matchingChorales.add(null); }else { matchingChorales.addAll(longestMatch.getMatch()); } remainingExtractions = remainingExtractions.subList(longestMatch.getMatch().size(), remainingExtractions.size()); } return matchingChorales; } @Autowired  SetMelodicSynthEvent(MelodyGenerator melodydGenerator, MelodicExtractor melodicExtractor, IBachChoraleDal bachChoraleDal); @Override QueueState set(QueueState queueState); Map<ProgressionType, List<BachChorale>> createTypeToBachChorales(List<BachChorale> choralesDb, Map<ProgressionType, List<HarmonyExtraction>> typeToHarmonicExtractionMap); List<String> findUnusedNotes(List<String> usedNotes, List<String> availableNotes); Map<ProgressionType, List<String>> createTypeToChordSequenceMap(Map<ProgressionType, int[]> typeToMatchLengthAndOffset, List<BachChorale> chorales); List<BachChorale> createMatchingChorales(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions); LongestMatchResponse getLongestMatch(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions); int interateCollection(int indexOffset, List<BachChorale> bachChorales, List<HarmonyExtraction> extractions); }
SetMelodicSynthEvent implements IEventChain { public List<BachChorale> createMatchingChorales(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions) { List<BachChorale> matchingChorales = new ArrayList<>(); List<HarmonyExtraction> remainingExtractions = harmonyExtractions; while (matchingChorales.size() < harmonyExtractions.size()){ LongestMatchResponse longestMatch = getLongestMatch(bachChorales, remainingExtractions); if(longestMatch.getMatch().isEmpty()){ longestMatch.addMatchingChord(null); matchingChorales.add(null); }else { matchingChorales.addAll(longestMatch.getMatch()); } remainingExtractions = remainingExtractions.subList(longestMatch.getMatch().size(), remainingExtractions.size()); } return matchingChorales; } @Autowired  SetMelodicSynthEvent(MelodyGenerator melodydGenerator, MelodicExtractor melodicExtractor, IBachChoraleDal bachChoraleDal); @Override QueueState set(QueueState queueState); Map<ProgressionType, List<BachChorale>> createTypeToBachChorales(List<BachChorale> choralesDb, Map<ProgressionType, List<HarmonyExtraction>> typeToHarmonicExtractionMap); List<String> findUnusedNotes(List<String> usedNotes, List<String> availableNotes); Map<ProgressionType, List<String>> createTypeToChordSequenceMap(Map<ProgressionType, int[]> typeToMatchLengthAndOffset, List<BachChorale> chorales); List<BachChorale> createMatchingChorales(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions); LongestMatchResponse getLongestMatch(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions); int interateCollection(int indexOffset, List<BachChorale> bachChorales, List<HarmonyExtraction> extractions);  }