]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-performer.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / key-performer.cc
1 /*
2   key-performer.cc -- implement Key_performer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "music-sequence.hh"
10 #include "audio-item.hh"
11 #include "performer.hh"
12 #include "warn.hh"
13
14 class Key_performer : public Performer
15 {
16 public:
17   TRANSLATOR_DECLARATIONS (Key_performer);
18   ~Key_performer ();
19
20 protected:
21   virtual bool try_music (Music *ev);
22   void process_music ();
23   void stop_translation_timestep ();
24
25 private:
26   Music *key_ev_;
27   Audio_key *audio_;
28 };
29
30 Key_performer::Key_performer ()
31 {
32   key_ev_ = 0;
33   audio_ = 0;
34 }
35
36 Key_performer::~Key_performer ()
37 {
38 }
39
40 void
41 Key_performer::process_music ()
42 {
43   if (key_ev_)
44     {
45       SCM pitchlist = key_ev_->get_property ("pitch-alist");
46       SCM proc = ly_lily_module_constant ("alterations-in-key");
47
48       SCM acc = scm_call_1 (proc, pitchlist);
49
50       Pitch key_do (0,
51                     scm_to_int (scm_caar (pitchlist)),
52                     scm_to_int (scm_cdar (pitchlist)));
53
54       Pitch c_do (0, 0, 0);
55
56       SCM c_pitchlist
57         = ly_transpose_key_alist (pitchlist,
58                                   pitch_interval (key_do, c_do).smobbed_copy ());
59
60       /* MIDI keys are too limited for lilypond scales.
61          We check for minor scale and assume major otherwise.  */
62
63       SCM third = scm_assoc (scm_from_int (2),
64                              c_pitchlist);
65       bool minor = (scm_is_pair (third)
66                     && scm_is_integer (scm_cdr (third))
67                     && scm_to_int (scm_cdr (third)) == FLAT);
68
69       audio_ = new Audio_key (scm_to_int (acc),
70                               !minor);
71
72       Audio_element_info info (audio_, key_ev_);
73       announce_element (info);
74       key_ev_ = 0;
75     }
76 }
77
78 void
79 Key_performer::stop_translation_timestep ()
80 {
81   if (audio_)
82     {
83       play_element (audio_);
84       audio_ = 0;
85     }
86 }
87
88 bool
89 Key_performer::try_music (Music *ev)
90 {
91   if (!key_ev_)
92     key_ev_ = ev;
93
94   return true;
95 }
96
97 #include "translator.icc"
98
99 ADD_TRANSLATOR (Key_performer,
100                 "", "",
101                 "key-change-event",
102                 "", "");