]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-name.cc
release: 1.3.72
[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 "molecule.hh"
11 #include "paper-def.hh"
12 #include "lookup.hh"
13 #include "score-element.hh"
14
15 /*
16   TODO: move text lookup out of Chord_name
17  */
18
19 /*
20   word is roman text or property-styled text:
21    "text"
22    ("text" . property-alist)
23  */
24
25 Molecule
26 Chord_name::ly_word2molecule (Score_element * me, SCM word, Real* x) 
27 {
28   *x = 0;
29
30   SCM options_alist = SCM_EOL;
31   if (gh_pair_p (word))
32     {
33       options_alist = gh_cdr (word);
34       word = gh_car (word);
35     }
36
37   if (gh_string_p (word))
38     {
39       /*
40         UGH. Should read from font metric structure.
41       */
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 ();
46
47       String w = ly_scm2string (word);
48
49       String style;
50       SCM s = scm_assoc (ly_symbol2scm ("style"), options_alist);
51       if (s != SCM_BOOL_F)
52         {
53           style = ly_scm2string (gh_cdr (s));
54         }
55
56       Offset offset;
57       int size = 0;
58       /*
59         urg, `type'
60       */
61       s = scm_assoc (ly_symbol2scm ("type"), options_alist);
62       if (s != SCM_BOOL_F && ly_scm2string (gh_cdr (s)) == "super")
63         {
64           Real super_y = ex / 2;
65           offset = Offset (0, super_y);
66           if (!size)
67             size = -2;
68         }
69
70       s = scm_assoc (ly_symbol2scm ("size"), options_alist);
71       if (s != SCM_BOOL_F)
72         {
73           size = gh_scm2int (gh_cdr (s));
74         }
75
76       s = scm_assoc (ly_symbol2scm ("offset"), options_alist);
77       if (s != SCM_BOOL_F)
78         {
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;
84         }
85
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 ());
92
93       mol.translate (offset);
94       return mol;
95     }
96   return Molecule ();
97 }
98
99 /*
100   ;; text: list of word
101   ;; word: string + optional list of property
102   ;; property: align, kern, font (?), size
103  */
104 Molecule
105 Chord_name::ly_text2molecule (Score_element * me, SCM text) 
106 {
107   Molecule mol;
108   if (gh_list_p (text))
109     {
110       while (gh_cdr (text) != SCM_EOL)
111         {
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);
117         }
118       text = gh_car (text);
119     }  
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;
125 }
126
127 MAKE_SCHEME_CALLBACK(Chord_name,brew_molecule);
128
129 SCM
130 Chord_name::brew_molecule (SCM smob) 
131 {
132   Score_element *sc = unsmob_element (smob);
133   SCM style = sc->get_elt_property ("style");
134
135   if (!gh_string_p (style))
136     style = ly_str02scm ("banter");
137
138   SCM inversion = sc-> get_elt_property ("inversion");
139   if (inversion != SCM_BOOL_T)
140     inversion = SCM_BOOL_F;
141
142   SCM bass =  sc->get_elt_property ("bass");
143   if (bass != SCM_BOOL_T)
144     bass = SCM_BOOL_F;
145
146   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));
152
153   return ly_text2molecule (sc, text).create_scheme ();
154 }