Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / tab-note-heads-engraver.cc
blob958c85d3e7d5b55bdecd2c33d5a19c1483c40c23
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2002--2011 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/>.
20 #include <cctype>
21 #include <cstdio>
23 #include "engraver.hh"
25 using namespace std;
27 #include "articulations.hh"
28 #include "duration.hh"
29 #include "item.hh"
30 #include "output-def.hh"
31 #include "pitch.hh"
32 #include "rhythmic-head.hh"
33 #include "stream-event.hh"
34 #include "warn.hh"
35 #include "context.hh"
37 #include "translator.icc"
39 /**
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_;
48 public:
49 TRANSLATOR_DECLARATIONS (Tab_note_heads_engraver);
51 protected:
52 DECLARE_TRANSLATOR_LISTENER (note);
53 DECLARE_TRANSLATOR_LISTENER (string_number);
54 DECLARE_TRANSLATOR_LISTENER (fingering);
55 void process_music ();
57 void stop_translation_timestep ();
60 Tab_note_heads_engraver::Tab_note_heads_engraver ()
64 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, note);
65 void
66 Tab_note_heads_engraver::listen_note (Stream_event *ev)
68 note_events_.push_back (ev);
71 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, string_number);
72 void
73 Tab_note_heads_engraver::listen_string_number (Stream_event *ev)
75 tabstring_events_.push_back (ev);
78 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, fingering);
79 void
80 Tab_note_heads_engraver::listen_fingering (Stream_event *ev)
82 fingering_events_.push_back (ev);
85 void
86 Tab_note_heads_engraver::process_music ()
88 SCM tab_strings = articulation_list (note_events_,
89 tabstring_events_,
90 "string-number-event");
91 SCM defined_fingers = articulation_list (note_events_,
92 fingering_events_,
93 "fingering-event");
94 SCM tab_notes = ly_cxx_vector_to_list (note_events_);
95 SCM proc = get_property ("noteToFretFunction");
96 SCM string_fret_finger = SCM_EOL;
97 if (ly_is_procedure (proc))
98 string_fret_finger = scm_call_3 (proc,
99 context ()->self_scm (),
100 tab_notes,
101 scm_list_2 (tab_strings,
102 defined_fingers));
103 SCM note_entry = SCM_EOL;
104 SCM string_number = SCM_EOL;
105 SCM fret = SCM_EOL;
106 SCM fret_label = SCM_EOL;
107 SCM fret_procedure = get_property ("tablatureFormat");
108 SCM staff_line_procedure = get_property ("tabStaffLineLayoutFunction");
109 SCM staff_position = SCM_EOL;
110 vsize fret_count = (vsize) scm_ilength (string_fret_finger);
111 bool length_changed = (note_events_.size () != fret_count);
112 vsize index;
114 if (string_fret_finger != SCM_EOL)
115 for (vsize i = 0; i < fret_count; i++)
117 note_entry = scm_list_ref (string_fret_finger, scm_from_int (i));
118 string_number = scm_car (note_entry);
119 fret = scm_cadr (note_entry);
120 fret_label = scm_call_3 (fret_procedure,
121 context ()->self_scm (),
122 string_number,
123 fret);
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 (),
129 string_number);
130 note->set_property ("staff-position", staff_position);
134 void
135 Tab_note_heads_engraver::stop_translation_timestep ()
137 note_events_.clear ();
138 tabstring_events_.clear ();
139 fingering_events_.clear ();
142 ADD_TRANSLATOR (Tab_note_heads_engraver,
143 /* doc */
144 "Generate one or more tablature note heads from event of type"
145 " @code{NoteEvent}.",
147 /* create */
148 "TabNoteHead ",
150 /* read */
151 "defaultStrings "
152 "fretLabels "
153 "highStringOne "
154 "middleCPosition "
155 "minimumFret "
156 "noteToFretFunction "
157 "stringOneTopmost "
158 "stringTunings "
159 "tablatureFormat "
160 "tabStaffLineLayoutFunction ",
162 /* write */