]> git.donarmstrong.com Git - lilypond.git/blob - lily/clef-item.cc
release: 0.1.59
[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 <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"
16
17
18 void
19 Clef_item::do_pre_processing()
20 {
21   change_b_ = ! (break_status_i() == 1);
22
23   if (default_b_)
24     {
25       set_empty(break_status_i() != 1);
26       transparent_b_ = (break_status_i() != 1);
27     }
28 }
29
30 Clef_item::Clef_item()
31 {
32   breakable_b_ =true;
33   default_b_ = false;
34   change_b_ = true;
35   read ("violin");
36 }
37
38 /*
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.
43  */
44 void
45 Clef_item::read (String t)
46 {
47   symbol_= t;
48   if (t == "violin") 
49     {
50       y_position_i_ = -2;
51     }
52   else if (t == "bass") 
53     {
54       y_position_i_ = 2;
55     }
56   else if (t == "G" || t == "G2" || t == "treble")
57     {
58       symbol_ = "violin";
59       y_position_i_ = -2;
60     }
61   else if (t == "french" || t == "G1") 
62     {
63       symbol_="violin";
64       y_position_i_ = -4;
65     }
66   else if (t == "soprano" || t == "C1") 
67     {
68       symbol_="alto";
69       y_position_i_ = -4;
70     }
71   else if (t == "mezzosoprano" || t == "C2")
72     {
73       symbol_ = "alto";
74       y_position_i_ = -2;
75     }
76   else if (t == "alto") 
77     {
78       symbol_ = "alto";
79       y_position_i_ = 0;
80     }
81   else if (t == "C3")
82     {
83       symbol_ = "alto";
84       y_position_i_ = 0;
85   }
86   else if (t == "tenor" || t == "C4") 
87   {
88       symbol_ = "alto";
89       y_position_i_ = 2;
90     }
91   else if (t == "baritone" || t == "C5")
92     {
93       symbol_ = "alto";
94       y_position_i_ = 4;
95     }
96   else if (t == "varbaritone" || t == "F3")
97     {
98       symbol_ = "bass";
99       y_position_i_ = 0;
100     }
101   else if (t == "F" || t == "F4")
102     {
103       symbol_ = "bass";
104       y_position_i_ = 2;
105     }
106   else if (t == "subbass")
107     {
108       symbol_ = "bass";
109       y_position_i_ = 4;
110     }
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;
125           }
126 }
127
128 void
129 Clef_item::read (Clef_engraver const &k)
130 {
131   read (k.clef_type_str_);
132 }
133
134 Molecule*
135 Clef_item::brew_molecule_p() const
136 {
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;
144 }
145
146
147 IMPLEMENT_IS_TYPE_B1(Clef_item,Item);