]> git.donarmstrong.com Git - lilypond.git/blob - lily/tab-note-heads-engraver.cc
Issue 4550 (2/2) Avoid "using namespace std;" in included files
[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
26 #include "articulations.hh"
27 #include "duration.hh"
28 #include "item.hh"
29 #include "output-def.hh"
30 #include "pitch.hh"
31 #include "rhythmic-head.hh"
32 #include "stream-event.hh"
33 #include "warn.hh"
34 #include "context.hh"
35
36 #include "translator.icc"
37
38 using std::vector;
39
40 /**
41    make (guitar-like) tablature note
42 */
43 class Tab_note_heads_engraver : public Engraver
44 {
45   vector<Stream_event *> note_events_;
46   vector<Stream_event *> tabstring_events_;
47   vector<Stream_event *> fingering_events_;
48
49 public:
50   TRANSLATOR_DECLARATIONS (Tab_note_heads_engraver);
51
52 protected:
53   DECLARE_TRANSLATOR_LISTENER (note);
54   DECLARE_TRANSLATOR_LISTENER (string_number);
55   DECLARE_TRANSLATOR_LISTENER (fingering);
56   void process_music ();
57
58   void stop_translation_timestep ();
59 };
60
61 Tab_note_heads_engraver::Tab_note_heads_engraver ()
62 {
63 }
64
65 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, note);
66 void
67 Tab_note_heads_engraver::listen_note (Stream_event *ev)
68 {
69   note_events_.push_back (ev);
70 }
71
72 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, string_number);
73 void
74 Tab_note_heads_engraver::listen_string_number (Stream_event *ev)
75 {
76   tabstring_events_.push_back (ev);
77 }
78
79 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, fingering);
80 void
81 Tab_note_heads_engraver::listen_fingering (Stream_event *ev)
82 {
83   fingering_events_.push_back (ev);
84 }
85
86 void
87 Tab_note_heads_engraver::process_music ()
88 {
89   SCM tab_strings = articulation_list (note_events_,
90                                        tabstring_events_,
91                                        "string-number-event");
92   SCM defined_fingers = articulation_list (note_events_,
93                                            fingering_events_,
94                                            "fingering-event");
95   SCM tab_notes = ly_cxx_vector_to_list (note_events_);
96   SCM proc = get_property ("noteToFretFunction");
97   SCM string_fret_finger = SCM_EOL;
98   if (ly_is_procedure (proc))
99     string_fret_finger = scm_call_3 (proc,
100                                      context ()->self_scm (),
101                                      tab_notes,
102                                      scm_list_2 (tab_strings,
103                                                  defined_fingers));
104   SCM note_entry = SCM_EOL;
105   SCM string_number = SCM_EOL;
106   SCM fret = SCM_EOL;
107   SCM fret_label = SCM_EOL;
108   SCM fret_procedure = get_property ("tablatureFormat");
109   SCM staff_line_procedure = get_property ("tabStaffLineLayoutFunction");
110   SCM staff_position = SCM_EOL;
111   vsize fret_count = (vsize) scm_ilength (string_fret_finger);
112   bool length_changed = (note_events_.size () != fret_count);
113   vsize index;
114
115   if (!scm_is_null (string_fret_finger))
116     for (vsize i = 0; i < fret_count; i++)
117       {
118         note_entry = scm_list_ref (string_fret_finger, scm_from_int (i));
119         string_number = scm_car (note_entry);
120         if (scm_is_true (string_number))
121           {
122             fret = scm_cadr (note_entry);
123             fret_label = scm_call_3 (fret_procedure,
124                                      context ()->self_scm (),
125                                      string_number,
126                                      fret);
127             index = length_changed ? 0 : i;
128             Item *note = make_item ("TabNoteHead", note_events_[index]->self_scm ());
129             note->set_property ("text", fret_label);
130             staff_position = scm_call_2 (staff_line_procedure,
131                                          context ()->self_scm (),
132                                          string_number);
133             note->set_property ("staff-position", staff_position);
134           }
135       }
136 }
137
138 void
139 Tab_note_heads_engraver::stop_translation_timestep ()
140 {
141   note_events_.clear ();
142   tabstring_events_.clear ();
143   fingering_events_.clear ();
144 }
145
146 ADD_TRANSLATOR (Tab_note_heads_engraver,
147                 /* doc */
148                 "Generate one or more tablature note heads from event of type"
149                 " @code{NoteEvent}.",
150
151                 /* create */
152                 "TabNoteHead ",
153
154                 /* read */
155                 "defaultStrings "
156                 "fretLabels "
157                 "highStringOne "
158                 "middleCPosition "
159                 "minimumFret "
160                 "noteToFretFunction "
161                 "stringOneTopmost "
162                 "stringTunings "
163                 "tablatureFormat "
164                 "tabStaffLineLayoutFunction ",
165
166                 /* write */
167                 ""
168                );
169