Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / key-performer.cc
blob93d932b8d5494a0a3483eaa9e66991572ef52030
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "audio-item.hh"
21 #include "music-sequence.hh"
22 #include "performer.hh"
23 #include "stream-event.hh"
24 #include "warn.hh"
26 #include "translator.icc"
28 class Key_performer : public Performer
30 public:
31 TRANSLATOR_DECLARATIONS (Key_performer);
32 ~Key_performer ();
34 protected:
35 void process_music ();
36 void stop_translation_timestep ();
38 DECLARE_TRANSLATOR_LISTENER (key_change);
39 private:
40 Stream_event *key_ev_;
41 Audio_key *audio_;
44 Key_performer::Key_performer ()
46 key_ev_ = 0;
47 audio_ = 0;
50 Key_performer::~Key_performer ()
54 void
55 Key_performer::process_music ()
57 if (key_ev_)
59 SCM pitchlist = key_ev_->get_property ("pitch-alist");
60 SCM proc = ly_lily_module_constant ("alterations-in-key");
62 SCM acc = scm_call_1 (proc, pitchlist);
64 Pitch key_do (0,
65 scm_to_int (scm_caar (pitchlist)),
66 ly_scm2rational (scm_cdar (pitchlist)));
68 Pitch c_do (0, 0, 0);
70 SCM c_pitchlist
71 = ly_transpose_key_alist (pitchlist,
72 pitch_interval (key_do, c_do).smobbed_copy ());
74 /* MIDI keys are too limited for lilypond scales.
75 We check for minor scale and assume major otherwise. */
77 SCM third = scm_assoc (scm_from_int (2),
78 c_pitchlist);
79 bool minor = (scm_is_pair (third)
80 && scm_is_number (scm_cdr (third))
81 && ly_scm2rational (scm_cdr (third)) == FLAT_ALTERATION);
83 audio_ = new Audio_key (scm_to_int (acc),
84 !minor);
86 Audio_element_info info (audio_, key_ev_);
87 announce_element (info);
88 key_ev_ = 0;
92 void
93 Key_performer::stop_translation_timestep ()
95 if (audio_)
97 audio_ = 0;
101 IMPLEMENT_TRANSLATOR_LISTENER (Key_performer, key_change);
102 void
103 Key_performer::listen_key_change (Stream_event *ev)
105 if (!key_ev_)
106 key_ev_ = ev;
109 ADD_TRANSLATOR (Key_performer,
110 /* doc */
113 /* create */
116 /* read */
119 /* write */