2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2002--2015 Han-Wen Nienhuys, Jean-Baptiste Lamy <jiba@tuxfamily.org>,
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 #include "engraver.hh"
27 #include "articulations.hh"
28 #include "duration.hh"
30 #include "output-def.hh"
32 #include "rhythmic-head.hh"
33 #include "stream-event.hh"
37 #include "translator.icc"
40 make (guitar-like) tablature note
42 class Tab_note_heads_engraver : public Engraver
44 vector<Stream_event *> note_events_;
45 vector<Stream_event *> tabstring_events_;
46 vector<Stream_event *> fingering_events_;
49 TRANSLATOR_DECLARATIONS (Tab_note_heads_engraver);
52 void listen_note (Stream_event *);
53 void listen_string_number (Stream_event *);
54 void listen_fingering (Stream_event *);
55 void process_music ();
57 void stop_translation_timestep ();
60 Tab_note_heads_engraver::Tab_note_heads_engraver (Context *c)
66 Tab_note_heads_engraver::listen_note (Stream_event *ev)
68 note_events_.push_back (ev);
72 Tab_note_heads_engraver::listen_string_number (Stream_event *ev)
74 tabstring_events_.push_back (ev);
78 Tab_note_heads_engraver::listen_fingering (Stream_event *ev)
80 fingering_events_.push_back (ev);
84 Tab_note_heads_engraver::process_music ()
86 SCM tab_strings = articulation_list (note_events_,
88 "string-number-event");
89 SCM defined_fingers = articulation_list (note_events_,
92 SCM tab_notes = ly_cxx_vector_to_list (note_events_);
93 SCM proc = get_property ("noteToFretFunction");
94 SCM string_fret_finger = SCM_EOL;
95 if (ly_is_procedure (proc))
96 string_fret_finger = scm_call_3 (proc,
97 context ()->self_scm (),
99 scm_list_2 (tab_strings,
101 SCM note_entry = SCM_EOL;
102 SCM string_number = SCM_EOL;
104 SCM fret_label = SCM_EOL;
105 SCM fret_procedure = get_property ("tablatureFormat");
106 SCM staff_line_procedure = get_property ("tabStaffLineLayoutFunction");
107 SCM staff_position = SCM_EOL;
108 vsize fret_count = (vsize) scm_ilength (string_fret_finger);
109 bool length_changed = (note_events_.size () != fret_count);
112 if (!scm_is_null (string_fret_finger))
113 for (vsize i = 0; i < fret_count; i++)
115 note_entry = scm_list_ref (string_fret_finger, scm_from_int (i));
116 string_number = scm_car (note_entry);
117 if (scm_is_true (string_number))
119 fret = scm_cadr (note_entry);
120 fret_label = scm_call_3 (fret_procedure,
121 context ()->self_scm (),
124 index = length_changed ? 0 : i;
125 Item *note = make_item ("TabNoteHead", note_events_[index]->self_scm ());
126 note->set_property ("text", fret_label);
127 staff_position = scm_call_2 (staff_line_procedure,
128 context ()->self_scm (),
130 note->set_property ("staff-position", staff_position);
136 Tab_note_heads_engraver::stop_translation_timestep ()
138 note_events_.clear ();
139 tabstring_events_.clear ();
140 fingering_events_.clear ();
144 Tab_note_heads_engraver::boot ()
146 ADD_LISTENER (Tab_note_heads_engraver, note);
147 ADD_LISTENER (Tab_note_heads_engraver, string_number);
148 ADD_LISTENER (Tab_note_heads_engraver, fingering);
151 ADD_TRANSLATOR (Tab_note_heads_engraver,
153 "Generate one or more tablature note heads from event of type"
154 " @code{NoteEvent}.",
165 "noteToFretFunction "
169 "tabStaffLineLayoutFunction ",