]> git.donarmstrong.com Git - lilypond.git/blob - rhythmstaf.cc
61eca843f807f410ced7ea95bd967664813f02a4
[lilypond.git] / rhythmstaf.cc
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
11  
12
13 Rhythmic_column::Rhythmic_column(Score_column*s, Rhythmic_staff *rs)
14     : Staff_column(s)
15 {
16     the_note = 0;
17     staff_ = rs;
18 }
19
20
21 void
22 Rhythmic_staff::set_output(PScore* ps )
23 {
24     theline = new Linestaff(1);
25     pscore_ = ps;
26     pscore_->add(theline);
27 }
28
29 // should integrate handling of BREAK commands into Staff_column
30 void
31 Rhythmic_column::process_commands( )
32 {
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;
46             
47         case TYPESET:
48             typeset_command ( com , breakstat);
49             break;
50         default :
51             break;
52         }
53         
54     }
55 }
56 /**
57  accept:
58
59     BREAK: all
60     TYPESET: bar, meter
61
62     */
63
64
65
66 void
67 Rhythmic_column::process_requests()
68 {
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             switch(rq->tag){
73             case Request::NOTE:
74             case Request::REST:
75                 if (the_note){
76                     WARN << "too many notes.\n";
77                     return;
78                 }
79                 the_note = rq;
80                 break;
81                 
82             default:
83                 return;
84             }
85         }
86     
87 }
88
89
90 void
91 Rhythmic_column::typeset_command(Command *com, int breakst)
92 {
93     Item *i = new Item;
94     const Symbol*s=0;
95
96     if (com -> args[0] ==  "|" ) {
97         s = Symbol::find_bar("|");      
98     } else
99         assert(false);
100     
101     i->output=new Molecule(Atom(s));
102     staff_->pscore_->typeset_item(i, score_column->pcol,
103                                   staff_->theline,breakst);
104 }
105
106 void
107 Rhythmic_column::typeset_req(Request *rq)
108 {
109     Item *i = new Item;
110     const Symbol*s=0;
111
112     switch(rq->tag){
113     case Request::NOTE:
114         s = Symbol::find_ball(rq->note()->balltype);
115         break;
116     case Request::REST:
117         s = Symbol::find_rest(rq->rest()->balltype);
118         break;
119     default:
120         assert(false);
121         break;
122     }  
123     i->output = new Molecule(Atom(s));
124
125     staff_->pscore_->typeset_item(i, score_column->pcol, staff_->theline,0 );   
126 }
127
128 void
129 Rhythmic_staff::grant_requests()
130 {
131     for  (PCursor<Staff_column*> cc(cols); cc.ok(); cc++) {
132         Rhythmic_column *rp = (Rhythmic_column*)*cc;
133         if (rp->the_note)
134             rp->typeset_req( rp->the_note);
135     }
136 }
137
138 Staff_column*
139 Rhythmic_staff::create_col(Score_column*s)
140 {
141     Rhythmic_column *rc = new Rhythmic_column(s,this);
142
143     return rc;
144 }
145
146 Staff *
147 get_new_rhythmstaff()
148 {
149     return new Rhythmic_staff;
150 }