OLD | NEW |
(Empty) | |
| 1 /* |
| 2 This file is part of LilyPond, the GNU music typesetter. |
| 3 |
| 4 Copyright (C) 2020--2020 David Stephen Grant <david@davidgrant.no> |
| 5 |
| 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. |
| 10 |
| 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. |
| 15 |
| 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/>. |
| 18 */ |
| 19 |
| 20 #include "lyric-transition.hh" |
| 21 |
| 22 #include "lookup.hh" |
| 23 #include "output-def.hh" |
| 24 #include "paper-column.hh" |
| 25 #include "moment.hh" |
| 26 #include "rod.hh" |
| 27 #include "spanner.hh" |
| 28 #include "system.hh" |
| 29 |
| 30 MAKE_SCHEME_CALLBACK (Lyric_transition, set_spacing_rods, 1); |
| 31 SCM |
| 32 Lyric_transition::set_spacing_rods (SCM smob) |
| 33 { |
| 34 Grob *me = unsmob<Grob> (smob); |
| 35 SCM num_length = me->get_property ("minimum-length"); |
| 36 SCM broken_length = me->get_property ("minimum-length-after-break"); |
| 37 |
| 38 if (scm_is_number (num_length) |
| 39 || scm_is_number (broken_length)) |
| 40 { |
| 41 Spanner *sp = dynamic_cast<Spanner *> (me); |
| 42 System *root = get_root_system (me); |
| 43 Drul_array<Item *> bounds (sp->get_bound (LEFT), |
| 44 sp->get_bound (RIGHT)); |
| 45 if (!bounds[LEFT] || !bounds[RIGHT]) |
| 46 return SCM_UNSPECIFIED; |
| 47 |
| 48 Drul_array<Real> gaps (0, 0); |
| 49 for (LEFT_and_RIGHT (d)) |
| 50 { |
| 51 SCM bounds = sp->get_property ("bound-details"); |
| 52 SCM details = ly_assoc_get ((d == LEFT) |
| 53 ? ly_symbol2scm ("left") |
| 54 : ly_symbol2scm ("right"), bounds, SCM_BO
OL_F); |
| 55 gaps[d] = robust_scm2double (ly_assoc_get (ly_symbol2scm ("padding"), |
| 56 details, SCM_BOOL_F), 0.0); |
| 57 } |
| 58 Real total_padding = gaps[LEFT] + gaps[RIGHT]; |
| 59 |
| 60 std::vector<Item *> cols (root->broken_col_range (bounds[LEFT]->get_column
(), |
| 61 bounds[RIGHT]->get_colum
n ())); |
| 62 |
| 63 if (cols.size ()) |
| 64 { |
| 65 Rod r; |
| 66 |
| 67 r.item_drul_[LEFT] = sp->get_bound (LEFT); |
| 68 r.item_drul_[RIGHT] = cols[0]->find_prebroken_piece (LEFT); |
| 69 r.distance_ = robust_scm2double (num_length, 0); |
| 70 |
| 71 /* |
| 72 We always want to draw the transition line. Syllables |
| 73 and padding must be considered, and extra space added |
| 74 accordingly. (If the line is omitted, the meaning of |
| 75 the music notation changes.) |
| 76 */ |
| 77 r.distance_ += bounds_protrusion (&r); |
| 78 r.distance_ += total_padding; |
| 79 r.add_to_cols (); |
| 80 |
| 81 /* |
| 82 r.distance_ may have been modified by add_to_cols () |
| 83 above. For treatment of minimum-distance-after-break |
| 84 consistent with minimum-distance (which will use the |
| 85 changed value), we cannot directly reset r.distance_ to |
| 86 broken_length. |
| 87 */ |
| 88 r.distance_ -= bounds_protrusion (&r); |
| 89 r.item_drul_[LEFT] = cols.back ()->find_prebroken_piece (RIGHT); |
| 90 r.item_drul_[RIGHT] = sp->get_bound (RIGHT); |
| 91 if (scm_is_number (broken_length)) |
| 92 { |
| 93 r.distance_ += robust_scm2double (broken_length, 0) - |
| 94 robust_scm2double (num_length, 0); |
| 95 } |
| 96 |
| 97 r.distance_ += bounds_protrusion (&r); |
| 98 r.add_to_cols (); |
| 99 } |
| 100 |
| 101 Rod r; |
| 102 /* |
| 103 As r is a fresh rod, we can set distance_ with no complication. |
| 104 */ |
| 105 r.distance_ = robust_scm2double (num_length, 0); |
| 106 |
| 107 r.item_drul_[LEFT] = sp->get_bound (LEFT); |
| 108 r.item_drul_[RIGHT] = sp->get_bound (RIGHT); |
| 109 r.distance_ += bounds_protrusion (&r); |
| 110 r.distance_ += total_padding; |
| 111 r.add_to_cols (); |
| 112 |
| 113 /* |
| 114 We do not know yet if the spanner is going to have a bound that is |
| 115 broken. To account for this uncertainty, we add the rod twice: |
| 116 once for the central column (see above) and once for the left column |
| 117 (see below). As end_rods_ are never used when rods_ are used and vice |
| 118 versa, this rod will only be accessed once for each spacing |
| 119 configuraiton before line breaking. Then, as a grob never exists in |
| 120 both unbroken and broken forms after line breaking, only one of these |
| 121 two rods will be in the column vector used for spacing in |
| 122 simple-spacer.cc get_line_confugration. |
| 123 */ |
| 124 if (Item *left_pbp = sp->get_bound (RIGHT)->find_prebroken_piece (LEFT)) |
| 125 { |
| 126 r.item_drul_[RIGHT] = left_pbp; |
| 127 r.add_to_cols (); |
| 128 } |
| 129 } |
| 130 |
| 131 return SCM_UNSPECIFIED; |
| 132 } |
| 133 |
| 134 Real |
| 135 Lyric_transition::bounds_protrusion (const Rod *r) |
| 136 { |
| 137 /* Calculate protrusion of bounds into rod */ |
| 138 Real w = 0; |
| 139 for (LEFT_and_RIGHT (d)) |
| 140 { |
| 141 if (r->item_drul_[d]) |
| 142 w += -d * r->item_drul_[d]->extent (r->item_drul_[d], X_AXIS)[-d]; |
| 143 } |
| 144 return w; |
| 145 } |
| 146 |
| 147 ADD_INTERFACE (Lyric_transition, |
| 148 "A transition line is an arrow from one syllable" |
| 149 " to another, to indicate a gradual change of vowel.", |
| 150 |
| 151 /* properties */ |
| 152 "minimum-length " |
| 153 "bound-details " |
| 154 ); |
OLD | NEW |