]> git.donarmstrong.com Git - lilypond.git/blob - lily/clef-item.cc
234b85fbb4af1963ba0466d896e7f5903255bc42
[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--1998 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 #include "text-item.hh"
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   octave_dir_ = CENTER;
36   read ("violin");
37   // Ugh: This should be const, I guess.
38   octave_marker_td_p_ = new Text_def();
39   octave_marker_td_p_->text_str_ = "8";
40   octave_marker_td_p_->style_str_ = "italic";
41 }
42
43 /*
44  * Convert input clef string to 
45  * a clef symbol and a line position.
46  * This would be better done in the lexer (more efficient)
47  * or as a table-lookup.
48  */
49 void
50 Clef_item::read (String t)
51 {
52   symbol_= t;
53   if (t == "violin") 
54     {
55       y_position_i_ = -2;
56     }
57   else if (t == "bass") 
58     {
59       y_position_i_ = 2;
60     }
61   else if (t == "G" || t == "G2" || t == "treble")
62     {
63       symbol_ = "violin";
64       y_position_i_ = -2;
65     }
66   else if (t == "french" || t == "G1") 
67     {
68       symbol_="violin";
69       y_position_i_ = -4;
70     }
71   else if (t == "soprano" || t == "C1") 
72     {
73       symbol_="alto";
74       y_position_i_ = -4;
75     }
76   else if (t == "mezzosoprano" || t == "C2")
77     {
78       symbol_ = "alto";
79       y_position_i_ = -2;
80     }
81   else if (t == "alto") 
82     {
83       symbol_ = "alto";
84       y_position_i_ = 0;
85     }
86   else if (t == "C3")
87     {
88       symbol_ = "alto";
89       y_position_i_ = 0;
90   }
91   else if (t == "tenor" || t == "C4") 
92   {
93       symbol_ = "alto";
94       y_position_i_ = 2;
95     }
96   else if (t == "baritone" || t == "C5")
97     {
98       symbol_ = "alto";
99       y_position_i_ = 4;
100     }
101   else if (t == "varbaritone" || t == "F3")
102     {
103       symbol_ = "bass";
104       y_position_i_ = 0;
105     }
106   else if (t == "F" || t == "F4")
107     {
108       symbol_ = "bass";
109       y_position_i_ = 2;
110     }
111   else if (t == "subbass")
112     {
113       symbol_ = "bass";
114       y_position_i_ = 4;
115     }
116   else if (isdigit(t[1]))
117           switch (t[0])
118           { // we've already dealt with plain F, G  or C clef 
119                   // position 0 is line 3.        
120           case 'G':
121           case 'g':
122                   symbol_ = "violin";
123                   y_position_i_ =   2 * (t[1] - '0') - 6;
124                   break;
125           case 'F':
126           case 'f':
127                   symbol_ = "bass";
128                   y_position_i_ = 2 * (t[1] - '0') - 6;
129                   break;
130           }
131 }
132
133 void
134 Clef_item::read (Clef_engraver const &k)
135 {
136   read (k.clef_type_str_);
137   octave_dir_ = k.octave_dir_;
138 }
139
140 Molecule*
141 Clef_item::brew_molecule_p() const
142 {
143   String t = symbol_;
144   if  (change_b_)
145     t += "_change";
146   Atom s = paper()->lookup_l ()->clef (t);
147   Molecule*output = new Molecule (Atom (s));
148   output->translate_axis (paper()->internote_f () * y_position_i_, Y_AXIS);
149   if (octave_dir_)
150     output->add_at_edge (Y_AXIS, 
151                          octave_dir_,
152                          Molecule(octave_marker_td_p_->get_atom(paper(), 
153                                                                 CENTER)));
154   return output;
155 }
156
157
158 IMPLEMENT_IS_TYPE_B1(Clef_item,Item);