Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import javax.sound.midi.*;
  2.  
  3. /**
  4. * Created by JK on 25.09.2017.
  5. */
  6. public class MiniMiniMusicApp {
  7.  
  8. public static void main(String[] args) {
  9. MiniMiniMusicApp mini = new MiniMiniMusicApp();
  10. mini.play();
  11. }
  12.  
  13. public void play() {
  14. try {
  15. Sequencer player = MidiSystem.getSequencer();
  16. player.open();
  17.  
  18. Sequence seq = new Sequence(Sequence.PPQ, 4);
  19.  
  20. Track track = seq.createTrack();
  21.  
  22. ShortMessage a = new ShortMessage();
  23. a.setMessage(144, 1, 44, 100);
  24. MidiEvent noteOn = new MidiEvent(a, 1);
  25. track.add(noteOn);
  26.  
  27. ShortMessage b = new ShortMessage();
  28. a.setMessage(128, 1, 44, 100);
  29. MidiEvent noteOff = new MidiEvent(b, 16);
  30. track.add(noteOn);
  31.  
  32. player.setSequence(seq);
  33.  
  34. player.start();
  35.  
  36. } catch (Exception ex) {
  37. ex.printStackTrace();
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement