UNPKG

4.86 kBHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>JSDoc: Source: index.js</title>
6
7 <script src="scripts/prettify/prettify.js"> </script>
8 <script src="scripts/prettify/lang-css.js"> </script>
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13 <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14</head>
15
16<body>
17
18<div id="main">
19
20 <h1 class="page-title">Source: index.js</h1>
21
22
23
24
25
26
27 <section>
28 <article>
29 <pre class="prettyprint source linenums"><code>var circleOfFifths = {
30 "major": { "-7": "B", "-6": "F#", "-5": "Db", "-4": "Ab", "-3": "Eb", "-2": "Bb", "-1": "F", "0" : "C", "1" : "G", "2" : "D", "3" : "A", "4" : "E", "5" : "B", "6" : "F#", "7" : "Db" },
31 "minor": { "-7": "G#", "-6": "D#", "-5": "Bb", "-4": "F", "-3": "C", "-2": "G", "-1": "D", "0" : "A", "1" : "E", "2" : "B", "3" : "F#", "4" : "C#", "5" : "G#", "6" : "D#", "7" : "Bb" }
32};
33var accidental = {
34 "flat-flat": "__",
35 "flat": "_",
36 "natural": "=",
37 "sharp" : "^",
38 "sharp-sharp" : "^^",
39 "undefined" : ""
40};
41var pitches = {
42 "1": { "A": "A,,,", "B": "B,,,", "C": "C,,,", "D": "D,,,", "E": "E,,,", "F": "F,,,", "G": "G,,," },
43 "2": { "A": "A,,", "B": "B,,", "C": "C,,", "D": "D,,", "E": "E,,", "F": "F,,", "G": "G,," },
44 "3": { "A": "A,", "B": "B,", "C": "C,", "D": "D,", "E": "E,", "F": "F,", "G": "G," },
45 "4": { "A": "A", "B": "B", "C": "C", "D": "D", "E": "E", "F": "F", "G": "G" },
46 "5": { "A": "a", "B": "b", "C": "c", "D": "d", "E": "e", "F": "f", "G": "g" },
47 "6": { "A": "a'", "B": "b'", "C": "c'", "D": "d'", "E": "e'", "F": "f'", "G": "g'" },
48 "7": { "A": "a''", "B": "b''", "C": "c''", "D": "d''", "E": "e''", "F": "f''", "G": "g''" },
49 "8": { "A": "a'''", "B": "b'''", "C": "c'''", "D": "d'''", "E": "e'''", "F": "f'''", "G": "g'''" }
50};
51
52/**
53 * Returns the abc notation string from given input
54 * @param {object} input - The parsed input from input file
55 * @returns {string}
56 */
57function getAbcString(input) {
58 var outputData = "";
59 outputData += "X:"
60 + input.id
61 + "\n";
62 outputData += "T:"
63 + input.id
64 + "\n";
65 outputData += "M:"
66 + input.attributes.time.beats
67 + "/"
68 + input.attributes.time["beat-type"]
69 + "\n";
70 outputData += "L:"
71 + "1/"
72 + (input.attributes.divisions * input.attributes.time["beat-type"])
73 + "\n";
74 outputData += "K:"
75 + getAbcKey(input.attributes.key.fifths, input.attributes.key.mode)
76 + "\n";
77
78 for (var i = 0; i &lt; input.measures.length; i++) {
79 var measure = input.measures[i];
80 if (measure.attributes.repeat.left) {
81 outputData += "\n"
82 + "|:";
83 } else {
84 //outputData += "|";
85 }
86
87 for (var j = 0; j &lt; measure.notes.length; j++) {
88
89 outputData += " "
90 + getAbcNote(measure.notes[j]);
91 }
92
93 if (measure.attributes.repeat.right) {
94 outputData += ":|"
95 + "\n";
96 } else {
97 outputData += "|";
98 }
99
100 }
101
102 return outputData;
103}
104
105/**
106 * Returns the key for abc notation from given fifths
107 * @param {number} fifths - The position inside the circle of fifths
108 * @param {string|undefined} mode - The mode (major / minor)
109 * @returns {string}
110 */
111function getAbcKey(fifths, mode) {
112 if (typeof mode === 'undefined') mode = 'major';
113 return circleOfFifths[mode][fifths];
114}
115
116/**
117 * Returns a note in abc notation from given note object (JSON)
118 * @param {object} note - The note that should be transformed to abc
119 * @returns {string}
120 */
121function getAbcNote(note) {
122 // check if rest
123 if (note.rest) {
124 // return rest as abc
125 return "z" + note.duration;
126 } else {
127 // return note as abc
128 return accidental[note.pitch.accidental]
129 + pitches[note.pitch.octave][note.pitch.step]
130 + note.duration;
131 }
132}
133
134
135/**
136 * Returns a string in abc notation from given data
137 * @param {object} data - The JSON data that should be transformed to abc
138 * @returns {string}
139 */
140exports.convert2Abc = function(data) {
141 return getAbcString(JSON.parse(data));
142};
143
144// Run jsdoc with: jsdoc index.js -d doc -R README.md
145</code></pre>
146 </article>
147 </section>
148
149
150
151
152</div>
153
154<nav>
155 <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#convert2Abc">convert2Abc</a></li><li><a href="global.html#getAbcKey">getAbcKey</a></li><li><a href="global.html#getAbcNote">getAbcNote</a></li><li><a href="global.html#getAbcString">getAbcString</a></li></ul>
156</nav>
157
158<br class="clear">
159
160<footer>
161 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Apr 07 2016 18:36:08 GMT+0200 (Mitteleuropäische Sommerzeit)
162</footer>
163
164<script> prettyPrint(); </script>
165<script src="scripts/linenumber.js"> </script>
166</body>
167</html>