Skip to content

Commit

Permalink
End-of-file behaviour has been fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
DC37 committed Jan 3, 2014
1 parent 2600d1d commit 359bad2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/smp/components/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class Values {

/**
* The number of lines in the staff, by default. This number
* is typically 384.
* is typically 400.
*/
public static int DEFAULT_LINES_PER_SONG = 400;

Expand Down
9 changes: 8 additions & 1 deletion src/smp/components/controls/ArrowButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class ArrowButton extends ImagePushButton {
*/
private double skipAmount;

/** Tells us whether we're at the end of the file. */
private boolean endOfFile = false;

/** This is the slider that the scrollbar will affect. */
private Slider scrollbar;

Expand Down Expand Up @@ -62,7 +65,7 @@ public double getSkipAmount() {
protected void reactPressed(MouseEvent event) {
super.reactPressed(event);
scrollbar.adjustValue(scrollbar.getValue() + skipAmount);
if (scrollbar.getMax() <= scrollbar.getValue()) {
if (scrollbar.getMax() <= scrollbar.getValue() && endOfFile) {
scrollbar.setMax(scrollbar.getMax()
+ Values.NOTELINES_IN_THE_WINDOW * 2);
StaffSequence s = theStaff.getSequence();
Expand All @@ -71,6 +74,10 @@ protected void reactPressed(MouseEvent event) {
+ Values.NOTELINES_IN_THE_WINDOW * 2; i++)
s.addLine(new StaffNoteLine(i));
}
if (scrollbar.getMax() <= scrollbar.getValue())
endOfFile = true;
else
endOfFile = false;
}

@Override
Expand Down
72 changes: 34 additions & 38 deletions src/smp/components/staff/Staff.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,21 @@ public synchronized void redraw() {
setLocation(StateMachine.getMeasureLineNum());
}

/** Turns off all highlights in the play bars in the staff. */
private void highlightsOff() {
ArrayList<ImageView> playBars = staffImages.getPlayBars();
for(ImageView i : playBars) {
i.setImage(ImageLoader.getSpriteFX(
ImageIndex.NONE));
}
}


/**
* Begins animation of the Staff.
*/
public void startSong() {
highlightsOff();
lastLine = findLastLine();
if (lastLine == 0 && theSequence.getLine(0).isEmpty()) {
theControls.getStopButton().reactPressed(null);
Expand All @@ -151,11 +161,10 @@ public void startSong() {
*/
private int findLastLine() {
ArrayList<StaffNoteLine> lines = theSequence.getTheLines();
for (int i = lines.size() - 1; i >= 0; i--) {
for (int i = lines.size() - 1; i >= 0; i--)
if (!lines.get(i).isEmpty()) {
return i;
}
}
return 0;
}

Expand All @@ -164,11 +173,18 @@ private int findLastLine() {
*/
public void stopSong() {
songPlaying = false;
for (ImageView i : staffImages.getPlayBars()) {
i.setImage(ImageLoader.getSpriteFX(ImageIndex.NONE));
}
animationService.cancel();
animationService.reset();
try {
Thread.sleep(1);
while (true) {
if (!animationService.isRunning())
break;
}
} catch (InterruptedException e) {

}
highlightsOff();
}

/**
Expand Down Expand Up @@ -272,7 +288,7 @@ public static ImageIndex switchAcc(int acc) {
*
*/
public void setTempo(double tempo) {
double mill = (1 / (tempo / 60.0)) * 1000;
double mill = (60.0 / tempo) * 1000;
delayMillis = (int) mill;
double nano = (mill - delayMillis) * Math.pow(10, 6);
delayNanos = (int) nano;
Expand All @@ -292,6 +308,9 @@ public void setCurrVal(DoubleProperty d) {
*/
class AnimationService extends Service<Staff> {

/** Whether we have zeroed the staff or not. */
private boolean zero = false;

@Override
protected Task<Staff> createTask() {
return new AnimationTask();
Expand All @@ -305,15 +324,13 @@ protected Task<Staff> createTask() {
*/
private void bumpHighlights(ArrayList<ImageView> playBars, int index,
boolean advance) {
for (ImageView i : playBars) {
i.setImage(
ImageLoader.getSpriteFX(ImageIndex.NONE));
}
highlightsOff();
playBars.get(index).setImage(
ImageLoader.getSpriteFX(ImageIndex.PLAY_BAR1));
if (advance) {
if (advance && !zero)
shiftStaff();
}
if (zero)
zero = false;

}

Expand Down Expand Up @@ -370,11 +387,6 @@ class AnimationTask extends Task<Staff> {
*/
private int index = 0;

/**
* This is the current measure line.
*/
private int currMeasureLine = 0;

/**
* Whether we need to advance the satff ahead by a few lines or not.
*/
Expand All @@ -386,19 +398,16 @@ class AnimationTask extends Task<Staff> {
@Override
protected Staff call() throws Exception {
playBars = staffImages.getPlayBars();
currMeasureLine = StateMachine.getMeasureLineNum();
int counter = currMeasureLine;
int counter = StateMachine.getMeasureLineNum();
do {
playNextLine();
counter++;
if (counter % Values.NOTELINES_IN_THE_WINDOW == 0)
currMeasureLine += Values.NOTELINES_IN_THE_WINDOW;
if (counter % 4 == 0 && counter > lastLine) {
if (counter > lastLine && counter % 4 == 0) {
if (StateMachine.isLoopPressed()) {
currMeasureLine = 0;
counter = 0;
index = 0;
zeroStaff();
zero = true;
} else {
songPlaying = false;
}
Expand All @@ -408,20 +417,12 @@ protected Staff call() throws Exception {
} catch (InterruptedException e) {
// Do nothing
}
} while (songPlaying && currMeasureLine
<= Values.DEFAULT_LINES_PER_SONG);
highlightsOff();
} while (songPlaying);
hitStop();
highlightsOff();
return theMatrix.getStaff();
}

/** Turns off all highlights in the play bars in the staff. */
private void highlightsOff() {
for(ImageView i : playBars) {
i.setImage(ImageLoader.getSpriteFX(
ImageIndex.NONE));
}
}

/** Hits the stop button for the song. */
private void hitStop() {
Expand All @@ -435,11 +436,6 @@ private void hitStop() {
* they are.
*/
private void playNextLine() {
if (StateMachine.getMeasureLineNum() >=
Values.DEFAULT_LINES_PER_SONG
- Values.NOTELINES_IN_THE_WINDOW) {
songPlaying = false;
}
bumpHighlights(playBars, index, advance);
playSoundLine(index);
advance = false;
Expand Down

0 comments on commit 359bad2

Please sign in to comment.