An external MIDI file is loaded. Using a DAW, I created a 4-note MIDI file.
The file is loaded, and the pattern read. It should be note that velocity (in DAWs) is referred to as attack velocity (a) in the pattern string of JFugue. Also the 16 MIDI channels are referred to as V0 to V15, voice 0 to voice 15.
package jfugue3;
import java.io.File;
import java.io.IOException;
import java.net.URL;
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 javax.sound.midi.InvalidMidiDataException;
import org.jfugue.midi.MidiFileManager;
import org.jfugue.pattern.Pattern;
import org.jfugue.player.Player;
public class JFugue3 extends Application {
public static void main(String[] args) {
launch(args);
}
TextArea text;
Button button;
Player player;
@Override
public void start(Stage primaryStage) throws Exception {
button = new Button("Load MIDI");
button.setOnAction(e->example());
player = new Player();
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 3. Loading MIDI file");
primaryStage.setScene(scene);
primaryStage.show();
}
private void example() {
URL midURL = getClass().getResource("/JFugue3.mid");
String fileName = midURL.toString().substring(6);
Pattern pattern = null;
try {
pattern = MidiFileManager
.loadPatternFromMidi(new File(fileName));
} catch (IOException ex) {
} catch (InvalidMidiDataException ex) {
}
text.setText("\nPattern: " + pattern
+ "\nT100: Tempo 100 BPM"
+ "\nV0: MIDI channel 1"
+ "\nC6qa71: C6 quarter-note at 71 velocity"
+ "\nD6a80: D6 quarter-note at 80 velocity"
+ "\nE6ha90: D6 half-note at 90 velocity"
+ "\nF6ha101: F6 half-note at 101 velocity");
player.play(pattern);
}
}
This is the output:
No comments:
Post a Comment