Skip to content

Commit

Permalink
checking for a patch that doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhitman committed Jun 12, 2024
1 parent f0a1ca6 commit 0ae70af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/amy.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ int8_t oscs_init() {
ks_init();
filters_init();
algo_init();
patches_init();

if(pcm_samples) {
pcm_init();
Expand Down
1 change: 1 addition & 0 deletions src/amy.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ extern struct state amy_global;

float atoff(const char *s);
int8_t oscs_init();
void patches_init();
void parse_breakpoint(struct synthinfo * e, char* message, uint8_t bp_set) ;
void parse_algorithm_source(struct synthinfo * e, char* message) ;
void hold_and_modify(uint16_t osc) ;
Expand Down
17 changes: 14 additions & 3 deletions src/patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ uint16_t memory_patch_oscs[MEMORY_PATCHES];
uint8_t osc_to_voice[AMY_OSCS];
uint16_t voice_to_base_osc[MAX_VOICES];

void patches_init() {
for(uint8_t i=0;i<MEMORY_PATCHES;i++) {
memory_patch_oscs[i] = 0;
memory_patch[i] = NULL;
}
}

void patches_reset() {
for(uint8_t v=0;v<MAX_VOICES;v++) {
Expand All @@ -35,7 +41,8 @@ void patches_reset() {
AMY_UNSET(osc_to_voice[i]);
}
for(uint8_t i=0;i<MEMORY_PATCHES;i++) {
if(memory_patch[i] != NULL) free(memory_patch[i]);
if(memory_patch_oscs[i] > 0) free(memory_patch[i]);
memory_patch[i] = NULL;
memory_patch_oscs[i] = 0;
}
}
Expand All @@ -58,7 +65,7 @@ void patches_store_patch(char * message) {
start = i+1;
}
}
if(memory_patch[patch_number-1024] != NULL) { free(memory_patch[patch_number-1024]); }
if(memory_patch_oscs[patch_number-1024] >0) { free(memory_patch[patch_number-1024]); }
memory_patch[patch_number-1024] = malloc(strlen(patch)+1);
memory_patch_oscs[patch_number-1024] = max_osc + 1;
strcpy(memory_patch[patch_number-1024], patch);
Expand Down Expand Up @@ -93,8 +100,12 @@ void patches_load_patch(struct event e) {
char *message;
uint16_t patch_osc = 0;
if(e.load_patch > 1023) {
message = memory_patch[e.load_patch-1024];
patch_osc = memory_patch_oscs[e.load_patch-1024];
if(patch_osc > 0){
message = memory_patch[e.load_patch-1024];
} else {
num_voices = 0; // don't do anything
}
} else {
message = (char*)patch_commands[e.load_patch];
patch_osc = patch_oscs[e.load_patch];
Expand Down

0 comments on commit 0ae70af

Please sign in to comment.