lilypond-1.3.28
[lilypond.git] / lily / music-output-def.cc
blobf1cf79cb65386443b2dfc60320470cb7b66ba9e9
1 /*
2 music-output-def.cc -- implement Music_output_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "scope.hh"
10 #include "debug.hh"
11 #include "music-output-def.hh"
12 #include "global-translator.hh"
13 #include "dictionary-iter.hh"
14 #include "identifier.hh"
15 #include "main.hh"
16 #include "lily-guile.hh"
18 int
19 Music_output_def::get_next_default_count () const
21 return 0;
26 Music_output_def::Music_output_def ()
28 scope_p_ = new Scope;
29 translator_p_dict_p_ = new Scope;
32 Music_output_def::~Music_output_def ()
34 delete scope_p_;
35 delete translator_p_dict_p_;
38 Music_output_def::Music_output_def (Music_output_def const &s)
40 scope_p_ = new Scope (*s.scope_p_);
41 translator_p_dict_p_ = new Scope (*s.translator_p_dict_p_);
42 default_properties_ = s.default_properties_;
44 for (Scope_iter i (*translator_p_dict_p_); i.ok (); i++)
46 Translator * t = i.val ()->access_content_Translator_group (false);
47 t-> output_def_l_ = this;
51 void
52 Music_output_def::assign_translator (Translator_group*tp)
54 String s =tp->type_str_;
55 if (s.empty_b ())
57 tp->warning (_("Interpretation context with empty type"));
59 if (translator_p_dict_p_->elem_b (s))
60 delete translator_p_dict_p_->elem (s);
62 translator_p_dict_p_->elem (s) = new Translator_group_identifier (tp, 0);
63 tp ->output_def_l_ = this;
66 Translator*
67 Music_output_def::find_translator_l (String name) const
69 if (translator_p_dict_p_->elem_b (name))
70 return translator_p_dict_p_->elem (name)->access_content_Translator_group (false);
72 if (global_translator_dict_p->elem_b (name))
73 return global_translator_dict_p->elem(name);
75 return 0;
79 Global_translator *
80 Music_output_def::get_global_translator_p ()
82 Translator * t = find_translator_l ("Score");
83 if (!t)
84 error (_f ("Can't find `%s' context", "Score"));
85 t = t->clone ();
86 Global_translator *g = dynamic_cast <Global_translator *> (t);
87 t->add_processing ();
89 return g;
92 void
93 Music_output_def::print () const
95 #ifndef NPRINT
96 DEBUG_OUT << "Translators: \n";
97 translator_p_dict_p_->print ();
98 DEBUG_OUT << "Other definitions.\n";
99 scope_p_->print( );
100 #endif
103 String
104 Music_output_def::get_default_output () const
106 if (safe_global_b || !scope_p_->elem_b ("output"))
107 return "";
108 Identifier * id = scope_p_->elem ("output");
110 String *p = id->access_content_String (false);
111 return p ? *p : String ("");