Package javax.sound.midi

Examples of javax.sound.midi.MidiEvent


              long tick)
    throws InvalidMidiDataException{
   
    ShortMessage msg = new ShortMessage();
    msg.setMessage(0xB0 + channel, controlNum, value);
    MidiEvent evt = new MidiEvent(msg, tick);
    return evt;
  }
View Full Code Here


                //Track currTrack = sequence.createTrack();

                currentTime = phrase.getStartTime();
                long phraseTick = (long)(currentTime * m_ppqn * trackTempoRatio);
                MidiEvent evt;

                if (phrase.getInstrument() != NO_INSTRUMENT) instrument = phrase.getInstrument();
                evt = createProgramChangeEvent(currChannel, instrument, phraseTick);
                currTrack.add(evt);

                m_tempoHistory.push(new Float(m_currentTempo));

                tempo = new Float(phrase.getTempo()).floatValue();
                if (tempo != Phrase.DEFAULT_TEMPO) {
                    m_currentTempo = tempo;
                    //System.out.println("jMusic MidiSynth notification: Phrase TempoEvent (BPM) = " + tempo);
                }

                elementTempoRatio = m_masterTempo/m_currentTempo;

                double lastPanPosition = -1.0
                int offSetTime = 0;         
                /// Each note
                Enumeration notes = phrase.getNoteList().elements();
                while(notes.hasMoreElements()) {
                    Note note = (Note) notes.nextElement();
                    // deal with offset
                    offSetTime = (int)(note.getOffset() * m_ppqn * elementTempoRatio);

          //handle frequency pitch types
          int pitch = -1;
          if(note.getPitchType() == Note.MIDI_PITCH) {
            pitch = note.getPitch();
          } else {
            pitch = Note.freqToMidiPitch(note.getFrequency());
          }

                    int dynamic = note.getDynamic();

                    if (pitch == Note.REST) {
                        phraseTick += note.getRhythmValue() * m_ppqn * elementTempoRatio;
                        continue;
                    }

                    long onTick = (long)(phraseTick);
                    // pan
                    if (note.getPan() != lastPanPosition) {
      evt = createCChangeEvent(currChannel, 10, (int)(note.getPan()*127), onTick);
      currTrack.add(evt);
      lastPanPosition = note.getPan();
        }

                    evt = createNoteOnEvent(currChannel, pitch, dynamic, onTick + offSetTime);
                    currTrack.add(evt);

                    long offTick = (long)(phraseTick + note.getDuration() * m_ppqn * elementTempoRatio);

                    evt = createNoteOffEvent(currChannel, pitch, dynamic, offTick + offSetTime);
                    currTrack.add(evt);

                    phraseTick += note.getRhythmValue() * m_ppqn * elementTempoRatio;

                    // TODO:  Should this be ticks since we have tempo stuff
                    // to worry about
                    //System.out.println("offtick = " + offTick + " ppq = " +
      //         m_ppqn + " score length = " + score.getEndTime() +
      //         " length * ppq = " + (m_ppqn * score.getEndTime()));
                    if ((double)offTick > longestTime) {
                        longestTime = (double)offTick;
                        longestTrack = currTrack;
                        //longestRatio = trackTempoRatio;
                    }
                }

                Float d = (Float)m_tempoHistory.pop();
                m_currentTempo = d.floatValue();

            } // while(phrases.hasMoreElements())

            Float d = (Float)m_tempoHistory.pop();
            m_currentTempo = d.floatValue();

        } // while(parts.hasMoreElements())

        // add a meta event to indicate the end of the sequence.
        if (longestTime > 0.0 && longestTrack != null) {
            MetaMessage msg = new MetaMessage();
            byte [] data = new byte[0];
            msg.setMessage(StopType, data, 0);
            MidiEvent evt = new MidiEvent(msg, (long)longestTime); //+ 100 if you want leave some space for reverb tail
            longestTrack.add(evt);
        }

        return sequence;
    }
View Full Code Here

                    } // switch sys-ex or meta
                    break;
                default:
                    throw new InvalidMidiDataException("Invalid status byte: " + status);
                } // switch
                track.add(new MidiEvent(message, tick));
            } // while
        } catch (ArrayIndexOutOfBoundsException e) {
            if (DEBUG) e.printStackTrace();
            // fix for 4834374
            throw new EOFException("invalid MIDI file");
View Full Code Here

          }
       }
    }
       
    public  MidiEvent makeEvent(int comd, int chan, int one, int two, int tick) {
        MidiEvent event = null;
        try {
            ShortMessage a = new ShortMessage();
            a.setMessage(comd, chan, one, two);
            event = new MidiEvent(a, tick);
           
        } catch(Exception e) {
      e.printStackTrace();
    }
        return event;
View Full Code Here

                    } // switch sys-ex or meta
                    break;
                default:
                    throw new InvalidMidiDataException("Invalid status byte: " + status);
                } // switch
                track.add(new MidiEvent(message, tick));
            } // while
        } catch (ArrayIndexOutOfBoundsException e) {
            if (DEBUG) e.printStackTrace();
            // fix for 4834374
            throw new EOFException("invalid MIDI file");
View Full Code Here

TOP

Related Classes of javax.sound.midi.MidiEvent

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.