2 chord-name.cc -- implement Chord_name
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "chord-name.hh"
10 #include "musical-request.hh"
13 #include "molecule.hh"
14 #include "paper-def.hh"
16 #include "staff-symbol-referencer.hh"
20 TODO: move text lookup out of Chord_name
24 word is roman text or styled text:
30 UGH. remove Dictionary< > and use Scheme_hash_table
33 Chord_name::ly_word2molecule (SCM word) const
38 Using the dict doesn't save code, since you have to compare
39 dict entries by hand later on anyway.
42 Dictionary<SCM> option_dict;
45 SCM options = gh_cdr (word);
47 while (gh_pair_p (options))
49 SCM option = gh_car (options);
50 if (gh_pair_p (option))
52 SCM key = gh_car (option);
53 SCM val = gh_cdr (option);
55 if (gh_symbol_p (key))
56 k = ly_symbol2string (key);
57 else if (gh_string_p (key))
58 k = ly_scm2string (key);
63 options = gh_cdr (options);
68 UGH. Should read from font metric structure.
70 Real ex = lookup_l ()->text ("", "x", paper_l ()).extent(Y_AXIS).length ();
71 if (gh_string_p (word))
73 String w = ly_scm2string (word);
78 if (option_dict.elem_b ("size"))
79 size = gh_scm2int (option_dict["size"]);
82 if (option_dict.elem_b ("style"))
83 style = ly_scm2string (option_dict["style"]);
85 if (option_dict.elem_b ("type")
86 && ly_scm2string (option_dict["type"]) == "super")
88 Real super_y = ex / 2;
89 //super_y += -acc.extent (Y_AXIS)[MIN];
90 offset = Offset (0, super_y);
94 if (option_dict.elem_b ("offset"))
97 SCM s = option_dict["offset"];
99 offset = Offset (gh_scm2double (gh_car (s)),
100 gh_scm2double (gh_cdr (s))) * ex;
102 if (option_dict.elem_b ("font")
103 && ly_scm2string (option_dict["font"]) == "feta")
104 mol = paper_l ()->lookup_l (size)->afm_find (w);
106 mol = paper_l ()->lookup_l (size)->text (style, w, paper_l ());
108 mol.translate (offset);
115 ;; text: list of word
116 ;; word: string + optional list of property
117 ;; property: align, kern, font (?), size
120 Chord_name::ly_text2molecule (SCM text) const
123 if (gh_list_p (text))
125 while (gh_cdr (text) != SCM_EOL)
127 Molecule m = ly_word2molecule (gh_car (text));
129 mol.add_at_edge (X_AXIS, RIGHT, m, 0);
130 text = gh_cdr (text);
132 text = gh_car (text);
134 Molecule m = ly_word2molecule (text);
136 mol.add_at_edge (X_AXIS, RIGHT, m, 0);
140 MAKE_SCHEME_SCORE_ELEMENT_CALLBACKS(Chord_name);
143 Chord_name::do_brew_molecule () const
145 SCM style = get_elt_property ("style");
146 if (style == SCM_UNDEFINED)
147 style = ly_str02scm ("banter");
149 SCM inversion = get_elt_property ("inversion");
150 if (inversion == SCM_UNDEFINED)
151 inversion = SCM_BOOL_F;
153 SCM bass = get_elt_property ("bass");
154 if (bass == SCM_UNDEFINED)
157 SCM pitches = get_elt_property ("pitches");
159 SCM text = scm_eval (gh_list (ly_symbol2scm ("chord::user-name"),
161 ly_quote_scm (pitches),
162 ly_quote_scm (gh_cons (inversion, bass)),
165 return ly_text2molecule (text);
168 Chord_name::Chord_name (SCM s)