package yakimusic.sound;
import java.util.HashMap;
import org.jfugue.Pattern;
import org.jfugue.Player;
import org.jfugue.Rhythm;
public class YMLRhythm {
private static final char[] chars = new char[] { 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q' };
private int layer = 0;
private Rhythm rhythm;
public YMLRhythm() {
rhythm = new Rhythm();
}
public static YMLRhythm getDefault(String s){
YMLRhythm r = null;
if(s.equals("hip-hop")){
r = YMLRhythm.genRapRhythm('s');
}else if(s.equals("house")){
r = YMLRhythm.genHouseRhythm('s');
}else if(s.equals("ska")){
r = YMLRhythm.genSkaRhythm('s');
}else if(s.equals("pop")){
/*falta el pop*/
}
return r;
}
public void addRhythmTrack(String instrument, String rhythmString, char duration) {
String instrumID = YMLInstrument.getInstrumentRealName(instrument);
char caracter = chars[layer];
String aux = rhythmString.replace("*", caracter + "");
rhythm.setLayer(layer, aux);
rhythm.addSubstitution('.', "R" + duration);
rhythm.addSubstitution(caracter, "[" + instrumID + "]" + duration);
layer++;
}
public void addRhythmTrack(String instrument, String rhythmString) {
int vol = 3; //Volumen del ritmo
for(int i=0; i < vol; i++){
addRhythmTrack(instrument, rhythmString, 'q');
//addRhythmTrack(instrument, rhythmString, 'w');
}
}
public Pattern getRhythmPattern(){
return rhythm.getPattern();
}
public void testPlay(final int times){
Thread hilo = new Thread() {
@Override
public void run() {
Pattern pattern = getRhythmPattern();
pattern.repeat(times);
Player player = new Player();
player.play(pattern);
}
};
hilo.start();
}
public static YMLRhythm genRapRhythm(char duration){
YMLRhythm rhythm = new YMLRhythm();
rhythm.addRhythmTrack("BASS-DRUM", "*.....*.....*.....*..*..*.....*.....*...........", duration);
rhythm.addRhythmTrack("ACOUSTIC-SNARE", "............*.......................*...........", duration);
rhythm.addRhythmTrack("CLOSED_HI_HAT", "*...........*...........*...........*.....*.....", duration);
rhythm.addRhythmTrack("OPEN_HI_HAT", "..........................................*.....", duration);
return rhythm;
}
public static YMLRhythm genHouseRhythm(char duration){
YMLRhythm rhythm = new YMLRhythm();
rhythm.addRhythmTrack("BASS-DRUM", "*...........*...........*...........*...........", duration);
rhythm.addRhythmTrack("HIHAT-OPEN", "............*.......................*...........", duration);
rhythm.addRhythmTrack("HIHAT-CLOSED", "......*...........*...........*...........*.....", duration);
return rhythm;
}
public static YMLRhythm genSkaRhythm(char duration){
YMLRhythm rhythm = new YMLRhythm();
rhythm.addRhythmTrack("BASS-DRUM", "*.......................*.......................", duration);
rhythm.addRhythmTrack("HIHAT-CLOSED", "......*...........*...........*...........*.....", duration);
rhythm.addRhythmTrack("ACOUSTIC-SNARE", "............*.......................*...........", duration);
return rhythm;
}
}