Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Song transposeSong(){
- //this method creates a temporary song based on the chordpro format of the selected song except transposing the chords
- // by the specified amount and then returns the transposed song
- ArrayList<String> transposedChordProLines = new ArrayList<String>();
- boolean atChord = false;
- boolean skipChar = false;
- String keysSharp[] = {"A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"}; //arrays to store all 12 keys
- String keysFlat[] = {"A", "Bb", "B", "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab"};
- for(int i = 0; i < chordProLines.size(); i++){
- String transposedLine = "";
- for(int j = 0; j < chordProLines.get(i).length(); j++){
- if (skipChar == true){
- skipChar = false;
- }
- else if(chordProLines.get(i).charAt(j) == '['){
- atChord = true;
- transposedLine += chordProLines.get(i).charAt(j);
- }
- else if(chordProLines.get(i).charAt(j) == ']'){
- atChord = false;
- transposedLine += chordProLines.get(i).charAt(j);
- }
- else if(atChord == true){
- 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'){
- String currentKey = Character.toString(chordProLines.get(i).charAt(j));
- if(chordProLines.get(i).charAt(j+1) == 'b' || chordProLines.get(i).charAt(j+1) == '#'){
- currentKey += Character.toString(chordProLines.get(i).charAt(j+1));
- }
- for(int k = 0; k < 12; k++){
- if(currentKey.equals(keysSharp[k])){
- transposedLine += keysSharp[(k + transpositionIndex) % 12];
- if(currentKey.length() > 1){
- skipChar = true;
- }
- break;
- }
- else if(currentKey.equals(keysFlat[k])){
- transposedLine += keysFlat[(k + transpositionIndex) % 12];
- if(currentKey.length() > 1){
- skipChar = true;
- }
- break;
- }
- }
- }
- else{
- transposedLine += chordProLines.get(i).charAt(j);
- }
- }
- else {
- transposedLine += chordProLines.get(i).charAt(j);
- }
- }
- transposedChordProLines.add(transposedLine);
- }
- Song transposedSong = new Song(getSongTitle(), transposedChordProLines);
- //transposedSong.printToConsole();
- return transposedSong;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement