+
+
+Music *
+run_music_function (Lily_parser *parser, SCM expr)
+{
+ SCM func = scm_car (expr);
+ Input *loc = unsmob_input (scm_cadr (expr));
+ SCM args = scm_cddr (expr);
+ SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
+
+ SCM type_check_proc = ly_lily_module_constant ("type-check-list");
+ bool ok = true;
+
+ if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
+ {
+ parser->error_level_ = 1;
+ ok = false;
+ }
+
+ SCM m = SCM_EOL;
+ if (ok)
+ m = scm_apply_0 (func, scm_cons (parser->self_scm(),
+ scm_cdr (expr)));
+
+
+ Music* retval = 0;
+ if (unsmob_music (m))
+ {
+ retval = unsmob_music (m);
+ retval->protect ();
+ }
+ else
+ {
+ if (ok)
+ loc->error (_ ("music head function must return Music object"));
+ retval = MY_MAKE_MUSIC ("Music");
+ }
+ retval->set_spot (*loc);
+ return retval;
+}
+
+bool
+is_regular_identifier (SCM id)
+{
+ std::string str = ly_scm2string (id);
+ char const *s = str.c_str ();
+
+ bool v = true;
+#if 0
+ isalpha (*s);
+ s++;
+#endif
+ while (*s && v)
+ {
+ v = v && isalnum (*s);
+ s++;
+ }
+ return v;
+}
+
+
+SCM
+get_first_context_id (SCM type, Music *m)
+{
+ SCM id = m->get_property ("context-id");
+ if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
+ && scm_is_string (m->get_property ("context-id"))
+ && scm_c_string_length (id) > 0)
+ {
+ return id;
+ }
+ return SCM_EOL;
+}
+
+SCM
+make_simple_markup (SCM a)
+{
+ return a;
+}
+
+bool
+is_duration (int t)
+{
+ return t && t == 1 << intlog2 (t);
+}
+
+void
+set_music_properties (Music *p, SCM a)
+{
+ for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
+ p->internal_set_property (scm_caar (k), scm_cdar (k));
+}
+
+
+SCM
+make_chord_step (int step, int alter)
+{
+ if (step == 7)
+ alter += FLAT;
+
+ while (step < 0)
+ step += 7;
+ Pitch m ((step -1) / 7, (step - 1) % 7, alter);
+ return m.smobbed_copy ();
+}
+
+
+SCM
+make_chord (SCM pitch, SCM dur, SCM modification_list)
+{
+ SCM chord_ctor = ly_lily_module_constant ("construct-chord");
+ SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
+
+ unsmob_music (ch)->protect();
+ return ch;
+}
+
+
+/* Todo: actually also use apply iso. call too ... */
+bool
+ly_input_procedure_p (SCM x)
+{
+ return ly_is_procedure (x)
+ || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
+}
+
+Music*
+set_property_music (SCM sym, SCM value)
+{
+ Music *p = MY_MAKE_MUSIC ("PropertySet");
+ p->set_property ("symbol", sym);
+ p->set_property ("value", value);
+ return p;
+}
+
+Music*
+make_music_relative (Pitch start, Music *music)
+{
+ Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
+ relative->set_property ("element", music->self_scm ());
+
+ Pitch last = music->to_relative_octave (start);
+ if (lily_1_8_relative)
+ music->set_property ("last-pitch", last.smobbed_copy ());
+ return relative;
+}
+
+Music *
+make_lyric_combine_music (SCM name, Music *music)
+{
+ Music *combine = MY_MAKE_MUSIC ("LyricCombineMusic");
+ combine->set_property ("element", music->self_scm ());
+ combine->set_property ("associated-context", name);
+ return combine;
+}
+
+
+int
+yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
+{
+ Lily_parser *pars = (Lily_parser*) v;
+ Lily_lexer *lex = pars->lexer_;
+
+ lex->lexval = (void*) s;
+ lex->lexloc = loc;
+ lex->prepare_for_next_token ();
+ return lex->yylex ();
+}