MIDI

MIDI:Musical Instrument Digtial Interface

Five Steps:

1.Gets a Sequencer and open it

     Sequencer player=MidiSystem.getSequencer();

     player.open();

2. Make a new Sequence

    Sequence seq=new Sequence(timing,4);

3.Get a new Track from the Sequence;

   Track t=seq.CreateTrack();

4.Fill the Track with MidiEvents and give the Sequence to the Sequencer

   t.add(myMidiEvent1);

   player.setSequence(seq);

 Example:

import javax.sound.midi.*;

public class Untitled927 {
 
  public static void main(String[] args){
  Untitled927 one=new Untitled927();
  one.play();
 
  }
 
  public void play(){
  try{
    Sequencer player=MidiSystem.getSequencer();
    player.open();
   
    Sequence seq=new Sequence(Sequence.PPQ,4);
   
    Track track=seq.createTrack();
   
    ShortMessage a=new ShortMessage();
    a.setMessage(144,1,44,100);
    MidiEvent noteon=new MidiEvent(a,1);
    track.add(noteon);
   
    ShortMessage b=new ShortMessage();
    b.setMessage(128,1,44,100);
    MidiEvent noteoff=new MidiEvent(b,16);
    track.add(noteoff);
   
    player.setSequence(seq);
   
    player.start();
       
  }catch(Exception ex){
  ex.printStackTrace();
  }
   
  }
}

Make a MidiEvent (song data)

1.Make a Message

    ShortMessage a =new ShortMessage();

2.put  the Instruction in the Message

    a.setMessage(114,1,44,100);

3.Make a new MidiEvent using the Message

     MidiEvent noteon=new MidiEvent (a,1);

4.Add the MidiEvent to the Track

     track.add(noteon);

 

Midi message :the heart of a MidiEvent

 a.setMessage(Message type,channel,note to play, velocity);

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值