當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。