#include "misc.hh"
const int STEMLEN=7;
-
-Stem::Stem(int c, Real len)
+NAME_METHOD(Stem);
+Stem::Stem(int c) //, Moment len)
{
- note_length = len;
+// note_length = len;
beams_left = 0;
beams_right = 0;
minnote = 1000; // invalid values
}
void
-Stem::print() const
+Stem::do_print() const
{
#ifndef NPRINT
- mtor << "{\n";
mtor << "flag "<< flag << " print_flag " << print_flag
<< "min,max [" << minnote << ", " << maxnote << "]";
-
-
- Item::print();
- mtor << "}\n";
#endif
}
void
Stem::set_stemend(Real se)
{
- assert(!output);
+
// todo: margins
- assert((dir > 0 && se >= maxnote) || (se <= minnote && dir <0));
+ if (! ((dir > 0 && se >= maxnote) || (se <= minnote && dir <0)) )
+ WARN << "Weird stem size; check for narrow beams.\n";
top = (dir < 0) ? maxnote : se;
bot = (dir < 0) ? se : minnote;
- flag = dir*ABS(flag);
+ flag = dir*abs(flag);
}
void
Stem::add(Notehead *n)
{
+ assert(status < PRECALCED);
+
if (n->balltype == 1)
return;
int p = n->position;
minnote = p;
if ( p> maxnote)
maxnote = p;
- heads.add(n);
+ heads.push(n);
+ n->dependencies.push(this);
}
+int
+Stem::get_default_dir()
+{
+ if (dir)
+ return dir;
+ Real mean = (minnote+maxnote)/2;
+ return (mean > staff_center) ? -1: 1;
+}
void
Stem::set_default_dir()
{
- Real mean = (minnote+maxnote)/2;
- dir = (mean > staff_center) ? -1: 1;
+ dir = get_default_dir();
}
-
void
Stem::set_default_stemlen()
{
Stem::set_noteheads()
{
heads.sort(Notehead::compare);
- int parity=0;
+ heads[0]->extremal = -1;
+ heads.last()->extremal = 1;
+ int parity=1;
int lastpos = heads[0]->position;
- for (int i=1; i < heads.sz(); i ++) {
- if (ABS(lastpos- heads[i]->position) == 1) {
+ for (int i=1; i < heads.size(); i ++) {
+ int dy =abs(lastpos- heads[i]->position);
+
+ if (dy <= 1) {
if (parity)
heads[i]->x_dir = (stem_xoffset>0) ? 1:-1;
parity = !parity;
}
void
-Stem::postprocess()
+Stem::do_pre_processing()
{
if (bot == top)
set_default_extents();
set_noteheads();
- brew_molecole();
}
+
Interval
Stem::width()const
{
- if (!print_flag || ABS(flag) <= 4)
+ if (!print_flag || abs(flag) <= 4)
return Interval(0,0); // TODO!
Paperdef*p= paper();
- Interval r(p->lookup_->flag(flag).dim.x);
+ Interval r(p->lookup_p_->flag(flag).dim.x);
r+= stem_xoffset;
return r;
}
-void
-Stem::brew_molecole()
+Molecule*
+Stem::brew_molecule_p()const return out;
{
- assert(pstaff_);
assert(bot!=top);
- assert(!output);
+
Paperdef *p =paper();
Real dy = p->internote();
- Symbol ss =p->lookup_->stem(bot*dy,top*dy);
+ Symbol ss =p->lookup_p_->stem(bot*dy,top*dy);
- output = new Molecule(Atom(ss));
+ out = new Molecule(Atom(ss));
- if (print_flag&&ABS(flag) > 4){
- Symbol fl = p->lookup_->flag(flag);
+ if (print_flag&&abs(flag) > 4){
+ Symbol fl = p->lookup_p_->flag(flag);
Molecule m(fl);
if (flag < -4){
- output->add_bottom(m);
+ out->add_bottom(m);
} else if (flag > 4) {
- output->add_top(m);
+ out->add_top(m);
} else
assert(false);
}
- output->translate(Offset(stem_xoffset,0));
-
+ out->translate(Offset(stem_xoffset,0));
}
Real
Stem::hpos()const
{
- return pcol_->hpos + stem_xoffset;
+ return pcol_l_->hpos + stem_xoffset;
}
-void
-Stem::preprocess()
-{
- set_default_extents(); // needed for the flags.
-}