lilypond-1.1.55
[lilypond.git] / lily / staff-switching-translator.cc
blobffeda7fc2646157195ad4e34e45fb5109f0c357b
1 /*
2 staff-switching-translator.cc -- implement Staff_switching_translator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include "engraver.hh"
10 #include "interpretation-context-handle.hh"
11 #include "drul-array.hh"
12 #include "engraver-group.hh"
13 #include "musical-request.hh"
15 class Staff_switching_translator : public Engraver
17 Interpretation_context_handle my_voice_;
18 Drul_array<Interpretation_context_handle> staff_handle_drul_;
19 protected:
20 virtual bool do_try_music (Music* m);
21 virtual void do_creation_processing ();
22 public:
23 Staff_switching_translator ();
24 VIRTUAL_COPY_CONS(Translator);
27 Staff_switching_translator::Staff_switching_translator ()
31 void
32 Staff_switching_translator::do_creation_processing ()
34 Translator_group * daddy =daddy_grav_l (); // staff switching context
36 staff_handle_drul_[UP].set_translator (daddy->daddy_trans_l_ -> find_create_translator_l ("Staff", "upper"));
37 staff_handle_drul_[DOWN].set_translator (daddy->daddy_trans_l_-> find_create_translator_l ("Staff", "lower"));
40 staff_handle_drul_[DOWN].report_to_l ()->set_property ("defaultClef", "bass");
42 my_voice_.set_translator (staff_handle_drul_[UP].report_to_l ()->find_create_translator_l ("Voice", daddy->id_str_));
45 bool
46 Staff_switching_translator::do_try_music (Music*m)
48 if (Note_req*nr = dynamic_cast<Note_req*> (m))
50 Direction staff = (nr->pitch_.semitone_pitch () >= 0)
51 ? UP
52 : DOWN;
55 Translator_group * mv = my_voice_.report_to_l ();
56 Translator_group *dest_staff =staff_handle_drul_[staff].report_to_l ();
57 if (mv->daddy_trans_l_ != dest_staff)
59 mv->daddy_trans_l_->remove_translator_p (mv);
60 dest_staff->add_translator (mv);
64 return my_voice_.try_music (m);
67 ADD_THIS_TRANSLATOR(Staff_switching_translator);