]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/context.hh
fd3c75b3f0f5daa28ca22def92188c1bcc8bf319
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef CONTEXT_HH
10 #define CONTEXT_HH
11
12 #include "context-key-manager.hh"
13 #include "lily-proto.hh"
14 #include "listener.hh"
15 #include "moment.hh"
16 #include "std-vector.hh"
17 #include "virtual-methods.hh"
18
19 class Context
20 {
21   Scheme_hash_table *properties_dict () const;
22   Context (Context const &src);
23
24   DECLARE_SMOBS (Context, dummy);
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   Context_key_manager key_manager_;
42   
43   SCM properties_scm_;
44   SCM context_list_;
45   SCM accepts_list_;
46   SCM aliases_;
47   Translator_group *implementation_;
48   string id_string_;
49   
50   /* Events reported in the context is sent to this dispatcher. */
51   Dispatcher *event_source_;
52
53   /* Events reported to this context or recursively in any of its
54      children, are sent to this dispatcher. */
55   Dispatcher *events_below_;
56
57   // Translator_group is allowed to set implementation_.
58   friend class Translator_group;
59   // Context_def::instantiate initialises some protected members.
60   friend class Context_def;
61   // UGH! initialises implementation_
62   friend SCM ly_make_global_translator (SCM);
63   void clear_key_disambiguations ();
64
65   DECLARE_LISTENER (set_property_from_event);
66   DECLARE_LISTENER (unset_property_from_event);
67   
68 public:
69   Object_key const *get_grob_key (string name);
70   Object_key const *get_context_key (string name, string id);
71
72   string id_string () const { return id_string_; }
73   SCM children_contexts () const { return context_list_; }
74   SCM default_child_context_name () const;
75
76   Dispatcher *event_source () const { return event_source_; }
77   Dispatcher *events_below () const { return events_below_; }
78   void internal_send_stream_event (SCM type, Input *origin, SCM props[]);
79
80   SCM get_definition () const { return definition_; }
81   SCM get_definition_mods () const { return definition_mods_; }
82
83   Translator_group *implementation () const { return implementation_; }
84   Context *get_parent_context () const;
85   Context (Object_key const *);
86
87   /* properties:  */
88   SCM internal_get_property (SCM name_sym) const;
89   SCM properties_as_alist () const;
90   Context *where_defined (SCM name_sym, SCM *value) const;
91   void unset_property (SCM var_sym);
92
93 #ifndef NDEBUG
94   void internal_set_property (SCM var_sym, SCM value, char const *file, int line, char const *fun);
95 #else
96   void internal_set_property (SCM var_sym, SCM value);
97 #endif
98
99   Context *create_context (Context_def *, string, SCM);
100   DECLARE_LISTENER (create_context_from_event);
101   DECLARE_LISTENER (acknowledge_infant);
102   DECLARE_LISTENER (remove_context);
103   DECLARE_LISTENER (change_parent);
104   void disconnect_from_parent ();
105   void check_removal ();
106   string context_name () const;
107   SCM context_name_symbol () const;
108   Global_context *get_global_context () const;
109
110   virtual Context *get_score_context () const;
111   virtual Output_def *get_output_def () const;
112   virtual Moment now_mom () const;
113   virtual Context *get_default_interpreter ();
114
115   bool is_alias (SCM) const;
116   void add_alias (SCM);
117   void add_context (Context *trans);
118   bool is_bottom_context () const;
119   bool is_removable () const;
120
121   Context *find_create_context (SCM context_name,
122                                 string id, SCM ops);
123   Context *create_unique_context (SCM context_name, string context_id,
124                                   SCM ops);
125   vector<Context*> path_to_acceptable_context (SCM alias,
126                                                   Output_def *) const;
127 };
128
129 /*
130   Context arg?
131 */
132
133 void apply_property_operations (Context *tg, SCM pre_init_ops);
134 void execute_pushpop_property (Context *trg, SCM prop, SCM eltprop, SCM val);
135 void execute_general_pushpop_property (Context *context,
136                                        SCM context_property, SCM grob_property_path, SCM val);
137 SCM updated_grob_properties (Context *tg, SCM sym);
138 Context *find_context_below (Context *where,
139                              SCM type_sym, string id);
140 bool melisma_busy (Context *);
141
142 Context *get_voice_to_lyrics (Context *lyrics);
143 Grob *get_current_note_head (Context *voice);
144 Grob *get_current_rest (Context *voice);
145 DECLARE_UNSMOB (Context, context);
146
147 Moment measure_position (Context const *context);
148 Rational measure_length (Context const *context);
149 void set_context_property_on_children (Context *trans, SCM sym, SCM val);
150
151 /* Shorthand for creating and broadcasting stream events. */
152 #define send_stream_event(ctx, type, origin, ...)                               \
153 {                                                                       \
154   SCM props[] = { __VA_ARGS__, 0 };                                     \
155   ctx->internal_send_stream_event (ly_symbol2scm (type), origin, props);        \
156 }
157
158 #endif /* CONTEXT_HH */
159