Monday, July 11, 2016

JFugue 11. Chord Progression

We can use ChordProgression class to indicate scale degree.


The roman numeral and the key will get the chords which we can get using getPattern() method. We do not have to explicitly call the getPattern in the play() method.


You can quickly play the chords moving the mouse, from one button to another. We don't click as those events are not monitored via callbacks.


package jfugue11;

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;
import org.jfugue.theory.ChordProgression;

public class JFugue11 extends Application {
    
    public static void main(String[] args) {
        launch(args);
    }
    
    RealtimePlayer player;
    TextArea text;
    Button button1, button2;
    
    @Override
    public void stop() {
        player.close();
    }
    @Override
    public void start(Stage primaryStage) throws Exception {
        
        button1 = new Button("I IV V");
        button2 = new Button("ii iii vi");
        
        button1.setPrefSize(150, 100);
        button2.setPrefSize(150, 100);
        
                
        button1.setOnMouseEntered(e->example1());
        button2.setOnMouseEntered(e->example2());
        
        player = new RealtimePlayer();
        
        VBox examples = new VBox(10, button1, button2);
        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 11. Chord Progression");
        
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    
    private void example1() {
        ChordProgression cp = new ChordProgression(button1.getText())
                .setKey("D");
        text.appendText("\n" + cp.getPattern());
        player.play(cp);
    }
    
    private void example2() {
        ChordProgression cp = new ChordProgression(button2.getText())
                .setKey("D");
        text.appendText("\n" + cp.getPattern());
        player.play(cp);
    }
}

This is the output:


No comments:

Post a Comment