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 "molecule.hh"
11 #include "paper-def.hh"
13 #include "score-element.hh"
14 #include "paper-column.hh"
15 #include "line-of-score.hh"
16 #include "staff-symbol-referencer.hh"
19 TODO: move text lookup out of Chord_name
23 word is roman text or property-styled text:
25 ("text" . property-alist)
28 Chord_name::ly_word2molecule (Score_element * me, SCM word, Real* x)
32 SCM options_alist = SCM_EOL;
35 options_alist = gh_cdr (word);
39 if (gh_string_p (word))
42 UGH. Should read from font metric structure.
44 Real ex = me->lookup_l ()->text ("", "x",
45 me->paper_l ()).extent (Y_AXIS).length ();
46 Real em = me->lookup_l ()->text ("", "m",
47 me->paper_l ()).extent (X_AXIS).length ();
49 String w = ly_scm2string (word);
52 SCM s = scm_assoc (ly_symbol2scm ("style"), options_alist);
55 style = ly_scm2string (gh_cdr (s));
63 s = scm_assoc (ly_symbol2scm ("type"), options_alist);
64 if (s != SCM_BOOL_F && ly_scm2string (gh_cdr (s)) == "super")
66 Real super_y = ex / 2;
67 offset = Offset (0, super_y);
72 s = scm_assoc (ly_symbol2scm ("size"), options_alist);
75 size = gh_scm2int (gh_cdr (s));
78 s = scm_assoc (ly_symbol2scm ("offset"), options_alist);
84 offset = Offset (0, gh_scm2double (gh_cdr (o))) * ex;
85 *x = gh_scm2double (gh_car (o)) * em;
89 s = scm_assoc (ly_symbol2scm ("font"), options_alist);
90 if (s != SCM_BOOL_F && ly_scm2string (gh_cdr (s)) == "feta")
91 mol = me->paper_l ()->lookup_l (size)->afm_find (w);
93 mol = me->paper_l ()->lookup_l (size)->text (style, w, me->paper_l ());
95 mol.translate (offset);
102 ;; text: list of word
103 ;; word: string + optional list of property
104 ;; property: align, kern, font (?), size
107 Chord_name::ly_text2molecule (Score_element * me, SCM text)
110 if (gh_list_p (text))
112 while (gh_cdr (text) != SCM_EOL)
115 Molecule m = ly_word2molecule (me, gh_car (text), &x);
117 mol.add_at_edge (X_AXIS, RIGHT, m, x);
118 text = gh_cdr (text);
120 text = gh_car (text);
123 Molecule m = ly_word2molecule (me,text, &x);
125 mol.add_at_edge (X_AXIS, RIGHT, m, x);
129 MAKE_SCHEME_CALLBACK (Chord_name,after_line_breaking,1);
131 Chord_name::after_line_breaking (SCM smob)
133 Item* me = dynamic_cast<Item*> (unsmob_element (smob));
136 SCM s = me->get_elt_property ("begin-of-line-visible");
139 if (Paper_column::rank_i (me->column_l ()) -
141 hmm, what's my column number in this line?
142 why doesn't this work?
143 me->line_l ()->rank_i_ > 2)
145 me->line_l ()->spanned_rank_iv ()[LEFT] > 1)
148 return SCM_UNSPECIFIED;
151 MAKE_SCHEME_CALLBACK (Chord_name,brew_molecule,1);
153 Chord_name::brew_molecule (SCM smob)
155 Score_element *me = unsmob_element (smob);
156 SCM style = me->get_elt_property ("style");
158 if (!gh_string_p (style))
159 style = ly_str02scm ("banter");
161 SCM inversion = me-> get_elt_property ("inversion");
162 if (inversion == SCM_EOL)
163 inversion = SCM_BOOL_F;
165 SCM bass = me->get_elt_property ("bass");
169 SCM pitches = me->get_elt_property ("pitches");
170 SCM func = me->get_elt_property (ly_symbol2scm ("chord-name-function"));
171 SCM text = gh_call3 (func, style, pitches, gh_cons (inversion, bass));
173 Molecule mol = ly_text2molecule (me, text);
175 SCM space = me->get_elt_property ("word-space");
176 if (gh_number_p (space))
180 mol.add_at_edge (X_AXIS, RIGHT, m, gh_scm2double (space)*
181 Staff_symbol_referencer::staff_space (me));
184 return mol.create_scheme ();