]> git.donarmstrong.com Git - lilypond.git/blob - lily/tab-note-heads-engraver.cc
po-replace
[lilypond.git] / lily / tab-note-heads-engraver.cc
1 /*
2   head-grav.cc -- part of GNU LilyPond
3
4   (c)  1997--2002 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 "musical-request.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> note_p_arr_;
25   
26   Link_array<Item> dot_p_arr_;
27   Link_array<Note_req> note_req_l_arr_;
28   Link_array<Text_script_req> tabstring_req_arr_;
29 public:
30   TRANSLATOR_DECLARATIONS(Tab_note_heads_engraver);
31
32 protected:
33   virtual void start_translation_timestep ();
34   virtual bool try_music (Music *req_l) ;
35   virtual void process_music ();
36
37   virtual void stop_translation_timestep ();
38 };
39
40
41 Tab_note_heads_engraver::Tab_note_heads_engraver()
42 {
43 }
44
45 bool
46 Tab_note_heads_engraver::try_music (Music *m) 
47 {
48   if (Note_req * n =dynamic_cast <Note_req *> (m))
49     {
50       note_req_l_arr_.push (n);
51       return true;
52     }
53   else if (Text_script_req * ts = dynamic_cast<Text_script_req*> (m))
54     {
55       if (m->get_mus_property ("text-type") != ly_symbol2scm ("finger")) return false;
56       
57       //if (tabstring_req_arr_.size () < note_req_l_arr_.size ()) {
58         tabstring_req_arr_.push (ts);
59       //}
60       return true;
61     }
62   else if (dynamic_cast<Busy_playing_req*> (m))
63     {
64       return note_req_l_arr_.size ();
65     }
66   
67   return false;
68 }
69
70
71 void
72 Tab_note_heads_engraver::process_music ()
73 {
74   /*
75   for (int i=0; i < tabstring_req_arr_.size (); i++) {
76       Music * tabstring_req = tabstring_req_arr_[i];
77       
78       size_t lenp;
79       char* tab_string_as_str = gh_scm2newstr(tabstring_req->get_mus_property ("text"), &lenp);
80   }
81   */
82   
83   for (int i=0; i < note_req_l_arr_.size (); i++)
84     {
85       Item * note_p  = new Item (get_property ("TabNoteHead"));
86       
87       Music * req = note_req_l_arr_[i];
88       
89       Music * tabstring_req = tabstring_req_arr_[i];
90       
91       size_t lenp;
92       char* tab_string_as_str = gh_scm2newstr(tabstring_req->get_mus_property ("text"), &lenp);
93       int tab_string = atoi(tab_string_as_str);
94       
95       Duration dur = *unsmob_duration (req->get_mus_property ("duration"));
96       
97       note_p->set_grob_property ("duration-log", gh_int2scm (dur.duration_log ()));
98
99       if (dur.dot_count ())
100         {
101           Item * d = new Item (get_property ("Dots"));
102           Rhythmic_head::set_dots (note_p, d);
103           
104           if (dur.dot_count ()
105               != gh_scm2int (d->get_grob_property ("dot-count")))
106             d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
107
108           d->set_parent (note_p, Y_AXIS);
109           announce_grob (d, SCM_EOL);
110           dot_p_arr_.push (d);
111         }
112       
113       SCM stringTunings = get_property ("stringTunings");
114       int number_of_strings = ((int) gh_length(stringTunings));
115       
116       int pos = 2 * tab_string - 2; // No tab-note between the string !!!
117       
118       if (((float) (number_of_strings / 2)) != (((float) number_of_strings) / 2.0)) { // even number of string
119         pos = pos + 1;
120       }
121       
122       SCM c0 = get_property ("centralCPosition");
123       if (gh_number_p (c0)) pos += gh_scm2int (c0);
124       
125       SCM scm_pitch = req->get_mus_property ("pitch");
126       SCM proc      = get_property ("tablatureFormat");
127       SCM text      = gh_call3 (proc, gh_int2scm (tab_string), stringTunings, scm_pitch);
128       note_p->set_grob_property ("text", text);
129       
130       note_p->set_grob_property ("staff-position", gh_int2scm (pos));
131       announce_grob (note_p, req->self_scm());
132       note_p_arr_.push (note_p);
133     }
134 }
135
136 void
137 Tab_note_heads_engraver::stop_translation_timestep ()
138 {
139   for (int i=0; i < note_p_arr_.size (); i++)
140     {
141       typeset_grob (note_p_arr_[i]);
142     }
143
144   note_p_arr_.clear ();
145   for (int i=0; i < dot_p_arr_.size (); i++)
146     {
147       typeset_grob (dot_p_arr_[i]);
148     }
149   dot_p_arr_.clear ();
150   
151   note_req_l_arr_.clear ();
152   
153   tabstring_req_arr_.clear ();
154 }
155
156 void
157 Tab_note_heads_engraver::start_translation_timestep ()
158 {
159 }
160
161
162 ENTER_DESCRIPTION(Tab_note_heads_engraver,
163 /* descr */       "Generate one or more tablature noteheads from Music of type Note_req.",
164 /* creats*/       "TabNoteHead Dots",
165 /* acks  */       "",
166 /* reads */       "centralCPosition stringTunings",
167 /* write */       "");
168