Commit 9e338936 authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch15] Updated Beat box for better layout in the book

parent 5377bc65
Loading
Loading
Loading
Loading
+9 −9
Changes for src/main/java/ch15/BeatBox.java: 9 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ public class BeatBox {
    frame.setVisible(true);
  }

  public void setUpMidi() {
  private void setUpMidi() {
    try {
      sequencer = MidiSystem.getSequencer();
      sequencer.open();
@@ -97,7 +97,7 @@ public class BeatBox {
    }
  }

  public void buildTrackAndStart() {
  private void buildTrackAndStart() {
    int[] trackList;

    sequence.deleteTrack(track);
@@ -118,17 +118,22 @@ public class BeatBox {
      track.add(makeEvent(CONTROL_CHANGE, 1, 127, 0, 16));
    }

    track.add(makeEvent(192, 9, 1, 0, 15));
    track.add(makeEvent(PROGRAM_CHANGE, 9, 1, 0, 15));
    try {
      sequencer.setSequence(sequence);
      sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY);
      sequencer.start();
      sequencer.setTempoInBPM(120);
      sequencer.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void changeTempo(float tempoMultiplier) {
    float tempoFactor = sequencer.getTempoFactor();
    sequencer.setTempoFactor(tempoFactor * tempoMultiplier);
  }

  private void makeTracks(int[] list) {
    for (int i = 0; i < 16; i++) {
      int key = list[i];
@@ -140,11 +145,6 @@ public class BeatBox {
    }
  }

  private void changeTempo(float tempoMultiplier) {
    float tempoFactor = sequencer.getTempoFactor();
    sequencer.setTempoFactor(tempoFactor * tempoMultiplier);
  }

  public static MidiEvent makeEvent(int cmd, int chnl, int one, int two, int tick) {
    MidiEvent event = null;
    try {