2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1996--2015 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "performer.hh"
21 #include "audio-item.hh"
22 #include "audio-column.hh"
23 #include "global-context.hh"
24 #include "stream-event.hh"
27 #include "translator.icc"
31 class Note_performer : public Performer
34 TRANSLATOR_DECLARATIONS (Note_performer);
37 void stop_translation_timestep ();
38 void process_music ();
40 DECLARE_TRANSLATOR_LISTENER (note);
41 DECLARE_TRANSLATOR_LISTENER (breathing);
43 vector<Stream_event *> note_evs_;
44 vector<Audio_note *> notes_;
46 vector<Audio_note *> last_notes_;
52 Note_performer::process_music ()
54 if (!note_evs_.size ())
58 SCM prop = get_property ("instrumentTransposition");
59 if (unsmob<Pitch> (prop))
60 transposing = *unsmob<Pitch> (prop);
62 for (vsize i = 0; i < note_evs_.size (); i++)
64 Stream_event *n = note_evs_[i];
65 SCM pit = n->get_property ("pitch");
67 if (Pitch *pitp = unsmob<Pitch> (pit))
69 SCM articulations = n->get_property ("articulations");
70 Stream_event *tie_event = 0;
71 Moment len = get_event_length (n, now_mom ());
73 for (SCM s = articulations; scm_is_pair (s); s = scm_cdr (s))
75 Stream_event *ev = unsmob<Stream_event> (scm_car (s));
79 if (ev->in_event_class ("tie-event"))
81 SCM f = ev->get_property ("midi-length");
82 if (ly_is_procedure (f))
83 len = robust_scm2moment (scm_call_2 (f, len.smobbed_copy (),
84 context ()->self_scm ()),
86 velocity += robust_scm2int (ev->get_property ("midi-extra-velocity"), 0);
89 Audio_note *p = new Audio_note (*pitp, len,
90 tie_event, transposing, velocity);
91 Audio_element_info info (p, n);
92 announce_element (info);
96 Grace notes shorten the previous non-grace note. If it was
97 part of a tie, shorten the first note in the tie.
99 if (now_mom ().grace_part_)
101 if (last_start_.grace_part_ == Rational (0))
103 for (vsize i = 0; i < last_notes_.size (); i++)
105 Audio_note *tie_head = last_notes_[i]->tie_head ();
106 Moment start = tie_head->audio_column_->when ();
107 //Shorten the note if it would overlap. It might
108 //not if there's a rest in between.
109 if (start + tie_head->length_mom_ > now_mom ())
110 tie_head->length_mom_ = now_mom () - start;
119 Note_performer::stop_translation_timestep ()
121 if (note_evs_.size ())
123 last_notes_ = notes_;
124 last_start_ = now_mom ();
131 IMPLEMENT_TRANSLATOR_LISTENER (Note_performer, note)
133 Note_performer::listen_note (Stream_event *ev)
135 note_evs_.push_back (ev);
138 IMPLEMENT_TRANSLATOR_LISTENER (Note_performer, breathing)
140 Note_performer::listen_breathing (Stream_event *ev)
142 //Shorten previous note if needed
143 SCM f = ev->get_property ("midi-length");
144 if (ly_is_procedure (f))
145 for (vsize i = 0; i < last_notes_.size (); i++)
147 //Pass midi-length the available time since the last note started,
148 //including any intervening rests. It returns how much is left for the
150 Moment start = last_notes_[i]->audio_column_->when ();
151 Moment available = now_mom () - start;
152 Moment len = robust_scm2moment (scm_call_2 (f, available.smobbed_copy (),
153 context ()->self_scm ()), available);
154 //Take time from the first note of the tie, since it has all the length.
155 Audio_note *tie_head = last_notes_[i]->tie_head ();
156 len += start - tie_head->audio_column_->when ();
157 if (len < tie_head->length_mom_)
158 tie_head->length_mom_ = len;
162 ADD_TRANSLATOR (Note_performer,
176 Note_performer::Note_performer ()