Frage

Can someone show me how to control the volume of an MIDI sequencer without using a sound bank or synthesizer?

I want to make the MIDI fade out before continuing to the next MIDI in sequence

            if(midiplay)
            {

                midi = s + savereq;
                try {
                    //System.out.println("Play MIDI " + midi);
                    if (musicSr != null)
                    {
                                               /* This is where I want it to fade out*/
                        musicSr.stop(); //stop sequencer
                        musicSr.close(); //close sequencer
                    }
                    musicSr = null; 
                    musicS = null;

                    File music = new File(midi);
                    if(music.exists())
                    {
                        musicS = MidiSystem.getSequence(music);
                    }

                    // Create a sequencer for the sequence
                    musicSr = MidiSystem.getSequencer();
                            musicSr.open();
                            musicSr.setSequence(musicS);
                            musicSr.setLoopCount(musicSr.LOOP_CONTINUOUSLY);
                            musicSr.start();

                } catch (Exception ex) {
                    ex.printStackTrace();
                }


                midiplay = false;

            }
War es hilfreich?

Lösung

  1. Call getSequence to get the Sequence;
  2. call getTracks to get the list of tracks;
  3. in each track, for each channel used in the track, call add to add multiple events at the appropriate time positions:

    track.add(new MidiEvent(
        new ShortMessage(ShortMessage.CONTROL_CHANGE, channel, 7, volume),
        tick));
    
  4. maybe remove other volume change events (that would interfere with your fadeout) from the track;
  5. wait a little time for the fadeout to happen.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top