]> git.donarmstrong.com Git - lilypond.git/blob - lily/tab-note-heads-engraver.cc
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[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> notes_;
25   
26   Link_array<Item> dots_;
27   Link_array<Note_req> note_reqs_;
28   Link_array<String_number_req> tabstring_reqs_;
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) ;
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_reqs_.push (n);
51       return true;
52     }
53   else if (String_number_req * ts = dynamic_cast<String_number_req*> (m))
54     {
55       while(tabstring_reqs_.size () < note_reqs_.size ()-1)
56         tabstring_reqs_.push(0);
57       tabstring_reqs_.push(ts);
58       return true;
59     }
60   else if (dynamic_cast<Busy_playing_req*> (m))
61     {
62       return note_reqs_.size ();
63     }
64   
65   return false;
66 }
67
68
69 void
70 Tab_note_heads_engraver::process_music ()
71 {
72   for (int i=0; i < note_reqs_.size (); i++)
73     {
74       SCM stringTunings = get_property ("stringTunings");
75       int number_of_strings = ((int) gh_length(stringTunings));
76       bool high_string_one = to_boolean(get_property ("highStringOne"));
77
78       Item * note  = new Item (get_property ("TabNoteHead"));
79       
80       Music * req = note_reqs_[i];
81       
82       Music * tabstring_req = 0;
83       if(tabstring_reqs_.size()>i)
84         tabstring_req = tabstring_reqs_[i];
85       // printf("%d %d\n",tabstring_reqs_.size(),i);
86       // size_t lenp;
87       int tab_string;
88       bool string_found;
89       if (tabstring_req) {
90         //char* tab_string_as_string = gh_scm2newstr(tabstring_req->get_mus_property ("text"), &lenp);
91         //tab_string = atoi(tab_string_as_string);
92         tab_string = gh_scm2int(tabstring_req->get_mus_property ("string-number"));
93         string_found = true;
94       }
95       else {
96         tab_string = high_string_one ? 1 : number_of_strings;
97         string_found = false;
98       }
99       
100       Duration dur = *unsmob_duration (req->get_mus_property ("duration"));
101       
102       note->set_grob_property ("duration-log", gh_int2scm (dur.duration_log ()));
103
104       if (dur.dot_count ())
105         {
106           Item * d = new Item (get_property ("Dots"));
107           Rhythmic_head::set_dots (note, d);
108           
109           if (dur.dot_count ()
110               != gh_scm2int (d->get_grob_property ("dot-count")))
111             d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
112
113           d->set_parent (note, Y_AXIS);
114           announce_grob (d, SCM_EOL);
115           dots_.push (d);
116         }
117       
118       
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;
123
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)));
127         if(fret<min_fret)
128           tab_string += high_string_one ? 1 : -1;
129         else
130           string_found = true;
131       }
132
133       SCM text = gh_call3 (proc, gh_int2scm (tab_string), stringTunings, scm_pitch);
134
135       int pos = 2 * tab_string - number_of_strings - 1; // No tab-note between the string !!!
136       if(to_boolean(get_property("stringOneTopmost")))
137         pos = -pos;
138       
139       note->set_grob_property ("text", text);      
140       
141       note->set_grob_property ("staff-position", gh_int2scm (pos));
142       announce_grob (note, req->self_scm());
143       notes_.push (note);
144     }
145 }
146
147 void
148 Tab_note_heads_engraver::stop_translation_timestep ()
149 {
150   for (int i=0; i < notes_.size (); i++)
151     {
152       typeset_grob (notes_[i]);
153     }
154
155   notes_.clear ();
156   for (int i=0; i < dots_.size (); i++)
157     {
158       typeset_grob (dots_[i]);
159     }
160   dots_.clear ();
161   
162   note_reqs_.clear ();
163   
164   tabstring_reqs_.clear ();
165 }
166
167 void
168 Tab_note_heads_engraver::start_translation_timestep ()
169 {
170 }
171
172
173 ENTER_DESCRIPTION(Tab_note_heads_engraver,
174 /* descr */       "Generate one or more tablature noteheads from Music of type Note_req.",
175 /* creats*/       "TabNoteHead Dots",
176 /* acks  */       "",
177 /* reads */       "centralCPosition stringTunings minimumFret tablatureFormat highStringOne stringOneTopmost",
178 /* write */       "");
179