]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-performer.cc
*** empty log message ***
[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--2003 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_req* 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
48       /*
49         UGH. primitive-eval.
50        */
51       SCM pitchlist = key_req_->get_mus_property ("pitch-alist");
52       SCM proc = scm_primitive_eval (ly_symbol2scm ("accidentals-in-key")); 
53       SCM acc = gh_call1 (proc, pitchlist);
54       proc = scm_primitive_eval (ly_symbol2scm ("major-key"));
55  
56       Pitch my_do (0, 
57                    gh_scm2int (ly_caar (pitchlist)),
58                    gh_scm2int (ly_cdar (pitchlist)));
59                   
60       Pitch to_c (-1,
61                    (7 - gh_scm2int (ly_caar (pitchlist))) % 7,
62                    -gh_scm2int (ly_cdar (pitchlist)));
63
64       my_do.transpose (to_c);
65       to_c.alteration_ -= my_do.alteration_;
66
67       SCM c_pitchlist = transpose_key_alist (pitchlist, to_c.smobbed_copy());
68       SCM major = gh_call1 (proc, c_pitchlist);
69
70       audio_ = new Audio_key (gh_scm2int (acc), major == SCM_BOOL_T); 
71       Audio_element_info info (audio_, key_req_);
72       announce_element (info);
73       key_req_ = 0;
74     }
75 }
76
77 void
78 Key_performer::stop_translation_timestep ()
79 {
80   if (audio_)
81     {
82       play_element (audio_);
83       audio_ = 0;
84     }
85 }
86
87 bool
88 Key_performer::try_music (Music* req)
89 {
90   if (Key_change_req *kc = dynamic_cast <Key_change_req *> (req))
91     {
92       if (key_req_)
93         warning (_ ("FIXME: key change merge"));
94
95       key_req_ = kc;
96       return true;
97     }
98
99   return false;
100 }
101
102 ENTER_DESCRIPTION(Key_performer,
103                   "","",
104                   "key-change-event",
105                   "","","");