newWidth = 50;
repaint();
}
private void convertLineToPhrase(boolean hiRes) {
Phrase phr = null;
double[][] storer = new double[drawPoints.size() / 4][3];
Enumeration drawEnum = drawPoints.elements();
int counter = 0;
while (drawEnum.hasMoreElements()) {
int x1 = ((Integer) (drawEnum.nextElement())).intValue();
int y1 = ((Integer) (drawEnum.nextElement())).intValue();
int x2 = ((Integer) (drawEnum.nextElement())).intValue();
int y2 = ((Integer) (drawEnum.nextElement())).intValue();
//System.out.println("Values are "+x1/beatWidth+" "+y1 /beatWidth+" "+x2 /beatWidth+" "+y2 /beatWidth);
if (hiRes) { // was the option key held down
// fine grade
for (int i = 0; i < Math.abs(y1 - y2); i++) {
storer[counter][0] = (double) (((Integer) drawPoints.elementAt(counter * 4)).
intValue()) / beatWidth +
((double) Math.abs(x2 - x1) / beatWidth / (double) (Math.abs(y1 - y2)) + 1.0) /
(Math.abs(y1 - y2) + 1); //onset time
if ((int) ((Integer) drawPoints.elementAt(counter * 4)).intValue() >
(int) ((Integer) drawPoints.elementAt(counter * 4 + 2)).intValue()) {
//revised onset time for drawing backwards
storer[counter][0] = (double) (((Integer) drawPoints.elementAt(counter * 4 + 2)).
intValue()) / beatWidth / (double) (Math.abs(y1 - y2)) + 1.0;
}
//pitch
storer[counter][1] = (double) (127 - y1 + i);
//duration
storer[counter][2] = (double) Math.abs(x2 - x1) / beatWidth /
(double) (Math.abs(y1 - y2)) + 1.0;
}
} else {
// course grade
storer[counter][0] = (double) (((Integer) drawPoints.elementAt(counter * 4)).
intValue()) / beatWidth; //onset time
if ((int) ((Integer) drawPoints.elementAt(counter * 4)).intValue() >
(int) ((Integer) drawPoints.elementAt(counter * 4 + 2)).intValue()) {
//revised onset time for drawing backwards
storer[counter][0] = (double) (((Integer) drawPoints.elementAt(counter * 4 + 2)).
intValue()) / beatWidth;
}
storer[counter][1] = (double) (127 - y1); //pitch
storer[counter][2] = (double) Math.abs(x2 - x1) / beatWidth; //duration
}
counter++;
}
// sort notes into onset order
quickSort(storer, 0, storer.length - 1);
// put notes into a phrase
if (drawPoints.size() > 0) phr = new Phrase(storer[0][0]);
for (int i = 0; i < storer.length - 1; i++) {
// prevent out of range notes being generated at the edges
if (storer[i][1] < 0) storer[i][1] = 0;
if (storer[i][1] > 127) storer[i][1] = 127;
Note n = new Note((int) storer[i][1], storer[i + 1][0] - storer[i][0]);
// avoid unnecessary repeat notes
if (i > 0 && n.getPitchType() == Note.MIDI_PITCH &&
((Note) (phr.getNoteList().lastElement())).getPitchType() == Note.MIDI_PITCH) {
if (phr.size() > 0 && n.getPitch() ==
((Note) (phr.getNoteList().lastElement())).getPitch()) {
Mod.append(((Note) (phr.getNoteList().lastElement())), n);
} else {
phr.addNote(n);
}
} else phr.addNote(n);
}
// last note
if (storer[storer.length - 1][1] < 0) storer[storer.length - 1][1] = 0;
if (storer[storer.length - 1][1] > 127) storer[storer.length - 1][1] = 127;
Note n = new Note((int) storer[storer.length - 1][1], storer[storer.length - 1][2]);
n.setDuration(storer[storer.length - 1][2]);
phr.addNote(n);
// add phrase to the score as a new part
if (phr != null) {
currentChannel++;
if (currentChannel > 15) currentChannel = scoreChannels;