2 event.cc -- implement Event
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 Event::get_length () const
16 Duration *d = unsmob_duration (get_property ("duration"));
22 return d->get_length ();
26 Event::compress (Moment m)
28 Duration *d = unsmob_duration (get_property ("duration"));
30 set_property ("duration", d ->compressed (m.main_part_).smobbed_copy ());
35 Event::to_relative_octave (Pitch last)
37 Pitch *old_pit = unsmob_pitch (get_property ("pitch"));
40 Pitch new_pit = *old_pit;
41 new_pit = new_pit.to_relative_octave (last);
43 SCM check = get_property ("absolute-octave");
44 if (scm_is_number (check) &&
45 new_pit.get_octave () != scm_to_int (check))
47 Pitch expected_pit (scm_to_int (check),
48 new_pit.get_notename (),
49 new_pit.get_alteration ());
50 origin ()->warning (_f ("octave check failed; expected %s, found: %s",
51 expected_pit.to_string (),
52 new_pit.to_string ()));
53 new_pit = expected_pit;
56 set_property ("pitch", new_pit.smobbed_copy ());
70 LY_DEFINE (ly_music_duration_length, "ly:music-duration-length", 1, 0,0,
72 "Extract the duration field from @var{mus}, and return the length.")
74 Music* m = unsmob_music (mus);
75 SCM_ASSERT_TYPE (m, mus, SCM_ARG1, __FUNCTION__, "Music");
77 Duration *d = unsmob_duration (m->get_property ("duration"));
86 programming_error ("Music has no duration");
87 return l.smobbed_copy ();
92 LY_DEFINE (ly_music_duration_compress, "ly:music-duration-compress", 2, 0,0,
94 "Compress @var{mus} by factor @var{fact}, which is a @code{Moment}.")
96 Music* m = unsmob_music (mus);
97 Moment * f = unsmob_moment (fact);
98 SCM_ASSERT_TYPE (m, mus, SCM_ARG1, __FUNCTION__, "Music");
99 SCM_ASSERT_TYPE (f, fact, SCM_ARG2, __FUNCTION__, "Moment");
101 Duration *d = unsmob_duration (m->get_property ("duration"));
103 m->set_property ("duration", d->compressed (f->main_part_).smobbed_copy ());
104 return SCM_UNSPECIFIED;
110 This is hairy, since the scale in a key-change event may contain
114 TODO: this should use ly:pitch.
116 LY_DEFINE (ly_transpose_key_alist, "ly:transpose-key-alist",
117 2, 0, 0, (SCM l, SCM pit),
118 "Make a new key alist of @var{l} transposed by pitch @var{pit}")
120 SCM newlist = SCM_EOL;
121 Pitch *p = unsmob_pitch (pit);
123 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
125 SCM key = scm_caar (s);
126 SCM alter = scm_cdar (s);
127 if (scm_is_pair (key))
129 Pitch orig (scm_to_int (scm_car (key)),
130 scm_to_int (scm_cdr (key)),
133 orig =orig.transposed (*p);
135 SCM key = scm_cons (scm_int2num (orig.get_octave ()),
136 scm_int2num (orig.get_notename ()));
138 newlist = scm_cons (scm_cons (key, scm_int2num (orig.get_alteration ())),
141 else if (scm_is_number (key))
143 Pitch orig (0, scm_to_int (key), scm_to_int (alter));
144 orig = orig.transposed (*p);
146 key =scm_int2num (orig.get_notename ());
147 alter = scm_int2num (orig.get_alteration ());
148 newlist = scm_cons (scm_cons (key, alter), newlist);
151 return scm_reverse_x (newlist, SCM_EOL);
155 Key_change_ev::transpose (Pitch p)
157 SCM pa = get_property ("pitch-alist");
159 set_property ("pitch-alist", ly_transpose_key_alist (pa, p.smobbed_copy ()));
160 Pitch tonic = *unsmob_pitch (get_property ("tonic"));
161 set_property ("tonic",
162 tonic.smobbed_copy ());
166 alist_equal_p (SCM a, SCM b)
169 scm_is_pair (s); s = scm_cdr (s))
171 SCM key = scm_caar (s);
172 SCM val = scm_cdar (s);
173 SCM l = scm_assoc (key, b);
176 || !ly_c_equal_p ( scm_cdr (l), val))
182 ADD_MUSIC (Key_change_ev);