]> git.donarmstrong.com Git - lilypond.git/blob - lily/event.cc
cd803f87c0e0fbc17e40cf2b511fa412998b35c0
[lilypond.git] / lily / event.cc
1 /*
2   event.cc -- implement Event
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "event.hh"
10 #include "warn.hh"
11
12 Moment
13 Event::get_length () const
14 {
15   Duration *d = unsmob_duration (get_property ("duration"));
16   if (!d)
17     {
18       Moment m ;
19       return m;
20     }
21   return d->get_length ();
22 }
23
24 void
25 Event::compress (Moment m)
26 {
27   Duration *d =  unsmob_duration (get_property ("duration"));
28   if (d)
29     set_property ("duration", d ->compressed (m.main_part_).smobbed_copy ());
30 }
31
32
33 Pitch
34 Event::to_relative_octave (Pitch last)
35 {
36   Pitch *old_pit = unsmob_pitch (get_property ("pitch"));
37   if (old_pit)
38     {
39       Pitch new_pit = *old_pit;
40       new_pit = new_pit.to_relative_octave (last);
41
42       SCM check = get_property ("absolute-octave");
43       if (scm_is_number (check) &&
44           new_pit.get_octave () != scm_to_int (check))
45         {
46           Pitch expected_pit (scm_to_int (check),
47                               new_pit.get_notename (),
48                               new_pit.get_alteration ());
49           origin ()->warning (_f ("octave check failed; expected %s, found: %s",
50                                   expected_pit.to_string (),
51                                   new_pit.to_string ()));
52           new_pit = expected_pit;
53         }
54       
55       set_property ("pitch", new_pit.smobbed_copy ());
56   
57       return new_pit;
58     }
59   return last;
60 }
61   
62 Event::Event ()
63   : Music ()
64 {
65 }
66
67 ADD_MUSIC (Event);
68
69 void
70 Key_change_ev::transpose (Pitch p)
71 {
72   SCM pa = get_property ("pitch-alist");
73   set_property ("pitch-alist", ly_transpose_key_alist (pa, p.smobbed_copy ()));
74
75   Event::transpose (p);
76 }
77
78 bool
79 alist_equal_p (SCM a, SCM b)
80 {
81   for (SCM s = a;
82        scm_is_pair (s); s = scm_cdr (s))
83     {
84       SCM key = scm_caar (s);
85       SCM val = scm_cdar (s);
86       SCM l = scm_assoc (key, b);
87
88       if (l == SCM_BOOL_F
89           || !ly_c_equal_p ( scm_cdr (l), val))
90
91         return false;
92     }
93   return true;
94 }
95 ADD_MUSIC (Key_change_ev);