-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathvisualizer.html
142 lines (132 loc) · 4.79 KB
/
visualizer.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
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
<!-- Copyright 2018 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<link rel="stylesheet" href="./style.css">
<title>Visualizer</title>
<style>
input[type="file"] {
width: 0;
height: 0;
opacity: 0;
cursor: pointer;
display: none;
}
textarea {
display: block;
margin-bottom: 4px;
}
</style>
<style id="customStyle">
</style>
</head>
<body>
<h1>Visualizers</h1>
<p>
There are several MIDI or <code>NoteSequence</code> visualizers available.
You can connect it to an <code>mm.Player</code> to update the visualization
in sync with the audio.
</p>
<section>
<p>Load a melody in any of these formats:</p>
<button id="urlBtn">Load URL</button>
<button id="seqBtn">Load NoteSequence</button>
<label class="button">
Load midi file
<input type="file" id="fileInput">
</label>
<br><br>
<button id="playBtn" disabled>wait...</button>
<span class="input">
<b>Tempo:</b>
<input id="tempoInput" value="100" type="range" min="20" max="240" value="120" step="1">
<span id="tempoValue"></span>
</span>
</section>
<h2 id="PianoRollSVGVisualizer">mm.PianoRollSVGVisualizer</h2>
<section>
<div class="visualizer-container">
<svg id="svg"></svg>
</div>
</section>
<h2>mm.StaffSVGVisualizer</h2>
<section>
<div class="visualizer-container">
<div id="staff"></div>
</div>
</section>
<h2>mm.WaterfallSVGVisualizer</h2>
<section>
<label><input type="checkbox" id="waterfallCheckbox">Show only necessary octaves</label>
<br>
<div class="visualizer-container">
<div id="waterfall">
</div>
</div>
</section>
<h2>mm.PianoRollCanvasVisualizer</h2>
<section>
<p>
<b>Note:</b> This has the same visual output as <code>mm.PianoRollSVGVisualizer</code>,
but using a canvas instead of an svg. This visualizers also redraws the entire
sequence on every time step. For longer sequences, canvases become really expensive and
big, and might crash the renderer.
We recommend using the <code>PianoRollSVGVisualizer</code>mm.PianoRollSVGVisualizer</code>,
if performance is a concern.
</p>
<div class="visualizer-container">
<canvas id="canvas"></canvas>
</div>
</section>
<h2>Styling SVG visualizers</h2>
<section>
<p>
SVG visualizers (piano roll and waterfall) support CSS! Use a selector like
<code>svg rect.note</code> to match notes, and style them using the
<a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/Presentation">
available CSS properties</a>. More advanced styling is possible:
<ul>
<li>Currently playing notes can be matched using the <code>.active</code> class.</li>
<li>Notes can also be matched based on properties like instrument or pitch (using
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors">
attribute selectors</a>), thanks to the
data attributes <code>data-instrument</code>, <code>data-program</code>,
<code>data-is-drum</code> and <code>data-pitch</code>.</li>
<li>A <code>--midi-velocity</code> custom property is defined on every note and can be
accessed using the
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/var">
<code>var()</code> CSS function</a>.</li>
</ul>
</p>
<p>
To demonstrate this, we need a slightly juiced up version of our <code>NoteSequence</code>:
<button id="seqVelBtn">Load</button>
</p>
<p>Click below to apply the following style sheet:
<textarea id="styleInput" rows="10" cols="100">
svg rect.note {
fill: rgb(calc(var(--midi-velocity) * 1.2 + 100), 30, calc(255 - var(--midi-velocity)));
}
svg rect.note.active {
stroke: black;
stroke-width: 1.5;
stroke-opacity: 0.5;
}</textarea>
<button id="applyStyleBtn">Apply</button></p>
</section>
<script src="visualizer_bundle.js"></script>
</body>
</html>