~ubuntu-branches/ubuntu/precise/lilypond/precise

« back to all changes in this revision

Viewing changes to lily/bar-number-engraver.cc

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Bushnell, BSG
  • Date: 2006-12-19 10:18:12 UTC
  • mfrom: (3.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061219101812-7awtjkp0i393wxty
Tags: 2.8.7-3
scripts/midi2ly.py: When setting DATADIR, find Lilypond python files
in the @TOPLEVEL_VERSION@ directory, not 'current'.  Patch thanks to
Chris Lamb (chris@chris-lamb.co.uk).  (Closes: #400550)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
  source file of the GNU LilyPond music typesetter
5
5
 
6
 
  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
6
  (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
7
*/
8
8
 
9
 
 
10
 
#include "lily-guile.hh"
11
9
#include "paper-column.hh"
12
 
#include "paper-def.hh"
 
10
#include "output-def.hh"
13
11
#include "side-position-interface.hh"
14
 
#include "item.hh"
15
 
#include "moment.hh"
16
12
#include "engraver.hh"
17
13
#include "context.hh"
 
14
#include "grob-array.hh"
 
15
 
 
16
#include "translator.icc"
18
17
 
19
18
/*
20
 
  
21
 
TODO: detect the top staff (stavesFound), and acknowledge staff-group
22
 
system-start-delims. If we find these, and the top staff is in the
23
 
staff-group, add padding to the bar number.
24
 
 
 
19
  TODO: detect the top staff (stavesFound), and acknowledge staff-group
 
20
  system-start-delims. If we find these, and the top staff is in the
 
21
  staff-group, add padding to the bar number.
25
22
*/
26
23
 
27
 
 
28
24
class Bar_number_engraver : public Engraver
29
25
{
30
26
protected:
31
 
  Item* text_;
 
27
  Item *text_;
32
28
protected:
33
 
  virtual void stop_translation_timestep ();
34
 
  virtual void acknowledge_grob (Grob_info);
35
 
  virtual void process_music ();
 
29
  void stop_translation_timestep ();
 
30
  DECLARE_ACKNOWLEDGER (break_aligned);
 
31
  DECLARE_ACKNOWLEDGER (break_alignment);
 
32
  void process_music ();
36
33
  void create_items ();
37
 
  TRANSLATOR_DECLARATIONS (Bar_number_engraver );
 
34
  TRANSLATOR_DECLARATIONS (Bar_number_engraver);
38
35
};
39
36
 
40
 
 
41
37
void
42
38
Bar_number_engraver::process_music ()
43
39
{
44
40
  // todo include (&&!time->cadenza_b_)
45
41
 
46
42
  SCM wb = get_property ("whichBar");
47
 
  
48
 
  if (gh_string_p (wb))
 
43
 
 
44
  if (scm_is_string (wb))
49
45
    {
50
 
      SCM smp = get_property ("measurePosition");
51
 
      
52
 
      Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
 
46
      Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
53
47
      if (mp.main_part_ == Rational (0))
54
48
        {
55
49
          SCM bn = get_property ("currentBarNumber");
56
50
          SCM proc = get_property ("barNumberVisibility");
57
 
          if (gh_number_p (bn) && gh_procedure_p (proc)
58
 
              && to_boolean (gh_call1(proc, bn)))
 
51
          if (scm_is_number (bn) && ly_is_procedure (proc)
 
52
              && to_boolean (scm_call_1 (proc, bn)))
59
53
            {
60
54
              create_items ();
61
55
              // guh.
62
56
              text_->set_property
63
 
                ("text", scm_makfrom0str (to_string (gh_scm2int (bn)).to_str0 ()));
 
57
                ("text", scm_number_to_string (bn, scm_from_int (10)));
64
58
            }
65
59
        }
66
60
    }
67
 
 
68
61
}
69
62
 
70
 
 
71
 
 
72
63
Bar_number_engraver::Bar_number_engraver ()
73
64
{
74
 
  text_ =0;
 
65
  text_ = 0;
75
66
}
76
67
 
77
 
                                               
 
68
 
 
69
/*
 
70
  see rehearsal mark comments.
 
71
 */
78
72
void
79
 
Bar_number_engraver::acknowledge_grob (Grob_info inf)
 
73
Bar_number_engraver::acknowledge_break_aligned (Grob_info inf)
80
74
{
81
 
  Grob * s = inf.grob_;
 
75
  Grob *s = inf.grob ();
82
76
  if (text_
83
 
      && dynamic_cast<Item*> (s)
84
 
      && s->get_property ("break-align-symbol") == ly_symbol2scm ("left-edge"))
 
77
      && !text_->get_parent (X_AXIS)
 
78
      && dynamic_cast<Item *> (s)
 
79
      && (s->get_property_data (ly_symbol2scm ("break-align-symbol"))
 
80
          == text_->get_property_data (ly_symbol2scm ("break-align-symbol"))))
85
81
    {
86
82
      /*
87
83
        By default this would land on the Paper_column -- so why
90
86
    }
91
87
}
92
88
 
93
 
void 
 
89
 
 
90
void
 
91
Bar_number_engraver::acknowledge_break_alignment (Grob_info inf)
 
92
{
 
93
  Grob *s = inf.grob ();
 
94
  if (text_
 
95
      && dynamic_cast<Item *> (s))
 
96
    {
 
97
      text_->set_parent (s, X_AXIS);
 
98
    }
 
99
}
 
100
 
 
101
void
94
102
Bar_number_engraver::stop_translation_timestep ()
95
103
{
96
104
  if (text_)
97
105
    {
98
 
      text_->set_property ("side-support-elements", get_property ("stavesFound"));
99
 
      typeset_grob (text_);
100
 
      text_ =0;
 
106
      text_->set_object ("side-support-elements",
 
107
                         grob_list_to_grob_array (get_property ("stavesFound")));
 
108
      text_ = 0;
101
109
    }
102
110
}
103
111
 
104
 
 
105
112
void
106
113
Bar_number_engraver::create_items ()
107
114
{
108
115
  if (text_)
109
116
    return;
110
117
 
111
 
  text_ = make_item ("BarNumber");
112
 
  Side_position_interface::set_axis (text_,Y_AXIS);
113
 
 
114
 
  announce_grob (text_, SCM_EOL);
 
118
  text_ = make_item ("BarNumber", SCM_EOL);
115
119
}
116
120
 
117
 
ENTER_DESCRIPTION (Bar_number_engraver,
118
 
/* descr */       "A bar number is created whenever measurePosition is zero. It is\n"
119
 
                   "put on top of all staves, and appears only at  left side of the staff. "
120
 
                   "The staves are taken from @code{stavesFound}, which is maintained by "
121
 
                   "@code{@ref{Staff_collecting_engraver}}. "
122
 
                   ,
123
 
                   
124
 
/* creats*/       "BarNumber",
125
 
/* accepts */     "",
126
 
/* acks  */      "break-aligned-interface",
127
 
/* reads */       "currentBarNumber stavesFound barNumberVisibility" ,
128
 
/* write */       "");
 
121
 
 
122
ADD_ACKNOWLEDGER(Bar_number_engraver,break_aligned);
 
123
ADD_ACKNOWLEDGER(Bar_number_engraver,break_alignment);
 
124
 
 
125
ADD_TRANSLATOR (Bar_number_engraver,
 
126
                /* doc */ "A bar number is created whenever measurePosition "
 
127
                "is zero and when there is a bar line (ie. when @code{whichBar} is set. "
 
128
                "It is \n"
 
129
                "put on top of all staves, and appears only at  left side of the staff. "
 
130
                "The staves are taken from @code{stavesFound}, which is maintained by "
 
131
                "@code{@ref{Staff_collecting_engraver}}. ",
 
132
 
 
133
                /* create */ "BarNumber",
 
134
                /* accept */ "",
 
135
                /* read */
 
136
                "currentBarNumber "
 
137
                "whichBar "
 
138
                "stavesFound "
 
139
                "barNumberVisibility ",
 
140
                /* write */ "");