]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.26
authorfred <fred>
Sun, 24 Mar 2002 19:28:57 +0000 (19:28 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:28:57 +0000 (19:28 +0000)
hdr/register.hh [new file with mode: 0644]
hdr/request.hh
src/melodicstaff.cc
src/request.cc
src/rhythmstaff.cc

diff --git a/hdr/register.hh b/hdr/register.hh
new file mode 100644 (file)
index 0000000..e94faca
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+  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
+
index c401fcdd9d7ba709950f6641e298ae9c002b7297..2cc9decef1716d965683563a6186c162b6e53c32 100644 (file)
@@ -11,14 +11,15 @@ struct Request {
     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; }
@@ -35,17 +36,23 @@ struct Request {
     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
@@ -54,12 +61,11 @@ struct Rhythmic_req : virtual Request {
     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);
 };
 
 
@@ -68,29 +74,24 @@ struct Text_req : virtual Request {
     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;
@@ -98,19 +99,17 @@ struct Melodic_req :virtual  Request
     // 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);
+ };
 /**
 */
 
@@ -118,25 +117,20 @@ struct Note_req : Rhythmic_req, virtual Melodic_req {
 ///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 {
@@ -144,11 +138,11 @@ 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#
@@ -160,20 +154,19 @@ struct Beam_req : Span_req {
     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; }
 };
 
 
@@ -183,10 +176,8 @@ struct Script_req : Request {
     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&);
 };
@@ -199,19 +190,16 @@ struct Mark_req : Request {
     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
@@ -243,7 +231,6 @@ enum Loudness {
 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
index e533fd3143b2b4431092f87bfb37f4d57374668a..849a64b2094bbaa43441f0fdd4dcd4990afb3716 100644 (file)
@@ -6,7 +6,7 @@
 #include "paper.hh"
 #include "molecule.hh"
 #include "linepstaff.hh"
-#include "rhythmstaff.hh"
+//#include "rhythmstaff.hh"
 #include "sccol.hh" 
 #include "localkeyitem.hh"
 #include "request.hh"
@@ -25,12 +25,8 @@ Melodic_staff::set_output(PScore*ps)
 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;
 }
@@ -45,22 +41,13 @@ Melodic_staff::get_TYPESET_item(Command*com)
 }
 
 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)
 {
index c6ff787c668fd172a72e925c39e89b59d2cf1436..323932a6a9f9a9cc00b5c800c068fdba86916e31 100644 (file)
@@ -6,51 +6,50 @@
 
 #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
 }
 
@@ -65,25 +64,37 @@ Request::Request(Request const&)
 /****************/
 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;
@@ -92,9 +103,9 @@ Rhythmic_req::Rhythmic_req()
 }
 
 void
-Rhythmic_req::print() const
+Rhythmic_req::do_print() const
 {
-    mtor << "rhythmic: " << balltype ;
+    mtor << "ball: " << balltype ;
     int d =dots;
     while (d--)
        mtor << '.';
@@ -117,32 +128,41 @@ Lyric_req::Lyric_req(Text_def* def_p)
 }
 
 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;
@@ -161,7 +181,7 @@ Script_req::Script_req(Script_req const &s)
 }
 
 void
-Script_req::print() const
+Script_req::do_print() const
 {
     mtor << " dir " << dir ;
     scriptdef->print();
@@ -193,7 +213,7 @@ Text_req::Text_req(int dir_i, Text_def* tdef_p)
 }
 
 void
-Text_req::print() const
+Text_req::do_print() const
 {
     mtor << " dir " << dir_i_ ;
     tdef_p_->print();
@@ -209,10 +229,10 @@ Mark_req::Mark_req(String s)
 }
 
 void
-Mark_req::print()const
+Mark_req::do_print()const
 {
 #ifndef NDEBUG
-    mtor<< "Mark `" << mark_str_ << "\'\n";
+    mtor<< " `" << mark_str_ << "\'\n";
 #endif
 }
 /****************/
@@ -229,9 +249,8 @@ Staff_command_req::Staff_command_req(Staff_command_req const&src)
     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();
 }
 
index 5f5df7e361751a11f0008210da99dec3f4058c0b..519ea18cfa5fa7591c1f9c1390d3b5e62df790a0 100644 (file)
@@ -32,30 +32,16 @@ Rhythmic_staff::get_TYPESET_item(Command *com)
 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;
-}
-