]> git.donarmstrong.com Git - lilypond.git/blob - lily/stream-event.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / stream-event.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2014 Erik Sandberg  <mandolaerik@gmail.com>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "stream-event.hh"
21
22 #include "ly-smobs.icc"
23 #include "context.hh"
24 #include "input.hh"
25 #include "music.hh"
26 #include "pitch.hh"
27
28 /* TODO: Rename Stream_event -> Event */
29
30 Stream_event::Stream_event ()
31   : Prob (ly_symbol2scm ("Stream_event"), SCM_EOL)
32 {
33 }
34
35 Stream_event::Stream_event (SCM event_class, SCM immutable_props)
36   : Prob (ly_symbol2scm ("Stream_event"),
37           scm_acons (ly_symbol2scm ("class"), event_class, immutable_props))
38 {
39 }
40
41 Stream_event::Stream_event (SCM class_name, Input *origin)
42   : Prob (ly_symbol2scm ("Stream_event"),
43           scm_list_1 (scm_cons (ly_symbol2scm ("class"), class_name)))
44 {
45   if (origin)
46     set_spot (origin);
47 }
48
49 SCM
50 Stream_event::copy_mutable_properties () const
51 {
52   return ly_event_deep_copy (mutable_property_alist_);
53 }
54
55 Input *
56 Stream_event::origin () const
57 {
58   Input *i = unsmob_input (get_property ("origin"));
59   return i ? i : &dummy_input_global;
60 }
61
62 void
63 Stream_event::set_spot (Input *i)
64 {
65   set_property ("origin", make_input (*i));
66 }
67
68 bool
69 Stream_event::internal_in_event_class (SCM class_name)
70 {
71   SCM cl = get_property ("class");
72   return scm_c_memq (class_name, cl) != SCM_BOOL_F;
73 }
74
75 MAKE_SCHEME_CALLBACK (Stream_event, undump, 1);
76 MAKE_SCHEME_CALLBACK (Stream_event, dump, 1);
77
78 void
79 Stream_event::make_transposable ()
80 {
81   /* This is in preparation for transposing stuff
82      that may be defined in the immutable part */
83
84   for (SCM s = immutable_property_alist_; scm_is_pair (s); s = scm_cdr (s))
85     {
86       SCM entry = scm_car (s);
87       SCM prop = scm_car (entry);
88       SCM val = scm_cdr (entry);
89
90       if ((unsmob_pitch (val)
91            || (prop == ly_symbol2scm ("element") && unsmob_music (val))
92            || (prop == ly_symbol2scm ("elements") && scm_is_pair (val))
93            || (prop == ly_symbol2scm ("pitch-alist") && scm_is_pair (val)))
94           && scm_is_false (scm_assq (prop, mutable_property_alist_)))
95         mutable_property_alist_
96           = scm_acons (prop, ly_music_deep_copy (val), mutable_property_alist_);
97     }
98 }
99
100 SCM
101 Stream_event::dump (SCM self)
102 {
103   Stream_event *ev = unsmob_stream_event (self);
104   // Reversed alists look prettier.
105   return scm_cons (scm_reverse (ev->immutable_property_alist_),
106                    scm_reverse (ev->mutable_property_alist_));
107 }
108
109 SCM
110 Stream_event::undump (SCM data)
111 {
112   Stream_event *obj = new Stream_event ();
113   obj->immutable_property_alist_ = scm_reverse (scm_car (data));
114   obj->mutable_property_alist_ = scm_reverse (scm_cdr (data));
115   return obj->unprotect ();
116 }
117
118 Stream_event *
119 unsmob_stream_event (SCM m)
120 {
121   return dynamic_cast<Stream_event *> (unsmob_prob (m));
122 }