Correct left text alignment of DynamicTextSpanner.
[lilypond.git] / lily / key-performer.cc
blob8a12e9bcf5f00b325f3dca5945b56ebba346b6ee
1 /*
2 key-performer.cc -- implement Key_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "audio-item.hh"
10 #include "music-sequence.hh"
11 #include "performer.hh"
12 #include "stream-event.hh"
13 #include "warn.hh"
15 #include "translator.icc"
17 class Key_performer : public Performer
19 public:
20 TRANSLATOR_DECLARATIONS (Key_performer);
21 ~Key_performer ();
23 protected:
24 void process_music ();
25 void stop_translation_timestep ();
27 DECLARE_TRANSLATOR_LISTENER (key_change);
28 private:
29 Stream_event *key_ev_;
30 Audio_key *audio_;
33 Key_performer::Key_performer ()
35 key_ev_ = 0;
36 audio_ = 0;
39 Key_performer::~Key_performer ()
43 void
44 Key_performer::process_music ()
46 if (key_ev_)
48 SCM pitchlist = key_ev_->get_property ("pitch-alist");
49 SCM proc = ly_lily_module_constant ("alterations-in-key");
51 SCM acc = scm_call_1 (proc, pitchlist);
53 Pitch key_do (0,
54 scm_to_int (scm_caar (pitchlist)),
55 ly_scm2rational (scm_cdar (pitchlist)));
57 Pitch c_do (0, 0, 0);
59 SCM c_pitchlist
60 = ly_transpose_key_alist (pitchlist,
61 pitch_interval (key_do, c_do).smobbed_copy ());
63 /* MIDI keys are too limited for lilypond scales.
64 We check for minor scale and assume major otherwise. */
66 SCM third = scm_assoc (scm_from_int (2),
67 c_pitchlist);
68 bool minor = (scm_is_pair (third)
69 && scm_is_number (scm_cdr (third))
70 && ly_scm2rational (scm_cdr (third)) == FLAT_ALTERATION);
72 audio_ = new Audio_key (scm_to_int (acc),
73 !minor);
75 Audio_element_info info (audio_, key_ev_);
76 announce_element (info);
77 key_ev_ = 0;
81 void
82 Key_performer::stop_translation_timestep ()
84 if (audio_)
86 audio_ = 0;
90 IMPLEMENT_TRANSLATOR_LISTENER (Key_performer, key_change);
91 void
92 Key_performer::listen_key_change (Stream_event *ev)
94 if (!key_ev_)
95 key_ev_ = ev;
98 ADD_TRANSLATOR (Key_performer,
99 /* doc */
102 /* create */
105 /* read */
108 /* write */