Package javax.sound.midi

Examples of javax.sound.midi.Track


    /** MIDI �C�x���g�̒P��V�[�P���X��ݒ肵�܂��B */
    public void setMidiSequence(Sequence midiSequence) {

        this.timeBase = midiSequence.getResolution();

        Track midiTracks[] = midiSequence.getTracks();
        for (int t = 0; t < midiTracks.length; t++) {
            for (int i = 0; i < midiTracks[t].size(); i++) {
                javax.sound.midi.MidiMessage midiMessage = midiTracks[t].get(i).getMessage();
                if (midiMessage instanceof MetaMessage &&
                    ((MetaMessage) midiMessage).getType() == MidiConstants.META_TEMPO) {
View Full Code Here


        while (true) {
            MidiEvent selevent = null;
            int seltrack = -1;
            for (int i = 0; i < tracks.length; i++) {
                int trackpos = trackspos[i];
                Track track = tracks[i];
                if (trackpos < track.size()) {
                    MidiEvent event = track.get(trackpos);
                    if (selevent == null || event.getTick() < selevent.getTick()) {
                        selevent = event;
                        seltrack = i;
                    }
                }
View Full Code Here

     * @return array of file types.  If no file types are supported,
     * returns an array of length 0.
     */
    public int[] getMidiFileTypes(Sequence sequence){
        int typesArray[];
        Track tracks[] = sequence.getTracks();

        if( tracks.length==1 ) {
            typesArray = new int[2];
            typesArray[0] = MIDI_TYPE_0;
            typesArray[1] = MIDI_TYPE_1;
View Full Code Here

    //=================================================================================


    private InputStream getFileStream(int type, Sequence sequence) throws IOException {
        Track tracks[] = sequence.getTracks();
        int bytesBuilt = 0;
        int headerLength = 14;
        int length = 0;
        int timeFormat;
        float divtype;
View Full Code Here

        while (true) {
            MidiEvent selevent = null;
            int seltrack = -1;
            for (int i = 0; i < tracks.length; i++) {
                int trackpos = trackspos[i];
                Track track = tracks[i];
                if (trackpos < track.size()) {
                    MidiEvent event = track.get(trackpos);
                    if (selevent == null || event.getTick() < selevent.getTick()) {
                        selevent = event;
                        seltrack = i;
                    }
                }
View Full Code Here

      sequencer.open();    //Open up the sequencer object we created
      sequencer.addControllerEventListener(ml, new int[] {127})
      //Add a control event listener using our ml object
     
      Sequence seq = new Sequence(Sequence.PPQ, 4);   //Create a new sequence with a type and res
      Track track = seq.createTrack();        //Set the track to our new track on seq
     
      int r = 0;
     
      for (int i = 5; i < 61; i += 4)
      {
       
        r = (int) ((Math.random() * 50) + 1);
       
        //Picking up the beats and adding our events to the track
        //Helps to add our rectangles along with the beat itself
        track.add(makeEvent(144, 1, r, 100,i));
        track.add(makeEvent(176, 1, 127, 0, i));
        track.add(makeEvent(128, 1, r, 100, i + 2));
       
      }
     
      //Set the sequencer's sequence to the Sequence object we created
      sequencer.setSequence(seq);
View Full Code Here

        m_masterTempo = m_currentTempo =
                new Float(score.getTempo()).floatValue();
        //System.out.println("jMusic MidiSynth notification: Score TempoEvent (BPM) = " + score.getTempo());

        Track longestTrack = null;
        double longestTime = 0.0;
        double longestRatio = 1.0;

        Enumeration parts = score.getPartList().elements();
        while (parts.hasMoreElements()) {
            Part inst = (Part) parts.nextElement();

            int currChannel = inst.getChannel();
            if (currChannel > 16) {
                throw new
                        InvalidMidiDataException(inst.getTitle() +
                        " - Invalid Channel Number: " +
                        currChannel);
            }

            m_tempoHistory.push(new Float(m_currentTempo));

            float tempo = new Float(inst.getTempo()).floatValue();
            //System.out.println("jMusic MidiSynth notification: Part TempoEvent (BPM) = " + tempo);
            if (tempo != Part.DEFAULT_TEMPO) {
                m_currentTempo = tempo;
            } else if (tempo < Part.DEFAULT_TEMPO)
                System.out.println("jMusic MidiSynth error: Part TempoEvent (BPM) too low = " + tempo);

            trackTempoRatio = m_masterTempo / m_currentTempo;

            int instrument = inst.getInstrument();
            if (instrument == NO_INSTRUMENT) instrument = 0;

            Enumeration phrases = inst.getPhraseList().elements();
            double max = 0;
            double currentTime = 0.0;

            //
            // One track per Part
            /////////////
            Track currTrack = sequence.createTrack();
            while (phrases.hasMoreElements()) {
                /////////////////////////////////////////////////
                // Each phrase represents a new Track element
                // Err no
                // There is a 65? track limit
                // ////////////////////////////
                Phrase phrase = (Phrase) phrases.nextElement();

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

        m_masterTempo = m_currentTempo =
            new Float(score.getTempo()).floatValue();
    //System.out.println("jMusic MidiSynth notification: Score TempoEvent (BPM) = " + score.getTempo());

        Track longestTrack = null;
        double longestTime = 0.0;
        double longestRatio = 1.0;

        Enumeration parts = score.getPartList().elements();
        while(parts.hasMoreElements()) {
            Part inst = (Part) parts.nextElement();

            int currChannel = inst.getChannel();
            if (currChannel > 16) {
                throw new
                    InvalidMidiDataException(inst.getTitle() +
                                            " - Invalid Channel Number: " +
                                            currChannel);
            }

            m_tempoHistory.push(new Float(m_currentTempo));

            float tempo = new Float(inst.getTempo()).floatValue();
      //System.out.println("jMusic MidiSynth notification: Part TempoEvent (BPM) = " + tempo);
            if (tempo != Part.DEFAULT_TEMPO) {
                m_currentTempo = tempo;
            } else if (tempo < Part.DEFAULT_TEMPO)
                System.out.println("jMusic MidiSynth error: Part TempoEvent (BPM) too low = " + tempo);

            trackTempoRatio = m_masterTempo/m_currentTempo;

            int instrument = inst.getInstrument();
            if (instrument == NO_INSTRUMENT) instrument = 0;

            Enumeration phrases = inst.getPhraseList().elements();
            double max = 0;
            double currentTime = 0.0;
     
      //
      // One track per Part
      /////////////
            Track currTrack=sequence.createTrack();
            while(phrases.hasMoreElements()) {
                /////////////////////////////////////////////////
                // Each phrase represents a new Track element
    // Err no
    // There is a 65? track limit
    // ////////////////////////////
                Phrase phrase = (Phrase) phrases.nextElement();

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

TOP

Related Classes of javax.sound.midi.Track

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.