Skip to content

Commit a23438d

Browse files
A few more comments
1 parent bee7598 commit a23438d

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

rubric.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
GRADE: 32/32
1+
GRADE: 31/32
22
------------
33

44
Functional requirements - 16 points
55
===================================
66
* 1/1 The window should have a Play Scale button.
77
* 1/1 The window should have a Stop Playing button.
8-
* 3/3 When the user clicks the Play scale button, a dialog appears asking the user for a note number in the range 0 to 115 (see the window on the right above).
8+
* 3/3 When the user clicks the Play scale button, a dialog appears asking the user for a note number in the range 0 to 115.
99
* 1/1 Then an 8-note scale is played starting at the given note.
10-
* 1/1 The scale should be the usual Do Re Mi Fa Sol La Ti Do notes going up in pitch.
10+
* 0/1 The scale should be the usual Do Re Mi Fa Sol La Ti Do notes going up in pitch. *See https://en.wikipedia.org/wiki/Solfège#Major *
1111
* 1/1 After playing the scale going up, it should then play the same scale again but going down from the highest note.
1212
* 1/1 The user might click the Play scale button when a scale is already being played. If the user clicks OK, then the scale being played should immediately stop and the new scale should be played instead. If the user clicks Cancel, then the scale currently playing should continue playing.
1313
* 1/1 When the user clicks the Stop playing button, the scale should stop playing immediately.
@@ -30,7 +30,8 @@ Elementary style - 4 points
3030
==========================
3131
* 1/1 Some attempt at descriptive method, parameter, and variable names.
3232
* 1/1 Consistent indentation.
33-
* 2/2 Appropriate use of basic language constructs; reasonably concise code.
33+
* 1/1 Appropriate use of basic language constructs; reasonably concise code.
34+
* 1/1 Code divided into methods.
3435

3536
Next time I will look for "self-explanatory code" and appropriate use of
3637
access modifiers.

src/scaleplayer/ScalePlayer.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,39 @@
2626
*/
2727
public class ScalePlayer extends Application {
2828

29+
//TODO: Why does this field exist?
2930
private static int startingNote;
31+
//TODO: Could this field be static, final?
3032
private MidiPlayer sequence = new MidiPlayer(2, 60);
3133

3234
/**
3335
* Start: Handles the menu bar, buttons, exits, and events.
34-
* @param primaryStage
36+
* @param primaryStage //TODO: What is it for?
3537
*/
3638
@Override
3739
public void start(Stage primaryStage) {
3840

3941
//create menu bar
4042
MenuBar menuBar = new MenuBar();
43+
//TODO: Is the next line necessary?
4144
menuBar.prefWidthProperty().bind(primaryStage.widthProperty());
4245
Menu file = new Menu("File");
4346
menuBar.getMenus().add(file);
4447
MenuItem exitMenuItem = new MenuItem("Exit");
4548
file.getItems().add(exitMenuItem);
4649
exitMenuItem.setOnAction(actionEvent -> System.exit(0));
4750
primaryStage.setOnCloseRequest(e -> System.exit(0));
51+
//TODO: Confusing that the above line is here,
52+
//as it's not part of creating the menu bar
4853

4954
//play button
5055
Button playBtn = new Button();
5156
playBtn.setText("Play Scale");
57+
//NOTE: The below is ugly, but you'll fix it with CSS
5258
playBtn.setStyle("-fx-base: #b6e7c9;");
59+
//TODO: Is an anonymous inner class necessary?
5360
playBtn.setOnAction(new EventHandler<ActionEvent>() {
54-
61+
//TODO: This is way too much code to nest inside another method.
5562
/**
5663
* Handles the start and gets a note from the user, and starts the MidiPlayer using sequence.
5764
* @param event
@@ -61,10 +68,12 @@ public void handle(ActionEvent event) {
6168
TextInputDialog dialog = new TextInputDialog();
6269
dialog.setTitle("Starting Note");
6370
dialog.setHeaderText("Please enter a note (0-115)");
71+
//TODO: Set a default text input value
6472

6573
//get result, parse it into an int in a roundabout way, then play scale once its had
6674
Optional<String> result = dialog.showAndWait();
6775
if (result.isPresent()){
76+
//TODO: Why not just set startingNote to Integer.parseInt(result)?
6877
String stringResult = result.toString();
6978
stringResult = stringResult.substring(9, stringResult.length()-1);
7079
startingNote = Integer.parseInt(stringResult);
@@ -76,9 +85,11 @@ public void handle(ActionEvent event) {
7685
});
7786

7887
//stop button
88+
//TODO: See comments above
7989
Button stopBtn = new Button();
8090
stopBtn.setText("Stop Playing");
8191
stopBtn.setStyle("-fx-base: #eda6a6;");
92+
//TODO: Is an anonymous inner class necessary?
8293
stopBtn.setOnAction(new EventHandler<ActionEvent>() {
8394

8495
/**
@@ -100,8 +111,9 @@ public void handle(ActionEvent event) {
100111
hbox.setAlignment(Pos.CENTER);
101112

102113
//Overhead for showing screen
114+
//NOTE: Good choice
103115
BorderPane root = new BorderPane();
104-
116+
105117
root.setTop(menuBar);
106118
root.setCenter(hbox);
107119

@@ -110,14 +122,18 @@ public void handle(ActionEvent event) {
110122
primaryStage.setTitle("Scale Player");
111123
primaryStage.setScene(scene);
112124
primaryStage.show();
125+
126+
//NOTE: This method is much too long.
113127
}
114128

115129

116130
/**
117131
* Stops the current MidiPlayer sequence
118-
* @param sequence
132+
* @param sequence //TODO: What is it?
119133
*/
134+
//TODO: Why is this public?
120135
public void stopScale(MidiPlayer sequence) {
136+
//TODO: Why do you need to define a one line method?
121137
sequence.stop();
122138
}
123139

@@ -126,6 +142,7 @@ public void stopScale(MidiPlayer sequence) {
126142
* @param sequence
127143
*/
128144
public void clearScale(MidiPlayer sequence) {
145+
//TODO: See above
129146
sequence.clear();
130147
}
131148

@@ -135,7 +152,12 @@ public void clearScale(MidiPlayer sequence) {
135152
* @param sequence
136153
* @param startingNote
137154
*/
155+
//TODO: Why public?
138156
public void playScale(MidiPlayer sequence, int startingNote) {
157+
//TODO: Fix this so it's a Do-Re-Mi scale
158+
//https://en.wikipedia.org/wiki/Solfège#Major
159+
//TODO: Replace magic numbers with constants
160+
//TODO: Fix indentation
139161
for(int i=1; i<9; i++)
140162
{
141163
sequence.addNote(startingNote, 100, i, 1,
@@ -161,4 +183,4 @@ public static void main(String[] args) {
161183
launch(args);
162184
}
163185

164-
}
186+
}

0 commit comments

Comments
 (0)