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
public void go() { try { sq.open(); Sequence seq = new Sequence(Sequence.PPQ, 4); Track track = seq.createTrack(); track.add(addNote(144, 9, 56, 100, 1)); track.add(addNote(128, 9, 56, 100, 4)); sq.setSequence(seq); sq.setTempoInBPM(tempo); sq.setLoopCount(Sequencer.LOOP_CONTINUOUSLY); sq.start(); } catch (Exception ex) { ex.printStackTrace(); } }
/** Gets the default transmitter and receiver, and then links them. */ private void linkTransmitterToReceiver() { try { // Set up the sequencer (including its tempo) sequencer.open(); sequencer.setSequence(sequence); sequencer.setTempoInBPM(song.getBPM()); // Get the system's default synthesizer and set that up, too. Synthesizer synth = MidiSystem.getSynthesizer(); synth.open(); // Get the receiver and transmitter to use and set those up. Receiver receiver = synth.getReceiver(); Transmitter transmitter = sequencer.getTransmitter(); transmitter.setReceiver(receiver); } catch (Exception ex) { // Something went wrong. ex.printStackTrace(); System.exit(1); } }