summaryrefslogtreecommitdiff
path: root/lily/include/translator.icc
blob: 904e3c127c60bcef5c85cda95dd8d7421bd2009c (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
  translator.icc -- declare Translator glue wiring.

  source file of the GNU LilyPond music typesetter

  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
*/

#ifndef TRANSLATOR_ICC
#define TRANSLATOR_ICC

#include "listener.hh"
#include "std-vector.hh"
#include "translator.hh"

/**
   A macro to automate administration of translators.
*/
#define ADD_THIS_TRANSLATOR(T)						\
  translator_listener_record *T::listener_list_;			\
  SCM T::static_description_ = SCM_EOL;					\
  static void _ ## T ## _adder ()					\
  {									\
    T *t = new T;							\
    T::static_description_ = t->static_translator_description ();	\
    scm_permanent_object (T::static_description_);			\
    add_translator (t);							\
  }									\
  SCM T::translator_description () const				\
  {									\
    return static_description_;						\
  }									\
  ADD_GLOBAL_CTOR (_ ## T ## _adder);

#define ADD_TRANSLATOR(classname, desc, grobs, accepted, read, write)	\
  Drul_array< vector<Acknowledge_information> > classname::acknowledge_static_array_drul_;	\
  IMPLEMENT_FETCH_PRECOMPUTABLE_METHODS (classname);			\
  ADD_THIS_TRANSLATOR (classname);					\
  Engraver_void_function_engraver_grob_info				\
  classname::static_get_acknowledger (SCM sym)				\
  {									\
    return generic_get_acknowledger (sym, &acknowledge_static_array_drul_[START]);	\
  }									\
  Engraver_void_function_engraver_grob_info				\
  classname::static_get_end_acknowledger (SCM sym)				\
  {									\
    return generic_get_acknowledger (sym, &acknowledge_static_array_drul_[STOP]);	\
  }									\
  SCM									\
  classname::static_translator_description () const			\
  {									\
    SCM static_properties = SCM_EOL;					\
    /*  static_properties = acons (name , gh_str02scm (Translator::name (self_scm ())),	\
	static_properties_);						\
    */									\
    static_properties = scm_acons (ly_symbol2scm ("grobs-created"),	\
				   parse_symbol_list (grobs), static_properties); \
									\
    static_properties = scm_acons (ly_symbol2scm ("description"),	\
				   scm_makfrom0str (desc), static_properties); \
									\
    static_properties = scm_acons (ly_symbol2scm ("events-accepted"),	\
				   parse_symbol_list (accepted), static_properties); \
									\
    static_properties = scm_acons (ly_symbol2scm ("properties-read"),	\
				   parse_symbol_list (read), static_properties); \
									\
    static_properties = scm_acons (ly_symbol2scm ("properties-written"), \
				   parse_symbol_list (write), static_properties); \
									\
    return static_properties;						\
  }

#define IMPLEMENT_FETCH_PRECOMPUTABLE_METHODS(T)			\
  void									\
  T::fetch_precomputable_methods (Translator_void_method_ptr ptrs[])	\
  {									\
    ptrs[START_TRANSLATION_TIMESTEP] =					\
      ((Translator_void_method_ptr) & T::start_translation_timestep ==	\
       (Translator_void_method_ptr) & Translator::start_translation_timestep) \
      ? 0								\
      : (Translator_void_method_ptr) & T::start_translation_timestep;	\
									\
    ptrs[STOP_TRANSLATION_TIMESTEP] =					\
      ((Translator_void_method_ptr) & T::stop_translation_timestep == (Translator_void_method_ptr) & Translator::stop_translation_timestep) \
      ? 0								\
      : (Translator_void_method_ptr) & T::stop_translation_timestep;	\
									\
    ptrs[PROCESS_MUSIC] =						\
      ((Translator_void_method_ptr) & T::process_music == (Translator_void_method_ptr) & Translator::process_music) \
      ? 0								\
      : (Translator_void_method_ptr) & T::process_music;		\
									\
    ptrs[PROCESS_ACKNOWLEDGED] =					\
      ((Translator_void_method_ptr) & T::process_acknowledged == (Translator_void_method_ptr) & Translator::process_acknowledged) \
      ? 0								\
      : (Translator_void_method_ptr) & T::process_acknowledged;		\
  }

void add_acknowledger (Engraver_void_function_engraver_grob_info ptr,
		       char const *func_name,
		       vector<Acknowledge_information> *ack_array);

Engraver_void_function_engraver_grob_info
generic_get_acknowledger (SCM sym,
			  vector<Acknowledge_information> const *ack_array);

#define ADD_ACKNOWLEDGER(CLASS, NAME)					\
  void CLASS ## NAME ## _ack_adder ()					\
  {									\
    add_acknowledger ((Engraver_void_function_engraver_grob_info) & CLASS::acknowledge_ ## NAME, #NAME, &CLASS::acknowledge_static_array_drul_[START]); \
  }									\
  ADD_SCM_INIT_FUNC (CLASS ## NAME ## _ack_adder_initclass, CLASS ## NAME ## _ack_adder);

#define ADD_END_ACKNOWLEDGER(CLASS, NAME)					\
  void CLASS ## NAME ## _end_ack_adder ()					\
  {									\
    add_acknowledger ((Engraver_void_function_engraver_grob_info) & CLASS::acknowledge_end_ ## NAME, #NAME, &CLASS::acknowledge_static_array_drul_[STOP]); \
  }									\
  ADD_SCM_INIT_FUNC (CLASS ## NAME ## _end_ack_adder_initclass, CLASS ## NAME ## _end_ack_adder);

/*
  Implement the method cl::listen_##m, and make it listen to stream 
  events of class m.
 */
#define IMPLEMENT_TRANSLATOR_LISTENER(cl, m)		\
void							\
cl :: _internal_declare_ ## m ()			\
{							\
  static translator_listener_record r;			\
  add_translator_listener (&listener_list_, &r, _get_ ## m ## _listener, #m); \
}							\
							\
ADD_SCM_INIT_FUNC (cl ## _declare_event_ ## m, cl::_internal_declare_ ## m);	\
							\
Listener						\
cl :: _get_ ## m ## _listener (void *me)		\
{							\
  cl *obj = (cl *) me;					\
  return obj->GET_LISTENER (_listen_scm_ ## m);		\
}							\
							\
IMPLEMENT_LISTENER (cl, _listen_scm_ ## m)		\
void							\
cl::_listen_scm_ ## m (SCM sev)				\
{							\
  Stream_event *ev = unsmob_stream_event (sev);		\
  protect_event (sev);					\
  listen_ ## m (ev);					\
}

/*
  This helper is only meaningful inside listen_* methods.
*/
extern bool internal_event_assignment (Stream_event **old_ev, Stream_event *new_ev, const char *function);
#define ASSIGN_EVENT_ONCE(o,n) internal_event_assignment (&o, n, __FUNCTION__)

#endif /* TRANSLATOR_ICC */