File size: 4,050 Bytes
af6912c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<meta http-equiv="x-ua-compatible" content="ie=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="icon" href="favicon.ico" type="image/x-icon" />
	<link rel="stylesheet" type="text/css" href="../abcjs-audio.css">
	<link rel="stylesheet" href="examples-styles.css" />

	<title>Output Transposition</title>
	<script src="../dist/abcjs-basic.js" type="text/javascript"></script>
	<script type="text/javascript">
		var editor;
		var renderParams = { responsive: "resize", selectTypes: false };
		var outputEl;
		var abcEl;
		var currentAbc = ""
		window.onload = function () {
			abcEl = document.querySelector("#abc");
			outputEl = document.querySelector("#transposed");
			visualTransposeEl = document.querySelector(".transpose");

			editor = new ABCJS.Editor("abc", {
				canvas_id: "paper",
				warnings_id: "warnings",
				abcjsParams: renderParams,
			});

			visualTransposeEl.addEventListener("change", paramChanged);
			paramChanged(false);
		};

		function paramChanged(userAction) {
			var visualObj = editor.tunes
			var abc = abcEl.value
			var steps = visualTransposeEl.value
			var output = ABCJS.strTranspose(abc, visualObj, steps)
			outputEl.innerText = output
			var newVisualObj = ABCJS.renderAbc("paper2", output, renderParams)
			if (userAction)
				createSynth(newVisualObj[0])
		}

		var synthControl

		function createSynth(visualObj) {
			if (!synthControl) {
				synthControl = new ABCJS.synth.SynthController();
				synthControl.load("#audio", null, { displayRestart: true, displayPlay: true, displayProgress: true });
			}
			var midiBuffer = new ABCJS.synth.CreateSynth();
			midiBuffer.init({
				visualObj: visualObj,
			}).then(function (response) {
				synthControl.setTune(visualObj, true).then(function (response) {
				}).catch(function (error) {
					console.warn("Audio problem:", error);
				});
			}).catch(function (error) {
				console.warn("Audio problem:", error);
			});

		}
	</script>
	<style>
		@media only screen and (min-width: 700px) {
			.container {
				max-width: 1200px;
			}
		}

		.input,
		.output {
			display: flex;
			column-gap: 10px;
		}

		.input>div,
		.output>div {
			width: 50%;
		}

		#abc,
		#transposed {
			font-family: monaco, monospace;
			font-size: 1em;
			height: 300px;
		}

		#transposed {
			border: 1px solid #888;
			padding: 10px;
			margin-top: 0;
			overflow: auto;
		}
		label {
			margin-top: 10px;
			display: block;
		}
	</style>
</head>

<body>
	<header>
		<img src="https://paulrosen.github.io/abcjs/img/abcjs_comp_extended_08.svg" alt="abcjs logo">
		<h1>Output Transposition</h1>
	</header>
	<div class="container">
		<main>
			<p>This demonstrates transposing an ABC string and retrieving that transposed string. Type any valid ABC string in the "input string" area and choose your transposition in half-steps below the input string. The resultant ABC string, transposed audio, and transposed notation are shown on the right side of the page.</p>
			<section class="input">
				<div>
					<h2>Input String</h2>
					<textarea aria-label="ABC string" id="abc" spellcheck="false">
X: 1
T: Cooley's
M: 4/4
L: 1/8
R: reel
K: Em
V: Melody
|:D2|EB{c}BA B2 EB|~B2 AB dBAG|FDAD BDAD|FDAD dAFD|
EBBA B2 EB|B2 AB defg|afe^c dBAF|DEFD E2:|
|:gf|eB B2 efge|eB B2 gedB|A2 FA DAFA|A2 FA defg|
eB B2 eBgB|eB B2 defg|afe^c dBAF|DEFD E2:|
</textarea>
					<label>Transpose:
						<input
							class="transpose"
							type="number"
							min="-24"
							max="24"
							step="1"
							value="0">
					</label>
				</div>
				<div>
					<h2>Output String</h2>
					<pre id="transposed"></pre>
					<div id="audio"></div>
				</div>
			</section>

			<div id="warnings"></div>
			<section class="output">
				<div>
					<h2>Original Output</h2>
					<div id="paper" class="visible-background"></div>
				</div>
				<div>
					<h2>Transposed Output</h2>
					<div id="paper2" class="visible-background"></div>
				</div>
			</section>
		</main>
	</div>
</body>

</html>