summaryrefslogtreecommitdiff
path: root/lily/trill-spanner-engraver.cc
blob: 6634b5ea43be9cee202f9772cdeb79f00f6f765a (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
  This file is part of LilyPond, the GNU music typesetter.

  Copyright (C) 2000--2015 Jan Nieuwenhuizen <janneke@gnu.org>

  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/>.
*/

/*
  C&P from text-spanner.cc

  - todo: ending should be detected automatically? a new note
  automatically is the end of the trill?
*/

#include "engraver.hh"

#include "international.hh"
#include "note-column.hh"
#include "pointer-group-interface.hh"
#include "side-position-interface.hh"
#include "stream-event.hh"
#include "spanner.hh"

#include "translator.icc"

class Trill_spanner_engraver : public Engraver
{
public:
  TRANSLATOR_DECLARATIONS (Trill_spanner_engraver);
protected:
  virtual void finalize ();
  void listen_trill_span (Stream_event *);
  void acknowledge_note_column (Grob_info);

  void stop_translation_timestep ();
  void process_music ();

private:
  Spanner *span_;
  Spanner *finished_;
  Stream_event *current_event_;
  Drul_array<Stream_event *> event_drul_;
  void typeset_all ();
};

Trill_spanner_engraver::Trill_spanner_engraver ()
{
  finished_ = 0;
  current_event_ = 0;
  span_ = 0;
  event_drul_.set (0, 0);
}

void
Trill_spanner_engraver::listen_trill_span (Stream_event *ev)
{
  Direction d = to_dir (ev->get_property ("span-direction"));
  ASSIGN_EVENT_ONCE (event_drul_[d], ev);
}

void
Trill_spanner_engraver::acknowledge_note_column (Grob_info info)
{
  if (span_)
    {
      Pointer_group_interface::add_grob (span_,
                                         ly_symbol2scm ("note-columns"),
                                         info.grob ());
      if (!span_->get_bound (LEFT))
        add_bound_item (span_, info.grob ());
    }
  else if (finished_)
    {
      Pointer_group_interface::add_grob (finished_, ly_symbol2scm ("note-columns"),
                                         info.grob ());
      if (!finished_->get_bound (RIGHT))
        add_bound_item (finished_, info.grob ());
    }
}

void
Trill_spanner_engraver::process_music ()
{
  if (span_
      && (event_drul_[STOP] || event_drul_[START]))
    {
      Stream_event *ender = event_drul_[STOP];
      if (!ender)
        ender = event_drul_[START];
      finished_ = span_;
      announce_end_grob (finished_, ender->self_scm ());
      span_ = 0;
      current_event_ = 0;
    }

  if (event_drul_[START])
    {
      current_event_ = event_drul_[START];
      span_ = make_spanner ("TrillSpanner", event_drul_[START]->self_scm ());
      Side_position_interface::set_axis (span_, Y_AXIS);
    }
}

void
Trill_spanner_engraver::typeset_all ()
{
  if (finished_)
    {
      if (!finished_->get_bound (RIGHT))
        {
          Grob *e = unsmob<Grob> (get_property ("currentMusicalColumn"));
          finished_->set_bound (RIGHT, e);
        }
      finished_ = 0;
    }
}

void
Trill_spanner_engraver::stop_translation_timestep ()
{
  if (span_ && !span_->get_bound (LEFT))
    {
      Grob *e = unsmob<Grob> (get_property ("currentMusicalColumn"));
      span_->set_bound (LEFT, e);
    }

  typeset_all ();
  event_drul_.set (0, 0);
}

void
Trill_spanner_engraver::finalize ()
{
  typeset_all ();
  if (span_)
    {
      Grob *e = unsmob<Grob> (get_property ("currentCommandColumn"));
      span_->set_bound (RIGHT, e);
    }
}


void
Trill_spanner_engraver::boot ()
{
  ADD_LISTENER (Trill_spanner_engraver, trill_span);
  ADD_ACKNOWLEDGER (Trill_spanner_engraver, note_column);
}

ADD_TRANSLATOR (Trill_spanner_engraver,
                /* doc */
                "Create trill spanner from an event.",

                /* create */
                "TrillSpanner ",

                /* read */
                "currentCommandColumn "
                "currentMusicalColumn ",

                /* write */
                ""
               );