]> git.donarmstrong.com Git - lilypond.git/blob - lily/stream-event.cc
Web-ja: update introduction
[lilypond.git] / lily / stream-event.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 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 "context.hh"
23 #include "input.hh"
24 #include "music.hh"
25 #include "pitch.hh"
26
27 /* TODO: Rename Stream_event -> Event */
28
29 Stream_event::Stream_event ()
30   : Prob (ly_symbol2scm ("Stream_event"), SCM_EOL)
31 {
32 }
33
34 Stream_event::Stream_event (SCM event_class, SCM immutable_props)
35   : Prob (ly_symbol2scm ("Stream_event"),
36           scm_acons (ly_symbol2scm ("class"), event_class, immutable_props))
37 {
38 }
39
40 Stream_event::Stream_event (SCM class_name, Input *origin)
41   : Prob (ly_symbol2scm ("Stream_event"),
42           scm_list_1 (scm_cons (ly_symbol2scm ("class"), class_name)))
43 {
44   if (origin)
45     set_spot (origin);
46 }
47
48 SCM
49 Stream_event::copy_mutable_properties () const
50 {
51   return ly_event_deep_copy (mutable_property_alist_);
52 }
53
54 Input *
55 Stream_event::origin () const
56 {
57   Input *i = unsmob<Input> (get_property ("origin"));
58   return i ? i : &dummy_input_global;
59 }
60
61 void
62 Stream_event::set_spot (Input *i)
63 {
64   set_property ("origin", i->smobbed_copy ());
65 }
66
67 bool
68 Stream_event::internal_in_event_class (SCM class_name)
69 {
70   SCM cl = get_property ("class");
71   return scm_is_true (scm_c_memq (class_name, cl));
72 }
73
74 MAKE_SCHEME_CALLBACK (Stream_event, undump, 1);
75 MAKE_SCHEME_CALLBACK (Stream_event, dump, 1);
76
77 void
78 Stream_event::make_transposable ()
79 {
80   /* This is in preparation for transposing stuff
81      that may be defined in the immutable part */
82
83   for (SCM s = immutable_property_alist_; scm_is_pair (s); s = scm_cdr (s))
84     {
85       SCM entry = scm_car (s);
86       SCM prop = scm_car (entry);
87       SCM val = scm_cdr (entry);
88
89       if ((unsmob<Pitch> (val)
90            || (scm_is_eq (prop, ly_symbol2scm ("element")) && unsmob<Music> (val))
91            || (scm_is_eq (prop, ly_symbol2scm ("elements")) && scm_is_pair (val))
92            || (scm_is_eq (prop, ly_symbol2scm ("pitch-alist")) && scm_is_pair (val)))
93           && scm_is_false (scm_assq (prop, mutable_property_alist_)))
94         mutable_property_alist_
95           = scm_acons (prop, music_deep_copy (val), mutable_property_alist_);
96     }
97 }
98
99 SCM
100 Stream_event::dump (SCM self)
101 {
102   Stream_event *ev = unsmob<Stream_event> (self);
103   // Reversed alists look prettier.
104   return scm_cons (scm_reverse (ev->immutable_property_alist_),
105                    scm_reverse (ev->mutable_property_alist_));
106 }
107
108 SCM
109 Stream_event::undump (SCM data)
110 {
111   Stream_event *obj = new Stream_event ();
112   obj->immutable_property_alist_ = scm_reverse (scm_car (data));
113   obj->mutable_property_alist_ = scm_reverse (scm_cdr (data));
114   return obj->unprotect ();
115 }