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


Java Sequence类代码示例

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


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

示例1: getSequence

import javax.sound.midi.Sequence; //导入依赖的package包/类
public Sequence getSequence(InputStream stream) throws InvalidMidiDataException, IOException {
    SMFParser smfParser = new SMFParser();
    MidiFileFormat format = getMidiFileFormatFromStream(stream,
                                                        MidiFileFormat.UNKNOWN_LENGTH,
                                                        smfParser);

    // must be MIDI Type 0 or Type 1
    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; i++) {
        if (smfParser.nextTrack()) {
            smfParser.readTrack(sequence.createTrack());
        } else {
            break;
        }
    }
    return sequence;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:StandardMidiFileReader.java

示例2: getMidiFileTypes

import javax.sound.midi.Sequence; //导入依赖的package包/类
/**
 * Obtains the file types that this provider can write from the
 * sequence specified.
 * @param sequence the sequence for which midi file type support
 * is queried
 * @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;
    } else {
        typesArray = new int[1];
        typesArray[0] = MIDI_TYPE_1;
    }

    return typesArray;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:StandardMidiFileWriter.java

示例3: write

import javax.sound.midi.Sequence; //导入依赖的package包/类
public int write(Sequence in, int type, OutputStream out) throws IOException {
    byte [] buffer = null;

    int bytesRead = 0;
    long bytesWritten = 0;

    if( !isFileTypeSupported(type,in) ) {
        throw new IllegalArgumentException("Could not write MIDI file");
    }
    // First get the fileStream from this sequence
    InputStream fileStream = getFileStream(type,in);
    if (fileStream == null) {
        throw new IllegalArgumentException("Could not write MIDI file");
    }
    buffer = new byte[bufferSize];

    while( (bytesRead = fileStream.read( buffer )) >= 0 ) {
        out.write( buffer, 0, (int)bytesRead );
        bytesWritten += bytesRead;
    }
    // Done....return bytesWritten
    return (int) bytesWritten;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:StandardMidiFileWriter.java

示例4: getSequence

import javax.sound.midi.Sequence; //导入依赖的package包/类
@Override
public Sequence getSequence(InputStream stream) throws InvalidMidiDataException, IOException {
    SMFParser smfParser = new SMFParser();
    MidiFileFormat format = getMidiFileFormatFromStream(stream,
                                                        MidiFileFormat.UNKNOWN_LENGTH,
                                                        smfParser);

    // must be MIDI Type 0 or Type 1
    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; i++) {
        if (smfParser.nextTrack()) {
            smfParser.readTrack(sequence.createTrack());
        } else {
            break;
        }
    }
    return sequence;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:StandardMidiFileReader.java

示例5: getMidiFileTypes

import javax.sound.midi.Sequence; //导入依赖的package包/类
/**
 * Obtains the file types that this provider can write from the
 * sequence specified.
 * @param sequence the sequence for which midi file type support
 * is queried
 * @return array of file types.  If no file types are supported,
 * returns an array of length 0.
 */
@Override
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;
    } else {
        typesArray = new int[1];
        typesArray[0] = MIDI_TYPE_1;
    }

    return typesArray;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:StandardMidiFileWriter.java

示例6: write

import javax.sound.midi.Sequence; //导入依赖的package包/类
@Override
public int write(Sequence in, int type, OutputStream out) throws IOException {
    Objects.requireNonNull(out);
    if (!isFileTypeSupported(type, in)) {
        throw new IllegalArgumentException("Could not write MIDI file");
    }
    byte [] buffer = null;

    int bytesRead = 0;
    long bytesWritten = 0;

    // First get the fileStream from this sequence
    InputStream fileStream = getFileStream(type,in);
    if (fileStream == null) {
        throw new IllegalArgumentException("Could not write MIDI file");
    }
    buffer = new byte[bufferSize];

    while( (bytesRead = fileStream.read( buffer )) >= 0 ) {
        out.write( buffer, 0, bytesRead );
        bytesWritten += bytesRead;
    }
    // Done....return bytesWritten
    return (int) bytesWritten;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:StandardMidiFileWriter.java

示例7: write

import javax.sound.midi.Sequence; //导入依赖的package包/类
public int write(Sequence in, int type, OutputStream out) throws IOException {
    Objects.requireNonNull(out);
    if (!isFileTypeSupported(type, in)) {
        throw new IllegalArgumentException("Could not write MIDI file");
    }
    byte [] buffer = null;

    int bytesRead = 0;
    long bytesWritten = 0;

    // First get the fileStream from this sequence
    InputStream fileStream = getFileStream(type,in);
    if (fileStream == null) {
        throw new IllegalArgumentException("Could not write MIDI file");
    }
    buffer = new byte[bufferSize];

    while( (bytesRead = fileStream.read( buffer )) >= 0 ) {
        out.write( buffer, 0, bytesRead );
        bytesWritten += bytesRead;
    }
    // Done....return bytesWritten
    return (int) bytesWritten;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:25,代码来源:StandardMidiFileWriter.java

示例8: resetTracks

import javax.sound.midi.Sequence; //导入依赖的package包/类
public void resetTracks(){
	try {
		Sequence sequence = this.getSequencer().getSequence();
		if(sequence != null){
			Track[] tracks = sequence.getTracks();
			if( tracks != null ){
				int count = tracks.length;
				for( int i = 0 ; i < count; i++ ){
					this.setSolo( i , false );
					this.setMute( i , false );
				}
			}
		}
	} catch (Throwable throwable) {
		throwable.printStackTrace();
	}
}
 
开发者ID:theokyr,项目名称:TuxGuitar-1.3.1-fork,代码行数:18,代码来源:MidiSequencerImpl.java

示例9: RegisterSong

import javax.sound.midi.Sequence; //导入依赖的package包/类
@Override
public int RegisterSong(byte[] data) {
	try {
           Sequence sequence;
        ByteArrayInputStream bis;
        try {
            // If data is a midi file, load it directly
            bis = new ByteArrayInputStream(data);
            sequence = MidiSystem.getSequence(bis);
        } catch (InvalidMidiDataException ex) {
        	// Well, it wasn't. Dude.
               bis = new ByteArrayInputStream(data);
            sequence = MusReader.getSequence(bis);
        }
           sequencer.stop(); // stops current music if any
           sequencer.setSequence(sequence); // Create a sequencer for the sequence
           songloaded=true;
    } catch (Exception e) {
    	e.printStackTrace();
    	return -1;
    } 
	// In good old C style, we return 0 upon success?
	return 0;
}
 
开发者ID:AXDOOMER,项目名称:mochadoom,代码行数:25,代码来源:DavidMusicModule.java

示例10: exportMidiSequence

import javax.sound.midi.Sequence; //导入依赖的package包/类
/**
 * Exports the location of each slice into a MIDI file
 */
public Sequence exportMidiSequence(final File file, final int ppq) throws IOException {
	final double tempoBps = (double) getTempo() / 60.0;
	final MidiSequenceBuilder builder = new MidiSequenceBuilder(ppq);
	final Track track = builder.getTrack();
	final int n = markers.size();
	int startTick = 0;
	int key = 35;
	for (int i = 0; i < n; i++) {
		final int location = getLocation(i);
		startTick = (int) Math.round(ppq * tempoBps * location / samplingRate);
		int tickLength = 32;
		builder.addNote(track, startTick, tickLength, key++);
	}
	if (file != null) {
		builder.save(file);
	}
	return builder.getSequence();
}
 
开发者ID:cyriux,项目名称:mpcmaid,代码行数:22,代码来源:Markers.java

示例11: setupMidi

import javax.sound.midi.Sequence; //导入依赖的package包/类
public void setupMidi() throws Exception {
	synthesizer = MidiSystem.getSynthesizer();
	synthesizer.open();
	midiChannels = synthesizer.getChannels();
	sequencer = MidiSystem.getSequencer();
	sequence = new Sequence(Sequence.PPQ, 10);
	Soundbank sb = synthesizer.getDefaultSoundbank();
	if (sb != null) {
		instruments = synthesizer.getDefaultSoundbank().getInstruments();
		for (int i = 0; i < instruments.length; i++) {
			System.out.printf("%4d: %s%n", i, instruments[i]);
		}
		if (instruments.length > 0) {
			synthesizer.loadInstrument(instruments[0]);
			midiChannels[currentChannel].programChange(0);
		}
		if (instruments.length > 14) {
			synthesizer.loadInstrument(instruments[14]);
			midiChannels[currentChannel].programChange(14);
		}
	}
}
 
开发者ID:haogrgr,项目名称:haogrgr-projects,代码行数:23,代码来源:ActorDemo.java

示例12: getDrumSequencesInDirectory

import javax.sound.midi.Sequence; //导入依赖的package包/类
/**
 * Loads all drum sequences found in a given directory.
 * 
 * @param dirPath
 * @return
 */
public static List<MidiSequence> getDrumSequencesInDirectory(String dirPath) {
	File folder = new File(dirPath);
	File[] listOfFiles = folder.listFiles();
	List<MidiSequence> drumSequences = new ArrayList<MidiSequence>();

	for (File file : listOfFiles) {
		String path = file.getAbsolutePath();
		Sequence sequence = MidiUtilities.loadSequence(path);
		if (sequence != null) {
			MidiSequence drumSequence = new MidiSequence();
			drumSequence.setFileName(file.getName());
			drumSequence.setDirectoryPath(dirPath);
			drumSequence.setMidiSequence(sequence);
			drumSequences.add(drumSequence);
		}
	}
	return drumSequences;
}
 
开发者ID:TaylorPeer,项目名称:AI-909,代码行数:25,代码来源:MidiUtilities.java

示例13: getMicrosecondsPerQuarterNote

import javax.sound.midi.Sequence; //导入依赖的package包/类
/**
 * Gets the number of microseconds per quarter note for a sequence, used to
 * determine its BPM.
 * 
 * @param sequence
 * @return
 */
private static int getMicrosecondsPerQuarterNote(Sequence sequence) {

	// Check all MIDI tracks for MIDI_SET_TEMPO message
	for (Track track : sequence.getTracks()) {
		for (int i = 0; i < track.size(); i++) {
			MidiEvent event = track.get(i);
			MidiMessage message = event.getMessage();
			if (message instanceof MetaMessage) {
				MetaMessage m = (MetaMessage) message;
				byte[] data = m.getData();
				int type = m.getType();
				if (type == MIDI_SET_TEMPO) {
					return ((data[0] & 0xff) << 16) | ((data[1] & 0xff) << 8) | (data[2] & 0xff);
				}
			}
		}
	}
	return 0;
}
 
开发者ID:TaylorPeer,项目名称:AI-909,代码行数:27,代码来源:MidiUtilities.java

示例14: render

import javax.sound.midi.Sequence; //导入依赖的package包/类
/**
 * Adds this Note at the specified time on the specified Track and
 * channel in the specified Sequence, then returns the time that a
 * sequential Note should be added.
 * @param seq           the Sequence to which to add this Note
 * @param track         the Track in the Sequence to which to add this Note
 * @param time          the time at which to start this Note
 * @param ch            the channel on which to put this Note 
 * @param transposition amount by which to transpose this note in semitones
 * @param sendBankSelect
 * @return 
 * @throws javax.sound.midi.InvalidMidiDataException 
 */

public long render(Sequence seq, 
                   Track track, 
                   long time, 
                   int ch, 
                   int transposition,
                   boolean sendBankSelect)
        throws InvalidMidiDataException
  {
    if( sendBankSelect )
      {
        
      }
    int dur = getRhythmValue();
    long offTime = time + dur * seq.getResolution() / BEAT;
    render(seq, track, time, offTime, ch, transposition);
    
    return offTime;
  }
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:33,代码来源:Note.java

示例15: go

import javax.sound.midi.Sequence; //导入依赖的package包/类
public void go() {
	setUpGui();

	try {
		Sequencer sequencer = MidiSystem.getSequencer();
		sequencer.open();
		sequencer.addControllerEventListener(ml, new int[] {127});
		Sequence seq = new Sequence(Sequence.PPQ, 4);
		Track track = seq.createTrack();

		int r = 0;
		for (int i = 0; i < 60; i+=4) {
			r = (int) ((Math.random() * 50) + 1);
			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));
		} // end loop

		sequencer.setSequence(seq);
		sequencer.start();
		sequencer.setTempoInBPM(120);
	} catch (Exception ex) {ex.printStackTrace();}
}
 
开发者ID:miguelalba-old,项目名称:Head-First-Java,代码行数:24,代码来源:MiniMusicPlayer3.java


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