Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HEXTER_DEFAULT_PATCH envvar to load a patch file at startup #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/dx7_voice_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "hexter_types.h"
#include "dx7_voice.h"
#include "dx7_voice_data.h"
#include "gui_data.h"

/* in dx7_voice_patches.c: */
extern int friendly_patch_count;
Expand Down Expand Up @@ -434,6 +435,11 @@ dssp_error_message(const char *fmt, ...)
void
hexter_data_patches_init(dx7_patch_t *patches)
{
/* Try loading from file first */
if ( hexter_file_patches_init(patches) == 1 ) {
return;
}

int i;

memcpy(patches, friendly_patches, friendly_patch_count * sizeof(dx7_patch_t));
Expand All @@ -443,6 +449,51 @@ hexter_data_patches_init(dx7_patch_t *patches)
}
}

/*
* hexter_file_patches_init
*
* initialize the patch bank if HEXTER_DEFAULT_PATCH envar is set to a
* valid patch file.
*/
int
hexter_file_patches_init(dx7_patch_t *patches)
{
char *env = "HEXTER_DEFAULT_PATCH";
char *val = NULL;
int ret;
char *message;

val = getenv(env);

if (!val) {
fprintf(stderr, "%s is not defined, will load embedded friendly patches.\n",
env);
return 0;
}

fprintf(stderr, "%s is defined, loading default patches from %s\n",
env, val);

if (gui_data_load(val, 0, &message)) {

/* successfully loaded at least one patch */
fprintf(stderr, "Load Patch File succeeded: %s\n", message);
gui_data_send_dirty_patch_sections();
ret = 1;

} else { /* didn't load anything successfully */

fprintf(stderr, "Load Patch File failed: %s\n", message);
ret = 0;

}
free(message);

return ret;

}


/*
* hexter_data_performance_init
*
Expand Down
1 change: 1 addition & 0 deletions src/dx7_voice_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void dx7_patch_unpack(dx7_patch_t *packed_patch, uint8_t number,
uint8_t *unpacked_patch);
void dx7_patch_pack(uint8_t *unpacked_patch, dx7_patch_t *packed_patch,
uint8_t number);
int hexter_file_patches_init(dx7_patch_t *patches);
void hexter_data_patches_init(dx7_patch_t *patches);
void hexter_data_performance_init(uint8_t *performance);

Expand Down