lilypond-1.3.69
[lilypond.git] / lily / chord-name.cc
blob4becdee60fa1a5c1e30134629531a0cdc2b95bf2
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 "molecule.hh"
11 #include "paper-def.hh"
12 #include "lookup.hh"
13 #include "score-element.hh"
16 TODO: move text lookup out of Chord_name
20 word is roman text or property-styled text:
21 "text"
22 ("text" . property-alist)
25 Molecule
26 Chord_name::ly_word2molecule (Score_element * me, SCM word, Real* x)
28 *x = 0;
30 SCM options_alist = SCM_EOL;
31 if (gh_pair_p (word))
33 options_alist = gh_cdr (word);
34 word = gh_car (word);
37 if (gh_string_p (word))
40 UGH. Should read from font metric structure.
42 Real ex = me->lookup_l ()->text ("", "x",
43 me->paper_l ()).extent (Y_AXIS).length ();
44 Real em = me->lookup_l ()->text ("", "m",
45 me->paper_l ()).extent (X_AXIS).length ();
47 String w = ly_scm2string (word);
49 String style;
50 SCM s = scm_assoc (ly_symbol2scm ("style"), options_alist);
51 if (s != SCM_BOOL_F)
53 style = ly_scm2string (gh_cdr (s));
56 Offset offset;
57 int size = 0;
59 urg, `type'
61 s = scm_assoc (ly_symbol2scm ("type"), options_alist);
62 if (s != SCM_BOOL_F && ly_scm2string (gh_cdr (s)) == "super")
64 Real super_y = ex / 2;
65 offset = Offset (0, super_y);
66 if (!size)
67 size = -2;
70 s = scm_assoc (ly_symbol2scm ("size"), options_alist);
71 if (s != SCM_BOOL_F)
73 size = gh_scm2int (gh_cdr (s));
76 s = scm_assoc (ly_symbol2scm ("offset"), options_alist);
77 if (s != SCM_BOOL_F)
79 // hmm
80 SCM o = gh_cdr (s);
81 if (gh_pair_p (o))
82 offset = Offset (0, gh_scm2double (gh_cdr (o))) * ex;
83 *x = gh_scm2double (gh_car (o)) * em;
86 Molecule mol;
87 s = scm_assoc (ly_symbol2scm ("font"), options_alist);
88 if (s != SCM_BOOL_F && ly_scm2string (gh_cdr (s)) == "feta")
89 mol = me->paper_l ()->lookup_l (size)->afm_find (w);
90 else
91 mol = me->paper_l ()->lookup_l (size)->text (style, w, me->paper_l ());
93 mol.translate (offset);
94 return mol;
96 return Molecule ();
100 ;; text: list of word
101 ;; word: string + optional list of property
102 ;; property: align, kern, font (?), size
104 Molecule
105 Chord_name::ly_text2molecule (Score_element * me, SCM text)
107 Molecule mol;
108 if (gh_list_p (text))
110 while (gh_cdr (text) != SCM_EOL)
112 Real x;
113 Molecule m = ly_word2molecule (me, gh_car (text), &x);
114 if (!m.empty_b ())
115 mol.add_at_edge (X_AXIS, RIGHT, m, x);
116 text = gh_cdr (text);
118 text = gh_car (text);
120 Real x;
121 Molecule m = ly_word2molecule (me,text, &x);
122 if (!m.empty_b ())
123 mol.add_at_edge (X_AXIS, RIGHT, m, x);
124 return mol;
127 MAKE_SCHEME_CALLBACK(Chord_name,brew_molecule);
130 Chord_name::brew_molecule (SCM smob)
132 Score_element *sc = unsmob_element (smob);
133 SCM style = sc->get_elt_property ("style");
134 if (style == SCM_UNDEFINED)
135 style = ly_str02scm ("banter");
137 SCM inversion = sc-> get_elt_property ("inversion");
138 if (inversion == SCM_UNDEFINED)
139 inversion = SCM_BOOL_F;
141 SCM bass = sc->get_elt_property ("bass");
142 if (bass == SCM_UNDEFINED)
143 bass = SCM_BOOL_F;
145 SCM pitches = sc->get_elt_property ("pitches");
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));
153 return ly_text2molecule (sc, text).create_scheme ();