Debian Codegraph @

lib/ChordPro/res/abc/abc2svg/pedline-1.js

raw symbols SCIP
1 // pedline.js - module to draw pedal lines instead of 'Ped .. *'
2 //
3 // Copyright (C) 2020-2023 Jean-Francois Moine
4 //
5 // This file is part of abc2svg.
6 //
7 // abc2svg is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // abc2svg is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Lesser General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with abc2svg. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // This module is loaded when "%%pedline" appears in a ABC source.
21 //
22 // Parameters
23 // %%pedline 1
24
25 if (typeof abc2svg == "undefined")
26 var abc2svg = {}
27
28 abc2svg.pedline = {
29 draw_all_deco: function(of) {
30 var de, i, x, dp, ds,
31 a_de = this.a_de()
32
33 if (!a_de.length)
34 return // no decoration in this music line
35 if (this.cfmt().pedline) {
36 for (i = 0; i < a_de.length; i++) {
37 de = a_de[i]
38 if (de.dd.name != "ped)")
39 continue
40 ds = de.start
41 dp = de.prev
42 // ( .. ) ( .. )
43 // \ de
44 // \ de.start
45 // \ de.prev
46 // \ de.prev.start
47 // |_____/\____|
48 if (dp && dp.dd.name == "ped)"
49 && dp.s.v == ds.s.v) {
50 de.defl.nost = // /\
51 dp.defl.noen = 2
52 de.x = ds.s.x - 10
53 de.val = de.s.x - ds.s.x - 3
54 dp.val = de.x - dp.x
55
56 if (de.y > dp.y)
57 de.y = dp.y
58 dp.y = de.y
59 } else {
60 de.x = ds.s.x - 8
61 if (!de.defl.noen)
62 de.val = de.s.x - ds.s.x - de.s.wl
63 }
64 }
65 }
66 of()
67 }, // draw_all_deco()
68
69 out_lped: function(of, x, y, val, defl) {
70 if (!this.cfmt().pedline) {
71 of(x, y, val, defl)
72 return
73 }
74 this.xypath(x, y + 8)
75 if (defl.nost) {
76 if (defl.nost == 2) { // \
77 this.out_svg("l2.5 6")
78 val -= 2.5
79 } else {
80 this.out_svg("m0 6")
81 }
82 } else {
83 this.out_svg("v6")
84 }
85 if (defl.noen) {
86 if (defl.noen == 2) { // /
87 val -= 2.5
88 this.out_svg("h" + val.toFixed(1) + 'l2.5 -6')
89 } else {
90 this.out_svg("h" + val.toFixed(1))
91 }
92 } else {
93 this.out_svg("h" + val.toFixed(1) + 'v-6')
94 }
95 this.out_svg('"/>\n')
96 }, // out_lped()
97
98 set_fmt: function(of, cmd, param) {
99 if (cmd == "pedline")
100 this.cfmt().pedline = this.get_bool(param)
101 else
102 of(cmd, param)
103 }, // set_fmt()
104
105 set_hooks: function(abc) {
106 abc.draw_all_deco = abc2svg.pedline.draw_all_deco.bind(abc, abc.draw_all_deco)
107 abc.out_lped = abc2svg.pedline.out_lped.bind(abc, abc.out_lped)
108 abc.set_format = abc2svg.pedline.set_fmt.bind(abc, abc.set_format)
109 } // set_hooks()
110 } // pedline
111
112 if (!abc2svg.mhooks)
113 abc2svg.mhooks = {}
114 abc2svg.mhooks.pedline = abc2svg.pedline.set_hooks