Who knows how to make this read every letter, not just the first one. (Reading Txt. files)

Hey guys, Im trying to make processing read out the letters in this txt. file. There are 4 letters in the file all scrambled up looking like this (gtcclclgtlcgttttgl). As of right now it is reading all of the letters as i can see in the bottom of the programming window, yet it is only making sounds for the first time that specific letter appears. I'm guessing it is a problem in my if statement but can anyone make it continue after it has read that specific letter? Thankyou thankyou

import ddf.minim.*;
Minim minim;
AudioPlayer bass2;
AudioPlayer bass3;
AudioPlayer bass4;
AudioPlayer bass5;
String[] lines;
String data;
int i=0; 
char letter;
int a;
int c;
int g;
int t;
void setup() {
  size(500, 500);
  background(0);
  lines = loadStrings("dna.txt");
  data = lines[i]; 
  frameRate(5);
  minim = new Minim(this);
  bass2 = minim.loadFile("beep-2.mp3");
  bass3 = minim.loadFile("beep-3.mp3");
  bass4 = minim.loadFile("beep-4.mp3");
  bass5 = minim.loadFile("beep-5.mp3");
}
void draw() { 

  if (letter == 'A') {
    bass2.play();
    stroke(255);
    smooth();
    noFill();
    ellipse(100, 100, 100, 100);
    i++;
  }

  if (letter == 'C') {
    bass3.play() ;
    stroke(255);
     smooth();
    noFill();
    ellipse(400, 100, 100, 100);
    i++;    
  }
  if (letter == 'G') {
    bass4.play() ;
    stroke(255);
     smooth();
    noFill();
    ellipse(400, 400, 100, 100);
    i++;    
  }
  if (letter == 'T') {
    bass5.play();
    stroke(255);
     smooth();
    noFill();
    ellipse(100, 400, 100, 100);
    i++;   
  }

  letter = data.charAt(i); 
  println(letter);
  i++;
}

Answers

  • edited November 2013

    maybe you need a** for loop** that works as long as there are letters in the file?? Then it will keep going through the code? And I think you need only one i++ at the end.

    I'm new at this, so just trying to learn to help.

  • can i get a rewind()?

    http://code.compartmental.net/tools/minim/manual-playable/

    you need to call rewind() to get samples to play again. play() just continues from where it was, and given that it was at the end so you won't hear anything.

  • edited November 2013

    Earlier, I have written a similar code here .

Sign In or Register to comment.