当前位置: 首页>>代码示例>>Java>>正文


Java MidiFileFormat.UNKNOWN_LENGTH属性代码示例

本文整理汇总了Java中javax.sound.midi.MidiFileFormat.UNKNOWN_LENGTH属性的典型用法代码示例。如果您正苦于以下问题:Java MidiFileFormat.UNKNOWN_LENGTH属性的具体用法?Java MidiFileFormat.UNKNOWN_LENGTH怎么用?Java MidiFileFormat.UNKNOWN_LENGTH使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.sound.midi.MidiFileFormat的用法示例。


在下文中一共展示了MidiFileFormat.UNKNOWN_LENGTH属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMidiFileFormat

public MidiFileFormat getMidiFileFormat(File file) throws InvalidMidiDataException, IOException {
    FileInputStream fis = new FileInputStream(file); // throws IOException
    BufferedInputStream bis = new BufferedInputStream(fis, bisBufferSize);

    // $$fb 2002-04-17: part of fix for 4635286: MidiSystem.getMidiFileFormat() returns format having invalid length
    long length = file.length();
    if (length > Integer.MAX_VALUE) {
        length = MidiFileFormat.UNKNOWN_LENGTH;
    }
    MidiFileFormat fileFormat = null;
    try {
        fileFormat = getMidiFileFormatFromStream(bis, (int) length, null);
    } finally {
        bis.close();
    }
    return fileFormat;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:StandardMidiFileReader.java

示例2: getMidiFileFormat

@Override
public MidiFileFormat getMidiFileFormat(File file) throws InvalidMidiDataException, IOException {
    FileInputStream fis = new FileInputStream(file); // throws IOException
    BufferedInputStream bis = new BufferedInputStream(fis, bisBufferSize);

    // $$fb 2002-04-17: part of fix for 4635286: MidiSystem.getMidiFileFormat() returns format having invalid length
    long length = file.length();
    if (length > Integer.MAX_VALUE) {
        length = MidiFileFormat.UNKNOWN_LENGTH;
    }
    MidiFileFormat fileFormat = null;
    try {
        fileFormat = getMidiFileFormatFromStream(bis, (int) length, null);
    } finally {
        bis.close();
    }
    return fileFormat;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:StandardMidiFileReader.java

示例3: 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

示例4: 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

示例5: 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

示例6: fillMetadata

@Override
public void fillMetadata(final Content content, final Log logger) throws Exception
{
    final URL url = content.getURL(); // Throws NullPointerException if content is null. May throw SecurityException, IllegalArgumentException, MalformedURLException.

    try
    {
        final AudioFileFormat audioFileFormat = AudioSystem.getAudioFileFormat(url); // May throw UnsupportedAudioFileException, IOException.

        content.setWidth(0);
        content.setHeight(0);

        final AudioFormat audioFormat = audioFileFormat.getFormat();

        if ((audioFileFormat.getFrameLength() == AudioSystem.NOT_SPECIFIED) || (audioFormat.getSampleRate() == (float) AudioSystem.NOT_SPECIFIED))
        {
            logger.debug("Unknown audio duration");
        }
        else
        {
            content.setDuration((long)(((float) audioFileFormat.getFrameLength() * 1000.0f) / audioFormat.getSampleRate()));
        }

        return;
    }
    catch (UnsupportedAudioFileException e)
    {
        // Try the next format.
        logger.debug(e.toString());
    }

    final MidiFileFormat midiFormat = MidiSystem.getMidiFileFormat(url); // May throw InvalidMidiDataException, IOException.

    content.setWidth(0);
    content.setHeight(0);

    final long duration = midiFormat.getMicrosecondLength();

    if (duration == MidiFileFormat.UNKNOWN_LENGTH)
    {
        logger.debug("Unknown MIDI duration");
    }
    else
    {
        content.setDuration((duration + 999L) / 1000L);
    }
}
 
开发者ID:LizzyProject,项目名称:Lizzy,代码行数:47,代码来源:SoundMetadataProvider.java

示例7: 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:openjdk,项目名称:jdk7-jdk,代码行数:75,代码来源:StandardMidiFileReader.java


注:本文中的javax.sound.midi.MidiFileFormat.UNKNOWN_LENGTH属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。