Saturday, July 23, 2016

JFugue17. Chord progression from 2Pac's Changes (1998)

We play chord progression from 2Pac's Changes.


The pattern in patt1 is repeated twice. The tempo is set at 105. The dotted notes are indicated by putting a dot(.) after the duration such as q. for dotted quarter note. We have to be careful to put spacing between all tokens so they are properly parsed.


package jfugue17;

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;

public class JFugue17 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 2pac");
                
        button.setOnAction(e->example());
        
        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 17. Play 2Pac");
        
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    
    private void example() {
        
        Player player = new Player();
        
        String patt1 = "E5+G5+C5i. E5+G5+C6i. D5+G5+B5h A5s G5s "
                + "D5+F#5+A5i. D5+G5+B5i. C5+E5+G5q. E5i D5s C5s "
                + "G4+B5+D5q.";
        String patt2 = "A5s B5s";
        String patt = "T105 " + patt1 + " " + patt2 + " " + patt1;
        text.appendText("Playing pattern:\n" + patt + "\n\n");
        player.play(patt);
    }
}

This is the output after playing it twice:


No comments:

Post a Comment