-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
98 lines (94 loc) · 3.64 KB
/
index.html
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
<!doctype html>
<html lang="en-GB">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>itwriter demo: write Impulse Tracker files with JavaScript.</title>
<style>
body { margin: auto; width: 800px; max-width: 90%; background-color: #263238; color: #D2D8DB; font-family: arial, helvetica; }
a { color: white; }
img { max-width: 90vw; }
</style>
</head>
<body>
<h1><a href="https://github.com/chr15m/itwriter">itwriter</a> demo</h1>
<p><a href="https://github.com/chr15m/itwriter">itwriter</a> is a JavaScript library for writing Impulse Tracker format audio files.</p>
<p>The following code generates an Impulse Tracker module binary file dynamically using JavaScript and attaches it to a download link.
Click <a id="dl" href="#">here to download</a> it.</p>
<p>See the <a href="https://github.com/chr15m/itwriter">itwriter</a> project on GitHub for more info.</p>
<img src="impulse-tracker.png"/>
<h3>Source code:</h3>
<pre></pre>
</body>
<script type="module">
import itwriter from "./index.js";
/* Make some samples. */
const sine = [...(new Array(4410))].map((v, i) => Math.sin(i/10));
const square = [...(new Array(4410))].map((v, i) => Math.sin(i/10) > 0 ? 1 : -1);
const noisefn = () => [...(new Array(441))].map((v, i) => Math.random() * 2 - 1);
/* Create an impulse tracker file from JSON structure. */
const it = itwriter({
"title": "itwriter example", // track title
"bpm": 125, // how fast to play in bpm
"ticks": 4, // how many ticks to fit in each row
"message": "hello!\n\nthis is my song message.", // optional embedded message
"samples": [
{ // samples can be stereo or mono floating point format
"filename": "sine.wav",
"name": "sinewave",
"samplerate": 44100,
"channels": [sine, sine] // stereo
},
{
"filename": "sqr.wav",
"name": "brutal square",
"samplerate": 44100,
"channels": [square] // mono
},
{
"filename": "noise.wav",
"name": "noise clip",
"samplerate": 22050, // differnt sample rate
"channels": [noisefn(), noisefn()]
}
],
"channelnames": { // zero-indexed channel names (optional)
1: "thingo"
},
"order": [0, 1, 0], // what order to play the patterns
"patterns": [
{
"rows": 16, // pattern length in rows
"channels": [
{ // zero-indexed list of events in each vertical channel
0: { "note": "E-6", "instrument": 0, "vol": "v64" },
4: { "note": "C-6", "instrument": 0, "vol": "v64" }
},
{
2: { "note": "E-6", "vol": "v64", "fx": "SD1" },
4: { "note": "G-6", "instrument": 1, "vol": "v32" }
}
]
},
{
"name": "a patn name", // optional pattern name
"rows": 8,
"channels": [
{
0: {"note": "C-5", "instrument": 0, "vol": "v64"},
1: {"vol": "p54"},
3: {"vol": "g03"},
5: {"note": "C-5", "instrument": 2, "vol": "v64"},
}
]
},
]
});
console.log(it);
const a = document.querySelector("a#dl")
a.setAttribute("download", "example.it");
a.setAttribute("href", URL.createObjectURL(new File([it], {"name": "example.it"})));
document.querySelector("pre").textContent = document.querySelector("script").textContent;
</script>
</html>