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

« back to all changes in this revision

Viewing changes to lily/instrument-name-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:
1
 
/*   
2
 
  instrument-name-engraver.cc --  implement Instrument_name_engraver
3
 
  
 
1
/*
 
2
  instrument-name-engraver.cc -- implement Instrument_name_engraver
 
3
 
4
4
  source file of the GNU LilyPond music typesetter
5
 
  
6
 
  (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
 
  
8
 
 */
 
5
 
 
6
  (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
7
*/
9
8
 
10
9
#include "engraver.hh"
11
 
#include "item.hh"
12
 
#include "bar-line.hh"
13
 
#include "system-start-delimiter.hh"
 
10
#include "spanner.hh"
 
11
#include "pointer-group-interface.hh"
14
12
#include "side-position-interface.hh"
 
13
#include "axis-group-interface.hh"
15
14
#include "align-interface.hh"
16
 
#include "axis-group-interface.hh"
17
 
#include "context.hh"
18
 
#include "text-item.hh"
 
15
#include "text-interface.hh"
 
16
#include "system.hh"
 
17
 
 
18
#include "translator.icc"
19
19
 
20
20
class Instrument_name_engraver : public Engraver
21
21
{
22
 
  
23
22
public:
24
23
  TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
25
24
 
26
25
protected:
27
 
  Grob *text_;
 
26
  Spanner *text_spanner_;
28
27
 
29
 
  virtual void create_text ();
30
 
  virtual void initialize ();
31
 
  virtual void acknowledge_grob (Grob_info);
32
 
  virtual void stop_translation_timestep ();
33
 
  virtual void process_music ();
 
28
  virtual void finalize ();
 
29
  DECLARE_ACKNOWLEDGER (axis_group);
 
30
  void process_music ();
34
31
};
35
32
 
36
33
Instrument_name_engraver::Instrument_name_engraver ()
37
34
{
38
 
  text_ = 0;
39
 
}
40
 
 
41
 
 
42
 
void
43
 
Instrument_name_engraver::initialize ()
44
 
{
45
 
  daddy_context_->set_property ("instrumentSupport", SCM_EOL); 
46
 
}
47
 
 
48
 
void
49
 
Instrument_name_engraver::stop_translation_timestep ()
50
 
{
51
 
  if (text_)
52
 
    {
53
 
      text_->set_property ("side-support-elements",
54
 
                                get_property ("instrumentSupport"));
55
 
      typeset_grob (text_);
56
 
      text_ = 0;
57
 
    }
58
 
}
59
 
 
60
 
 
61
 
void
62
 
Instrument_name_engraver::create_text ()
63
 
{
64
 
  if (text_)
65
 
    return ;
66
 
  
67
 
  SCM txt = get_property ("instrument");
68
 
  
69
 
  if (now_mom () > Moment (0))
70
 
    txt = get_property ("instr");
71
 
  /*
72
 
    UGH.
73
 
  */
74
 
  if (txt == SCM_EOL)
75
 
    return ;
76
 
 
77
 
  
78
 
  text_ = make_item ("InstrumentName");
79
 
      
80
 
  if (text_->get_property ("text") != txt)
81
 
    text_->set_property ("text", txt);
82
 
  announce_grob (text_, SCM_EOL);
83
 
  }
84
 
 
85
 
void
86
 
Instrument_name_engraver::acknowledge_grob (Grob_info i)
87
 
{
88
 
  if (Bar_line::has_interface (i.grob_))
89
 
    {
90
 
      create_text ();
91
 
    }
92
 
 
93
 
  if (dynamic_cast<Spanner*> (i.grob_)
94
 
      && i.grob_->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
95
 
    return;
96
 
 
97
 
  /*
98
 
    Hang the instrument names on the staves, but not on the alignment
99
 
    groups enclosing that staff. The alignment has no real location,
100
 
    but is only a vehicle for the placement routine it contains, and
101
 
    therefore the location of its refpoint won't be very useful.
102
 
 
103
 
    We could also just use stavesFound, but lets keep this working
104
 
    without staffs as well.
105
 
  */
106
 
  if (dynamic_cast<Spanner*> (i.grob_)
107
 
      && ((Axis_group_interface::has_interface (i.grob_)
108
 
           && Axis_group_interface::has_axis (i.grob_, Y_AXIS)))
109
 
      && !Align_interface::has_interface (i.grob_))
110
 
    {
111
 
      SCM nl = gh_cons (i.grob_->self_scm (),
112
 
                        get_property ("instrumentSupport"));
113
 
 
114
 
      daddy_context_->set_property ("instrumentSupport", nl);
115
 
    }
 
35
  text_spanner_ = 0;
116
36
}
117
37
 
118
38
void
119
39
Instrument_name_engraver::process_music ()
120
40
{
121
 
  /*
122
 
    Also create text if barlines in other groups. This allows
123
 
    a name to be attached to lyrics or chords. 
124
 
   */
125
 
  if (gh_string_p (get_property ("whichBar")))
126
 
    create_text ();
127
 
}
128
 
 
129
 
ENTER_DESCRIPTION (Instrument_name_engraver,
130
 
/* descr */       " Prints the name of the instrument (specified by "
131
 
" @code{Staff.instrument} and @code{Staff.instr}) "
132
 
"at the left of the staff. ",
133
 
/* creats*/       "InstrumentName",
134
 
/* accepts */     "",
135
 
/* acks  */      "bar-line-interface axis-group-interface",
136
 
/* reads */       "instrument instr",
137
 
/* write */       "");
138
 
 
139
 
/****************************************************************/
140
 
 
141
 
 
142
 
class Vocal_name_engraver : public Instrument_name_engraver
143
 
{
144
 
public:
145
 
  TRANSLATOR_DECLARATIONS (Vocal_name_engraver);
146
 
  virtual void create_text ();
147
 
};
148
 
 
149
 
 
150
 
Vocal_name_engraver::Vocal_name_engraver ()
151
 
{
152
 
}
153
 
 
154
 
 
155
 
void
156
 
Vocal_name_engraver::create_text ()
157
 
{
158
 
  if (text_)
159
 
    return ;
160
 
  
161
 
  SCM txt = get_property ("vocalName");
162
 
  
163
 
  if (now_mom () > Moment (0))
164
 
    txt = get_property ("vocNam");
165
 
 
166
 
  /*
167
 
    UGH.
168
 
  */
169
 
  if (txt == SCM_EOL)
170
 
    return ;
171
 
  
172
 
  text_ = make_item ("VocalName");
173
 
      
174
 
  if (text_->get_property ("text") != txt)
175
 
    text_->set_property ("text", txt);
176
 
  announce_grob (text_, SCM_EOL);
177
 
}
178
 
 
179
 
 
180
 
 
181
 
ENTER_DESCRIPTION (Vocal_name_engraver,
182
 
/* descr */       " Prints the name of the a lyric voice (specified by "
183
 
" @code{Staff.vocalName} and @code{Staff.vocNam}) "
184
 
"at the left of the staff. ",
185
 
/* creats*/       "VocalName",
186
 
/* accepts */     "",
187
 
/* acks  */      "bar-line-interface axis-group-interface",
188
 
/* reads */       "vocNam vocalName",
189
 
/* write */       "");
 
41
  if (!text_spanner_)
 
42
    {
 
43
      SCM long_text = get_property ("instrument");
 
44
      SCM short_text = get_property ("instr");
 
45
 
 
46
      if (!(Text_interface::is_markup (long_text)
 
47
            || Text_interface::is_markup (short_text)))
 
48
        {
 
49
          long_text = get_property ("vocalName");
 
50
          short_text = get_property ("vocNam");
 
51
        }
 
52
  
 
53
      if (Text_interface::is_markup (long_text)
 
54
          || Text_interface::is_markup (short_text))
 
55
        {
 
56
          text_spanner_ = make_spanner ("InstrumentName", SCM_EOL);
 
57
          
 
58
          Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
 
59
          text_spanner_->set_bound (LEFT, col);
 
60
          text_spanner_->set_property ("text", short_text);
 
61
          text_spanner_->set_property ("long-text", long_text);
 
62
        }
 
63
    }
 
64
}
 
65
 
 
66
void
 
67
Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
 
68
{
 
69
  if (text_spanner_ 
 
70
      && dynamic_cast<Spanner *> (info.grob ())
 
71
      && Axis_group_interface::has_axis (info.grob (), Y_AXIS)
 
72
      && (!Align_interface::has_interface (info.grob ())))
 
73
    {
 
74
      Grob *staff = info.grob();
 
75
      Pointer_group_interface::add_grob (text_spanner_, ly_symbol2scm ("elements"), staff);
 
76
      Side_position_interface::add_support (text_spanner_, staff);
 
77
    }
 
78
}
 
79
 
 
80
void
 
81
Instrument_name_engraver::finalize ()
 
82
{
 
83
  if (text_spanner_)
 
84
    {
 
85
      text_spanner_->set_bound (RIGHT,
 
86
                                unsmob_grob (get_property ("currentCommandColumn")));
 
87
 
 
88
      Pointer_group_interface::set_ordered (text_spanner_, ly_symbol2scm ("elements"), false);
 
89
 
 
90
      System *system = get_root_system (text_spanner_);
 
91
 
 
92
      /*
 
93
        UGH, should handle this in Score_engraver.
 
94
       */
 
95
      if (system)
 
96
        Axis_group_interface::add_element (system, text_spanner_);
 
97
      else
 
98
        text_spanner_->programming_error ("can't find root system");
 
99
    }
 
100
}
 
101
 
 
102
#include "translator.icc"
 
103
 
 
104
ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
 
105
 
 
106
ADD_TRANSLATOR (Instrument_name_engraver,
 
107
 
 
108
                /* doc */
 
109
                "Creates a system start text for instrument or vocal names.",
 
110
                
 
111
                /* create */
 
112
                "InstrumentName ",
 
113
                
 
114
                /* accept */
 
115
                "",
 
116
                
 
117
                /* read */
 
118
                "vocNam vocalName instrument instr "
 
119
                "currentCommandColumn",
 
120
 
 
121
                /* write */ "");