2 tab-note-heads-engraver.cc -- part of GNU LilyPond
4 based on note-heads-engraver.cc, by Jean-Baptiste Lamy <jiba@tuxfamily.org>,
13 #include "dot-column.hh"
15 #include "duration.hh"
18 #include "output-def.hh"
19 #include "rhythmic-head.hh"
20 #include "score-engraver.hh"
21 #include "staff-symbol-referencer.hh"
22 #include "stream-event.hh"
25 #include "translator.icc"
28 make (guitar-like) tablature note
30 class Tab_note_heads_engraver : public Engraver
35 vector<Stream_event*> note_events_;
36 vector<Stream_event*> tabstring_events_;
38 TRANSLATOR_DECLARATIONS (Tab_note_heads_engraver);
41 DECLARE_TRANSLATOR_LISTENER (note);
42 DECLARE_TRANSLATOR_LISTENER (string_number);
43 void process_music ();
45 void stop_translation_timestep ();
48 Tab_note_heads_engraver::Tab_note_heads_engraver ()
52 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, note);
54 Tab_note_heads_engraver::listen_note (Stream_event *ev)
56 note_events_.push_back (ev);
59 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, string_number);
61 Tab_note_heads_engraver::listen_string_number (Stream_event *ev)
63 tabstring_events_.push_back (ev);
67 Tab_note_heads_engraver::process_music ()
70 for (vsize i = 0; i < note_events_.size (); i++)
72 SCM stringTunings = get_property ("stringTunings");
73 int number_of_strings = ((int) ly_length (stringTunings));
74 bool high_string_one = to_boolean (get_property ("highStringOne"));
76 Stream_event *event = note_events_[i];
77 Item *note = make_item ("TabNoteHead", event->self_scm ());
79 Stream_event *tabstring_event = 0;
81 for (SCM s = event->get_property ("articulations");
82 !tabstring_event && scm_is_pair (s); s = scm_cdr (s))
84 Music *art = unsmob_music (scm_car (s));
86 if (art->is_mus_type ("string-number-event"))
87 tabstring_event = art->to_event ();
90 if (!tabstring_event && j < tabstring_events_.size ())
92 tabstring_event = tabstring_events_[j];
93 if (j + 1 < tabstring_events_.size ())
101 tab_string = scm_to_int (tabstring_event->get_property ("string-number"));
106 tab_string = high_string_one ? 1 : number_of_strings;
107 string_found = false;
110 Duration dur = *unsmob_duration (event->get_property ("duration"));
111 note->set_property ("duration-log",
112 scm_from_int (dur.duration_log ()));
114 if (dur.dot_count ())
116 Item *d = make_item ("Dots", event->self_scm ());
117 Rhythmic_head::set_dots (note, d);
120 != scm_to_int (d->get_property ("dot-count")))
121 d->set_property ("dot-count", scm_from_int (dur.dot_count ()));
123 d->set_parent (note, Y_AXIS);
128 SCM scm_pitch = event->get_property ("pitch");
129 SCM proc = get_property ("tablatureFormat");
130 SCM min_fret_scm = get_property ("minimumFret");
131 int min_fret = scm_is_number (min_fret_scm) ? scm_to_int (min_fret_scm) : 0;
133 while (!string_found)
135 int fret = unsmob_pitch (scm_pitch)->semitone_pitch ()
136 - scm_to_int (scm_list_ref (stringTunings, scm_from_int (tab_string - 1)));
138 tab_string += high_string_one ? 1 : -1;
143 SCM text = scm_call_3 (proc, scm_from_int (tab_string), stringTunings, scm_pitch);
145 int pos = 2 * tab_string - number_of_strings - 1; // No tab-note between the string !!!
146 if (to_boolean (get_property ("stringOneTopmost")))
149 note->set_property ("text", text);
151 note->set_property ("staff-position", scm_from_int (pos));
152 notes_.push_back (note);
157 Tab_note_heads_engraver::stop_translation_timestep ()
161 note_events_.clear ();
162 tabstring_events_.clear ();
165 ADD_TRANSLATOR (Tab_note_heads_engraver,
166 /* doc */ "Generate one or more tablature noteheads from Music of type NoteEvent.",
167 /* create */ "TabNoteHead Dots",
168 /* accept */ "note-event string-number-event",
169 /* read */ "middleCPosition stringTunings minimumFret tablatureFormat highStringOne stringOneTopmost",