2 head-grav.cc -- part of GNU LilyPond
4 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "rhythmic-head.hh"
10 #include "paper-def.hh"
11 #include "musical-request.hh"
13 #include "dot-column.hh"
14 #include "staff-symbol-referencer.hh"
16 #include "score-engraver.hh"
20 make (guitar-like) tablature note
22 class Tab_note_heads_engraver : public Engraver
24 Link_array<Item> notes_;
26 Link_array<Item> dots_;
27 Link_array<Note_req> note_reqs_;
28 Link_array<Text_script_req> tabstring_reqs_;
30 TRANSLATOR_DECLARATIONS(Tab_note_heads_engraver);
33 virtual void start_translation_timestep ();
34 virtual bool try_music (Music *req) ;
35 virtual void process_music ();
37 virtual void stop_translation_timestep ();
41 Tab_note_heads_engraver::Tab_note_heads_engraver()
46 Tab_note_heads_engraver::try_music (Music *m)
48 if (Note_req * n =dynamic_cast <Note_req *> (m))
53 else if (Text_script_req * ts = dynamic_cast<Text_script_req*> (m))
55 if (m->get_mus_property ("text-type") != ly_symbol2scm ("finger")) return false;
57 while(tabstring_reqs_.size () < note_reqs_.size ()-1)
58 tabstring_reqs_.push(0);
59 tabstring_reqs_.push(ts);
62 else if (dynamic_cast<Busy_playing_req*> (m))
64 return note_reqs_.size ();
72 Tab_note_heads_engraver::process_music ()
74 for (int i=0; i < note_reqs_.size (); i++)
76 SCM stringTunings = get_property ("stringTunings");
77 int number_of_strings = ((int) gh_length(stringTunings));
79 Item * note = new Item (get_property ("TabNoteHead"));
81 Music * req = note_reqs_[i];
83 Music * tabstring_req = 0;
84 if(tabstring_reqs_.size()>i)
85 tabstring_req = tabstring_reqs_[i];
86 // printf("%d %d\n",tabstring_reqs_.size(),i);
91 char* tab_string_as_string = gh_scm2newstr(tabstring_req->get_mus_property ("text"), &lenp);
92 tab_string = atoi(tab_string_as_string);
96 tab_string = number_of_strings;
100 Duration dur = *unsmob_duration (req->get_mus_property ("duration"));
102 note->set_grob_property ("duration-log", gh_int2scm (dur.duration_log ()));
104 if (dur.dot_count ())
106 Item * d = new Item (get_property ("Dots"));
107 Rhythmic_head::set_dots (note, d);
110 != gh_scm2int (d->get_grob_property ("dot-count")))
111 d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
113 d->set_parent (note, Y_AXIS);
114 announce_grob (d, SCM_EOL);
119 SCM scm_pitch = req->get_mus_property ("pitch");
120 SCM proc = get_property ("tablatureFormat");
121 SCM min_fret_scm = get_property ("minimumFret");
122 int min_fret = gh_number_p(min_fret_scm) ? gh_scm2int(min_fret_scm) : 0;
124 while(!string_found) {
125 int fret = unsmob_pitch(scm_pitch)->semitone_pitch()
126 - gh_scm2int(gh_list_ref(stringTunings,gh_int2scm(tab_string-1)));
133 SCM text = gh_call3 (proc, gh_int2scm (tab_string), stringTunings, scm_pitch);
135 int pos = 2 * tab_string - 2; // No tab-note between the string !!!
137 if (number_of_strings % 2) { // odd number of string
142 note->set_grob_property ("text", text);
143 SCM c0 = get_property ("centralCPosition");
144 if (gh_number_p (c0)) pos += gh_scm2int (c0);
147 note->set_grob_property ("staff-position", gh_int2scm (pos));
148 announce_grob (note, req->self_scm());
154 Tab_note_heads_engraver::stop_translation_timestep ()
156 for (int i=0; i < notes_.size (); i++)
158 typeset_grob (notes_[i]);
162 for (int i=0; i < dots_.size (); i++)
164 typeset_grob (dots_[i]);
170 tabstring_reqs_.clear ();
174 Tab_note_heads_engraver::start_translation_timestep ()
179 ENTER_DESCRIPTION(Tab_note_heads_engraver,
180 /* descr */ "Generate one or more tablature noteheads from Music of type Note_req.",
181 /* creats*/ "TabNoteHead Dots",
183 /* reads */ "centralCPosition stringTunings minimumFret",