]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/context.hh
* lily/global-context-scheme.cc: Separated ly:run-translator into
[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   void internal_set_property (SCM var_sym, SCM value);
91   Context *where_defined (SCM name_sym, SCM *value) const;
92   void unset_property (SCM var_sym);
93
94   Context *create_context (Context_def *, string, SCM);
95   DECLARE_LISTENER (create_context_from_event);
96   DECLARE_LISTENER (acknowledge_infant);
97   DECLARE_LISTENER (remove_context);
98   DECLARE_LISTENER (change_parent);
99   void disconnect_from_parent ();
100   void check_removal ();
101   string context_name () const;
102   SCM context_name_symbol () const;
103   Global_context *get_global_context () const;
104
105   virtual Context *get_score_context () const;
106   virtual Output_def *get_output_def () const;
107   virtual Moment now_mom () const;
108   virtual Context *get_default_interpreter ();
109
110   bool is_alias (SCM) const;
111   void add_alias (SCM);
112   void add_context (Context *trans);
113   bool is_bottom_context () const;
114   bool is_removable () const;
115   bool try_music (Music *);
116
117   Context *find_create_context (SCM context_name,
118                                 string id, SCM ops);
119   Context *create_unique_context (SCM context_name, string context_id,
120                                   SCM ops);
121   vector<Context*> path_to_acceptable_context (SCM alias,
122                                                   Output_def *) const;
123 };
124
125 /*
126   Context arg?
127 */
128
129 void apply_property_operations (Context *tg, SCM pre_init_ops);
130 void execute_pushpop_property (Context *trg, SCM prop, SCM eltprop, SCM val);
131 void execute_general_pushpop_property (Context *context,
132                                        SCM context_property, SCM grob_property_path, SCM val);
133 SCM updated_grob_properties (Context *tg, SCM sym);
134 Context *find_context_below (Context *where,
135                              SCM type_sym, string id);
136 bool melisma_busy (Context *);
137
138 Context *get_voice_to_lyrics (Context *lyrics);
139 Grob *get_current_note_head (Context *voice);
140 Grob *get_current_rest (Context *voice);
141 DECLARE_UNSMOB (Context, context);
142
143 Moment measure_position (Context const *context);
144 Rational measure_length (Context const *context);
145 void set_context_property_on_children (Context *trans, SCM sym, SCM val);
146
147 /* Shorthand for creating and broadcasting stream events. */
148 #define send_stream_event(ctx, type, origin, ...)                               \
149 {                                                                       \
150   SCM props[] = { __VA_ARGS__, 0 };                                     \
151   ctx->internal_send_stream_event (ly_symbol2scm (type), origin, props);        \
152 }
153
154 #endif /* CONTEXT_HH */
155