@Test public void shouldCreateHashMapWithCminAndEmaj(){ HiveChord eMinChord = new HiveChord("emin"); HiveChord cMajChord = new HiveChord("cmaj"); HiveChord fmin7Chord = new HiveChord("fmin7"); HarmonicLoop loopEmin = new HarmonicLoop(); loopEmin.setBarCount(4); loopEmin.setChords(Arrays.asList(eMinChord)); HarmonicLoop loopCmaj7 = new HarmonicLoop(); loopCmaj7.setBarCount(4); loopCmaj7.setChords(Arrays.asList(cMajChord)); HarmonicLoop loopFmin7Cmaj = new HarmonicLoop(); loopFmin7Cmaj.setBarCount(4); loopFmin7Cmaj.setChords(Arrays.asList(cMajChord,fmin7Chord)); ProgressionUnit progressionUnitOne = new ProgressionUnit(); progressionUnitOne.setType(ProgressionType.VERSE); progressionUnitOne.initBars(4); progressionUnitOne.getProgressionUnitBars().get(0).setChord(eMinChord); progressionUnitOne.getProgressionUnitBars().get(0).setHarmonicLoop(loopEmin); ProgressionUnit progressionUnitTwo = new ProgressionUnit(); progressionUnitTwo.setType(ProgressionType.BRIDGE); progressionUnitTwo.initBars(4); progressionUnitTwo.getProgressionUnitBars().get(0).setChord(cMajChord); progressionUnitTwo.getProgressionUnitBars().get(0).setHarmonicLoop(loopCmaj7); ProgressionUnit progressionUnitThree = new ProgressionUnit(); progressionUnitThree.setType(ProgressionType.CHORUS); progressionUnitThree.initBars(4); progressionUnitThree.getProgressionUnitBars().get(0).setChord(fmin7Chord); progressionUnitThree.getProgressionUnitBars().get(0).setHarmonicLoop(loopFmin7Cmaj); HashMap<ProgressionType, List<HiveChord>> typeToProgressionMap = chordSelector.selectChordsFrom4BarLoop(Arrays.asList(progressionUnitOne, progressionUnitTwo, progressionUnitThree)); assertThat(typeToProgressionMap.size()).isEqualTo(3); assertThat(typeToProgressionMap.get(ProgressionType.VERSE).size()).isEqualTo(4); assertThat(typeToProgressionMap.get(ProgressionType.VERSE).get(0).getChordName()).isEqualToIgnoringCase("emin"); assertThat(typeToProgressionMap.get(ProgressionType.VERSE).get(1).getChordName()).isEqualToIgnoringCase("emin"); assertThat(typeToProgressionMap.get(ProgressionType.VERSE).get(2).getChordName()).isEqualToIgnoringCase("emin"); assertThat(typeToProgressionMap.get(ProgressionType.VERSE).get(3).getChordName()).isEqualToIgnoringCase("emin"); assertThat(typeToProgressionMap.get(ProgressionType.BRIDGE).size()).isEqualTo(4); assertThat(typeToProgressionMap.get(ProgressionType.BRIDGE).get(0).getChordName()).isEqualToIgnoringCase("cmaj"); assertThat(typeToProgressionMap.get(ProgressionType.BRIDGE).get(1).getChordName()).isEqualToIgnoringCase("cmaj"); assertThat(typeToProgressionMap.get(ProgressionType.BRIDGE).get(2).getChordName()).isEqualToIgnoringCase("cmaj"); assertThat(typeToProgressionMap.get(ProgressionType.BRIDGE).get(3).getChordName()).isEqualToIgnoringCase("cmaj"); assertThat(typeToProgressionMap.get(ProgressionType.CHORUS).size()).isEqualTo(4); assertThat(typeToProgressionMap.get(ProgressionType.CHORUS).get(0).getChordName()).isEqualToIgnoringCase("fmin7"); assertThat(typeToProgressionMap.get(ProgressionType.CHORUS).get(1).getChordName()).isEqualToIgnoringCase("fmin7"); assertThat(typeToProgressionMap.get(ProgressionType.CHORUS).get(2).getChordName()).isEqualToIgnoringCase("fmin7"); assertThat(typeToProgressionMap.get(ProgressionType.CHORUS).get(3).getChordName()).isEqualToIgnoringCase("fmin7"); }
@Override public HashMap<ProgressionType, List<HiveChord>> selectChordsFrom4BarLoop(List<ProgressionUnit> progressionUnits) { HashMap<ProgressionType, List<HiveChord>> typeToHiveChords = new HashMap<>(); for (ProgressionUnit progressionUnit : progressionUnits) { if (typeToHiveChords.get(progressionUnit.getType()) == null) { HiveChord[] fourBarChordList = new HiveChord[4]; HarmonicLoop loop = progressionUnit.getProgressionUnitBars().get(0).getHarmonicLoop(); List<HiveChord> chordsInBar = progressionUnit.getProgressionUnitBars().stream().map(pBar -> pBar.getChord()).filter(chord -> chord != null).collect(Collectors.toList()); List<HiveChord> compatibleChords = new ArrayList<>(); for (HiveChord chord : chordsInBar) { for (HiveChord loopChord : loop.getChords()) { if (chord.isEqualOrTriadMatch(loopChord)) { compatibleChords.add(chord); } } } for (Integer i = 0; i < progressionUnit.getProgressionUnitBars().size(); i++) { HiveChord currentChord = progressionUnit.getProgressionUnitBars().get(i).getChord(); if (i.equals(0) || compatibleChords.isEmpty()) { fourBarChordList[i] = currentChord; } else { fourBarChordList[i] = compatibleChords.get(new Random().nextInt(compatibleChords.size())); } } typeToHiveChords.put(progressionUnit.getType(), Arrays.asList(fourBarChordList)); } } return typeToHiveChords; }
ChordSelector implements IChordSelector { @Override public HashMap<ProgressionType, List<HiveChord>> selectChordsFrom4BarLoop(List<ProgressionUnit> progressionUnits) { HashMap<ProgressionType, List<HiveChord>> typeToHiveChords = new HashMap<>(); for (ProgressionUnit progressionUnit : progressionUnits) { if (typeToHiveChords.get(progressionUnit.getType()) == null) { HiveChord[] fourBarChordList = new HiveChord[4]; HarmonicLoop loop = progressionUnit.getProgressionUnitBars().get(0).getHarmonicLoop(); List<HiveChord> chordsInBar = progressionUnit.getProgressionUnitBars().stream().map(pBar -> pBar.getChord()).filter(chord -> chord != null).collect(Collectors.toList()); List<HiveChord> compatibleChords = new ArrayList<>(); for (HiveChord chord : chordsInBar) { for (HiveChord loopChord : loop.getChords()) { if (chord.isEqualOrTriadMatch(loopChord)) { compatibleChords.add(chord); } } } for (Integer i = 0; i < progressionUnit.getProgressionUnitBars().size(); i++) { HiveChord currentChord = progressionUnit.getProgressionUnitBars().get(i).getChord(); if (i.equals(0) || compatibleChords.isEmpty()) { fourBarChordList[i] = currentChord; } else { fourBarChordList[i] = compatibleChords.get(new Random().nextInt(compatibleChords.size())); } } typeToHiveChords.put(progressionUnit.getType(), Arrays.asList(fourBarChordList)); } } return typeToHiveChords; } }
ChordSelector implements IChordSelector { @Override public HashMap<ProgressionType, List<HiveChord>> selectChordsFrom4BarLoop(List<ProgressionUnit> progressionUnits) { HashMap<ProgressionType, List<HiveChord>> typeToHiveChords = new HashMap<>(); for (ProgressionUnit progressionUnit : progressionUnits) { if (typeToHiveChords.get(progressionUnit.getType()) == null) { HiveChord[] fourBarChordList = new HiveChord[4]; HarmonicLoop loop = progressionUnit.getProgressionUnitBars().get(0).getHarmonicLoop(); List<HiveChord> chordsInBar = progressionUnit.getProgressionUnitBars().stream().map(pBar -> pBar.getChord()).filter(chord -> chord != null).collect(Collectors.toList()); List<HiveChord> compatibleChords = new ArrayList<>(); for (HiveChord chord : chordsInBar) { for (HiveChord loopChord : loop.getChords()) { if (chord.isEqualOrTriadMatch(loopChord)) { compatibleChords.add(chord); } } } for (Integer i = 0; i < progressionUnit.getProgressionUnitBars().size(); i++) { HiveChord currentChord = progressionUnit.getProgressionUnitBars().get(i).getChord(); if (i.equals(0) || compatibleChords.isEmpty()) { fourBarChordList[i] = currentChord; } else { fourBarChordList[i] = compatibleChords.get(new Random().nextInt(compatibleChords.size())); } } typeToHiveChords.put(progressionUnit.getType(), Arrays.asList(fourBarChordList)); } } return typeToHiveChords; }  }
ChordSelector implements IChordSelector { @Override public HashMap<ProgressionType, List<HiveChord>> selectChordsFrom4BarLoop(List<ProgressionUnit> progressionUnits) { HashMap<ProgressionType, List<HiveChord>> typeToHiveChords = new HashMap<>(); for (ProgressionUnit progressionUnit : progressionUnits) { if (typeToHiveChords.get(progressionUnit.getType()) == null) { HiveChord[] fourBarChordList = new HiveChord[4]; HarmonicLoop loop = progressionUnit.getProgressionUnitBars().get(0).getHarmonicLoop(); List<HiveChord> chordsInBar = progressionUnit.getProgressionUnitBars().stream().map(pBar -> pBar.getChord()).filter(chord -> chord != null).collect(Collectors.toList()); List<HiveChord> compatibleChords = new ArrayList<>(); for (HiveChord chord : chordsInBar) { for (HiveChord loopChord : loop.getChords()) { if (chord.isEqualOrTriadMatch(loopChord)) { compatibleChords.add(chord); } } } for (Integer i = 0; i < progressionUnit.getProgressionUnitBars().size(); i++) { HiveChord currentChord = progressionUnit.getProgressionUnitBars().get(i).getChord(); if (i.equals(0) || compatibleChords.isEmpty()) { fourBarChordList[i] = currentChord; } else { fourBarChordList[i] = compatibleChords.get(new Random().nextInt(compatibleChords.size())); } } typeToHiveChords.put(progressionUnit.getType(), Arrays.asList(fourBarChordList)); } } return typeToHiveChords; }  HashMap<ProgressionType, HiveChord> selectFirstChordForType(List<ProgressionType> progressionTypes, List<HiveChord> hiveChordInDatabase); @Override HashMap<ProgressionType, List<HiveChord>> selectChordsFrom4BarLoop(List<ProgressionUnit> progressionUnits); HiveChord tempRandomChordSelect(List<HiveChord> getHiveChordInDatabase); HiveChord getChordTwoBarsPrior(HiveChord currentChord, List<HiveChord> hiveChordInDatabase); List<HiveChord> getChordCandidatesTwoBarsPrior(HiveChord currentChord, List<HiveChord> hiveChordInDatabase); HiveChord selectChordBetweenChords(HiveChord chordOne, HiveChord chordTwo, List<HiveChord> hiveChordInDatabase); @Override HiveChord selectChordBetweenChordsAndLoop(HiveChord chordOne, HiveChord chordTwo, HarmonicLoop harmonicLoop, List<HiveChord> hiveChordInDatabase); List<HiveChord> getChordCandidatesBetweenChords(HiveChord chordOne, HiveChord chordTwo, List<HiveChord> hiveChordInDatabase); @Override HiveChord selectMiddleChord(HarmonicLoop selectedLoop, HiveChord chordOneOfFour, HiveChord chordOneOfNextBar, List<HiveChord> hiveChordInDatabase); @Override HiveChord selectFourthChord(HarmonicLoop selectedLoop, HiveChord thirdChord, HiveChord nextChord, List<HiveChord> hiveChordInDatabase); }
ChordSelector implements IChordSelector { @Override public HashMap<ProgressionType, List<HiveChord>> selectChordsFrom4BarLoop(List<ProgressionUnit> progressionUnits) { HashMap<ProgressionType, List<HiveChord>> typeToHiveChords = new HashMap<>(); for (ProgressionUnit progressionUnit : progressionUnits) { if (typeToHiveChords.get(progressionUnit.getType()) == null) { HiveChord[] fourBarChordList = new HiveChord[4]; HarmonicLoop loop = progressionUnit.getProgressionUnitBars().get(0).getHarmonicLoop(); List<HiveChord> chordsInBar = progressionUnit.getProgressionUnitBars().stream().map(pBar -> pBar.getChord()).filter(chord -> chord != null).collect(Collectors.toList()); List<HiveChord> compatibleChords = new ArrayList<>(); for (HiveChord chord : chordsInBar) { for (HiveChord loopChord : loop.getChords()) { if (chord.isEqualOrTriadMatch(loopChord)) { compatibleChords.add(chord); } } } for (Integer i = 0; i < progressionUnit.getProgressionUnitBars().size(); i++) { HiveChord currentChord = progressionUnit.getProgressionUnitBars().get(i).getChord(); if (i.equals(0) || compatibleChords.isEmpty()) { fourBarChordList[i] = currentChord; } else { fourBarChordList[i] = compatibleChords.get(new Random().nextInt(compatibleChords.size())); } } typeToHiveChords.put(progressionUnit.getType(), Arrays.asList(fourBarChordList)); } } return typeToHiveChords; }  HashMap<ProgressionType, HiveChord> selectFirstChordForType(List<ProgressionType> progressionTypes, List<HiveChord> hiveChordInDatabase); @Override HashMap<ProgressionType, List<HiveChord>> selectChordsFrom4BarLoop(List<ProgressionUnit> progressionUnits); HiveChord tempRandomChordSelect(List<HiveChord> getHiveChordInDatabase); HiveChord getChordTwoBarsPrior(HiveChord currentChord, List<HiveChord> hiveChordInDatabase); List<HiveChord> getChordCandidatesTwoBarsPrior(HiveChord currentChord, List<HiveChord> hiveChordInDatabase); HiveChord selectChordBetweenChords(HiveChord chordOne, HiveChord chordTwo, List<HiveChord> hiveChordInDatabase); @Override HiveChord selectChordBetweenChordsAndLoop(HiveChord chordOne, HiveChord chordTwo, HarmonicLoop harmonicLoop, List<HiveChord> hiveChordInDatabase); List<HiveChord> getChordCandidatesBetweenChords(HiveChord chordOne, HiveChord chordTwo, List<HiveChord> hiveChordInDatabase); @Override HiveChord selectMiddleChord(HarmonicLoop selectedLoop, HiveChord chordOneOfFour, HiveChord chordOneOfNextBar, List<HiveChord> hiveChordInDatabase); @Override HiveChord selectFourthChord(HarmonicLoop selectedLoop, HiveChord thirdChord, HiveChord nextChord, List<HiveChord> hiveChordInDatabase);  }