Bonjour,
J'essaye actuellement de réaliser un éditeur de partitions comme projet de cours. Le changement de piste et d'instruments ainsi que l'enregistrement de chaque note fonctionne parfaitement, cependant j'ai un problème à la lecture du son, où chaque note se joue en même temps.
Voici une version simplifiée du code sans pistes et sans instruments :
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
SmartPoint smartPoint;
//changement de piste
Btn track1;
Btn track2;
ArrayList<AudioPlayer> piste1 = new ArrayList<AudioPlayer>();
int total_piste1 = piste1.size();
//notes
Btn a1;
Btn a2;
//bouton de lecture d'une piste
Btn lecture;
//création de chaque note
AudioPlayer grandpiano_A1;
AudioPlayer grandpiano_A2;
int piste;
void setup() {
size(600, 400);
minim = new Minim(this);
smartPoint = new SmartPoint();
track1 = new Btn(50, 10, 40, 40);
track2 = new Btn(120, 10, 40, 40);
a1 = new Btn((width-50), 10, 40, 40); //décalé de 50 sur la droite, et de 10 sur le haut
a2 = new Btn((width-120), 10, 40, 40);
lecture = new Btn((width-50), 80, 40, 40);
grandpiano_A1 = minim.loadFile("grand_piano/gp_A1.wav");
grandpiano_A2 = minim.loadFile("grand_piano/gp_A2.wav");
}
void draw() {
background(255);
smartPoint.update();
// btn.update();
lecture.display();
track1.display();
track2.display();
a1.display();
a2.display();
smartPoint.display();
if (smartPoint.hitTarget(a1)) {
if (grandpiano_A1.isPlaying() == false) {
grandpiano_A1.loop(0); //joue le son une fois.
piste1.add(grandpiano_A1);
println(piste1.size() + " A1"); //enregistre le son joué dans la case correspondante du tableau
}
}
if (smartPoint.hitTarget(a2)) {
if (grandpiano_A2.isPlaying() == false) {
piste1.add(grandpiano_A2);
grandpiano_A2.loop(0); //joue le son une fois.
println(piste1.size() + " A2"); //enregistre le son joué dans la case correspondante du tableau
}
}
if (smartPoint.hitTarget(track2)) {
piste = 2;
}
}
void mousePressed() {
if (smartPoint.hitTarget(lecture)) {
for (int i = 0; i < piste1.size (); i++) {
AudioPlayer PlayingNote = piste1.get(i);
if (PlayingNote.isPlaying() == false) {
PlayingNote.loop(0);
}
println(i);
}
}
}
void stop() {
grandpiano_A1.close();
grandpiano_A2.close();
minim.stop();
super.stop();
}
class Btn {
PVector location;
/** int width, height; //dame yo dame **/
int myWidth, myHeight;
color couleur;
Btn(float _x, float _y, int _myWidth, int _myHeight) {
location = new PVector(_x, _y);
myWidth = _myWidth;
myHeight = _myHeight;
couleur = color(255);
}
void display() {
fill(couleur);
stroke(0);
rect(location.x, location.y, myWidth, myHeight);
}
}
class SmartPoint {
PVector position;
SmartPoint() {
position = new PVector();
}
void display() {
noStroke();
fill(255, 0, 0);
ellipse(position.x, position.y, 5, 5);
}
void update() {
position.x = mouseX;
position.y = mouseY;
}
boolean hitTarget(Btn arg1) {
if ((this.position.x >= arg1.location.x) && (this.position.y >= arg1.location.y) && (this.position.x <= (arg1.location.x + arg1.myWidth)) && (this.position.y <= (arg1.location.y + arg1.myHeight))){
return(true);
} else {
return(false);
}
}
}
Hors ligne
Bonjour, c'est à priori un projet ambitieux, tant mieux. Mais pour pouvoir t'aider et débusquer le problème le mieux est que tu joignes une archive .zip de ton projet avec les fichiers audio.
Hors ligne
Voici l'archive du corps de mon projet.
Hors ligne