+/*
+ notehead.cc -- implement Note_head
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
#include "misc.hh"
-#include "notehead.hh"
+#include "note-head.hh"
#include "dimen.hh"
#include "debug.hh"
#include "paper-def.hh"
#include "lookup.hh"
#include "molecule.hh"
-#include "musicalrequest.hh"
+#include "musical-request.hh"
+
+/*
+ TODO
+
+ Separate notehead into
+
+
+ Rhythmic_head
+ Note_head
+ Rest
+ and Stem takes Rhythmic_heads
+ */
-Notehead::Notehead(int ss)
+Note_head::Note_head (int ss)
{
- x_dir = 0;
- staff_size=ss;
- position = 0;
- balltype = 0;
- dots = 0;
- extremal = 0;
+ x_dir_ = CENTER;
+ staff_size_i_=ss;
+ position_i_ = 0;
+ balltype_i_ = 0;
+ dots_i_ = 0;
+ dot_delta_y_i_ = 0;
+ extremal_i_ = 0;
+ rest_b_ = false;
}
void
-Notehead::set_rhythmic(Rhythmic_req*r_req_l)
+Note_head::do_pre_processing()
{
- balltype = r_req_l->balltype;
- dots = r_req_l->dots;
+ // 8 ball looks the same as 4 ball:
+ if (balltype_i_ > 2 && !rest_b_)
+ balltype_i_ = 2;
+
+ if (rest_b_)
+ {
+ if (balltype_i_ == 0)
+ position_i_ += 6;
+ else if (balltype_i_ == 0)
+ position_i_ += 4;
+ }
}
-
+
void
-Notehead::do_print()const
+Note_head::set_rhythmic (Rhythmic_req*r_req_l)
+{
+ balltype_i_ = r_req_l->duration_.durlog_i_;
+ dots_i_ = r_req_l->duration_.dots_i_;
+}
+
+
+IMPLEMENT_IS_TYPE_B1(Note_head,Item);
+
+void
+Note_head::do_print() const
{
#ifndef NPRINT
- mtor << "balltype "<< balltype << ", position = "<< position
- << "dots " << dots;
+ if (rest_b_)
+ DOUT << "REST! ";
+ DOUT << "balltype_i_ "<< balltype_i_ << ", position_i_ = "<< position_i_
+ << "dots_i_ " << dots_i_;
#endif
}
int
-Notehead::compare(Notehead *const &a, Notehead * const &b)
+Note_head::compare (Note_head *const &a, Note_head * const &b)
+{
+ return a->position_i_ - b->position_i_;
+}
+
+void
+Note_head::set_dots()
{
- return a->position - b->position;
+ if (!(position_i_ %2) && rest_b_ && balltype_i_ == 0)
+ dot_delta_y_i_ = -1;
+ else if (!(position_i_ %2))
+ dot_delta_y_i_ = 1;
}
+/*
+ Ugh, hairy.
+ */
Molecule*
-Notehead::brew_molecule_p() const return out;
+Note_head::brew_molecule_p() const
{
- Paper_def *p = paper();
-
- Real dy = p->internote();
- Symbol s = p->lookup_p_->ball(balltype);
-
- out = new Molecule(Atom(s));
- if (dots) {
- Symbol d = p->lookup_p_->dots(dots);
- Molecule dm;
- dm.add(Atom(d));
- if (!(position %2))
- dm.translate(Offset(0,dy));
- out->add_right(dm);
+ ((Note_head*)this)->set_dots(); // UGH GUH
+ Molecule*out = 0;
+ Paper_def *p = paper();
+ Real inter_f = p->internote_f();
+ Symbol s;
+
+ // ugh
+ bool streepjes_b = (position_i_<-1) || (position_i_ > staff_size_i_+1);
+
+ if (!rest_b_)
+ s = p->lookup_l()->ball (balltype_i_);
+ else
+ {
+ s = p->lookup_l()->rest (balltype_i_, streepjes_b);
+ }
+ out = new Molecule (Atom (s));
+ out->translate (x_dir_ * s.dim.x().length () , X_AXIS);
+ if (dots_i_)
+ {
+ Symbol d = p->lookup_l()->dots (dots_i_);
+ Molecule dm;
+ dm.add (Atom (d));
+ dm.translate (inter_f * dot_delta_y_i_ , Y_AXIS);
+ out->add_right (dm);
+ }
+
+
+ if (rest_b_)
+ {
+ streepjes_b = false;
}
- out->translate(Offset(x_dir * p->note_width(),0));
- bool streepjes = (position<-1)||(position > staff_size+1);
- if (streepjes) {
- int dir = sign(position);
- int s =(position<-1) ? -((-position)/2): (position-staff_size)/2;
- Symbol str = p->lookup_p_->streepjes(s);
- Molecule sm;
- sm.add(Atom(str));
- if (position % 2)
- sm.translate(Offset(0,-dy* dir));
- out->add(sm);
+
+ if (streepjes_b)
+ {
+ int dir = sign (position_i_);
+ int s =(position_i_<-1) ? -((-position_i_)/2): (position_i_-staff_size_i_)/2;
+
+ Symbol str = p->lookup_l()->streepjes (s);
+ Molecule sm;
+ sm.add (Atom (str));
+ if (position_i_ % 2)
+ sm.translate (-inter_f* dir, Y_AXIS);
+ out->add (sm);
}
-
- out->translate(Offset(0,dy*position));
+
+ out->translate (inter_f*position_i_, Y_AXIS);
+ return out;
}