]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-name.cc
release: 1.3.55
[lilypond.git] / lily / chord-name.cc
1 /*
2   chord-name.cc -- implement Chord_name
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "chord-name.hh"
10 #include "musical-request.hh"
11 #include "warn.hh"
12 #include "debug.hh"
13 #include "molecule.hh"
14 #include "paper-def.hh"
15 #include "lookup.hh"
16 #include "staff-symbol-referencer.hh"
17
18
19 /*
20   TODO: move text lookup out of Chord_name
21  */
22
23 /*
24   word is roman text or styled text:
25    "text"
26    ("style" . "text")
27  */
28
29 /*
30   UGH. remove Dictionary< > and use Scheme_hash_table
31  */
32 Molecule
33 Chord_name::ly_word2molecule (SCM word) const
34 {
35   /*
36     junkme.
37
38     Using the dict doesn't save code, since you have to compare
39     dict entries by hand later on anyway.
40     
41    */
42   Dictionary<SCM> option_dict;  
43   if (gh_pair_p (word))
44     {
45       SCM options = gh_cdr (word);
46       word = gh_car (word);
47       while (gh_pair_p (options))
48         {
49           SCM option = gh_car (options);
50           if (gh_pair_p (option))
51             {
52               SCM key = gh_car (option);
53               SCM val = gh_cdr (option);
54               String k;
55               if (gh_symbol_p (key))
56                 k = ly_symbol2string (key);
57               else if (gh_string_p (key))
58                 k = ly_scm2string (key);
59               else
60                 continue;
61               option_dict[k] = val;
62             }
63           options = gh_cdr (options);
64         }
65     }
66
67   /*
68     UGH. Should read from font metric structure.
69   */
70   Real ex = lookup_l ()->text ("", "x", paper_l ()).extent(Y_AXIS).length ();
71   if (gh_string_p (word))
72     {
73       String w = ly_scm2string (word);
74       Molecule mol;
75       Offset offset;
76
77       int size = 0;
78       if (option_dict.elem_b ("size"))
79         size = gh_scm2int (option_dict["size"]);
80
81       String style;
82       if (option_dict.elem_b ("style"))
83         style = ly_scm2string (option_dict["style"]);
84
85       if (option_dict.elem_b ("type")
86           && ly_scm2string (option_dict["type"]) == "super")
87         {
88           Real super_y = ex / 2;
89           //super_y += -acc.extent (Y_AXIS)[MIN];
90           offset = Offset (0, super_y);
91           if (!size)
92             size = -2;
93         }
94       if (option_dict.elem_b ("offset"))
95         {
96           // hmm
97           SCM s = option_dict["offset"];
98           if (gh_pair_p (s))
99             offset = Offset (gh_scm2double (gh_car (s)),
100                              gh_scm2double (gh_cdr (s))) * ex;
101         }
102       if (option_dict.elem_b ("font") 
103           && ly_scm2string (option_dict["font"]) == "feta")
104         mol = paper_l ()->lookup_l (size)->afm_find (w);
105       else
106         mol = paper_l ()->lookup_l (size)->text (style, w, paper_l ());
107
108       mol.translate (offset);
109       return mol;
110     }
111   return Molecule ();
112 }
113
114 /*
115   ;; text: list of word
116   ;; word: string + optional list of property
117   ;; property: align, kern, font (?), size
118  */
119 Molecule
120 Chord_name::ly_text2molecule (SCM text) const
121 {
122   Molecule mol;
123   if (gh_list_p (text))
124     {
125       while (gh_cdr (text) != SCM_EOL)
126         {
127           Molecule m = ly_word2molecule (gh_car (text));
128           if (!m.empty_b ())
129             mol.add_at_edge (X_AXIS, RIGHT, m, 0);
130           text = gh_cdr (text);
131         }
132       text = gh_car (text);
133     }  
134   Molecule m = ly_word2molecule (text);
135   if (!m.empty_b ())
136     mol.add_at_edge (X_AXIS, RIGHT, m, 0);
137   return mol;
138 }
139
140 Molecule 
141 Chord_name::do_brew_molecule () const
142 {
143   SCM style = get_elt_property ("style");
144   if (style == SCM_UNDEFINED)
145     style = ly_str02scm ("banter");
146
147   SCM inversion = get_elt_property ("inversion");
148   if (inversion == SCM_UNDEFINED)
149     inversion = SCM_BOOL_F;
150
151   SCM bass = get_elt_property ("bass");
152   if (bass == SCM_UNDEFINED)
153     bass = SCM_BOOL_F;
154
155   SCM pitches = get_elt_property ("pitches");
156
157   SCM text = scm_eval (gh_list (ly_symbol2scm ("chord::user-name"),
158                                 style,
159                                 ly_quote_scm (pitches),
160                                 ly_quote_scm (gh_cons (inversion, bass)),
161                                 SCM_UNDEFINED));
162
163   return ly_text2molecule (text);
164 }
165
166 Chord_name::Chord_name (SCM s)
167   : Item (s)
168 {
169 }