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


Java MidiTrack类代码示例

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


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

示例1: readTrack

import org.herac.tuxguitar.io.midi.base.MidiTrack; //导入依赖的package包/类
private void readTrack(DataInputStream in, MidiTrack track)throws MidiFileException, IOException{
	while (true){
		if (in.readInt() == TRACK_MAGIC){
			break;
		}
		int chunkLength = in.readInt();
		if (chunkLength % 2 != 0){
			chunkLength++;
		}
		in.skip(chunkLength);
	}
	
	MidiTrackReaderHelper helper = new MidiTrackReaderHelper(0,in.readInt(),-1);
	while (helper.remainingBytes > 0){
		helper.ticks += readVariableLengthQuantity(in, helper);
		MidiEvent event = readEvent(in, helper);
		if(event != null){
			track.add(event);
		}
	}
}
 
开发者ID:theokyr,项目名称:TuxGuitar-1.3.1-fork,代码行数:22,代码来源:MidiFileReader.java

示例2: writeTrack

import org.herac.tuxguitar.io.midi.base.MidiTrack; //导入依赖的package包/类
private static int writeTrack(MidiTrack track,DataOutputStream out)throws IOException{
	int length = 0;
	if (out != null){
		out.writeInt(TRACK_MAGIC);
	}
	if (out != null){
		out.writeInt( writeTrack(track, null) );
	}
	MidiEvent previous = null;
	for (int i = 0; i < track.size(); i++){
		MidiEvent event = track.get(i);
		length += writeEvent(event,previous,out);
		previous = event;
	}
	return length;
}
 
开发者ID:theokyr,项目名称:TuxGuitar-1.3.1-fork,代码行数:17,代码来源:MidiFileWriter.java

示例3: importSong

import org.herac.tuxguitar.io.midi.base.MidiTrack; //导入依赖的package包/类
public TGSong importSong() throws TGFileFormatException {
	try {
		if(this.settings == null || this.factory == null || this.stream == null ){
			return null;
		}
		MidiSequence sequence = new MidiFileReader().getSequence(this.stream);
		initFields(sequence);
		for(int i = 0; i < sequence.countTracks(); i++){
			MidiTrack track = sequence.getTrack(i);
			int trackNumber = getNextTrackNumber();
			int events = track.size();
			for(int j = 0;j < events;j ++){
				MidiEvent event = track.get(j);
				parseMessage(trackNumber,event.getTick(),event.getMessage());
			}
		}
		checkAll();
		
		TGSong song = this.factory.newSong();
		
		Iterator headers = this.headers.iterator();
		while(headers.hasNext()){
			song.addMeasureHeader((TGMeasureHeader)headers.next());
		}
		Iterator tracks = this.tracks.iterator();
		while(tracks.hasNext()){
			song.addTrack((TGTrack)tracks.next());
		}
		return new SongAdjuster(this.factory,song).adjustSong();
	} catch (Throwable throwable) {
		throw new TGFileFormatException(throwable);
	}
}
 
开发者ID:Totallicks,项目名称:totallicks-tuxguitar,代码行数:34,代码来源:MidiSongImporter.java

示例4: init

import org.herac.tuxguitar.io.midi.base.MidiTrack; //导入依赖的package包/类
private void init(){
	this.sequence = new MidiSequence(MidiSequence.PPQ,(int)TGDuration.QUARTER_TIME);
	for (int i = 0; i < getTracks(); i++) {
		this.sequence.addTrack(new MidiTrack());
	}
}
 
开发者ID:theokyr,项目名称:TuxGuitar-1.3.1-fork,代码行数:7,代码来源:MidiSequenceHandlerImpl.java

示例5: getSequence

import org.herac.tuxguitar.io.midi.base.MidiTrack; //导入依赖的package包/类
public MidiSequence getSequence(InputStream stream)throws MidiFileException, IOException{
	DataInputStream	in = new DataInputStream(stream);
	if (in.readInt() != HEADER_MAGIC){
		throw new MidiFileException("not a MIDI file: wrong header magic");
	}
	int headerLength = in.readInt();
	if (headerLength < HEADER_LENGTH){
		throw new MidiFileException("corrupt MIDI file: wrong header length");
	}
	int type = in.readShort();
	if (type < 0 || type > 2){
		throw new MidiFileException("corrupt MIDI file: illegal type");
	}
	if (type == 2){
		throw new MidiFileException("this implementation doesn't support type 2 MIDI files");
	}
	int trackCount = in.readShort();
	if (trackCount <= 0){
		throw new MidiFileException("corrupt MIDI file: number of tracks must be positive");
	}
	if (type == 0 && trackCount != 1){
		throw new MidiFileException("corrupt MIDI file:  type 0 files must contain exactely one track");
	}
	float divisionType = -1.0F;
	int resolution = -1;
	int division = in.readUnsignedShort();
	if ((division & 0x8000) != 0){
		int frameType = -((division >>> 8) & 0xFF);
		if(frameType == 24){
			divisionType = MidiSequence.SMPTE_24;
		}else if(frameType == 25){
			divisionType = MidiSequence.SMPTE_25;
		}else if(frameType == 29){
			divisionType = MidiSequence.SMPTE_30DROP;
		}else if(frameType == 30){
			divisionType = MidiSequence.SMPTE_30;
		}else{
			throw new MidiFileException("corrupt MIDI file: illegal frame division type");
		}
		resolution = division & 0xff;
	}else{
		divisionType = MidiSequence.PPQ;
		resolution = division & 0x7fff;
	}
	
	in.skip(headerLength - HEADER_LENGTH);
	
	MidiSequence sequence = new MidiSequence(divisionType,resolution);
	for (int i = 0; i < trackCount; i++){
		MidiTrack track = new MidiTrack();
		sequence.addTrack(track);
		readTrack(in, track);
	}
	
	in.close();
	
	return sequence;
}
 
开发者ID:theokyr,项目名称:TuxGuitar-1.3.1-fork,代码行数:59,代码来源:MidiFileReader.java

示例6: process

import org.herac.tuxguitar.io.midi.base.MidiTrack; //导入依赖的package包/类
public void process() throws TGFileFormatException {
	try {			
		InputStream stream = this.context.getAttribute(InputStream.class.getName());
		TGSongManager tgSongManager = this.context.getAttribute(TGDocumentContextAttributes.ATTRIBUTE_SONG_MANAGER);
		
		this.factory = tgSongManager.getFactory();
		this.settings = this.context.getAttribute(MidiSettings.class.getName());
		if( this.settings == null ) {
			this.settings = MidiSettings.getDefaults();
		}
		
		MidiSequence sequence = new MidiFileReader().getSequence(stream);
		initFields(sequence);
		for(int i = 0; i < sequence.countTracks(); i++){
			MidiTrack track = sequence.getTrack(i);
			int trackNumber = getNextTrackNumber();
			int events = track.size();
			for(int j = 0;j < events;j ++){
				MidiEvent event = track.get(j);
				parseMessage(trackNumber,event.getTick(),event.getMessage());
			}
		}
		
		TGSong tgSong = this.factory.newSong();
		
		this.checkAll(tgSongManager);
		
		Iterator<TGChannel> channels = this.channels.iterator();
		while(channels.hasNext()){
			tgSong.addChannel((TGChannel)channels.next());
		}
		Iterator<TGMeasureHeader> headers = this.headers.iterator();
		while(headers.hasNext()){
			tgSong.addMeasureHeader((TGMeasureHeader)headers.next());
		}
		Iterator<TGTrack> tracks = this.tracks.iterator();
		while(tracks.hasNext()){
			tgSong.addTrack((TGTrack)tracks.next());
		}
		
		this.context.setAttribute(TGDocumentContextAttributes.ATTRIBUTE_SONG, new SongAdjuster(this.factory, tgSong).adjustSong());
	} catch (Throwable throwable) {
		throw new TGFileFormatException(throwable);
	}
}
 
开发者ID:theokyr,项目名称:TuxGuitar-1.3.1-fork,代码行数:46,代码来源:MidiSongImporter.java


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