2 tab-note-heads-engraver.cc -- part of GNU LilyPond
4 based on note-heads-engraver.cc, by Jean-Baptiste Lamy <jiba@tuxfamily.org>,
12 #include "rhythmic-head.hh"
13 #include "output-def.hh"
16 #include "dot-column.hh"
17 #include "staff-symbol-referencer.hh"
19 #include "score-engraver.hh"
23 make (guitar-like) tablature note
25 class Tab_note_heads_engraver : public Engraver
27 Link_array<Item> notes_;
29 Link_array<Item> dots_;
30 Link_array<Music> note_events_;
31 Link_array<Music> tabstring_events_;
33 TRANSLATOR_DECLARATIONS (Tab_note_heads_engraver);
36 virtual bool try_music (Music *event);
37 virtual void process_music ();
39 virtual void stop_translation_timestep ();
42 Tab_note_heads_engraver::Tab_note_heads_engraver ()
47 Tab_note_heads_engraver::try_music (Music *m)
49 if (m->is_mus_type ("note-event"))
51 note_events_.push (m);
54 else if (m->is_mus_type ("string-number-event"))
56 tabstring_events_.push (m);
59 else if (m->is_mus_type ("busy-playing-event"))
61 return note_events_.size ();
68 Tab_note_heads_engraver::process_music ()
71 for (int i = 0; i < note_events_.size (); i++)
73 SCM stringTunings = get_property ("stringTunings");
74 int number_of_strings = ((int) ly_length (stringTunings));
75 bool high_string_one = to_boolean (get_property ("highStringOne"));
77 Music *event = note_events_[i];
78 Item *note = make_item ("TabNoteHead", event->self_scm ());
80 Music *tabstring_event = 0;
82 for (SCM s = event->get_property ("articulations");
83 !tabstring_event && scm_is_pair (s); s = scm_cdr (s))
85 Music *art = unsmob_music (scm_car (s));
87 if (art->is_mus_type ("string-number-event"))
88 tabstring_event = art;
91 if (!tabstring_event && j < tabstring_events_.size ())
93 tabstring_event = tabstring_events_[j];
94 if (j +1 < tabstring_events_.size ())
102 tab_string = scm_to_int (tabstring_event->get_property ("string-number"));
107 tab_string = high_string_one ? 1 : number_of_strings;
108 string_found = false;
111 Duration dur = *unsmob_duration (event->get_property ("duration"));
112 note->set_property ("duration-log",
113 scm_int2num (dur.duration_log ()));
115 if (dur.dot_count ())
117 Item *d = make_item ("Dots", event->self_scm ());
118 Rhythmic_head::set_dots (note, d);
121 != scm_to_int (d->get_property ("dot-count")))
122 d->set_property ("dot-count", scm_int2num (dur.dot_count ()));
124 d->set_parent (note, Y_AXIS);
129 SCM scm_pitch = event->get_property ("pitch");
130 SCM proc = get_property ("tablatureFormat");
131 SCM min_fret_scm = get_property ("minimumFret");
132 int min_fret = scm_is_number (min_fret_scm) ? scm_to_int (min_fret_scm) : 0;
134 while (!string_found)
136 int fret = unsmob_pitch (scm_pitch)->semitone_pitch ()
137 - scm_to_int (scm_list_ref (stringTunings, scm_int2num (tab_string - 1)));
139 tab_string += high_string_one ? 1 : -1;
144 SCM text = scm_call_3 (proc, scm_int2num (tab_string), stringTunings, scm_pitch);
146 int pos = 2 * tab_string - number_of_strings - 1; // No tab-note between the string !!!
147 if (to_boolean (get_property ("stringOneTopmost")))
150 note->set_property ("text", text);
152 note->set_property ("staff-position", scm_int2num (pos));
158 Tab_note_heads_engraver::stop_translation_timestep ()
162 note_events_.clear ();
163 tabstring_events_.clear ();
166 ADD_TRANSLATOR (Tab_note_heads_engraver,
167 /* descr */ "Generate one or more tablature noteheads from Music of type NoteEvent.",
168 /* creats*/ "TabNoteHead Dots",
169 /* accepts */ "note-event string-number-event busy-playing-event",
171 /* reads */ "middleCPosition stringTunings minimumFret tablatureFormat highStringOne stringOneTopmost",