]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/context.hh
Run `make grand-replace'.
[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--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef CONTEXT_HH
10 #define CONTEXT_HH
11
12 #include "duration.hh"
13 #include "lily-proto.hh"
14 #include "listener.hh"
15 #include "moment.hh"
16 #include "scm-hash.hh"
17 #include "std-vector.hh"
18 #include "virtual-methods.hh"
19
20 class Context
21 {
22   Scheme_hash_table *properties_dict () const;
23   Context (Context const &src);
24
25   DECLARE_SMOBS (Context);
26   DECLARE_CLASSNAME(Context);
27   void terminate ();
28
29 private:
30   friend class Context_handle;
31   int iterator_count_;
32   
33   /* Used internally by create_context */
34   Stream_event *infant_event_;
35
36 protected:
37   Context *daddy_context_;
38   /* The used Context_def */
39   SCM definition_;
40   /* Additions to the Context_def, given by \with */
41   SCM definition_mods_;
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
64   DECLARE_LISTENER (set_property_from_event);
65   DECLARE_LISTENER (unset_property_from_event);
66   
67 public:
68   string id_string () const { return id_string_; }
69   SCM children_contexts () const { return context_list_; }
70   SCM default_child_context_name () const;
71
72   Dispatcher *event_source () const { return event_source_; }
73   Dispatcher *events_below () const { return events_below_; }
74   void internal_send_stream_event (SCM type, Input *origin, SCM props[]);
75
76   SCM get_definition () const { return definition_; }
77   SCM get_definition_mods () const { return definition_mods_; }
78
79   Translator_group *implementation () const { return implementation_; }
80   Context *get_parent_context () const;
81   Context ();
82
83   /* properties:  */
84   SCM internal_get_property (SCM name_sym) const;
85   SCM properties_as_alist () const;
86   Context *where_defined (SCM name_sym, SCM *value) const;
87   void unset_property (SCM var_sym);
88
89   void instrumented_set_property (SCM, SCM, const char*, int, const char*);
90   void internal_set_property (SCM var_sym, SCM value);
91
92   Context *create_context (Context_def *, string, SCM);
93   DECLARE_LISTENER (create_context_from_event);
94   DECLARE_LISTENER (acknowledge_infant);
95   DECLARE_LISTENER (remove_context);
96   DECLARE_LISTENER (change_parent);
97   void disconnect_from_parent ();
98   void check_removal ();
99   string context_name () const;
100   SCM context_name_symbol () const;
101   Global_context *get_global_context () const;
102
103   virtual Context *get_score_context () const;
104   virtual Output_def *get_output_def () const;
105   virtual Moment now_mom () const;
106   virtual Context *get_default_interpreter ();
107
108   bool is_alias (SCM) const;
109   void add_alias (SCM);
110   void add_context (Context *trans);
111   bool is_bottom_context () const;
112   bool is_removable () const;
113
114   Context *find_create_context (SCM context_name,
115                                 string id, SCM ops);
116   Context *create_unique_context (SCM context_name, string context_id,
117                                   SCM ops);
118   vector<Context_def*> path_to_acceptable_context (SCM alias) const;
119 };
120
121 /*
122   Context arg?
123 */
124
125 void apply_property_operations (Context *tg, SCM pre_init_ops);
126 void execute_revert_property (Context *context,
127                               SCM context_property,
128                               SCM grob_property_path);
129 void execute_pushpop_property (Context *trg, SCM prop, SCM eltprop, SCM val);
130 void sloppy_general_pushpop_property (Context *context,
131                                        SCM context_property, SCM grob_property_path, SCM val);
132 SCM updated_grob_properties (Context *tg, SCM sym);
133 Context *find_context_below (Context *where,
134                              SCM type_sym, string id);
135 bool melisma_busy (Context *);
136
137 Context *get_voice_to_lyrics (Context *lyrics);
138 Grob *get_current_note_head (Context *voice);
139 Grob *get_current_rest (Context *voice);
140 DECLARE_UNSMOB (Context, context);
141
142 Moment measure_position (Context const *context);
143 Moment measure_position (Context const *context, Duration const *dur);
144 Rational measure_length (Context const *context);
145 int measure_number (Context const *context);
146 void set_context_property_on_children (Context *trans, SCM sym, SCM val);
147
148 /* Shorthand for creating and broadcasting stream events. */
149 #define send_stream_event(ctx, type, origin, ...)                               \
150 {                                                                       \
151   SCM props[] = { __VA_ARGS__, 0 };                                     \
152   ctx->internal_send_stream_event (ly_symbol2scm (type), origin, props);        \
153 }
154
155 SCM nested_property_alist (SCM alist, SCM prop_path, SCM value);
156 SCM nested_property_revert_alist (SCM alist, SCM prop_path);
157 SCM evict_from_alist (SCM, SCM, SCM);
158
159 #endif /* CONTEXT_HH */
160