]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-performer.cc
* input/test/staff-container.ly: update file
[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_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
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  
55       Pitch my_do (0, 
56                    gh_scm2int (ly_caar (pitchlist)),
57                    gh_scm2int (ly_cdar (pitchlist)));
58                   
59       Pitch to_c (-1,
60                    (7 - gh_scm2int (ly_caar (pitchlist))) % 7,
61                    -gh_scm2int (ly_cdar (pitchlist)));
62
63       my_do = my_do.transposed (to_c);
64       to_c = my_do.transposed (Pitch(0,0,- my_do.get_alteration ()));
65
66       SCM c_pitchlist = ly_transpose_key_alist (pitchlist, to_c.smobbed_copy());
67
68       /*
69         MIDI keys are too limited for lilypond scales.
70
71         TODO: should probably detect minor key, though.
72       */
73       audio_ = new Audio_key (gh_scm2int (acc), true); 
74       Audio_element_info info (audio_, key_req_);
75       announce_element (info);
76       key_req_ = 0;
77     }
78 }
79
80 void
81 Key_performer::stop_translation_timestep ()
82 {
83   if (audio_)
84     {
85       play_element (audio_);
86       audio_ = 0;
87     }
88 }
89
90 bool
91 Key_performer::try_music (Music* req)
92 {
93   if (Key_change_ev *kc = dynamic_cast <Key_change_ev *> (req))
94     {
95       if (key_req_)
96         warning (_ ("FIXME: key change merge"));
97
98       key_req_ = kc;
99       return true;
100     }
101
102   return false;
103 }
104
105 ENTER_DESCRIPTION(Key_performer,
106                   "","",
107                   "key-change-event",
108                   "","","");