diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9867e87..24108a9 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,12 +1,14 @@ - + + + @@ -18,11 +20,12 @@ + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -288,7 +309,7 @@ - + @@ -406,8 +427,8 @@ - - + + @@ -459,17 +480,23 @@ - - file://$PROJECT_DIR$/src/Composition/Crossover.kt - 27 + + file://$PROJECT_DIR$/src/Utils/Rest.java + 24 + + + + file://$PROJECT_DIR$/src/Main.java + 200 - - - file://$PROJECT_DIR$/src/Utils/Splitter.kt - 60 + + file://$PROJECT_DIR$/src/Utils/Conversor.java + 43 - @@ -511,6 +538,7 @@ + @@ -540,9 +568,6 @@ - - - @@ -553,82 +578,97 @@ - + - - + + - + - + - + - - + + - + - - + + - - - - + - - + + - - + + + + + + + + + - - - - - + + - + - - + + + + + + + + + - + - + + + + + + + + - - + + - - + + diff --git a/out/production/comp_music_alg/Utils/StaffInsertionKt.class b/out/production/comp_music_alg/Utils/StaffInsertionKt.class new file mode 100644 index 0000000..9cfaf3e Binary files /dev/null and b/out/production/comp_music_alg/Utils/StaffInsertionKt.class differ diff --git a/out/production/comp_music_alg/Utils/SymbolKt.class b/out/production/comp_music_alg/Utils/SymbolKt.class new file mode 100644 index 0000000..1555216 Binary files /dev/null and b/out/production/comp_music_alg/Utils/SymbolKt.class differ diff --git a/src/Main.java b/src/Main.java index debb08c..cb358c5 100644 --- a/src/Main.java +++ b/src/Main.java @@ -16,16 +16,18 @@ import static Composition.Ostinato.*; import static Utils.Conversor.*; import static Utils.Rest.*; -import static Utils.SplitterKt.splitDuration; +import static Utils.SplitterKt.splitDuration; +import static Utils.StaffInsertionKt.staffInsertion; +import static Utils.SymbolKt.insertSlur; public class Main { + private static Staff expanderAsStaff; + public static void main(String[] args) { /** - * * GENERATE .LY */ - PrintStream out = null; try { out = new PrintStream(new FileOutputStream("output.ly")); @@ -33,13 +35,11 @@ public static void main(String[] args) { e.printStackTrace(); } System.setOut(out); - + /** * START WRITE */ GenerateHeader(); - - GenerateExtendedNotes1(); GenerateGrupetos(); /** @@ -54,6 +54,7 @@ public static void main(String[] args) { } String[] finalConversion = LilypondConversor(notes); + expanderAsStaff = StaffConversor(notes); System.out.println("partONE = { "); @@ -112,6 +113,7 @@ public static void main(String[] args) { System.out.println("}"); + GenerateExtendedNotes1(); GenerateBody(); GenerateFooter(); @@ -150,73 +152,105 @@ private static void GenerateBody() { System.out.println("\t\t\\new StaffGroup"); System.out.println("\t\t\t<<"); - // Cello 1 - System.out.println("\t\t\t\\new Staff = \"CelloOne\" {"); - System.out.println("\t\t\t\t\\set Staff.instrumentName = #\"Cello 1\""); - // INSERT NOTES - System.out.println("\t\t\t\t\\clef bass"); - System.out.println("\t\t\t\t\\extendedNotesONE"); - System.out.println("\t\t\t}"); - - // Cello 2 - System.out.println("\t\t\t\\new Staff = \"CelloTwo\" {"); - System.out.println("\t\t\t\t\\set Staff.instrumentName = #\"Cello 2\""); - // INSERT NOTES - System.out.println("\t\t\t\t\\clef bass"); - System.out.println("\t\t\t\t\\extendedNotesTWO"); - System.out.println("\t\t\t}"); - - //Cello 3 - System.out.println("\t\t\t\\new Staff = \"CelloThree\" {"); - System.out.println("\t\t\t\t\\set Staff.instrumentName = #\"Cello 3\""); - // INSERT NOTES - System.out.println("\t\t\t\t\\clef bass"); - System.out.println("\t\t\t\t\\extendedNotesTHREE"); - System.out.println("\t\t\t}"); - - //Cello 4 - System.out.println("\t\t\t\\new Staff = \"CelloFour\" {"); - System.out.println("\t\t\t\t\\set Staff.instrumentName = #\"Cello 4\""); - // INSERT NOTES - System.out.println("\t\t\t\t\\clef bass"); - System.out.println("\t\t\t\t\\extendedNotesFOUR"); - System.out.println("\t\t\t}"); + // Cello 1 + System.out.println("\t\t\t\\new Staff = \"CelloOne\" {"); + System.out.println("\t\t\t\t\\set Staff.instrumentName = #\"Cello 1\""); + // INSERT NOTES + System.out.println("\t\t\t\t\\clef bass"); + System.out.println("\t\t\t\t\\extendedNotesONE"); + System.out.println("\t\t\t}"); + + // Cello 2 + System.out.println("\t\t\t\\new Staff = \"CelloTwo\" {"); + System.out.println("\t\t\t\t\\set Staff.instrumentName = #\"Cello 2\""); + // INSERT NOTES + System.out.println("\t\t\t\t\\clef bass"); + System.out.println("\t\t\t\t\\extendedNotesTWO"); + System.out.println("\t\t\t}"); + + //Cello 3 + System.out.println("\t\t\t\\new Staff = \"CelloThree\" {"); + System.out.println("\t\t\t\t\\set Staff.instrumentName = #\"Cello 3\""); + // INSERT NOTES + System.out.println("\t\t\t\t\\clef bass"); + System.out.println("\t\t\t\t\\extendedNotesTHREE"); + System.out.println("\t\t\t}"); + + //Cello 4 + System.out.println("\t\t\t\\new Staff = \"CelloFour\" {"); + System.out.println("\t\t\t\t\\set Staff.instrumentName = #\"Cello 4\""); + // INSERT NOTES + System.out.println("\t\t\t\t\\clef bass"); + System.out.println("\t\t\t\t\\extendedNotesFOUR"); + System.out.println("\t\t\t}"); System.out.println("\t\t\t>>"); System.out.println("\t\t>>"); System.out.println("\t}"); } + private static void GenerateExtendedNotes1() { + + Staff begin1 = expanderAsStaff; + Staff restForStaffs = RestGeneratorForStaff(expanderAsStaff); + List listOfNotes = Arrays.asList("a","b", "cis", "g", "gis"); List extendedNotes = extendNotes(55, 4, listOfNotes); - Result cello1 = splitDuration(extendedNotes.get(0)); - Result cello2 = splitDuration(extendedNotes.get(1)); - Result cello3 = splitDuration(extendedNotes.get(2)); - Result cello4 = splitDuration(extendedNotes.get(3)); + Staff cello1Line = staffInsertion(begin1, extendedNotes.get(0)); + Staff cello2Line = staffInsertion(restForStaffs, extendedNotes.get(1)); + Staff cello3Line = staffInsertion(restForStaffs, extendedNotes.get(2)); + Staff cello4Line = staffInsertion(restForStaffs, extendedNotes.get(3)); + + Result cello1 = splitDuration(cello1Line); + Result cello2 = splitDuration(cello2Line); + Result cello3 = splitDuration(cello3Line); + Result cello4 = splitDuration(cello4Line); + + Staff cello1WithSlur = insertSlur(cello1.getStaff()); + Staff cello2WithSlur = insertSlur(cello2.getStaff()); + Staff cello3WithSlur = insertSlur(cello3.getStaff()); + Staff cello4WithSlur = insertSlur(cello4.getStaff()); System.out.println("extendedNotesONE = { "); for (int i = 0 ; i < cello1.getStaff().getNote().size() ; i++) { - System.out.print(cello1.getStaff().getNote().get(i) + cello1.getStaff().getDuration().get(i).getLilypondDuration() + " "); + System.out.print( + cello1.getStaff().getNote().get(i) + + cello1.getStaff().getDuration().get(i).getLilypondDuration() + + cello1WithSlur.getSymbol().get(i) + " " + + ); } System.out.println("}"); System.out.println("extendedNotesTWO = { "); for (int i = 0 ; i < cello2.getStaff().getNote().size() ; i++) { - System.out.print(cello2.getStaff().getNote().get(i) + cello2.getStaff().getDuration().get(i).getLilypondDuration() + " "); + System.out.print( + cello2.getStaff().getNote().get(i) + + cello2.getStaff().getDuration().get(i).getLilypondDuration() + + cello2WithSlur.getSymbol().get(i) + " " + ); } System.out.println("}"); System.out.println("extendedNotesTHREE = { "); for (int i = 0 ; i < cello3.getStaff().getNote().size() ; i++) { - System.out.print(cello3.getStaff().getNote().get(i) + cello3.getStaff().getDuration().get(i).getLilypondDuration() + " "); + System.out.print( + cello3.getStaff().getNote().get(i) + + cello3.getStaff().getDuration().get(i).getLilypondDuration() + + cello3WithSlur.getSymbol().get(i) + " " + ); } System.out.println("}"); System.out.println("extendedNotesFOUR = { "); for (int i = 0 ; i < cello4.getStaff().getNote().size() ; i++) { - System.out.print(cello4.getStaff().getNote().get(i) + cello4.getStaff().getDuration().get(i).getLilypondDuration() + " "); + System.out.print( + cello4.getStaff().getNote().get(i) + + cello4.getStaff().getDuration().get(i).getLilypondDuration() + + cello4WithSlur.getSymbol().get(i) + " " + ); } System.out.println("}"); @@ -280,27 +314,44 @@ private static void GenerateCrossOver(Staff one, Staff two, Staff three, Staff f Result crossover3 = SimpleCrossover(three, four); Result crossover4 = SimpleCrossover(four, one); + Staff cross1WithSlur = insertSlur(crossover1.getStaff()); + Staff cross2WithSlur = insertSlur(crossover2.getStaff()); + Staff cross3WithSlur = insertSlur(crossover3.getStaff()); + Staff cross4WithSlur = insertSlur(crossover4.getStaff()); + System.out.println("crossoverONE = { "); for (int i = 0 ; i < crossover1.getStaff().getNote().size() ; i++) { - System.out.print(crossover1.getStaff().getNote().get(i) + crossover1.getStaff().getDuration().get(i).getLilypondDuration() + " "); + System.out.print(crossover1.getStaff().getNote().get(i) + + crossover1.getStaff().getDuration().get(i).getLilypondDuration() + + cross1WithSlur.getSymbol().get(i) + " " + ); } System.out.println("}"); System.out.println("crossoverTWO = { "); for (int i = 0 ; i < crossover2.getStaff().getNote().size() ; i++) { - System.out.print(crossover2.getStaff().getNote().get(i) + crossover2.getStaff().getDuration().get(i).getLilypondDuration() + " "); + System.out.print(crossover2.getStaff().getNote().get(i) + + crossover2.getStaff().getDuration().get(i).getLilypondDuration() + + cross2WithSlur.getSymbol().get(i) + " " + ); } System.out.println("}"); System.out.println("crossoverTHREE = { "); for (int i = 0 ; i < crossover3.getStaff().getNote().size() ; i++) { - System.out.print(crossover3.getStaff().getNote().get(i) + crossover3.getStaff().getDuration().get(i).getLilypondDuration() + " "); + System.out.print(crossover3.getStaff().getNote().get(i) + + crossover3.getStaff().getDuration().get(i).getLilypondDuration() + + cross3WithSlur.getSymbol().get(i) + " " + ); } System.out.println("}"); System.out.println("crossoverFOUR = { "); for (int i = 0 ; i < crossover4.getStaff().getNote().size() ; i++) { - System.out.print(crossover4.getStaff().getNote().get(i) + crossover4.getStaff().getDuration().get(i).getLilypondDuration() + " "); + System.out.print(crossover4.getStaff().getNote().get(i) + + crossover4.getStaff().getDuration().get(i).getLilypondDuration() + + cross4WithSlur.getSymbol().get(i) + " " + ); } System.out.println("}"); diff --git a/src/Utils/Conversor.java b/src/Utils/Conversor.java index 5783d62..81db2ac 100644 --- a/src/Utils/Conversor.java +++ b/src/Utils/Conversor.java @@ -1,5 +1,7 @@ package Utils; +import Composition.Staff; +import Finals.NoteDuration; import Objects.Note; public class Conversor { @@ -28,6 +30,20 @@ public static String[] LilypondConversor(Note[] notes) { return output; } + public static Staff StaffConversor(Note[] notes) { + Staff output = new Staff(); + + for (int i = 0 ; i < notes.length ; i++) { + String note = convertToPitch(notes[i].getPitchClass()) + convertToLilypondOctave( notes[i].getOctave()); + output.component1().add(i, note); + NoteDuration duration = new NoteDuration(notes[i].getDuration(), String.valueOf(notes[i].getDuration())); + output.component2().add(i,duration); + output.component3().add(i, ""); + } + + return output; + } + public static String[] LilypondConversorWithRandomRest(Note[] notes, int randomLevel) { String[] output = new String[notes.length]; @@ -141,4 +157,35 @@ private static String convertToDuration(int octave, int duration) { } return output; } + + private static String convertToLilypondOctave(int octave) { + String output; + switch (octave) { + case 0: + output = ",,,"; + break; + case 1: + output = ",,"; + break; + case 2: + output = ","; + break; + case 3: + output = ""; + break; + case 4: + output = "'"; + break; + case 5: + output = "''"; + break; + case 6: + output = "'''"; + break; + default: + output = ""; + break; + } + return output; + } } diff --git a/src/Utils/Rest.java b/src/Utils/Rest.java index eac84d6..90aa978 100644 --- a/src/Utils/Rest.java +++ b/src/Utils/Rest.java @@ -1,5 +1,7 @@ package Utils; +import Composition.Staff; + public class Rest { public static String[] RestGenerator(int[] rhythm, int size, int beginAt) { @@ -10,4 +12,16 @@ public static String[] RestGenerator(int[] rhythm, int size, int beginAt) { } return restList; } + + public static Staff RestGeneratorForStaff(Staff baseStaff) { + Staff output = new Staff(); + + for (int i = 0 ; i < baseStaff.getDuration().size() ; i++) { + output.component1().add(i, "r"); + output.component2().add(i, baseStaff.getDuration().get(i)); + output.component3().add(i, baseStaff.getSymbol().get(i)); + } + + return output; + } } \ No newline at end of file diff --git a/src/Utils/StaffInsertion.kt b/src/Utils/StaffInsertion.kt new file mode 100644 index 0000000..196718d --- /dev/null +++ b/src/Utils/StaffInsertion.kt @@ -0,0 +1,25 @@ +package Utils + +import Composition.Staff + +fun Staff.insertStaff(newStaff: Staff) : Staff { + note.addAll(newStaff.note) + duration.addAll(newStaff.duration) + symbol.addAll(newStaff.symbol) + return this +} + +fun staffInsertion(first: Staff, second: Staff) : Staff { + var output = Staff() + + output.note.addAll(first.note) + output.note.addAll(second.note) + + output.duration.addAll(first.duration) + output.duration.addAll(second.duration) + + output.symbol.addAll(first.symbol) + output.symbol.addAll(second.symbol) + + return output +} \ No newline at end of file diff --git a/src/Utils/Symbol.kt b/src/Utils/Symbol.kt new file mode 100644 index 0000000..18bb0e8 --- /dev/null +++ b/src/Utils/Symbol.kt @@ -0,0 +1,14 @@ +package Utils + +import Composition.Staff + +fun insertSlur(staff: Staff): Staff { + + for (index in 0..(staff.symbol.size-1)) { + if (index+1 > staff.symbol.size-1) { continue } + if (staff.note[index] == staff.note[index + 1]) { + staff.symbol.set(index, "~") + } + } + return staff +} \ No newline at end of file