]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tab-note-heads-engraver.cc
Run `make grand-replace'.
[lilypond.git] / lily / tab-note-heads-engraver.cc
index dd82a1d8e1fae32a8f7821d4ace8bab6fade03aa..ae012d65131d5d9c1e656dfb54b2379ff7caabfe 100644 (file)
@@ -1,7 +1,7 @@
 /*
   tab-note-heads-engraver.cc -- part of GNU LilyPond
 
-  (c) 2002--2007 Han-Wen Nienhuys, Jean-Baptiste Lamy <jiba@tuxfamily.org>,
+  (c) 2002--2008 Han-Wen Nienhuys, Jean-Baptiste Lamy <jiba@tuxfamily.org>,
 */
 
 #include <cctype>
@@ -67,11 +67,10 @@ Tab_note_heads_engraver::process_music ()
   for (vsize i = 0; i < note_events_.size (); i++)
     {
       SCM string_tunings = get_property ("stringTunings");
-      int number_of_strings = scm_ilength (string_tunings);
+      int string_count = scm_ilength (string_tunings);
       bool high_string_one = to_boolean (get_property ("highStringOne"));
 
       Stream_event *event = note_events_[i];
-      Item *note = make_item ("TabNoteHead", event->self_scm ());
 
       Stream_event *tabstring_event = 0;
 
@@ -91,53 +90,55 @@ Tab_note_heads_engraver::process_music ()
            j++;
        }
 
-      int tab_string;
-      bool string_found;
+      int string_number = 0;
       if (tabstring_event)
-       {
-         tab_string = scm_to_int (tabstring_event->get_property ("string-number"));
-         string_found = true;
-       }
-      else
-       {
-         tab_string = high_string_one ? 1 : number_of_strings;
-         string_found = false;
-       }
-
-      Duration dur = *unsmob_duration (event->get_property ("duration"));
+       string_number = scm_to_int (tabstring_event->get_property ("string-number"));
 
-      SCM scm_pitch = event->get_property ("pitch");
-      SCM proc = get_property ("tablatureFormat");
-      SCM min_fret_scm = get_property ("minimumFret");
-      int min_fret = scm_is_number (min_fret_scm) ? scm_to_int (min_fret_scm) : 0;
-
-      while (!string_found)
+      if (!string_number)
        {
-         int fret = unsmob_pitch (scm_pitch)->rounded_semitone_pitch ()
-           - scm_to_int (scm_list_ref (string_tunings, scm_from_int (tab_string - 1)));
-         if (fret < min_fret)
-           tab_string += high_string_one ? 1 : -1;
-         else
-           string_found = true;
+         SCM scm_pitch = event->get_property ("pitch");
+         int min_fret = robust_scm2int (get_property ("minimumFret"), 0);
+         int start = (high_string_one) ? 1 : string_count;
+         int end = (high_string_one) ? string_count+1 : 0;
+
+         int i = start;
+         do
+           {
+             int fret = unsmob_pitch (scm_pitch)->rounded_semitone_pitch ()
+               - scm_to_int (robust_list_ref (i - 1, string_tunings));
+         
+             if (fret >= min_fret)
+               {
+                 string_number = i;
+                 break;
+               }
+             i += high_string_one ? 1 : -1;
+           }
+         while (i != end);
        }
+      
+      if (string_number)
+       {
+         SCM proc = get_property ("tablatureFormat");
+         SCM text = scm_call_3 (proc, scm_from_int (string_number),
+                                context ()->self_scm (),
+                                event->self_scm ());
+         Item *note = make_item ("TabNoteHead", event->self_scm ());
+         note->set_property ("text", text);
 
-      SCM text = scm_call_3 (proc, scm_from_int (tab_string),
-                            context ()->self_scm (),
-                            event->self_scm ());
-      note->set_property ("text", text);
-
-
-      int pos = 2 * tab_string - number_of_strings - 1; // No tab-note between the string !!!
-      if (to_boolean (get_property ("stringOneTopmost")))
-       pos = -pos;
 
-      note->set_property ("staff-position", scm_from_int (pos));
+         int pos = 2 * string_number - string_count - 1; // No tab-note between the string !!!
+         if (to_boolean (get_property ("stringOneTopmost")))
+           pos = - pos;
 
+         note->set_property ("staff-position", scm_from_int (pos));
       
-      notes_.push_back (note);
+         notes_.push_back (note);
+       }
+      else
+       event->origin ()->warning ("could not calculate a string number.");
     }
 }
-
 void
 Tab_note_heads_engraver::stop_translation_timestep ()
 {
@@ -147,10 +148,12 @@ Tab_note_heads_engraver::stop_translation_timestep ()
 }
 
 ADD_TRANSLATOR (Tab_note_heads_engraver,
-               /* doc */ "Generate one or more tablature noteheads from event of type NoteEvent.",
+               /* doc */
+               "Generate one or more tablature noteheads from event of type"
+               " @code{NoteEvent}.",
+
                /* create */
-               "TabNoteHead "
-               ,
+               "TabNoteHead ",
 
                /* read */
                "middleCPosition "
@@ -160,5 +163,6 @@ ADD_TRANSLATOR (Tab_note_heads_engraver,
                "highStringOne "
                "stringOneTopmost ",
 
-               /* write */ "");
+               /* write */ ""
+               );