Example #1
0
  public void buildTrackAndStart() {
    int[] trackList = null;

    sequence.deleteTrack(track);
    track = sequence.createTrack();

    for (int i = 0; i < 16; i++) {
      trackList = new int[16];

      int key = instruments[i];

      for (int j = 0; j < 16; j++) {
        JCheckBox jc = (JCheckBox) checkboxList.get(j + (16 * i));
        if (jc.isSelected()) {
          trackList[j] = key;
        } else {
          trackList[j] = 0;
        }
      } // close inner loop

      makeTracks(trackList);
      track.add(makeEvent(176, 1, 127, 0, 16));
    } // close outer

    track.add(makeEvent(192, 9, 1, 0, 15));
    try {
      sequencer.setSequence(sequence);
      sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY);
      sequencer.start();
      sequencer.setTempoInBPM(120);
    } catch (Exception e) {
      e.printStackTrace();
    }
  } // close buildTrackAndStart method
Example #2
0
  public void go() {
    setUpGui();

    try {

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

      int r = 0;
      for (int i = 0; i < 300; 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

      sequencer.setSequence(seq);
      sequencer.start();
      sequencer.setTempoInBPM(120);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  } // close method
Example #3
0
  public void setUpMidi() {
    try {
      sequencer = MidiSystem.getSequencer();
      sequencer.open();
      sequence = new Sequence(Sequence.PPQ, 4);
      track = sequence.createTrack();
      sequencer.setTempoInBPM(120);

    } catch (Exception e) {
      e.printStackTrace();
    }
  } // close method
    public void actionPerformed(ActionEvent ev) {

      try {

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

        Sequencer sequencer = MidiSystem.getSequencer();
        sequencer.open();

        sequencer.addControllerEventListener(myPanel, new int[] {127});
        Sequence seq = new Sequence(Sequence.PPQ, 4);
        Track track = seq.createTrack();

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

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

          int rNum = (int) ((Math.random() * 50) + 1);
          if (rNum < 38) { // so now only do it if num <38 (75% of the time)

            track.add(makeEvent(144, 1, rNum, 100, i));

            track.add(makeEvent(176, 1, 127, 0, i));

            track.add(makeEvent(128, 1, rNum, 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(220);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    } // close actionperformed
  public void los() {
    guiErstellen();

    try {

      // einen Sequencer erzeugen (und öffnen),
      // eine Sequence und einen Track erzeugen

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

      // jetzt werden MidiEvents (die eine
      // MidiMessage enthalten) erzeugt

      int r = 0;
      for (int i = 0; i < 60; i += 4) {
        r = (int) ((Math.random() * 50) + 1);
        track.add(eventErzeugen(144, 1, r, 100, i));
        track.add(eventErzeugen(176, 1, 127, 0, i));
        track.add(eventErzeugen(128, 1, r, 100, i + 2));
      } // Ende der for-Schleife

      // Hinzufügen der Events zum Track und der Sequence
      // zum Sequencer, Setzen der Zeiten und Starten

      sequencer.setSequence(seq);
      sequencer.start();
      sequencer.setTempoInBPM(120);

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  } // Methode los schließen