@Test public void shouldFindLongestMatch() { 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"); BachChorale bSix = new BachChorale(); bSix.setChord("emin"); BachChorale bSeven = new BachChorale(); bSeven.setChord("cmaj"); HarmonyExtraction hOne = new HarmonyExtraction(); hOne.setChordname("emin"); HarmonyExtraction hTwo = new HarmonyExtraction(); hTwo.setChordname("cmaj"); HarmonyExtraction hThree = new HarmonyExtraction(); hThree.setChordname("dmin"); List<BachChorale> bachChoralesDb = Arrays.asList(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven); List<HarmonyExtraction> extractions = Arrays.asList(hOne, hTwo, hThree); SetMelodicSynthEvent.LongestMatchResponse matchResponse = setMelodicSynthEvent.getLongestMatch(bachChoralesDb, extractions); assertThat(matchResponse.getMatch()).hasSize(3); assertThat(matchResponse.getMatch().get(0).getChord()).isEqualTo(bTwo.getChord()); assertThat(matchResponse.getMatch().get(1).getChord()).isEqualTo(bThree.getChord()); assertThat(matchResponse.getMatch().get(2).getChord()).isEqualTo(bFour.getChord()); }
public LongestMatchResponse getLongestMatch(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions) { LongestMatchResponse longestMatchResponse = new LongestMatchResponse(); for (int currentLength = 0; currentLength < harmonyExtractions.size(); currentLength++) { List<HarmonyExtraction> extractionSubset = harmonyExtractions.subList(0, currentLength + 1); for (int i = 0; i < bachChorales.size() - extractionSubset.size(); i++) { LongestMatchResponse currentMatchResponse = new LongestMatchResponse(); for (int subSetIndex = 0; subSetIndex < extractionSubset.size(); subSetIndex++) { if(extractionSubset.get(subSetIndex) != null){ if (bachChorales.get(i + subSetIndex).getChord().equalsIgnoreCase(extractionSubset.get(subSetIndex).getChordname())) { currentMatchResponse.addMatchingChord(bachChorales.get(i + subSetIndex)); } } } if (longestMatchResponse == null || currentMatchResponse.getMatch().size() > longestMatchResponse.getMatch().size()) { if(matchesListPrefix(currentMatchResponse.getMatch(), extractionSubset)){ longestMatchResponse = currentMatchResponse; } } } String test = ""; } return longestMatchResponse; }
SetMelodicSynthEvent implements IEventChain { public LongestMatchResponse getLongestMatch(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions) { LongestMatchResponse longestMatchResponse = new LongestMatchResponse(); for (int currentLength = 0; currentLength < harmonyExtractions.size(); currentLength++) { List<HarmonyExtraction> extractionSubset = harmonyExtractions.subList(0, currentLength + 1); for (int i = 0; i < bachChorales.size() - extractionSubset.size(); i++) { LongestMatchResponse currentMatchResponse = new LongestMatchResponse(); for (int subSetIndex = 0; subSetIndex < extractionSubset.size(); subSetIndex++) { if(extractionSubset.get(subSetIndex) != null){ if (bachChorales.get(i + subSetIndex).getChord().equalsIgnoreCase(extractionSubset.get(subSetIndex).getChordname())) { currentMatchResponse.addMatchingChord(bachChorales.get(i + subSetIndex)); } } } if (longestMatchResponse == null || currentMatchResponse.getMatch().size() > longestMatchResponse.getMatch().size()) { if(matchesListPrefix(currentMatchResponse.getMatch(), extractionSubset)){ longestMatchResponse = currentMatchResponse; } } } String test = ""; } return longestMatchResponse; } }
SetMelodicSynthEvent implements IEventChain { public LongestMatchResponse getLongestMatch(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions) { LongestMatchResponse longestMatchResponse = new LongestMatchResponse(); for (int currentLength = 0; currentLength < harmonyExtractions.size(); currentLength++) { List<HarmonyExtraction> extractionSubset = harmonyExtractions.subList(0, currentLength + 1); for (int i = 0; i < bachChorales.size() - extractionSubset.size(); i++) { LongestMatchResponse currentMatchResponse = new LongestMatchResponse(); for (int subSetIndex = 0; subSetIndex < extractionSubset.size(); subSetIndex++) { if(extractionSubset.get(subSetIndex) != null){ if (bachChorales.get(i + subSetIndex).getChord().equalsIgnoreCase(extractionSubset.get(subSetIndex).getChordname())) { currentMatchResponse.addMatchingChord(bachChorales.get(i + subSetIndex)); } } } if (longestMatchResponse == null || currentMatchResponse.getMatch().size() > longestMatchResponse.getMatch().size()) { if(matchesListPrefix(currentMatchResponse.getMatch(), extractionSubset)){ longestMatchResponse = currentMatchResponse; } } } String test = ""; } return longestMatchResponse; } @Autowired  SetMelodicSynthEvent(MelodyGenerator melodydGenerator, MelodicExtractor melodicExtractor, IBachChoraleDal bachChoraleDal); }
SetMelodicSynthEvent implements IEventChain { public LongestMatchResponse getLongestMatch(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions) { LongestMatchResponse longestMatchResponse = new LongestMatchResponse(); for (int currentLength = 0; currentLength < harmonyExtractions.size(); currentLength++) { List<HarmonyExtraction> extractionSubset = harmonyExtractions.subList(0, currentLength + 1); for (int i = 0; i < bachChorales.size() - extractionSubset.size(); i++) { LongestMatchResponse currentMatchResponse = new LongestMatchResponse(); for (int subSetIndex = 0; subSetIndex < extractionSubset.size(); subSetIndex++) { if(extractionSubset.get(subSetIndex) != null){ if (bachChorales.get(i + subSetIndex).getChord().equalsIgnoreCase(extractionSubset.get(subSetIndex).getChordname())) { currentMatchResponse.addMatchingChord(bachChorales.get(i + subSetIndex)); } } } if (longestMatchResponse == null || currentMatchResponse.getMatch().size() > longestMatchResponse.getMatch().size()) { if(matchesListPrefix(currentMatchResponse.getMatch(), extractionSubset)){ longestMatchResponse = currentMatchResponse; } } } String test = ""; } return longestMatchResponse; } @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 LongestMatchResponse getLongestMatch(List<BachChorale> bachChorales, List<HarmonyExtraction> harmonyExtractions) { LongestMatchResponse longestMatchResponse = new LongestMatchResponse(); for (int currentLength = 0; currentLength < harmonyExtractions.size(); currentLength++) { List<HarmonyExtraction> extractionSubset = harmonyExtractions.subList(0, currentLength + 1); for (int i = 0; i < bachChorales.size() - extractionSubset.size(); i++) { LongestMatchResponse currentMatchResponse = new LongestMatchResponse(); for (int subSetIndex = 0; subSetIndex < extractionSubset.size(); subSetIndex++) { if(extractionSubset.get(subSetIndex) != null){ if (bachChorales.get(i + subSetIndex).getChord().equalsIgnoreCase(extractionSubset.get(subSetIndex).getChordname())) { currentMatchResponse.addMatchingChord(bachChorales.get(i + subSetIndex)); } } } if (longestMatchResponse == null || currentMatchResponse.getMatch().size() > longestMatchResponse.getMatch().size()) { if(matchesListPrefix(currentMatchResponse.getMatch(), extractionSubset)){ longestMatchResponse = currentMatchResponse; } } } String test = ""; } return longestMatchResponse; } @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);  }