--- /dev/null
+/*
+ register.hh -- part of LilyPond
+
+ (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef REGISTER_HH
+#define REGISTER_HH
+#include "proto.hh"
+#include "sstack.hh"
+
+/// data container.
+struct Staff_elem_info {
+ Staff_elem * elem_p_;
+// Array<const Request*> requestor_l_arr_;
+ Request*req_l_;
+ const Voice * voice_l_;
+ Voice_group_registers * group_regs_l_;
+ int group;
+ Request_register * origin_reg_l_;
+
+ /****/
+ Staff_elem_info(Staff_elem*, Request*, Request_register*);
+ Staff_elem_info();
+};
+
+/// Hungarian postfix: reg
+struct Request_register {
+ Complex_walker * walk_l_;
+ Array<Request*> accepted_req_arr_;
+
+ /****************/
+
+ Request_register(Complex_walker*);
+ Request_register();
+ virtual ~Request_register(){}
+
+ /// take note of item/spaanner
+ virtual void acknowledge_element(Staff_elem_info){}
+ /**
+ put item in spanner. Adjust local key; etc.
+ */
+
+ ///
+ virtual bool try_request(Request *req_l) =0;
+ /**
+ try to fit the request in this register
+
+ RETURN
+ false: request noted, but not taken.
+
+ true: request swallowed, now owned by this
+
+ (may be we could use C++ exceptions.. :-)
+ */
+
+ /// make items/spanners with the requests you got
+ virtual void process_request()=0;
+
+ /// typeset any spanners. Empty accepted_req_arr_
+ void pre_move_processing();
+ void post_move_processing();
+
+protected:
+ /// virtual, called by pre_move_process()
+ virtual void do_pre_move_process(){}
+ virtual void do_post_move_process(){}
+};
+/**
+ a struct which processes requests, and creates the Staff_elems
+ */
+
+struct Notehead_register : Request_register {
+ Item* note_l_;
+ /****************/
+ Notehead_register(Complex_walker*);
+ virtual bool try_request(Request *req_l) ;
+ virtual void process_request();
+ virtual void do_pre_move_process();
+};
+
+struct Slur_register : Request_register {
+ sstack<Slur *> slur_l_stack_;
+ Array<Slur*> end_slur_l_arr_;
+
+
+ /****************/
+ ~Slur_register();
+ Slur_register(Complex_walker*);
+ virtual bool try_request(Request*);
+ virtual void process_request();
+ virtual void acknowledge_element(Staff_elem_info);
+ virtual void do_pre_move_process();
+};
+
+struct Stem_beam_register : Request_register {
+ Stem * stem_p_;
+ Beam * beam_p_;
+ Beam_req * beam_req_l_;
+ Stem_req * stem_req_l_;
+ bool end_beam_b_;
+ Rhythmic_grouping *current_grouping;
+
+ /****************/
+ Stem_beam_register(Complex_walker*);
+ ~Stem_beam_register();
+ virtual bool try_request(Request*);
+ virtual void process_request();
+ virtual void acknowledge_element(Staff_elem_info);
+ virtual void do_pre_move_process();
+ virtual void do_post_move_process();
+};
+
+#if 0
+struct Script_register : Request_register {
+ Script * script_p_;
+ /****************/
+ Script_register(Complex_walker*);
+ virtual bool try_request(Request*);
+ virtual void process_request();
+ virtual void acknowledge_element(Staff_elem_info);
+ virtual void do_pre_move_process();
+};
+
+struct Text_register:Request_register{
+ Text_item * text_p_;
+
+ /****************/
+ Text_register(Complex_walker*);
+ virtual bool try_request(Request*);
+ virtual void process_request();
+ virtual void acknowledge_element(Staff_elem_info);
+ virtual void do_pre_move_process();
+};
+#endif
+
+struct Local_key_register : Request_register {
+ Local_key_item* key_item_p_;
+
+ /****************/
+
+ virtual bool try_request(Request*);
+ virtual void process_request();
+ virtual void acknowledge_element(Staff_elem_info);
+ virtual void do_pre_move_process();
+ Local_key_register(Complex_walker*);
+};
+
+#endif // REGISTER_HH
+
Voice_element*elt_l_;
/****************/
-
Request();
Request(Request const&);
virtual ~Request(){}
- virtual void print()const ;
- virtual Moment duration() const { return 0.0; }
+ virtual const char * name() const { return "Request";}
virtual Request* clone() const =0;
+ void print()const ;
+
+ virtual Moment duration() const { return 0; }
/* accessors for children */
virtual Barcheck_req *barcheck() { return 0; }
virtual Melodic_req *melodic() { return 0; }
virtual Mark_req * mark() { return 0; }
virtual Staff_command_req* command() { return 0;}
+protected:
+ virtual void do_print()const ;
};
-
/**
a voice element wants something printed.
see lilygut page
*/
+
+
+#define REQUESTMETHODS(T,accessor) \
+virtual T * accessor() { return this;}\
+virtual const char* name()const { return #T; }\
+virtual Request *clone() const { return new T(*this); } \
+virtual void do_print() const
struct Barcheck_req : Request {
- virtual Barcheck_req *barcheck() { return this; }
- void print ()const;
- Request*clone() const;
+ REQUESTMETHODS(Barcheck_req,barcheck);
};
/// a request with a duration
int dots;
Moment plet_factor;
/****************/
-
+ static int compare(const Rhythmic_req &, const Rhythmic_req &);
Moment duration() const;
Rhythmic_req();
- Rhythmic_req*rhythmic() { return this;}
- void print ()const;
- Request*clone() const;
+ Rhythmic_req(int,int);
+ REQUESTMETHODS(Rhythmic_req, rhythmic);
};
int dir_i_;
Text_def *tdef_p_;
/****************/
- Text_req* text() { return this; }
- virtual void print() const;
- Request *clone()const;
-
Text_req(int d, Text_def*);
~Text_req();
Text_req(Text_req const&);
+ REQUESTMETHODS(Text_req,text);
};
struct Lyric_req : public Rhythmic_req, Text_req {
Lyric_req(Text_def* t_p);
- void print() const;
- Lyric_req* lreq_l() { return this; }
- Request* clone() const;
+ REQUESTMETHODS(Lyric_req, lreq_l);
};
struct Melodic_req :virtual Request
{
/// 0 is c
- int name;
+ int notename;
int octave;
int accidental;
bool forceacc;
// return height from central c (in halflines)
int height()const;
Melodic_req();
- Melodic_req*melodic() { return this;}
- virtual void print() const;
- Request*clone() const;
+
+ REQUESTMETHODS(Melodic_req,melodic);
};
/// Put a note of specified type, height, and with accidental on the staff.
struct Note_req : Rhythmic_req, virtual Melodic_req {
- Rhythmic_req* rhythmic() { return Rhythmic_req::rhythmic(); }
- Note_req*note() { return this;}
- virtual void print() const;
- Request*clone() const;
-};
+
+ Rhythmic_req* rhythmic() { return Rhythmic_req::rhythmic(); }
+ REQUESTMETHODS(Note_req, note);
+ };
/**
*/
///Put a rest on the staff.
struct Rest_req : Rhythmic_req {
- void print()const;
-
- Rest_req * rest() { return this;}
- Request*clone() const ;
+ REQUESTMETHODS(Rest_req,rest);
};
/**
Why a request? It might be a good idea to not typeset the rest, if the paper is too crowded.
*/
/// attach a stem to the noteball
-struct Stem_req : Request {
- /// 4,8,16, ..
- int stem_number;
-
- virtual Stem_req *stem() {return this;}
- Stem_req(int s) { stem_number = s; }
- Request*clone() const;
- virtual void print() const;
+struct Stem_req : Rhythmic_req {
+ Stem_req(int s, int dots);
+ REQUESTMETHODS(Stem_req,stem);
};
+/**
+ Rhythmic_req parent needed to determine if it will fit inside a beam.
+ */
/// requests to start or stop something.
struct Span_req : Request {
enum {
NOSPAN, START, STOP
} spantype ;
+ static int compare(const Span_req &r1, const Span_req &r2);
+ REQUESTMETHODS(Span_req,span);
- virtual void print() const;
- Span_req*span() { return this; }
Span_req();
- virtual Request*clone()const;
+
};
/**
This type of request typically results in the creation of a #Spanner#
int nplet;
/****************/
-
+ REQUESTMETHODS(Beam_req,beam);
+
Beam_req();
- virtual Beam_req * beam() { return this; }
- virtual Request*clone()const;
};
+
/** if #nplet# is set, the staff will try to put an
appropriate number over the beam
*/
/// a slur
struct Slur_req : Span_req {
+ REQUESTMETHODS(Slur_req,slur);
- virtual Request*clone()const;
- virtual Slur_req*slur() { return this; }
};
Script_def *scriptdef;
/****************/
- Script_req*script() { return this; }
- virtual void print() const;
- Request *clone()const;
Script_req(int d, Script_def*);
+ REQUESTMETHODS(Script_req,script);
~Script_req();
Script_req(Script_req const&);
};
String mark_str_;
/****************/
Mark_req(String);
- Mark_req* mark() { return this; }
- virtual void print() const;
- Request *clone() const;
+ REQUESTMETHODS(Mark_req,mark);
};
struct Staff_command_req : Request {
Input_command * com_p_;
- Staff_command_req* command() { return this;}
+ /****************/
Staff_command_req(Staff_command_req const&);
~Staff_command_req();
Staff_command_req(Input_command*);
- Request*clone()const;
- void print()const;
+ REQUESTMETHODS(Staff_command_req,command);
};
#if 0
struct Bracket_req : Span_req {
int nplet; // print a number over the beam.
};
-
/**
Start/stop a bracket at this note. if #nplet# is set, the staff will
try to put an appropriate number over the bracket
#include "paper.hh"
#include "molecule.hh"
#include "linepstaff.hh"
-#include "rhythmstaff.hh"
+//#include "rhythmstaff.hh"
#include "sccol.hh"
#include "localkeyitem.hh"
#include "request.hh"
Notehead*
Melodic_staff::get_notehead(Note_req *rq, int bottom)
{
- int b = rq->rhythmic()->balltype;
- int d = rq->rhythmic()->dots;
-
Notehead *n =new Notehead((NO_LINES-1)*2);
- n->balltype =b;
- n->dots = d;
+ n->set_rhythmic(rq->rhythmic());
n->position = rq->note()->height() + bottom;
return n;
}
}
Stem *
-Melodic_staff::get_stem(Stem_req*rq, Moment dur)
+Melodic_staff::get_stem(Stem_req*rq)
{
- Stem * s = new Stem(NO_LINES-1, dur);
- s->flag = rq->stem_number;
+ Stem * s = new Stem(NO_LINES-1);
+ s->flag = rq->balltype;
return s;
}
-/*
- creation
- */
-Staff *
-get_new_melodicstaff()
-{
- return new Melodic_staff;
-}
-
Rest*
Melodic_staff::get_rest(Rest_req*rq)
{
#include "inputcommand.hh"
-#define VIRTUALCONS(T,R) R *T::clone() const { return new T(*this); } struct T
-#define RCONS(T) VIRTUALCONS(T, Request)
-
-RCONS(Rest_req);
-RCONS(Barcheck_req);
-RCONS(Text_req);
-RCONS(Rhythmic_req);
-RCONS(Lyric_req);
-RCONS(Mark_req);
-RCONS(Stem_req);
-RCONS(Script_req);
-RCONS(Note_req);
-RCONS(Melodic_req);
-RCONS(Span_req);
-RCONS(Slur_req);
-RCONS(Beam_req);
-RCONS(Staff_command_req);
-
void
-Stem_req::print() const
+Stem_req::do_print() const
+{
+ Rhythmic_req::do_print();
+}
+
+Stem_req::Stem_req(int s, int d)
+ : Rhythmic_req(s,d)
{
- mtor << "Stem\n";
}
+
/****************/
void
-Barcheck_req::print() const
+Barcheck_req::do_print() const
{
#ifndef NPRINT
- mtor << "Barcheck\n";
+
#endif
}
+
/****************/
+
void
-Request::print() const
+Request::print() const
+
+{
+ mtor << name() << " {";
+ do_print();
+ mtor << "}\n";
+}
+
+
+void
+Request::do_print() const
{
#ifndef NPRINT
- mtor << "Req{ unknown }\n";
#endif
}
void
-Span_req::print() const
+Span_req::do_print() const
{
#ifndef NPRINT
- mtor << "Span_req {" << spantype << "}\n";
+ mtor << spantype ;
#endif
}
/****************/
Melodic_req::Melodic_req()
{
- name = 0;
+ notename = 0;
octave = 0;
accidental = 0;
forceacc = false;
}
void
-Melodic_req::print() const
+Melodic_req::do_print() const
{
- mtor << "note: " << name << " oct: "<< octave;
+ mtor << "notename: " << notename << " oct: "<< octave;
}
int
Melodic_req::height() const
{
- return name + octave*7;
+ return notename + octave*7;
}
/****************/
+int
+Rhythmic_req::compare(const Rhythmic_req &r1, const Rhythmic_req &r2)
+{
+ return r1.duration() - r2.duration();
+}
+Rhythmic_req::Rhythmic_req(int b, int d)
+{
+ plet_factor = 1;
+ balltype = b;
+ dots = d;
+}
+
Rhythmic_req::Rhythmic_req()
{
plet_factor = 1;
}
void
-Rhythmic_req::print() const
+Rhythmic_req::do_print() const
{
- mtor << "rhythmic: " << balltype ;
+ mtor << "ball: " << balltype ;
int d =dots;
while (d--)
mtor << '.';
}
void
-Lyric_req::print() const
-{
- mtor << "lyric: ";
- Rhythmic_req::print();
- Text_req::print();
+Lyric_req::do_print() const
+{
+ Rhythmic_req::do_print();
+ Text_req::do_print();
}
/****************/
void
-Note_req::print() const
+Note_req::do_print() const
{
- Melodic_req::print();
- Rhythmic_req::print();
+ Melodic_req::do_print();
+ Rhythmic_req::do_print();
}
/****************/
void
-Rest_req::print() const
+Rest_req::do_print() const
{
- mtor << "rest, " ;
- Rhythmic_req::print();
+ Rhythmic_req::do_print();
}
+
/****************/
Beam_req::Beam_req()
{
nplet = 0;
}
+
+void Beam_req::do_print()const{}
/****************/
+void Slur_req::do_print()const{}
+/****************/
+int
+Span_req:: compare(const Span_req &r1, const Span_req &r2)
+{
+ return r1.spantype - r2.spantype;
+}
+
Span_req::Span_req()
{
spantype = NOSPAN;
}
void
-Script_req::print() const
+Script_req::do_print() const
{
mtor << " dir " << dir ;
scriptdef->print();
}
void
-Text_req::print() const
+Text_req::do_print() const
{
mtor << " dir " << dir_i_ ;
tdef_p_->print();
}
void
-Mark_req::print()const
+Mark_req::do_print()const
{
#ifndef NDEBUG
- mtor<< "Mark `" << mark_str_ << "\'\n";
+ mtor<< " `" << mark_str_ << "\'\n";
#endif
}
/****************/
com_p_ = new Input_command(*src.com_p_);
}
void
-Staff_command_req::print()const
+Staff_command_req::do_print()const
{
- mtor << "Command request: " ;
com_p_->print();
}
Notehead*
Rhythmic_staff::get_notehead(Note_req *rq, int)
{
- int b = rq->rhythmic()->balltype;
- int d = rq->rhythmic()->dots;
-
Notehead *n =new Notehead(1);
- n->balltype = b;
- n->dots =d;
+ n->set_rhythmic(rq->rhythmic());
n->position = 0;
return n;
}
Stem *
-Rhythmic_staff::get_stem(Stem_req*rq, Moment l)
+Rhythmic_staff::get_stem(Stem_req*rq)
{
- Stem * s = new Stem(0,l);
- s->flag = rq->stem_number;
+ Stem * s = new Stem(0);
+ s->flag = rq->balltype;
return s;
}
-
-/*
- creation
- */
-Staff *
-get_new_rhythmstaff()
-{
- return new Rhythmic_staff;
-}
-