From 5596b3e646edc81c656a1ee5a2c78e6894d8dd47 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Fri, 4 Jul 2025 18:10:23 -0500 Subject: [PATCH] add instrument palette --- src/instrument_palette.cpp | 44 ++++++++++++++++++++++++++++ src/instrument_palette.hpp | 11 +++++++ src/scene/tracker/channel_status.cpp | 7 ++++- src/scene/tracker/tracklist.cpp | 12 ++++++-- xm_player.mk | 1 + 5 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 src/instrument_palette.cpp create mode 100644 src/instrument_palette.hpp diff --git a/src/instrument_palette.cpp b/src/instrument_palette.cpp new file mode 100644 index 0000000..c259da7 --- /dev/null +++ b/src/instrument_palette.cpp @@ -0,0 +1,44 @@ +#include + +#include "instrument_palette.hpp" + +namespace instrument_palette { + + uint32_t color[] = { + 0xe70000, + 0x38b144, + 0xef5983, + 0x61efcd, + 0xdf3700, + 0x019f5c, + 0xef9a5a, + 0x59c7ef, + 0xe55d00, + 0x0d789f, + 0xeee462, + 0x6197ef, + 0xe79c00, + 0x1a4697, + 0x65ef72, + 0xa57bef, + }; + + vec3i color3[] = { + {0xe7, 0x00, 0x00}, + {0x38, 0xb1, 0x44}, + {0xef, 0x59, 0x83}, + {0x61, 0xef, 0xcd}, + {0xdf, 0x37, 0x00}, + {0x01, 0x9f, 0x5c}, + {0xef, 0x9a, 0x5a}, + {0x59, 0xc7, 0xef}, + {0xe5, 0x5d, 0x00}, + {0x0d, 0x78, 0x9f}, + {0xee, 0xe4, 0x62}, + {0x61, 0x97, 0xef}, + {0xe7, 0x9c, 0x00}, + {0x1a, 0x46, 0x97}, + {0x65, 0xef, 0x72}, + {0xa5, 0x7b, 0xef}, + }; +} diff --git a/src/instrument_palette.hpp b/src/instrument_palette.hpp new file mode 100644 index 0000000..9cfcaa7 --- /dev/null +++ b/src/instrument_palette.hpp @@ -0,0 +1,11 @@ +#include + +#include "math/vec3.hpp" + +using vec3i = vec<3, int>; + +namespace instrument_palette { + + extern uint32_t color[]; + extern vec3i color3[]; +} diff --git a/src/scene/tracker/channel_status.cpp b/src/scene/tracker/channel_status.cpp index 3023abd..114889c 100644 --- a/src/scene/tracker/channel_status.cpp +++ b/src/scene/tracker/channel_status.cpp @@ -5,6 +5,7 @@ #include "channel_status.hpp" #include "texture.hpp" +#include "instrument_palette.hpp" static inline int round_up_div(int n, int m) { @@ -64,7 +65,11 @@ void draw(ta_multiwriter& multi, int x, int y) int keyon = 128 * (state.channel[ch].keyon - 224) / 16; if (keyon < 0) keyon = 0; - uint32_t base_color = (keyon << 16) | (keyon << 8) | (keyon << 0); + if (keyon > 255) keyon = 255; + + int instrument_ix = state.channel[ch].instrument & 15; + vec3i i_color = instrument_palette::color3[instrument_ix] * keyon / 255; + uint32_t base_color = (i_color.x << 16) | (i_color.y << 8) | (i_color.z << 0); transfer_rectangle(multi.op, xi, y, 1.0 / 10000.0, width_per_col, height_per_row, diff --git a/src/scene/tracker/tracklist.cpp b/src/scene/tracker/tracklist.cpp index f80e3c1..dcbe9ff 100644 --- a/src/scene/tracker/tracklist.cpp +++ b/src/scene/tracker/tracklist.cpp @@ -7,6 +7,8 @@ #include "widget/button_label.hpp" #include "widget/left_aligned.hpp" +#include "instrument_palette.hpp" + namespace scene::tracker::tracklist { static bool samples_tab = false; @@ -24,7 +26,7 @@ namespace scene::tracker::tracklist { const float width = glyph::hori_advance * 20 + 3 * 2; const int line_rows_half = 5; const int line_rows = line_rows_half * 2 + 1; - const float height = glyph::vert_advance * line_rows + 3 * 2; + const float height = (glyph::vert_advance + 1) * line_rows + 3 * 2; #define __length(c) ((sizeof (c)) / (sizeof (c[0]))) @@ -72,8 +74,12 @@ namespace scene::tracker::tracklist { transfer_string(writer, (const char *)interpreter::state.xm.instrument_header[i]->instrument_name, x, y, 1.0 / 10.0, - 0xffffff); - y += glyph::vert_advance; + instrument_palette::color[i & 15]); + + transfer_string(writer, (const char *)interpreter::state.xm.instrument_header[i]->instrument_name, + x+1, y+1, 1.0 / 11.0, + 0x444444); + y += glyph::vert_advance + 1; } } diff --git a/xm_player.mk b/xm_player.mk index f38976b..79093f6 100644 --- a/xm_player.mk +++ b/xm_player.mk @@ -57,6 +57,7 @@ XM_PLAYER_OBJ = \ src/graphics_primitive.o \ src/input.o \ src/interpreter.o \ + src/instrument_palette.o \ src/main.o \ src/malloc.o \ src/playlist.o \