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