2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2002--2009 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 "duration.hh"
29 #include "output-def.hh"
31 #include "rhythmic-head.hh"
32 #include "stream-event.hh"
36 #include "translator.icc"
39 make (guitar-like) tablature note
41 class Tab_note_heads_engraver : public Engraver
45 vector<Stream_event*> note_events_;
46 vector<Stream_event*> tabstring_events_;
48 TRANSLATOR_DECLARATIONS (Tab_note_heads_engraver);
51 DECLARE_TRANSLATOR_LISTENER (note);
52 DECLARE_TRANSLATOR_LISTENER (string_number);
53 void process_music ();
55 void stop_translation_timestep ();
58 Tab_note_heads_engraver::Tab_note_heads_engraver ()
62 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, note);
64 Tab_note_heads_engraver::listen_note (Stream_event *ev)
66 note_events_.push_back (ev);
69 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, string_number);
71 Tab_note_heads_engraver::listen_string_number (Stream_event *ev)
73 tabstring_events_.push_back (ev);
77 Tab_note_heads_engraver::process_music ()
80 for (vsize i = 0; i < note_events_.size (); i++)
82 SCM string_tunings = get_property ("stringTunings");
83 int string_count = scm_ilength (string_tunings);
84 bool high_string_one = to_boolean (get_property ("highStringOne"));
86 Stream_event *event = note_events_[i];
88 Stream_event *tabstring_event = 0;
90 for (SCM s = event->get_property ("articulations");
91 !tabstring_event && scm_is_pair (s); s = scm_cdr (s))
93 Stream_event *art = unsmob_stream_event (scm_car (s));
95 if (art->in_event_class ("string-number-event"))
96 tabstring_event = art;
99 if (!tabstring_event && j < tabstring_events_.size ())
101 tabstring_event = tabstring_events_[j];
102 if (j + 1 < tabstring_events_.size ())
106 int string_number = 0;
108 string_number = scm_to_int (tabstring_event->get_property ("string-number"));
112 SCM scm_pitch = event->get_property ("pitch");
113 int min_fret = robust_scm2int (get_property ("minimumFret"), 0);
114 int start = (high_string_one) ? 1 : string_count;
115 int end = (high_string_one) ? string_count+1 : 0;
120 int fret = unsmob_pitch (scm_pitch)->rounded_semitone_pitch ()
121 - scm_to_int (robust_list_ref (i - 1, string_tunings));
123 if (fret >= min_fret)
128 i += high_string_one ? 1 : -1;
135 SCM proc = get_property ("tablatureFormat");
136 SCM text = scm_call_3 (proc, scm_from_int (string_number),
137 context ()->self_scm (),
139 Item *note = make_item ("TabNoteHead", event->self_scm ());
140 note->set_property ("text", text);
143 int pos = 2 * string_number - string_count - 1; // No tab-note between the string !!!
144 if (to_boolean (get_property ("stringOneTopmost")))
147 note->set_property ("staff-position", scm_from_int (pos));
149 notes_.push_back (note);
152 event->origin ()->warning ("could not calculate a string number.");
156 Tab_note_heads_engraver::stop_translation_timestep ()
159 note_events_.clear ();
160 tabstring_events_.clear ();
163 ADD_TRANSLATOR (Tab_note_heads_engraver,
165 "Generate one or more tablature noteheads from event of type"
166 " @code{NoteEvent}.",