Debian Codegraph @

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

raw symbols SCIP
1 // temper.js - module to define the temperament
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 // This module is loaded when "%%temperament" appears in a ABC source.
21 //
22 // Parameters
23 // %%temperament <list>
24 // The <list> must contain 12 integer values that are the detune values in cents
25 // of the 12 notes of the equal scale.
26 // Examples:
27 //
28 // % pythagore (~500 B.C)
29 // %%temperament +00 +14 +04 -06 +08 -02 +12 +02 +16 +06 -04 +10
30 //
31 // % just intonation
32 // %%temperament +00 -08 -18 -06 -14 -02 -10 +02 -08 -16 -04 -12
33 //
34 // % meantone (Pietro Aaron 1523)
35 // %%temperament +00 -24 -07 +10 -14 +03 -21 -03 -27 +10 +07 -17
36 //
37 // % Andreas Werckmeister III (1681)
38 // %%temperament +00 -04 +04 +00 -04 +04 +00 +02 -08 +00 +02 -02
39 //
40 // % well temperament (F.A. Vallotti 1754)
41 // %%temperament +00 -06 -04 -02 -08 +02 -08 -02 -04 -06 +00 -10
42
43 if (typeof abc2svg == "undefined")
44 var abc2svg = {}
45
46 abc2svg.temper = {
47
48 // get the temperament
49 set_fmt: function(of, cmd, param) {
50 if (cmd == "temperament") {
51 var i, tb,
52 tb40 = new Float32Array(40),
53 ls = new Float32Array(param.split(/ +/))
54
55 for (i = 0; i < ls.length; i++) {
56 if (isNaN(ls[i]))
57 break
58 ls[i] = i + ls[i] / 100 // delta -> MIDI/octave
59 }
60 switch (i) {
61 case 12:
62 tb = [ 10,11,0,1,2,0, // C
63 0,1,2,3,4,0, // D
64 2,3,4,5,6, // E
65 3,4,5,6,7,0, // F
66 5,6,7,8,9,0, // G
67 7,8,9,10,11,0, // A
68 9,10,11,0,1] // B
69 break
70 default:
71 this.syntax(1, this.errs.bad_val, "%%temperament")
72 return
73 }
74 for (i = 0; i < 40; i++)
75 tb40[i] = ls[tb[i]]
76 this.cfmt().temper = tb40
77 return
78 }
79 of(cmd, param)
80 },
81
82 set_hooks: function(abc) {
83 abc.set_format = abc2svg.temper.set_fmt.bind(abc, abc.set_format)
84 }
85 } // temper
86
87 if (!abc2svg.mhooks)
88 abc2svg.mhooks = {}
89 abc2svg.mhooks.temper = abc2svg.temper.set_hooks