2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2015 Han-Wen Nienhuys
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/>.
24 #include "articulations.hh"
27 #include "engraver.hh"
29 #include "stream-event.hh"
32 #include "translator.icc"
35 make (guitar-like) tablature note
37 class Fretboard_engraver : public Engraver
41 vector<Stream_event *> note_events_;
42 vector<Stream_event *> tabstring_events_;
43 vector<Stream_event *> fingering_events_;
45 TRANSLATOR_DECLARATIONS (Fretboard_engraver);
48 void stop_translation_timestep ();
49 void process_music ();
50 virtual void derived_mark () const;
51 DECLARE_TRANSLATOR_LISTENER (note);
52 DECLARE_TRANSLATOR_LISTENER (string_number);
53 DECLARE_TRANSLATOR_LISTENER (fingering);
60 Fretboard_engraver::derived_mark () const
62 scm_gc_mark (last_placements_);
65 Fretboard_engraver::Fretboard_engraver ()
68 last_placements_ = SCM_BOOL_F;
71 IMPLEMENT_TRANSLATOR_LISTENER (Fretboard_engraver, note);
73 Fretboard_engraver::listen_note (Stream_event *ev)
75 note_events_.push_back (ev);
78 IMPLEMENT_TRANSLATOR_LISTENER (Fretboard_engraver, string_number);
80 Fretboard_engraver::listen_string_number (Stream_event *ev)
82 tabstring_events_.push_back (ev);
85 IMPLEMENT_TRANSLATOR_LISTENER (Fretboard_engraver, fingering);
87 Fretboard_engraver::listen_fingering (Stream_event *ev)
89 fingering_events_.push_back (ev);
93 Fretboard_engraver::process_music ()
95 if (!note_events_.size ())
98 SCM tab_strings = articulation_list (note_events_,
100 "string-number-event");
101 SCM fingers = articulation_list (note_events_,
104 fret_board_ = make_item ("FretBoard", note_events_[0]->self_scm ());
105 SCM fret_notes = ly_cxx_vector_to_list (note_events_);
106 SCM proc = get_property ("noteToFretFunction");
107 if (ly_is_procedure (proc))
109 context ()->self_scm (),
111 scm_list_2 (tab_strings, fingers),
112 fret_board_->self_scm ());
113 SCM changes = get_property ("chordChanges");
114 SCM placements = fret_board_->get_property ("dot-placement-list");
115 if (to_boolean (changes)
116 && ly_is_equal (last_placements_, placements))
117 fret_board_->set_property ("begin-of-line-visible", SCM_BOOL_T);
119 last_placements_ = placements;
123 Fretboard_engraver::stop_translation_timestep ()
126 note_events_.clear ();
127 tabstring_events_.clear ();
128 fingering_events_.clear ();
131 ADD_TRANSLATOR (Fretboard_engraver,
133 "Generate fret diagram from one or more events of type"
134 " @code{NoteEvent}.",
143 "maximumFretStretch "
145 "noteToFretFunction "
146 "predefinedDiagramTable "