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


Java Sequence.SMPTE_30属性代码示例

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


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

示例1: getSequence

/** Create a sequence from an InputStream.
 *  This is the counterpart of {@link MidiSystem#getSequence(InputStream)}
 *  for MUS format.
 *
 * @param is MUS data (this method does not try to auto-detect the format.)
 */
public static Sequence getSequence(InputStream is)
throws IOException, InvalidMidiDataException {
    DataInputStream dis = new DataInputStream(is);
    dis.skip(6);
    int rus = dis.readUnsignedShort();
    short scoreStart = Swap.SHORT((char) rus);
    dis.skip(scoreStart - 8);
    Sequence sequence = new Sequence(Sequence.SMPTE_30, 14, 1);
    Track track = sequence.getTracks()[0];
    int[] chanVelocity = new int[16];
    Arrays.fill(chanVelocity, 100);
    EventGroup eg;
    long tick = 0;
    while ((eg = nextEventGroup(dis, chanVelocity)) != null) {
        tick = eg.appendTo(track, tick);
    }
    MetaMessage endOfSequence = new MetaMessage();
    endOfSequence.setMessage(47, new byte[] {0}, 1);
    track.add(new MidiEvent(endOfSequence, tick));
    return sequence;
}
 
开发者ID:AXDOOMER,项目名称:mochadoom,代码行数:27,代码来源:MusReader.java

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

示例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:vilie,项目名称:javify,代码行数:72,代码来源:MidiFileReader.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:nmldiegues,项目名称:jvm-stm,代码行数:72,代码来源:MidiFileReader.java

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

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

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