Spaces:
Running
on
Zero
Running
on
Zero
fix color in midi_visualizer
Browse files- javascript/app.js +15 -4
javascript/app.js
CHANGED
@@ -104,6 +104,7 @@ class MidiVisualizer extends HTMLElement{
|
|
104 |
this.midiEvents = [];
|
105 |
this.activeNotes = [];
|
106 |
this.midiTimes = [];
|
|
|
107 |
this.wrapper = null;
|
108 |
this.svg = null;
|
109 |
this.timeLine = null;
|
@@ -145,17 +146,20 @@ class MidiVisualizer extends HTMLElement{
|
|
145 |
this.wrapper = wrapper;
|
146 |
this.svg = svg;
|
147 |
this.timeLine= timeLine;
|
|
|
|
|
|
|
|
|
148 |
this.setPlayTime(0);
|
149 |
}
|
150 |
|
151 |
-
clearMidiEvents(
|
152 |
this.pause()
|
153 |
this.midiEvents = [];
|
154 |
this.activeNotes = [];
|
155 |
this.midiTimes = [];
|
|
|
156 |
this.t1 = 0
|
157 |
-
if (!keepColor)
|
158 |
-
this.colorMap.clear()
|
159 |
this.setPlayTime(0);
|
160 |
this.totalTimeMs = 0;
|
161 |
this.playTimeMs = 0
|
@@ -201,6 +205,9 @@ class MidiVisualizer extends HTMLElement{
|
|
201 |
midiEvent.push(rect)
|
202 |
this.setPlayTime(t);
|
203 |
this.wrapper.scrollTo(this.svgWidth - this.wrapper.offsetWidth, 0)
|
|
|
|
|
|
|
204 |
}
|
205 |
this.midiEvents.push(midiEvent);
|
206 |
this.svg.style.width = `${this.svgWidth}px`;
|
@@ -209,7 +216,11 @@ class MidiVisualizer extends HTMLElement{
|
|
209 |
}
|
210 |
|
211 |
getColor(track, channel){
|
212 |
-
let key =
|
|
|
|
|
|
|
|
|
213 |
let color = this.colorMap.get(key);
|
214 |
if(!!color){
|
215 |
return color;
|
|
|
104 |
this.midiEvents = [];
|
105 |
this.activeNotes = [];
|
106 |
this.midiTimes = [];
|
107 |
+
this.patches = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
108 |
this.wrapper = null;
|
109 |
this.svg = null;
|
110 |
this.timeLine = null;
|
|
|
146 |
this.wrapper = wrapper;
|
147 |
this.svg = svg;
|
148 |
this.timeLine= timeLine;
|
149 |
+
for(let i = 0; i <= 128 ; i++){
|
150 |
+
this.colorMap.set(i, HSVtoRGB(i / 129, 1, 1))
|
151 |
+
}
|
152 |
+
console.log(this.colorMap)
|
153 |
this.setPlayTime(0);
|
154 |
}
|
155 |
|
156 |
+
clearMidiEvents(){
|
157 |
this.pause()
|
158 |
this.midiEvents = [];
|
159 |
this.activeNotes = [];
|
160 |
this.midiTimes = [];
|
161 |
+
this.patches = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
162 |
this.t1 = 0
|
|
|
|
|
163 |
this.setPlayTime(0);
|
164 |
this.totalTimeMs = 0;
|
165 |
this.playTimeMs = 0
|
|
|
205 |
midiEvent.push(rect)
|
206 |
this.setPlayTime(t);
|
207 |
this.wrapper.scrollTo(this.svgWidth - this.wrapper.offsetWidth, 0)
|
208 |
+
}else if(midiEvent[0] === "patch_change"){
|
209 |
+
let channel = midiEvent[3]
|
210 |
+
this.patches[channel] = midiEvent[4]
|
211 |
}
|
212 |
this.midiEvents.push(midiEvent);
|
213 |
this.svg.style.width = `${this.svgWidth}px`;
|
|
|
216 |
}
|
217 |
|
218 |
getColor(track, channel){
|
219 |
+
let key = this.patches[channel];
|
220 |
+
if( channel === 9){
|
221 |
+
// drum
|
222 |
+
key = 128;
|
223 |
+
}
|
224 |
let color = this.colorMap.get(key);
|
225 |
if(!!color){
|
226 |
return color;
|