summaryrefslogtreecommitdiff
path: root/src/lookup.cc
blob: d0ce3cb7435954df947dde61da21a3b286f61992 (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
151
152
153
154
155
156
157
158
159
160
#include "lookup.hh"
#include "debug.hh"
#include "symtable.hh"
#include "dimen.hh"
#include "tex.hh"

void
Lookup::parse(Text_db&t)
{
    symtables_->read(t) ;
}

Lookup::Lookup()
{
    symtables_ = new Symtables;
}

Lookup::~Lookup()
{
    delete symtables_;
}

Symbol
Lookup::ball(int j)
{
    if (j > 4)
	j = 4;

    Symtable * st = (*symtables_)("balls");
    return st->lookup(String(j));
}

Symbol
Lookup::rest(int j)
{
    return (*symtables_)("rests")->lookup(String(j));
}


Symbol
Lookup::bar(String s)
{
    return (*symtables_)("bars")->lookup(s);
}
 Symbol
Lookup::dots(int j)
{
    if (j>3)
	error("max 3 dots");
    return (*symtables_)("dots")->lookup(j);
}

Symbol
Lookup::flag(int j)
{
    return (*symtables_)("flags")->lookup(j);
}

Symbol
Lookup::streepjes(int i)
{
    assert(i);
    
    int arg;
    String idx ;
    if (i<0) {
	idx = "botlines";
	arg = -i;
    }else {
	arg = i;
	idx = "toplines";
    }
    Symbol ret = (*symtables_)("streepjes")->lookup(idx);
    
    svec<String> a;
    a.add(arg);
    ret.tex = substitute_args(ret.tex, a);

    return ret;
}

/****************************************************************/
// bare bones.

struct Linestaf_symbol : Parametric_symbol {
    int lines;
    Linestaf_symbol(int n, Symtables*s): Parametric_symbol(s) { lines = n;}
    Symbol eval(svec<String>)const;
};


Symbol
Linestaf_symbol::eval(svec<String> w)const
{
    Real wid = w[0].fvalue();

    Symbol s;
    s.dim.x = Interval(0,wid);
    Real dy=(lines-1)*convert_dimen(5,"pt"); // TODO!
    s.dim.y = Interval(0,dy);
    svec<String> a;
    a.add(lines);
    a.add(w[0]);
    s.tex = (*symtables_)("param")->lookup("linestaf").tex;
    s.tex = substitute_args(s.tex, a);
    return s;
}

/****************************************************************/


struct Meter_sym:Parametric_symbol {

    Meter_sym(Symtables*s) : Parametric_symbol(s){  }
    Symbol eval(svec<String> a) const{
	Symbol s;
	s.dim.x = Interval( convert_dimen(-5,"pt"),
			    convert_dimen(5,"pt"));
	s.dim.y = Interval(0, convert_dimen(10,"pt") );	// todo
	String src = (*symtables_)("param")->lookup("meter").tex;
	s.tex = substitute_args(src,a);
	return s;
    }
};
/****************************************************************/

struct Stem_sym:Parametric_symbol {

    Stem_sym(Symtables*s) : Parametric_symbol(s) {  }
    Symbol eval(svec<String> a) const {
	Real y1 = a[0].fvalue();
	Real y2 = a[1].fvalue();
	assert(y1 <= y2);
	Symbol s;
	s.dim.x = Interval(0,0);
	s.dim.y = Interval(y1,y2);

	String src = (*symtables_)("param")->lookup("stem").tex;
	s.tex = substitute_args(src,a);
	return s;
    }
};

Parametric_symbol *
Lookup::meter(String )
{
    return new Meter_sym(symtables_);
}

Parametric_symbol *
Lookup::linestaff(int n)
{
    return new Linestaf_symbol(n,symtables_);
}

Parametric_symbol*
Lookup::stem()
{
    return new Stem_sym(symtables_);
}