2 plet-spanner.cc -- implement Plet_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
13 #include "molecule.hh"
15 #include "paper-def.hh"
16 #include "plet-spanner.hh"
18 #include "text-def.hh"
22 UHGUGH THIS IS BROKEN! do not derive from Bow
24 IMPLEMENT_IS_TYPE_B1 (Plet_spanner
,Bow
);
26 Plet_spanner::Plet_spanner ()
29 stem_l_drul_
[RIGHT
] =0;
30 stem_l_drul_
[LEFT
] =0;
33 tdef_p_
= new Text_def
;
34 tdef_p_
->align_dir_
= CENTER
;
35 tdef_p_
->style_str_
= "italic";
38 Plet_spanner::Plet_spanner (Plet_spanner
const& c
)
41 tdef_p_
= new Text_def (*c
.tdef_p_
);
42 stem_l_drul_
= c
.stem_l_drul_
;
43 visibility_i_
= c
.visibility_i_
;
46 Plet_spanner::~Plet_spanner ()
52 Plet_spanner::brew_molecule_p () const
54 Molecule
* mol_p
= new Molecule
;
56 Real w
= width ().length ();
58 Real dy_f
= dy_f_drul_
[RIGHT
] - dy_f_drul_
[LEFT
];
60 w
+= (dx_f_drul_
[RIGHT
] - dx_f_drul_
[LEFT
]);
62 Atom a
= lookup_l ()->plet (dy_f
, w
, dir_
);
64 a
.translate (Offset (dx_f_drul_
[LEFT
], dy_f_drul_
[LEFT
]));
66 if (visibility_i_
>= 2)
69 Real interline_f
= paper ()->interline_f ();
70 Real numy_f
= (dir_
> 0 ? 0 : -interline_f
) + dir_
* interline_f
/ 2;
71 Atom
num (tdef_p_
->get_atom (paper (), CENTER
));
72 num
.translate (Offset (width ().length () / 1.8 + dx_f_drul_
[LEFT
],
73 dy_f_drul_
[LEFT
] + dy_f
/ 2 + numy_f
));
75 if (visibility_i_
>= 1)
76 mol_p
->add_atom (num
);
82 Plet_spanner::do_add_processing ()
84 if (! (stem_l_drul_
[LEFT
] && stem_l_drul_
[RIGHT
]))
85 warning (_ ("lonely plet"));
88 Drul_array
<Stem
*> new_stem_drul
= stem_l_drul_
;
91 new_stem_drul
[d
] = stem_l_drul_
[(Direction
)-d
];
92 } while (flip(&d
) != LEFT
);
93 stem_l_drul_
= new_stem_drul
;
97 Plet_spanner::do_post_processing ()
99 Real interline_f
= paper ()->interline_f ();
100 Real nh_f
= interline_f
/ 2;
101 assert (stem_l_drul_
[LEFT
] || stem_l_drul_
[RIGHT
]);
104 Real nw_f
= paper ()->note_width () * 0.8;
109 Stem
* s
= stem_l_drul_
[d
] ? stem_l_drul_
[d
] : stem_l_drul_
[(Direction
)-d
];
111 dy_f_drul_
[d
] = dir_
== s
->get_dir () ? s
->stem_end_f ()
112 : s
->stem_begin_f () + dir_
* nh_f
/ 2;
113 dy_f_drul_
[d
] *= .5 * interline_f
;
114 dy_f_drul_
[d
] += dir_
* interline_f
;
116 dx_f_drul_
[d
] = nw_f
;
118 while (flip(&d
) != LEFT
);
120 if (stem_l_drul_
[d
]->empty_b ())
124 dy_f_drul_
[d
] = dy_f_drul_
[u
]; // ughugh \[/3 r8 c8 r8 \]/1
127 while (flip(&d
) != LEFT
);
131 Plet_spanner::do_substitute_dependency (Score_element
* o
, Score_element
* n
)
133 Stem
* new_l
= n
? dynamic_cast<Stem
*> (n
) : 0;
134 if (dynamic_cast <Item
*> (o
) == stem_l_drul_
[LEFT
])
135 stem_l_drul_
[LEFT
] = new_l
;
136 else if (dynamic_cast <Item
*> (o
) == stem_l_drul_
[RIGHT
])
137 stem_l_drul_
[RIGHT
] = new_l
;
141 Plet_spanner::set_default_dir ()
143 Real m
= (stem_l_drul_
[LEFT
]->stem_end_f ()
144 + stem_l_drul_
[RIGHT
]->stem_end_f ()) / 2;
145 dir_
= (m
< 0) ? DOWN
: UP
;
149 Plet_spanner::set_stem (Direction d
, Stem
* stem_l
)
151 assert (!stem_l_drul_
[d
]);
152 stem_l_drul_
[d
] = stem_l
;
153 set_bounds (d
, stem_l
);
155 add_dependency (stem_l
);