]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-performer.cc
Web-ja: update introduction
[lilypond.git] / lily / key-performer.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Jan Nieuwenhuizen <janneke@gnu.org>
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 "audio-item.hh"
21 #include "music-sequence.hh"
22 #include "performer.hh"
23 #include "stream-event.hh"
24 #include "warn.hh"
25 #include "lily-imports.hh"
26
27 #include "translator.icc"
28
29 class Key_performer : public Performer
30 {
31 public:
32   TRANSLATOR_DECLARATIONS (Key_performer);
33   ~Key_performer ();
34
35 protected:
36   void process_music ();
37   void stop_translation_timestep ();
38
39   void listen_key_change (Stream_event *);
40 private:
41   Stream_event *key_ev_;
42   Audio_key *audio_;
43 };
44
45 Key_performer::Key_performer (Context *c)
46   : Performer (c)
47 {
48   key_ev_ = 0;
49   audio_ = 0;
50 }
51
52 Key_performer::~Key_performer ()
53 {
54 }
55
56 void
57 Key_performer::process_music ()
58 {
59   if (key_ev_)
60     {
61       SCM pitchlist = key_ev_->get_property ("pitch-alist");
62
63       SCM acc = Lily::alterations_in_key (pitchlist);
64
65       Pitch key_do (0,
66                     scm_to_int (scm_caar (pitchlist)),
67                     ly_scm2rational (scm_cdar (pitchlist)));
68
69       Pitch c_do;
70
71       SCM c_pitchlist
72         = ly_transpose_key_alist (pitchlist,
73                                   pitch_interval (key_do, c_do).smobbed_copy ());
74
75       /* MIDI keys are too limited for lilypond scales.
76          We check for minor scale and assume major otherwise.  */
77
78       SCM third = scm_assoc (scm_from_int (2),
79                              c_pitchlist);
80       bool minor = (scm_is_pair (third)
81                     && scm_is_number (scm_cdr (third))
82                     && ly_scm2rational (scm_cdr (third)) == FLAT_ALTERATION);
83
84       audio_ = new Audio_key (scm_to_int (acc),
85                               !minor);
86
87       Audio_element_info info (audio_, key_ev_);
88       announce_element (info);
89       key_ev_ = 0;
90     }
91 }
92
93 void
94 Key_performer::stop_translation_timestep ()
95 {
96   if (audio_)
97     {
98       audio_ = 0;
99     }
100 }
101
102 void
103 Key_performer::listen_key_change (Stream_event *ev)
104 {
105   if (!key_ev_)
106     key_ev_ = ev;
107 }
108
109 void
110 Key_performer::boot ()
111 {
112   ADD_LISTENER (Key_performer, key_change);
113 }
114
115 ADD_TRANSLATOR (Key_performer,
116                 /* doc */
117                 "",
118
119                 /* create */
120                 "",
121
122                 /* read */
123                 "",
124
125                 /* write */
126                 ""
127                );