]> git.donarmstrong.com Git - lilypond.git/blob - lily/clef-modifier.cc
6d802ad2710948b271a669469f992be44f29dd2c
[lilypond.git] / lily / clef-modifier.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2014--2014 Janek WarchoĊ‚ <lemniskata.bernoullego@gmail.com>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "item.hh"
21
22 struct Clef_modifier
23 {
24   DECLARE_SCHEME_CALLBACK (calc_parent_alignment, (SCM));
25   DECLARE_GROB_INTERFACE ();
26 };
27
28 MAKE_SCHEME_CALLBACK (Clef_modifier, calc_parent_alignment, 1)
29 SCM
30 Clef_modifier::calc_parent_alignment (SCM smob)
31 {
32   Grob *me = Grob::unsmob (smob);
33   Grob *clef = me->get_parent (X_AXIS);
34   string full_clef_name = ly_scm2string (clef->get_property ("glyph"));
35
36   int separator_position = full_clef_name.find ('.');
37   string clef_type = full_clef_name.substr (separator_position + 1,
38                                             separator_position + 2);
39
40   // find entry with keyname clef_type in clef-alignments
41   SCM alist_entry = scm_assq (ly_symbol2scm (clef_type.c_str ()),
42                               me->get_property ("clef-alignments"));
43
44   if (scm_is_pair (alist_entry))
45     {
46       SCM entry_value = scm_cdr (alist_entry);
47       // the value should be a pair of numbers - first is the alignment
48       // for modifiers below the clef, second for those above.
49       if (scm_is_pair (entry_value))
50         if (robust_scm2dir (me->get_property ("direction"), DOWN) == DOWN)
51           return scm_car (entry_value);
52         else
53           return scm_cdr (entry_value);
54
55       else // default alignment = centered
56         return scm_from_double (0);
57     }
58   else // default alignment = centered
59     return scm_from_double (0);
60 }
61
62 ADD_INTERFACE (Clef_modifier,
63                "The number describing transposition of the clef, placed below\n"
64                "or above clef sign. Usually this is 8 (octave transposition)\n"
65                "or 15 (two octaves), but LilyPond allows any integer here.",
66
67                /* properties */
68                "clef-alignments "
69               );
70