summaryrefslogtreecommitdiff
path: root/rhythmstaf.cc
blob: a7fade6fc5f487378434f554eab1f7c59798f18c (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "request.hh"
#include "debug.hh"
#include "linestaff.hh"
#include "staff.hh"
#include "pstaff.hh"
#include "pscore.hh"
#include "command.hh"
#include "molecule.hh"
#include "rhythmstaf.hh"
#include "symbol.hh"
 

Rhythmic_column::Rhythmic_column(Score_column*s, Rhythmic_staff *rs)
    : Staff_column(s)
{
    the_note = 0;
    staff_ = rs;
}


void
Rhythmic_staff::set_output(PScore* ps )
{
    theline = new Linestaff(1);
    pscore_ = ps;
    pscore_->add(theline);
}

// should integrate handling of BREAK commands into Staff_column
void
Rhythmic_column::process_commands( )
{
    int breakstat = BREAK_END;
    for (int i = 0 ; i < s_commands.sz(); i++) {
	Command *com = s_commands[i];
	switch (com->code){
	case INTERPRET:
	    break;
	case BREAK_PRE:
	case BREAK_MIDDLE:
	case BREAK_POST:
	case BREAK_END:
	    score_column->set_breakable();
	    breakstat = com->code;
	    break;
	    
	case TYPESET:
	    typeset_command ( com , breakstat);
	    break;
	default :
	    break;
	}
	
    }
}
/**
 accept:

    BREAK: all
    TYPESET: bar, meter

    */



void
Rhythmic_column::process_requests()
{
    for (int i = 0 ; i < v_elts.sz(); i ++)
	for (PCursor<Request *> rqc(v_elts[i]->reqs); rqc.ok(); rqc++) {
	    Request *rq= rqc;
	    switch(rq->tag){
	    case Request::NOTE:
	    case Request::REST:
		if (the_note){
		    WARN << "too many notes.\n";
		    return;
		}
		the_note = rq;
		break;
		
	    default:
		return;
	    }
	}
    
}


void
Rhythmic_column::typeset_command(Command *com, int breakst)
{
    Item *i = new Item;
    const Symbol*s=0;

    if (com -> args[0] ==  "BAR" ) {
	s = Symbol::find_bar(com->args[1]);	
    } else
	assert(false);
    
    i->output=new Molecule(Atom(s));
    staff_->pscore_->typeset_item(i, score_column->pcol,
				  staff_->theline,breakst);
}

void
Rhythmic_column::typeset_req(Request *rq)
{
    Item *i = new Item;
    const Symbol*s=0;

    switch(rq->tag){
    case Request::NOTE:
	s = Symbol::find_ball(rq->note()->balltype);
	break;
    case Request::REST:
	s = Symbol::find_rest(rq->rest()->balltype);
	break;
    default:
	assert(false);
	break;
    }  
    i->output = new Molecule(Atom(s));

    staff_->pscore_->typeset_item(i, score_column->pcol, staff_->theline,0 );	
}

void
Rhythmic_staff::grant_requests()
{
    for  (PCursor<Staff_column*> cc(cols); cc.ok(); cc++) {
	Rhythmic_column *rp = (Rhythmic_column*)*cc;
	if (rp->the_note)
	    rp->typeset_req( rp->the_note);
    }
}

Staff_column*
Rhythmic_staff::create_col(Score_column*s)
{
    Rhythmic_column *rc = new Rhythmic_column(s,this);

    return rc;
}

Staff *
get_new_rhythmstaff()
{
    return new Rhythmic_staff;
}