]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/context.hh
Merge branch 'translation' into staging
[lilypond.git] / lily / include / context.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef CONTEXT_HH
21 #define CONTEXT_HH
22
23 #include "duration.hh"
24 #include "lily-proto.hh"
25 #include "listener.hh"
26 #include "moment.hh"
27 #include "scm-hash.hh"
28 #include "std-vector.hh"
29 #include "virtual-methods.hh"
30
31 class Context
32 {
33   Scheme_hash_table *properties_dict () const;
34   Context (Context const &src);
35
36   DECLARE_SMOBS (Context);
37   DECLARE_CLASSNAME (Context);
38   void terminate ();
39
40 private:
41   friend class Context_handle;
42   /* how many Context_handles point to this Context */
43   int client_count_;
44
45   /* Used internally by create_context */
46   Stream_event *infant_event_;
47
48 protected:
49   Context *daddy_context_;
50   /* The used Context_def */
51   SCM definition_;
52   /* Additions to the Context_def, given by \with */
53   SCM definition_mods_;
54
55   SCM properties_scm_;
56   SCM context_list_;
57   SCM accepts_list_;
58   SCM aliases_;
59   Translator_group *implementation_;
60   string id_string_;
61
62   /* Events reported in the context is sent to this dispatcher. */
63   Dispatcher *event_source_;
64
65   /* Events reported to this context or recursively in any of its
66      children, are sent to this dispatcher. */
67   Dispatcher *events_below_;
68
69   // Translator_group is allowed to set implementation_.
70   friend class Translator_group;
71   // Context_def::instantiate initialises some protected members.
72   friend class Context_def;
73   // UGH! initialises implementation_
74   friend SCM ly_make_global_translator (SCM);
75
76   DECLARE_LISTENER (set_property_from_event);
77   DECLARE_LISTENER (unset_property_from_event);
78
79 public:
80   string id_string () const { return id_string_; }
81   SCM children_contexts () const { return context_list_; }
82   SCM default_child_context_name () const;
83
84   Dispatcher *event_source () const { return event_source_; }
85   Dispatcher *events_below () const { return events_below_; }
86   void internal_send_stream_event (SCM type, Input *origin, SCM props[]);
87
88   SCM get_definition () const { return definition_; }
89   SCM get_definition_mods () const { return definition_mods_; }
90
91   Translator_group *implementation () const { return implementation_; }
92   Context *get_parent_context () const;
93   Context ();
94
95   /* properties:  */
96   SCM internal_get_property (SCM name_sym) const;
97   SCM properties_as_alist () const;
98   Context *where_defined (SCM name_sym, SCM *value) const;
99   void unset_property (SCM var_sym);
100
101   void instrumented_set_property (SCM, SCM, const char *, int, const char *);
102   void internal_set_property (SCM var_sym, SCM value);
103
104   Context *create_context (Context_def *, string, SCM);
105   DECLARE_LISTENER (create_context_from_event);
106   DECLARE_LISTENER (acknowledge_infant);
107   DECLARE_LISTENER (remove_context);
108   DECLARE_LISTENER (change_parent);
109   void disconnect_from_parent ();
110   void check_removal ();
111   string context_name () const;
112   SCM context_name_symbol () const;
113   Global_context *get_global_context () const;
114
115   virtual Context *get_score_context () const;
116   virtual Output_def *get_output_def () const;
117   virtual Moment now_mom () const;
118   virtual Context *get_default_interpreter (string context_id = "");
119
120   // It would make some sense to have the following just available in
121   // a global context.  It would be decidedly tricky, however, to have
122   // it initialized before the constructor of its Context base class
123   // was able to trigger garbage collection.
124   SCM ancestor_lookup_;
125   SCM make_event_class (SCM);
126
127   bool is_alias (SCM) const;
128   void add_alias (SCM);
129   void add_context (Context *trans);
130   bool is_bottom_context () const;
131   bool is_removable () const;
132
133   Context *find_create_context (SCM context_name,
134                                 string id, SCM ops);
135   Context *create_unique_context (SCM context_name, string context_id,
136                                   SCM ops);
137   vector<Context_def *> path_to_acceptable_context (SCM alias) const;
138 };
139
140 /*
141   Context arg?
142 */
143
144 void apply_property_operations (Context *tg, SCM pre_init_ops);
145 void execute_revert_property (Context *context,
146                               SCM context_property,
147                               SCM grob_property_path);
148 void execute_pushpop_property (Context *trg, SCM prop, SCM eltprop, SCM val);
149 void sloppy_general_pushpop_property (Context *context,
150                                       SCM context_property, SCM grob_property_path, SCM val);
151 SCM updated_grob_properties (Context *tg, SCM sym);
152 Context *find_context_below (Context *where,
153                              SCM type_sym, string id);
154 bool melisma_busy (Context *);
155
156 Context *get_voice_to_lyrics (Context *lyrics);
157 Grob *get_current_note_head (Context *voice, bool include_grace_notes);
158 Grob *get_current_rest (Context *voice);
159 DECLARE_UNSMOB (Context, context);
160
161 Moment measure_position (Context const *context);
162 Moment measure_position (Context const *context, Duration const *dur);
163 Rational measure_length (Context const *context);
164 int measure_number (Context const *context);
165
166 bool check_repeat_count_visibility (Context const *context, SCM count);
167
168 void set_context_property_on_children (Context *trans, SCM sym, SCM val);
169
170 /* Shorthand for creating and broadcasting stream events. */
171 #define send_stream_event(ctx, type, origin, ...)                               \
172 {                                                                       \
173   SCM props[] = { __VA_ARGS__, 0 };                                     \
174   ctx->internal_send_stream_event (ly_symbol2scm (type), origin, props);        \
175 }
176
177 SCM nested_property_alist (SCM alist, SCM prop_path, SCM value);
178 SCM nested_property_revert_alist (SCM alist, SCM prop_path);
179 SCM evict_from_alist (SCM, SCM, SCM);
180
181 #endif /* CONTEXT_HH */