2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2004--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 #include "duration.hh"
24 #include "lily-proto.hh"
25 #include "listener.hh"
27 #include "scm-hash.hh"
28 #include "std-vector.hh"
29 #include "virtual-methods.hh"
33 Scheme_hash_table *properties_dict () const;
34 Context (Context const &src);
36 DECLARE_SMOBS (Context);
37 DECLARE_CLASSNAME (Context);
41 friend class Context_handle;
42 /* how many Context_handles point to this Context */
45 /* Used internally by create_context */
46 Stream_event *infant_event_;
49 Context *daddy_context_;
50 /* The used Context_def */
52 /* Additions to the Context_def, given by \with */
60 Translator_group *implementation_;
63 /* Events reported in the context is sent to this dispatcher. */
64 Dispatcher *event_source_;
66 /* Events reported to this context or recursively in any of its
67 children, are sent to this dispatcher. */
68 Dispatcher *events_below_;
70 // Translator_group is allowed to set implementation_.
71 friend class Translator_group;
72 // Context_def::instantiate initialises some protected members.
73 friend class Context_def;
74 // UGH! initialises implementation_
75 friend SCM ly_make_global_translator (SCM);
77 DECLARE_LISTENER (set_property_from_event);
78 DECLARE_LISTENER (unset_property_from_event);
81 string id_string () const { return id_string_; }
82 SCM children_contexts () const { return context_list_; }
83 SCM default_child_context_name () const;
85 Dispatcher *event_source () const { return event_source_; }
86 Dispatcher *events_below () const { return events_below_; }
87 void internal_send_stream_event (SCM type, Input *origin, SCM props[]);
89 SCM get_definition () const { return definition_; }
90 SCM get_definition_mods () const { return definition_mods_; }
92 Translator_group *implementation () const { return implementation_; }
93 Context *get_parent_context () const;
97 SCM internal_get_property (SCM name_sym) const;
98 SCM properties_as_alist () const;
99 Context *where_defined (SCM name_sym, SCM *value) const;
100 void unset_property (SCM var_sym);
102 void instrumented_set_property (SCM, SCM, const char *, int, const char *);
103 void internal_set_property (SCM var_sym, SCM value);
105 Context *create_context (Context_def *, string, SCM);
106 DECLARE_LISTENER (create_context_from_event);
107 DECLARE_LISTENER (acknowledge_infant);
108 DECLARE_LISTENER (remove_context);
109 DECLARE_LISTENER (change_parent);
110 void disconnect_from_parent ();
111 void check_removal ();
112 string context_name () const;
113 SCM context_name_symbol () const;
114 Global_context *get_global_context () const;
116 virtual Context *get_score_context () const;
117 virtual Output_def *get_output_def () const;
118 virtual Moment now_mom () const;
119 virtual Context *get_default_interpreter (string context_id = "");
121 bool is_alias (SCM) const;
122 void add_alias (SCM);
123 void add_context (Context *trans);
124 bool is_bottom_context () const;
125 bool is_removable () const;
127 Context *find_create_context (SCM context_name,
129 Context *create_unique_context (SCM context_name, string context_id,
131 vector<Context_def *> path_to_acceptable_context (SCM alias) const;
138 void apply_property_operations (Context *tg, SCM pre_init_ops);
139 void execute_revert_property (Context *context,
140 SCM context_property,
141 SCM grob_property_path);
142 void execute_pushpop_property (Context *trg, SCM prop, SCM eltprop, SCM val);
143 void sloppy_general_pushpop_property (Context *context,
144 SCM context_property, SCM grob_property_path, SCM val);
145 SCM updated_grob_properties (Context *tg, SCM sym);
146 Context *find_context_below (Context *where,
147 SCM type_sym, string id);
148 bool melisma_busy (Context *);
150 Context *get_voice_to_lyrics (Context *lyrics);
151 Grob *get_current_note_head (Context *voice, bool include_grace_notes);
152 Grob *get_current_rest (Context *voice);
153 DECLARE_UNSMOB (Context, context);
155 Moment measure_position (Context const *context);
156 Moment measure_position (Context const *context, Duration const *dur);
157 Rational measure_length (Context const *context);
158 int measure_number (Context const *context);
160 bool check_repeat_count_visibility (Context const *context, SCM count);
162 void set_context_property_on_children (Context *trans, SCM sym, SCM val);
164 /* Shorthand for creating and broadcasting stream events. */
165 #define send_stream_event(ctx, type, origin, ...) \
167 SCM props[] = { __VA_ARGS__, 0 }; \
168 ctx->internal_send_stream_event (ly_symbol2scm (type), origin, props); \
171 SCM nested_property_alist (SCM alist, SCM prop_path, SCM value);
172 SCM nested_property_revert_alist (SCM alist, SCM prop_path);
173 SCM evict_from_alist (SCM, SCM, SCM);
175 #endif /* CONTEXT_HH */