]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/auto-change-iterator.cc
Imported Upstream version 2.19.45
[lilypond.git] / lily / auto-change-iterator.cc
index 0ae3021d4670172be651ba9e1abd56df4b90f4ed..55ff27d316aa5d453024fdda1f76c75c7007f26e 100644 (file)
@@ -1,99 +1,41 @@
-/*   
-  auto-change-iterator.cc -- implement  Auto_change_iterator
+/*
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
-  
-  (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
- */
+  Copyright (C) 1999--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-#include "auto-change-music.hh"
-#include "auto-change-iterator.hh"
-#include "translator-group.hh"
-#include "musical-request.hh"
+  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.
 
+  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.
 
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
-void
-Auto_change_iterator::change_to (Music_iterator *it, String to_type,
-                                String to_id)
-{
-  Translator_group * current = it->report_to_l ();
-  Translator_group * last = 0;
-
-  /*
-    Cut & Paste from Change_iterator (ugh).
+#include "change-iterator.hh"
+#include "change-sequence-iterator.hh"
 
-    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_str_ != to_type)
-    {
-      last = current;
-      current = current->daddy_trans_l_;
-    }
+class Auto_change_iterator : public Change_sequence_iterator
+{
+public:
+  DECLARE_SCHEME_CALLBACK (constructor, ());
+  Auto_change_iterator () {}
 
-  if (current && current->id_str_ == to_id)
-    {
-      String msg;
-      msg += _ ("Can't switch translators, I'm there already");
-    }
-  
-  if (current) 
-    if (last)
-      {
-       Translator_group * dest = 
-         it->report_to_l ()->find_create_translator_l (to_type, to_id);
-       current->remove_translator_p (last);
-       dest->add_group_translator (last);
-      }
-    else
-      {
-       /*
-         We could change the current translator's id, but that would make 
-         errors hard to catch
-         
-          last->translator_id_str_  = change_l ()->change_to_id_str_;
-       */
-       //      error (_ ("I'm one myself"));
-      }
-  else
-    ; //    error (_ ("none of these in my family"));
+private:
+  virtual void change_to (const string &id);
+};
 
-}
-Pitch_interrogate_req* spanish_inquisition; // nobody expects it
 void
-Auto_change_iterator::do_process_and_next (Moment m)
+Auto_change_iterator::change_to (const string &id)
 {
-  Music_wrapper_iterator::do_process_and_next (m);
-
-  if (!spanish_inquisition)
-    spanish_inquisition = new Pitch_interrogate_req;
-
-  Music_iterator *it = try_music (spanish_inquisition);
-
-  if (it && spanish_inquisition->pitch_arr_.size ())
-    {
-      Musical_pitch p = spanish_inquisition->pitch_arr_[0];
-      Direction s = Direction (sign(p.steps ()));
-      if (s != where_dir_)
-       {
-         where_dir_ = s;
-         String to_id =  (s >= 0) ?  "up" : "down";
-         Auto_change_music const * auto_mus = dynamic_cast<Auto_change_music const* > (music_l_);
-
-         change_to (it, auto_mus->what_str_, to_id);     
-       }
-    }
-
-  spanish_inquisition->pitch_arr_.clear ();
+  // 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);
 }
 
-Auto_change_iterator::Auto_change_iterator( )
-{
-  where_dir_ = CENTER;
-}
+IMPLEMENT_CTOR_CALLBACK (Auto_change_iterator);