The percussion sounds of midi instruments are on channel 10, or voice 9 in JFugue (V9).
In JFugue, we can use layers to deal with percussive sound. In example1(), we see how layers may be used. One bar of music is defined, 'O' is for BASS_DRUM and 'X' stands for HAND_CLAP, both of 8th note duration. The '.' indicates Rest of 8th note-duration. In example2() through example5(), we see alternative ways of creating same sound. We also have 5 buttons that will run one of the five example methods.
package jfugue6;
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.player.Player;
import org.jfugue.rhythm.Rhythm;
public class JFugue6 extends Application {
public static void main(String[] args) {
launch(args);
}
TextArea text;
Button button1, button2, button3, button4, button5;
@Override
public void start(Stage primaryStage) throws Exception {
button1 = new Button("Play Rhythm");
button2 = new Button("Play Pattern with Layers");
button3 = new Button("Play Pattern without\nLayers");
button4 = new Button("Play Pattern with MIDI \nNote Numbers");
button5 = new Button("Play Pattern with Notes");
button1.setPrefSize(150, 100);
button2.setPrefSize(150, 100);
button3.setPrefSize(150, 100);
button4.setPrefSize(150, 100);
button5.setPrefSize(150, 100);
button1.setOnAction(e->example1());
button2.setOnAction(e->example2());
button3.setOnAction(e->example3());
button4.setOnAction(e->example4());
button5.setOnAction(e->example5());
VBox examples = new VBox(10, button1, button2, button3,
button4, button5);
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 6. Rhythm");
primaryStage.setScene(scene);
primaryStage.show();
}
private void example1() {
Rhythm rhythm = new Rhythm()
.addLayer("O.O.O.O.")
.addLayer(".X.....X");
Player player = new Player();
player.play(rhythm.getPattern());
text.appendText("\n\n1. " + rhythm.getPattern().toString());
}
private void example2() {
Player player = new Player();
String patt = "V9 L0 [BASS_DRUM]i Ri [BASS_DRUM]i Ri "
+ "[BASS_DRUM]i Ri [BASS_DRUM]i Ri "
+ "L1 Ri [HAND_CLAP]i Ri Ri Ri Ri Ri [HAND_CLAP]i";
player.play(patt);
text.appendText("\n\n2. "+patt);
}
private void example3() {
Player player = new Player();
String patt = "V9 [BASS_DRUM]i [HAND_CLAP]i [BASS_DRUM]i Ri "
+ "[BASS_DRUM]i Ri [BASS_DRUM]i [HAND_CLAP]i";
player.play(patt);
text.appendText("\n\n3. "+patt);
}
private void example4() {
Player player = new Player();
String patt = "V9 36i 39i 36i Ri "
+ "36i Ri 36i 39i";
player.play(patt);
text.appendText("\n\n4. "+patt);
}
private void example5() {
Player player = new Player();
String patt = "V9 C3i Eb3i C3i Ri "
+ "C3i Ri C3i Eb3i";
player.play(patt);
text.appendText("\n\n5. "+patt);
}
}
This is the output after all five buttons have been clicked:
No comments:
Post a Comment