Package javax.sound.midi

Examples of javax.sound.midi.Sequence


        this.midiFile = midiFile;

        try {
            sequencer = MidiSystem.getSequencer(false);
            sequencer.open();
            Sequence seq = MidiSystem.getSequence(midiFile);
            sequencer.setSequence(seq);
            if (loop) {
                sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
            }
        } catch (MidiUnavailableException e) {
View Full Code Here


    //TODO pool synthesizers

    public static void midi2wav(InputStream is, OutputStream os) {
        try {
            Sequence sequence = MidiSystem.getSequence(is);
            render(sequence, os);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

      Sequencer sequencer = MidiSystem.getSequencer(); //Create a new midi system sequencer
      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)
      {
View Full Code Here

      if (sound instanceof Clip) {
        Clip clip = (Clip) sound;
        clip.setFramePosition(0);
        clip.start();
      } else if (sequencer != null && sound instanceof Sequence) {
        Sequence sequence = (Sequence) sound;
        try {
          sequencer.setSequence(sequence);
          sequencer.start();
        } catch (InvalidMidiDataException e) {
          System.err.println(e.getMessage());
View Full Code Here

        if ((format.getType() != 0) && (format.getType() != 1)) {
            throw new InvalidMidiDataException("Invalid or unsupported file type: "  + format.getType());
        }

        // construct the sequence object
        Sequence sequence = new Sequence(format.getDivisionType(), format.getResolution());

        // for each track, go to the beginning and read the track events
        for (int i = 0; i < smfParser.tracks && smfParser.nextTrack(); i++) {
            smfParser.readTrack(sequence.createTrack());
        }
        return sequence;
    }
View Full Code Here

     * @throws IOException if an I/O exception occurs
     */
    public Sequence getSequence(URL url) throws InvalidMidiDataException, IOException {
        InputStream is = new BufferedInputStream(url.openStream(),
                                bisBufferSize); // throws IOException
        Sequence seq;
        try {
            seq = getSequence(is);
        } finally {
            is.close();
        }
View Full Code Here

     * @throws IOException if an I/O exception occurs
     */
    public Sequence getSequence(File file) throws InvalidMidiDataException, IOException {
        InputStream is = new BufferedInputStream(new FileInputStream(file),
                                 bisBufferSize); // throws IOException
        Sequence seq;
        try {
            seq = getSequence(is);
        } finally {
            is.close();
        }
View Full Code Here

            stop();
        }
        this.strFilename = strFilename;
        File midiFile = new File(strFilename);

        Sequence sequence = null;
        if(strFilename.startsWith("http"))
            sequence=MidiSystem.getSequence(new URL(strFilename));
        else
            sequence = MidiSystem.getSequence(midiFile);
        sm_sequencer = MidiSystem.getSequencer();
View Full Code Here

        xhtml.startDocument();

        // MidiSystem expects the stream to support the mark feature
        InputStream buffered = new BufferedInputStream(stream);
        try {
            Sequence sequence = MidiSystem.getSequence(buffered);

            Track[] tracks = sequence.getTracks();
            metadata.set("tracks", String.valueOf(tracks.length));
            // TODO: Use XMPDM.TRACKS?

            Patch[] patches = sequence.getPatchList();
            metadata.set("patches", String.valueOf(patches.length));

            float type = sequence.getDivisionType();
            if (type == Sequence.PPQ) {
                metadata.set("divisionType", "PPQ");
            } else if (type == Sequence.SMPTE_24) {
                metadata.set("divisionType", "SMPTE_24");
            } else if (type == Sequence.SMPTE_25) {
View Full Code Here

    */
    protected Sequence scoreToSeq(Score score)
        throws InvalidMidiDataException {

        //Create the Sequence
        Sequence sequence = new Sequence(Sequence.PPQ, m_ppqn);
        if (null == sequence) {
            return null;
        }

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

TOP

Related Classes of javax.sound.midi.Sequence

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.