lilypond-1.3.65
[lilypond.git] / lily / chord-name.cc
blob0d4ff138499a7b2fe91603e5b84df0bfaa033951
1 /*
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>
7 */
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"
20 TODO: move text lookup out of Chord_name
24 word is roman text or property-styled text:
25 "text"
26 ("text" . property-alist)
29 Molecule
30 Chord_name::ly_word2molecule (SCM word, Real* x) const
32 *x = 0;
34 SCM options_alist = SCM_EOL;
35 if (gh_pair_p (word))
37 options_alist = gh_cdr (word);
38 word = gh_car (word);
41 if (gh_string_p (word))
44 UGH. Should read from font metric structure.
46 Real ex = lookup_l ()->text ("", "x",
47 paper_l ()).extent (Y_AXIS).length ();
48 Real em = lookup_l ()->text ("", "m",
49 paper_l ()).extent (X_AXIS).length ();
51 String w = ly_scm2string (word);
53 String style;
54 SCM s = scm_assoc (ly_symbol2scm ("style"), options_alist);
55 if (s != SCM_BOOL_F)
57 style = ly_scm2string (gh_cdr (s));
60 Offset offset;
61 int size = 0;
63 urg, `type'
65 s = scm_assoc (ly_symbol2scm ("type"), options_alist);
66 if (s != SCM_BOOL_F && ly_scm2string (gh_cdr (s)) == "super")
68 Real super_y = ex / 2;
69 offset = Offset (0, super_y);
70 if (!size)
71 size = -2;
74 s = scm_assoc (ly_symbol2scm ("size"), options_alist);
75 if (s != SCM_BOOL_F)
77 size = gh_scm2int (gh_cdr (s));
80 s = scm_assoc (ly_symbol2scm ("offset"), options_alist);
81 if (s != SCM_BOOL_F)
83 // hmm
84 SCM o = gh_cdr (s);
85 if (gh_pair_p (o))
86 offset = Offset (0, gh_scm2double (gh_cdr (o))) * ex;
87 *x = gh_scm2double (gh_car (o)) * em;
90 Molecule mol;
91 s = scm_assoc (ly_symbol2scm ("font"), options_alist);
92 if (s != SCM_BOOL_F && ly_scm2string (gh_cdr (s)) == "feta")
93 mol = paper_l ()->lookup_l (size)->afm_find (w);
94 else
95 mol = paper_l ()->lookup_l (size)->text (style, w, paper_l ());
97 mol.translate (offset);
98 return mol;
100 return Molecule ();
104 ;; text: list of word
105 ;; word: string + optional list of property
106 ;; property: align, kern, font (?), size
108 Molecule
109 Chord_name::ly_text2molecule (SCM text) const
111 Molecule mol;
112 if (gh_list_p (text))
114 while (gh_cdr (text) != SCM_EOL)
116 Real x;
117 Molecule m = ly_word2molecule (gh_car (text), &x);
118 if (!m.empty_b ())
119 mol.add_at_edge (X_AXIS, RIGHT, m, x);
120 text = gh_cdr (text);
122 text = gh_car (text);
124 Real x;
125 Molecule m = ly_word2molecule (text, &x);
126 if (!m.empty_b ())
127 mol.add_at_edge (X_AXIS, RIGHT, m, x);
128 return mol;
131 MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Chord_name,brew_molecule);
134 Chord_name::brew_molecule (SCM smob)
136 Score_element *sc = unsmob_element (smob);
137 SCM style = sc->get_elt_property ("style");
138 if (style == SCM_UNDEFINED)
139 style = ly_str02scm ("banter");
141 SCM inversion = sc-> get_elt_property ("inversion");
142 if (inversion == SCM_UNDEFINED)
143 inversion = SCM_BOOL_F;
145 SCM bass = sc->get_elt_property ("bass");
146 if (bass == SCM_UNDEFINED)
147 bass = SCM_BOOL_F;
149 SCM pitches = sc->get_elt_property ("pitches");
151 SCM text = scm_eval (gh_list (ly_symbol2scm ("chord::user-name"),
152 style,
153 ly_quote_scm (pitches),
154 ly_quote_scm (gh_cons (inversion, bass)),
155 SCM_UNDEFINED));
157 return dynamic_cast<Chord_name*> (sc)->
158 ly_text2molecule (text).create_scheme ();
161 Chord_name::Chord_name (SCM s)
162 : Item (s)