]> git.donarmstrong.com Git - lilypond.git/blob - lily/tab-note-heads-engraver.cc
[lilypond-book] Fix indentation in LaTeX mode.
[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--2010 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
47 public:
48   TRANSLATOR_DECLARATIONS (Tab_note_heads_engraver);
49
50 protected:
51   DECLARE_TRANSLATOR_LISTENER (note);
52   DECLARE_TRANSLATOR_LISTENER (string_number);
53   void process_music ();
54
55   void stop_translation_timestep ();
56 };
57
58 Tab_note_heads_engraver::Tab_note_heads_engraver ()
59 {
60 }
61
62 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, note);
63 void
64 Tab_note_heads_engraver::listen_note (Stream_event *ev)
65 {
66   note_events_.push_back (ev);
67 }
68
69 IMPLEMENT_TRANSLATOR_LISTENER (Tab_note_heads_engraver, string_number);
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::process_music ()
78 {
79   SCM tab_strings = articulation_list (note_events_,
80                                        tabstring_events_,
81                                        "string-number-event");
82   SCM tab_notes = ly_cxx_vector_to_list (note_events_);
83   SCM proc = get_property ("noteToFretFunction");
84   SCM string_fret_finger = SCM_EOL;
85   if (ly_is_procedure (proc))
86     string_fret_finger = scm_call_3 (proc,
87                                      context ()->self_scm (),
88                                      tab_notes,
89                                      tab_strings);
90   SCM note_entry = SCM_EOL;
91   SCM string_number = SCM_EOL;
92   SCM fret = SCM_EOL;
93   SCM fret_label = SCM_EOL;
94   SCM fret_procedure = get_property ("tablatureFormat");
95   SCM staff_line_procedure = get_property ("tabStaffLineLayoutFunction");
96   SCM staff_position = SCM_EOL;
97   vsize fret_count = (vsize) scm_ilength (string_fret_finger);
98   bool length_changed = (note_events_.size () != fret_count);
99   vsize index;
100
101   if (string_fret_finger != SCM_EOL)
102     for (vsize i = 0; i < fret_count; i++)
103       {
104         note_entry = scm_list_ref (string_fret_finger, scm_from_int (i));
105         string_number = scm_car (note_entry);
106         fret = scm_cadr (note_entry);
107         fret_label = scm_call_3 (fret_procedure,
108                                  context ()->self_scm (),
109                                  string_number,
110                                  fret);
111         index = length_changed ? 0 : i;
112         Item *note = make_item ("TabNoteHead", note_events_[index]->self_scm ());
113         note->set_property ("text", fret_label);
114         staff_position = scm_call_2 (staff_line_procedure,
115                                      context ()->self_scm (),
116                                      string_number);
117         note->set_property ("staff-position", staff_position);
118       }
119 }
120
121 void
122 Tab_note_heads_engraver::stop_translation_timestep ()
123 {
124   note_events_.clear ();
125   tabstring_events_.clear ();
126 }
127
128 ADD_TRANSLATOR (Tab_note_heads_engraver,
129                 /* doc */
130                 "Generate one or more tablature note heads from event of type"
131                 " @code{NoteEvent}.",
132
133                 /* create */
134                 "TabNoteHead ",
135
136                 /* read */
137                 "fretLabels "
138                 "highStringOne "
139                 "middleCPosition "
140                 "minimumFret "
141                 "noteToFretFunction "
142                 "stringOneTopmost "
143                 "stringTunings "
144                 "tablatureFormat "
145                 "tabStaffLineLayoutFunction ",
146
147                 /* write */ ""
148                 );
149