local scales = {{
    name = "Chromatic",
    intervals = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
    chords = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
              {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}}
}, {
    name = "Major",
    alt_names = {"Ionian"},
    intervals = {0, 2, 4, 5, 7, 9, 11, 12},
    chords = {{1, 2, 3, 4, 5, 6, 7, 14}, {14, 15, 17, 18, 19, 20, 21, 22, 23}, {14, 15, 17, 19}, {1, 2, 3, 4, 5},
              {1, 2, 4, 8, 9, 10, 11, 14, 15}, {14, 15, 17, 19, 21, 22}, {24, 26}, {1, 2, 3, 4, 5, 6, 7, 14}}
}, {
    name = "Natural Minor",
    alt_names = {"Minor", "Aeolian"},
    intervals = {0, 2, 3, 5, 7, 8, 10, 12},
    chords = {{14, 15, 17, 19, 21, 22}, {24, 26}, {1, 2, 3, 4, 5, 6, 7, 14}, {14, 15, 17, 18, 19, 20, 21, 22, 23},
              {14, 15, 17, 19}, {1, 2, 3, 4, 5}, {1, 2, 4, 8, 9, 10, 11, 14, 15}, {14, 15, 17, 19, 21, 22}}
}, {
    name = "Harmonic Minor",
    intervals = {0, 2, 3, 5, 7, 8, 11, 12},
    chords = {{14, 16, 17}, {24, 25, 26}, {12, 27}, {17, 18, 19, 20, 21, 24, 25, 26}, {1, 8, 12, 13, 14, 15},
              {1, 2, 3, 16, 17, 18, 24, 25}, {12, 24, 25}, {14, 16, 17}}
}, {
    name = "Melodic Minor",
    intervals = {0, 2, 3, 5, 7, 9, 11, 12},
    chords = {{14, 16, 17, 18, 20}, {14, 15, 17, 18, 19}, {12, 27}, {1, 2, 4, 8, 9}, {1, 8, 9, 10, 12, 13, 14, 15},
              {24, 26}, {12, 13, 24, 26}, {14, 16, 17, 18, 20}}
}, {
    name = "Dorian",
    intervals = {0, 2, 3, 5, 7, 9, 10, 12},
    chords = {{14, 15, 17, 18, 19, 20, 21, 22, 23}, {14, 15, 17, 19}, {1, 2, 3, 4, 5}, {1, 2, 4, 8, 9, 10, 11, 14, 15},
              {14, 15, 17, 19, 21, 22}, {24, 26}, {1, 2, 3, 4, 5, 6, 7, 14}, {14, 15, 17, 18, 19, 20, 21, 22, 23}}
}, {
    name = "Phrygian",
    intervals = {0, 1, 3, 5, 7, 8, 10, 12},
    chords = {{14, 15, 17, 19}, {1, 2, 3, 4, 5}, {1, 2, 4, 8, 9, 10, 11, 14, 15}, {14, 15, 17, 19, 21, 22}, {24, 26},
              {1, 2, 3, 4, 5, 6, 7, 14}, {14, 15, 17, 18, 19, 20, 21, 22, 23}, {14, 15, 17, 19}}
}, {
    name = "Lydian",
    intervals = {0, 2, 4, 6, 7, 9, 11, 12},
    chords = {{1, 2, 3, 4, 5}, {1, 2, 4, 8, 9, 10, 11, 14, 15}, {14, 15, 17, 19, 21, 22}, {24, 26},
              {1, 2, 3, 4, 5, 6, 7, 14}, {14, 15, 17, 18, 19, 20, 21, 22, 23}, {14, 15, 17, 19}, {1, 2, 3, 4, 5}}
}, {
    name = "Mixolydian",
    intervals = {0, 2, 4, 5, 7, 9, 10, 12},
    chords = {{1, 2, 4, 8, 9, 10, 11, 14, 15}, {14, 15, 17, 19, 21, 22}, {24, 26}, {1, 2, 3, 4, 5, 6, 7, 14},
              {14, 15, 17, 18, 19, 20, 21, 22, 23}, {14, 15, 17, 19}, {1, 2, 3, 4, 5}, {1, 2, 4, 8, 9, 10, 11, 14, 15}}
}, {
    name = "Locrian",
    intervals = {0, 1, 3, 5, 6, 8, 10, 12},
    chords = {{24, 26}, {1, 2, 3, 4, 5, 6, 7, 14}, {14, 15, 17, 18, 19, 20, 21, 22, 23}, {14, 15, 17, 19},
              {1, 2, 3, 4, 5}, {1, 2, 4, 8, 9, 10, 11, 14, 15}, {14, 15, 17, 19, 21, 22}, {24, 26}}
}, {
    name = "Whole Tone",
    intervals = {0, 2, 4, 6, 8, 10, 12},
    chords = {{12, 13}, {12, 13}, {12, 13}, {12, 13}, {12, 13}, {12, 13}, {12, 13}}
}, {
    name = "Major Pentatonic",
    alt_names = {"Gagaku Ryo Sen Pou"},
    intervals = {0, 2, 4, 7, 9, 12},
    chords = {{1, 2, 4}, {14, 15}, {}, {14}, {14, 15, 17, 19}, {1, 2, 4}}
}, {
    name = "Minor Pentatonic",
    alt_names = {"Zokugaku Yo Sen Pou"},
    intervals = {0, 3, 5, 7, 10, 12},
    chords = {{14, 15, 17, 19}, {1, 2, 4}, {14, 15}, {}, {14}, {14, 15, 17, 19}}
}, {
    name = "Major Bebop",
    intervals = {0, 2, 4, 5, 7, 8, 9, 11, 12},
    chords = {{1, 2, 3, 4, 5, 6, 7, 12, 14, 27}, {14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26},
              {1, 8, 12, 13, 14, 15, 17, 19}, {1, 2, 3, 4, 5, 16, 17, 18, 20, 24, 25}, {1, 2, 4, 8, 9, 10, 11, 14, 15},
              {12, 24, 25, 27}, {14, 15, 16, 17, 19, 21, 22}, {24, 25, 26}, {1, 2, 3, 4, 5, 6, 7, 12, 14, 27}}
}, {
    name = "Altered Scale",
    intervals = {0, 1, 3, 4, 6, 8, 10, 12},
    chords = {{12, 13, 24, 26}, {14, 16, 17, 18, 20}, {14, 15, 17, 18, 19}, {12, 27}, {1, 2, 4, 8, 9},
              {1, 8, 9, 10, 12, 13, 14, 15}, {24, 26}, {12, 13, 24, 26}}
}, {
    name = "Dorian Bebop",
    intervals = {0, 2, 3, 4, 5, 7, 9, 10, 12},
    chords = {{1, 2, 4, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20, 21, 22, 23}, {14, 15, 17, 19, 21, 22}, {1, 2, 3, 4, 5},
              {24, 26}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15}, {14, 15, 17, 18, 19, 20, 21, 22, 23},
              {14, 15, 17, 19, 24, 26}, {1, 2, 3, 4, 5, 6, 7, 14},
              {1, 2, 4, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20, 21, 22, 23}}
}, {
    name = "Mixolydian Bebop",
    intervals = {0, 2, 4, 5, 7, 9, 10, 11, 12},
    chords = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15}, {14, 15, 17, 18, 19, 20, 21, 22, 23},
              {14, 15, 17, 19, 24, 26}, {1, 2, 3, 4, 5, 6, 7, 14},
              {1, 2, 4, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20, 21, 22, 23}, {14, 15, 17, 19, 21, 22}, {1, 2, 3, 4, 5},
              {24, 26}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15}}
}, {
    name = "Blues Scale",
    alt_names = {"Blues"},
    intervals = {0, 3, 5, 6, 7, 10, 12},
    chords = {{14, 15, 17, 19, 24, 26}, {1, 2, 4, 17, 18, 20}, {14, 15}, {}, {}, {14}, {14, 15, 17, 19, 24, 26}}
}, {
    name = "Diminished Whole Half",
    intervals = {0, 2, 3, 5, 6, 8, 9, 11, 12},
    chords = {{24, 25}, {1, 2, 8, 17, 18, 19, 24, 25, 26}, {24, 25}, {1, 2, 8, 17, 18, 19, 24, 25, 26}, {24, 25},
              {1, 2, 8, 17, 18, 19, 24, 25, 26}, {24, 25}, {1, 2, 8, 17, 18, 19, 24, 25, 26}, {24, 25}}
}, {
    name = "Diminished Half Whole",
    intervals = {0, 1, 3, 4, 6, 7, 9, 10, 12},
    chords = {{1, 2, 8, 17, 18, 19, 24, 25, 26}, {24, 25}, {1, 2, 8, 17, 18, 19, 24, 25, 26}, {24, 25},
              {1, 2, 8, 17, 18, 19, 24, 25, 26}, {24, 25}, {1, 2, 8, 17, 18, 19, 24, 25, 26}, {24, 25},
              {1, 2, 8, 17, 18, 19, 24, 25, 26}}
}, {
    name = "Neapolitan Major",
    intervals = {0, 1, 3, 5, 7, 9, 11, 12},
    chords = {{14, 16, 17, 18}, {12, 13, 27}, {12, 13}, {1, 8, 9, 12, 13}, {12, 13}, {12, 13, 24, 26}, {12, 13},
              {14, 16, 17, 18}}
}, {
    name = "Hungarian Major",
    intervals = {0, 3, 4, 6, 7, 9, 10, 12},
    chords = {{1, 2, 8, 17, 18, 19, 24, 25, 26}, {1, 2, 17, 18, 24, 25}, {24}, {24, 25, 26}, {},
              {17, 18, 19, 24, 25, 26}, {}, {1, 2, 8, 17, 18, 19, 24, 25, 26}}
}, {
    name = "Harmonic Major",
    intervals = {0, 2, 4, 5, 7, 8, 11, 12},
    chords = {{1, 3, 5, 6, 12, 14, 27}, {24, 25, 26}, {1, 8, 12, 13, 17, 19}, {16, 17, 18, 20, 24, 25},
              {1, 2, 8, 14, 15}, {12, 24, 25, 27}, {24, 25}, {1, 3, 5, 6, 12, 14, 27}}
}, {
    name = "Hungarian Minor",
    intervals = {0, 2, 3, 6, 7, 8, 11, 12},
    chords = {{16, 17, 24}, {}, {12, 27}, {}, {1, 3, 12, 14, 27}, {1, 3, 8, 16, 17, 19, 24, 26}, {1, 2, 12, 17, 18},
              {16, 17, 24}}
}, {
    name = "Lydian Minor",
    intervals = {0, 2, 4, 6, 7, 8, 10, 12},
    chords = {{1, 8, 9, 12, 13}, {12, 13}, {12, 13, 24, 26}, {12, 13}, {14, 16, 17, 18}, {12, 13, 27}, {12, 13},
              {1, 8, 9, 12, 13}}
}, {
    name = "Neapolitan Minor",
    alt_names = {"Byzantine"},
    intervals = {0, 1, 3, 5, 7, 8, 11, 12},
    chords = {{14, 16, 17}, {1, 3, 5, 8, 9}, {12, 13}, {17, 19, 21, 24, 26}, {12, 13}, {1, 2, 3, 14, 16, 17, 18}, {12},
              {14, 16, 17}}
}, {
    name = "Major Locrian",
    intervals = {0, 2, 4, 5, 6, 8, 10, 12},
    chords = {{12, 13}, {12, 13, 24, 26}, {12, 13}, {14, 16, 17, 18}, {12, 13, 27}, {12, 13}, {1, 8, 9, 12, 13},
              {12, 13}}
}, {
    name = "Leading Whole Tone",
    intervals = {0, 2, 4, 6, 8, 10, 11, 12},
    chords = {{12, 13, 27}, {12, 13}, {1, 8, 9, 12, 13}, {12, 13}, {12, 13, 24, 26}, {12, 13}, {14, 16, 17, 18},
              {12, 13, 27}}
}, {
    name = "Six Tone Symmetrical",
    intervals = {0, 1, 4, 5, 8, 9, 11, 12},
    chords = {{12, 27}, {1, 3, 8, 12, 13, 16, 17, 19, 27}, {1, 2, 12, 14}, {1, 3, 12, 16, 17, 24, 27}, {12},
              {1, 3, 5, 12, 16, 17, 27}, {}, {12, 27}}
}, {
    name = "Balinese",
    intervals = {0, 1, 3, 7, 8, 12},
    chords = {{17}, {}, {}, {}, {1, 3, 14}, {17}}
}, {
    name = "Persian",
    intervals = {0, 1, 4, 5, 6, 8, 11, 12},
    chords = {{12, 27}, {1, 3, 8, 14, 15, 16, 17, 19}, {1, 2, 4, 12}, {16, 17, 24}, {14, 15}, {12, 13}, {14}, {12, 27}}
}, {
    name = "East Indian Purvi",
    intervals = {0, 1, 4, 6, 7, 8, 11, 12},
    chords = {{1, 3, 12, 27}, {14, 15, 16, 17, 19, 24, 26}, {1, 2, 4, 12, 17, 18, 20}, {14, 15}, {}, {12, 13, 27}, {14},
              {1, 3, 12, 27}}
}, {
    name = "Oriental",
    intervals = {0, 1, 4, 5, 6, 9, 10, 12},
    chords = {{}, {12, 27}, {}, {1, 3, 12, 14, 27}, {1, 3, 8, 16, 17, 19, 24, 26}, {1, 2, 12, 17, 18}, {16, 17, 24}, {}}
}, {
    name = "Double Harmonic",
    intervals = {0, 1, 4, 5, 7, 8, 11, 12},
    chords = {{1, 3, 12, 14, 27}, {1, 3, 8, 16, 17, 19, 24, 26}, {1, 2, 12, 17, 18}, {16, 17, 24}, {}, {12, 27}, {},
              {1, 3, 12, 14, 27}}
}, {
    name = "Enigmatic",
    intervals = {0, 1, 4, 6, 8, 10, 11, 12},
    chords = {{12, 13, 27}, {14, 15, 16, 17, 18, 19}, {1, 2, 4, 12}, {1, 8, 9, 10, 14, 15}, {12, 13}, {24, 26}, {14},
              {12, 13, 27}}
}, {
    name = "Overtone",
    intervals = {0, 2, 4, 6, 7, 9, 10, 12},
    chords = {{1, 2, 4, 8, 9}, {1, 8, 9, 10, 12, 13, 14, 15}, {24, 26}, {12, 13, 24, 26}, {14, 16, 17, 18, 20},
              {14, 15, 17, 18, 19}, {12, 27}, {1, 2, 4, 8, 9}}
}, {
    name = "Eight Tone Spanish",
    intervals = {0, 1, 3, 4, 5, 6, 8, 10, 12},
    chords = {{12, 13, 24, 26}, {1, 2, 3, 4, 5, 6, 7, 14, 16, 17, 18, 20}, {14, 15, 17, 18, 19, 20, 21, 22, 23},
              {12, 27}, {14, 15, 16, 17, 19}, {1, 2, 3, 4, 5, 8, 9}, {1, 2, 4, 8, 9, 10, 11, 12, 13, 14, 15},
              {14, 15, 17, 19, 21, 22, 24, 26}, {12, 13, 24, 26}}
}, {
    name = "Prometheus",
    intervals = {0, 2, 4, 6, 9, 10, 12},
    chords = {{}, {1, 8, 9, 12, 13}, {}, {12, 13, 24, 26}, {14, 17, 18}, {12, 27}, {}}
}, {
    name = "Gagaku Rittsu Sen Pou",
    intervals = {0, 2, 5, 7, 9, 10, 12},
    chords = {{14, 15}, {14, 15, 17, 19}, {1, 2, 4, 14}, {14, 15, 17, 19, 21, 22}, {}, {1, 2, 3, 4, 5}, {14, 15}}
}, {
    name = "In Sen Pou",
    intervals = {0, 1, 5, 2, 8, 12},
    chords = {{}, {1, 3}, {17, 18}, {24, 26}, {}, {}}
}, {
    name = "Okinawa",
    intervals = {0, 4, 5, 7, 11, 12},
    chords = {{1, 3, 14}, {17}, {}, {}, {}, {1, 3, 14}}
}}
local function hash_djb(str)
    local hash = 5381
    for i = 1, #str do
        local c = string.byte(str, i)
        hash = (hash * 33 + c) % 2 ^ 32
    end
    return math.floor(hash)
end
-- print((hash_djb("helloworld")))

local function generate_c_code(scales)
    local c_code = [[
#include <stdint.h>

#define MAX_INTERVALS 16
#define MAX_SCALES 50

typedef struct {
    uint8_t intervals[MAX_INTERVALS];
    uint8_t interval_count;
} Scale;

float SCALE_CHROMATIC[13] = {0.0f, 1.0f/12.0f, 2.0f/12.0f, 3.0f/12.0f, 4.0f/12.0f, 5.0f/12.0f, 6.0f/12.0f, 7.0f/12.0f, 8.0f/12.0f, 9.0f/12.0f, 10.0f/12.0f, 11.0f/12.0f, 1.0f};

Scale SCALES[MAX_SCALES] = {
]]

    for _, scale in ipairs(scales) do
        local name = scale.name or ""
        local alt_names = scale.alt_names or {}
        local intervals = scale.intervals or {}

        c_code = c_code .. string.format('    {\n        // %s\n\t{', name)
        for i, interval in ipairs(intervals) do
            c_code = c_code .. string.format("%d", interval)
            if i < #intervals then
                c_code = c_code .. ", "
            end
        end

        c_code = c_code .. string.format("},\n        %d\n    },\n", #intervals)
    end

    c_code = c_code .. "};\n"
    return c_code
end

-- Example usage:
-- Replace the placeholder `scales` table with your actual MusicUtil.SCALES data.
local c_code = generate_c_code(scales)
print(c_code)

-- -- print names of scales
-- -- make select 
-- for i, scale in ipairs(scales) do
--     print(string.format("<option value=%d>%s</option>", i, scale.name))
-- end
