* stepmake/stepmake/metafont-rules.make: backport 1.7 fixes.
[lilypond.git] / lily / key-performer.cc
blob7401a637de01672927c1ce887d804afc064152bd
1 /*
2 key-performer.cc -- implement Key_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "lily-guile.hh"
10 #include "command-request.hh"
11 #include "audio-item.hh"
12 #include "performer.hh"
13 #include "warn.hh"
16 class Key_performer : public Performer
18 public:
19 TRANSLATOR_DECLARATIONS(Key_performer);
20 ~Key_performer ();
22 protected:
23 virtual bool try_music (Music* req);
24 virtual void create_audio_elements ();
25 virtual void stop_translation_timestep ();
27 private:
28 Key_change_req* key_req_;
29 Audio_key* audio_;
32 Key_performer::Key_performer ()
34 key_req_ = 0;
35 audio_ = 0;
38 Key_performer::~Key_performer ()
42 void
43 Key_performer::create_audio_elements ()
45 if (key_req_)
47 SCM pitchlist = key_req_->get_mus_property ("pitch-alist");
48 SCM proc = scm_primitive_eval (ly_symbol2scm ("accidentals-in-key"));
49 SCM acc = gh_call1 (proc, pitchlist);
50 proc = scm_primitive_eval (ly_symbol2scm ("major-key"));
52 Pitch my_do (0,
53 gh_scm2int (ly_caar (pitchlist)),
54 gh_scm2int (ly_cdar (pitchlist)));
56 Pitch to_c (-1,
57 (7 - gh_scm2int (ly_caar (pitchlist))) % 7,
58 -gh_scm2int (ly_cdar (pitchlist)));
60 my_do.transpose (to_c);
61 to_c.alteration_ -= my_do.alteration_;
63 Key_change_req *key = new Key_change_req;
64 key->set_mus_property ("pitch-alist", scm_list_copy (pitchlist));
65 ((Music*)key)->transpose (to_c);
66 SCM c_pitchlist = key->get_mus_property ("pitch-alist");
67 SCM major = gh_call1 (proc, c_pitchlist);
69 audio_ = new Audio_key (gh_scm2int (acc), major == SCM_BOOL_T);
70 Audio_element_info info (audio_, key_req_);
71 announce_element (info);
72 key_req_ = 0;
76 void
77 Key_performer::stop_translation_timestep ()
79 if (audio_)
81 play_element (audio_);
82 audio_ = 0;
86 bool
87 Key_performer::try_music (Music* req)
89 if (Key_change_req *kc = dynamic_cast <Key_change_req *> (req))
91 if (key_req_)
92 warning (_ ("FIXME: key change merge"));
94 key_req_ = kc;
95 return true;
98 return false;
101 ENTER_DESCRIPTION(Key_performer,"","","","","");