Debian Codegraph @

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

raw symbols SCIP
1 // soloffs.js - module to set the X offset of some elements at start of music line
2 //
3 // Copyright (C) 2018-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 // Parameters
21 // %%soloffs <type>=<offset> [<type>=<offset>]*
22 // <type> is one of 'part', 'tempo' or 'space'
23 // <offset> is the X offset from the start of staff
24
25 if (typeof abc2svg == "undefined")
26 var abc2svg = {}
27
28 abc2svg.soloffs = {
29
30 set_fmt: function(of, cmd, parm) {
31 if (cmd == "soloffs") {
32 var i, v,
33 C = abc2svg.C,
34 soloffs = this.cfmt().soloffs = {}
35
36 parm = parm.split(/\s+/)
37 while (parm.length) {
38 i = parm.shift().split('=')
39 v = Number(i[1])
40 if (isNaN(v))
41 continue // error
42 switch (i[0]) {
43 // case 'bar':
44 // soloffs[C.BAR] = v
45 // break
46 case 'part':
47 soloffs[C.PART] = v // see deco.js
48 break
49 case 'tempo':
50 soloffs[C.TEMPO] = v + 16 // see deco.js
51 break
52 case 'space':
53 soloffs[C.SPACE] = v
54 break
55 // default:
56 // // error
57 // break
58 }
59 }
60 return
61 }
62 of(cmd, parm)
63 },
64
65 set_sym_glue: function(of, width) {
66 var s,
67 tsfirst = this.get_tsfirst(),
68 soloffs = this.cfmt().soloffs;
69
70 of(width) // compute the x offset of the symbols
71 if (!soloffs)
72 return
73 for (s = tsfirst; s; s = s.ts_next) {
74 if (s.time != tsfirst.time)
75 break
76 if (soloffs[s.type] != undefined)
77 s.x = soloffs[s.type]
78 if (s.part && soloffs[abc2svg.C.PART] != undefined)
79 s.part.x = soloffs[abc2svg.C.PART]
80 }
81 }, // set_sym_glue()
82
83 set_hooks: function(abc) {
84 abc.set_sym_glue = abc2svg.soloffs.set_sym_glue.bind(abc, abc.set_sym_glue);
85 abc.set_format = abc2svg.soloffs.set_fmt.bind(abc, abc.set_format)
86 }
87 } // soloffs
88
89 if (!abc2svg.mhooks)
90 abc2svg.mhooks = {}
91 abc2svg.mhooks.soloffs = abc2svg.soloffs.set_hooks