1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.effect.Reflection;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Rectangle;
import org.springframework.context.ApplicationContext;
/**
*
* @author fnac
*/
public class Clavier extends Parent{
private String[] notes = {"Do", "Ré", "Mi", "Fa", "Sol", "La", "Si", "Do"};
private int[] sons = {60, 62, 64, 65, 67, 69, 71, 72};
private Touche[] touches = new Touche[8];
private String[] raccourcis = {"A", "Z", "E", "R", "T", "Y", "U", "I"};
private SoundPlayer sound;
private Volume vol;
private Metronome metr;
private ApplicationContext appCtx;
public Clavier(SoundPlayer sound, Metronome metr){
this.sound = sound;
this.metr = metr;
Rectangle arriereClavier = new Rectangle(480, 200, Color.BLACK);
arriereClavier.setArcHeight(30);
arriereClavier.setArcWidth(30);
arriereClavier.setFill( // ajout d'un dégradé
new LinearGradient(0f, 0f, 0f, 1f, true, CycleMethod.NO_CYCLE,
new Stop[] {
new Stop(0, Color.web("#333333")),
new Stop(1, Color.web("#000000"))
}
)
);
Reflection reflect = new Reflection(1, 0.25, 0, 0.5);// application d'un effet de réflection
arriereClavier.setEffect(reflect);
this.setTranslateX(10);
this.setTranslateY(250);
this.getChildren().add(arriereClavier);
Touche touche = appCtx.getBean("touch", Touche.class);
int var = -5;
int dep = (int)(arriereClavier.getWidth() - (8 * (touche.getLarg() + 5))) / 2;
for (int i = 0; i < 8; i++){
touches[i] = new Touche(notes[i], i * (touche.getLarg() + 5) + dep, 100 + var, sons[i], raccourcis[i], sound, metr);
this.getChildren().add(touches[i]);
var = - var;
}
this.setOnKeyPressed(new EventHandler<KeyEvent>(){
public void handle(KeyEvent ke) {
if (ke.getCode().equals(KeyCode.UP)) {
changeVolume(true);
}
if (ke.getCode().equals(KeyCode.DOWN)) {
changeVolume(false);
}
for (Touche t : touches){
if (t.getRaccourci().toUpperCase().equals(ke.getText().toUpperCase())){
t.appui();
break;
}
}
}
});
this.setOnKeyReleased(new EventHandler<KeyEvent>(){
public void handle(KeyEvent ke) {
for (Touche t : touches){
if (t.getRaccourci().toUpperCase().equals(ke.getText().toUpperCase())){
t.relachement();
break;
}
}
}
});
};
public void setVol(Volume vol){
this.vol = vol;
}
public void changeVolume(boolean up){
if (up) {
this.vol.slider.setValue(this.vol.slider.getValue() + 5);
}
else {
this.vol.slider.setValue(this.vol.slider.getValue() - 5);
}
}
public SoundPlayer getSound() {
return sound;
}
public void setSound(SoundPlayer sound) {
this.sound = sound;
}
public Metronome getMetr() {
return metr;
}
public void setMetr(Metronome metr) {
this.metr = metr;
}
} |