TGMeasureManager.java

Index Score
org.herac.tuxguitar.song.managers
TuxGuitar

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
PARAMSNumber of formal parameter declarations
LOOPSNumber of loops
COMPARISONSNumber of comparison operators
INTERFACE_COMPLEXITYInterface complexity
CYCLOMATICCyclomatic complexity
BLOCKSNumber of blocks
DECL_COMMENTSComments in declarations
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
OPERANDSNumber of operands
EXITSProcedure exits
FUNCTIONSNumber of function declarations
UNIQUE_OPERANDSNumber of unique operands
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
LOCLines of code
RETURNSNumber of return points from functions
EXEC_COMMENTSComments in executable code
LOGICAL_LINESNumber of statements
PROGRAM_VOCABHalstead program vocabulary
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
ELOCEffective lines of code
LINESNumber of lines in the source file
SIZESize of the file in bytes
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0145JAVA0145 Tab character used in source file
JAVA0144JAVA0144 Line exceeds maximum M characters
COMMENTSComment lines
LINE_COMMENTNumber of line comments
DOC_COMMENTNumber of javadoc comment lines
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
JAVA0034JAVA0034 Missing braces in if statement
JAVA0076JAVA0076 Use of magic number
NEST_DEPTHMaximum nesting depth
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
WHITESPACENumber of whitespace lines
JAVA0126JAVA0126 Method declares unchecked exception in throws
UNIQUE_OPERATORSNumber of unique operators
JAVA0130JAVA0130 Non-static method does not use instance fields
package org.herac.tuxguitar.song.managers; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.herac.tuxguitar.song.factory.TGFactory; import org.herac.tuxguitar.song.models.TGBeat; import org.herac.tuxguitar.song.models.TGChord; import org.herac.tuxguitar.song.models.TGDuration; import org.herac.tuxguitar.song.models.TGMeasure; import org.herac.tuxguitar.song.models.TGNote; import org.herac.tuxguitar.song.models.TGString; import org.herac.tuxguitar.song.models.TGText; import org.herac.tuxguitar.song.models.effects.TGEffectBend; import org.herac.tuxguitar.song.models.effects.TGEffectGrace; import org.herac.tuxguitar.song.models.effects.TGEffectHarmonic; import org.herac.tuxguitar.song.models.effects.TGEffectTremoloBar; import org.herac.tuxguitar.song.models.effects.TGEffectTremoloPicking; import org.herac.tuxguitar.song.models.effects.TGEffectTrill; public class TGMeasureManager { private TGSongManager songManager; public TGMeasureManager(TGSongManager songManager){ this.songManager = songManager; } public TGSongManager getSongManager(){ return this.songManager; } public void orderBeats(TGMeasure measure){ for(int i = 0;i < measure.countBeats();i++){ TGBeat minBeat = null; for(int j = i;j < measure.countBeats();j++){ TGBeat beat = measure.getBeat(j); if(minBeat == null || beat.getStart() < minBeat.getStart()){ minBeat = beat; } } measure.moveBeat(i, minBeat); } } /** * Agrega un beat al compas */ public void addBeat(TGMeasure measure,TGBeat beat){ //Verifico si entra en el compas if(validateDuration(measure,beat,false,false)){ //Agrego el beat measure.addBeat(beat); } } public void removeBeat(TGBeat beat){ beat.getMeasure().removeBeat(beat); } public void removeBeat(TGMeasure measure,long start,boolean moveNextComponents){ TGBeat beat = getBeat(measure, start); if(beat != null){ removeBeat(beat, moveNextComponents); } } /** * Elimina un silencio del compas. * si se asigna moveNextComponents = true. los componentes que le siguen * se moveran para completar el espacio vacio que dejo el silencio */ public void removeBeat(TGBeat beat,boolean moveNextBeats){ TGMeasure measure = beat.getMeasure(); removeBeat(beat); if(moveNextBeats){ long start = beat.getStart(); long length = beat.getDuration().getTime(); TGBeat next = getNextBeat(measure.getBeats(),beat); if(next != null){ length = next.getStart() - start; } moveBeats(beat.getMeasure(),start + length,-length, beat.getDuration()); } } public void removeBeatsBeforeEnd(TGMeasure measure,long fromStart){ List beats = getBeatsBeforeEnd( measure.getBeats() , fromStart); Iterator it = beats.iterator(); while(it.hasNext()){ TGBeat beat = (TGBeat) it.next(); removeBeat(beat); } } public void addNote(TGMeasure measure,long start, TGNote note, TGDuration duration){ TGBeat beat = getBeat(measure, start); if(beat != null){ addNote(beat, note, duration); } } public void addNote(TGBeat beat, TGNote note, TGDuration duration){ addNote(beat, note, duration, beat.getStart()); } public void addNote(TGBeat beat, TGNote note, TGDuration duration, long start){ //Verifico si entra en el compas if(validateDuration(beat.getMeasure(),beat, duration,true,true)){ //Borro lo que haya en la misma posicion removeNote(beat.getMeasure(),beat.getStart(),note.getString()); duration.copy(beat.getDuration()); //trato de agregar un silencio similar al lado tryChangeSilenceAfter(beat.getMeasure(),beat); // Despues de cambiar la duracion, verifico si hay un beat mejor para agregar la nota. TGBeat realBeat = beat; if(realBeat.getStart() != start){ TGBeat beatIn = getBeatIn(realBeat.getMeasure(), start); if( beatIn != null ) { realBeat = beatIn; } } realBeat.addNote(note); } } public void removeNote(TGNote note){ note.getBeat().removeNote(note); } /** * Elimina los Componentes que empiecen en Start y esten en la misma cuerda * Si hay un Silencio lo borra sin importar la cuerda */ public void removeNote(TGMeasure measure,long start,int string){ TGBeat beat = getBeat(measure, start); if(beat != null){ for( int i = 0; i < beat.countNotes(); i ++){ TGNote note = beat.getNote(i); if(note.getString() == string){ removeNote(note); //si era el unico componente agrego un silencio if(beat.isRestBeat()){ //Borro un posible acorde removeChord(measure, beat.getStart()); } return; } } } } public void removeNotesAfterString(TGMeasure measure,int string){ List notesToRemove = new ArrayList(); Iterator beats = measure.getBeats().iterator(); while(beats.hasNext()){ TGBeat beat = (TGBeat)beats.next(); Iterator notes = beat.getNotes().iterator(); while(notes.hasNext()){ TGNote note = (TGNote)notes.next(); if(note.getString() > string){ notesToRemove.add(note); } } } Iterator it = notesToRemove.iterator(); while(it.hasNext()){ TGNote note = (TGNote)it.next(); removeNote(note); } } /** * Retorna Todas las Notas en la posicion Start */ public List getNotes(TGMeasure measure,long start){ List notes = new ArrayList(); TGBeat beat = getBeat(measure, start); if(beat != null){ Iterator it = beat.getNotes().iterator(); while(it.hasNext()){ TGNote note = (TGNote)it.next(); notes.add(note); } } return notes; } /** * Retorna la Nota en la posicion y cuerda */ public TGNote getNote(TGMeasure measure,long start,int string) { TGBeat beat = getBeat(measure, start); if(beat != null){ return getNote(beat, string); } return null; } /** * Retorna la Nota en la cuerda */ public TGNote getNote(TGBeat beat,int string) { Iterator it = beat.getNotes().iterator(); while(it.hasNext()){ TGNote note = (TGNote)it.next(); if (note.getString() == string) { return note; } } return null; } public TGNote getPreviousNote(TGMeasure measure,long start, int string) { TGBeat beat = getBeat(measure, start); if( beat != null ){ TGBeat previous = getPreviousBeat(measure.getBeats(),beat); while(previous != null){ for (int i = 0; i < previous.countNotes(); i++) { TGNote current = previous.getNote(i); if (current.getString() == string) { return current; } } previous = getPreviousBeat(measure.getBeats(),previous); } } return null; } public TGNote getNextNote(TGMeasure measure,long start, int string) { TGBeat beat = getBeat(measure, start); if( beat != null ){ TGBeat next = getNextBeat(measure.getBeats(),beat); while(next != null){ for (int i = 0; i < next.countNotes(); i++) { TGNote current = next.getNote(i); if (current.getString() == string) { return current; } } next = getNextBeat(measure.getBeats(),next); } } return null; } /** * Retorna las Nota en la posicion y cuerda */ public TGBeat getBeat(TGMeasure measure,long start) { Iterator it = measure.getBeats().iterator(); while(it.hasNext()){ TGBeat beat = (TGBeat)it.next(); if (beat.getStart() == start) { return beat; } } return null; } /** * Retorna las Nota en la posicion y cuerda */ public TGBeat getBeatIn(TGMeasure measure,long start) { Iterator it = measure.getBeats().iterator(); while(it.hasNext()){ TGBeat beat = (TGBeat)it.next(); if (beat.getStart() <= start && (beat.getStart() + beat.getDuration().getTime() > start)) { return beat; } } return null; } /** * Retorna el Siguiente Componente */ public TGBeat getNextBeat(List beats,TGBeat beat) { TGBeat next = null; for (int i = 0; i < beats.size(); i++) { TGBeat current = (TGBeat) beats.get(i); if (current.getStart() > beat.getStart()) { if (next == null) { next = current; } else if (current.getStart() < next.getStart()) { next = current; } else if (current.getStart() == next.getStart() && current.getDuration().getTime() <= next.getDuration().getTime()) { next = current; } } } return next; } /** * Retorna el Componente Anterior */ public TGBeat getPreviousBeat(List beats,TGBeat beat) { TGBeat previous = null; for (int i = 0; i < beats.size(); i++) { TGBeat current = (TGBeat) beats.get(i); if (current.getStart() < beat.getStart()) { if (previous == null) { previous = current; } else if (current.getStart() > previous.getStart()) { previous = current; } else if (current.getStart() == previous.getStart() && current.getDuration().getTime() <= previous.getDuration().getTime()) { previous = current; } } } return previous; } /** * Retorna el Primer Componente */ public TGBeat getFirstBeat(List components) { TGBeat first = null; for (int i = 0; i < components.size(); i++) { TGBeat component = (TGBeat) components.get(i); if (first == null || component.getStart() < first.getStart()) { first = component; } } return first; } /** * Retorna el Ultimo Componente */ public TGBeat getLastBeat(List components) { TGBeat last = null; for (int i = 0; i < components.size(); i++) { TGBeat component = (TGBeat) components.get(i); if (last == null || last.getStart() < component.getStart()) { last = component; } } return last; } /** * Retorna el Siguiente Componente */ public TGBeat getNextRestBeat(List beats,TGBeat component) { TGBeat next = getNextBeat(beats, component); while(next != null && !next.isRestBeat()){ next = getNextBeat(beats, next); } return next; } /** * Retorna Todos los desde Start hasta el final del compas */ public List getBeatsBeforeEnd(List beats,long fromStart) { List list = new ArrayList(); Iterator it = beats.iterator(); while(it.hasNext()){ TGBeat current = (TGBeat)it.next(); if (current.getStart() >= fromStart) { list.add(current); } } return list; } public void moveAllBeats(TGMeasure measure,long theMove){ moveBeats(measure.getBeats(),theMove); } public boolean moveBeats(TGMeasure measure,long start,long theMove, TGDuration fillDuration){ if( theMove == 0 ){ return false; } boolean success = true; long measureStart = measure.getStart(); long measureEnd = (measureStart + measure.getLength()); // Muevo los componentes List beatsToMove = getBeatsBeforeEnd(measure.getBeats(),start); moveBeats(beatsToMove,theMove); if(success){ List beatsToRemove = new ArrayList(); List beats = new ArrayList(measure.getBeats()); // Verifica los silencios a eliminar al principio del compas TGBeat first = getFirstBeat( beats ); while(first != null && first.isRestBeat() && !first.isTextBeat() && first.getStart() < measureStart){ beats.remove(first); beatsToRemove.add(first); first = getNextBeat( beats,first); } // Verifica los silencios a eliminar al final del compas TGBeat last = getLastBeat(beats); while(last != null && last.isRestBeat() && !last.isTextBeat() && (last.getStart() + last.getDuration().getTime() ) > measureEnd ){ beats.remove(last); beatsToRemove.add(last); last = getPreviousBeat(beats,last); } // Si el primer o ultimo componente, quedan fuera del compas, entonces el movimiento no es satisfactorio if(first != null && last != null){ if(first.getStart() < measureStart || (last.getStart() + last.getDuration().getTime()) > measureEnd){ success = false; } } if(success){ // Elimino los silencios que quedaron fuera del compas. Iterator it = beatsToRemove.iterator(); while( it.hasNext() ){ TGBeat beat = (TGBeat)it.next(); removeBeat(beat); } // Se crean silencios en los espacios vacios, si la duracion fue especificada. if( fillDuration != null ){ if( theMove < 0 ){ last = getLastBeat(measure.getBeats()); TGBeat beat = getSongManager().getFactory().newBeat(); beat.setStart( (last != null ? last.getStart() + last.getDuration().getTime() : start ) ); fillDuration.copy( beat.getDuration() ); if( (beat.getStart() + beat.getDuration().getTime()) <= measureEnd ){ addBeat(measure, beat ); } } else{ first = getFirstBeat(getBeatsBeforeEnd(measure.getBeats(),start)); TGBeat beat = getSongManager().getFactory().newBeat(); beat.setStart( start ); fillDuration.copy( beat.getDuration() ); if( (beat.getStart() + beat.getDuration().getTime()) <= (first != null ?first.getStart() : measureEnd ) ){ addBeat(measure, beat ); } } } } } // Si el movimiento no es satisfactorio, regreso todo como estaba if(! success ){ moveBeats(beatsToMove,-theMove); } return success; } /** * Mueve los componentes */ private void moveBeats(List beats,long theMove){ Iterator it = beats.iterator(); while(it.hasNext()){ TGBeat beat = (TGBeat)it.next(); moveBeat(beat,theMove); } } /** * Mueve el componente */ private void moveBeat(TGBeat beat,long theMove){ //obtengo el start viejo long start = beat.getStart(); //asigno el nuevo start beat.setStart(start + theMove); } public void cleanBeat(TGBeat beat){ if( beat.getText() != null ){ beat.removeChord(); } if( beat.getChord() != null){ beat.removeText(); } this.cleanBeatNotes(beat); } public void cleanBeatNotes(TGBeat beat){ while(beat.countNotes() > 0 ){ TGNote note = beat.getNote(0); removeNote(note); } } public void cleanBeatNotes(TGMeasure measure, long start){ TGBeat beat = getBeat(measure, start); if(beat != null){ cleanBeatNotes(beat); } } /** * Agrega el acorde al compas */ public void addChord(TGMeasure measure,long start, TGChord chord){ TGBeat beat = getBeat(measure, start); if(beat != null){ addChord(beat, chord); } } /** * Agrega el acorde al compas */ public void addChord(TGBeat beat,TGChord chord){ beat.removeChord(); beat.setChord(chord); } /** * Retorna el acorde en la position */ public TGChord getChord(TGMeasure measure,long start) { TGBeat beat = getBeat(measure, start); if(beat != null){ return beat.getChord(); } return null; } /** * Borra el acorde en la position */ public void removeChord(TGMeasure measure,long start) { TGBeat beat = getBeat(measure, start); if(beat != null){ beat.removeChord(); } } /** * Agrega el texto al compas */ public void addText(TGMeasure measure,long start, TGText text){ TGBeat beat = getBeat(measure, start); if(beat != null){ addText(beat, text); } } /** * Agrega el texto al compas */ public void addText(TGBeat beat,TGText text){ beat.removeText(); if(!text.isEmpty()){ beat.setText(text); } } /** * Retorna el texto en la position */ public TGText getText(TGMeasure measure,long start) { TGBeat beat = getBeat(measure, start); if(beat != null){ return beat.getText(); } return null; } /** * Borra el texto en el pulso */ public void removeText(TGBeat beat){ beat.removeText(); } /** * Borra el texto en la position */ public boolean removeText(TGMeasure measure,long start) { TGBeat beat = getBeat(measure, start); if(beat != null){ removeText(beat); return true; } return false; } public void cleanMeasure(TGMeasure measure){ while( measure.countBeats() > 0){ removeBeat( measure.getBeat(0)); } } /** * Mueve la nota a la cuerda de arriba */ public int shiftNoteUp(TGMeasure measure,long start,int string){ return shiftNote(measure, start, string,-1); } /** * Mueve la nota a la cuerda de abajo */ public int shiftNoteDown(TGMeasure measure,long start,int string){ return shiftNote(measure, start, string,1); } /** * Mueve la nota a la siguiente cuerda */ private int shiftNote(TGMeasure measure,long start,int string,int move){ TGNote note = getNote(measure,start,string); if(note != null){ int nextStringNumber = (note.getString() + move); while(getNote(measure,start,nextStringNumber) != null){ nextStringNumber += move; } if(nextStringNumber >= 1 && nextStringNumber <= measure.getTrack().stringCount()){ TGString currentString = measure.getTrack().getString(note.getString()); TGString nextString = measure.getTrack().getString(nextStringNumber); int noteValue = (note.getValue() + currentString.getValue()); if(noteValue >= nextString.getValue() && ((nextString.getValue() + 30 > noteValue) || measure.getTrack().isPercussionTrack()) ){ note.setValue(noteValue - nextString.getValue()); note.setString(nextString.getNumber()); return note.getString(); } } } return 0; } /** * Mueve la nota 1 semitono arriba */ public boolean moveSemitoneUp(TGMeasure measure,long start,int string){ return moveSemitone(measure, start, string,1); } /** * Mueve la nota 1 semitono abajo */ public boolean moveSemitoneDown(TGMeasure measure,long start,int string){ return moveSemitone(measure, start, string,-1); } /** * Mueve la nota los semitonos indicados */ private boolean moveSemitone(TGMeasure measure,long start,int string,int semitones){ TGNote note = getNote(measure,start,string); if(note != null){ int newValue = (note.getValue() + semitones); if(newValue >= 0 && (newValue < 30 || measure.getTrack().isPercussionTrack()) ){ note.setValue(newValue); return true; } } return false; } /** * Verifica si el componente se puede insertar en el compas. * si no puede, con la opcion removeSilences, verifica si el motivo por el * cual no entra es que lo siguen silencios. de ser asi los borra. */ public boolean validateDuration(TGMeasure measure,TGBeat beat,boolean moveNextComponents, boolean setCurrentDuration){ return validateDuration(measure, beat, beat.getDuration(),moveNextComponents, setCurrentDuration); } public boolean validateDuration(TGMeasure measure,TGBeat beat,TGDuration duration,boolean moveNextBeats, boolean setCurrentDuration){ int errorMargin = 10; this.orderBeats(measure); long measureStart = measure.getStart(); long measureEnd = (measureStart + measure.getLength()); long beatStart = beat.getStart(); long beatLength = duration.getTime(); long beatEnd = (beatStart + beatLength); List beats = measure.getBeats(); //Verifico si hay un beat en el mismo lugar, y comparo las duraciones. TGBeat currentBeat = getBeat(measure,beatStart); if(currentBeat != null && beatLength <= currentBeat.getDuration().getTime()){ /*if(componentAtBeat instanceof TGSilence){ removeSilence((TGSilence)componentAtBeat, false); }*/ return true; } //Verifico si hay lugar para meter el beat TGBeat nextComponent = getNextBeat(beats,beat); if(currentBeat == null){ if(nextComponent == null && beatEnd < (measureEnd + errorMargin)){ return true; } if(nextComponent != null && beatEnd < (nextComponent.getStart() + errorMargin)){ return true; } } // Busca si hay espacio disponible de silencios entre el componente y el el que le sigue.. si encuentra lo borra if(nextComponent != null && nextComponent.isRestBeat()){ //Verifico si lo que sigue es un silencio. y lo borro long nextBeatEnd = 0; List nextBeats = new ArrayList(); while(nextComponent != null && nextComponent.isRestBeat() && !nextComponent.isTextBeat()){ nextBeats.add(nextComponent); nextBeatEnd = nextComponent.getStart() + nextComponent.getDuration().getTime(); nextComponent = getNextBeat(beats,nextComponent); } if(nextComponent == null){ nextBeatEnd = measureEnd; }else if(!nextComponent.isRestBeat() || nextComponent.isTextBeat()){ nextBeatEnd = nextComponent.getStart(); } if(beatEnd <= (nextBeatEnd + errorMargin)){ while(!nextBeats.isEmpty()){ TGBeat currBeat = (TGBeat)nextBeats.get(0); nextBeats.remove(currBeat); removeBeat(currBeat, false); } return true; } } // Busca si hay espacio disponible de silencios entre el componente y el final.. si encuentra mueve todo if(moveNextBeats){ nextComponent = getNextBeat(beats,beat); if(nextComponent != null){ long requiredLength = (beatLength - (nextComponent.getStart() - beatStart)); long nextSilenceLength = 0; TGBeat nextRestBeat = getNextRestBeat(beats, beat); while(nextRestBeat != null && !nextRestBeat.isTextBeat()){ nextSilenceLength += nextRestBeat.getDuration().getTime(); nextRestBeat = getNextRestBeat(beats, nextRestBeat); } if(requiredLength <= (nextSilenceLength + errorMargin)){ beats = getBeatsBeforeEnd(measure.getBeats(),nextComponent.getStart()); while(!beats.isEmpty()){ TGBeat current = (TGBeat)beats.get(0); if(current.isRestBeat() && !current.isTextBeat()){ requiredLength -= current.getDuration().getTime(); removeBeat(current, false); }else if(requiredLength > 0){ moveBeat(current,requiredLength); } beats.remove(0); } return true; } } } // como ultimo intento, asigno la duracion de cualquier componente existente en el lugar. if(setCurrentDuration && currentBeat != null){ /*if(componentAtBeat instanceof TGSilence){ removeSilence((TGSilence)componentAtBeat, false); }*/ currentBeat.getDuration().copy( duration ); return true; } return false; } /** * Cambia la Duracion del pulso. */ public void changeDuration(TGMeasure measure,TGBeat beat,TGDuration duration,boolean tryMove){ //obtengo la duracion vieja TGDuration oldDuration = beat.getDuration().clone(getSongManager().getFactory()); //si no entra vuelvo a dejar la vieja if(validateDuration(measure,beat, duration,tryMove,false)){ //se lo agrego a todas las notas en la posicion beat.setDuration(duration.clone(getSongManager().getFactory())); //trato de agregar un silencio similar al lado tryChangeSilenceAfter(measure,beat); }else{ oldDuration.copy( beat.getDuration() ); } } public void tryChangeSilenceAfter(TGMeasure measure,TGBeat beat){ autoCompleteSilences(measure); TGBeat nextBeat = getNextBeat(measure.getBeats(),beat); long beatEnd = (beat.getStart() + beat.getDuration().getTime()); long measureEnd = (measure.getStart() + measure.getLength()); if(nextBeat != null && nextBeat.isRestBeat() && beatEnd <= measureEnd){ long theMove = (getRealStart(measure,beatEnd)) - getRealStart(measure,nextBeat.getStart()); if((nextBeat.getStart() + theMove) < measureEnd && (nextBeat.getStart() + nextBeat.getDuration().getTime() + theMove) <= measureEnd){ moveBeat(nextBeat,theMove); changeDuration(measure,nextBeat,beat.getDuration().clone(getSongManager().getFactory()),false); } } } /** * Calcula si hay espacios libres. y crea nuevos silencios */ public void autoCompleteSilences(TGMeasure measure){ long start = measure.getStart(); long end = 0; long diff = 0; List components = measure.getBeats(); TGBeat component = getFirstBeat(components); while (component != null) { end = component.getStart() + component.getDuration().getTime(); if(component.getStart() > start){ diff = component.getStart() - start; if(diff > 0){ createSilences(measure,start,diff); } } start = end; component = getNextBeat(components,component); } end = measure.getStart() + measure.getLength(); diff = end - start; if(diff > 0){ createSilences(measure,start,diff); } } /** * Crea Silencios temporarios en base a length */ private void createSilences(TGMeasure measure,long start,long length){ long nextStart = start; List durations = createDurations(getSongManager().getFactory(),length); Iterator it = durations.iterator(); while(it.hasNext()){ TGDuration duration = (TGDuration)it.next(); TGBeat beat = getSongManager().getFactory().newBeat(); beat.setStart( getRealStart(measure, nextStart) ); duration.copy(beat.getDuration()); addBeat(measure,beat); nextStart += duration.getTime(); } } public long getRealStart(TGMeasure measure,long currStart){ long beatLength = TGSongManager.getDivisionLength(measure.getHeader()); long start = currStart; boolean startBeat = (start % beatLength == 0); if(!startBeat){ TGDuration minDuration = getSongManager().getFactory().newDuration(); minDuration.setValue(TGDuration.SIXTY_FOURTH); minDuration.getTupleto().setEnters(3); minDuration.getTupleto().setTimes(2); for(int i = 0;i < minDuration.getTime();i++){ start ++; startBeat = (start % beatLength == 0); if(startBeat){ break; } } if(!startBeat){ start = currStart; } } return start; } /** * Liga la nota */ public void changeTieNote(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ changeTieNote(note); } } /** * Liga la nota */ public void changeTieNote(TGNote note){ note.setTiedNote(!note.isTiedNote()); note.getEffect().setDeadNote(false); } /** * Agrega un vibrato */ public void changeVibratoNote(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setVibrato(!note.getEffect().isVibrato()); } } /** * Agrega una nota muerta */ public void changeDeadNote(TGNote note){ note.getEffect().setDeadNote(!note.getEffect().isDeadNote()); note.setTiedNote(false); } /** * Agrega un slide */ public void changeSlideNote(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setSlide(!note.getEffect().isSlide()); } } /** * Agrega un hammer */ public void changeHammerNote(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setHammer(!note.getEffect().isHammer()); } } /** * Agrega un palm-mute */ public void changePalmMute(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setPalmMute(!note.getEffect().isPalmMute()); } } /** * Agrega un staccato */ public void changeStaccato(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setStaccato(!note.getEffect().isStaccato()); } } /** * Agrega un tapping */ public void changeTapping(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setTapping(!note.getEffect().isTapping()); } } /** * Agrega un slapping */ public void changeSlapping(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setSlapping(!note.getEffect().isSlapping()); } } /** * Agrega un popping */ public void changePopping(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setPopping(!note.getEffect().isPopping()); } } /** * Agrega un bend */ public void changeBendNote(TGMeasure measure,long start,int string,TGEffectBend bend){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setBend(bend); } } /** * Agrega un tremoloBar */ public void changeTremoloBar(TGMeasure measure,long start,int string,TGEffectTremoloBar tremoloBar){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setTremoloBar(tremoloBar); } } /** * Agrega un GhostNote */ public void changeGhostNote(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setGhostNote(!note.getEffect().isGhostNote()); } } /** * Agrega un AccentuatedNote */ public void changeAccentuatedNote(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setAccentuatedNote(!note.getEffect().isAccentuatedNote()); } } /** * Agrega un GhostNote */ public void changeHeavyAccentuatedNote(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setHeavyAccentuatedNote(!note.getEffect().isHeavyAccentuatedNote()); } } /** * Agrega un harmonic */ public void changeHarmonicNote(TGMeasure measure,long start,int string,TGEffectHarmonic harmonic){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setHarmonic(harmonic); } } /** * Agrega un grace */ public void changeGraceNote(TGMeasure measure,long start,int string,TGEffectGrace grace){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setGrace(grace); } } /** * Agrega un trill */ public void changeTrillNote(TGMeasure measure,long start,int string,TGEffectTrill trill){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setTrill(trill); } } /** * Agrega un tremolo picking */ public void changeTremoloPicking(TGMeasure measure,long start,int string,TGEffectTremoloPicking tremoloPicking){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setTremoloPicking(tremoloPicking); } } /** * Agrega un fadeIn */ public void changeFadeIn(TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.getEffect().setFadeIn(!note.getEffect().isFadeIn()); } } /** * Cambia el Velocity */ public void changeVelocity(int velocity,TGMeasure measure,long start,int string){ TGNote note = getNote(measure,start,string); if(note != null){ note.setVelocity(velocity); } } /* public static List createDurations(TGFactory factory,long time){ List durations = new ArrayList(); TGDuration tempDuration = factory.newDuration(); tempDuration.setValue(TGDuration.WHOLE); tempDuration.setDotted(true); long tempTime = time; boolean finish = false; while(!finish){ long currentDurationTime = tempDuration.getTime(); if(currentDurationTime <= tempTime){ durations.add(tempDuration.clone(factory)); tempTime -= currentDurationTime; }else{ if(tempDuration.isDotted()){ tempDuration.setDotted(false); }else{ tempDuration.setValue(tempDuration.getValue() * 2); tempDuration.setDotted(true); } } if(tempDuration.getValue() > TGDuration.SIXTY_FOURTH){ finish = true; } } return durations; } */ public static List createDurations(TGFactory factory,long time){ List durations = new ArrayList(); TGDuration minimum = factory.newDuration(); minimum.setValue(TGDuration.SIXTY_FOURTH); minimum.setDotted(false); minimum.setDoubleDotted(false); minimum.getTupleto().setEnters(3); minimum.getTupleto().setTimes(2); long missingTime = time; while( missingTime > minimum.getTime() ){ TGDuration duration = TGDuration.fromTime(factory, missingTime, minimum , 10); durations.add( duration.clone(factory) ); missingTime -= duration.getTime(); } return durations; } }

The table below shows all metrics for TGMeasureManager.java.

MetricValueDescription
BLOCKS219.00Number of blocks
BLOCK_COMMENT34.00Number of block comment lines
COMMENTS237.00Comment lines
COMMENT_DENSITY 0.41Comment density
COMPARISONS205.00Number of comparison operators
CYCLOMATIC252.00Cyclomatic complexity
DECL_COMMENTS58.00Comments in declarations
DOC_COMMENT176.00Number of javadoc comment lines
ELOC574.00Effective lines of code
EXEC_COMMENTS29.00Comments in executable code
EXITS136.00Procedure exits
FUNCTIONS80.00Number of function declarations
HALSTEAD_DIFFICULTY86.96Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY301.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 4.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 4.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108152.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA011021.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA011723.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 1.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 1.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 6.00JAVA0144 Line exceeds maximum M characters
JAVA01452444.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 0.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA025412.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1140.00Number of lines in the source file
LINE_COMMENT27.00Number of line comments
LOC787.00Lines of code
LOGICAL_LINES374.00Number of statements
LOOPS36.00Number of loops
NEST_DEPTH 6.00Maximum nesting depth
OPERANDS2155.00Number of operands
OPERATORS4170.00Number of operators
PARAMS202.00Number of formal parameter declarations
PROGRAM_LENGTH6325.00Halstead program length
PROGRAM_VOCAB616.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS99.00Number of return points from functions
SIZE31551.00Size of the file in bytes
UNIQUE_OPERANDS570.00Number of unique operands
UNIQUE_OPERATORS46.00Number of unique operators
WHITESPACE116.00Number of whitespace lines