protected void adaptToTune ( Tune tune , ScoreMetrics metrics ) { //reinit the values of the engraving mode setMode ( m_mode , m_variation ) ; if ( m_mode != NONE ) { //11=notes spacing at 45px (default font size) double ratio = 100 * ( 11 / metrics . getNotesSpacing ( ) ) - 100 ; int oldVariation = m_variation ; setMode ( m_mode , m_variation - ( int ) ratio ) ; m_variation = oldVariation ; Music music = tune . getMusic ( ) ; Note shortestNote = music . getShortestNoteInAllVoices ( ) ; int shortestDuration = Note . SIXTEENTH ; if ( shortestNote != null ) shortestDuration = shortestNote . getDuration ( ) ; //System.out.println("shortest note duration = "+shortest.getDuration()); short min = /*(shortestDuration >= Note.QUARTER) ? Note.SIXTEENTH : */ Note . SIXTEENTH ; if ( shortestDuration > min ) { TreeSet set = new TreeSet ( spacesAfter . keySet ( ) ) ; Object [ ] durations = set . toArray ( ) ; int iMin = 0 , iShortest = 0 ; for ( int i = 0 ; i < durations . length ; i ++ ) { //System.out.println("durations["+i+"] = "+durations[i]); int j = ( Integer ) durations [ i ] ; if ( j == min ) iMin = i ; if ( j == shortestDuration ) iShortest = i ; } int offset = ( iShortest > iMin ) ? iShortest - iMin : 0 ; if ( offset != 0 ) { for ( int i = durations . length - 1 ; i >= iShortest ; i -- ) { //DEBUG /*String s = ""; for (Iterator itSet = set.iterator(); itSet.hasNext();) { Integer i2 = (Integer) itSet.next(); System.out.print(i2+"\t"); s += getSpaceAfter(i2.intValue())+"\t"; } System.out.println("\n"+s);*/ setSpaceAfter ( ( Integer ) durations [ i ] , getSpaceAfter ( ( Integer ) durations [ i - offset ] ) ) ; } } //System.out.println(spaceAfter.keySet().toArray()); //System.out.println(spaceAfter.entrySet().toArray()); } } }
Adapt the engraving to the tune i . e . search for the shortest note in the tune . If shortest note is a quarter we can reduce the space between quarter .