The JFugue jar has to be added to the Project for all JFugue applications and will be assumed from now on.
Here no sound is played. However the Note class is used to print the 128 MIDI numbers (0-127), their common names, and frequencies.
This will be the template from now on. There will be one button, or a set of buttons at left. The TextArea at right will be help screen and output of program. Most examples will have sound as well. For each button, we have two events which are monitored: setOnAction when it is clicked and setOnMouseEntered when the mouse hovers over the button. Right now, hovering prints heading and then clicking will print the 127 values, in separate lines.
package jfugue1;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import org.jfugue.theory.Note;
public class JFugue1 extends Application {
public static void main(String[] args) {
launch(args);
}
TextArea text;
@Override
public void start(Stage primaryStage) throws Exception {
Button button = new Button("Get Values ");
button.setOnAction(e->example());
button.setOnMouseEntered(e->help());
VBox examples = new VBox(10, button);
examples.setPadding(new Insets(10));
text = new TextArea();
text.setPrefRowCount(20);
text.setPrefColumnCount(32);
text.setFont(Font.font("Verdana", 20));
text.setEditable(false);
text.setWrapText(true);
HBox root = new HBox(50,examples,text);
Scene scene = new Scene(root, 900, 600, Color.LIGHTSKYBLUE);
primaryStage.setTitle("JFugue 1. MIDI numbers");
primaryStage.setScene(scene);
primaryStage.show();
}
private void example() {
String[] common = Note.NOTE_NAMES_COMMON;
Note note = new Note();
String string;
for (int i = 0; i<128; i++) {
note.setValue((byte)i);
string = "\n" + i
+ "\t\t" + common[note.getPositionInOctave()]
+ note.getOctave()
+ "\t\t"
+ String.format("%.1f",Note.getFrequencyForNote(i))
+ " Hz";
text.appendText(string);
}
}
private void help() {
String h = String.join("\n",
"MIDI Numbers, Common Note Names and Frequencies");
text.setText(h);
}
}
This is the output for the first few notes:
No comments:
Post a Comment