当前位置: 首页>>代码示例>>Java>>正文


Java VoiceEvt.setMidiChannel方法代码示例

本文整理汇总了Java中jm.midi.event.VoiceEvt.setMidiChannel方法的典型用法代码示例。如果您正苦于以下问题:Java VoiceEvt.setMidiChannel方法的具体用法?Java VoiceEvt.setMidiChannel怎么用?Java VoiceEvt.setMidiChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jm.midi.event.VoiceEvt的用法示例。


在下文中一共展示了VoiceEvt.setMidiChannel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import jm.midi.event.VoiceEvt; //导入方法依赖的package包/类
/**
 * Called from the JavaSound MIDI Input Port for each new MIDI event
 */
public void send(MidiMessage message, long deltaTime){
	System.out.println("New MIDI message");
	Event event = null;
	ByteArrayInputStream bais=new ByteArrayInputStream(message.getMessage());
	DataInputStream dis = new DataInputStream(bais);
	try{
		dis.mark(2);
		int status = dis.readUnsignedByte();
		int length = 0;
		//check running status
		if(status < 0x80){
			status = oldStatus;
			dis.reset();
		}
		if(status >= 0xFF){//MetaEvent
			int type = dis.readUnsignedByte();
			length = MidiUtil.readVarLength(dis);
			event = MidiUtil.createMetaEvent(type);
		}else if(status >= 0xF0){ //System Exclusive -- Not Supported
			System.err.println("SysEX not supported");
			length = MidiUtil.readVarLength(dis);
		}else if(status >= 0x80){ //MIDI voice event
			short selection = (short) (status /0x10);
			short midiChannel = (short) (status - (selection * 0x10));
			VoiceEvt evt = (VoiceEvt)MidiUtil.createVoiceEvent(selection);
			evt.setMidiChannel(midiChannel);
			event = evt;
			if(event == null){
				throw new IOException("Read Error");
			}
		}
		if(event != null){
			event.setTime((int)deltaTime);
			event.read(dis);
		}
		oldStatus = status;
	}catch(Exception e){
		e.printStackTrace();
		System.exit(1);
	}
	this.notifyListeners(event);
}
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:46,代码来源:RTMidiIn.java

示例2: readTrackChunk

import jm.midi.event.VoiceEvt; //导入方法依赖的package包/类
/**
 * Reads a MIDI track chunk
 *
 * @param DataInputStream
 *            dis - the input stream to read from
 * @exception IOException
 */
private void readTrackChunk(DataInputStream dis) throws IOException {
    // local variables for Track class
    Track track = new Track();
    // Insert new Track into a list of tracks
    this.trackList.addElement(track);
    int deltaTime = 0;
    // Read track header
    if (dis.readInt() != 0x4D54726B) {// If MTrk read is wrong
        throw new IOException("Track started in wrong place!!!!  ABORTING");
    } else {// If MTrk read ok get bytesRemaining
        dis.readInt();
    }
    // loop variables
    int status, oldStatus = 0, eventLength = 0;
    // Start gathering event data
    Event event = null;
    while (true) {
        try {
            // get variable length timestamp
            deltaTime = MidiUtil.readVarLength(dis);
            // mark stream so we can return if we need running status
            dis.mark(2);
            status = dis.readUnsignedByte();
            // decide on running status
            if (status < 0x80) { // set running status
                status = oldStatus;
                // return stream to before status read
                dis.reset();
            }
            // create default event of correct type
            if (status >= 0xFF) { // Meta Event
                int type = dis.readUnsignedByte();
                eventLength = MidiUtil.readVarLength(dis);
                event = jm.midi.MidiUtil.createMetaEvent(type);
            } else if (status >= 0xF0) { // System Exclusive --- NOT
                                         // SUPPORTED
                eventLength = MidiUtil.readVarLength(dis);
            } else if (status >= 0x80) { // MIDI voice event
                short selection = (short) (status / 0x10);
                short midiChannel = (short) (status - (selection * 0x10));
                VoiceEvt evt = (VoiceEvt) MidiUtil.createVoiceEvent(selection);
                if (evt == null) {
                    throw new IOException("MIDI file read error: invalid voice event type!");
                }
                evt.setMidiChannel(midiChannel);
                event = evt;
            }
            oldStatus = status;
        } catch (EOFException ex) {
            logger.warn("EOFException (" + ex.getMessage() + ") encountered in SMFTools");
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
        if (event != null) {
            // read data into the new event and
            // add the new event to the Track object
            event.setTime(deltaTime);
            event.read(dis);
            track.addEvent(event);
            // event.print();
            if (event instanceof EndTrack)
                break;
        } else {
            // skip the stream ahead to next valid event
            dis.skipBytes(eventLength);
        }
    }
}
 
开发者ID:Glamdring,项目名称:computoser,代码行数:76,代码来源:SMFTools.java

示例3: send

import jm.midi.event.VoiceEvt; //导入方法依赖的package包/类
/**
 * Called from the JavaSound MIDI Input Port for each new MIDI event
 */
public void send(MidiMessage message, long deltaTime){
	System.out.println("New MIDI message");
	Event event = null;
	ByteArrayInputStream bais=new ByteArrayInputStream(message.getMessage());
	DataInputStream dis = new DataInputStream(bais);
	try{
		dis.mark(2);
		int status = dis.readUnsignedByte();
		int length = 0;
		//check running status
		if(status < 0x80){
			status = oldStatus;
			dis.reset();
		}
		if(status >= 0xFF){//MetaEvent
			int type = dis.readUnsignedByte();
			length = MidiUtil.readVarLength(dis);
			event = MidiUtil.createMetaEvent(type);
		}else if(status >= 0xF0){ //System Exclusive -- Not Supported
			System.out.println("SysEX---");
			length = MidiUtil.readVarLength(dis);
		}else if(status >= 0x80){ //MIDI voice event
			short selection = (short) (status /0x10);
			short midiChannel = (short) (status - (selection * 0x10));
			VoiceEvt evt = (VoiceEvt)MidiUtil.createVoiceEvent(selection);
			evt.setMidiChannel(midiChannel);
			event = evt;
			if(event == null){
				throw new IOException("Read Error");
			}
		}
		if(event != null){
			event.setTime((int)deltaTime);
			event.read(dis);
		}
		oldStatus = status;
	}catch(Exception e){
		e.printStackTrace();
		System.exit(1);
	}
	this.notifyListeners(event);
}
 
开发者ID:Armaxis,项目名称:jmg,代码行数:46,代码来源:RTMidiIn.java

示例4: readTrackChunk

import jm.midi.event.VoiceEvt; //导入方法依赖的package包/类
/**
 * Reads a MIDI track chunk
 * @param DataInputStream dis - the input stream to read from
 * @exception IOException
 */
private void readTrackChunk(DataInputStream dis) 
           throws IOException{
           //local variables for Track class
           Track track = new Track();
           //Insert new Track into a list of tracks
           this.trackList.addElement(track);  
           int deltaTime = 0;
           if(VERBOSE) System.out.println("Reading Track ..........");
           //Read track header
           if(dis.readInt() != 0x4D54726B){//If MTrk read is wrong
                   throw new IOException
                           ("Track started in wrong place!!!!  ABORTING");
           }else{//If MTrk read ok get bytesRemaining
                   dis.readInt();
           }
           //loop variables
           int status, oldStatus =0, eventLength = 0;
           //Start gathering event data
           Event event = null;
           while(true){
               try{
                   //get variable length timestamp
                   deltaTime = MidiUtil.readVarLength(dis); 
                   //mark stream so we can return if we need running status
                   dis.mark(2);
                   status = dis.readUnsignedByte();
                   //decide on running status
                   if(status < 0x80){ //set running status
                       status = oldStatus;
                       //return stream to before status read
                       dis.reset();
                   }
                   //create default event of correct type
                   if(status >= 0xFF){ //Meta Event
                       int type = dis.readUnsignedByte(); 
                       eventLength = MidiUtil.readVarLength(dis);
                       event = MidiUtil.createMetaEvent(type); 
                   }else if(status >= 0xF0){ //System Exclusive --- NOT SUPPORTED
                       System.out.println("SysEX---");
                       eventLength = MidiUtil.readVarLength( dis);
                   }else if(status >= 0x80){ //MIDI voice event 
                       short selection = (short) (status / 0x10);
                       short midiChannel = (short) (status - (selection * 0x10));
                       VoiceEvt evt = (VoiceEvt)MidiUtil.createVoiceEvent(selection);
                       evt.setMidiChannel(midiChannel);
                       event = evt;
                       if(event == null){
                          throw new IOException("MIDI file read error: invalid voice event type!");
                       }
                   }
                   oldStatus = status;
               }catch(Exception e){
                   e.printStackTrace();
                   System.exit(1);
               }   
               if(event != null){
                   //read data into the new event and
                   //add the new event to the Track object
                   event.setTime(deltaTime);
                   event.read(dis);
                   //if (VERBOSE) event.print();
                   track.addEvent(event);
                   //event.print();
                   if(event instanceof EndTrack)
                           break;
               }else{
                   //skip the stream ahead to next valid event
                   dis.skipBytes(eventLength);
               }	
           }
}
 
开发者ID:Armaxis,项目名称:jmg,代码行数:77,代码来源:SMF.java


注:本文中的jm.midi.event.VoiceEvt.setMidiChannel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。