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>
9 #include "audio-item.hh"
10 #include "music-sequence.hh"
11 #include "performer.hh"
12 #include "stream-event.hh"
15 #include "translator.icc"
17 class Key_performer : public Performer
20 TRANSLATOR_DECLARATIONS (Key_performer);
24 void process_music ();
25 void stop_translation_timestep ();
27 DECLARE_TRANSLATOR_LISTENER (key_change);
29 Stream_event *key_ev_;
33 Key_performer::Key_performer ()
39 Key_performer::~Key_performer ()
44 Key_performer::process_music ()
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);
54 scm_to_int (scm_caar (pitchlist)),
55 ly_scm2rational (scm_cdar (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),
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),
75 Audio_element_info info (audio_, key_ev_);
76 announce_element (info);
82 Key_performer::stop_translation_timestep ()
90 IMPLEMENT_TRANSLATOR_LISTENER (Key_performer, key_change);
92 Key_performer::listen_key_change (Stream_event *ev)
98 ADD_TRANSLATOR (Key_performer,