]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-name.cc
patch::: 1.3.49.hwn1: deze dus
[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   UGH. remove Dictionary< >
30  */
31 Molecule
32 Chord_name::ly_word2molecule (SCM word) const
33 {
34   Dictionary<SCM> option_dict;  // junkme
35   if (gh_pair_p (word))
36     {
37       SCM options = gh_cdr (word);
38       word = gh_car (word);
39       while (gh_pair_p (options))
40         {
41           SCM option = gh_car (options);
42           if (option != SCM_UNDEFINED && option != SCM_BOOL_F
43               && gh_pair_p (option))
44             {
45               SCM key = gh_car (option);
46               SCM val = gh_cdr (option);
47               String k;
48               if (gh_symbol_p (key))
49                 k = ly_symbol2string (key);
50               else if (gh_string_p (key))
51                 k = ly_scm2string (key);
52               else
53                 continue;
54               option_dict[k] = val;
55             }
56           options = gh_cdr (options);
57         }
58     }
59   Real ex = lookup_l ()->text ("", "x", paper_l ()).extent
60             ()[Y_AXIS].length ();
61   if (gh_string_p (word))
62     {
63       String w = ly_scm2string (word);
64       Molecule mol;
65       Offset offset;
66
67       int size = 0;
68       if (option_dict.elem_b ("size"))
69         size = gh_scm2int (option_dict["size"]);
70
71       String style;
72       if (option_dict.elem_b ("style"))
73         style = ly_scm2string (option_dict["style"]);
74
75       if (option_dict.elem_b ("type")
76           && ly_scm2string (option_dict["type"]) == "super")
77         {
78           Real super_y = ex / 2;
79           //super_y += -acc.extent ()[Y_AXIS][MIN];
80           offset = Offset (0, super_y);
81           if (!size)
82             size = -2;
83         }
84       if (option_dict.elem_b ("offset"))
85         {
86           // hmm
87           SCM s = option_dict["offset"];
88           if (gh_pair_p (s))
89             offset = Offset (gh_scm2double (gh_car (s)),
90                              gh_scm2double (gh_cdr (s))) * ex;
91         }
92       if (option_dict.elem_b ("font") 
93           && ly_scm2string (option_dict["font"]) == "feta")
94         mol = paper_l ()->lookup_l (size)->afm_find (w);
95       else
96         mol = paper_l ()->lookup_l (size)->text (style, w, paper_l ());
97
98       mol.translate (offset);
99       return mol;
100     }
101   return Molecule ();
102 }
103
104 /*
105   ;; text: list of word
106   ;; word: string + optional list of property
107   ;; property: align, kern, font (?), size
108  */
109 Molecule
110 Chord_name::ly_text2molecule (SCM text) const
111 {
112   Molecule mol;
113   if (gh_list_p (text))
114     {
115       while (gh_cdr (text) != SCM_EOL)
116         {
117           Molecule m = ly_word2molecule (gh_car (text));
118           if (!m.empty_b ())
119             mol.add_at_edge (X_AXIS, RIGHT, m, 0);
120           text = gh_cdr (text);
121         }
122       text = gh_car (text);
123     }  
124   Molecule m = ly_word2molecule (text);
125   if (!m.empty_b ())
126     mol.add_at_edge (X_AXIS, RIGHT, m, 0);
127   return mol;
128 }
129
130 Molecule 
131 Chord_name::do_brew_molecule () const
132 {
133   SCM style = get_elt_property ("style");
134   if (style == SCM_UNDEFINED)
135     style = ly_str02scm ("banter");
136
137   SCM inversion = get_elt_property ("inversion");
138   if (inversion == SCM_UNDEFINED)
139     inversion = SCM_BOOL_F;
140
141   SCM bass = get_elt_property ("bass");
142   if (bass == SCM_UNDEFINED)
143     bass = SCM_BOOL_F;
144
145   SCM pitches = get_elt_property ("pitches");
146
147   SCM text = scm_eval (gh_list (ly_symbol2scm ("chord::user-name"),
148                                 style,
149                                 ly_quote_scm (pitches),
150                                 ly_quote_scm (gh_cons (inversion, bass)),
151                                 SCM_UNDEFINED));
152
153   return ly_text2molecule (text);
154 }