lilypond-0.1.59
[lilypond.git] / lily / clef-item.cc
blob0d1a185923be893a1f6285b01b96f221f6f32f7c
1 /*
2 clef-item.cc -- implement Clef_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include <ctype.h>
10 #include "clef-item.hh"
11 #include "string.hh"
12 #include "molecule.hh"
13 #include "paper-def.hh"
14 #include "lookup.hh"
15 #include "clef-grav.hh"
18 void
19 Clef_item::do_pre_processing()
21 change_b_ = ! (break_status_i() == 1);
23 if (default_b_)
25 set_empty(break_status_i() != 1);
26 transparent_b_ = (break_status_i() != 1);
30 Clef_item::Clef_item()
32 breakable_b_ =true;
33 default_b_ = false;
34 change_b_ = true;
35 read ("violin");
39 * Convert input clef string to
40 * a clef symbol and a line position.
41 * This would be better done in the lexer (more efficient)
42 * or as a table-lookup.
44 void
45 Clef_item::read (String t)
47 symbol_= t;
48 if (t == "violin")
50 y_position_i_ = -2;
52 else if (t == "bass")
54 y_position_i_ = 2;
56 else if (t == "G" || t == "G2" || t == "treble")
58 symbol_ = "violin";
59 y_position_i_ = -2;
61 else if (t == "french" || t == "G1")
63 symbol_="violin";
64 y_position_i_ = -4;
66 else if (t == "soprano" || t == "C1")
68 symbol_="alto";
69 y_position_i_ = -4;
71 else if (t == "mezzosoprano" || t == "C2")
73 symbol_ = "alto";
74 y_position_i_ = -2;
76 else if (t == "alto")
78 symbol_ = "alto";
79 y_position_i_ = 0;
81 else if (t == "C3")
83 symbol_ = "alto";
84 y_position_i_ = 0;
86 else if (t == "tenor" || t == "C4")
88 symbol_ = "alto";
89 y_position_i_ = 2;
91 else if (t == "baritone" || t == "C5")
93 symbol_ = "alto";
94 y_position_i_ = 4;
96 else if (t == "varbaritone" || t == "F3")
98 symbol_ = "bass";
99 y_position_i_ = 0;
101 else if (t == "F" || t == "F4")
103 symbol_ = "bass";
104 y_position_i_ = 2;
106 else if (t == "subbass")
108 symbol_ = "bass";
109 y_position_i_ = 4;
111 else if (isdigit(t[1]))
112 switch (t[0])
113 { // we've already dealt with plain F, G or C clef
114 // position 0 is line 3.
115 case 'G':
116 case 'g':
117 symbol_ = "violin";
118 y_position_i_ = 2 * (t[1] - '0') - 6;
119 break;
120 case 'F':
121 case 'f':
122 symbol_ = "bass";
123 y_position_i_ = 2 * (t[1] - '0') - 6;
124 break;
128 void
129 Clef_item::read (Clef_engraver const &k)
131 read (k.clef_type_str_);
134 Molecule*
135 Clef_item::brew_molecule_p() const
137 String t = symbol_;
138 if (change_b_)
139 t += "_change";
140 Atom s = paper()->lookup_l ()->clef (t);
141 Molecule*output = new Molecule (Atom (s));
142 output->translate_axis (paper()->internote_f () * y_position_i_, Y_AXIS);
143 return output;
147 IMPLEMENT_IS_TYPE_B1(Clef_item,Item);