FileDocCategorySizeDatePackage
MiniMusicPlayer3.javaAPI DocExample2974Sat Jan 08 12:06:56 GMT 2005None

MiniMusicPlayer3

public class MiniMusicPlayer3 extends Object

Fields Summary
static JFrame
f
static MyDrawPanel
ml
Constructors Summary
Methods Summary
public voidgo()

       setUpGui();

       try {

         // make (and open) a sequencer, make a sequence and track

         Sequencer sequencer = MidiSystem.getSequencer();         
         sequencer.open();
        
         sequencer.addControllerEventListener(ml, new int[] {127});
         Sequence seq = new Sequence(Sequence.PPQ, 4);
         Track track = seq.createTrack();     

         // now make two midi events (containing a midi message)

      int r = 0;
      for (int i = 0; i < 60; i+= 4) {

          r = (int) ((Math.random() * 50) + 1);
         
          track.add(makeEvent(144,1,r,100,i));
        
          track.add(makeEvent(176,1,127,0,i));
         
          track.add(makeEvent(128,1,r,100,i + 2));
       } // end loop
        
          // add the events to the track            
          // add the sequence to the sequencer, set timing, and start

          sequencer.setSequence(seq);
 
          sequencer.start();
          sequencer.setTempoInBPM(120);
      } catch (Exception ex) {ex.printStackTrace();}
  
public static voidmain(java.lang.String[] args)


         
           MiniMusicPlayer3 mini = new MiniMusicPlayer3();
           mini.go();
     
public javax.sound.midi.MidiEventmakeEvent(int comd, int chan, int one, int two, int tick)

          MidiEvent event = null;
          try {
            ShortMessage a = new ShortMessage();
            a.setMessage(comd, chan, one, two);
            event = new MidiEvent(a, tick);
            
          }catch(Exception e) { }
          return event;
       
public voidsetUpGui()

       ml = new MyDrawPanel();
       f.setContentPane(ml);
       f.setBounds(30,30, 300,300);
       f.setVisible(true);