]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
*** empty log message ***
[lilypond.git] / lily / parser.yy
1 %{ // -*-Fundamental-*-
2
3 /*
4   parser.yy -- Bison/C++ parser for lilypond
5
6   source file of the GNU LilyPond music typesetter
7
8   (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9            Jan Nieuwenhuizen <janneke@gnu.org>
10 */
11
12 /*
13   Two shift/reduce problems:
14     - empty music-list
15     - empty pre-events
16
17
18
19 (bullshit.
20
21 s/r:
22
23 1.      foo = bar.
24
25         "bar" -> String -> Lyric -> Music
26
27         "bar" -> String
28
29
30 2.  \repeat
31         \repeat .. \alternative
32
33
34     \repeat { \repeat .. \alternative }
35
36 or
37
38     \repeat { \repeat } \alternative 
39
40 )
41
42 --hwn
43
44  */
45
46 /*
47
48 TODO:
49
50 * The rules for who is protecting what are very shady. Uniformise
51   this.
52
53 * There are too many lexical modes. 
54
55
56 */
57
58 #include <ctype.h>
59
60 #include "translator-def.hh"
61 #include "lily-guile.hh"
62 #include "misc.hh"
63 #include "my-lily-lexer.hh"
64 #include "paper-def.hh"
65 #include "midi-def.hh"
66 #include "main.hh"
67 #include "file-path.hh"
68 #include "warn.hh"
69 #include "dimensions.hh"
70 #include "my-lily-parser.hh"
71 #include "score.hh"
72 #include "input-file-results.hh"
73 #include "input.hh"
74 #include "lilypond-input-version.hh"
75 #include "scm-hash.hh"
76 #include "auto-change-iterator.hh"
77 #include "chord.hh"
78 #include "ly-modules.hh"
79 #include "music-sequence.hh"
80 #include "input-smob.hh"
81 #include "event.hh"
82
83 bool
84 regular_identifier_b (SCM id)
85 {
86   String str = ly_scm2string (id);
87   char const *s = str.to_str0 () ;
88
89   bool v = true;
90   while (*s && v)
91    {
92         v = v && isalpha (*s);
93         s++;
94    }
95   return v;
96 }
97
98
99
100 bool
101 is_duration_b (int t)
102 {
103   return t && t == 1 << intlog2 (t);
104 }
105
106 void
107 set_music_properties (Music *p, SCM a)
108 {
109   for (SCM k = a; gh_pair_p (k); k = ly_cdr (k))
110         {
111         p->internal_set_mus_property (ly_caar (k), ly_cdar (k));
112         }
113 }
114
115
116
117 #define MY_MAKE_MUSIC(x)  make_music_by_name (ly_symbol2scm (x))
118
119 Music* 
120 set_property_music (SCM sym, SCM value)
121 {
122         Music * p = MY_MAKE_MUSIC("PropertySet");
123         p->set_mus_property ("symbol", sym);
124         p->set_mus_property ("value", value);
125         return p;
126 }
127
128
129 // needed for bison.simple's malloc () and free ()
130
131 // #include <malloc.h>
132 #include <stdlib.h>
133
134
135
136 #define YYERROR_VERBOSE 1
137
138 My_lily_parser* my_lily_parser;
139 #define YYPARSE_PARAM my_lily_parser
140 #define YYLEX_PARAM my_lily_parser
141 #define THIS\
142         ((My_lily_parser *) my_lily_parser)
143
144 #define yyerror THIS->parser_error
145
146 %}
147
148 /* We use SCMs to do strings, because it saves us the trouble of
149 deleting them.  Let's hope that a stack overflow doesnt trigger a move
150 of the parse stack onto the heap. */
151
152
153 %union {
154         String * string;
155     Music *music;
156     Score *score;
157     Music_output_def * outputdef;
158     SCM scm;
159     int i;
160 }
161 %{
162
163 int
164 yylex (YYSTYPE *s,  void * v)
165 {
166         My_lily_parser   *pars = (My_lily_parser*) v;
167         My_lily_lexer * lex = pars->lexer_;
168
169         lex->lexval = (void*) s;
170         lex->prepare_for_next_token();
171         return lex->yylex ();
172 }
173
174
175 %}
176
177 %pure_parser
178
179 /* tokens which are not keywords */
180 %token AUTOCHANGE
181 %token ALIAS
182 %token APPLY
183 %token ACCEPTS
184 %token ALTERNATIVE
185 %token BAR
186 %token BREATHE
187 %token CHORDMODIFIERS
188 %token CHORDS
189 %token CLEF
190 %token CONSISTS
191 %token DURATION
192 %token SEQUENTIAL
193 %token GROBDESCRIPTIONS
194 %token SIMULTANEOUS
195 %token CONSISTSEND
196 %token DENIES
197 %token EXTENDER
198 %token FIGURES FIGURE_OPEN FIGURE_CLOSE
199 %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
200 %token GRACE 
201 %token HEADER
202 %token HYPHEN
203 %token INVALID
204 %token KEY
205 %token LYRICS
206 %token MARK
207 %token MULTI_MEASURE_REST
208 %token MIDI
209 %token PITCH
210 %token DEFAULT
211 %token NAME
212 %token PITCHNAMES
213 %token NOTES
214 %token ONCE
215 %token PAPER
216 %token PARTIAL
217 %token PROPERTY
218 %token OVERRIDE SET REVERT 
219 %token RELATIVE
220 %token REMOVE
221 %token REPEAT
222 %token ADDLYRICS
223 %token PARTCOMBINE
224 %token SCM_T
225 %token SCORE
226 %token SKIP
227 %token SPANREQUEST
228 %token COMMANDSPANREQUEST
229 %token TEMPO
230 %token OUTPUTPROPERTY
231 %token TIME_T
232 %token TIMES
233 %token TRANSLATOR
234 %token TRANSPOSE
235 %token TYPE
236 %token UNSET
237 %token CONTEXT
238 %token REST
239
240 %token CHORD_OPEN
241 %token CHORD_CLOSE
242
243
244 /* escaped */
245 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
246 %token E_LEFTSQUARE E_RIGHTSQUARE E_TILDE
247 %token E_BACKSLASH
248 %token <i> E_UNSIGNED
249 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET  CHORD_SLASH
250 %token FIGURE_SPACE
251
252 %type <i>       exclamations questions dots optional_rest
253 %type <i>       bass_number bass_mod
254 %type <scm>     br_bass_figure bass_figure figure_list figure_spec
255 %token <i>      DIGIT
256 %token <scm>    NOTENAME_PITCH
257 %token <scm>    TONICNAME_PITCH
258 %token <scm>    CHORDMODIFIER_PITCH
259 %token <scm>    DURATION_IDENTIFIER
260 %token <scm>    FRACTION
261 %token <id>     IDENTIFIER
262
263
264 %token <scm>    SCORE_IDENTIFIER
265 %token <scm>    MUSIC_OUTPUT_DEF_IDENTIFIER
266 %token <scm>    NUMBER_IDENTIFIER
267 %token <scm>    EVENT_IDENTIFIER
268 %token <scm>    MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
269 %token <scm>    STRING_IDENTIFIER SCM_IDENTIFIER 
270 %token <scm>    RESTNAME
271 %token <scm>    STRING   
272 %token <scm>    SCM_T
273 %token <i>      UNSIGNED
274 %token <scm>   REAL
275
276 %type <outputdef> output_def
277 %type <scm>     lilypond_header lilypond_header_body
278 %type <music>   open_event_parens close_event_parens open_event close_event
279 %type <music> event_with_dir event_that_take_dir verbose_event
280 %type <i>       sub_quotes sup_quotes
281 %type <music>   simple_element  event_chord command_element Simple_music  Composite_music 
282 %type <music>   Repeated_music
283 %type <scm>     Alternative_music
284 %type <i>       tremolo_type
285 %type <i>       bare_int  bare_unsigned
286 %type <i>       script_dir
287 %type <scm>     identifier_init 
288
289 %type <music> note_chord_element chord_body chord_body_element
290 %type <scm>  chord_body_elements 
291 %type <scm> steno_duration optional_notemode_duration multiplied_duration
292 %type <scm>  verbose_duration
293         
294 %type <scm>  pre_events post_events
295 %type <music> gen_text_def
296 %type <scm>   steno_pitch pitch absolute_pitch
297 %type <scm>   explicit_pitch steno_tonic_pitch
298
299 %type <scm>     chord_additions chord_subtractions chord_notes chord_step
300 %type <music>   chord
301 %type <scm>     chord_note chord_inversion chord_bass
302 %type <scm>     duration_length fraction
303
304 %type <scm>  embedded_scm scalar
305 %type <music>   Music Sequential_music Simultaneous_music 
306 %type <music>   relative_music re_rhythmed_music part_combined_music
307 %type <music>   property_def translator_change  simple_property_def
308 %type <scm> Music_list
309 %type <outputdef>  music_output_def_body
310 %type <music> shorthand_command_req
311 %type <music>   post_event 
312 %type <music> command_req verbose_command_req
313 %type <music>   extender_req
314 %type <music> hyphen_req
315 %type <music> string_event
316 %type <scm>     string bare_number number_expression number_term number_factor 
317 %type <score>   score_block score_body
318
319 %type <scm>     translator_spec_block translator_spec_body
320 %type <music>   tempo_event
321 %type <scm> notenames_body notenames_block chordmodifiers_block
322 %type <scm>     script_abbreviation
323
324
325
326 %left '-' '+'
327
328 /* We don't assign precedence to / and *, because we might need varied
329 prec levels in different prods */
330
331 %left UNARY_MINUS
332
333 %%
334
335 lilypond:       /* empty */
336         | lilypond toplevel_expression {}
337         | lilypond assignment  { }
338         | lilypond error {
339                 THIS->error_level_  = 1;
340         }
341         | lilypond INVALID      {
342                 THIS->error_level_  = 1;
343         }
344         ;
345
346 toplevel_expression:
347         notenames_block                 {
348                 THIS->lexer_->pitchname_tab_ =  $1;
349         }
350         | chordmodifiers_block                  {
351                 THIS->lexer_->chordmodifier_tab_  = $1;
352         }
353         | lilypond_header {
354                 THIS->input_file_->header_ = $1;
355         }
356         | score_block {
357                 THIS->input_file_->scores_.push ($1);
358         }
359         | output_def {
360                 if (dynamic_cast<Paper_def*> ($1))
361                         THIS->lexer_->set_identifier (scm_makfrom0str ("$defaultpaper"), $1->self_scm ());
362                 else if (dynamic_cast<Midi_def*> ($1))
363                         THIS->lexer_->set_identifier (scm_makfrom0str ("$defaultmidi"), $1->self_scm ());
364         }
365         ;
366
367 embedded_scm:
368         SCM_T
369         | SCM_IDENTIFIER 
370         ;
371
372
373 chordmodifiers_block:
374         CHORDMODIFIERS notenames_body   {  $$ = $2; }
375         ;
376
377 notenames_block:
378         PITCHNAMES notenames_body   {  $$ = $2; }
379         ;
380
381 notenames_body:
382         embedded_scm    {
383           int i = scm_ilength ($1);
384
385           SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
386           for (SCM s = $1; gh_pair_p (s); s = ly_cdr (s)) {
387                 SCM pt = ly_cdar (s);
388                 if (!unsmob_pitch (pt))
389                         THIS->parser_error ("Need pitch object.");
390                 else
391                         scm_hashq_set_x (tab, ly_caar (s), pt);
392           }
393
394           $$ = tab;
395         }
396         ;
397
398 lilypond_header_body:
399         {
400                 $$ = ly_make_anonymous_module (); 
401                 THIS->lexer_->add_scope ($$);
402         }
403         | lilypond_header_body assignment  { 
404                 
405         }
406         ;
407
408 lilypond_header:
409         HEADER '{' lilypond_header_body '}'     {
410                 $$ = THIS->lexer_-> remove_scope();
411         }
412         ;
413
414
415 /*
416         DECLARATIONS
417 */
418 assignment:
419         STRING {
420                 THIS->push_spot ();
421         }
422         /* cont */ '=' identifier_init  {
423
424         /*
425                 Should find generic way of associating input with objects.
426         */
427                 Input ip = THIS->pop_spot ();
428
429                 if (! regular_identifier_b ($1))
430                 {
431                         ip.warning (_ ("Identifier should have alphabetic characters only"));
432                 }
433
434                 THIS->lexer_->set_identifier ($1, $4);
435
436 /*
437  TODO: devise standard for protection in parser.
438
439   The parser stack lives on the C-stack, which means that
440 all objects can be unprotected as soon as they're here.
441
442 */
443         }
444         | embedded_scm { }
445         ;
446
447
448
449 identifier_init:
450         score_block {
451                 $$ = $1->self_scm ();
452                 scm_gc_unprotect_object ($$);
453         }
454         | output_def {
455                 $$ = $1->self_scm ();
456                 scm_gc_unprotect_object ($$);
457         }
458         | translator_spec_block {
459                 $$ = $1;
460         }
461         | Music  {
462                 $$ = $1->self_scm ();
463                 scm_gc_unprotect_object ($$);
464         }
465         | post_event {
466                 $$ = $1->self_scm ();
467                 scm_gc_unprotect_object ($$);
468         }
469         | verbose_duration {
470                 $$ = $1;
471         }
472         | number_expression {
473                 $$ = $1;
474         }
475         | string {
476                 $$ = $1;
477         }
478         | embedded_scm  {
479                 $$ = $1;
480         }
481         ;
482
483 translator_spec_block:
484         TRANSLATOR '{' translator_spec_body '}'
485                 {
486                 $$ = $3;
487         }
488         ;
489
490 translator_spec_body:
491         TRANSLATOR_IDENTIFIER   {
492                 $$ = $1;
493                 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
494         }
495         | TYPE STRING   {
496                 $$ = Translator_def::make_scm ();
497                 Translator_def*td =  unsmob_translator_def ($$);
498                 td->translator_group_type_ = $2;
499                 td->set_spot (THIS->here_input ());
500         }
501         | translator_spec_body STRING '=' embedded_scm                  {
502                 unsmob_translator_def ($$)->add_property_assign ($2, $4);
503         }
504         | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
505                 unsmob_translator_def ($$)
506                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
507         }
508         | translator_spec_body STRING SET embedded_scm '=' embedded_scm {
509                 unsmob_translator_def ($$)
510                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
511         }
512         | translator_spec_body STRING REVERT embedded_scm  {
513           unsmob_translator_def ($$)->add_pop_property (
514                 scm_string_to_symbol ($2), $4);
515         }
516         | translator_spec_body NAME STRING  {
517                 unsmob_translator_def ($$)->type_name_ = $3;
518         }
519         | translator_spec_body CONSISTS STRING  {
520                 unsmob_translator_def ($$)->add_element ($3);
521         }
522         | translator_spec_body ALIAS STRING  {
523                 Translator_def*td = unsmob_translator_def ($$);
524                 td->type_aliases_ = scm_cons ($3, td->type_aliases_);
525         }
526         | translator_spec_body GROBDESCRIPTIONS embedded_scm {
527                 Translator_def*td = unsmob_translator_def($$);
528                 // td->add_property_assign (ly_symbol2scm ("allGrobDescriptions"), $3);
529                 for (SCM p = $3; gh_pair_p (p); p = ly_cdr (p))
530                         td->add_property_assign (scm_symbol_to_string (ly_caar (p)), ly_cdar (p));
531         }
532         | translator_spec_body CONSISTSEND STRING  {
533                 unsmob_translator_def ($$)->add_last_element ( $3);
534         }
535         | translator_spec_body ACCEPTS STRING  {
536                 unsmob_translator_def ($$)->set_acceptor ($3,true);
537         }
538         | translator_spec_body DENIES STRING  {
539                 unsmob_translator_def ($$)->set_acceptor ($3,false);
540         }
541         | translator_spec_body REMOVE STRING  {
542                 unsmob_translator_def ($$)->remove_element ($3);
543         }
544         ;
545
546 /*
547         SCORE
548 */
549 score_block:
550         SCORE { 
551                 THIS->push_spot ();
552         }
553         /*cont*/ '{' score_body '}'     {
554                 THIS->pop_spot ();
555                 $$ = $4;
556                 if (!$$->defs_.size ())
557                 {
558                   Music_output_def *id =
559                         unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
560                   $$->add_output (id ? id->clone () :  new Paper_def );
561                 }
562         }
563         ;
564
565 score_body:
566         Music   {
567                 $$ = new Score;
568         
569                 $$->set_spot (THIS->here_input ());
570                 SCM m = $1->self_scm ();
571                 scm_gc_unprotect_object (m);
572
573                 /*
574                         guh.
575                 */
576                 SCM check_funcs = scm_c_eval_string ("toplevel-music-functions");
577                 for (; gh_pair_p (check_funcs); check_funcs = gh_cdr (check_funcs))
578                         m = gh_call1 (gh_car (check_funcs), m);
579                 $$->music_ = m;
580
581         }
582         | SCORE_IDENTIFIER {
583                 $$ = unsmob_score ($1);
584                 $$->set_spot (THIS->here_input ());
585         }
586         | score_body lilypond_header    {
587                 $$->header_ = $2;
588         }
589         | score_body output_def {
590                 $$->add_output ($2);
591         }
592         | score_body error {
593
594         }
595         ;
596
597
598 /*
599         MIDI
600 */
601 output_def:
602         music_output_def_body '}' {
603                 $$ = $1;
604                 THIS-> lexer_-> remove_scope ();
605         }
606         ;
607
608 music_output_def_body:
609         MIDI '{'    {
610                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi"));
611
612
613                 Midi_def* p =0;
614                 if (id)
615                         p = dynamic_cast<Midi_def*> (id->clone ());
616                 else
617                         p = new Midi_def;
618
619                 $$ = p;
620                 THIS->lexer_->add_scope (p->scope_);
621         }
622         | PAPER '{'     {
623                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
624                   Paper_def *p = 0;
625                 if (id)
626                         p = dynamic_cast<Paper_def*> (id->clone ());
627                 else
628                         p = new Paper_def;
629
630                 THIS->lexer_->add_scope (p->scope_);
631                 $$ = p;
632         }
633         | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER         {
634                 Music_output_def * o =  unsmob_music_output_def ($3);
635                 $$ =o;
636
637                 THIS->lexer_->add_scope (o->scope_);
638         }
639         | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER  {
640                 Music_output_def * o =  unsmob_music_output_def ($3);
641                 $$ = o;
642
643                 THIS->lexer_->add_scope (o->scope_);
644         }
645         | music_output_def_body assignment  {
646
647         }
648         | music_output_def_body translator_spec_block   {
649                 $$->assign_translator ($2);
650         }
651         | music_output_def_body tempo_event  {
652                 /*
653                         junk this ? there already is tempo stuff in
654                         music.
655                 */
656                 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
657                 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
658                 Midi_def * md = dynamic_cast<Midi_def*> ($$);
659                 if (md)
660                         md->set_tempo (d->get_length (), m);
661         }
662         | music_output_def_body error {
663
664         }
665         ;
666
667 tempo_event:
668         TEMPO steno_duration '=' bare_unsigned  {
669                 $$ = MY_MAKE_MUSIC("TempoEvent");
670                 $$->set_mus_property ("duration", $2);
671                 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
672         }
673         ;
674
675 /*
676 The representation of a  list is the
677
678   (LIST . LAST-CONS)
679
680  to have  efficient append.
681 */
682 Music_list: /* empty */ {
683                 $$ = scm_cons (SCM_EOL, SCM_EOL);
684         }
685         | Music_list Music {
686                 SCM s = $$;
687                 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
688                 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
689                 if (gh_pair_p (ly_cdr (s)))
690                         gh_set_cdr_x (ly_cdr (s), c); /* append */
691                 else
692                         gh_set_car_x (s, c); /* set first cons */
693                 gh_set_cdr_x (s, c) ;  /* remember last cell */ 
694         }
695         | Music_list error {
696         }
697         ;
698
699
700 Music:
701         Simple_music
702         | Composite_music
703         ;
704
705 Alternative_music:
706         /* empty */ {
707                 $$ = SCM_EOL;
708         }
709         | ALTERNATIVE '{' Music_list '}' {
710                 $$ = $3;
711         }
712         ;
713
714 Repeated_music:
715         REPEAT string bare_unsigned Music Alternative_music
716         {
717                 Music *beg = $4;
718                 int times = $3;
719                 SCM alts = gh_pair_p ($5) ? gh_car ($5) : SCM_EOL;
720                 if (times < scm_ilength (alts)) {
721                   unsmob_music (gh_car (alts))
722                     ->origin ()->warning (
723                     _("More alternatives than repeats.  Junking excess alternatives."));
724                   alts = ly_truncate_list (times, alts);
725                 }
726
727
728                 static SCM proc;
729                 if (!proc)
730                         proc = scm_c_eval_string ("make-repeated-music");
731
732                 SCM mus = scm_call_1 (proc, $2);
733                 scm_gc_protect_object (mus); // UGH. 
734                 Music *r =unsmob_music (mus);
735                 if (beg)
736                         {
737                         r-> set_mus_property ("element", beg->self_scm ());
738                         scm_gc_unprotect_object (beg->self_scm ());
739                         }
740                 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
741
742                 r-> set_mus_property ("elements",alts);
743                 if (gh_equal_p ($2, scm_makfrom0str ("tremolo")))
744                 {
745                 /*
746                 we can not get durations and other stuff correct down the line, so we have to
747                 add to the duration log here.
748                 */
749                         SCM func = scm_primitive_eval (ly_symbol2scm ("shift-duration-log"));
750                         if (($3 % 3) == 0)
751                           gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3*2/3)),gh_int2scm(1));
752                         else
753                           gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3)), gh_int2scm(0));
754                 }
755                 r->set_spot (*$4->origin ());
756
757                 $$ = r;
758         }
759         ;
760
761 Sequential_music:
762         SEQUENTIAL '{' Music_list '}'           {
763                 $$ = MY_MAKE_MUSIC("SequentialMusic");
764                 $$->set_mus_property ("elements", ly_car ($3));
765                 $$->set_spot(THIS->here_input());
766         }
767         | '{' Music_list '}'            {
768                 $$ = MY_MAKE_MUSIC("SequentialMusic");
769                 $$->set_mus_property ("elements", ly_car ($2));
770                 $$->set_spot(THIS->here_input());
771         }
772         ;
773
774 Simultaneous_music:
775         SIMULTANEOUS '{' Music_list '}'{
776                 $$ = MY_MAKE_MUSIC("SimultaneousMusic");
777                 $$->set_mus_property ("elements", ly_car ($3));
778                 $$->set_spot(THIS->here_input());
779
780         }
781         | '<' Music_list '>'    {
782                 $$ = MY_MAKE_MUSIC("SimultaneousMusic");
783                 $$->set_mus_property ("elements", ly_car ($2));
784                 $$->set_spot(THIS->here_input());
785         }
786         ;
787
788 Simple_music:
789         event_chord             { $$ = $1; }
790         | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm     {
791                 SCM pred = $2;
792                 if (!gh_symbol_p ($3))
793                 {
794                         THIS->parser_error (_ ("Second argument must be a symbol")); 
795                 }
796                 /* Should check # args */
797                 if (!gh_procedure_p (pred))
798                 {
799                         THIS->parser_error (_ ("First argument must be a procedure taking one argument"));
800                 }
801
802                 Music*m = MY_MAKE_MUSIC("OutputPropertySetMusic");
803                 m->set_mus_property ("predicate", pred);
804                 m->set_mus_property ("grob-property", $3);
805                 m->set_mus_property ("grob-value",  $5);
806
807                 $$ = m;
808         }
809         | MUSIC_IDENTIFIER {
810                 $$ = unsmob_music ($1);
811         }
812         | property_def
813         | translator_change
814         ;
815
816
817 Composite_music:
818         CONTEXT STRING Music    {
819                 Music*csm =MY_MAKE_MUSIC("ContextSpeccedMusic");
820
821                 csm->set_mus_property ("element", $3->self_scm ());
822                 scm_gc_unprotect_object ($3->self_scm ());
823
824                 csm->set_mus_property ("context-type",$2);
825                 csm->set_mus_property ("context-id", scm_makfrom0str (""));
826
827                 $$ = csm;
828         }
829         | AUTOCHANGE STRING Music       {
830         Music*chm = MY_MAKE_MUSIC("AutoChangeMusic");
831                 chm->set_mus_property ("element", $3->self_scm ());
832                 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_proc);
833
834                 scm_gc_unprotect_object ($3->self_scm ());
835                 chm->set_mus_property ("what", $2); 
836
837                 $$ = chm;
838                 chm->set_spot (*$3->origin ());
839         }
840         | GRACE Music {
841 #if 1
842         /*
843                 The other version is for easier debugging  of
844                 Sequential_music_iterator in combination with grace notes.
845         */
846
847                 SCM start = THIS->lexer_->lookup_identifier ("startGraceMusic");
848                 SCM stop = THIS->lexer_->lookup_identifier ("stopGraceMusic");
849                 Music *startm = unsmob_music (start);
850                 Music *stopm = unsmob_music (stop);
851
852                 SCM ms = SCM_EOL;
853                 if (stopm) {
854                         stopm = stopm->clone ();
855                         ms = scm_cons (stopm->self_scm (), ms);
856                         scm_gc_unprotect_object (stopm->self_scm ());
857                 }
858                 ms = scm_cons ($2->self_scm (), ms);
859                 scm_gc_unprotect_object ($2->self_scm());
860                 if (startm) {
861                         startm = startm->clone ();
862                         ms = scm_cons (startm->self_scm () , ms);
863                         scm_gc_unprotect_object (startm->self_scm ());
864                 }
865
866         
867                 Music* seq = MY_MAKE_MUSIC("SequentialMusic");
868                 seq->set_mus_property ("elements", ms);
869
870                 
871                 $$ = MY_MAKE_MUSIC("GraceMusic");
872                 $$->set_mus_property ("element", seq->self_scm ());
873                 scm_gc_unprotect_object (seq->self_scm ());
874 #else
875                 $$ = MY_MAKE_MUSIC("GraceMusic");
876                 $$->set_mus_property ("element", $2->self_scm ());
877                 scm_gc_unprotect_object ($2->self_scm ());
878 #endif
879         }
880         | CONTEXT string '=' string Music {
881                 Music * csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
882
883                 csm->set_mus_property ("element", $5->self_scm ());
884                 scm_gc_unprotect_object ($5->self_scm ());
885
886                 csm->set_mus_property ("context-type", $2);
887                 csm->set_mus_property ("context-id", $4);
888
889                 $$ = csm;
890         }
891         | TIMES {
892                 THIS->push_spot ();
893         }
894         /* CONTINUED */ 
895                 fraction Music  
896
897         {
898                 int n = gh_scm2int (ly_car ($3)); int d = gh_scm2int (ly_cdr ($3));
899                 Music *mp = $4;
900         $$= MY_MAKE_MUSIC("TimeScaledMusic");
901                 $$->set_spot (THIS->pop_spot ());
902
903
904                 $$->set_mus_property ("element", mp->self_scm ());
905                 scm_gc_unprotect_object (mp->self_scm ());
906                 $$->set_mus_property ("numerator", gh_int2scm (n));
907                 $$->set_mus_property ("denominator", gh_int2scm (d));
908                 $$->compress (Moment (Rational (n,d)));
909
910         }
911         | Repeated_music                { $$ = $1; }
912         | Simultaneous_music            { $$ = $1; }
913         | Sequential_music              { $$ = $1; }
914         | TRANSPOSE pitch Music {
915                 $$ = MY_MAKE_MUSIC("TransposedMusic");
916                 Music *p = $3;
917                 Pitch pit = *unsmob_pitch ($2);
918
919                 p->transpose (pit);
920                 $$->set_mus_property ("element", p->self_scm ());
921                 scm_gc_unprotect_object (p->self_scm ());
922         }
923         | TRANSPOSE steno_tonic_pitch Music {
924                 $$ = MY_MAKE_MUSIC("TransposedMusic");
925                 Music *p = $3;
926                 Pitch pit = *unsmob_pitch ($2);
927
928                 p->transpose (pit);
929                 $$->set_mus_property ("element", p->self_scm ());
930                 scm_gc_unprotect_object (p->self_scm ());
931         
932         }
933         | APPLY embedded_scm Music  {
934                 SCM ret = gh_call1 ($2, $3->self_scm ());
935                 Music *m = unsmob_music (ret);
936                 if (!m) {
937                         THIS->parser_error ("\\apply must return a Music");
938                         m = MY_MAKE_MUSIC("Music");
939                         }
940                 $$ = m;
941         }
942         | NOTES
943                 { THIS->lexer_->push_note_state (); }
944         Music
945                 { $$ = $3;
946                   THIS->lexer_->pop_state ();
947                 }
948         | FIGURES
949                 { THIS->lexer_->push_figuredbass_state (); }
950         Music
951                 {
952                   Music * chm = MY_MAKE_MUSIC("UntransposableMusic");
953                   chm->set_mus_property ("element", $3->self_scm ());
954                   $$ = chm;
955                   scm_gc_unprotect_object ($3->self_scm());
956
957                   THIS->lexer_->pop_state ();
958         }
959         | CHORDS
960                 { THIS->lexer_->push_chord_state (); }
961         Music
962                 {
963                   Music * chm = MY_MAKE_MUSIC("UnrelativableMusic");
964                   chm->set_mus_property ("element", $3->self_scm ());
965                   scm_gc_unprotect_object ($3->self_scm());
966                   $$ = chm;
967
968                   THIS->lexer_->pop_state ();
969         }
970         | LYRICS
971                 { THIS->lexer_->push_lyric_state (); }
972         Music
973                 {
974                   $$ = $3;
975                   THIS->lexer_->pop_state ();
976         }
977         | relative_music        { $$ = $1; }
978         | re_rhythmed_music     { $$ = $1; } 
979         | part_combined_music   { $$ = $1; } 
980         ;
981
982 relative_music:
983         RELATIVE absolute_pitch Music {
984                 Music * p = $3;
985                 Pitch pit = *unsmob_pitch ($2);
986                 $$ = MY_MAKE_MUSIC("RelativeOctaveMusic");
987
988                 $$->set_mus_property ("element", p->self_scm ());
989                 scm_gc_unprotect_object (p->self_scm ());
990
991                 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
992
993         }
994         ;
995
996 re_rhythmed_music:
997         ADDLYRICS Music Music {
998         Music*l =MY_MAKE_MUSIC("LyricCombineMusic");
999           l->set_mus_property ("elements", gh_list ($2->self_scm (), $3->self_scm (), SCM_UNDEFINED));
1000           scm_gc_unprotect_object ($3->self_scm ());
1001           scm_gc_unprotect_object ($2->self_scm ());
1002           $$ = l;
1003         }
1004         ;
1005
1006 part_combined_music:
1007         PARTCOMBINE STRING Music Music {
1008         Music * p= MY_MAKE_MUSIC("PartCombineMusic");
1009                 p->set_mus_property ("what", $2);
1010                 p->set_mus_property ("elements", gh_list ($3->self_scm (),$4->self_scm (), SCM_UNDEFINED));  
1011
1012                 scm_gc_unprotect_object ($3->self_scm ());
1013                 scm_gc_unprotect_object ($4->self_scm ());  
1014
1015                 $$ = p;
1016         }
1017         ;
1018
1019 translator_change:
1020         TRANSLATOR STRING '=' STRING  {
1021                 Music*t= MY_MAKE_MUSIC("TranslatorChange");
1022                 t-> set_mus_property ("change-to-type", $2);
1023                 t-> set_mus_property ("change-to-id", $4);
1024
1025                 $$ = t;
1026                 $$->set_spot (THIS->here_input ());
1027         }
1028         ;
1029
1030 property_def:
1031         simple_property_def
1032         | ONCE simple_property_def {
1033                 $$ = $2;
1034                 SCM e = $2->get_mus_property ("element");
1035                 unsmob_music (e)->set_mus_property ("once", SCM_BOOL_T);
1036         }
1037         ;
1038
1039 simple_property_def:
1040         PROPERTY STRING '.' STRING '='  scalar {
1041                 Music *t = set_property_music (scm_string_to_symbol ($4), $6);
1042                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1043
1044                 csm->set_mus_property ("element", t->self_scm ());
1045                 scm_gc_unprotect_object (t->self_scm ());
1046
1047                 $$ = csm;
1048                 $$->set_spot (THIS->here_input ());
1049
1050                 csm-> set_mus_property ("context-type", $2);
1051         }
1052         | PROPERTY STRING '.' STRING UNSET {
1053                 
1054                 Music *t = MY_MAKE_MUSIC("PropertyUnset");
1055                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1056
1057                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1058                 csm->set_mus_property ("element", t->self_scm ());
1059                 scm_gc_unprotect_object (t->self_scm ());
1060
1061                 $$ = csm;
1062                 $$->set_spot (THIS->here_input ());
1063
1064                 csm-> set_mus_property ("context-type", $2);
1065         }
1066         | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
1067                 bool autobeam
1068                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1069                 bool itc = internal_type_checking_global_b;
1070                 Music *t = MY_MAKE_MUSIC("OverrideProperty");
1071                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1072                 t->set_mus_property ("pop-first", SCM_BOOL_T);
1073                 if (autobeam)
1074                         internal_type_checking_global_b = false;
1075                 t->set_mus_property ("grob-property", $6);
1076                 if (autobeam)
1077                         internal_type_checking_global_b = itc;
1078                 t->set_mus_property ("grob-value", $8);
1079
1080                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1081                 csm->set_mus_property ("element", t->self_scm ());
1082                 scm_gc_unprotect_object (t->self_scm ());
1083                 $$ = csm;
1084                 $$->set_spot (THIS->here_input ());
1085
1086                 csm-> set_mus_property ("context-type", $2);
1087         }
1088         | PROPERTY STRING '.' STRING OVERRIDE
1089                 embedded_scm '=' embedded_scm
1090         {
1091                 /*
1092                         UGH UGH UGH UGH.
1093                 */
1094                 bool autobeam
1095                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1096                 bool itc = internal_type_checking_global_b;
1097
1098                 Music *t = MY_MAKE_MUSIC("OverrideProperty");
1099                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1100                 if (autobeam)
1101                         internal_type_checking_global_b = false;
1102                 t->set_mus_property ("grob-property", $6);
1103                 t->set_mus_property ("grob-value", $8);
1104                 if (autobeam)
1105                         internal_type_checking_global_b = itc;
1106
1107                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1108                 csm->set_mus_property ("element", t->self_scm ());
1109                 scm_gc_unprotect_object (t->self_scm ());
1110
1111                 $$ = csm;
1112                 $$->set_spot (THIS->here_input ());
1113
1114                 csm-> set_mus_property ("context-type", $2);
1115
1116         }
1117         | PROPERTY STRING '.' STRING REVERT embedded_scm {
1118                 Music *t = MY_MAKE_MUSIC("RevertProperty");
1119                 bool autobeam
1120                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1121                 bool itc = internal_type_checking_global_b;
1122
1123                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1124                 if (autobeam)
1125                         internal_type_checking_global_b = false;
1126                 t->set_mus_property ("grob-property", $6);
1127                 if (autobeam)
1128                         internal_type_checking_global_b = itc;
1129         
1130                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1131                 csm->set_mus_property ("element", t->self_scm ());
1132                 scm_gc_unprotect_object (t->self_scm ());
1133
1134                 $$ = csm;
1135                 $$->set_spot (THIS->here_input ());
1136
1137                 csm-> set_mus_property ("context-type", $2);
1138         }
1139         ;
1140
1141
1142 scalar:
1143         string          { $$ = $1; }
1144         | bare_int      { $$ = gh_int2scm ($1); }
1145         | embedded_scm  { $$ = $1; }
1146         ;
1147
1148
1149 event_chord:
1150         pre_events {
1151                 THIS->push_spot ();
1152         } /*cont */ simple_element post_events  {
1153                 SCM elts = $3-> get_mus_property ("elements");
1154
1155                 elts = gh_append3 (elts, scm_reverse_x ($1, SCM_EOL),
1156                                    scm_reverse_x ($4, SCM_EOL));
1157
1158                 $3-> set_mus_property ("elements", elts);
1159                 $$ = $3;
1160         }
1161         | command_element
1162         | note_chord_element
1163         ;
1164
1165
1166 note_chord_element:
1167         chord_body optional_notemode_duration post_events
1168         {
1169                 SCM dur = unsmob_duration ($2)->smobbed_copy();
1170                 SCM es = $1->get_mus_property ("elements");
1171                 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1172
1173                 for (SCM s = es; gh_pair_p (s); s = gh_cdr (s))
1174                   unsmob_music (gh_car(s))->set_mus_property ("duration", dur);
1175                 es = gh_append2 (es, postevs);
1176
1177                 $1-> set_mus_property ("elements", es);
1178                 $$ = $1;
1179         }
1180         ;
1181
1182 chord_body:
1183         CHORD_OPEN chord_body_elements CHORD_CLOSE
1184         {
1185                 $$ = MY_MAKE_MUSIC("EventChord");
1186                 $$->set_mus_property ("elements",
1187                         scm_reverse_x ($2, SCM_EOL));
1188         }
1189         ;
1190
1191 chord_body_elements:
1192         /* empty */             { $$ = SCM_EOL; }
1193         | chord_body_elements chord_body_element {
1194                 $$ = gh_cons ($2->self_scm(), $1);
1195                 scm_gc_unprotect_object ($2->self_scm());
1196         }
1197         ;
1198
1199 chord_body_element:
1200         pitch exclamations questions post_events
1201         {
1202                 Music * n = MY_MAKE_MUSIC("NoteEvent");
1203                 n->set_mus_property ("pitch", $1);
1204                 if ($3 % 2)
1205                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1206                 if ($2 % 2 || $3 % 2)
1207                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1208
1209                 SCM arts = scm_reverse_x ($4, SCM_EOL);
1210                 n->set_mus_property ("articulations", arts);
1211
1212                 $$ = n;
1213         }
1214         ;
1215
1216 command_element:
1217         command_req {
1218                 $$ = MY_MAKE_MUSIC("EventChord");
1219                 $$->set_mus_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1220           scm_gc_unprotect_object ($1->self_scm());
1221
1222                 $$-> set_spot (THIS->here_input ());
1223                 $1-> set_spot (THIS->here_input ());
1224         }
1225         | E_LEFTSQUARE {
1226                 Music *l = MY_MAKE_MUSIC("LigatureEvent");
1227                 l->set_mus_property ("span-direction", gh_int2scm (START));
1228                 l->set_spot (THIS->here_input ());
1229
1230                 $$ = MY_MAKE_MUSIC("EventChord");
1231                 $$->set_mus_property ("elements", scm_cons (l->self_scm (), SCM_EOL));
1232           scm_gc_unprotect_object (l->self_scm());
1233                 $$->set_spot (THIS->here_input ());
1234         }
1235         | E_RIGHTSQUARE {
1236                 Music *l = MY_MAKE_MUSIC("LigatureEvent");
1237                 l->set_mus_property ("span-direction", gh_int2scm (STOP));
1238                 l->set_spot (THIS->here_input ());
1239
1240                 $$ = MY_MAKE_MUSIC("EventChord");
1241                 $$->set_mus_property ("elements", scm_cons (l->self_scm (), SCM_EOL));
1242                 $$->set_spot (THIS->here_input ());
1243           scm_gc_unprotect_object (l->self_scm());
1244
1245         }
1246         | E_BACKSLASH {
1247                 $$ = MY_MAKE_MUSIC("VoiceSeparator");
1248                 $$->set_spot (THIS->here_input ());
1249         }
1250         | '|'      {
1251
1252                 $$ = MY_MAKE_MUSIC("BarCheck");
1253                 $$->set_spot (THIS->here_input ());
1254         }
1255         | BAR STRING                    {
1256                 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1257
1258                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1259                 csm->set_mus_property ("element", t->self_scm ());
1260                 scm_gc_unprotect_object (t->self_scm ());
1261
1262                 $$ = csm;
1263                 $$->set_spot (THIS->here_input ());
1264
1265                 csm->set_mus_property ("context-type", scm_makfrom0str ("Timing"));
1266         }
1267         | PARTIAL duration_length       {
1268                 Moment m = - unsmob_duration ($2)->get_length ();
1269                 Music * p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1270
1271                 Music * sp = MY_MAKE_MUSIC("ContextSpeccedMusic");
1272                 sp->set_mus_property ("element", p->self_scm ());
1273                 scm_gc_unprotect_object (p->self_scm ());
1274
1275                 $$ =sp ;
1276                 sp-> set_mus_property ("context-type", scm_makfrom0str ("Timing"));
1277         }
1278         | CLEF STRING  {
1279                 static SCM proc ;
1280                 if (!proc)
1281                         proc = scm_c_eval_string ("make-clef-set");
1282
1283                 SCM result = scm_call_1 (proc, $2);
1284                 scm_gc_protect_object (result);
1285                 $$ = unsmob_music (result);
1286         }
1287         | TIME_T fraction  {
1288                 Music * p1 = set_property_music (ly_symbol2scm ( "timeSignatureFraction"), $2);
1289
1290                 int l = gh_scm2int (ly_car ($2));
1291                 int o = gh_scm2int (ly_cdr ($2));
1292
1293                 Moment one_beat = Moment (1)/Moment (o);
1294                 Moment len = Moment (l) * one_beat;
1295
1296
1297                 Music *p2 = set_property_music (ly_symbol2scm ("measureLength"), len.smobbed_copy ());
1298                 Music *p3 = set_property_music (ly_symbol2scm ("beatLength"), one_beat.smobbed_copy ());
1299
1300                 SCM list = scm_list_n (p1->self_scm (), p2->self_scm (), p3->self_scm(), SCM_UNDEFINED);
1301                 Music *seq = MY_MAKE_MUSIC("SequentialMusic");
1302                 seq->set_mus_property ("elements", list);
1303                 
1304
1305                 Music * sp = MY_MAKE_MUSIC("ContextSpeccedMusic");
1306                 sp->set_mus_property ("element", seq->self_scm ());
1307
1308                 scm_gc_unprotect_object (p3->self_scm ());
1309                 scm_gc_unprotect_object (p2->self_scm ());
1310                 scm_gc_unprotect_object (p1->self_scm ());
1311                 scm_gc_unprotect_object (seq->self_scm ());
1312
1313                 $$ = sp;
1314
1315                 sp-> set_mus_property ("context-type", scm_makfrom0str ( "Timing"));
1316         }
1317         ;
1318
1319 command_req:
1320         shorthand_command_req   { $$ = $1; }
1321         | verbose_command_req   { $$ = $1; }
1322         ;
1323
1324 shorthand_command_req:
1325         extender_req {
1326                 $$ = $1;
1327         }
1328         | hyphen_req {
1329                 $$ = $1;
1330         }
1331         | '~'   {
1332                 $$ = MY_MAKE_MUSIC("TieEvent");
1333         }
1334         | '['           {
1335                 Music *b= MY_MAKE_MUSIC("BeamEvent");
1336                 b->set_mus_property ("span-direction", gh_int2scm (START))
1337 ;
1338                 $$ =b;
1339
1340
1341                 THIS->last_beam_start_ = b->self_scm ();
1342         }
1343         | ']'           {
1344                 Music *b= MY_MAKE_MUSIC("BeamEvent");
1345                 b->set_mus_property ("span-direction", gh_int2scm (STOP));
1346                 $$ = b;
1347         }
1348         | BREATHE {
1349                 $$ = MY_MAKE_MUSIC("BreathingSignEvent");
1350         }
1351         | E_TILDE {
1352                 $$ = MY_MAKE_MUSIC("PorrectusEvent");
1353         }
1354         ;
1355
1356 verbose_command_req:
1357         MARK DEFAULT  {
1358                 Music * m = MY_MAKE_MUSIC("MarkEvent");
1359                 $$ = m;
1360         }
1361         | MARK scalar {
1362                 Music *m = MY_MAKE_MUSIC("MarkEvent");
1363                 m->set_mus_property ("label", $2);
1364                 $$ = m;
1365         }
1366         | SKIP duration_length {
1367                 Music * skip = MY_MAKE_MUSIC("SkipEvent");
1368                 skip->set_mus_property ("duration", $2);
1369
1370                 $$ = skip;
1371         }
1372         | tempo_event {
1373                 $$ = $1;
1374         }
1375         | KEY DEFAULT {
1376                 Music *key= MY_MAKE_MUSIC("KeyChangeEvent");
1377                 $$ = key;
1378         }
1379         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1380                 Music *key= MY_MAKE_MUSIC("KeyChangeEvent");
1381                 
1382                 key->set_mus_property ("pitch-alist", $3);
1383                 ((Music*)key)->transpose (* unsmob_pitch ($2));
1384                 $$ = key; 
1385         }
1386         ;
1387
1388 post_events:
1389         /* empty */ {
1390                 $$ = SCM_EOL;
1391         }
1392         | post_events post_event {
1393                 $2->set_spot (THIS->here_input ());
1394                 $$ = gh_cons ($2->self_scm(), $$);
1395                 scm_gc_unprotect_object ($2->self_scm());
1396         }
1397         ;
1398
1399 post_event:
1400         verbose_event
1401         | event_with_dir
1402         | close_event
1403         | string_event
1404         ;
1405
1406 string_event:
1407         E_UNSIGNED {
1408                 Music * s = MY_MAKE_MUSIC("StringNumberEvent");
1409                 s->set_mus_property ("string-number",  gh_int2scm($1));
1410                 s->set_spot (THIS->here_input ());
1411                 $$ = s;
1412         }
1413         ;
1414
1415
1416 event_that_take_dir:
1417         gen_text_def
1418         | verbose_event
1419         | close_event
1420         | open_event
1421         | script_abbreviation {
1422                 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1423                 Music *a = MY_MAKE_MUSIC("ArticulationEvent");
1424                 if (gh_string_p (s))
1425                         a->set_mus_property ("articulation-type", s);
1426                 else THIS->parser_error (_ ("Expecting string as script definition"));
1427                 $$ = a;
1428         }
1429         ;
1430
1431 event_with_dir:
1432         script_dir event_that_take_dir  {
1433                 $2->set_mus_property ("direction", gh_int2scm ($1));
1434                 $$ = $2;
1435         }
1436         ;
1437         
1438 verbose_event:
1439         EVENT_IDENTIFIER        {
1440                 $$ = unsmob_music ($1);
1441         }
1442         | tremolo_type  {
1443                Music * a = MY_MAKE_MUSIC("TremoloEvent");
1444                a->set_spot (THIS->here_input ());
1445                a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1446                $$ = a;
1447         }
1448         ;
1449
1450 sup_quotes:
1451         '\'' {
1452                 $$ = 1;
1453         }
1454         | sup_quotes '\'' {
1455                 $$ ++;
1456         }
1457         ;
1458
1459 sub_quotes:
1460         ',' {
1461                 $$ = 1;
1462         }
1463         | sub_quotes ',' {
1464                 $$ ++ ;
1465         }
1466         ;
1467
1468 steno_pitch:
1469         NOTENAME_PITCH  {
1470                 $$ = $1;
1471         }
1472         | NOTENAME_PITCH sup_quotes     {
1473                 Pitch p = *unsmob_pitch ($1);
1474                 p.octave_ +=  $2;
1475                 $$ = p.smobbed_copy ();
1476         }
1477         | NOTENAME_PITCH sub_quotes      {
1478                 Pitch p =* unsmob_pitch ($1);
1479
1480                 p.octave_ +=  -$2;
1481                 $$ = p.smobbed_copy ();
1482
1483         }
1484         ;
1485
1486 /*
1487 ugh. duplication
1488 */
1489
1490 steno_tonic_pitch:
1491         TONICNAME_PITCH {
1492                 $$ = $1;
1493         }
1494         | TONICNAME_PITCH sup_quotes    {
1495                 Pitch p = *unsmob_pitch ($1);
1496                 p.octave_ +=  $2;
1497                 $$ = p.smobbed_copy ();
1498         }
1499         | TONICNAME_PITCH sub_quotes     {
1500                 Pitch p =* unsmob_pitch ($1);
1501
1502                 p.octave_ +=  -$2;
1503                 $$ = p.smobbed_copy ();
1504
1505         }
1506         ;
1507
1508 pitch:
1509         steno_pitch {
1510                 $$ = $1;
1511         }
1512         | explicit_pitch {
1513                 $$ = $1;
1514         }
1515         ;
1516
1517 explicit_pitch:
1518         PITCH embedded_scm {
1519                 $$ = $2;
1520                 if (!unsmob_pitch ($2)) {
1521                         THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1522                          $$ = Pitch ().smobbed_copy ();
1523                 }
1524         }
1525         ;
1526
1527 verbose_duration:
1528         DURATION embedded_scm   {
1529                 $$ = $2;
1530                 if (!unsmob_duration ($2))
1531                 {
1532                         THIS->parser_error (_ ("Must have duration object"));
1533                         $$ = Duration ().smobbed_copy ();
1534                 }
1535         }
1536         ;
1537
1538 extender_req:
1539         EXTENDER {
1540                 if (!THIS->lexer_->lyric_state_b ())
1541                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1542                 $$ = MY_MAKE_MUSIC("ExtenderEvent");
1543         }
1544         ;
1545
1546 hyphen_req:
1547         HYPHEN {
1548                 if (!THIS->lexer_->lyric_state_b ())
1549                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1550                 $$ = MY_MAKE_MUSIC("HyphenEvent");
1551         }
1552         ;
1553
1554 close_event:
1555         close_event_parens {
1556                 $$ = $1;
1557                 dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (START))
1558 ;
1559         }
1560         ;
1561  
1562 close_event_parens:
1563         '('     {
1564                 Music * s= MY_MAKE_MUSIC("SlurEvent");
1565                 $$ = s;
1566                 s->set_spot (THIS->here_input());
1567         }
1568         | E_OPEN        {
1569                 Music * s= MY_MAKE_MUSIC("PhrasingSlurEvent");
1570                 $$ = s;
1571                 s->set_spot (THIS->here_input());
1572         }
1573         | E_SMALLER {
1574                 Music *s =MY_MAKE_MUSIC("CrescendoEvent");
1575                 $$ = s;
1576                 s->set_spot (THIS->here_input());
1577         }
1578         | E_BIGGER {
1579                 Music *s =MY_MAKE_MUSIC("DecrescendoEvent");
1580                 $$ = s;
1581                 s->set_spot (THIS->here_input());
1582         }
1583         ;
1584
1585
1586 open_event:
1587         open_event_parens {
1588                 $$ = $1;
1589                 dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (STOP))
1590 ;
1591         }
1592         ;
1593
1594 open_event_parens:
1595         E_EXCLAMATION   {
1596                 Music *s =  MY_MAKE_MUSIC("CrescendoEvent");
1597                 s->set_spot (THIS->here_input());
1598
1599                 $$ = s;
1600         }
1601         | ')'   {
1602                 Music * s= MY_MAKE_MUSIC("SlurEvent");
1603                 $$ = s;
1604                 s->set_spot (THIS->here_input());
1605
1606         }
1607         | E_CLOSE       {
1608                 Music * s= MY_MAKE_MUSIC("PhrasingSlurEvent");
1609                 $$ = s;
1610                 s->set_mus_property ("span-type", scm_makfrom0str ( "phrasing-slur"));
1611                 s->set_spot (THIS->here_input());
1612         }
1613         ;
1614
1615 gen_text_def:
1616         embedded_scm {
1617                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1618                 t->set_mus_property ("text", $1);
1619                 t->set_spot (THIS->here_input ());
1620                 $$ = t;
1621         }
1622         | string {
1623                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1624                 t->set_mus_property ("text", $1);
1625                 t->set_spot (THIS->here_input ());
1626                 $$ = t;
1627         }
1628         | DIGIT {
1629                 Music * t = MY_MAKE_MUSIC("FingerEvent");
1630                 SCM finger = ly_symbol2scm ("finger");
1631                 t->set_mus_property ("digit",  gh_int2scm ($1));
1632                 t->set_spot (THIS->here_input ());
1633                 $$ = t;
1634         }
1635         ;
1636
1637 script_abbreviation:
1638         '^'             {
1639                 $$ = scm_makfrom0str ("Hat");
1640         }
1641         | '+'           {
1642                 $$ = scm_makfrom0str ("Plus");
1643         }
1644         | '-'           {
1645                 $$ = scm_makfrom0str ("Dash");
1646         }
1647         | '|'           {
1648                 $$ = scm_makfrom0str ("Bar");
1649         }
1650         | '>'           {
1651                 $$ = scm_makfrom0str ("Larger");
1652         }
1653         | '.'           {
1654                 $$ = scm_makfrom0str ("Dot");
1655         }
1656         | '_' {
1657                 $$ = scm_makfrom0str ("Underscore");
1658         }
1659         ;
1660
1661 script_dir:
1662         '_'     { $$ = DOWN; }
1663         | '^'   { $$ = UP; }
1664         | '-'   { $$ = CENTER; }
1665         ;
1666
1667 pre_events:
1668         /* empty */ { 
1669                 $$ = SCM_EOL;
1670         }
1671         | pre_events open_event {
1672                 $$ = gh_cons ($2->self_scm(), $$);
1673                 scm_gc_unprotect_object ($2->self_scm());
1674         }
1675         ;
1676
1677 absolute_pitch:
1678         steno_pitch     {
1679                 $$ = $1;
1680         }
1681         ;
1682
1683 duration_length:
1684         multiplied_duration {
1685                 $$ = $1;
1686         }
1687         | verbose_duration {
1688                 $$ = $1;
1689         }       
1690         ;
1691
1692 optional_notemode_duration:
1693         {
1694                 Duration dd = THIS->default_duration_;
1695                 $$ = dd.smobbed_copy ();
1696
1697                 THIS->beam_check ($$);
1698         }
1699         | multiplied_duration   {
1700                 $$ = $1;
1701                 THIS->default_duration_ = *unsmob_duration ($$);
1702
1703                 THIS->beam_check ($$);
1704         }
1705         | verbose_duration {
1706                 $$ = $1;
1707                 THIS->default_duration_ = *unsmob_duration ($$);
1708         }       
1709         ;
1710
1711 steno_duration:
1712         bare_unsigned dots              {
1713                 int l = 0;
1714                 if (!is_duration_b ($1))
1715                         THIS->parser_error (_f ("not a duration: %d", $1));
1716                 else
1717                         l =  intlog2 ($1);
1718
1719                 $$ = Duration (l, $2).smobbed_copy ();
1720         }
1721         | DURATION_IDENTIFIER dots      {
1722                 Duration *d =unsmob_duration ($1);
1723                 Duration k (d->duration_log (),d->dot_count () + $2);
1724
1725                 *d = k;
1726                 $$ = $1;
1727         }
1728         ;
1729
1730
1731
1732
1733 multiplied_duration:
1734         steno_duration {
1735                 $$ = $1;
1736         }
1737         | multiplied_duration '*' bare_unsigned {
1738                 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1739         }
1740         | multiplied_duration '*' FRACTION {
1741                 Rational  m (gh_scm2int (ly_car ($3)), gh_scm2int (ly_cdr ($3)));
1742
1743                 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1744         }
1745         ;
1746
1747 fraction:
1748         FRACTION { $$ = $1; }
1749         | UNSIGNED '/' UNSIGNED {
1750                 $$ = scm_cons (gh_int2scm ($1), gh_int2scm ($3));
1751         }
1752         ;
1753
1754 dots:
1755         /* empty */     {
1756                 $$ = 0;
1757         }
1758         | dots '.' {
1759                 $$ ++;
1760         }
1761         ;
1762
1763
1764 tremolo_type: 
1765         ':'     {
1766                 $$ =0;
1767         }
1768         | ':' bare_unsigned {
1769                 if (!is_duration_b ($2))
1770                         THIS->parser_error (_f ("not a duration: %d", $2));
1771                 $$ = $2;
1772         }
1773         ;
1774
1775
1776
1777 /*****************************************************************
1778                 BASS FIGURES
1779 *****************************************************************/
1780 bass_number:
1781         DIGIT
1782         | UNSIGNED 
1783         ;
1784
1785 bass_mod:
1786         '-'     { $$ = -1; }
1787         | '+'   { $$ = 1; } 
1788         | '!'   { $$ = 0; }
1789         ;
1790
1791 bass_figure:
1792         FIGURE_SPACE {
1793                 Music *bfr = MY_MAKE_MUSIC("BassFigureEvent");
1794                 $$ = bfr->self_scm();
1795                 scm_gc_unprotect_object ($$);
1796         }
1797         | bass_number  {
1798                 Music *bfr = MY_MAKE_MUSIC("BassFigureEvent");
1799                 $$ = bfr->self_scm();
1800
1801                 bfr->set_mus_property ("figure", gh_int2scm ($1));
1802
1803                 scm_gc_unprotect_object ($$);
1804         }
1805         | bass_figure bass_mod {
1806                 Music *m = unsmob_music ($1);
1807                 if ($2) {
1808                         SCM salter =m->get_mus_property ("alteration");
1809                         int alter = gh_number_p ( salter) ? gh_scm2int (salter) : 0;
1810                         m->set_mus_property ("alteration",
1811                                 gh_int2scm (alter + $2));
1812                 } else {
1813                         m->set_mus_property ("alteration", gh_int2scm (0));
1814                 }
1815         }
1816         ;
1817
1818 br_bass_figure:
1819         '[' bass_figure {
1820                 $$ = $2;
1821                 unsmob_music ($$)->set_mus_property ("bracket-start", SCM_BOOL_T);
1822         }
1823         | bass_figure   {
1824                 $$ = $1;
1825         }
1826         | br_bass_figure ']' {
1827                 $$ = $1;
1828                 unsmob_music ($1)->set_mus_property ("bracket-stop", SCM_BOOL_T);
1829         }
1830         ;
1831
1832 figure_list:
1833         /**/            {
1834                 $$ = SCM_EOL;
1835         }
1836         | figure_list br_bass_figure {
1837                 $$ = scm_cons ($2, $1); 
1838         }
1839         ;
1840
1841 figure_spec:
1842         FIGURE_OPEN figure_list FIGURE_CLOSE {
1843                 Music * m = MY_MAKE_MUSIC("EventChord");
1844                 $2 = scm_reverse_x ($2, SCM_EOL);
1845                 m->set_mus_property ("elements",  $2);
1846                 $$ = m->self_scm ();
1847         }
1848         ;
1849
1850
1851 optional_rest:
1852         /**/   { $$ = 0; }
1853         | REST { $$ = 1; }
1854         ;
1855
1856 simple_element:
1857         pitch exclamations questions optional_notemode_duration optional_rest {
1858
1859                 Input i = THIS->pop_spot ();
1860                 if (!THIS->lexer_->note_state_b ())
1861                         THIS->parser_error (_ ("Have to be in Note mode for notes"));
1862
1863                 Music *n = 0;
1864                 if ($5)
1865                         n =  MY_MAKE_MUSIC("RestEvent");
1866                 else
1867                         n =  MY_MAKE_MUSIC("NoteEvent");
1868                 
1869                 n->set_mus_property ("pitch", $1);
1870                 n->set_mus_property ("duration", $4);
1871
1872
1873                 if ($3 % 2)
1874                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1875                 if ($2 % 2 || $3 % 2)
1876                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1877
1878                 Music *v = MY_MAKE_MUSIC("EventChord");
1879                 v->set_mus_property ("elements", scm_list_n (n->self_scm (), SCM_UNDEFINED));
1880                 scm_gc_unprotect_object (n->self_scm());
1881
1882                 v->set_spot (i);
1883                 n->set_spot (i);
1884                 $$ = v;
1885         }
1886         | figure_spec optional_notemode_duration {
1887                 Music * m = unsmob_music ($1);
1888                 Input i = THIS->pop_spot (); 
1889                 m->set_spot (i);
1890                 for (SCM s = m->get_mus_property ("elements"); gh_pair_p (s); s = ly_cdr (s))
1891                 {
1892                         unsmob_music (ly_car (s))->set_mus_property ("duration", $2);
1893                 }
1894                 $$ = m;
1895         }       
1896         | RESTNAME optional_notemode_duration           {
1897
1898                 Input i = THIS->pop_spot ();
1899                 Music * ev = 0;
1900                 if (ly_scm2string ($1) =="s") {
1901                         /* Space */
1902                         ev = MY_MAKE_MUSIC("SkipEvent");
1903                   }
1904                 else {
1905                         ev = MY_MAKE_MUSIC("RestEvent");
1906                 
1907                     }
1908                 ev->set_mus_property ("duration" ,$2);
1909                 ev->set_spot (i);
1910                 Music * velt = MY_MAKE_MUSIC("EventChord");
1911                 velt->set_mus_property ("elements", scm_list_n (ev->self_scm (),SCM_UNDEFINED));
1912                 velt->set_spot (i);
1913
1914                 $$ = velt;
1915         }
1916         | MULTI_MEASURE_REST optional_notemode_duration         {
1917                 THIS->pop_spot ();
1918
1919                 static SCM proc ;
1920                 if (!proc)
1921                         proc = scm_c_eval_string ("make-multi-measure-rest");
1922
1923                 SCM mus = scm_call_2 (proc, $2,
1924                         make_input (THIS->here_input()));       
1925                 scm_gc_protect_object (mus);
1926                 $$ = unsmob_music (mus);
1927         }
1928         | STRING optional_notemode_duration     {
1929                 Input i = THIS->pop_spot ();
1930
1931                 Music * lreq = MY_MAKE_MUSIC("LyricEvent");
1932                 lreq->set_mus_property ("text", $1);
1933                 lreq->set_mus_property ("duration",$2);
1934                 lreq->set_spot (i);
1935                 Music * velt = MY_MAKE_MUSIC("EventChord");
1936                 velt->set_mus_property ("elements", scm_list_n (lreq->self_scm (), SCM_UNDEFINED));
1937
1938                 $$= velt;
1939         }
1940         | chord {
1941                 THIS->pop_spot ();
1942
1943                 if (!THIS->lexer_->chord_state_b ())
1944                         THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1945                 $$ = $1;
1946         }
1947         ;
1948
1949
1950 chord:
1951         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1952                 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1953                 $$->set_spot (THIS->here_input ());
1954         };
1955
1956 chord_additions: 
1957         {
1958                 $$ = SCM_EOL;
1959         } 
1960         | CHORD_COLON chord_notes {
1961                 $$ = $2;
1962         }
1963         ;
1964
1965 chord_notes:
1966         chord_step {
1967                 $$ = $1;
1968         }
1969         | chord_notes '.' chord_step {
1970                 $$ = gh_append2 ($$, $3);
1971         }
1972         ;
1973
1974 chord_subtractions: 
1975         {
1976                 $$ = SCM_EOL;
1977         } 
1978         | CHORD_CARET chord_notes {
1979                 $$ = $2;
1980         }
1981         ;
1982
1983
1984 chord_inversion:
1985         {
1986                 $$ = SCM_EOL;
1987         }
1988         | CHORD_SLASH steno_tonic_pitch {
1989                 $$ = $2;
1990         }
1991         ;
1992
1993 chord_bass:
1994         {
1995                 $$ = SCM_EOL;
1996         }
1997         | CHORD_BASS steno_tonic_pitch {
1998                 $$ = $2;
1999         }
2000         ;
2001
2002 chord_step:
2003         chord_note {
2004                 $$ = scm_cons ($1, SCM_EOL);
2005         }
2006         | CHORDMODIFIER_PITCH {
2007                 $$ = scm_cons (unsmob_pitch ($1)->smobbed_copy (), SCM_EOL);
2008         }
2009         | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
2010                 $$ = scm_list_n (unsmob_pitch ($1)->smobbed_copy (),
2011                         $2, SCM_UNDEFINED);
2012         }
2013         ;
2014
2015 chord_note:
2016         bare_unsigned {
2017                  Pitch m;
2018                 m.notename_ = ($1 - 1) % 7;
2019                 m.octave_ = $1 > 7 ? 1 : 0;
2020                 m.alteration_ = 0;
2021
2022                 $$ = m.smobbed_copy ();
2023         } 
2024         | bare_unsigned '+' {
2025                 Pitch m;
2026                 m.notename_ = ($1 - 1) % 7;
2027                 m.octave_ = $1 > 7 ? 1 : 0;
2028                 m.alteration_ = 1;
2029
2030
2031                 $$ = m.smobbed_copy ();
2032         }
2033         | bare_unsigned CHORD_MINUS {
2034                 Pitch m;
2035                 m.notename_ = ($1 - 1) % 7;
2036                 m.octave_ = $1 > 7 ? 1 : 0;
2037                 m.alteration_ = -1;
2038
2039                 $$ = m.smobbed_copy ();
2040         }
2041         ;
2042
2043 /*
2044         UTILITIES
2045  */
2046 number_expression:
2047         number_expression '+' number_term {
2048                 $$ = scm_sum ($1, $3);
2049         }
2050         | number_expression '-' number_term {
2051                 $$ = scm_difference ($1, $3);
2052         }
2053         | number_term 
2054         ;
2055
2056 number_term:
2057         number_factor {
2058                 $$ = $1;
2059         }
2060         | number_factor '*' number_factor {
2061                 $$ = scm_product ($1, $3);
2062         }
2063         | number_factor '/' number_factor {
2064                 $$ = scm_divide ($1, $3);
2065         }
2066         ;
2067
2068 number_factor:
2069         '-'  number_factor { /* %prec UNARY_MINUS */
2070                 $$ = scm_difference ($2, SCM_UNDEFINED);
2071         }
2072         | bare_number
2073         ;
2074
2075
2076 bare_number:
2077         UNSIGNED        {
2078                 $$ = gh_int2scm ($1);
2079         }
2080         | REAL          {
2081                 $$ = $1;
2082         }
2083         | NUMBER_IDENTIFIER             {
2084                 $$ = $1;
2085         }
2086         | REAL NUMBER_IDENTIFIER        {
2087                 $$ = gh_double2scm (gh_scm2double ($1) * gh_scm2double ($2));
2088         }
2089         | UNSIGNED NUMBER_IDENTIFIER    {
2090                 $$ = gh_double2scm ($1 * gh_scm2double ($2));
2091         }
2092         ;
2093
2094
2095 bare_unsigned:
2096         UNSIGNED {
2097                         $$ = $1;
2098         }
2099         | DIGIT {
2100                 $$ = $1;
2101         }
2102         ;
2103
2104 bare_int:
2105         bare_number {
2106                 if (scm_integer_p ($1) == SCM_BOOL_T)
2107                 {
2108                         int k = gh_scm2int ($1);
2109                         $$ = k;
2110                 } else
2111                 {
2112                         THIS->parser_error (_ ("need integer number arg"));
2113                         $$ = 0;
2114                 }
2115         }
2116         | '-' bare_int {
2117                 $$ = -$2;
2118         }
2119         ;
2120
2121
2122 string:
2123         STRING          {
2124                 $$ = $1;
2125         }
2126         | STRING_IDENTIFIER     {
2127                 $$ = $1;
2128         }
2129         | string '+' string {
2130                 $$ = scm_string_append (scm_list_n ($1, $3, SCM_UNDEFINED));
2131         }
2132         ;
2133
2134
2135 exclamations:
2136                 { $$ = 0; }
2137         | exclamations '!'      { $$ ++; }
2138         ;
2139
2140 questions:
2141                 { $$ = 0; }
2142         | questions '?' { $$ ++; }
2143         ;
2144
2145
2146 %%
2147
2148 void
2149 My_lily_parser::set_yydebug (bool )
2150 {
2151 #if 0
2152         yydebug = 1;
2153 #endif
2154 }
2155
2156 extern My_lily_parser * current_parser;
2157
2158 void
2159 My_lily_parser::do_yyparse ()
2160 {
2161         current_parser = this;;
2162         yyparse ((void*)this);
2163 }
2164
2165
2166 /*
2167 Should make this optional?    It will also complain when you do
2168
2169         [s4]
2170
2171 which is entirely legitimate.
2172
2173 Or we can scrap it. Barchecks should detect wrong durations, and
2174 skipTypesetting speeds it up a lot.
2175 */
2176
2177 void
2178 My_lily_parser::beam_check (SCM dur)
2179 {
2180   Duration *d = unsmob_duration (dur);
2181   if (unsmob_music (last_beam_start_) && d->duration_log () <= 2)
2182     {
2183       Music * m = unsmob_music (last_beam_start_);
2184       m->origin ()->warning (_("Suspect duration found following this beam"));
2185     }
2186   last_beam_start_ = SCM_EOL;
2187 }
2188
2189
2190 /*
2191 It is a little strange, to have this function in this file, but
2192 otherwise, we have to import music classes into the lexer.
2193
2194 */
2195 int
2196 My_lily_lexer::try_special_identifiers (SCM * destination, SCM sid)
2197 {
2198         if (gh_string_p (sid)) {
2199                 *destination = sid;
2200                 return STRING_IDENTIFIER;
2201         } else if (gh_number_p (sid)) {
2202                 *destination = sid;
2203                 return NUMBER_IDENTIFIER;
2204         } else if (unsmob_translator_def (sid)) {
2205                 *destination = unsmob_translator_def (sid)->clone_scm();
2206                 return TRANSLATOR_IDENTIFIER;
2207         } else if (unsmob_score (sid)) {
2208                 Score *sc =  new Score (*unsmob_score (sid));
2209                 *destination =sc->self_scm ();
2210                 return SCORE_IDENTIFIER;
2211         } else if (Music * mus =unsmob_music (sid)) {
2212                 *destination = unsmob_music (sid)->clone ()->self_scm();
2213                 unsmob_music (*destination)->
2214                         set_mus_property ("origin", make_input (last_input_));
2215                 return dynamic_cast<Event*> (mus)
2216                         ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2217         } else if (unsmob_duration (sid)) {
2218                 *destination = unsmob_duration (sid)->smobbed_copy();
2219                 return DURATION_IDENTIFIER;
2220         } else if (unsmob_music_output_def (sid)) {
2221                 Music_output_def *p = unsmob_music_output_def (sid);
2222                 p = p->clone ();
2223
2224                 *destination = p->self_scm();
2225                 return MUSIC_OUTPUT_DEF_IDENTIFIER;
2226         }
2227         return -1;      
2228 }