2 event.cc -- implement Event
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 Event::get_length () const
16 Duration *d = unsmob_duration (get_mus_property ("duration"));
22 return d->get_length ();
26 Event::compress (Moment m)
28 Duration *d = unsmob_duration (get_mus_property ("duration"));
30 set_mus_property ("duration", d ->compressed (m.main_part_).smobbed_copy ());
34 Event::transpose (Pitch delta)
36 Pitch *p = unsmob_pitch (get_mus_property ("pitch"));
40 Pitch np = p->transposed (delta);
42 if (abs (np.get_alteration ()) > 2)
44 warning (_f ("Transposition by %s makes alteration larger than two",
48 set_mus_property ("pitch", np.smobbed_copy ());
52 Event::to_relative_octave (Pitch last)
54 Pitch *old_pit = unsmob_pitch (get_mus_property ("pitch"));
57 Pitch new_pit = *old_pit;
58 new_pit = new_pit.to_relative_octave (last);
59 set_mus_property ("pitch", new_pit.smobbed_copy ());
72 LY_DEFINE(music_duration_length, "music-duration-length", 1, 0,0,
74 "Extract the duration field from @var{mus}, and return the length.")
76 Music* m = unsmob_music(mus);
77 SCM_ASSERT_TYPE(m, mus, SCM_ARG1, __FUNCTION__, "Music");
79 Duration *d = unsmob_duration (m->get_mus_property ("duration"));
88 programming_error("Music has no duration");
89 return l.smobbed_copy();
94 LY_DEFINE(music_duration_compress, "ly:music-duration-compress", 2, 0,0,
95 (SCM mus, SCM factor),
96 "Extract the duration field from @var{mus}, and compress it.")
98 Music* m = unsmob_music(mus);
99 Moment * f = unsmob_moment (factor);
100 SCM_ASSERT_TYPE(m, mus, SCM_ARG1, __FUNCTION__, "Music");
101 SCM_ASSERT_TYPE(f, factor, SCM_ARG2, __FUNCTION__, "Moment");
103 Duration *d = unsmob_duration (m->get_mus_property ("duration"));
105 m->set_mus_property ("duration", d->compressed (f->main_part_).smobbed_copy());
106 return SCM_UNSPECIFIED;
112 This is hairy, since the scale in a key-change event may contain
116 TODO: this should use ly:pitch.
118 LY_DEFINE(transpose_key_alist, "ly:transpose-key-alist",
119 2, 0,0, (SCM l, SCM pitch),
120 "Make a new key alist of @var{l} transposed by pitch @var{pitch}")
122 SCM newlist = SCM_EOL;
123 Pitch *p = unsmob_pitch (pitch);
125 for (SCM s = l; gh_pair_p (s); s = ly_cdr (s))
127 SCM key = ly_caar (s);
128 SCM alter = ly_cdar (s);
131 Pitch orig (gh_scm2int (ly_car (key)),
132 gh_scm2int (ly_cdr (key)),
135 orig =orig.transposed (*p);
137 SCM key = gh_cons (scm_int2num (orig.get_octave ()),
138 scm_int2num (orig.get_notename ()));
140 newlist = gh_cons (gh_cons (key, scm_int2num (orig.get_alteration ())),
143 else if (gh_number_p (key))
145 Pitch orig (0, gh_scm2int (key), gh_scm2int (alter));
146 orig = orig.transposed (*p);
148 key =scm_int2num (orig.get_notename ());
149 alter = scm_int2num (orig.get_alteration());
150 newlist = gh_cons (gh_cons (key, alter), newlist);
153 return scm_reverse_x (newlist, SCM_EOL);
157 Key_change_ev::transpose (Pitch p)
159 SCM pa = get_mus_property ("pitch-alist");
161 set_mus_property ("pitch-alist", transpose_key_alist (pa, p.smobbed_copy()));
162 Pitch tonic = *unsmob_pitch (get_mus_property ("tonic"));
163 set_mus_property ("tonic",
164 tonic.smobbed_copy ());
168 alist_equal_p (SCM a, SCM b)
171 gh_pair_p (s); s = ly_cdr (s))
173 SCM key = ly_caar (s);
174 SCM val = ly_cdar (s);
175 SCM l = scm_assoc (key, b);
178 || !gh_equal_p ( ly_cdr (l), val))
184 ADD_MUSIC (Key_change_ev);