X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftab-note-heads-engraver.cc;h=f89dad11009e6271ecbffbc7e6f827c30b5f64e9;hb=38d7d319eabc906e82fb42002678c6d42a23b6f7;hp=d7e3f9bd66ebc0eb9a292793f954acfb9f89e1d9;hpb=bd78c003160e138bc3118ee8ede5929d6011d58e;p=lilypond.git diff --git a/lily/tab-note-heads-engraver.cc b/lily/tab-note-heads-engraver.cc index d7e3f9bd66..f89dad1100 100644 --- a/lily/tab-note-heads-engraver.cc +++ b/lily/tab-note-heads-engraver.cc @@ -1,26 +1,24 @@ /* tab-note-heads-engraver.cc -- part of GNU LilyPond - based on note-heads-engraver.cc, by Jean-Baptiste Lamy , - - (c) 2002--2006 + (c) 2002--2009 Han-Wen Nienhuys, Jean-Baptiste Lamy , */ #include #include + +#include "engraver.hh" + using namespace std; -#include "dot-column.hh" -#include "dots.hh" #include "duration.hh" #include "item.hh" #include "output-def.hh" #include "pitch.hh" #include "rhythmic-head.hh" -#include "score-engraver.hh" -#include "staff-symbol-referencer.hh" #include "stream-event.hh" #include "warn.hh" +#include "context.hh" #include "translator.icc" @@ -68,12 +66,11 @@ Tab_note_heads_engraver::process_music () vsize j = 0; for (vsize i = 0; i < note_events_.size (); i++) { - SCM stringTunings = get_property ("stringTunings"); - int number_of_strings = ((int) ly_length (stringTunings)); + SCM string_tunings = get_property ("stringTunings"); + 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; @@ -93,49 +90,55 @@ Tab_note_heads_engraver::process_music () j++; } - int tab_string; - bool string_found; + int string_number = 0; if (tabstring_event) + string_number = scm_to_int (tabstring_event->get_property ("string-number")); + + if (!string_number) { - tab_string = scm_to_int (tabstring_event->get_property ("string-number")); - 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); } - else + + if (string_number) { - tab_string = high_string_one ? 1 : number_of_strings; - string_found = false; - } + 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); - Duration dur = *unsmob_duration (event->get_property ("duration")); - 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; + int pos = 2 * string_number - string_count - 1; // No tab-note between the string !!! + if (to_boolean (get_property ("stringOneTopmost"))) + pos = - pos; - while (!string_found) - { - int fret = unsmob_pitch (scm_pitch)->semitone_pitch () - - scm_to_int (scm_list_ref (stringTunings, scm_from_int (tab_string - 1))); - if (fret < min_fret) - tab_string += high_string_one ? 1 : -1; - else - string_found = true; + note->set_property ("staff-position", scm_from_int (pos)); + + notes_.push_back (note); } - - SCM text = scm_call_3 (proc, scm_from_int (tab_string), stringTunings, scm_pitch); - - 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 ("text", text); - - note->set_property ("staff-position", scm_from_int (pos)); - notes_.push_back (note); + else + event->origin ()->warning ("could not calculate a string number."); } } - void Tab_note_heads_engraver::stop_translation_timestep () { @@ -145,14 +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.", - /* create */ - "TabNoteHead " - , + /* doc */ + "Generate one or more tablature noteheads from event of type" + " @code{NoteEvent}.", - /* accept */ - "note-event " - "string-number-event ", + /* create */ + "TabNoteHead ", /* read */ "middleCPosition " @@ -162,5 +163,6 @@ ADD_TRANSLATOR (Tab_note_heads_engraver, "highStringOne " "stringOneTopmost ", - /* write */ ""); + /* write */ "" + );