Skip to content

Commit

Permalink
Getting those file lengths implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
DC37 committed Jan 4, 2014
1 parent 359bad2 commit 3a8becb
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ Tasklist:
* Volume bars implemented (done - December 17, 2013)
* Save & Load songs (done - December 18, 2013)
* Loop button loops the song (done - December 18, 2013)
* End-of-File Behaviour fix (done - December 25, 2013)
* Release to a test group (v0.9 - **Alpha Release** - December 25, 2013)
* Measure line numbers (done - December 27, 2013)
* Tempo selector interface (done - December 27, 2013)
* Remove limit on song length (done - January 1, 2014)
* End-of-File Behaviour fix (done - January 3, 2014)
* Options dialog
* Import MPC songs
* Arranger mode
Expand Down
67 changes: 53 additions & 14 deletions src/smp/components/controls/ArrowButton.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package smp.components.controls;

import java.util.Timer;
import java.util.TimerTask;

import smp.ImageIndex;
import smp.components.Values;
import smp.components.controls.TempoAdjustButton.clickHold;
import smp.components.general.ImagePushButton;
import smp.components.staff.sequences.StaffNoteLine;
import smp.components.staff.sequences.StaffSequence;
import javafx.application.Platform;
import javafx.scene.control.Slider;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
Expand All @@ -31,6 +36,9 @@ public class ArrowButton extends ImagePushButton {
/** This is the slider that the scrollbar will affect. */
private Slider scrollbar;

/** This is a timer object for click-and-hold. */
private Timer t;

/**
* Default constructor.
* @param i The <code>ImageView</code> object that we are
Expand All @@ -39,6 +47,7 @@ public class ArrowButton extends ImagePushButton {
public ArrowButton(ImageView i, Slider scr, ImageIndex pr,
ImageIndex notPr) {
super(i);
t = new Timer();
scrollbar = scr;
getImages(pr, notPr);
}
Expand All @@ -64,25 +73,55 @@ public double getSkipAmount() {
@Override
protected void reactPressed(MouseEvent event) {
super.reactPressed(event);
scrollbar.adjustValue(scrollbar.getValue() + skipAmount);
if (scrollbar.getMax() <= scrollbar.getValue() && endOfFile) {
scrollbar.setMax(scrollbar.getMax()
+ Values.NOTELINES_IN_THE_WINDOW * 2);
StaffSequence s = theStaff.getSequence();
int start = (int) scrollbar.getMax();
for(int i = start; i < start
+ Values.NOTELINES_IN_THE_WINDOW * 2; i++)
s.addLine(new StaffNoteLine(i));
}
if (scrollbar.getMax() <= scrollbar.getValue())
endOfFile = true;
else
endOfFile = false;
bumpStaff();
TimerTask tt = new clickHold();
t.schedule(tt, Values.HOLDTIME,
Values.REPEATTIME);
}

/** Bumps the staff by some amount. */
private void bumpStaff() {
Platform.runLater(new Runnable() {

@Override
public void run() {
scrollbar.adjustValue(scrollbar.getValue() + skipAmount);
if (scrollbar.getMax() <= scrollbar.getValue() && endOfFile) {
scrollbar.setMax(scrollbar.getMax()
+ Values.NOTELINES_IN_THE_WINDOW * 2);
StaffSequence s = theStaff.getSequence();
int start = (int) scrollbar.getMax();
for(int i = start; i < start
+ Values.NOTELINES_IN_THE_WINDOW * 2; i++)
s.addLine(new StaffNoteLine(i));
}
if (scrollbar.getMax() <= scrollbar.getValue())
endOfFile = true;
else
endOfFile = false;
}
});
}

@Override
protected void reactReleased(MouseEvent event) {
super.reactReleased(event);
t.cancel();
t = new Timer();
}

/**
* This is a timer task that increments the current line of the song.
* @author RehdBlob
* @since 2014.01.02
*/
class clickHold extends TimerTask {

@Override
public void run() {
bumpStaff();
}

}

}
23 changes: 20 additions & 3 deletions src/smp/components/controls/LoadButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;

import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.stage.FileChooser;
import smp.components.Values;
import smp.components.general.ImagePushButton;
import smp.components.staff.sequences.StaffNoteLine;
import smp.components.staff.sequences.StaffSequence;
import smp.fx.Dialog;
import smp.fx.SMPFXController;
Expand Down Expand Up @@ -47,7 +49,7 @@ private void load() {
boolean cont = true;
if (StateMachine.isModified())
cont = Dialog.showYesNoDialog("The current song has been modified!\n"
+ "Load the song anyway?");
+ "Load anyway?");
if (cont) {
try {
FileChooser f = new FileChooser();
Expand All @@ -60,19 +62,21 @@ private void load() {
ObjectInputStream o_in = new
ObjectInputStream(f_in);
StaffSequence loaded = (StaffSequence) o_in.readObject();
normalize(loaded);
theStaff.setSequence(loaded);
StateMachine.setTempo(loaded.getTempo());
theStaff.getControlPanel().updateCurrTempo();
theStaff.getControlPanel().getScrollbar().setMax(
loaded.getTheLines().size());
loaded.getTheLines().size()
- Values.NOTELINES_IN_THE_WINDOW);
theStaff.getNoteMatrix().redraw();
o_in.close();
f_in.close();
String fname = inputFile.getName();
try {
fname = fname.substring(0, fname.indexOf("."));
} catch (IndexOutOfBoundsException e) {

// Do nothing
}
SMPFXController.getSongName().setText(fname);
StateMachine.setModified(false);
Expand All @@ -86,5 +90,18 @@ private void load() {
}
}

/**
* Makes a sequence fit on the screen.
* @param theSeq The sequence to normalize.
*/
private void normalize(StaffSequence theSeq) {
ArrayList<StaffNoteLine> theLines = theSeq.getTheLines();
while (theLines.size() % 4 != 0 ||
theLines.size() % Values.NOTELINES_IN_THE_WINDOW != 0) {
theLines.add(new StaffNoteLine(theLines.size()));
}

}


}
5 changes: 4 additions & 1 deletion src/smp/components/controls/OptionsButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
public class OptionsButton extends ImagePushButton {

/** This is the text that will be shown in the options dialog. */
private String txt = "";
private String txt = "Not implemented yet";



/**
* Default constructor.
Expand All @@ -48,6 +50,7 @@ private void options() {
dialog.setHeight(150);
dialog.setWidth(250);
dialog.setResizable(false);
dialog.setTitle("Options");
dialog.initStyle(StageStyle.UTILITY);
Label label = new Label(txt);
Button okButton = new Button("OK");
Expand Down
3 changes: 2 additions & 1 deletion src/smp/components/controls/SaveButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ private void saveObject() {
try {
FileChooser f = new FileChooser();
f.setInitialDirectory(new File(System.getProperty("user.dir")));
f.setInitialFileName(SMPFXController.getSongName().getText());
f.setInitialFileName(SMPFXController.getSongName().getText()
+ ".txt");
f.getExtensionFilters().addAll(
new ExtensionFilter("Text file", "*.txt"),
new ExtensionFilter("All files", "*"));
Expand Down
36 changes: 19 additions & 17 deletions src/smp/components/staff/Staff.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,16 @@ public synchronized void redraw() {

/** 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));
}
Platform.runLater(new Runnable() {
@Override
public void run() {
ArrayList<ImageView> playBars = staffImages.getPlayBars();
for(ImageView i : playBars) {
i.setImage(ImageLoader.getSpriteFX(
ImageIndex.NONE));
}
}
});
}


Expand All @@ -147,7 +152,8 @@ private void highlightsOff() {
public void startSong() {
highlightsOff();
lastLine = findLastLine();
if (lastLine == 0 && theSequence.getLine(0).isEmpty()) {
if ((lastLine == 0 && theSequence.getLine(0).isEmpty())
|| (lastLine < StateMachine.getMeasureLineNum())) {
theControls.getStopButton().reactPressed(null);
return;
}
Expand Down Expand Up @@ -175,15 +181,6 @@ public void stopSong() {
songPlaying = false;
animationService.cancel();
animationService.reset();
try {
Thread.sleep(1);
while (true) {
if (!animationService.isRunning())
break;
}
} catch (InterruptedException e) {

}
highlightsOff();
}

Expand Down Expand Up @@ -324,7 +321,12 @@ protected Task<Staff> createTask() {
*/
private void bumpHighlights(ArrayList<ImageView> playBars, int index,
boolean advance) {
highlightsOff();
for (int i = 0; i < playBars.size(); i++)
if (i != index)
playBars.get(i).setImage(
ImageLoader.getSpriteFX(ImageIndex.NONE));


playBars.get(index).setImage(
ImageLoader.getSpriteFX(ImageIndex.PLAY_BAR1));
if (advance && !zero)
Expand Down Expand Up @@ -418,8 +420,8 @@ protected Staff call() throws Exception {
// Do nothing
}
} while (songPlaying);
hitStop();
highlightsOff();
hitStop();
return theMatrix.getStaff();
}

Expand Down
4 changes: 2 additions & 2 deletions src/smp/fx/Dialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public void handle(ActionEvent event) {
*/
public static String showTextDialog(String txt) {
final Stage dialog = new Stage();
dialog.setHeight(150);
dialog.setWidth(250);
dialog.setHeight(125);
dialog.setWidth(150);
dialog.setResizable(false);
dialog.initStyle(StageStyle.UTILITY);
Label label = new Label(txt);
Expand Down

0 comments on commit 3a8becb

Please sign in to comment.