~ubuntu-branches/ubuntu/precise/lilypond/precise

« back to all changes in this revision

Viewing changes to lily/auto-change-iterator.cc

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Bushnell, BSG
  • Date: 2006-12-19 10:18:12 UTC
  • mfrom: (3.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061219101812-7awtjkp0i393wxty
Tags: 2.8.7-3
scripts/midi2ly.py: When setting DATADIR, find Lilypond python files
in the @TOPLEVEL_VERSION@ directory, not 'current'.  Patch thanks to
Chris Lamb (chris@chris-lamb.co.uk).  (Closes: #400550)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*   
 
1
/*
2
2
  auto-change-iterator.cc -- implement  Auto_change_iterator
3
3
 
4
4
  source file of the GNU LilyPond music typesetter
5
 
  
6
 
  (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
 
  
8
 
 */
9
 
 
10
 
#include "music.hh"
 
5
 
 
6
  (c) 1999--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
7
*/
 
8
 
11
9
#include "context.hh"
12
 
#include "event.hh"
 
10
#include "direction.hh"
 
11
#include "international.hh"
13
12
#include "music-wrapper-iterator.hh"
14
 
#include "direction.hh"
15
13
 
16
14
class Auto_change_iterator : public Music_wrapper_iterator
17
15
{
18
16
public:
19
17
  DECLARE_SCHEME_CALLBACK (constructor, ());
20
 
  
 
18
 
21
19
  Auto_change_iterator ();
22
20
 
23
21
protected:
 
22
  virtual void do_quit ();
24
23
  virtual void construct_children ();
25
 
  virtual void process (Moment);  
26
 
  Array<Pitch> pending_pitch (Moment)const;
 
24
  virtual void process (Moment);
 
25
  vector<Pitch> pending_pitch (Moment) const;
27
26
private:
28
27
  SCM split_list_;
29
28
  Direction where_dir_;
30
 
  void change_to (Music_iterator* , SCM, String);
 
29
  void change_to (Music_iterator *, SCM, string);
31
30
  Moment start_moment_;
 
31
 
 
32
  Context_handle up_;
 
33
  Context_handle down_;
32
34
};
33
35
 
34
 
 
35
 
 
36
36
void
37
37
Auto_change_iterator::change_to (Music_iterator *it, SCM to_type_sym,
38
 
                                 String to_id)
 
38
                                 string to_id)
39
39
{
40
 
  Context * current = it->get_outlet ();
41
 
  Context * last = 0;
 
40
  Context *current = it->get_outlet ();
 
41
  Context *last = 0;
42
42
 
43
43
  /*
44
44
    Cut & Paste from Change_iterator (ugh).
45
45
 
46
 
    TODO: abstract this function 
47
 
   */
48
 
  
 
46
    TODO: abstract this function
 
47
  */
 
48
 
49
49
  /* find the type  of translator that we're changing.
50
 
     
51
 
     If \translator Staff = bass, then look for Staff = *
52
 
   */
 
50
 
 
51
  If \translator Staff = bass, then look for Staff = *
 
52
  */
53
53
  while (current && !current->is_alias (to_type_sym))
54
54
    {
55
55
      last = current;
56
 
      current = current->daddy_context_;
57
 
    }
58
 
 
59
 
  if (current && current->id_string_ == to_id)
60
 
    {
61
 
      String msg;
62
 
      msg += _ ("Can't switch translators, I'm there already");
63
 
    }
64
 
  
65
 
  if (current) 
66
 
    if (last)
67
 
      {
68
 
        Context * dest = 
69
 
          it->get_outlet ()->find_create_context (to_type_sym, to_id, SCM_EOL);
70
 
        current->remove_context (last);
71
 
        dest->add_context (last);
72
 
      }
73
 
    else
74
 
      {
75
 
        /*
76
 
          We could change the current translator's id, but that would make 
77
 
          errors hard to catch
78
 
          
79
 
        */
80
 
      }
81
 
  else
82
 
    ;
83
 
 
 
56
      current = current->get_parent_context ();
 
57
    }
 
58
 
 
59
  if (current && current->id_string () == to_id)
 
60
    {
 
61
      string msg;
 
62
      msg += _f ("can't change, already in translator: %s", to_id);
 
63
    }
 
64
 
 
65
  if (current)
 
66
    {
 
67
      if (last)
 
68
        {
 
69
          Context *dest
 
70
            = it->get_outlet ()->find_create_context (to_type_sym, to_id, SCM_EOL);
 
71
          current->remove_context (last);
 
72
          dest->add_context (last);
 
73
        }
 
74
      else
 
75
        {
 
76
          /*
 
77
            We could change the current translator's id, but that would make
 
78
            errors hard to catch
 
79
 
 
80
          */
 
81
          ;
 
82
        }
 
83
    }
84
84
}
85
85
 
86
86
void
87
87
Auto_change_iterator::process (Moment m)
88
88
{
89
89
  Music_wrapper_iterator::process (m);
90
 
  
 
90
 
91
91
  Moment now = get_outlet ()->now_mom ();
92
92
  Moment *splitm = 0;
93
 
  
94
 
  for (; gh_pair_p (split_list_); split_list_ = gh_cdr (split_list_))
 
93
 
 
94
  for (; scm_is_pair (split_list_); split_list_ = scm_cdr (split_list_))
95
95
    {
96
 
      splitm = unsmob_moment (gh_caar (split_list_));
 
96
      splitm = unsmob_moment (scm_caar (split_list_));
97
97
      if ((*splitm + start_moment_) > now)
98
 
        break ;
99
 
 
100
 
      SCM tag = gh_cdar (split_list_);
101
 
      Direction d = to_dir  (tag);
102
 
      
 
98
        break;
 
99
 
 
100
      SCM tag = scm_cdar (split_list_);
 
101
      Direction d = to_dir (tag);
 
102
 
103
103
      if (d && d != where_dir_)
104
104
        {
105
105
          where_dir_ = d;
106
 
          String to_id = (d >= 0) ?  "up" : "down";
 
106
          string to_id = (d >= 0) ? "up" : "down";
107
107
          change_to (child_iter_,
108
108
                     ly_symbol2scm ("Staff"),
109
109
                     to_id);
120
120
void
121
121
Auto_change_iterator::construct_children ()
122
122
{
 
123
  split_list_ = get_music ()->get_property ("split-list");
 
124
  start_moment_ = get_outlet ()->now_mom ();
 
125
 
 
126
  SCM props = get_outlet ()->get_property ("trebleStaffProperties");
 
127
  Context *up = get_outlet ()->find_create_context (ly_symbol2scm ("Staff"),
 
128
                                                    "up", props);
 
129
 
 
130
  props = get_outlet ()->get_property ("bassStaffProperties");
 
131
  Context *down = get_outlet ()->find_create_context (ly_symbol2scm ("Staff"),
 
132
                                                      "down", props);
 
133
 
 
134
  up_.set_context (up);
 
135
  down_.set_context (down);
 
136
 
 
137
  Context *voice = up->find_create_context (ly_symbol2scm ("Voice"),
 
138
                                            "", SCM_EOL);
 
139
  set_context (voice);
123
140
  Music_wrapper_iterator::construct_children ();
124
 
  split_list_ =  get_music ()->get_property ("split-list");
125
 
  start_moment_ = get_outlet ()->now_mom ();
 
141
}
 
142
 
 
143
void
 
144
Auto_change_iterator::do_quit ()
 
145
{
 
146
  up_.set_context (0);
 
147
  down_.set_context (0);
126
148
}
127
149
 
128
150
IMPLEMENT_CTOR_CALLBACK (Auto_change_iterator);