// Corpus21P2js.pde // Modif par rapport a Corpus21P2.pde = suppression de: // selectInput("select the XML File (format Praat textGrid):", "fileSelected"); // ... // Essai avec Safari, Firefox, Opera, Chrome sous MacOSX.6 // aucun ne fonctionne! // Seul Firefox affiche une fenetre Orange, donc un debut d'execution, et le message d'erreur: // Ouverture de: reunion.xml // Le fichier xml n'a pas le bon format 2 // xml1.listChildren()[1] = undefined // Probleme = true exit // Gerard Paresys // 17 7 2014 // Processing 2.0.3 // // Utilise la library minim incluse dans Processing 2 // http://code.compartmental.net/minim/ // // Si le dossier data contient 4 fichiers nommés: // XXX.xml (format Praat TextGrid sauve en UTF8) // XXX.mp3 // XXX_Pitch.txt // XXX_Intensity.txt // le sketch les ouvre // sinon un selecteur de fichiers s'ouvre // // Modifier la ligne 37 au besoin // // Le dossier data doit contenir aussi: // Georgia.ttf // // Touche S Sauve l'ecran (format png) // Touche Espace Pause // Clic souris dans la fenêtre d'abord // Ouvre le fichier XXX.xml // Ouvre et joue le fichier Audio XXX.mp3 // Ouvre le fichier texte XXX_Pitch.txtt généré par Praat // Ouvre le fichier texte XXX_Intensity.txt généré par Praat // Dessine les courbes Pitch et Intensity synchronisées avec l'Audio // Chronomètre... // import ddf.minim.*; // pour AudioPlayer import java.util.Calendar; // Processing 2.0 String NomFichierXML = "reunion.xml"; // les fichiers "reunion..." doivent etre dans le dossier data // sinon le selecteur de fichier s'ouvre color Couleur = color(250, 100, 0); // ornge boolean Verbose = false; boolean Maille = true; PFont maFonte; String NomFichierAudio = "XXX.mp3"; String NomFichierPitch = "XXX_Pitch.txt"; String NomFichierIntensity = "XXX_Intensity.txt"; float FacteurX = 32; float Facteur; int Couche = 0; //Traduction // int Couche = 1; //Transcription boolean DessinCurveVertex = false; boolean DessinCaractere = false; int Blur = 60; // 255: normal pas de blur 0: Blur max Essayer 100 boolean AfficheT = false; // Chrono en bas a gauche boolean DessinPitch = false; // boolean DessinIntensity = true; // // number of grid points horizontal int xCount = 30; //20 // number of grid points vertical int yCount = 23; int offsetX = 0, offsetY = 0, clickX = 0, clickY = 0; float rotationX = 0, rotationY = 0, targetRotationX = 0, targetRotationY = 0, clickRotationX, clickRotationY; int[][] Tableau = new int[2 * xCount + 1][2 * yCount + 1]; String[] list, LignesPitch; String[] LignesIntensity; int IndexPitch = 0; int IndexCaracterePitch = 0; int IndexIntensity = 0; int IndexCaractereIntensity = 0; float xAvantPitch, xApresPitch, yAvantPitch, yApresPitch; float xAvantIntensity, xApresIntensity, yAvantIntensity, yApresIntensity; int LigneText, x; AudioPlayer player; Minim minim; float temps, DureeFichier; boolean Probleme = false, Fin = false, FichierOuvert = false; boolean ToucheEspace = false, Pause = false, Trace = false, DebutTrace = false; float[] LignePitch, LigneIntensity; float TempsPause = 0, TempsDebutPause = 0; XML xml1, kid1, kid2; XML[] kid1Data, kidkid1Data, kidkid1intervals, kidkid1intervalsxmax; XML[] Traduction, Transcription; int NombreDeChild2, NombreSegment; int IndexXML = 0, n; float xmin, xmax; String s1, s2, Content1 = "", Content2 = "", Content = ""; char Caractere; GridPoint[][] points; float xgrid, ygrid; void setup() { size(800, 600, P3D); // maFonte = loadFont("Helvetica-50.vlw"); // maFonte = loadFont("Geneva-48.vlw"); // maFonte = createFont("Georgia", 24); maFonte = createFont("Georgia", 18); EffaceTableau(); background(Couleur); // File Fichier = new File(dataPath(NomFichierXML)); // if (Fichier.exists()) Ouverture(NomFichierXML); // else selectInput("select the XML File (format Praat textGrid):", "fileSelected"); // else exit(); Ouverture(NomFichierXML); game = new Game(70, 70, 1); } void draw() { game.update(); background(Couleur); game.draw(); if (! Pause) { temps = millis() - TempsPause; //temps en ms if ((! Fin) && AfficheT) AfficheTemps(temps); temps = temps / 1000; // temps en sec } if (FichierOuvert) { if (IndexXML < (NombreSegment-1)) { if (temps > xmax) { // Passage au segment suivant IndexXML = IndexXML + 1; Content = Traduction[IndexXML].getContent(); Content2 = Transcription[IndexXML].getContent(); if (Verbose) println(); if (Verbose) println("IndexXML = " + IndexXML); if (Content == null) IndexXML = IndexXML + 1; else if (Content.equals("_") == true) IndexXML = IndexXML + 1;//Elimination des caracteres _ qui separe les segments // else if ((temps > xmin) && ! Pause) { else if (! Pause) { n = Traduction[IndexXML].getInt("n"); xmin = Traduction[IndexXML].getFloat("xmin"); xmax = Traduction[IndexXML].getFloat("xmax"); println(); println("Segment = " + n + " xmin = " + xmin + " xmax = " + xmax); // println(" xmin = " + xmin); // println(" xmax = " + xmax); IndexCaracterePitch = 0; IndexCaractereIntensity = 0; // xApresPitch = 10; // xApresPitch = 0; // IndexXML = IndexXML + 1; Content1 = trim(Content); Content2 = trim(Content2); // noStroke(); // pas de contour // fill(0); // Rect noir // rect(0, YIntensity(40), width, 100); // textFont(maFonte, 20); // fill(255, 255, 0); // Texte jaune // text(Content2, 10, YIntensity(40) + 5, width-20, 50 ); // Transcription // fill(120, 120, 255); // Texte bleu // text(Content1, 10, YIntensity(40) + 55, width-20, 50 ); // Traduction // DebutTrace = true; println(Content2); println(Content1); } } } lights(); // directionalLight(255, 0, 0, 1, 1, 0); // noLights(); // background(0); // background(255, 0, 0); //Rouge // background(Couleur); // noStroke(); // pas de contour // stroke(0); // fill(0); // Rect noir // rect(0, YIntensity(40), width, 100); // textFont(maFonte, 20); textFont(maFonte); //fill(255, 255, 0); // Texte jaune fill(0, 0, 0); // Texte noir text(Content2, 10, YIntensity(40) + 5, width-20, 50 ); // Transcription // trim pour supprimer des carriage return dans le .xml // fill(120, 120, 255); // Texte bleu fill(255, 0, 0); // Texte rouge text(Content1, 10, YIntensity(40) + 55, width-20, 50 ); // Traduction if (true) { setView(); for (int y = -yCount; y < yCount; y++) { // for (int y = -yCount; y < n-yCount; y++) { beginShape(QUAD_STRIP); // fill(255, 255, 255); // Blanc fill(Couleur); noStroke(); // if (Maille) { stroke(100); // Couleur des lignes 0=noir 255=blanc strokeWeight(1); // Epaisseur des lignes } // noFill(); for (int x = - xCount; x <= xCount; x++) { // vertex(x, y, random(1)); // vertex(x, y+1, random(1)); // vertex(x, y, Tableau[x + xCount][y + yCount]); // vertex(x, y+1, Tableau[x + xCount][y+1+ yCount]); // vertex(x * 8, y * 8, Tableau[x + xCount][y + yCount]); // vertex(x * 8, (y+1) * 8, Tableau[x + xCount][y+1+ yCount]); // vertex(y * 8, x * 8, Tableau[x + xCount][y + yCount]); // vertex((y+1) * 8, x * 8, Tableau[x + xCount][y+1+ yCount]); // vertex(y * 8, x * abs(x) / 4, Tableau[x + xCount][y + yCount]); // vertex((y+1) * 8, x * abs(x) / 4, Tableau[x + xCount][y+1+ yCount]); // vertex(y * 8, x * abs(x) / 4, Tableau[x + xCount][y + yCount] + 10 * cos(sqrt(x*x/10 + y*y/10))); // vertex((y+1) * 8, x * abs(x) / 4, Tableau[x + xCount][y+1+ yCount] + 10 * cos(sqrt(x*x/10 + y*y/10))); // vertex(y * 8, x * 8, Tableau[x + xCount][y + yCount] + 30 * cos(sqrt(x*x/10 + y*y/10))); // vertex((y+1) * 8, x * 8, Tableau[x + xCount][y+1+ yCount] + 30 * cos(sqrt(x*x/10 + (y+1)*(y+1)/10))); // if (y > -yCount) vertex((y-1) * 8, x * 8, Tableau[x + xCount][y-1 + yCount] + 30 * cos(sqrt(x*x/10 + (y-1)*(y-1)/10))); // vertex(y * 8, x * 8, Tableau[x + xCount][y + yCount] + 30 * cos(sqrt(x*x/10 + y*y/10))); // if (y > -yCount) vertex(x * 8, (y-1) * 8, Tableau[x + xCount][y-1 + yCount] + 30 * cos(sqrt(x*x/10 + (y-1)*(y-1)/10))); // vertex(x * 8, y * 8, Tableau[x + xCount][y + yCount] + 30 * cos(sqrt(x*x/10 + y*y/10))); PVector p = points[x+xCount][y+yCount].position; // vertex(p.x, p.y); // vertex(xgrid, ygrid); //vertex(p.x-(width/2), p.y-(height/2), Tableau[x + xCount][y + yCount]); //vertex(p.x-(width/2), p.y-(height/2), Tableau[x + xCount][y+1+ yCount]); // int yy = y-1; //if (y > -yCount) vertex(p.x-(width/2), points[x+xCount][y+yCount-1].position.y-(height/2), Tableau[x + xCount][y-1+ yCount]); // vertex(p.x-(width/2), p.y -(height/2), Tableau[x + xCount][y + yCount]); if (y > -yCount) vertex((p.x-(width/2))+50, points[x+xCount][y+yCount-1].position.y-(height/2)+50, Tableau[x + xCount][y-1+ yCount]); vertex((p.x-(width/2))+50, p.y -(height/2)+50, Tableau[x + xCount][y + yCount]); } endShape(); } } // println("xgrid = " + xgrid); // println("ygrid = " + ygrid); // Dans cette version l'axe horizontal de la ligne de pitch =Duree du segment // et le dessin est fait avec: beginShape(); vertex(x, y); ou curvevertex(x, y); endShape(); au choix if (DessinPitch) { if (IndexPitch < LignesPitch.length) { LignePitch = float(split(LignesPitch[IndexPitch], " ")); if (Float.isNaN(LignePitch[0])) IndexPitch = IndexPitch + 1; if ((temps > LignePitch[0]) && ! Pause) { if (Float.isNaN(LignePitch[1])) IndexPitch = IndexPitch + 1; else { if (Trace) { if (IndexCaracterePitch < Content1.length()) { textFont(maFonte, 14); Caractere = Content1.charAt(IndexCaracterePitch); xApresPitch = int(((LignePitch[0] - xmin) / (xmax - xmin)) * float(width)); // yApresPitch = YPitch(LignePitch[1]) ; yApresPitch = YPitch(LignePitch[1] + 120) ; println("LignePitch[0] = " + LignePitch[0] + " xApresPitch = " + xApresPitch + " yApresPitch = " + yApresPitch ); if (DebutTrace) { println("Debuttrace n = " + n); beginShape(); // if (DessinCurveVertex) curveVertex(xApresPitch, yApresPitch); else vertex(xApresPitch, yApresPitch, 0); xAvantPitch = xApresPitch; yAvantPitch = yApresPitch; DebutTrace = false; } if (DessinCurveVertex) curveVertex(xApresPitch, yApresPitch); else vertex(xApresPitch, yApresPitch, 0); smooth(); stroke(150); // Couleur des lignes 0=noir 255=blanc strokeWeight(1); // Epaisseur des lignes noFill(); line(xAvantPitch, yAvantPitch, xApresPitch, yApresPitch); if (DessinCaractere) { fill(0, 0, 0); // Texte noir translate(xApresPitch, yApresPitch); rotate(atan2((yApresPitch - yAvantPitch), textWidth(Caractere))); text(Caractere, 0, 0); rotate(atan2(-(yApresPitch - yAvantPitch), textWidth(Caractere))); } xAvantPitch = xApresPitch; yAvantPitch = yApresPitch; IndexCaracterePitch = IndexCaracterePitch +1; } } Trace = true; IndexPitch = IndexPitch + 1; } } } else Fin = true; } // if (DessinIntensity) { if (false) { if (IndexIntensity < LignesIntensity.length) { LigneIntensity = float(split(LignesIntensity[IndexIntensity], " ")); if (Float.isNaN(LigneIntensity[0])) IndexIntensity = IndexIntensity + 1; if ((temps > LigneIntensity[0]) && ! Pause) { if (Float.isNaN(LigneIntensity[1])) IndexIntensity = IndexIntensity + 1; else { // if (Trace) { xApresIntensity = int(((LigneIntensity[0] - xmin) / (xmax - xmin)) * float(xCount * 2)); if ((xApresIntensity < (2 * xCount + 1)) && (xApresIntensity > 0) && (n < (2 * yCount + 1))) { // Tableau[int(xApresIntensity)][n] = int(yApresIntensity); // Tableau[int(xApresIntensity)][n] = int(LigneIntensity[1]); Tableau[int(xApresIntensity)][n] = int((LigneIntensity[1] - 30)*2.0); // Tableau[int(xApresIntensity)][n] = n; println("Tableau[int(xApresIntensity)][n] = " + Tableau[int(xApresIntensity)][n]); } // println("xApresIntensity = " + xApresIntensity + " n = " + n + " LigneIntensity[1] = " + LigneIntensity[1] ); Trace = true; // IndexIntensity = IndexIntensity + 5; IndexIntensity = IndexIntensity + 3; } } } else Fin = true; } if (DessinIntensity) { // La derniere ligne du fichier XXX_Intensity.txt // LigneIntensity = float(split(LignesIntensity[LignesIntensity.length - 1], " ")); // float[] Fff = float(split(LignesIntensity[LignesIntensity.length - 1], " ")); //println("Fff[0] = " + Fff[0] + " Fff[1] = " + Fff[1]); // xApresIntensity = int(((temps - xmin) / (xmax - xmin)) * float(xCount * 2)); xApresIntensity = int(((temps - xmin) / (12)) * float(xCount * 2)); //println("xApresIntensity = " + xApresIntensity); if ((xApresIntensity < (2 * xCount + 1)) && (xApresIntensity > 0) && (n < (2 * yCount + 1))) { // int Facteur = int(temps * 100.0); // int Facteur = int(temps * Fff[0] / Fff[1]); // int Facteur = int(temps * LignesIntensity.length / Fff[0]); int Ligne = int(temps * Facteur); if (Verbose) println("Facteur = " + Facteur); if (Verbose) println("Ligne = " + Ligne); if (Ligne < LignesIntensity.length) { LigneIntensity = float(split(LignesIntensity[Ligne], " ")); // Tableau[int(xApresIntensity)][n] = int((LigneIntensity[1] - 30.0) * 2.0); Tableau[int(xApresIntensity)][n] = int((LigneIntensity[1] - 20.0) * 2.0); if (Verbose) println("Tableau[" + int(xApresIntensity) + "][" + n + "] = " + Tableau[int(xApresIntensity)][n]); } } } } } float YPitch(float w) { // w en Hz YPitch en pixel return ((500 - w) / 2) + 100; //return ((500 - w) / 2) + 10; } float YIntensity(float w) { if (w < 40) w= 40; return ((100 - w) * 3) + 312; } void AfficheTemps(float T) { T = T / 1000; x = 728; fill(0); rect(x - 3, 587, 100, 15); fill(255); textFont(maFonte, 12); text(T + " sec", x, 590); } void EffaceEcran() { PImage CopiEcran; // background(255); // Fond blanc noStroke(); // pas de contour // CopiEcran = get(0, int(YPitch(500)), width, int(YPitch(0))); CopiEcran = get(0, int(YPitch(500)) + 1, width, int(YPitch(0))); image(CopiEcran, 0, YPitch(500)+30); fill(0, Blur); // 0=noir 255=blanc // rect(0, YPitch(500), width, YIntensity(40) - YPitch(500)); rect(0, 0, width, YIntensity(40) - YPitch(500)); // textFont(maFonte, 16); //text("Fichier: " + NomFichierPitch + " ("+ LignesPitch.length + " LignesPitch)", 5, 10); textFont(maFonte, 12); stroke(0, 0, 0); // Ligne noire // fill(0, 0, 0); // Texte noir // line(0, YPitch(75), width, YPitch(75)); // text("75Hz", width - 40, YPitch(75) - 10); // line(0, YPitch(500), width, YPitch(500)); // text("500Hz", width - 40, YPitch(500) + 2); // text("Pause : Espace", width - 85, 575); // fill(255, 0, 0); // Texte rouge // stroke(255, 0, 0); // Ligne rouge // text("100dB", width - 40, YPitch(75) + 2); // text("40dB", width - 40, YIntensity(40) - 10); // line(0, YIntensity(40), width, YIntensity(40)); // line(0, YIntensity(40), width, YIntensity(100)); xAvantPitch = 0; yAvantPitch = YPitch(75) ; xAvantIntensity = 0; yAvantIntensity = YIntensity(40) ; } void Debut() { TempsPause = millis(); IndexPitch = 0; IndexIntensity = 0; IndexXML = 0; EffaceEcran(); PlayerAudioDebut(); } void PlayerAudioDebut() { player.close(); player = minim.loadFile(NomFichierAudio, 2048); player.play(); } void keyPressed() { // println("key = " + key); if (key == ' ') { // barre d'espace ToucheEspace = ! ToucheEspace; Pause = ToucheEspace; if (Pause) { player.pause(); TempsDebutPause = millis(); } else { player.play(); TempsPause = TempsPause + millis() - TempsDebutPause; } } else if ( key == 'p' || key == 'P' ) { Couche = 0; // P Phonème Debut(); } else if (key == 'y' || key == 'Y') { Couche = 1; // Y Syllabe Debut(); } else if (key == 'm' || key == 'M') { Couche = 2; // M Mot Debut(); } else if (key == 'h' || key == 'H') { Couche = 3; // H Phonétique Debut(); } else if (key == 'o' || key == 'O') { Couche = 4; // O Orthographique Debut(); } else if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png"); else if (keyPressed && (key == CODED)) { // If it's a coded key if (keyCode == LEFT) { // Left arrow FacteurX = FacteurX / 2; Debut(); } else if (keyCode == RIGHT) { // Right arrow FacteurX = FacteurX * 2; Debut(); } } { // println("key = " + key + " Erreur taper Espace"); } } String timestamp() { Calendar now = Calendar.getInstance(); println("Frame saved"); // return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now); return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now); } //void fileSelected(File FichierChoisi) { // if (FichierChoisi == null) { // println("Pas de fichier XXX.xml ouvert!"); // exit(); // } // else Ouverture(FichierChoisi.getAbsolutePath()); //} void Ouverture(String NomFichier) { // println("NomFichierXML = " + NomFichier); Probleme = false; // File Fichier = new File(dataPath(NomFichier)); // if (!Fichier.exists()) { // println("Le fichier " + NomFichier + " n'existe pas"); // Probleme = true; // } if (!Probleme) { list = split(NomFichier, '.'); NomFichierXML = list[0] + ".xml"; if (loadStrings(NomFichierXML) == null) { println("Le fichier " + NomFichierXML + " n'existe pas"); Probleme = true; } } if (!Probleme) { // xml1 = new XMLElement(this, NomFichierXML); xml1 = loadXML(NomFichierXML); //Processing 2.0 println("Ouverture de: " + NomFichierXML); if (Verbose) println("1-----------------------------------------------------------"); // NombreDeChild1 = xml1.getChildCount(); if (xml1.hasChildren()) { // println("xml1.hasChildren"); if (Verbose) println("xml1.listChildren() : "); if (Verbose) println(xml1.listChildren()); } else { println("Le fichier xml n'a pas le bon format 1"); Probleme = true; } } if (!Probleme) { if (!(xml1.listChildren()[1] == "items" )) { println("Le fichier xml n'a pas le bon format 2"); println("xml1.listChildren()[1] = " + xml1.listChildren()[1]); Probleme = true; } } if (!Probleme) { kid1Data = xml1.getChildren("items"); // println("2-----------------------------------------------------------"); // println(kid1Data); kidkid1Data = kid1Data[0].getChildren("item"); // s2 = kidkid1Data[1].getName(); // println("s2 = " + s2); if (Verbose) println("kidkid1Data-----------------------------------------------------------"); // println(kidkid1Data); // gros a lister if (Verbose) println("-----------------------------------------------------------"); if (Verbose) println("Length of kidkid1Data = " + kidkid1Data.length); if (Verbose) println("kidkid1Data[0].getName() = " + kidkid1Data[0].getName()); if (Verbose) println("kidkid1Data[1].getName() = " + kidkid1Data[1].getName()); if (Verbose) println("kidkid1Data[0].listAttributes() = " + kidkid1Data[1].getChildren("item")); // kidkid1intervals = kidkid1Data[4].getChildren("intervals"); // println(); // println("-----------------------------------------------------------"); // println(kidkid1intervals); // println("-----------------------------------------------------------"); // println("Length of kidkid1intervals = " + kidkid1intervals.length); // println("kidkid1intervals[10].getName() = " + kidkid1intervals[10].getName()); // println("kidkid1intervals[11].getName() = " + kidkid1intervals[11].getName()); // println("kidkid1intervals.listAttributes() = " + kidkid1intervals[10].getChildren("intervals")); // // // kidkid1intervalsxmax = kidkid1intervals[76].getChildren("xmax"); // println(); // println("-----------------------------------------------------------"); // println("kidkid1intervals[26].getInt(\"n\") = " + kidkid1intervals[26].getInt("n")); // println("kidkid1intervals[26].getFloat(\"xmax\") = " + kidkid1intervals[26].getFloat("xmax")); // println("kidkid1intervals[26].getFloat(\"xmin\") = " + kidkid1intervals[26].getFloat("xmin")); // println("kidkid1intervals[26].getContent() = " + kidkid1intervals[26].getContent()); // println(); // println("kidkid1intervals[27].getFloat(\"xmax\") = " + kidkid1intervals[27].getFloat("xmax")); // println("-----------------------------------------------------------"); // println("Length of kidkid1intervalsxmax = " + kidkid1intervalsxmax.length); // println("kidkid1intervalsxmax[10].getName() = " + kidkid1intervalsxmax[10].getName()); // println("kidkid1intervalsxmax[11].getName() = " + kidkid1intervalsxmax[11].getName()); // println("kidkid1intervalsxmax.listAttributes() = " + kidkid1intervalsxmax[10].getChildren("intervals")); // fill(0); // textFont(maFonte, 16); // fill(180); // textFont(maFonte, 12); // text(NomFichierXML, 10, 65); Traduction = kidkid1Data[0].getChildren("intervals"); NombreSegment = Traduction.length; if (Verbose) println("oooooooooooooooooooooooooooooooooooooooooooooo"); // println(Traduction); // gros a lister if (Verbose) println("oooooooooooooooooooooooooooooooooooooooooooooo"); Transcription = kidkid1Data[1].getChildren("intervals"); if (NombreSegment != Transcription.length ) { println("Le fichier xml n'a pas le bon format 3"); println("il n'y a pas le meme nombre de segment transcrit et traduit"); Probleme = true; } } if (! Probleme) { NomFichierPitch = list[0] + "_Pitch.txt"; if (loadStrings(NomFichierPitch) == null) { println("Le fichier " + NomFichierPitch + " n'existe pas"); Probleme = true; } else { LignesPitch = loadStrings(NomFichierPitch); println("Ouverture de: " + NomFichierPitch +" " + LignesPitch.length + " lignes" ); } } if (! Probleme) { NomFichierIntensity = list[0] + "_Intensity.txt"; if (loadStrings(NomFichierIntensity) == null) { println("Le fichier " + NomFichierIntensity + " n'existe pas"); Probleme = true; } else { LignesIntensity = loadStrings(NomFichierIntensity); println("Ouverture de: " + NomFichierIntensity +" " + LignesIntensity.length + " lignes" ); } } if (! Probleme) { NomFichierAudio = list[0] + ".mp3"; if (loadStrings(NomFichierAudio) == null) { println("Le fichier " + NomFichierAudio + " n'existe pas"); Probleme = true; } else println("Ouverture de: " + NomFichierAudio); } if (! Probleme) { println("NombreSegment = " + NombreSegment); minim = new Minim(this); player = minim.loadFile(NomFichierAudio, 2048); LignePitch = float(split(LignesPitch[LignesPitch.length - 1 ], " ")); DureeFichier = LignePitch[0]; if (Verbose) println("Duree " + NomFichierPitch + " = " + DureeFichier + " sec"); LigneIntensity = float(split(LignesIntensity[LignesIntensity.length - 1 ], " ")); DureeFichier = LigneIntensity[0]; if (Verbose) println("Duree " + NomFichierIntensity + " = " + DureeFichier + " sec"); // float[] Fff = float(split(LignesIntensity[LignesIntensity.length - 1], " ")); // int Facteur = int(temps * LignesIntensity.length / Fff[0]); Facteur = LignesIntensity.length / LigneIntensity[0]; //Nombre de lignes / Duree totale fichier XXX_Intensity.txt player.play(); TempsPause = millis(); FichierOuvert = true; xmax = 0; IndexXML = -1; } else { println("Probleme = " + Probleme + " exit"); exit(); } } void mousePressed() { clickX = mouseX; clickY = mouseY; clickRotationX = rotationX; clickRotationY = rotationY; } void setView() { translate(width*0.5, height*0.5); if (mousePressed) { offsetX = mouseX-clickX; offsetY = mouseY-clickY; targetRotationX = clickRotationX + offsetX/float(width) * TWO_PI; targetRotationY = min(max(clickRotationY + offsetY/float(height) * TWO_PI, -HALF_PI), HALF_PI); rotationX += (targetRotationX-rotationX)*0.25; rotationY += (targetRotationY-rotationY)*0.25; } rotateX(-rotationY); rotateY(rotationX); } void EffaceTableau() { for (int y = -yCount; y < yCount; y++) { for (int x = - xCount; x <= xCount; x++) { Tableau[x + xCount][y + yCount] = 0; } } // Tableau[xCount][yCount] = 10; } void stop() { // always close Minim audio classes when you are done with them player.close(); minim.stop(); super.stop(); } class Game { Grid grid; Planet[] planets; Game(int gridWidth, int gridHeight, int numPlanets) { noFill(); strokeWeight(2); stroke(color(0, 128, 0)); grid = new Grid(gridWidth, gridHeight); planets = new Planet[numPlanets]; for (int i = 0; i < planets.length; i++) { // planets[i] = new Planet(int(random(width)), int(random(height)), int(random(5, 20))); // Planet(int x, int y, int mass) planets[i] = new Planet(int(random(width)), int(random(height)), int(random(10, 50))); // Planet(int x, int y, int mass) } } void update() { //Gravitate planets toward each other for (int i = 0; i < planets.length - 1; i++) { for (int j = i + 1; j < planets.length; j++) { planets[i].gravitate(planets[j]); } } //Update positions for (int i = 0; i < planets.length; i++) { planets[i].updatePosition(); planets[i].wrap(); } grid.update(planets); } void draw() { grid.draw(); for (int i = 0; i < planets.length; i++) { planets[i].draw(); } } } /* OpenProcessing Tweak of *@*http://www.openprocessing.org/sketch/1011*@* */ /* !do not delete the line above, required for linking your tweak if you upload again */ Game game; //void setup() //{ // size(600,600); // game = new Game(50, 50, 5); // frameRate(30); //} //void draw() //{ // game.update(); // background(0); // game.draw(); // println(frameRate); //} class Grid { // GridPoint[][] points; int w, h; Grid(int w, int h) { this.w = w; this.h = h; points = new GridPoint[w][h]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int sx = (int)map(x, 0, w - 1, 0, width - 1), sy = (int)map(y, 0, h - 1, 0, height - 1); points[x][y] = new GridPoint(sx, sy); } } } void update(Planet[] planets) { for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { points[x][y].update(planets); } } } void update() { for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { points[x][y].update(); } } } void draw() { // //Draw horizontal lines // for (int y = 0; y < h; y++) // { // beginShape(); // for (int x = 0; x < w; x++) // { // PVector p = points[x][y].position; // vertex(p.x, p.y); // xgrid = p.x; // ygrid = p.y; // } // endShape(); // } // // //Draw vertical lines // for (int x = 0; x < w; x++) // { // beginShape(); // for (int y = 0; y < h; y++) // { // PVector p = points[x][y].position; // vertex(p.x, p.y); // } // endShape(); // } } } float toPlanetMult = 10; float toOriginMult = 0.2; class GridPoint { PVector origin, position; GridPoint(int x, int y) { origin = new PVector(x, y); position = new PVector(x, y); } void update(Planet[] planets) { for (int i = 0; i < planets.length; i++) { //Move towards targets[i] PVector toTarget = PVector.sub(planets[i].pos, position); float distToTarget = toTarget.mag(); if (distToTarget > 0) toTarget.limit(min(planets[i].mass*toPlanetMult/distToTarget, distToTarget)); position.add(toTarget); } update(); } void update() { //Move towards origin PVector toOrigin = PVector.sub(origin, position); float distToOrigin = toOrigin.mag(); toOrigin.limit(distToOrigin*toOriginMult); position.add(toOrigin); } } float maxVelocity = 40; class Planet { PVector pos, vel; int mass; Planet(int x, int y, int mass) { pos = new PVector(x, y); vel = new PVector(0, 0); this.mass = mass; } //Gravitate planets toward each other void gravitate(Planet planet) { PVector toPlanet = PVector.sub(planet.pos, pos); toPlanet.div(sq(toPlanet.mag())); vel.add(PVector.mult(toPlanet, planet.mass)); planet.vel.sub(PVector.mult(toPlanet, mass)); } void updatePosition() { vel.limit(maxVelocity); vel.set(1,-10); pos.add(vel); } void wrap() { if (pos.x < 0) { pos.x = width; } else if (pos.x > width) { pos.x = 0; } if (pos.y < 0) { pos.y = height; pos.y = random(height); } else if (pos.y > height) { pos.y = 0; } } void draw() { // fill(0); // ellipse(pos.x, pos.y, mass*2, mass*2); // noFill(); } }