]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-performer.cc
74f702c6afaabb9e55dedd7f83bdf6f5688d8ee3
[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--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "lily-guile.hh"
10 #include "command-request.hh"
11 #include "audio-item.hh"
12 #include "performer.hh"
13
14 class Key_performer : public Performer
15 {
16 public:
17   VIRTUAL_COPY_CONS (Translator);
18   
19   Key_performer ();
20   ~Key_performer ();
21
22 protected:
23   virtual bool try_music (Music* req_l);
24   virtual void create_audio_elements ();
25   virtual void stop_translation_timestep ();
26
27 private:
28   Key_change_req* key_req_l_;
29   Audio_key* audio_p_;
30 };
31
32 ADD_THIS_TRANSLATOR (Key_performer);
33
34 Key_performer::Key_performer ()
35 {
36   key_req_l_ = 0;
37   audio_p_ = 0;
38 }
39
40 Key_performer::~Key_performer ()
41 {
42 }
43
44 void
45 Key_performer::create_audio_elements ()
46 {
47   if (key_req_l_) 
48     {
49       SCM pitchlist = key_req_l_->get_mus_property ("pitch-alist");
50       SCM proc = scm_eval2 (ly_symbol2scm ("accidentals-in-key"), SCM_EOL); 
51       SCM acc = gh_call1 (proc, pitchlist);
52       proc = scm_eval2 (ly_symbol2scm ("major-key"), SCM_EOL);
53       SCM major = gh_call1 (proc, pitchlist);
54       audio_p_ = new Audio_key (gh_scm2int (acc), major == SCM_BOOL_T); 
55       Audio_element_info info (audio_p_, key_req_l_);
56       announce_element (info);
57       key_req_l_ = 0;
58     }
59 }
60
61 void
62 Key_performer::stop_translation_timestep ()
63 {
64   if (audio_p_)
65     {
66       play_element (audio_p_);
67       audio_p_ = 0;
68     }
69 }
70
71 bool
72 Key_performer::try_music (Music* req_l)
73 {
74   if (Key_change_req *kc = dynamic_cast <Key_change_req *> (req_l))
75     {
76       if (key_req_l_)
77         warning (_ ("FIXME: key change merge"));
78
79       key_req_l_ = kc;
80       return true;
81     }
82
83   return false;
84 }
85