]> git.donarmstrong.com Git - lilypond.git/blob - lily/clef-item.cc
0c5c56eb2241bf654451f09132ac829c88f97261
[lilypond.git] / lily / clef-item.cc
1 /*
2   clef-item.cc -- implement Clef_item
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "clef-item.hh"
10 #include "string.hh"
11 #include "molecule.hh"
12 #include "paper-def.hh"
13 #include "lookup.hh"
14 #include "clef-grav.hh"
15
16
17 void
18 Clef_item::do_pre_processing()
19 {
20   change_b_ = ! (break_status_i() == 1);
21
22   if (default_b_)
23     {
24       set_empty(break_status_i() != 1);
25       transparent_b_ = (break_status_i() != 1);
26     }
27 }
28
29 Clef_item::Clef_item()
30 {
31   breakable_b_ =true;
32   default_b_ = false;
33   change_b_ = true;
34   read ("violin");
35 }
36
37 /*
38  * Convert input clef string to 
39  * a clef symbol and a line position.
40  * This would be better done in the lexer (more efficient)
41  * or as a table-lookup.
42  */
43 void
44 Clef_item::read (String t)
45 {
46   symbol_= t;
47   if (t == "violin") 
48     {
49       y_position_i_ = -2;
50     }
51   else if (t == "bass") 
52     {
53       y_position_i_ = 2;
54     }
55   else if (t == "G" || t == "G2" || t == "treble")
56     {
57       symbol_ = "violin";
58       y_position_i_ == -2;
59     }
60   else if (t == "french" || t == "G1") 
61     {
62       symbol_="violin";
63       y_position_i_ = -4;
64     }
65   else if (t == "soprano" || t == "C1") 
66     {
67       symbol_="alto";
68       y_position_i_ = -4;
69     }
70   else if (t == "mezzosoprano" || t == "C2")
71     {
72       symbol_ = "alto";
73       y_position_i_ = -2;
74     }
75   else if (t == "alto") 
76     {
77       symbol_ = "alto";
78       y_position_i_ = 0;
79     }
80   else if (t == "C3")
81     {
82       symbol_ = "alto";
83       y_position_i_ = 0;
84   }
85   else if (t == "tenor" || t == "C4") 
86   {
87       symbol_ = "alto";
88       y_position_i_ = 2;
89     }
90   else if (t == "baritone" || t == "C5")
91     {
92       symbol_ = "alto";
93       y_position_i_ = 4;
94     }
95   else if (t == "varbaritone" || t == "F3")
96     {
97       symbol_ = "bass";
98       y_position_i_ = 0;
99     }
100   else if (t == "F" || t == "F4")
101     {
102       symbol_ = "bass";
103       y_position_i_ = 2;
104     }
105   else if (t == "subbass")
106     {
107       symbol_ = "bass";
108       y_position_i_ = 4;
109     }
110   else if (isdigit(t[1]))
111           switch (t[0])
112           { // we've already dealt with plain F, G  or C clef 
113                   // position 0 is line 3.        
114           case 'G':
115           case 'g':
116                   symbol_ = "violin";
117                   y_position_i_ =   2 * (t[1] - '0') - 6;
118                   break;
119           case 'F':
120           case 'f':
121                   symbol_ = "bass";
122                   y_position_i_ = 2 * (t[1] - '0') - 6;
123                   break;
124           }
125 }
126
127 void
128 Clef_item::read (Clef_engraver const &k)
129 {
130   read (k.clef_type_str_);
131 }
132
133 Molecule*
134 Clef_item::brew_molecule_p() const
135 {
136   String t = symbol_;
137   if  (change_b_)
138     t += "_change";
139   Atom s = paper()->lookup_l ()->clef (t);
140   Molecule*output = new Molecule (Atom (s));
141   output->translate_axis (paper()->internote_f () * y_position_i_, Y_AXIS);
142   return output;
143 }
144
145
146 IMPLEMENT_IS_TYPE_B1(Clef_item,Item);