|
I'm writing an application at the moment trying to
take timing data from a MIDI file, and using this data to pause the program,
then update a display using the repaint() method. However, it only seems
to be able to do the repainting at the end of the run, not in the appropriate
places. Any suggestions.
thanks, Jos Roberts.
The specific code is as follows:
n.b. example.txt is the file I'm reading the data
from. strToInt is a simple method to convert a String representation of a
number to an int form. The MIDI file tokenises as follows: time of event; N/A;
N/A; note; strength of hit. If anyone is interested in the rest of the
program, or needs the program to help, drop me a line. JPR;-)
String line, junk;
long time,
delay;
long lastTime =
0;
double
timeCount;
int lineCount =
1;
BufferedReader in = new BufferedReader(new FileReader("example.txt"));
while (in != null)
{
line =
in.readLine();
StringTokenizer st = new
StringTokenizer(line);
junk =
st.nextToken();
time = (long)(MidiFunctions.strToInt(junk)*6.25);
delay = time -
lastTime;
junk = st.nextToken(); //need to remove 2 pieces of
information
junk =
st.nextToken();
if (junk.equals("TrkEnd"))
return lineCount;
//return number of
lines parsed (2*number of events)
junk = st.nextToken(); //info with key in.
key =
junk.substring(2);
junk =
st.nextToken();
if (junk.equals("v=0")) //noteOff signal
key = "";
timeCount =
time/1000.0;
t.sleep(delay);
repaint(10, 10, 80, 300,
195);
System.out.println(timeCount + " :
" + key);
lastTime = time;
lineCount ++;
} |
