]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-tremolo-iterator.cc
1658e55782a9fdfe01eb0c69b8ea919604148a34
[lilypond.git] / lily / chord-tremolo-iterator.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5                  Erik Sandberg <mandolaerik@gmail.com>
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "chord-tremolo-iterator.hh"
22
23 #include "input.hh"
24 #include "international.hh"
25 #include "misc.hh"
26 #include "repeated-music.hh"
27
28 Chord_tremolo_iterator::Chord_tremolo_iterator ()
29 {
30 }
31
32 SCM
33 Chord_tremolo_iterator::get_music_list () const
34 {
35   Music *mus = get_music ();
36   Input *origin = mus->origin ();
37   Moment l = mus->get_length ();
38   Music *body = Repeated_music::body (mus);
39   bool body_is_sequential = body->is_mus_type ("sequential-music");
40
41   int elt_count = body_is_sequential ? scm_ilength (body->get_property ("elements")) : 1;
42
43   if (elt_count <= 0)
44     elt_count = 1;
45
46   if (elt_count == 1)
47     {
48       Music *ev = make_music_by_name (ly_symbol2scm ("TremoloEvent"));
49       ev->set_spot (*origin);
50       ev->set_property ("repeat-count", mus->get_property ("repeat-count"));
51       ev->set_property ("tremolo-type", mus->get_property ("tremolo-type"));
52       return scm_list_2 (ev->unprotect (), body->self_scm ());
53     }
54   else
55     {
56       SCM tremolo_symbol = ly_symbol2scm ("TremoloSpanEvent");
57       SCM start_event_scm = scm_call_2 (ly_lily_module_constant ("make-span-event"), tremolo_symbol, scm_from_int (START));
58       unsmob_music (start_event_scm)->set_spot (*origin);
59       SCM stop_event_scm = scm_call_2 (ly_lily_module_constant ("make-span-event"), tremolo_symbol, scm_from_int (STOP));
60
61       Music *start_event = unsmob_music (start_event_scm);
62       Music *stop_event = unsmob_music (stop_event_scm);
63       start_event->set_spot (*origin);
64       stop_event->set_spot (*origin);
65       start_event->set_property ("repeat-count", mus->get_property ("repeat-count"));
66       start_event->set_property ("tremolo-type", mus->get_property ("tremolo-type"));
67
68       return scm_list_3 (start_event_scm, body->self_scm (), stop_event_scm);
69     }
70 }
71
72 IMPLEMENT_CTOR_CALLBACK (Chord_tremolo_iterator);