diff options
Diffstat (limited to 'stories/music/transpose.rst')
-rw-r--r-- | stories/music/transpose.rst | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/stories/music/transpose.rst b/stories/music/transpose.rst new file mode 100644 index 0000000..4b34b42 --- /dev/null +++ b/stories/music/transpose.rst | |||
@@ -0,0 +1,115 @@ | |||
1 | .. link: | ||
2 | .. description: | ||
3 | .. tags: | ||
4 | .. date: 1998/08/03 19:10:08 | ||
5 | .. title: Live no-barré transposer tool | ||
6 | .. slug: ../music/transpose | ||
7 | |||
8 | .. raw:: html | ||
9 | |||
10 | <script> | ||
11 | function addRow() { | ||
12 | var row = document.getElementById("chord-row-0"); | ||
13 | var addbutton = document.getElementById("addButton"); | ||
14 | var ourdiv = document.getElementById("transposer"); | ||
15 | var cloned = row.cloneNode(true); | ||
16 | var newid = window.rowid || 1; | ||
17 | window.rowid = newid + 1; | ||
18 | cloned.setAttribute( "id", "chord-row-" + newid ); | ||
19 | ourdiv.insertBefore(cloned, addbutton); | ||
20 | } | ||
21 | function isbarre(nv) { | ||
22 | var nobarre = [0,2,5,24,25,26,27,28,29,48,49,50,51,52,53,65,84,86,88,108,109,110,111,112,113,132,134]; | ||
23 | for( var len = nobarre.length, i=0; i<len; ++i ) | ||
24 | if( nobarre[i] == nv ) | ||
25 | return 0; | ||
26 | return 1; | ||
27 | } | ||
28 | function note_to_name(nv) { | ||
29 | return ["C","C#","D","D#","E","F","F#","G","G#","A","B","H"][~~(nv/12)]+["","m","7","m7","maj6","maj7"][nv%12]; | ||
30 | } | ||
31 | function updateTrans() { | ||
32 | var resulttext = document.getElementById("result"); | ||
33 | var notelist = document.getElementsByClassName("chord-row"); | ||
34 | var impossible_offsets = 0; | ||
35 | var notes = []; | ||
36 | |||
37 | for (var len = notelist.length, i=0; i<len; ++i) { | ||
38 | var note = notelist[i].getElementsByClassName("note"); | ||
39 | var modifier = notelist[i].getElementsByClassName("modifier"); | ||
40 | var nv = 1 * note[0].value; | ||
41 | var mv = 1 * modifier[0].value; | ||
42 | if( nv >= 0 ) { | ||
43 | notes.push( ( nv * 12 ) + mv ); | ||
44 | // test all transpositions for suitable chords | ||
45 | for (var off = 0; off < 12; ++off ) { | ||
46 | if ( isbarre( mv + 12 * ( ( nv + off ) % 12 ) ) ) | ||
47 | impossible_offsets |= 1<<off; | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | if( impossible_offsets == 0xfff ) { | ||
52 | resulttext.innerHTML = 'Keine Transposition / Not possible'; | ||
53 | } else { | ||
54 | var outtext = ''; | ||
55 | for( var off = 0; off < 12; ++off ) { | ||
56 | if( !( impossible_offsets & (1<<off) ) ) { | ||
57 | outtext += '<table><tr><th>original</th><th>transpose</th></tr>'; | ||
58 | for( var len = notes.length, i=0; i<len; ++i ) { | ||
59 | var transposed = 12 * ( ( ~~( notes[i] / 12 ) + off ) % 12 ) + ( notes[i] % 12 ); | ||
60 | if( ( ( notes %12 ) != 2 ) && transposed == 132 ) | ||
61 | outtext += "<tr><td>" + note_to_name(notes[i]) + "</td><td>H7 (unclean)</td></td>"; | ||
62 | else | ||
63 | outtext += "<tr><td>" + note_to_name(notes[i]) + "</td><td>" + note_to_name(transposed) + "</td></tr>"; | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | resulttext.innerHTML = outtext + "</table>"; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | </script> | ||
72 | <style> | ||
73 | table { | ||
74 | border: 1px black solid; | ||
75 | border-collapse: none; | ||
76 | margin: 2em 2em 0em 0em; | ||
77 | float: left; | ||
78 | } | ||
79 | td, th { | ||
80 | padding: 8px; | ||
81 | border: 1px silver dotted; | ||
82 | } | ||
83 | .chord-row, .addButton { | ||
84 | margin-bottom: 1em; | ||
85 | } | ||
86 | </style> | ||
87 | <div id="transposer"> | ||
88 | <div class="chord-row" id="chord-row-0"> | ||
89 | <select class="note" onchange="updateTrans()"> | ||
90 | <option value="-1">Note</option> | ||
91 | <option value="0">C</option> | ||
92 | <option value="1">C# / Db</option> | ||
93 | <option value="2">D</option> | ||
94 | <option value="3">D# / Eb</option> | ||
95 | <option value="4">E</option> | ||
96 | <option value="5">F</option> | ||
97 | <option value="6">F# / Gb</option> | ||
98 | <option value="7">G</option> | ||
99 | <option value="8">G# / Ab</option> | ||
100 | <option value="9">A</option> | ||
101 | <option value="10">A# / B</option> | ||
102 | <option value="10">H</option> | ||
103 | </select> | ||
104 | <select class="modifier" onchange="updateTrans()"> | ||
105 | <option value="0">Dur / major</option> | ||
106 | <option value="1">Moll / minor</option> | ||
107 | <option value="2">7</option> | ||
108 | <option value="3">Moll7 / min7</option> | ||
109 | <option value="4">Maj6</option> | ||
110 | <option value="5">Maj7</option> | ||
111 | </select> | ||
112 | </div> | ||
113 | <button id="addButton" type="button" onclick="addRow()">+</button> | ||
114 | <div id="result"></div> | ||
115 | </div> | ||