asigalov61 commited on
Commit
23dec6b
1 Parent(s): fb9c37a

Update javascript/app.js

Browse files
Files changed (1) hide show
  1. javascript/app.js +20 -9
javascript/app.js CHANGED
@@ -168,16 +168,27 @@ class MidiVisualizer extends HTMLElement{
168
 
169
  }
170
 
171
- getColor(track, channel){
172
- let key = `${track},${channel}`;
173
- let color = this.colorMap.get(key);
174
- if(!!color){
175
- return color;
176
- }
177
- color = HSVtoRGB(Math.random(),Math.random()*0.5 + 0.5,1);
178
- this.colorMap.set(key, color);
179
- return color;
180
  }
 
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  drawNote(x, y, w, h, fill) {
183
  if (!this.svg) {
 
168
 
169
  }
170
 
171
+ getColor(track, channel) {
172
+ // Create a unique hash for each track and channel combination
173
+ let hash = track * 1000 + channel;
174
+
175
+ // Convert the hash to a color
176
+ let color = hashToColor(hash);
177
+
178
+ return color;
 
179
  }
180
+
181
+ // Function to convert a hash to an RGB color
182
+ function hashToColor(hash) {
183
+ // Use bitwise operations to extract RGB components
184
+ let r = (hash & 0xFF0000) >> 16;
185
+ let g = (hash & 0x00FF00) >> 8;
186
+ let b = hash & 0x0000FF;
187
+
188
+ // Convert RGB values to a CSS color string
189
+ return `rgb(${r}, ${g}, ${b})`;
190
+ }
191
+
192
 
193
  drawNote(x, y, w, h, fill) {
194
  if (!this.svg) {