Spaces:
Sleeping
Sleeping
Commit
·
23dec6b
1
Parent(s):
fb9c37a
Update javascript/app.js
Browse files- 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 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 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) {
|