]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/context.hh
Fix some bugs in the dynamic engraver and PostScript backend
[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
13 #include "std-vector.hh"
14 #include "moment.hh"
15 #include "lily-proto.hh"
16 #include "virtual-methods.hh"
17 #include "context-key-manager.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   bool init_;
32
33 protected:
34   int unique_;
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   friend class Context_def;
57   void clear_key_disambiguations ();
58
59   
60 public:
61   Object_key const *get_grob_key (string name);
62   Object_key const *get_context_key (string name, string id);
63
64   Context *create_context (Context_def *, string, SCM);
65   string id_string () const { return id_string_; }
66   SCM children_contexts () const { return context_list_; }
67   SCM default_child_context_name () const;
68   int get_unique() { return unique_; }
69
70   Dispatcher *event_source () const { return event_source_; }
71   Dispatcher *events_below () const { return events_below_; }
72   void internal_send_stream_event (SCM type, SCM props[]);
73
74   SCM get_definition () const { return definition_; }
75   SCM get_definition_mods () const { return definition_mods_; }
76
77   Translator_group *implementation () const { return implementation_; }
78   Context *get_parent_context () const;
79   Context (Object_key const *);
80
81   /* properties:  */
82   SCM internal_get_property (SCM name_sym) const;
83   SCM properties_as_alist () const;
84   void internal_set_property (SCM var_sym, SCM value);
85   Context *where_defined (SCM name_sym, SCM *value) const;
86   void unset_property (SCM var_sym);
87
88   Context *remove_context (Context *trans);
89   void check_removal ();
90   string context_name () const;
91   SCM context_name_symbol () const;
92   Global_context *get_global_context () const;
93
94   virtual Score_context *get_score_context () const;
95   virtual Output_def *get_output_def () const;
96   virtual Moment now_mom () const;
97   virtual Context *get_default_interpreter ();
98
99   bool is_alias (SCM) const;
100   void add_alias (SCM);
101   void add_context (Context *trans);
102   bool is_bottom_context () const;
103   bool is_removable () const;
104   bool try_music (Music *);
105
106   Context *find_create_context (SCM context_name,
107                                 string id, SCM ops);
108   Context *create_unique_context (SCM context_name, string context_id,
109                                   SCM ops);
110   vector<Context*> path_to_acceptable_context (SCM alias,
111                                                   Output_def *) const;
112 };
113
114 /*
115   Context arg?
116 */
117
118 void apply_property_operations (Context *tg, SCM pre_init_ops);
119 void execute_pushpop_property (Context *trg, SCM prop, SCM eltprop, SCM val);
120 void execute_general_pushpop_property (Context *context,
121                                        SCM context_property, SCM grob_property_path, SCM val);
122 SCM updated_grob_properties (Context *tg, SCM sym);
123 Context *find_context_below (Context *where,
124                              SCM type_sym, string id);
125 bool melisma_busy (Context *);
126
127 Context *get_voice_to_lyrics (Context *lyrics);
128 Grob *get_current_note_head (Context *voice);
129 Grob *get_current_rest (Context *voice);
130 DECLARE_UNSMOB (Context, context);
131
132 Moment measure_position (Context const *context);
133 Rational measure_length (Context const *context);
134 void set_context_property_on_children (Context *trans, SCM sym, SCM val);
135
136 /* Shorthand for creating and broadcasting stream events. */
137 #define send_stream_event(ctx, type, ...)                               \
138 {                                                                       \
139   SCM props[] = { __VA_ARGS__, 0 };                                     \
140   ctx->internal_send_stream_event (ly_symbol2scm (type), props);        \
141 }
142
143 #endif /* CONTEXT_HH */
144