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
  private void autoscale() {

    int stateHash = FrameManager.getStateHash();

    //  if(lastFrameStateHash == stateHash) return;

    lastStateHash = stateHash;

    final Collection<Track> trackList = IGV.getInstance().getAllTracks();

    Map<String, List<Track>> autoscaleGroups = new HashMap<String, List<Track>>();

    for (Track track : trackList) {

      if (!track.isVisible()) continue;

      String asGroup = track.getAttributeValue(AttributeManager.GROUP_AUTOSCALE);
      if (asGroup != null) {
        if (!autoscaleGroups.containsKey(asGroup)) {
          autoscaleGroups.put(asGroup, new ArrayList<Track>());
        }
        autoscaleGroups.get(asGroup).add(track);
      } else if (track.getAutoScale()) {
        autoscaleGroup(Arrays.asList(track));
      }
    }

    if (autoscaleGroups.size() > 0) {
      for (List<Track> tracks : autoscaleGroups.values()) {
        autoscaleGroup(tracks);
      }
    }
  }
Example #3
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 #4
0
  public void makeTracks(int[] list) {

    for (int i = 0; i < 16; i++) {
      int key = list[i];

      if (key != 0) {
        track.add(makeEvent(144, 9, key, 100, i));
        track.add(makeEvent(128, 9, key, 100, i + 1));
      }
    }
  }
Example #5
0
  private void autoscaleGroup(List<Track> trackList) {

    List<ReferenceFrame> frames =
        FrameManager.isGeneListMode()
            ? FrameManager.getFrames()
            : Arrays.asList(FrameManager.getDefaultFrame());

    List<Range> inViewRanges = new ArrayList<Range>();

    synchronized (trackList) {
      for (Track track : trackList) {
        if (track instanceof ScalableTrack) {
          for (ReferenceFrame frame : frames) {
            Range range = ((ScalableTrack) track).getInViewRange(frame);
            if (range != null) {
              inViewRanges.add(range);
            }
          }
        }
      }

      if (inViewRanges.size() > 0) {

        Range inter = computeScale(inViewRanges);

        for (Track track : trackList) {

          DataRange dr = track.getDataRange();
          float min = Math.min(0, inter.min);
          float base = Math.max(min, dr.getBaseline());
          float max = inter.max;
          // Pathological case where min ~= max  (no data in view)
          if (max - min <= (2 * Float.MIN_VALUE)) {
            max = min + 1;
          }

          DataRange newDR = new DataRange(min, base, max, dr.isDrawBaseline());
          newDR.setType(dr.getType());
          track.setDataRange(newDR);
        }
      }
    }
  }
Example #6
0
 public boolean createEvent(int type, int num, long tick) {
   ShortMessage message = new ShortMessage();
   try {
     message.setMessage(type + cc.num, num, cc.velocity);
     MidiEvent event = new MidiEvent(message, tick);
     track.add(event);
     return true;
   } catch (Exception ex) {
     ex.printStackTrace();
     return false;
   }
 }
    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