]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/context.hh
don't change signatures depending on NDEBUG
[lilypond.git] / lily / include / context.hh
1 /*
2   context.hh -- declare  Context
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef CONTEXT_HH
10 #define CONTEXT_HH
11
12 #include "listener.hh"
13 #include "moment.hh"
14 #include "std-vector.hh"
15 #include "virtual-methods.hh"
16 #include "scm-hash.hh"
17 #include "lily-proto.hh"
18
19 class Context
20 {
21   Scheme_hash_table *properties_dict () const;
22   Context (Context const &src);
23
24   DECLARE_SMOBS (Context);
25   DECLARE_CLASSNAME(Context);
26   void terminate ();
27
28 private:
29   friend class Context_handle;
30   int iterator_count_;
31   
32   /* Used internally by create_context */
33   Stream_event *infant_event_;
34
35 protected:
36   Context *daddy_context_;
37   /* The used Context_def */
38   SCM definition_;
39   /* Additions to the Context_def, given by \with */
40   SCM definition_mods_;
41   
42   SCM properties_scm_;
43   SCM context_list_;
44   SCM accepts_list_;
45   SCM aliases_;
46   Translator_group *implementation_;
47   string id_string_;
48   
49   /* Events reported in the context is sent to this dispatcher. */
50   Dispatcher *event_source_;
51
52   /* Events reported to this context or recursively in any of its
53      children, are sent to this dispatcher. */
54   Dispatcher *events_below_;
55
56   // Translator_group is allowed to set implementation_.
57   friend class Translator_group;
58   // Context_def::instantiate initialises some protected members.
59   friend class Context_def;
60   // UGH! initialises implementation_
61   friend SCM ly_make_global_translator (SCM);
62
63   DECLARE_LISTENER (set_property_from_event);
64   DECLARE_LISTENER (unset_property_from_event);
65   
66 public:
67   string id_string () const { return id_string_; }
68   SCM children_contexts () const { return context_list_; }
69   SCM default_child_context_name () const;
70
71   Dispatcher *event_source () const { return event_source_; }
72   Dispatcher *events_below () const { return events_below_; }
73   void internal_send_stream_event (SCM type, Input *origin, SCM props[]);
74
75   SCM get_definition () const { return definition_; }
76   SCM get_definition_mods () const { return definition_mods_; }
77
78   Translator_group *implementation () const { return implementation_; }
79   Context *get_parent_context () const;
80   Context ();
81
82   /* properties:  */
83   SCM internal_get_property (SCM name_sym) const;
84   SCM properties_as_alist () const;
85   Context *where_defined (SCM name_sym, SCM *value) const;
86   void unset_property (SCM var_sym);
87
88   void internal_set_property (SCM var_sym, SCM value);
89
90   Context *create_context (Context_def *, string, SCM);
91   DECLARE_LISTENER (create_context_from_event);
92   DECLARE_LISTENER (acknowledge_infant);
93   DECLARE_LISTENER (remove_context);
94   DECLARE_LISTENER (change_parent);
95   void disconnect_from_parent ();
96   void check_removal ();
97   string context_name () const;
98   SCM context_name_symbol () const;
99   Global_context *get_global_context () const;
100
101   virtual Context *get_score_context () const;
102   virtual Output_def *get_output_def () const;
103   virtual Moment now_mom () const;
104   virtual Context *get_default_interpreter ();
105
106   bool is_alias (SCM) const;
107   void add_alias (SCM);
108   void add_context (Context *trans);
109   bool is_bottom_context () const;
110   bool is_removable () const;
111
112   Context *find_create_context (SCM context_name,
113                                 string id, SCM ops);
114   Context *create_unique_context (SCM context_name, string context_id,
115                                   SCM ops);
116   vector<Context*> path_to_acceptable_context (SCM alias,
117                                                   Output_def *) const;
118 };
119
120 /*
121   Context arg?
122 */
123
124 void apply_property_operations (Context *tg, SCM pre_init_ops);
125 void execute_pushpop_property (Context *trg, SCM prop, SCM eltprop, SCM val);
126 void execute_general_pushpop_property (Context *context,
127                                        SCM context_property, SCM grob_property_path, SCM val);
128 SCM updated_grob_properties (Context *tg, SCM sym);
129 Context *find_context_below (Context *where,
130                              SCM type_sym, string id);
131 bool melisma_busy (Context *);
132
133 Context *get_voice_to_lyrics (Context *lyrics);
134 Grob *get_current_note_head (Context *voice);
135 Grob *get_current_rest (Context *voice);
136 DECLARE_UNSMOB (Context, context);
137
138 Moment measure_position (Context const *context);
139 Rational measure_length (Context const *context);
140 void set_context_property_on_children (Context *trans, SCM sym, SCM val);
141
142 /* Shorthand for creating and broadcasting stream events. */
143 #define send_stream_event(ctx, type, origin, ...)                               \
144 {                                                                       \
145   SCM props[] = { __VA_ARGS__, 0 };                                     \
146   ctx->internal_send_stream_event (ly_symbol2scm (type), origin, props);        \
147 }
148
149 #endif /* CONTEXT_HH */
150