2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2002--2010 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 ()
81 vector
<Stream_event
*> string_events
;
83 for (vsize i
= 0; i
< note_events_
.size (); i
++)
86 Stream_event
*event
= note_events_
[i
];
88 Stream_event
*tabstring_event
= 0;
91 For notes inside a chord construct, string indications are
92 stored as articulations on the note, so we check through
95 for (SCM s
= event
->get_property ("articulations");
96 !tabstring_event
&& scm_is_pair (s
); s
= scm_cdr (s
))
98 Stream_event
*art
= unsmob_stream_event (scm_car (s
));
100 if (art
->in_event_class ("string-number-event"))
101 tabstring_event
= art
;
105 For string indications listed outside a chord construct,
106 a string_number_event is generated, so if there was no string
107 in the articulations, we check for string events outside
110 if (!tabstring_event
&& j
< tabstring_events_
.size ())
112 tabstring_event
= tabstring_events_
[j
];
113 if (j
+ 1 < tabstring_events_
.size ())
117 string_events
.push_back (tabstring_event
);
120 SCM tab_notes
= ly_cxx_vector_to_list (note_events_
);
121 SCM tab_strings
= SCM_EOL
;
122 if (string_events
.size ())
123 tab_strings
= ly_cxx_vector_to_list (string_events
);
124 SCM proc
= get_property ("noteToFretFunction");
125 SCM string_fret_finger
= SCM_EOL
;
126 if (ly_is_procedure (proc
))
127 string_fret_finger
= scm_call_3 (proc
,
128 context ()->self_scm (),
131 SCM note_entry
= SCM_EOL
;
132 SCM string_number
= SCM_EOL
;
134 SCM fret_label
= SCM_EOL
;
135 SCM fret_procedure
= get_property ("tablatureFormat");
136 SCM staff_line_procedure
= get_property ("tabStaffLineLayoutFunction");
137 SCM staff_position
= SCM_EOL
;
138 vsize fret_count
= (vsize
) scm_ilength (string_fret_finger
);
139 bool length_changed
= (note_events_
.size () != fret_count
);
142 if (string_fret_finger
!= SCM_EOL
)
143 for (vsize i
=0; i
< fret_count
; i
++)
145 note_entry
= scm_list_ref (string_fret_finger
, scm_from_int (i
));
146 string_number
= scm_car (note_entry
);
147 fret
= scm_cadr (note_entry
);
148 fret_label
= scm_call_3 (fret_procedure
,
149 context ()->self_scm (),
152 index
= length_changed
? 0 : i
;
153 Item
*note
= make_item ("TabNoteHead", note_events_
[index
]->self_scm ());
154 note
->set_property ("text", fret_label
);
155 staff_position
= scm_call_2 (staff_line_procedure
,
156 context ()->self_scm (),
158 note
->set_property ("staff-position", staff_position
);
159 notes_
.push_back (note
);
164 Tab_note_heads_engraver::stop_translation_timestep ()
167 note_events_
.clear ();
168 tabstring_events_
.clear ();
171 ADD_TRANSLATOR (Tab_note_heads_engraver
,
173 "Generate one or more tablature noteheads from event of type"
174 " @code{NoteEvent}.",
184 "noteToFretFunction "
188 "tabStaffLineLayoutFunction ",