Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. public Song transposeSong(){
  2. //this method creates a temporary song based on the chordpro format of the selected song except transposing the chords
  3. // by the specified amount and then returns the transposed song
  4. ArrayList<String> transposedChordProLines = new ArrayList<String>();
  5. boolean atChord = false;
  6. boolean skipChar = false;
  7. String keysSharp[] = {"A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"}; //arrays to store all 12 keys
  8. String keysFlat[] = {"A", "Bb", "B", "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab"};
  9. for(int i = 0; i < chordProLines.size(); i++){
  10. String transposedLine = "";
  11. for(int j = 0; j < chordProLines.get(i).length(); j++){
  12. if (skipChar == true){
  13. skipChar = false;
  14. }
  15. else if(chordProLines.get(i).charAt(j) == '['){
  16. atChord = true;
  17. transposedLine += chordProLines.get(i).charAt(j);
  18. }
  19. else if(chordProLines.get(i).charAt(j) == ']'){
  20. atChord = false;
  21. transposedLine += chordProLines.get(i).charAt(j);
  22. }
  23. else if(atChord == true){
  24. if(chordProLines.get(i).charAt(j) == 'A' || chordProLines.get(i).charAt(j) == 'B' || chordProLines.get(i).charAt(j) == 'C' || chordProLines.get(i).charAt(j) == 'D' || chordProLines.get(i).charAt(j) == 'E' || chordProLines.get(i).charAt(j) == 'F' || chordProLines.get(i).charAt(j) == 'G'){
  25. String currentKey = Character.toString(chordProLines.get(i).charAt(j));
  26. if(chordProLines.get(i).charAt(j+1) == 'b' || chordProLines.get(i).charAt(j+1) == '#'){
  27. currentKey += Character.toString(chordProLines.get(i).charAt(j+1));
  28. }
  29. for(int k = 0; k < 12; k++){
  30. if(currentKey.equals(keysSharp[k])){
  31. transposedLine += keysSharp[(k + transpositionIndex) % 12];
  32. if(currentKey.length() > 1){
  33. skipChar = true;
  34. }
  35. break;
  36. }
  37. else if(currentKey.equals(keysFlat[k])){
  38. transposedLine += keysFlat[(k + transpositionIndex) % 12];
  39. if(currentKey.length() > 1){
  40. skipChar = true;
  41. }
  42. break;
  43. }
  44. }
  45. }
  46. else{
  47. transposedLine += chordProLines.get(i).charAt(j);
  48. }
  49. }
  50. else {
  51. transposedLine += chordProLines.get(i).charAt(j);
  52. }
  53. }
  54. transposedChordProLines.add(transposedLine);
  55. }
  56. Song transposedSong = new Song(getSongTitle(), transposedChordProLines);
  57. //transposedSong.printToConsole();
  58. return transposedSong;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement