Package jm.midi.event

Examples of jm.midi.event.Event


    public void print() {
        System.out.println("------------------");
        System.out.println("Track");
        Enumeration enum1 = eventList.elements();
        while (enum1.hasMoreElements()) {
            Event event = (Event) enum1.nextElement();
            //event.print();
        }
        //System.out.println();
    }
View Full Code Here


            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;
View Full Code Here

        int header = 0x4D54726B;
        Enumeration aEnum = track.getEvtList().elements();
        aEnum = track.getEvtList().elements();
        //At this stage Except that all events are NoteOn events
        while (aEnum.hasMoreElements()) {
            Event evt = (Event) aEnum.nextElement();
            evt.write(dos);
            if (DEBUG) evt.print();
        }
        //Write to the real stream
        odos.writeInt(header);
        odos.writeInt(baos.size());
        odos.write(baos.toByteArray(), 0, baos.size());
View Full Code Here

    /**
     * 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);
View Full Code Here

  /**
   * 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);
View Full Code Here

        double[] currentLength = new double[100];
        Note[] curNote = new Note[100];
        int phrIndex = 0;
        // Go through evts
        for (int i = 0; i < evtList.size(); i++) {
            Event evt = (Event) evtList.elementAt(i);
            startTime += (double) evt.getTime() / (double) smf.getPPQN();
            if (evt.getID() == 007) {
                PChange pchg = (PChange) evt;
                part.setInstrument(pchg.getValue());
                // if this event is a NoteOn event go on
            } else if (evt.getID() == 005) {
                NoteOn noteOn = (NoteOn) evt;
                part.setChannel(noteOn.getMidiChannel());
                short pitch = noteOn.getPitch();
                int dynamic = noteOn.getVelocity();
                short midiChannel = noteOn.getMidiChannel();
View Full Code Here

            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 {
View Full Code Here

        int header = 0x4D54726B;
        Enumeration en = track.getEvtList().elements();
        en = track.getEvtList().elements();
        // At this stage Except that all events are NoteOn events
        while (en.hasMoreElements()) {
            Event evt = (Event) en.nextElement();
            evt.write(dos);
            if (DEBUG)
                evt.print();
        }
        // Write to the real stream
        odos.writeInt(header);
        odos.writeInt(baos.size());
        odos.write(baos.toByteArray(), 0, baos.size());
View Full Code Here

TOP

Related Classes of jm.midi.event.Event

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.