Saturday, July 23, 2016

JFugue18. Beethoven's Fur Elise

We play notes from Beethoven's Fur Elise.


The tokens, such as notes, should have space between them, and it does not matter how much. Thus it is better to put space before and after token since here some patterns are repeated.


package jfugue18;

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.realtime.RealtimePlayer;

public class JFugue18 extends Application {
    
    public static void main(String[] args) {
        launch(args);
    }
    
    TextArea text;
    Button button;
    RealtimePlayer rp;
    
    @Override
    public void stop() {
        rp.close();
    }
    
    @Override
    public void start(Stage primaryStage) throws Exception {
        
        
        rp = new RealtimePlayer();
        
        button = new Button("Play \nBeethoven's \nFur Elise");
                
        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 18. Beethoven's Fur Elise");
        
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    
    private void example() {
        
        String patt1 =" E6s D#6s E6s D#6s E6s B5s D6s C6s ";
        String patt2 = " A5i Rs C5s E5s A5s B5i Rs E5s ";
        String patt3 = " G#5s B5s C6i Rs E5s ";
        String patt4 = " C6s B5s A5i ";
 
        String patt = " T60 " + patt1 +  patt2 + patt3 
                + patt1 + patt2 + patt4;
        text.appendText("Playing pattern:\n" + patt + "\n\n");
        rp.play(patt);
    }
}

This is the output after playing it twice:


No comments:

Post a Comment