int[] blackNotes = {1, 3, 6, 8, 10};
boolean white = true;
for (int k = 0; k < blackNotes.length; k++) {
if (newPitch % 12 == blackNotes[k]) newPitch--;
}
Note n = new Note(newPitch, 1.0);
Phrase phr = theApp.getPhrase();
phr.addNote(n);
theApp.repaint();
// set cursor
theApp.setCursor(new Cursor(Cursor.HAND_CURSOR));
// get ready to drag it
selectedNote = phr.size() - 1;
//theApp.playCurrentNote(selectedNote);
clickedPosY = e.getY() + theApp.staveDelta;
clickedPosX = e.getX();
} else {
// check for a click on a note - head?
for (int i = 0; i < theApp.notePositions.size(); i += 2) {
Integer tempX = (Integer) theApp.notePositions.elementAt(i);
Integer tempY = (Integer) theApp.notePositions.elementAt(i + 1);
if (e.getX() > tempX.intValue() && e.getX() < tempX.intValue() + 15 && e.getY() +
theApp.staveDelta > tempY.intValue() + 22 && e.getY() +
theApp.staveDelta < tempY.intValue() + 35) {
// set cursor
theApp.setCursor(new Cursor(Cursor.MOVE_CURSOR));
selectedNote = i / 2;
clickedPosY = e.getY() + theApp.staveDelta;
clickedPosX = e.getX();
//System.out.println("Hit note "+ selectedNote);
// get out of loop ASAP
i = theApp.notePositions.size();
}
}
}
if (selectedNote < 0) { // no note clicked on or yet made
// check which note to insert
for (int j = 0; j < theApp.notePositions.size() - 2; j += 2) {
Integer tempX = (Integer) theApp.notePositions.elementAt(j);
Integer nextTempX = (Integer) theApp.notePositions.elementAt(j + 2);
if (e.getX() > tempX.intValue() + 15 && e.getX() < nextTempX.intValue()) {
// change cursor
theApp.setCursor(new Cursor(Cursor.HAND_CURSOR));
// add new note close to mouse clicked pitch
int newPitch = 85 - (e.getY() + theApp.staveDelta - theApp.bPos) / 2;
// make sure it is not an accidental
int[] blackNotes = {1, 3, 6, 8, 10};
boolean white = true;
for (int k = 0; k < blackNotes.length; k++) {
if (newPitch % 12 == blackNotes[k]) newPitch--;
}
Note n = new Note(newPitch, 1.0);
Phrase phr = theApp.getPhrase();
phr.getNoteList().insertElementAt(n, j / 2 + 1);
theApp.repaint();
// play and update variables for dragging it
selectedNote = j / 2 + 1;