// Ouvre le fichier texte jouineau_sport_Pitch_listing.txt // placé dans le dossier data // Dessine la courbe /** * Touche Espace Pause
* Touche Fleche <- Zoom Out
* Touche Fleche -> Zoom In
* Clic souris dans la fenêtre d'abord

* Ouvre et joue le fichier Audio jouineau_sport.wav
* Ouvre le fichier texte jouineau_sport_Pitch_listing.txt
* Dessine la courbe de pitch synchronisée avec l'Audio
* Chronomètre...
*/ import ddf.minim.*; // pour AudioPlayer PFont maFonte; String Texte1Nom = "jouineau_sport_Pitch_listing.txt"; String AudioNom = "jouineau_sport.wav"; String[] lignes; int index = 0; float xavant, xapres, yavant, yapres; int Ligne, x; AudioPlayer player; Minim minim; float temps, DureeFichier; boolean ToucheEspace = false, Pause = false; float[] nums; float TempsPause, TempsDebutPause = 0, FacteurX = 4; void setup() { size(800, 600); // "The size() function must be the first line in setup()" maFonte = loadFont("Helvetica-50.vlw"); smooth(); background(255); stroke(160); textAlign(LEFT, TOP); //RIGHT LEFT BOTTOM BASELINE TOP if (loadStrings(Texte1Nom) == null) { println("Le fichier " + Texte1Nom + " n'existe pas"); exit(); } else { println("Ouverture de: " + Texte1Nom); println(); lignes = loadStrings(Texte1Nom); minim = new Minim(this); // load a file, give the AudioPlayer buffers that are 2048 samples long player = minim.loadFile(AudioNom, 2048); player.play(); nums = float(split(lignes[lignes.length - 2 ], " ")); println(nums[0] + " " + nums[1]); DureeFichier = nums[0]; EffaceEcran(); TempsPause = millis(); } } void draw() { temps = millis() - TempsPause; if (! Pause) AfficheTemps(temps); temps = temps / 1000; if (index < lignes.length) { float[] nums = float(split(lignes[index], " ")); if (index < 0) { Ligne = (index * 14) + 20; fill(0, 0, 255); text(nums[0], 50, Ligne); fill(255, 0, 0); text(nums[1], 100, Ligne); } if (Float.isNaN(nums[1])) { index = index + 1; } else { if ((temps > nums[0]) && ! Pause) { //xapres = index * 750 / lignes.length; xapres = FacteurX * (width) * nums[0] / DureeFichier; yapres = YPitch(nums[1]) ; // text(xapres, 250, Ligne); // text(yapres, 350, Ligne); if ((xavant % width) < (xapres % width)) { stroke(0, 0, 0); // Ligne noire line(xavant % width, yavant, xapres % width, yapres); } else EffaceEcran(); xavant = xapres; yavant = yapres; index = index + 1; } } } // if (player.isPlaying() == false) { // player = minim.loadFile(AudioNom, 2048); // player.play(); // index = 0; //} } float YPitch(float w) { return ((500 - w) / 2) + 100; } void AfficheTemps(float T) { T = T / 1000; x = 728; fill(0); rect(x - 3, 587, 100, 15); fill(255); text(T + " sec", x, 590); } void EffaceEcran() { background(255); textFont(maFonte, 16); fill(0, 0, 0); text("Fichier: " + Texte1Nom + " ("+ lignes.length + " lignes)", 5, 10); textFont(maFonte, 12); stroke(0, 0, 0); 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)-10); text("Pause : Espace", width - 85, 575); xavant = 0; yavant = YPitch(75) ; } void PlayerAudioDebut() { player.close(); player = minim.loadFile(AudioNom, 2048); player.play(); } void keyPressed() { if (key == ' ') { // barre d'espace ToucheEspace = ! ToucheEspace; Pause = ToucheEspace; if (Pause) { player.pause(); TempsDebutPause = millis(); } else { player.play(); TempsPause = TempsPause + millis() - TempsDebutPause; } } else if (keyPressed && (key == CODED)) { // If it's a coded key if (keyCode == LEFT) { // If it's the left arrow FacteurX = FacteurX / 2; TempsPause = millis(); index =0; EffaceEcran(); PlayerAudioDebut(); } else if (keyCode == RIGHT) { // If it's the right arrow FacteurX = FacteurX * 2; TempsPause = millis(); index =0; EffaceEcran(); PlayerAudioDebut(); } } { println("key = " + key + " Erreur taper Espace"); } } void mousePressed() { ; } void stop() { // always close Minim audio classes when you are done with them player.close(); minim.stop(); super.stop(); }