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