當前位置: 首頁>>代碼示例>>Java>>正文


Java Sequence.SMPTE_25屬性代碼示例

本文整理匯總了Java中javax.sound.midi.Sequence.SMPTE_25屬性的典型用法代碼示例。如果您正苦於以下問題:Java Sequence.SMPTE_25屬性的具體用法?Java Sequence.SMPTE_25怎麽用?Java Sequence.SMPTE_25使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在javax.sound.midi.Sequence的用法示例。


在下文中一共展示了Sequence.SMPTE_25屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMidiFileFormatFromStream

private MidiFileFormat getMidiFileFormatFromStream(InputStream stream,
                                                   int fileLength,
                                                   SMFParser smfParser)
        throws InvalidMidiDataException, IOException{
    int maxReadLength = 16;
    int duration = MidiFileFormat.UNKNOWN_LENGTH;
    DataInputStream dis;

    if (stream instanceof DataInputStream) {
        dis = (DataInputStream) stream;
    } else {
        dis = new DataInputStream(stream);
    }
    if (smfParser == null) {
        dis.mark(maxReadLength);
    } else {
        smfParser.stream = dis;
    }

    int type;
    int numtracks;
    float divisionType;
    int resolution;

    try {
        int magic = dis.readInt();
        if( !(magic == MThd_MAGIC) ) {
            // not MIDI
            throw new InvalidMidiDataException("not a valid MIDI file");
        }

        // read header length
        int bytesRemaining = dis.readInt() - 6;
        type = dis.readShort();
        numtracks = dis.readShort();
        int timing = dis.readShort();

        // decipher the timing code
        if (timing > 0) {
            // tempo based timing.  value is ticks per beat.
            divisionType = Sequence.PPQ;
            resolution = timing;
        } else {
            // SMPTE based timing.  first decipher the frame code.
            int frameCode = -1 * (timing >> 8);
            switch(frameCode) {
            case 24:
                divisionType = Sequence.SMPTE_24;
                break;
            case 25:
                divisionType = Sequence.SMPTE_25;
                break;
            case 29:
                divisionType = Sequence.SMPTE_30DROP;
                break;
            case 30:
                divisionType = Sequence.SMPTE_30;
                break;
            default:
                throw new InvalidMidiDataException("Unknown frame code: " + frameCode);
            }
            // now determine the timing resolution in ticks per frame.
            resolution = timing & 0xFF;
        }
        if (smfParser != null) {
            // remainder of this chunk
            dis.skip(bytesRemaining);
            smfParser.tracks = numtracks;
        }
    } finally {
        // if only reading the file format, reset the stream
        if (smfParser == null) {
            dis.reset();
        }
    }
    MidiFileFormat format = new MidiFileFormat(type, divisionType, resolution, fileLength, duration);
    return format;
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:78,代碼來源:StandardMidiFileReader.java

示例2: getMidiFileFormat

public MidiFileFormat getMidiFileFormat(InputStream in)
  throws InvalidMidiDataException, IOException
{
  DataInputStream din;
  if (in instanceof DataInputStream)
    din = (DataInputStream) in;
  else
    din = new DataInputStream(in);

  int type, ntracks, division, resolution, bytes;
  float divisionType;

  if (din.readInt() != 0x4d546864) // "MThd"
    throw new InvalidMidiDataException("Invalid MIDI chunk header.");

  bytes = din.readInt();
  if (bytes < 6)
    throw new
      InvalidMidiDataException("Invalid MIDI chunk header length: " + bytes);

  type = din.readShort();
  if (type < 0 || type > 2)
    throw new
      InvalidMidiDataException("Invalid MIDI file type value: " + type);

  ntracks = din.readShort();
  if (ntracks <= 0)
    throw new
      InvalidMidiDataException("Invalid number of MIDI tracks: " + ntracks);

  division = din.readShort();
  if ((division & 0x8000) != 0)
    {
      division = -((division >>> 8) & 0xFF);
      switch (division)
        {
        case 24:
          divisionType = Sequence.SMPTE_24;
          break;

        case 25:
          divisionType = Sequence.SMPTE_25;
          break;

        case 29:
          divisionType = Sequence.SMPTE_30DROP;
          break;

        case 30:
          divisionType = Sequence.SMPTE_30;
          break;

        default:
          throw new
            InvalidMidiDataException("Invalid MIDI frame division type: "
                                     + division);
        }
      resolution = division & 0xff;
    }
  else
    {
      divisionType = Sequence.PPQ;
      resolution = division & 0x7fff;
    }

  // If we haven't read every byte in the header now, just skip the rest.
  din.skip(bytes - 6);

  return new ExtendedMidiFileFormat(type, divisionType, resolution,
                                    MidiFileFormat.UNKNOWN_LENGTH,
                                    MidiFileFormat.UNKNOWN_LENGTH, ntracks);
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:72,代碼來源:MidiFileReader.java

示例3: getMidiFileFormat

public MidiFileFormat getMidiFileFormat(InputStream in)
   throws InvalidMidiDataException, IOException
 {
   DataInputStream din;
   if (in instanceof DataInputStream)
     din = (DataInputStream) in;
   else
     din = new DataInputStream(in);
   
   int type, ntracks, division, resolution, bytes;
   float divisionType;
   
   if (din.readInt() != 0x4d546864) // "MThd"
     throw new InvalidMidiDataException("Invalid MIDI chunk header.");

   bytes = din.readInt();
   if (bytes < 6)
     throw new 
InvalidMidiDataException("Invalid MIDI chunk header length: " + bytes);

   type = din.readShort();
   if (type < 0 || type > 2)
     throw new 
InvalidMidiDataException("Invalid MIDI file type value: " + type);
   
   ntracks = din.readShort();
   if (ntracks <= 0)
     throw new 
InvalidMidiDataException("Invalid number of MIDI tracks: " + ntracks);
   
   division = din.readShort();
   if ((division & 0x8000) != 0)
     {
       division = -((division >>> 8) & 0xFF);
       switch (division)
         {
         case 24:
           divisionType = Sequence.SMPTE_24;
           break;

         case 25:
           divisionType = Sequence.SMPTE_25;
           break;

         case 29:
           divisionType = Sequence.SMPTE_30DROP;
           break;

         case 30:
           divisionType = Sequence.SMPTE_30;
           break;

         default:
           throw new 
      InvalidMidiDataException("Invalid MIDI frame division type: "
			       + division);
         }
       resolution = division & 0xff;
     }
   else
     {
       divisionType = Sequence.PPQ;
       resolution = division & 0x7fff;
     }
   
   // If we haven't read every byte in the header now, just skip the rest.
   din.skip(bytes - 6);
   
   return new ExtendedMidiFileFormat(type, divisionType, resolution,
                                     MidiFileFormat.UNKNOWN_LENGTH,
                                     MidiFileFormat.UNKNOWN_LENGTH, ntracks);
 }
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:72,代碼來源:MidiFileReader.java

示例4: parseSpecificTracks

public MusicScore parseSpecificTracks(int[] targets) {
    MusicScore score = new MusicScore();
    if (source != null) {
        score.setName(source.toString());
    }
    score.setLengthAsTick(sequence.getTickLength());
    score.setLengthAsMicrosecond(sequence.getMicrosecondLength());
    score.setResolution(sequence.getResolution());

    boolean isTickPerBeat = false;
    float fDivisionType = sequence.getDivisionType();
    String strDivisionType = null;
    if (fDivisionType == Sequence.PPQ) {
        strDivisionType = "PPQ";
        isTickPerBeat = true;
    } else if (fDivisionType == Sequence.SMPTE_24) {
        strDivisionType = "SMPTE, 24 frames per second";
    } else if (fDivisionType == Sequence.SMPTE_25) {
        strDivisionType = "SMPTE, 25 frames per second";
    } else if (fDivisionType == Sequence.SMPTE_30DROP) {
        strDivisionType = "SMPTE, 29.97 frames per second";
    } else if (fDivisionType == Sequence.SMPTE_30) {
        strDivisionType = "SMPTE, 30 frames per second";
    }

    Track[] tracks = sequence.getTracks();
    for (int i = 0; i < targets.length; i++) {
        for (int nEvent = 0; nEvent < tracks[targets[i]].size(); nEvent++) {
            MidiEvent event = tracks[targets[i]].get(nEvent);
            if (event.getMessage() instanceof ShortMessage) {
                ShortMessage message = (ShortMessage) event.getMessage();
                if (message.getCommand() == MIDIMessageCode.ProgramChange) {
                    score.setProgramCode(message.getData1());
                } else if (message.getCommand() == 0xB0) {
                    if (message.getData1() == 0) {
                        score.setProgramLSB(message.getData2());
                    }
                    if (message.getData1() == 32) {
                        score.setProgramMSB(message.getData2());
                    }
                }
                Note note = decodeShortMessage(message, tracks[targets[i]], nEvent, score.getUnitTime());
                score.addNote(note);
            } else if (event.getMessage() instanceof MetaMessage) {
                double startTime = tracks[targets[i]].get(nEvent).getTick() * score.getUnitTime();
                decodeMetaMessage((MetaMessage) event.getMessage(), score, startTime);
            }
        }
    }
    return score;
}
 
開發者ID:shuichi,項目名稱:MediaMatrix,代碼行數:51,代碼來源:MidiAnalyzer.java

示例5: parse

public MusicScore parse() {
    MusicScore score = new MusicScore();
    if (source != null) {
        score.setName(source.toString());
    }
    score.setLengthAsTick(sequence.getTickLength());
    score.setLengthAsMicrosecond(sequence.getMicrosecondLength());
    score.setResolution(sequence.getResolution());

    boolean isTickPerBeat = false;
    float fDivisionType = sequence.getDivisionType();
    String strDivisionType = null;
    if (fDivisionType == Sequence.PPQ) {
        strDivisionType = "PPQ";
        isTickPerBeat = true;
    } else if (fDivisionType == Sequence.SMPTE_24) {
        strDivisionType = "SMPTE, 24 frames per second";
    } else if (fDivisionType == Sequence.SMPTE_25) {
        strDivisionType = "SMPTE, 25 frames per second";
    } else if (fDivisionType == Sequence.SMPTE_30DROP) {
        strDivisionType = "SMPTE, 29.97 frames per second";
    } else if (fDivisionType == Sequence.SMPTE_30) {
        strDivisionType = "SMPTE, 30 frames per second";
    }

    Track[] tracks = sequence.getTracks();
    for (int nTrack = 0; nTrack < tracks.length; nTrack++) {
        for (int nEvent = 0; nEvent < tracks[nTrack].size(); nEvent++) {
            MidiEvent event = tracks[nTrack].get(nEvent);
            if (event.getMessage() instanceof ShortMessage) {
                ShortMessage message = (ShortMessage) event.getMessage();
                if (message.getCommand() == MIDIMessageCode.ProgramChange) {
                    score.setProgramCode(message.getData1());
                } else if (message.getCommand() == 0xB0) {
                    if (message.getData1() == 0) {
                        score.setProgramLSB(message.getData2());
                    }
                    if (message.getData1() == 32) {
                        score.setProgramMSB(message.getData2());
                    }
                }
                Note note = decodeShortMessage(message, tracks[nTrack], nEvent, score.getUnitTime());
                score.addNote(note);
            } else if (event.getMessage() instanceof MetaMessage) {
                double startTime = tracks[nTrack].get(nEvent).getTick() * score.getUnitTime();
                decodeMetaMessage((MetaMessage) event.getMessage(), score, startTime);
            }
        }
    }
    return score;
}
 
開發者ID:shuichi,項目名稱:MediaMatrix,代碼行數:51,代碼來源:MidiAnalyzer.java

示例6: parseMultiTrack

public MusicScore[] parseMultiTrack() {
    boolean isTickPerBeat = false;
    float fDivisionType = sequence.getDivisionType();
    String strDivisionType = null;
    if (fDivisionType == Sequence.PPQ) {
        strDivisionType = "PPQ";
        isTickPerBeat = true;
    } else if (fDivisionType == Sequence.SMPTE_24) {
        strDivisionType = "SMPTE, 24 frames per second";
    } else if (fDivisionType == Sequence.SMPTE_25) {
        strDivisionType = "SMPTE, 25 frames per second";
    } else if (fDivisionType == Sequence.SMPTE_30DROP) {
        strDivisionType = "SMPTE, 29.97 frames per second";
    } else if (fDivisionType == Sequence.SMPTE_30) {
        strDivisionType = "SMPTE, 30 frames per second";
    }

    final List<MusicScore> result = new ArrayList<MusicScore>();
    final Track[] tracks = sequence.getTracks();
    List<Tempo> tempo = null;
    for (int nTrack = 0; nTrack < tracks.length; nTrack++) {
        final MusicScore score = new MusicScore();
        if (source != null) {
            score.setName(source.toString());
        }
        result.add(score);
        score.setLengthAsTick(sequence.getTickLength());
        score.setLengthAsMicrosecond(sequence.getMicrosecondLength());
        score.setResolution(sequence.getResolution());
        for (int nEvent = 0; nEvent < tracks[nTrack].size(); nEvent++) {
            final MidiEvent event = tracks[nTrack].get(nEvent);
            if (event.getMessage() instanceof ShortMessage) {
                ShortMessage message = (ShortMessage) event.getMessage();
                if (message.getCommand() == MIDIMessageCode.ProgramChange) {
                    score.setProgramCode(message.getData1());
                } else if (message.getCommand() == 0xB0) {
                    if (message.getData1() == 0) {
                        score.setProgramLSB(message.getData2());
                    }
                    if (message.getData1() == 32) {
                        score.setProgramMSB(message.getData2());
                    }
                }
                final Note note = decodeShortMessage(message, tracks[nTrack], nEvent, score.getUnitTime());
                score.addNote(note);
            } else if (event.getMessage() instanceof MetaMessage) {
                double startTime = tracks[nTrack].get(nEvent).getTick() * score.getUnitTime();
                decodeMetaMessage((MetaMessage) event.getMessage(), score, startTime);
            }
        }
        if (tempo == null && score.getTempo().size() > 0) {
            tempo = score.getTempo();
        } else {
            score.setMicrosecondsPerQuarterNote((long) tempo.get(0).getTempo());
            score.setTempo(tempo);
        }
    }
    return result.toArray(new MusicScore[result.size()]);
}
 
開發者ID:shuichi,項目名稱:MediaMatrix,代碼行數:59,代碼來源:MidiAnalyzer.java


注:本文中的javax.sound.midi.Sequence.SMPTE_25屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。