]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-performer.cc
* lily/accidental-placement.cc (position_accidentals): bugfix in
[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--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "lily-guile.hh"
10
11 #include "audio-item.hh"
12 #include "performer.hh"
13 #include "warn.hh"
14
15
16 class Key_performer : public Performer
17 {
18 public:
19   TRANSLATOR_DECLARATIONS (Key_performer);
20   ~Key_performer ();
21
22 protected:
23   virtual bool try_music (Music* req);
24   virtual void create_audio_elements ();
25   virtual void stop_translation_timestep ();
26
27 private:
28   Key_change_ev* key_req_;
29   Audio_key* audio_;
30 };
31
32 Key_performer::Key_performer ()
33 {
34   key_req_ = 0;
35   audio_ = 0;
36 }
37
38 Key_performer::~Key_performer ()
39 {
40 }
41
42 void
43 Key_performer::create_audio_elements ()
44 {
45   if (key_req_) 
46     {
47       SCM pitchlist = key_req_->get_property ("pitch-alist");
48       static SCM proc;
49       if (!proc)
50         proc = scm_primitive_eval (ly_symbol2scm ("alterations-in-key"));
51       
52       SCM acc = gh_call1 (proc, pitchlist);
53       
54       Pitch key_do (0, 
55                     gh_scm2int (ly_caar (pitchlist)),
56                     gh_scm2int (ly_cdar (pitchlist)));
57
58       Pitch c_do (0, 0, 0);
59                   
60       SCM c_pitchlist
61         = ly_transpose_key_alist (pitchlist,
62                                   interval (key_do, c_do).smobbed_copy ());
63
64       /* MIDI keys are too limited for lilypond scales.
65          We check for minor scale and assume major otherwise.  */
66       SCM minor = scm_primitive_eval (ly_symbol2scm ("minor"));
67       audio_ = new Audio_key (gh_scm2int (acc),
68                               SCM_BOOL_T != scm_equal_p (minor, c_pitchlist));
69
70       Audio_element_info info (audio_, key_req_);
71       announce_element (info);
72       key_req_ = 0;
73     }
74 }
75
76 void
77 Key_performer::stop_translation_timestep ()
78 {
79   if (audio_)
80     {
81       play_element (audio_);
82       audio_ = 0;
83     }
84 }
85
86 bool
87 Key_performer::try_music (Music* req)
88 {
89   if (Key_change_ev *kc = dynamic_cast <Key_change_ev *> (req))
90     {
91       if (key_req_)
92         warning (_ ("FIXME: key change merge"));
93
94       key_req_ = kc;
95       return true;
96     }
97
98   return false;
99 }
100
101 ENTER_DESCRIPTION (Key_performer,
102                   "","",
103                   "key-change-event",
104                   "","","");