]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/context.hh
Fix 65.
[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 instrumented_set_property (SCM, SCM, const char*, int, const char*);
89   void internal_set_property (SCM var_sym, SCM value);
90
91   Context *create_context (Context_def *, string, SCM);
92   DECLARE_LISTENER (create_context_from_event);
93   DECLARE_LISTENER (acknowledge_infant);
94   DECLARE_LISTENER (remove_context);
95   DECLARE_LISTENER (change_parent);
96   void disconnect_from_parent ();
97   void check_removal ();
98   string context_name () const;
99   SCM context_name_symbol () const;
100   Global_context *get_global_context () const;
101
102   virtual Context *get_score_context () const;
103   virtual Output_def *get_output_def () const;
104   virtual Moment now_mom () const;
105   virtual Context *get_default_interpreter ();
106
107   bool is_alias (SCM) const;
108   void add_alias (SCM);
109   void add_context (Context *trans);
110   bool is_bottom_context () const;
111   bool is_removable () const;
112
113   Context *find_create_context (SCM context_name,
114                                 string id, SCM ops);
115   Context *create_unique_context (SCM context_name, string context_id,
116                                   SCM ops);
117   vector<Context_def*> path_to_acceptable_context (SCM alias) 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 SCM nested_property_alist (SCM alist, SCM prop_path, SCM value);
150 SCM nested_property_revert_alist (SCM alist, SCM prop_path);
151 SCM evict_from_alist (SCM, SCM, SCM);
152
153 #endif /* CONTEXT_HH */
154