1 package org.herac.tuxguitar.io.ptb.helper; 2 3 import org.herac.tuxguitar.song.models.TGDuration; 4 5 public class TrackStartHelper { 6 7 private int section; 8 private long[][] voices; 9 private boolean measureEmpty; 10 private boolean measureRest; 11 12 private long barStart; 13 private long barLength; 14 TrackStartHelper()15 public TrackStartHelper(){ 16 super(); 17 } 18 init(int section,int staffs)19 public void init(int section,int staffs){ 20 this.section = section; 21 this.voices = new long[staffs][2]; 22 this.measureEmpty = true; 23 this.measureRest = false; 24 this.barStart = 0; 25 this.barLength = 0; 26 } 27 getSection()28 public int getSection(){ 29 return this.section; 30 } 31 initVoices(long start)32 public void initVoices(long start){ 33 for(int i = 0; i < this.voices.length; i ++){ 34 for(int j = 0; j < this.voices[i].length; j ++){ 35 this.voices[i][j] = fixValue(start); 36 } 37 } 38 this.measureEmpty = true; 39 this.measureRest = false; 40 } 41 getMaxStart()42 public long getMaxStart(){ 43 long result = TGDuration.QUARTER_TIME; 44 for(int i = 0; i < this.voices.length; i ++){ 45 for(int j = 0; j < this.voices[i].length; j ++){ 46 result = Math.max(result,this.voices[i][j] ); 47 } 48 } 49 // checkRestMeasures 50 if( this.measureRest && this.measureEmpty ){ 51 result = Math.max(result, (this.barStart + this.barLength)); 52 } 53 return fixValue(result); 54 } 55 getVoiceStart(int staff,int voice)56 public long getVoiceStart(int staff,int voice){ 57 return this.voices[staff][voice]; 58 } 59 setVoiceStart(int staff,int voice,long start)60 public void setVoiceStart(int staff,int voice,long start){ 61 this.voices[staff][voice] = fixValue(start); 62 } 63 getBarStart()64 public long getBarStart() { 65 return this.barStart; 66 } 67 setBarStart(long barStart)68 public void setBarStart(long barStart) { 69 this.barStart = barStart; 70 } 71 getBarLength()72 public long getBarLength() { 73 return this.barLength; 74 } 75 setBarLength(long barLength)76 public void setBarLength(long barLength) { 77 this.barLength = barLength; 78 } 79 checkBeat( boolean rest )80 public void checkBeat( boolean rest ){ 81 this.measureEmpty = (this.measureEmpty && rest ); 82 this.measureRest = true; 83 } 84 fixValue(long value)85 public long fixValue(long value){ 86 return (((value % (TGDuration.QUARTER_TIME / 2)) + 10 > (TGDuration.QUARTER_TIME / 2))?(value + ((TGDuration.QUARTER_TIME / 2) - (value % (TGDuration.QUARTER_TIME / 2)))):value); 87 } 88 } 89