]> git.donarmstrong.com Git - lilypond.git/blob - lily/tab-note-heads-engraver.cc
Merge branch 'master' of /home/jcharles/GIT/Lily/. into translation
[lilypond.git] / lily / tab-note-heads-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2002--2015 Han-Wen Nienhuys, Jean-Baptiste Lamy <jiba@tuxfamily.org>,
5
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.
10
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.
15
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/>.
18 */
19
20 #include <cctype>
21 #include <cstdio>
22
23 #include "engraver.hh"
24
25 using namespace std;
26
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"
36
37 #include "translator.icc"
38
39 /**
40    make (guitar-like) tablature note
41 */
42 class Tab_note_heads_engraver : public Engraver
43 {
44   vector<Stream_event *> note_events_;
45   vector<Stream_event *> tabstring_events_;
46   vector<Stream_event *> fingering_events_;
47
48 public:
49   TRANSLATOR_DECLARATIONS (Tab_note_heads_engraver);
50
51 protected:
52   void listen_note (Stream_event *);
53   void listen_string_number (Stream_event *);
54   void listen_fingering (Stream_event *);
55   void process_music ();
56
57   void stop_translation_timestep ();
58 };
59
60 Tab_note_heads_engraver::Tab_note_heads_engraver ()
61 {
62 }
63
64 void
65 Tab_note_heads_engraver::listen_note (Stream_event *ev)
66 {
67   note_events_.push_back (ev);
68 }
69
70 void
71 Tab_note_heads_engraver::listen_string_number (Stream_event *ev)
72 {
73   tabstring_events_.push_back (ev);
74 }
75
76 void
77 Tab_note_heads_engraver::listen_fingering (Stream_event *ev)
78 {
79   fingering_events_.push_back (ev);
80 }
81
82 void
83 Tab_note_heads_engraver::process_music ()
84 {
85   SCM tab_strings = articulation_list (note_events_,
86                                        tabstring_events_,
87                                        "string-number-event");
88   SCM defined_fingers = articulation_list (note_events_,
89                                            fingering_events_,
90                                            "fingering-event");
91   SCM tab_notes = ly_cxx_vector_to_list (note_events_);
92   SCM proc = get_property ("noteToFretFunction");
93   SCM string_fret_finger = SCM_EOL;
94   if (ly_is_procedure (proc))
95     string_fret_finger = scm_call_3 (proc,
96                                      context ()->self_scm (),
97                                      tab_notes,
98                                      scm_list_2 (tab_strings,
99                                                  defined_fingers));
100   SCM note_entry = SCM_EOL;
101   SCM string_number = SCM_EOL;
102   SCM fret = SCM_EOL;
103   SCM fret_label = SCM_EOL;
104   SCM fret_procedure = get_property ("tablatureFormat");
105   SCM staff_line_procedure = get_property ("tabStaffLineLayoutFunction");
106   SCM staff_position = SCM_EOL;
107   vsize fret_count = (vsize) scm_ilength (string_fret_finger);
108   bool length_changed = (note_events_.size () != fret_count);
109   vsize index;
110
111   if (!scm_is_null (string_fret_finger))
112     for (vsize i = 0; i < fret_count; i++)
113       {
114         note_entry = scm_list_ref (string_fret_finger, scm_from_int (i));
115         string_number = scm_car (note_entry);
116         if (scm_is_true (string_number))
117           {
118             fret = scm_cadr (note_entry);
119             fret_label = scm_call_3 (fret_procedure,
120                                      context ()->self_scm (),
121                                      string_number,
122                                      fret);
123             index = length_changed ? 0 : i;
124             Item *note = make_item ("TabNoteHead", note_events_[index]->self_scm ());
125             note->set_property ("text", fret_label);
126             staff_position = scm_call_2 (staff_line_procedure,
127                                          context ()->self_scm (),
128                                          string_number);
129             note->set_property ("staff-position", staff_position);
130           }
131       }
132 }
133
134 void
135 Tab_note_heads_engraver::stop_translation_timestep ()
136 {
137   note_events_.clear ();
138   tabstring_events_.clear ();
139   fingering_events_.clear ();
140 }
141
142 void
143 Tab_note_heads_engraver::boot ()
144 {
145   ADD_LISTENER (Tab_note_heads_engraver, note);
146   ADD_LISTENER (Tab_note_heads_engraver, string_number);
147   ADD_LISTENER (Tab_note_heads_engraver, fingering);
148 }
149
150 ADD_TRANSLATOR (Tab_note_heads_engraver,
151                 /* doc */
152                 "Generate one or more tablature note heads from event of type"
153                 " @code{NoteEvent}.",
154
155                 /* create */
156                 "TabNoteHead ",
157
158                 /* read */
159                 "defaultStrings "
160                 "fretLabels "
161                 "highStringOne "
162                 "middleCPosition "
163                 "minimumFret "
164                 "noteToFretFunction "
165                 "stringOneTopmost "
166                 "stringTunings "
167                 "tablatureFormat "
168                 "tabStaffLineLayoutFunction ",
169
170                 /* write */
171                 ""
172                );
173