2 head-grav.cc -- part of GNU LilyPond
4 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "rhythmic-head.hh"
10 #include "paper-def.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<Music> note_events_;
28 Link_array<Music> tabstring_events_;
30 TRANSLATOR_DECLARATIONS(Tab_note_heads_engraver);
33 virtual bool try_music (Music *event) ;
34 virtual void process_music ();
36 virtual void stop_translation_timestep ();
40 Tab_note_heads_engraver::Tab_note_heads_engraver()
45 Tab_note_heads_engraver::try_music (Music *m)
47 if (m->is_mus_type ("note-event"))
49 note_events_.push (m);
52 else if (m->is_mus_type ("string-number-event"))
54 tabstring_events_.push (m);
57 else if (m->is_mus_type ("busy-playing-event"))
59 return note_events_.size ();
67 Tab_note_heads_engraver::process_music ()
70 for (int i=0; i < note_events_.size (); i++)
72 SCM stringTunings = get_property ("stringTunings");
73 int number_of_strings = ((int) gh_length(stringTunings));
74 bool high_string_one = to_boolean(get_property ("highStringOne"));
76 Item * note = new Item (get_property ("TabNoteHead"));
78 Music * event = note_events_[i];
81 Music * tabstring_event=0;
83 for (SCM s =event->get_mus_property ("articulations");
84 !tabstring_event && gh_pair_p (s); s = gh_cdr (s))
86 Music * art = unsmob_music (gh_car (s));
88 if (art->is_mus_type ("string-number-event"))
89 tabstring_event = art;
92 if (!tabstring_event && j < tabstring_events_.size ())
94 tabstring_event = tabstring_events_[j];
95 if (j +1 < tabstring_events_.size())
103 tab_string = gh_scm2int(tabstring_event->get_mus_property ("string-number"));
108 tab_string = high_string_one ? 1 : number_of_strings;
109 string_found = false;
112 Duration dur = *unsmob_duration (event->get_mus_property ("duration"));
113 note->set_grob_property ("duration-log",
114 gh_int2scm (dur.duration_log ()));
116 if (dur.dot_count ())
118 Item * d = new Item (get_property ("Dots"));
119 Rhythmic_head::set_dots (note, d);
122 != gh_scm2int (d->get_grob_property ("dot-count")))
123 d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
125 d->set_parent (note, Y_AXIS);
126 announce_grob (d, SCM_EOL);
131 SCM scm_pitch = event->get_mus_property ("pitch");
132 SCM proc = get_property ("tablatureFormat");
133 SCM min_fret_scm = get_property ("minimumFret");
134 int min_fret = gh_number_p(min_fret_scm) ? gh_scm2int(min_fret_scm) : 0;
138 int fret = unsmob_pitch(scm_pitch)->semitone_pitch()
139 - gh_scm2int(gh_list_ref(stringTunings,gh_int2scm(tab_string-1)));
141 tab_string += high_string_one ? 1 : -1;
146 SCM text = gh_call3 (proc, gh_int2scm (tab_string), stringTunings, scm_pitch);
148 int pos = 2 * tab_string - number_of_strings - 1; // No tab-note between the string !!!
149 if(to_boolean(get_property("stringOneTopmost")))
152 note->set_grob_property ("text", text);
154 note->set_grob_property ("staff-position", gh_int2scm (pos));
155 announce_grob (note, event->self_scm());
161 Tab_note_heads_engraver::stop_translation_timestep ()
163 for (int i=0; i < notes_.size (); i++)
165 typeset_grob (notes_[i]);
169 for (int i=0; i < dots_.size (); i++)
171 typeset_grob (dots_[i]);
175 note_events_.clear ();
176 tabstring_events_.clear ();
180 ENTER_DESCRIPTION(Tab_note_heads_engraver,
181 /* descr */ "Generate one or more tablature noteheads from Music of type NoteEvent.",
182 /* creats*/ "TabNoteHead Dots",
183 /* accepts */ "note-event string-number-event busy-playing-event",
185 /* reads */ "centralCPosition stringTunings minimumFret tablatureFormat highStringOne stringOneTopmost",