summaryrefslogtreecommitdiff
path: root/lily/custos.cc
blob: 3ed96f6a992ec4ec59f533cca3b5c1cacf1cb8bf (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
  custos.cc -- implement Custos

  source file of the GNU LilyPond music typesetter

  (c) 2000--2007 Juergen Reuter <reuter@ipd.uka.de>
*/

/* TODO:

- do not show if a clef change immediately follows in the next line

- decide: do or do not print custos if the next line starts with a rest
*/

#include <cstdio>
#include <cmath> // rint
using namespace std;

#include "custos.hh"
#include "direction.hh"
#include "font-interface.hh"
#include "international.hh"
#include "item.hh"
#include "note-head.hh"
#include "staff-symbol-referencer.hh"
#include "warn.hh"

MAKE_SCHEME_CALLBACK (Custos, print, 1);
SCM
Custos::print (SCM smob)
{
  Item *me = (Item *)unsmob_grob (smob);

  SCM scm_style = me->get_property ("style");
  string style;
  if (scm_is_symbol (scm_style))
    style = ly_symbol2string (scm_style);
  else
    style = "mensural";

  /*
   * Shall we use a common custos font character regardless if on
   * staffline or not, or shall we use individual font characters
   * for both cases?
   */
  bool adjust = true;

  int neutral_pos = robust_scm2int (me->get_property ("neutral-position"), 0);
  Direction neutral_direction
    = to_dir (me->get_property ("neutral-direction"));

  int pos = Staff_symbol_referencer::get_rounded_position (me);
  int sz = Staff_symbol_referencer::line_count (me) - 1;

  string font_char = "custodes." + style + ".";
  if (pos < neutral_pos)
    font_char += "u";
  else if (pos > neutral_pos)
    font_char += "d";
  else if (neutral_direction == UP)
    font_char += "u";
  else if (neutral_direction == DOWN)
    font_char += "d";
  else // auto direction; not yet supported -> use "d"
    font_char += "d";

  if (adjust)
    font_char += (((pos ^ sz) & 0x1) == 0) ? "1" : "0";
  else
    font_char += "2";

  Stencil stencil
    = Font_interface::get_default_font (me)->find_by_name (font_char);
  if (stencil.is_empty ())
    {
      me->warning (_f ("custos `%s' not found", font_char));
      return SCM_EOL;
    }

  return stencil.smobbed_copy ();
}

ADD_INTERFACE (Custos,
	       "A custos object.",
	       "style "
	       "neutral-position "
	       "neutral-direction ");