public void computeFingerings(Collection musicElements) {
		if (computedFingerings != null)
			computedFingerings.clear();
		//collect all notes
		Collection notes = new ArrayList(musicElements.size());
		Iterator it = musicElements.iterator();
		while (it.hasNext()) {
			MusicElement element = (MusicElement) it.next();
			if (element instanceof NoteAbstract) {
				NoteAbstract[] graces = ((NoteAbstract) element).getGracingNotes();
				if (graces != null) {
                    Collections.addAll(notes, graces);
				}
				notes.add(element);
			}
		}
		computedFingerings = new HashMap(notes.size());
		
		//TODO iterate notes collection, compute fingering
		it = notes.iterator();
		NoteAbstract lastNote = null;
		while (it.hasNext()) {
			NoteAbstract currentNote = (NoteAbstract) it.next();
			if (currentNote instanceof MultiNote) {
				//we have a chord
                for (Object o : (((MultiNote) currentNote).getNotesAsVector())) {
                    Note note = (Note) o;
                    if (note.isRest() || note.isEndingTie())
                        continue;
                    //just a random thing to put numbers on the tab :-)
                    int string = 1 + (int) (Math.random() * (m_strings.length - 1));
                    int fret = (int) (Math.random() * m_numberOfFret);
                    computedFingerings.put(note.getReference(),
                            new int[]{string, fret});
                }
			} else if (currentNote instanceof Note) {
				Note note = (Note) currentNote;
				if (!note.isEndingTie()) {
					int[] pos = null;
					if (note.isRest()) {
						//reinit penalty, player may have time
						//to move on the neck
					}
					else if ((lastNote != null)
						&& (lastNote instanceof Note)
						&& (note.getMidiLikeHeight()
							== ((Note)lastNote).getMidiLikeHeight())
						&& ((pos = getFingeringForNote((Note)lastNote)) != null)) {
						//If the current note is the same than the last note
						//keep the same position
						computedFingerings.put(note.getReference(),
							new int[] {pos[0], pos[1]});
					} else {
						//just a random thing to put numbers on the tab :-)
						int string = 1+(int)Math.round(Math.random()*(m_strings.length-1));
						int fret = (int)(Math.random()*m_numberOfFret);
						computedFingerings.put(note.getReference(),
							new int[]{string, fret});
					}
				}
			}
			lastNote = currentNote;
		}
		//use penalty parameters, use private field if needed:
		//- maximal gap between index finger and little finger
		//	e.g. guitar: 3 frets near headstock/nut, 5 near body
		//		 charango: 5 near headstock/nut, 7 near body
		//- pick another string (small penalty)
		//- move finger to another fret (greater penalty)
		//- void string in a chord (increasing with number of strings
		//	(no penalty for 3 or 4 strings, huge penalty for 7+ strings...)
		//
		//if a note is impossible to render on tab, set fret number to -1
		//(note lower than lowest string, more notes in MultiNote than strings...)
		//capodastre position = the minimal fret value
		
	}
public void computeFingerings ( Collection musicElements ) { if ( computedFingerings != null ) computedFingerings . clear ( ) ; Collection notes = new ArrayList ( musicElements . size ( ) ) ; Iterator it = musicElements . iterator ( ) ; while ( it . hasNext ( ) ) { MusicElement element = ( MusicElement ) it . next ( ) ; if ( element instanceof NoteAbstract ) { NoteAbstract [ ] graces = ( ( NoteAbstract ) element ) . getGracingNotes ( ) ; if ( graces != null ) { Collections . addAll ( notes , graces ) ; } notes . add ( element ) ; } } computedFingerings = new HashMap ( notes . size ( ) ) ; it = notes . iterator ( ) ; NoteAbstract lastNote = null ; while ( it . hasNext ( ) ) { NoteAbstract currentNote = ( NoteAbstract ) it . next ( ) ; if ( currentNote instanceof MultiNote ) { for ( Object o : ( ( ( MultiNote ) currentNote ) . getNotesAsVector ( ) ) ) { Note note = ( Note ) o ; if ( note . isRest ( ) || note . isEndingTie ( ) ) continue ; int string = 1 + ( int ) ( Math . random ( ) * ( m_strings . length - 1 ) ) ; int fret = ( int ) ( Math . random ( ) * m_numberOfFret ) ; computedFingerings . put ( note . getReference ( ) , new int [ ] { string , fret } ) ; } } else if ( currentNote instanceof Note ) { Note note = ( Note ) currentNote ; if ( ! note . isEndingTie ( ) ) { int [ ] pos = null ; if ( note . isRest ( ) ) { } else if ( ( lastNote != null ) && ( lastNote instanceof Note ) && ( note . getMidiLikeHeight ( ) == ( ( Note ) lastNote ) . getMidiLikeHeight ( ) ) && ( ( pos = getFingeringForNote ( ( Note ) lastNote ) ) != null ) ) { computedFingerings . put ( note . getReference ( ) , new int [ ] { pos [ 0 ] , pos [ 1 ] } ) ; } else { int string = 1 + ( int ) Math . round ( Math . random ( ) * ( m_strings . length - 1 ) ) ; int fret = ( int ) ( Math . random ( ) * m_numberOfFret ) ; computedFingerings . put ( note . getReference ( ) , new int [ ] { string , fret } ) ; } } } lastNote = currentNote ; } }
Here is the brain of tablature fingerings computation.
@param musicElements Collection of MusicElement in which notes
will be used for computation.