-/*
- auto-change-iterator.cc -- implement Auto_change_iterator
-
- source file of the GNU LilyPond music typesetter
-
- (c) 1999--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-
- */
-
-#include "music.hh"
-#include "auto-change-iterator.hh"
-#include "translator-group.hh"
-#include "musical-request.hh"
-
-
-
-void
-Auto_change_iterator::change_to (Music_iterator *it, String to_type,
- String to_id)
-{
- Translator_group * current = it->report_to ();
- Translator_group * last = 0;
-
- /*
- Cut & Paste from Change_iterator (ugh).
-
- TODO: abstract this function
- */
-
- /* find the type of translator that we're changing.
-
- If \translator Staff = bass, then look for Staff = *
- */
- while (current && current->type_string_ != to_type)
- {
- last = current;
- current = current->daddy_trans_;
- }
-
- if (current && current->id_string_ == to_id)
- {
- String msg;
- msg += _ ("Can't switch translators, I'm there already");
- }
-
- if (current)
- if (last)
- {
- Translator_group * dest =
- it->report_to ()->find_create_translator (to_type, to_id);
- current->remove_translator (last);
- dest->add_used_group_translator (last);
- }
- else
- {
- /*
- We could change the current translator's id, but that would make
- errors hard to catch
-
- last->translator_id_string_ = get_change ()->change_to_id_string_;
- */
- // error (_ ("I'm one myself"));
- }
- else
- ; // error (_ ("none of these in my family"));
-
-}
-
/*
- Look ahead to find first pitches to determine staff position.
- WARNING: this means that
-
- \autochange Staff \notes { .... \context Staff = otherstaff { .. } .. }
+ This file is part of LilyPond, the GNU music typesetter.
- will confuse the autochanger, since it will not notice that the
- music for OTHERSTAFF is not his.
+ Copyright (C) 1999--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
- PRECONDITION: this->ok () holds.
-*/
-Array<Pitch>
-Auto_change_iterator::pending_pitch (Moment m) const
-{
- Music_iterator * iter = child_iter_ ->clone ();
- Array<Pitch> ps;
- while (1)
- {
- SCM muses = iter->get_pending_events (m);
- for (SCM s = muses; gh_pair_p (s); s=ly_cdr (s))
- if (Note_req* nr = dynamic_cast<Note_req*> (unsmob_music (ly_car (s))))
- {
- ps.push (*unsmob_pitch (nr->get_mus_property ("pitch")));
- }
+ LilyPond is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- if (ps.size ())
- break;
+ LilyPond is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- iter->skip (m);
- if (!iter->ok ())
- break;
-
- m = iter->pending_moment ();
- }
+ You should have received a copy of the GNU General Public License
+ along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
+*/
- delete iter;
- return ps;
-}
+#include "change-iterator.hh"
+#include "change-sequence-iterator.hh"
-void
-Auto_change_iterator::process (Moment m)
+class Auto_change_iterator : public Change_sequence_iterator
{
- /*
- first we get the pitches, then we do the real work.
- Music_wrapper_iterator::process () might process (and throw away)
- pitches we need. */
- Array<Pitch> ps = pending_pitch (m);
-
- Music_wrapper_iterator::process (m);
- if (ps.size ())
- {
- Pitch p = ps[0];
- Direction s = Direction (sign (p.steps ()));
- /*
- Don't change for central C.
+public:
+ DECLARE_SCHEME_CALLBACK (constructor, ());
+ Auto_change_iterator () {}
- TODO: make this tunable somehow. Sometimes, you'd want to
- switch for C.C. as well.
+private:
+ virtual void change_to (const string &id);
+};
- */
- if (s && s != where_dir_)
- {
- where_dir_ = s;
- String to_id = (s >= 0) ? "up" : "down";
- String wh = ly_scm2string (get_music ()->get_mus_property ("what"));
- change_to (child_iter_, wh, to_id);
- }
- }
-}
-
-Auto_change_iterator::Auto_change_iterator ()
+void
+Auto_change_iterator::change_to (const string &id)
{
- where_dir_ = CENTER;
+ // N.B. change_to() returns an error message. Silence is the legacy
+ // behavior here, but maybe that should be changed.
+ Change_iterator::change_to (*child_iter_, ly_symbol2scm ("Staff"), id);
}
IMPLEMENT_CTOR_CALLBACK (Auto_change_iterator);