JFugue笔记更改无法正常工作 [英] JFugue note changing not working properly
问题描述
我正在尝试移调音符,但是它返回的结果不是应该的.您能检查我的代码并告诉我哪里错了吗?
I'm trying to transpose a note, but the result it returns is not what it should be. Could you please check my code and tell me where I am wrong?
public int changeTone(String chord) {
int changeTone = 0;
switch(chord) {
case "I":
changeTone = 0;
break;
case "II":
changeTone = 1;
break;
case "III":
changeTone = 2;
break;
case "IV":
changeTone = 3;
break;
case "V":
changeTone = 4;
break;
case "VI":
changeTone = 5;
break;
case "VII":
changeTone = 6;
break;
case "i":
changeTone = 0;
break;
case "ii":
changeTone = 2;
break;
case "iii":
changeTone = 4;
break;
case "iv":
changeTone = 5;
break;
case "v":
canviDeTo = 7;
break;
case "vi":
changeTone = 9;
break;
case "vii":
changeTone = 11;
break;
default:
System.out.println("Vaya");
break;
}
return changeTone ;
}
public String getChord(int interval) {
String chord = "";
switch(interval) {
case "0":
chord = "C";
break;
case "2":
chord = "D";
break;
case "4":
chord = "E";
break;
case "5":
chord = "F";
break;
case "7":
chord = "G";
break;
case "9":
chord = "A";
break;
case "11":
chord = "B";
}
return chord;
}
public String WriteChord(String chords, String tone) {
String finalChord;
String[] chordArray = chords.split("-");
for(int i=0; i < chordArray.length; i++){
String chord = chordArray[i];
int interval = changeTone(chord);
chord = getChord(interval);
Note note = new Note(chord);
finalChord += note.changeValue(interval).toString() += "-";
}
return finalChord;
}
好,因此,这样做的尝试是在给定间隔的和弦进行过程中更改和弦的值.像I-III-IV-iv.用户可以选择一个音调(音调,我注意),并以该音符为参考来更改和弦.因此,例如,运行代码应执行以下操作:
OK, so what this tries to do is to change the value of a chord given a chord progession with intervals. Like I-III-IV-iv. The user would choose a tone (the tonical, I note) and the chord would be changed taking the note as a reference. So, for example, running the code should do the following:
- 用户选择一个音调,说"E".
- 代码生成和弦进行过程,例如"I-III-IV-iv".
- 代码获取I和III,I和IV以及I和iv之间的间隔.
- 初始音符"E"随时间间隔更改其值.
预期输出为: E-G#-A#-A# 实际输出为: C-G#-G#-Bb
The expected output is: E-G#-A#-A# The actual output is: C-G#-G#-Bb
为什么这行不通?我简化了我的代码,所以如果您需要更多信息,请告诉我!预先感谢.
Why doesn't this work? I have simplified my code, so if you need a bit more let me know! Thanks in advance.
我已经更正了代码,并添加了预期的/得到的输出.
I have corrected the code and added the expected/gotten output.
推荐答案
JFugue已经支持音程和和弦进行.我希望以下代码能够满足您的需求:
JFugue already has support for intervals and chord progressions. I hope the following code satisfies your needs:
import org.jfugue.theory.ChordProgression;
public static void main(String[] args) {
ChordProgression cp = new ChordProgression("I-III-IV-iv").setKey("E");
System.out.println(cp);
}
此代码的输出为:
E4MAJ G#4MAJ A4MAJ A4MIN
您可以在播放器中直接播放
You can play this directly in a Player:
Player player = new Player(); // Don't forget to import org.jfugue.player.Player
player.play(cp);
如果由于默认的四分音符持续时间而使您演奏的速度过快,则可以将每个和弦演奏的时间更长一些,例如说整个音符:
If that's playing a little too fast for you because of the default duration of a quarter note, you can play each chord as something longer, say a whole note:
player.play(cp.eachChordAs("$!w"));
如果您只想要[E,G#,A,A]的根,(如果您发现我的音乐理论有误,请告诉我),您可以使用:
If you just want the roots, which in this case are [E, G#, A, A] (if you see an error with my music theory, please let me know), you can use:
cp.eachChordAs("$0");
http://www.jfugue.org/examples.html
这篇关于JFugue笔记更改无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!