### Pattern Configuration via API in JFugue Source: https://context7.com/dmkoelle/jfugue/llms.txt Demonstrates programmatic configuration of JFugue Patterns using method chaining. This allows setting voice, instrument, and other properties directly via the API for cleaner code. Requires JFugue library. ```java import org.jfugue.pattern.Pattern; import org.jfugue.player.Player; public class IntroToPatterns2 { public static void main(String[] args) { Pattern p1 = new Pattern("Eq Ch. | Eq Ch. | Dq Eq Dq Cq") .setVoice(0) .setInstrument("Piano"); Pattern p2 = new Pattern("Rw | Rw | GmajQQQ CmajQ") .setVoice(1) .setInstrument("Flute"); Player player = new Player(); player.play(p1, p2); } } ``` -------------------------------- ### Basic Music Playback with JFugue Player Source: https://context7.com/dmkoelle/jfugue/llms.txt Demonstrates basic music playback using the JFugue Player class. It takes a simple Staccato notation string representing musical notes and plays them. Requires the JFugue library. ```java import org.jfugue.player.Player; public class HelloWorld { public static void main(String[] args) { Player player = new Player(); player.play("C D E F G A B"); } } ``` -------------------------------- ### Advanced Chord Progression Manipulation in Java Source: https://context7.com/dmkoelle/jfugue/llms.txt Demonstrates using ChordProgression to transform chord sequences with indexing syntax for creating variations and arpeggios. Requires the JFugue library. ```java import org.jfugue.player.Player; import org.jfugue.theory.ChordProgression; public class AdvancedChordProgressions { public static void main(String[] args) { ChordProgression cp = new ChordProgression("I IV V"); Player player = new Player(); // Play each note of each chord as quarter notes player.play(cp.eachChordAs("$0q $1q $2q Rq")); // Play all chords with a specific rhythm pattern player.play(cp.allChordsAs("$0q $0q $0q $0q $1q $1q $2q $0q")); // Combine both methods: arpeggios in one voice, full chords in another player.play(cp.allChordsAs("$0 $0 $0 $0 $1 $1 $2 $0") .eachChordAs("V0 $0s $1s $2s Rs V1 $_q")); } } ``` -------------------------------- ### Basic Rhythm Creation and Layering in Java Source: https://context7.com/dmkoelle/jfugue/llms.txt Introduces JFugue's Rhythm API for creating drum patterns using character-based notation. Each character maps to a percussion instrument, allowing for layered sequences. Requires JFugue library. ```java import org.jfugue.player.Player; import org.jfugue.rhythm.Rhythm; public class IntroToRhythms { public static void main(String[] args) { // Each character maps to a percussion sound (O=bass drum, S=snare, `=hi-hat, +=crash) Rhythm rhythm = new Rhythm() .addLayer("O..oO...O..oOO..") // Bass drum pattern .addLayer("..S...S...S...S.") // Snare pattern .addLayer("````````````````") // Hi-hat pattern .addLayer("...............+"); // Crash cymbal new Player().play(rhythm.getPattern().repeat(2)); } } ``` -------------------------------- ### MIDI File Loading and Pattern Conversion in Java Source: https://context7.com/dmkoelle/jfugue/llms.txt Illustrates using JFugue's MidiFileManager to load MIDI files and convert them into JFugue's Staccato Pattern format for inspection and manipulation. Requires JFugue library. ```java import org.jfugue.midi.MidiFileManager; import org.jfugue.pattern.Pattern; import java.io.File; import java.io.IOException; import javax.sound.midi.InvalidMidiDataException; public class SeeMidi { public static void main(String[] args) throws IOException, InvalidMidiDataException { String fileName = "path/to/your/file.mid"; Pattern pattern = MidiFileManager.loadPatternFromMidi(new File(fileName)); System.out.println(pattern); // Prints Staccato notation of the MIDI file } } ``` -------------------------------- ### Chord Progressions with Music Theory in JFugue Source: https://context7.com/dmkoelle/jfugue/llms.txt Explains how to create chord progressions using JFugue's music theory features. It demonstrates generating chords based on Roman numeral notation and a specified key, and playing the progression. Requires JFugue library. ```java import org.jfugue.player.Player; import org.jfugue.theory.Chord; import org.jfugue.theory.ChordProgression; import org.jfugue.theory.Note; public class IntroToChordProgressions { public static void main(String[] args) { ChordProgression cp = new ChordProgression("I IV V"); Chord[] chords = cp.setKey("C").getChords(); for (Chord chord : chords) { System.out.print("Chord " + chord + " has these notes: "); Note[] notes = chord.getNotes(); for (Note note : notes) { System.out.print(note + " "); } System.out.println(); } Player player = new Player(); player.play(cp); } } ``` -------------------------------- ### Temporal Event Anticipation with TemporalPLP in Java Source: https://context7.com/dmkoelle/jfugue/llms.txt Demonstrates using TemporalPLP with Player.delayPlay() to receive musical events before they are played. This is useful for animations or visualizations that require preparation time. It uses JFugue's temporal and player functionalities. ```java import org.jfugue.devtools.DiagnosticParserListener; import org.jfugue.player.Player; import org.jfugue.temporal.TemporalPLP; import org.staccato.StaccatoParser; public class TemporalExample { private static final String MUSIC = "C D E F G A B"; private static final long TEMPORAL_DELAY = 500; public static void main(String[] args) { // Part 1: Parse the original music and capture timing StaccatoParser parser = new StaccatoParser(); TemporalPLP plp = new TemporalPLP(); parser.addParserListener(plp); parser.parse(MUSIC); // Part 2: Receive events early, while actual music plays with delay DiagnosticParserListener dpl = new DiagnosticParserListener(); plp.addParserListener(dpl); new Player().delayPlay(TEMPORAL_DELAY, MUSIC); plp.parse(); // This fires events 500ms before they're heard } } ``` -------------------------------- ### Twelve-Bar Blues Generation in Java Source: https://context7.com/dmkoelle/jfugue/llms.txt Shows how to generate a twelve-bar blues progression using JFugue's fluent API and ChordProgression. It involves method chaining for chord extensions, bar sequences, and dynamics. Requires JFugue library. ```java import org.jfugue.pattern.Pattern; import org.jfugue.player.Player; import org.jfugue.theory.ChordProgression; import java.io.IOException; public class TwelveBarBlues { public static void main(String[] args) throws IOException { // Create I-IV-V progression with 7th and 6th extensions Pattern pattern = new ChordProgression("I IV V") .distribute("7%6") // Add maj7th and 6th to each chord .allChordsAs("$0 $0 $0 $0 $1 $1 $0 $0 $2 $1 $0 $0") // 12-bar pattern .eachChordAs("$0ia100 $1ia80 $2ia80 $3ia80 $4ia100 $3ia80 $2ia80 $1ia80") // Arpeggio with dynamics .getPattern() .setInstrument("Acoustic_Bass") .setTempo(100); new Player().play(pattern); } } ``` -------------------------------- ### Java: Play a simple melody with JFugue Source: https://github.com/dmkoelle/jfugue/blob/master/README.md This Java code snippet demonstrates the basic usage of the JFugue Player to play a sequence of musical notes. It requires the JFugue library to be included in the project. The output is a simple C major scale played sequentially. ```java import org.jfugue.player.Player; public class HelloWorld { public static void main(String[] args) { Player player = new Player(); player.play("C D E F G A B"); } } ``` -------------------------------- ### Lindenmayer System Fractal Music with JFugue Source: https://context7.com/dmkoelle/jfugue/llms.txt This Java code snippet illustrates algorithmic composition using JFugue and Lindenmayer (L-system) string rewriting rules. It defines transformation rules and an axiom, then uses `ReplacementMapPreprocessor` with specified iterations to generate and play a fractal-like musical structure with multiple instruments. ```java import org.jfugue.pattern.Pattern; import org.jfugue.player.Player; import org.staccato.ReplacementMapPreprocessor; import java.util.HashMap; import java.util.Map; public class LSystemMusic { public static void main(String[] args) { // Define L-system transformation rules Map rules = new HashMap() {{ put("Cmajw", "Cmajw Fmajw"); put("Fmajw", "Rw Bbmajw"); put("Bbmajw", "Rw Fmajw"); put("C5q", "C5q G5q E6q C6q"); put("E6q", "G6q D6q F6i C6i D6q"); put("G6i+D6i", "Rq Rq G6i+D6i G6i+D6i Rq"); }}; // Configure preprocessor for 4 iterations ReplacementMapPreprocessor rmp = ReplacementMapPreprocessor.getInstance(); rmp.setReplacementMap(rules); rmp.setIterations(4); rmp.setRequireAngleBrackets(false); // Create initial axiom pattern Pattern axiom = new Pattern("T120 " + "V0 I[Flute] Rq C5q " + "V1 I[Tubular_Bells] Rq Rq Rq G6i+D6i " + "V2 I[Piano] Cmajw E6q " + "V3 I[Warm] E6q G6i+D6i " + "V4 I[Voice] C5q E6q"); Player player = new Player(); System.out.println(rmp.preprocess(axiom.toString(), null)); player.play(axiom); } } ``` -------------------------------- ### Solfege Notation with JFugue Replacement Map Source: https://context7.com/dmkoelle/jfugue/llms.txt This Java code snippet demonstrates how to use JFugue's `ReplacementMapPreprocessor` with a `SolfegeReplacementMap` to play music using solfege syllables (Do Re Mi). It shows how to configure the preprocessor to translate solfege into standard Staccato notation, both with and without angle brackets for duration specification. ```java import org.jfugue.pattern.Pattern; import org.jfugue.player.Player; import org.staccato.ReplacementMapPreprocessor; import org.staccato.maps.SolfegeReplacementMap; public class SolfegeReplacementMapDemo { public static void main(String[] args) { ReplacementMapPreprocessor rmp = ReplacementMapPreprocessor.getInstance(); rmp.setReplacementMap(new SolfegeReplacementMap()) .setRequireAngleBrackets(false); Player player = new Player(); player.play(new Pattern("do re mi fa so la ti do")); // Plays C D E F G A B C // Enable brackets to add durations rmp.setRequireAngleBrackets(true); player.play(new Pattern("q q h | q q h | q q h | q q h")); } } ``` -------------------------------- ### Advanced Rhythm Variations in Java Source: https://context7.com/dmkoelle/jfugue/llms.txt Demonstrates advanced rhythm manipulation in JFugue, including dynamic layer substitution for one-time and recurring alternate patterns, creating fills and breaks. Requires JFugue library. ```java import org.jfugue.player.Player; import org.jfugue.rhythm.Rhythm; public class AdvancedRhythms { public static void main(String[] args) { Rhythm rhythm = new Rhythm() .addLayer("O..oO...O..oOO..") // Layer 0 .addLayer("..S...S...S...S.") // Layer 1 .addLayer("````````````````") // Layer 2 .addLayer("...............+") // Layer 3 .addOneTimeAltLayer(3, 3, "...+...+...+...+") // Replace layer 3 on 4th measure .setLength(4); // 4 measures total new Player().play(rhythm.getPattern().repeat(2)); } } ``` -------------------------------- ### Realtime Interactive Music with RealtimePlayer in Java Source: https://context7.com/dmkoelle/jfugue/llms.txt Enables realtime music interaction by controlling note starts/stops, instruments, and patterns without latency using RealtimePlayer. It takes user input to trigger musical events. Requires JFugue and Java standard libraries. ```java import org.jfugue.pattern.Pattern; import org.jfugue.realtime.RealtimePlayer; import org.jfugue.theory.Note; import java.util.Random; import java.util.Scanner; import javax.sound.midi.MidiUnavailableException; public class RealtimeExample { private static Pattern[] PATTERNS = new Pattern[] { new Pattern("Cmajq Dmajq Emajq"), new Pattern("V0 Ei Gi Di Ci V1 Gi Ci Fi Ei"), new Pattern("V0 Cmajq V1 Gmajq") }; public static void main(String[] args) throws MidiUnavailableException { RealtimePlayer player = new RealtimePlayer(); Random random = new Random(); Scanner scanner = new Scanner(System.in); boolean quit = false; while (quit == false) { System.out.print("Enter a '+C' to start a note, '-C' to stop a note, " + "'i' for a random instrument, 'p' for a pattern, or 'q' to quit: "); String entry = scanner.next(); if (entry.startsWith("+")) { player.startNote(new Note(entry.substring(1))); } else if (entry.startsWith("-")) { player.stopNote(new Note(entry.substring(1))); } else if (entry.equalsIgnoreCase("i")) { player.changeInstrument(random.nextInt(128)); } else if (entry.equalsIgnoreCase("p")) { player.play(PATTERNS[random.nextInt(PATTERNS.length)]); } else if (entry.equalsIgnoreCase("q")) { quit = true; } } scanner.close(); player.close(); } } ``` -------------------------------- ### Pattern Manipulation and Composition in JFugue Source: https://context7.com/dmkoelle/jfugue/llms.txt Illustrates how to use JFugue's Pattern objects to encapsulate and manage musical sequences. Patterns can be combined and manipulated, providing an abstraction for building complex compositions. Requires JFugue library. ```java import org.jfugue.pattern.Pattern; import org.jfugue.player.Player; public class IntroToPatterns { public static void main(String[] args) { Pattern p1 = new Pattern("V0 I[Piano] Eq Ch. | Eq Ch. | Dq Eq Dq Cq"); Pattern p2 = new Pattern("V1 I[Flute] Rw | Rw | GmajQQQ CmajQ"); Player player = new Player(); player.play(p1, p2); } } ``` -------------------------------- ### Multi-Voice and Multi-Instrument JFugue Compositions Source: https://context7.com/dmkoelle/jfugue/llms.txt Shows how to create complex musical arrangements with multiple voices and instruments playing simultaneously. It utilizes Staccato notation for voice, instrument, duration, chords, and rests. Requires JFugue library. ```java import org.jfugue.player.Player; public class HelloWorld2 { public static void main(String[] args) { Player player = new Player(); // V0/V1 = voices, I[instrument], q=quarter note, h=half, w=whole, R=rest // Chords: Gmaj, Cmaj; Duration modifiers: . = dotted player.play("V0 I[Piano] Eq Ch. | Eq Ch. | Dq Eq Dq Cq V1 I[Flute] Rw | Rw | GmajQQQ CmajQ"); } } ``` -------------------------------- ### Parse MIDI with Custom Listeners in Java Source: https://context7.com/dmkoelle/jfugue/llms.txt Parses a MIDI file using MidiParser and converts it to a Staccato pattern via a StaccatoParserListener. This enables custom processing and format conversion of MIDI data. It requires the JFugue library and standard Java MIDI classes. ```java import org.jfugue.midi.MidiParser; import org.jfugue.pattern.Pattern; import org.jfugue.player.Player; import org.staccato.StaccatoParserListener; import java.io.File; import java.io.IOException; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiSystem; public class ParserDemo { public static void main(String[] args) throws InvalidMidiDataException, IOException { String fileName = "path/to/your/file.mid"; MidiParser parser = new MidiParser(); StaccatoParserListener listener = new StaccatoParserListener(); parser.addParserListener(listener); parser.parse(MidiSystem.getSequence(new File(fileName))); Pattern staccatoPattern = listener.getPattern(); System.out.println(staccatoPattern); Player player = new Player(); player.play(staccatoPattern); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.