add instrument palette

This commit is contained in:
Zack Buhman 2025-07-04 18:10:23 -05:00
parent 28b5d5f52e
commit 5596b3e646
5 changed files with 71 additions and 4 deletions

View File

@ -0,0 +1,44 @@
#include <stdint.h>
#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},
};
}

View File

@ -0,0 +1,11 @@
#include <stdint.h>
#include "math/vec3.hpp"
using vec3i = vec<3, int>;
namespace instrument_palette {
extern uint32_t color[];
extern vec3i color3[];
}

View File

@ -5,6 +5,7 @@
#include "channel_status.hpp" #include "channel_status.hpp"
#include "texture.hpp" #include "texture.hpp"
#include "instrument_palette.hpp"
static inline int round_up_div(int n, int m) 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; int keyon = 128 * (state.channel[ch].keyon - 224) / 16;
if (keyon < 0) keyon = 0; 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, transfer_rectangle(multi.op,
xi, y, 1.0 / 10000.0, xi, y, 1.0 / 10000.0,
width_per_col, height_per_row, width_per_col, height_per_row,

View File

@ -7,6 +7,8 @@
#include "widget/button_label.hpp" #include "widget/button_label.hpp"
#include "widget/left_aligned.hpp" #include "widget/left_aligned.hpp"
#include "instrument_palette.hpp"
namespace scene::tracker::tracklist { namespace scene::tracker::tracklist {
static bool samples_tab = false; static bool samples_tab = false;
@ -24,7 +26,7 @@ namespace scene::tracker::tracklist {
const float width = glyph::hori_advance * 20 + 3 * 2; const float width = glyph::hori_advance * 20 + 3 * 2;
const int line_rows_half = 5; const int line_rows_half = 5;
const int line_rows = line_rows_half * 2 + 1; 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]))) #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, transfer_string(writer, (const char *)interpreter::state.xm.instrument_header[i]->instrument_name,
x, y, 1.0 / 10.0, x, y, 1.0 / 10.0,
0xffffff); instrument_palette::color[i & 15]);
y += glyph::vert_advance;
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;
} }
} }

View File

@ -57,6 +57,7 @@ XM_PLAYER_OBJ = \
src/graphics_primitive.o \ src/graphics_primitive.o \
src/input.o \ src/input.o \
src/interpreter.o \ src/interpreter.o \
src/instrument_palette.o \
src/main.o \ src/main.o \
src/malloc.o \ src/malloc.o \
src/playlist.o \ src/playlist.o \