-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FrenchHornDemo to test sound on the conference
(cherry picked from commit 1adcaf4)
- Loading branch information
1 parent
a1b188c
commit d282c57
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
tea-service/src/main/java/org/example/teahouse/tea/FrenchHornDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.example.teahouse.tea; | ||
|
||
import javax.sound.midi.MidiChannel; | ||
import javax.sound.midi.MidiSystem; | ||
import javax.sound.midi.MidiUnavailableException; | ||
import javax.sound.midi.Synthesizer; | ||
|
||
public class FrenchHornDemo { | ||
public static void main(String[] args) throws MidiUnavailableException, InterruptedException { | ||
Synthesizer synthesizer = MidiSystem.getSynthesizer(); | ||
synthesizer.open(); | ||
MidiChannel channel = synthesizer.getChannels()[0]; | ||
// French Horn is bank #0 preset #60 | ||
channel.programChange(synthesizer.getAvailableInstruments()[60].getPatch().getProgram()); | ||
|
||
// C4 (middle C) | ||
int note = 60; | ||
try { | ||
channel.noteOn(note, 90); | ||
Thread.sleep(1_000); | ||
} | ||
finally { | ||
channel.noteOff(note); | ||
} | ||
} | ||
} |