In JFugue we can refer to absolute time such as 1.5, which indicates middle of measure 2. measure 1 starts at 0. We have to use @ to indicate next value is absolute time.
Here we use @0.0 to indicate next note starts at measure 1 start. We do not have to indicate where rests are, as the note properties are enough to provide all details for the timing.
package jfugue14;
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.text.Font;
import javafx.stage.Stage;
import org.jfugue.pattern.Pattern;
import org.jfugue.player.Player;
public class JFugue14 extends Application {
public static void main(String[] args) {
launch(args);
}
TextArea text;
String[] bText =
{"Using +",
"Using @",
"Using @, root\nlargest velocity",
"Using @, root\nsmallest velocity",
"Using @, root\nlargest duration",
"Using @, root\nsmallest duration"};
Button[] buttons = new Button[bText.length];
String[] patts =
{"C+E+G",
"@0.0 C @0.0 E @0.0 G",
"@0.0 Ca74 @0.0 E @0.0 Ga54",
"@0.0 Ca54 @0.0 E @0.0 Ga74",
"@0.0 Ch @0.0 E @0.0 G",
"@0.0 C @0.0 E @0.0 Gh"};
@Override
public void start(Stage primaryStage) throws Exception {
int w = 250, h = 100;
for (int i = 0; i<buttons.length; i++){
String str = String.valueOf(i);
buttons[i] = new Button(bText[i]);
buttons[i].setOnAction( e-> example(str));
buttons[i].setPrefSize(w,h);
buttons[i].setFont(Font.font("Verdana", 16));
}
VBox examples = new VBox(10, buttons);
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);
primaryStage.setTitle("JFugue 14. Absolute Time");
primaryStage.setScene(scene);
primaryStage.show();
}
private void example(String string) {
int i = Integer.valueOf(string);
Player player = new Player();
Pattern pattern = new Pattern(patts[i]);
text.appendText("\n" + (i+1) +". Pattern:\t" + pattern);
player.play(pattern);
}
}
This is the output after the 6 buttons have been clicked:
No comments:
Post a Comment