This plays Row Your Boat.
It uses the Mod class shown earlier to transpose the trumpet and clarinet parts above octave or below octave of the flute part.
package jfugue30;
import java.io.File;
import java.io.IOException;
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.midi.MidiFileManager;
import org.jfugue.pattern.Pattern;
import org.jfugue.player.Player;
public class JFugue30 extends Application {
public static void main(String[] args) {
launch(args);
}
TextArea text;
Button button;
@Override
public void start(Stage primaryStage) throws Exception {
button = new Button("Play Row\n\tYour\n"
+ "\tBoat");
button.setOnAction(e->example());
button.setFont(Font.font("Verdana", 16));
button.setPrefSize(200, 100);
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);
primaryStage.setTitle("JFugue 30. Row Your Boat");
primaryStage.setScene(scene);
primaryStage.show();
}
private void example() {
Player player = new Player();
Pattern flute = new Pattern();
flute.add("C5q C5q C5i. D5s E5q E5i. D5s E5i. F5s G5h")
.add("C6i C6i C6i G5i G5i G5i E5i E5i E5i C5i")
.add("C5i C5i")
.add("G5i. F5s E5i. D5s C5h")
.repeat(2);
Pattern trumpet =
new Pattern(Mod.transposeFromPattern(flute, 12));
Pattern clarinet =
new Pattern(Mod.transposeFromPattern(flute, -12));
flute.prepend("V0 I[FLUTE]");
trumpet.prepend("V1 I[TRUMPET] R/1.0");
clarinet.prepend("V2 I[CLARINET] R/2.0");
Pattern pattern = new Pattern(flute, trumpet, clarinet);
pattern.setTempo(108);
text.appendText("\n\nPattern:\n" + pattern + "\n");
try {
MidiFileManager.savePatternToMidi(pattern,
new File("RowYourBoat.mid"));
} catch (IOException ex) {
}
player.play(pattern);
}
}
This is the output:
You can open the saved midi file in a DAW. Here I use LMMS:
No comments:
Post a Comment