Skip to content

Commit

Permalink
serve js bundle in a seperate request to allow gzip
Browse files Browse the repository at this point in the history
  • Loading branch information
marchingband committed Dec 12, 2021
1 parent 5e8a6a8 commit 4821ad9
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 501 deletions.
2 changes: 2 additions & 0 deletions src/bundle.h

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions src/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ static void gpioTask(void* x) {
};
}

// void IRAM_ATTR isr(void *e){
void isr(void *e){
button_event_t *event = (button_event_t*)e;
event->val = digitalRead(event->pin);
isr_log_d("read %d",event->val);
xQueueSendFromISR(gpio_queue_handle, &event, NULL);
}

// void IRAM_ATTR touch_isr(void *e){
void touch_isr(void *e){
button_event_t *event = (button_event_t*)e;
uint32_t pad_intr = touch_pad_get_status();
Expand All @@ -71,7 +69,6 @@ Button::Button(int pin, int mode, int dbnc){
this->pressed = false;
event.pin = pin;
event.button = this;
// gpio_reset_pin(gpioNumToGpioNum_T(pin));
}

Button::Button(int pin, int mode, int dbnc, bool touch){
Expand All @@ -85,7 +82,6 @@ Button::Button(int pin, int mode, int dbnc, bool touch){
this->handleRelease = NULL;
event.pin = pin;
event.button = this;
// gpio_reset_pin(gpioNumToGpioNum_T(pin));
}

Button::~Button(){
Expand Down
2 changes: 0 additions & 2 deletions src/button_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#ifndef BUTTON_STRUCT_H
#define BUTTON_STRUCT_H

// #include "button.h"

class Button;

typedef struct {
Expand Down
7 changes: 0 additions & 7 deletions src/defines.h

This file was deleted.

82 changes: 0 additions & 82 deletions src/dev_board.cpp

This file was deleted.

129 changes: 45 additions & 84 deletions src/file_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,27 +467,6 @@ struct wav_lu_t null_wav_file = {
.length=0,
};

// struct wav_lu_t get_file_t_from_lookup_table(struct midi_event_t midi_event, int current_bank)
// {
// struct wav_lu_t file = wav_lut[current_bank][midi_event.note];
// if(file.isRack == -1){
// // it is not a rack
// return(file);
// }
// struct rack_lu_t rack = rack_lut[file.isRack];
// if(midi_event.velocity < rack.break_points[0]){
// // is below the bottom threshold
// return(null_wav_file);
// }
// for(int i=1; i<rack.num_layers; i++){
// if(midi_event.velocity < rack.break_points[i]){
// return(rack.layers[i-1]);
// }
// }
// // its above the top threshold
// return(null_wav_file);
// }

struct wav_lu_t get_file_t_from_lookup_table(uint8_t voice, uint8_t note, uint8_t velocity)
{
struct wav_lu_t file = wav_lut[voice][note];
Expand Down Expand Up @@ -819,32 +798,6 @@ char *print_config_json()
return out;
}

// char* print_fs_json(){
// cJSON *j_RESPONSE_ROOT = cJSON_CreateObject();
// cJSON *j_metadata = cJSON_AddObjectToObject(j_RESPONSE_ROOT,"metadata");
// cJSON *j_voices = cJSON_AddArrayToObject(j_RESPONSE_ROOT,"voices");
// cJSON *j_firmwares = cJSON_AddArrayToObject(j_RESPONSE_ROOT,"firmwares");
// cJSON *j_websites = cJSON_AddArrayToObject(j_RESPONSE_ROOT,"websites");
// cJSON *j_pin_config = cJSON_AddArrayToObject(j_RESPONSE_ROOT,"pinConfig");
// // for(int j=0;j<NUM_VOICES;j++)
// for(int j=0;j<1;j++)
// {
// feedLoopWDT();
// cJSON *voice = add_voice_json(j);
// cJSON_AddItemToArray(j_voices, voice);
// }
// add_metadata_json(j_metadata);
// add_firmware_json(j_firmwares);
// add_website_json(j_websites);
// add_pin_config_json(j_pin_config);

// char* out = cJSON_PrintUnformatted(j_RESPONSE_ROOT);
// feedLoopWDT();
// if(out == NULL){log_e("failed to print JSON");}
// cJSON_Delete(j_RESPONSE_ROOT);
// return out;
// }

cJSON* add_voice_json(uint8_t voice_num)
{
struct wav_file_t *voice = (struct wav_file_t *)ps_malloc(NUM_NOTES * sizeof(struct wav_file_t));
Expand All @@ -866,8 +819,8 @@ cJSON* add_voice_json(uint8_t voice_num)
if(ret==NULL){log_e("failed to make json isRack");continue;}
ret = cJSON_AddNumberToObject(note, "empty", voice[j].empty);
if(ret==NULL){log_e("failed to make json empty");continue;}
ret = cJSON_AddNumberToObject(note, "start_block", voice[j].start_block);
if(ret==NULL){log_e("failed to make json start block");continue;}
// ret = cJSON_AddNumberToObject(note, "start_block", voice[j].start_block);
// if(ret==NULL){log_e("failed to make json start block");continue;}
ret = cJSON_AddNumberToObject(note, "size", voice[j].length);
if(ret==NULL){log_e("failed to make json size");continue;}
ret = cJSON_AddNumberToObject(note, "mode", voice[j].play_back_mode);
Expand All @@ -880,8 +833,9 @@ cJSON* add_voice_json(uint8_t voice_num)
if(ret==NULL){log_e("failed to make json responseCurve");continue;}
ret = cJSON_AddNumberToObject(note, "priority", voice[j].priority);
if(ret==NULL){log_e("failed to make json priority");continue;}
if(voice[j].isRack != -1){
if(voice[j].isRack > -1){
// its a rack
// log_i("rack %d",voice[j].isRack);
struct rack_file_t rack_item = rack_files[voice[j].isRack];
cJSON *rack = cJSON_CreateObject();
if(rack==NULL){log_e("failed to make rack");continue;}
Expand All @@ -895,12 +849,12 @@ cJSON* add_voice_json(uint8_t voice_num)
if(note == NULL){log_e("unable to make note");continue;}
ret = cJSON_AddStringToObject(wav,"name",wav_file.name);
if(ret==NULL){log_e("failed to make json name");continue;}
ret = cJSON_AddNumberToObject(wav, "isRack", wav_file.isRack);
if(ret==NULL){log_e("failed to make json isRack");continue;}
// ret = cJSON_AddNumberToObject(wav, "isRack", wav_file.isRack);
// if(ret==NULL){log_e("failed to make json isRack");continue;}
ret = cJSON_AddNumberToObject(wav, "empty", wav_file.empty);
if(ret==NULL){log_e("failed to make json empty");continue;}
ret = cJSON_AddNumberToObject(wav, "start_block", wav_file.start_block);
if(ret==NULL){log_e("failed to make json start block");continue;}
// ret = cJSON_AddNumberToObject(wav, "start_block", wav_file.start_block);
// if(ret==NULL){log_e("failed to make json start block");continue;}
ret = cJSON_AddNumberToObject(wav, "size", wav_file.length);
if(ret==NULL){log_e("failed to make json size");continue;}
cJSON_AddItemToArray(layers,wav);
Expand Down Expand Up @@ -1079,13 +1033,13 @@ void close_website_to_emmc(char index){
write_website_lut_to_disk();
}

uint8_t *buf;
size_t bytes_read = 0;
size_t sector;
size_t bytes_left_in_sector;
size_t pointer;

size_t get_website_chunk(size_t start_block, size_t toWrite, uint8_t *buffer, size_t total){
uint8_t *buf;
size_t bytes_read = 0;
size_t sector;
size_t bytes_left_in_sector;
size_t pointer;
if(bytes_read==0){
buf = (uint8_t *)ps_malloc(SECTOR_SIZE);
sector = start_block;
Expand Down Expand Up @@ -1221,7 +1175,6 @@ void clear_rack(int isRack)
buf[isRack].free = 1;
buf[isRack].num_layers = 0;
ESP_ERROR_CHECK(emmc_write(buf,RACK_DIRECTORY_START_BLOCK,RACK_DIRECTORY_BLOCKS));
feedLoopWDT();
free(buf);
}

Expand All @@ -1248,30 +1201,38 @@ void updatePinConfig(cJSON *config){
cJSON_Delete(json);
}

// void deleteNote(int voice, int note)
// {
// struct wav_file_t *voice_data = (struct wav_file_t*)ps_malloc(BLOCKS_PER_VOICE * SECTOR_SIZE);
// if(voice_data==NULL){log_e("not enough ram to alloc voice_data");}

// size_t voice_start_block = WAV_LUT_START_BLOCK + (BLOCKS_PER_VOICE * voice);
// ESP_ERROR_CHECK(emmc_read(voice_data, voice_start_block, BLOCKS_PER_VOICE));
// voice_data[note].empty = 1;
// ESP_ERROR_CHECK(emmc_write(voice_data,voice_start_block,BLOCKS_PER_VOICE));
// if(voice_data[note].isRack > -1)
// {
// //its a rack so clear the rack data too
// struct rack_file_t *rack_data = (struct rack_file_t *)ps_malloc(RACK_DIRECTORY_BLOCKS * SECTOR_SIZE);
// if(buf == NULL){log_i("malloc rack_file_t buf failed");}
// ESP_ERROR_CHECK(emmc_read(rack_data, RACK_DIRECTORY_START_BLOCK, RACK_DIRECTORY_BLOCKS));
// rack_data[voice_data[note].isRack].num_layers = 0;
// rack_data[voice_data[note].isRack].free = 1;
// char *blank = "";
// memcpy(rack_data[voice_data[note].isRack].name, blank, 1);
// ESP_ERROR_CHECK(emmc_write(buf,RACK_DIRECTORY_START_BLOCK,RACK_DIRECTORY_BLOCKS));
// free(rack_data);
// };
// free(voice_data);
// }
void clean_up_rack_directory(void)
{
bool used[128] = {false};
bool should_init_rack_lut = false;
for(int i=0; i<NUM_VOICES; i++)
{
for(int j=0; j<NUM_NOTES; j++)
{
if(wav_lut[i][j].empty == 0 && wav_lut[i][j].isRack > -1)
{
used[wav_lut[i][j].isRack] = true;
}
}
}
for(int i=0; i<128; i++)
{
if(used[i] == false)
{
if(rack_lut[i].free == false)
{
// it's unused but marked as not free
log_i("recovering rack %d", i);
clear_rack(i);
should_init_rack_lut = true;
}
}
}
if(should_init_rack_lut)
{
read_rack_lut_from_disk();
}
}

void log_pin_config(void)
{
Expand Down
2 changes: 1 addition & 1 deletion src/file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void restore_emmc(uint8_t* source, size_t size);
void close_restore_emmc();
char *print_voice_json(int numVoice);
char *print_config_json();
// void deleteNote(int voice, int note);
void clean_up_rack_directory(void);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions src/html.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const char HTML[] = R"=====(<!doctype html><html lang="en"><head><title>Waver UI</title></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script src="http://192.168.5.18/bundle" type="text/javascript"></script></body></html>)=====";
Loading

0 comments on commit 4821ad9

Please sign in to comment.