]> git.donarmstrong.com Git - lilypond.git/blob - lily/tab-note-heads-engraver.cc
*** empty log message ***
[lilypond.git] / lily / tab-note-heads-engraver.cc
1 /*
2   head-grav.cc -- part of GNU LilyPond
3
4   (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
5 */
6 #include <ctype.h>
7 #include <stdio.h>
8
9 #include "rhythmic-head.hh"
10 #include "paper-def.hh"
11 #include "event.hh"
12 #include "dots.hh"
13 #include "dot-column.hh"
14 #include "staff-symbol-referencer.hh"
15 #include "item.hh"
16 #include "score-engraver.hh"
17 #include "warn.hh"
18
19 /**
20    make (guitar-like) tablature note
21 */
22 class Tab_note_heads_engraver : public Engraver
23 {
24   Link_array<Item> notes_;
25   
26   Link_array<Item> dots_;
27   Link_array<Music> note_events_;
28   Link_array<Music> tabstring_events_;
29 public:
30   TRANSLATOR_DECLARATIONS(Tab_note_heads_engraver);
31
32 protected:
33   virtual bool try_music (Music *event) ;
34   virtual void process_music ();
35
36   virtual void stop_translation_timestep ();
37 };
38
39
40 Tab_note_heads_engraver::Tab_note_heads_engraver()
41 {
42 }
43
44 bool
45 Tab_note_heads_engraver::try_music (Music *m) 
46 {
47   if (m->is_mus_type ("note-event"))
48     {
49       note_events_.push (m);
50       return true;
51     }
52   else if (m->is_mus_type ("string-number-event"))
53     {
54       tabstring_events_.push (m);
55       return true;
56     }
57   else if (m->is_mus_type ("busy-playing-event"))
58     {
59       return note_events_.size ();
60     }
61   
62   return false;
63 }
64
65
66 void
67 Tab_note_heads_engraver::process_music ()
68 {
69   int j = 0; 
70   for (int i=0; i < note_events_.size (); i++)
71     {
72
73
74       
75       SCM stringTunings = get_property ("stringTunings");
76       int number_of_strings = ((int) gh_length(stringTunings));
77       bool high_string_one = to_boolean(get_property ("highStringOne"));
78
79       Item * note  = new Item (get_property ("TabNoteHead"));
80       
81       Music * event = note_events_[i];
82
83       
84       Music * tabstring_event=0;
85
86       for (SCM s =event->get_mus_property ("articulations");
87            !tabstring_event && gh_pair_p (s); s = gh_cdr (s))
88         {
89           Music * art = unsmob_music (gh_car (s));
90
91           if (art->is_mus_type ("string-number-event"))
92             tabstring_event = art;
93         }
94
95       if (!tabstring_event  && j < tabstring_events_.size ())
96         {
97           tabstring_event = tabstring_events_[j];
98           if (j +1 <  tabstring_events_.size())
99             j++;
100         }
101
102       int tab_string;
103       bool string_found;
104       if (tabstring_event)
105         {
106           tab_string = gh_scm2int(tabstring_event->get_mus_property ("string-number"));
107           string_found = true;
108         }
109       else
110         {
111           tab_string = high_string_one ? 1 : number_of_strings;
112           string_found = false;
113         }
114       
115       Duration dur = *unsmob_duration (event->get_mus_property ("duration"));
116       note->set_grob_property ("duration-log",
117                                gh_int2scm (dur.duration_log ()));
118
119       if (dur.dot_count ())
120         {
121           Item * d = new Item (get_property ("Dots"));
122           Rhythmic_head::set_dots (note, d);
123           
124           if (dur.dot_count ()
125               != gh_scm2int (d->get_grob_property ("dot-count")))
126             d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
127
128           d->set_parent (note, Y_AXIS);
129           announce_grob (d, SCM_EOL);
130           dots_.push (d);
131         }
132       
133       
134       SCM scm_pitch = event->get_mus_property ("pitch");
135       SCM proc      = get_property ("tablatureFormat");
136       SCM min_fret_scm = get_property ("minimumFret");
137       int min_fret = gh_number_p(min_fret_scm) ? gh_scm2int(min_fret_scm) : 0;
138
139       while(!string_found)
140         {
141           int fret = unsmob_pitch(scm_pitch)->semitone_pitch()
142             - gh_scm2int(gh_list_ref(stringTunings,gh_int2scm(tab_string-1)));
143           if(fret<min_fret)
144             tab_string += high_string_one ? 1 : -1;
145           else
146             string_found = true;
147         }
148
149       SCM text = gh_call3 (proc, gh_int2scm (tab_string), stringTunings, scm_pitch);
150
151       int pos = 2 * tab_string - number_of_strings - 1; // No tab-note between the string !!!
152       if(to_boolean(get_property("stringOneTopmost")))
153         pos = -pos;
154       
155       note->set_grob_property ("text", text);      
156       
157       note->set_grob_property ("staff-position", gh_int2scm (pos));
158       announce_grob (note, event->self_scm());
159       notes_.push (note);
160     }
161 }
162
163 void
164 Tab_note_heads_engraver::stop_translation_timestep ()
165 {
166   for (int i=0; i < notes_.size (); i++)
167     {
168       typeset_grob (notes_[i]);
169     }
170
171   notes_.clear ();
172   for (int i=0; i < dots_.size (); i++)
173     {
174       typeset_grob (dots_[i]);
175     }
176   
177   dots_.clear ();
178   note_events_.clear ();
179   tabstring_events_.clear ();
180 }
181
182
183 ENTER_DESCRIPTION(Tab_note_heads_engraver,
184 /* descr */       "Generate one or more tablature noteheads from Music of type NoteEvent.",
185 /* creats*/       "TabNoteHead Dots",
186 /* accepts */     "note-event string-number-event busy-playing-event",
187 /* acks  */      "",
188 /* reads */       "centralCPosition stringTunings minimumFret tablatureFormat highStringOne stringOneTopmost",
189 /* write */       "");
190