lilypond-0.0.5
[lilypond.git] / rhythmstaf.cc
blobd2a85d62cee60f9ceb7d0fe5b0b0554ddd129dfc
1 #include "request.hh"
2 #include "debug.hh"
3 #include "linestaff.hh"
4 #include "staff.hh"
5 #include "pstaff.hh"
6 #include "pscore.hh"
7 #include "command.hh"
8 #include "molecule.hh"
9 #include "rhythmstaf.hh"
10 #include "lookupsyms.hh"
11 #include "sccol.hh"
13 Rhythmic_column::Rhythmic_column(Score_column*s, Rhythmic_staff *rs)
14 : Staff_column(s)
16 the_note = 0;
17 staff_ = rs;
21 void
22 Rhythmic_staff::set_output(PScore* ps )
24 theline = new Linestaff(1);
25 pscore_ = ps;
26 pscore_->add(theline);
29 // should integrate handling of BREAK commands into Staff_column
30 void
31 Rhythmic_column::process_commands( )
33 int breakstat = BREAK_END;
34 for (int i = 0 ; i < s_commands.sz(); i++) {
35 Command *com = s_commands[i];
36 switch (com->code){
37 case INTERPRET:
38 break;
39 case BREAK_PRE:
40 case BREAK_MIDDLE:
41 case BREAK_POST:
42 case BREAK_END:
43 score_column->set_breakable();
44 breakstat = com->code;
45 break;
47 case TYPESET:
48 typeset_command ( com , breakstat);
49 break;
50 default :
51 break;
56 /**
57 accept:
59 BREAK: all
60 TYPESET: bar, meter
66 void
67 Rhythmic_column::process_requests()
69 for (int i = 0 ; i < v_elts.sz(); i ++)
70 for (PCursor<Request *> rqc(v_elts[i]->reqs); rqc.ok(); rqc++) {
71 Request *rq= rqc;
72 if (rq->rhythmic()){
73 if (the_note){
74 WARN << "too many notes.\n";
75 return;
77 the_note = rq;
79 break;
85 void
86 Rhythmic_column::typeset_command(Command *com, int breakst)
88 Item *i = new Item;
89 Symbol s;
91 if (com -> args[0] == "BAR" ) {
92 s = Lookup::bar(com->args[1]);
93 } else if (com->args[0] == "METER") {
94 Parametric_symbol *p = Lookup::meter("general");
95 svec<String> arg( com->args);
96 arg.del(0);
97 s = p->eval(arg);
98 } else
99 assert(false);
101 Molecule * m =new Molecule(Atom(s));
103 Interval wid;
104 svec<Item*> sv(staff_->pscore_->
105 select_items(staff_->theline, score_column->pcol));
106 for (int j=0; j<sv.sz(); j++) {
107 wid.unite(sv[j]->output->extent().x);
109 if (!wid.empty())
110 m->translate(Offset(wid.max,0));
112 i->output=m;
113 staff_->pscore_->typeset_item(i, score_column->pcol,
114 staff_->theline,breakst);
117 void
118 Rhythmic_column::typeset_req(Request *rq)
120 Item *i = new Item;
121 Symbol s;
122 int dots=0;
124 if (rq->note())
125 s = Lookup::ball(rq->note()->balltype);
126 if (rq->rhythmic())
127 dots=rq->rhythmic()->dots;
128 if (rq->rest())
129 s = Lookup::rest(rq->rest()->balltype);
131 Molecule *m = new Molecule(Atom(s));
132 if (dots) {
133 Symbol d = Lookup::dots(dots);
134 Molecule dm;
135 dm.add(Atom(d));
136 m->add_right(dm);
138 i->output=m;
139 staff_->pscore_->typeset_item(i, score_column->pcol, staff_->theline,0 );
142 void
143 Rhythmic_staff::grant_requests()
145 for (PCursor<Staff_column*> cc(cols); cc.ok(); cc++) {
146 Rhythmic_column *rp = (Rhythmic_column*)*cc;
147 if (rp->the_note)
148 rp->typeset_req( rp->the_note);
152 Staff_column*
153 Rhythmic_staff::create_col(Score_column*s)
155 Rhythmic_column *rc = new Rhythmic_column(s,this);
157 return rc;
160 Staff *
161 get_new_rhythmstaff()
163 return new Rhythmic_staff;