2 music-output-def.cc -- implement Music_output_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "dictionary.hh"
13 #include "music-output-def.hh"
14 #include "global-translator.hh"
15 #include "translator-def.hh"
17 #include "file-path.hh"
18 #include "lily-guile.hh"
20 #include "ly-smobs.icc"
23 Music_output_def::get_next_score_count () const
28 Music_output_def::Music_output_def ()
30 style_sheet_
= SCM_EOL
;
31 scaled_fonts_
= SCM_EOL
;
33 variable_tab_
= new Scheme_hash_table
;
34 translator_tab_
= new Scheme_hash_table
;
37 scm_gc_unprotect_object (variable_tab_
->self_scm ());
38 scm_gc_unprotect_object (translator_tab_
->self_scm ());
41 Music_output_def::~Music_output_def ()
45 Music_output_def::Music_output_def (Music_output_def
const &s
)
47 variable_tab_
= new Scheme_hash_table (*s
.variable_tab_
);
48 translator_tab_
= new Scheme_hash_table (*s
.translator_tab_
);
50 style_sheet_
= SCM_EOL
;
51 scaled_fonts_
= SCM_EOL
;
54 scm_gc_unprotect_object (variable_tab_
->self_scm ());
55 scm_gc_unprotect_object (translator_tab_
->self_scm ());
57 style_sheet_
= scm_list_copy (s
.style_sheet_
);
58 scaled_fonts_
= scm_list_copy (s
.scaled_fonts_
);
62 IMPLEMENT_SMOBS (Music_output_def
);
64 IMPLEMENT_DEFAULT_EQUAL_P (Music_output_def
);
67 Music_output_def::mark_smob (SCM m
)
69 Music_output_def
* mo
= (Music_output_def
*) SCM_CELL_WORD_1 (m
);
70 scm_gc_mark (mo
->style_sheet_
);
71 scm_gc_mark (mo
->translator_tab_
->self_scm ());
72 scm_gc_mark (mo
->variable_tab_
->self_scm ());
74 return mo
->scaled_fonts_
;
78 Music_output_def::assign_translator (SCM transdef
)
80 Translator_def
*tp
= unsmob_translator_def (transdef
);
84 SCM s
= ly_symbol2scm ("");
85 if (gh_string_p (tp
->type_name_
))
86 s
= scm_string_to_symbol (tp
->type_name_
);
88 translator_tab_
->set (s
, transdef
);
92 find the translator for NAME. NAME may be a string or a symbol.
95 Music_output_def::find_translator (SCM name
) const
97 if (gh_string_p (name
))
98 name
= scm_string_to_symbol (name
);
101 translator_tab_
->try_retrieve (name
, &val
);
107 Music_output_def::get_global_translator ()
109 SCM key
= ly_symbol2scm ("Score");
110 Translator_def
* t
= unsmob_translator_def (find_translator (key
));
113 error (_f ("can't find `%s' context", "Score"));
115 Translator_group
* tg
= t
->instantiate (this);
119 return dynamic_cast <Global_translator
*> (tg
);
123 Music_output_def::print_smob (SCM s
, SCM p
, scm_print_state
*)
125 Music_output_def
* def
= unsmob_music_output_def (s
);
126 scm_puts ("#<Music_output_def ", p
);
128 scm_write (def
->type_name_
, p
);
137 ugh: should move into Music_output_def (complication: .midi and .tex
138 need separate counts.) */
140 Music_output_def::outname_string ()
142 String out
= output_name_global
;
143 int def
= get_next_score_count ();
144 if (def
&& out
!= "-")
146 Path p
= split_path (out
);
147 p
.base
+= "-" + to_string (def
);