source file of the GNU LilyPond music typesetter
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+ (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
#include "misc.hh"
#include "dots.hh"
#include "note-head.hh"
-#include "dimen.hh"
#include "debug.hh"
-#include "paper-def.hh"
#include "lookup.hh"
#include "molecule.hh"
#include "musical-request.hh"
+#include "stem.hh"
+void
+Note_head::flip_around_stem (Direction d)
+{
+ translate_axis (do_width ().length () * d, X_AXIS);
+}
Note_head::Note_head ()
{
- x_dir_ = CENTER;
- staff_size_i_= 8; // UGH
- position_i_ = 0;
- extremal_i_ = 0;
}
void
Note_head::do_pre_processing ()
{
+ Rhythmic_head::do_pre_processing ();
+
// 8 ball looks the same as 4 ball:
- if (balltype_i_ > 2)
+ String type;
+ SCM style = get_elt_property ("style");
+ if (style != SCM_UNDEFINED)
+ {
+ type = ly_scm2string (style);
+ }
+
+
+ if (balltype_i_ > 2 || type == "harmonic" || type == "cross")
balltype_i_ = 2;
+
if (dots_l_) // move into Rhythmic_head?
- dots_l_->position_i_ = position_i_;
+ dots_l_->set_position(int (position_f ()));
+
+
}
-IMPLEMENT_IS_TYPE_B1(Note_head,Rhythmic_head);
int
Note_head::compare (Note_head *const &a, Note_head * const &b)
{
- return a->position_i_ - b->position_i_;
+ return sign(a->position_f () - b->position_f ());
}
+/**
+ Don't account for ledgerlines in the width.
+ */
Interval
Note_head::do_width () const
{
- Atom a = paper ()->lookup_l()->ball (balltype_i_);
- Interval i = a.dim_[X_AXIS];
- i+= x_dir_ * i.length ();
- return i;
+ return make_molecule ().dim_[X_AXIS];
+}
+
+Molecule
+Note_head::make_molecule () const
+{
+ String type;
+ SCM style = get_elt_property ("style");
+ if (style != SCM_UNDEFINED)
+ {
+ type = ly_scm2string (style);
+ }
+
+ return lookup_l()->afm_find (String ("noteheads-")
+ + to_str (balltype_i_) + type);
}
Molecule*
-Note_head::brew_molecule_p() const
+Note_head::do_brew_molecule_p() const
{
- Molecule*out = 0;
- Paper_def *p = paper();
- Real inter_f = p->internote_f ();
+ Real inter_f = staff_line_leading_f ()/2;
+ int sz = lines_i ()-1;
- // ugh
- int streepjes_i = abs(position_i_) < staff_size_i_/2
+ int streepjes_i = abs (position_f ()) < sz
? 0
- : (abs(position_i_) - staff_size_i_/2) /2;
-
- Atom s = p->lookup_l()->ball (balltype_i_);
- out = new Molecule (Atom (s));
- out->translate_axis (x_dir_ * s.dim_[X_AXIS].length (), X_AXIS);
+ : (abs((int)position_f ()) - sz) /2;
+
+ Molecule* out = new Molecule (make_molecule ());
+
+ Box b = out->dim_;
if (streepjes_i)
{
- int dir = sign (position_i_);
-
- Atom streepje = p->lookup_l()->streepjes (balltype_i_, dir* streepjes_i);
-
- Molecule sm;
- sm.add (streepje);
- if (position_i_ % 2)
- sm.translate_axis (-inter_f* dir, Y_AXIS);
- out->add (sm);
+ Direction dir = (Direction)sign (position_f ());
+ Interval hd = out->dim_[X_AXIS];
+ Real hw = hd.length ()/4;
+
+ Molecule ledger
+ = lookup_l ()->ledger_line (Interval (hd[LEFT] - hw,
+ hd[RIGHT] + hw));
+
+ int parity = abs(int (position_f ())) % 2;
+
+ for (int i=0; i < streepjes_i; i++)
+ {
+ Molecule s (ledger);
+ s.translate_axis (-dir * inter_f * (i*2 + parity),
+ Y_AXIS);
+ out->add_molecule (s);
+ }
}
-
- out->translate_axis (inter_f*position_i_, Y_AXIS);
+
+ out->dim_ = b;
return out;
}
+