From f7ae7079c90d39973edef3f58903784e496fcc87 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 24 Oct 2014 02:34:16 +0100 Subject: [PATCH 01/10] Fix typos leading to state not being saved --- drmr.c | 2 +- drmr.ttl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drmr.c b/drmr.c index 923a3be..1cc4159 100644 --- a/drmr.c +++ b/drmr.c @@ -543,7 +543,7 @@ restore_state(LV2_Handle instance, static const void* extension_data(const char* uri) { static const LV2_State_Interface state_iface = { save_state, restore_state }; - if (!strcmp(uri, LV2_STATE_URI "#Interface")) return &state_iface; + if (!strcmp(uri, LV2_STATE__interface)) return &state_iface; return NULL; } diff --git a/drmr.ttl b/drmr.ttl index 8479635..f171a5b 100644 --- a/drmr.ttl +++ b/drmr.ttl @@ -19,7 +19,7 @@ doap:license ; lv2:requiredFeature urid:map ; ui:ui ; - lv2:extensionData ; + lv2:extensionData ; lv2:port [ a lv2:InputPort , atom:AtomPort; atom:bufferType atom:Sequence ; From f6e1a2110892096940242ae00acea899d6406a06 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 24 Oct 2014 03:12:39 +0100 Subject: [PATCH 02/10] Fix loading filenames starting with "file://" (used in lv2 presets) --- drmr.c | 8 +++++--- drmr_ui.c | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drmr.c b/drmr.c index 1cc4159..0e63ecc 100644 --- a/drmr.c +++ b/drmr.c @@ -31,7 +31,7 @@ static void* load_thread(void* arg) { DrMr* drmr = (DrMr*)arg; drmr_sample *loaded_samples,*old_samples; int loaded_count, old_scount; - char *request; + char *request, *request_orig; for(;;) { pthread_mutex_lock(&drmr->load_mutex); pthread_cond_wait(&drmr->load_cond, @@ -39,7 +39,9 @@ static void* load_thread(void* arg) { pthread_mutex_unlock(&drmr->load_mutex); old_samples = drmr->samples; old_scount = drmr->num_samples; - request = drmr->request_buf[drmr->curReq]; + request_orig = request = drmr->request_buf[drmr->curReq]; + if (!strncmp(request, "file://", 7)) + request += 7; loaded_samples = load_hydrogen_kit(request,drmr->rate,&loaded_count); if (!loaded_samples) { fprintf(stderr,"Failed to load kit at: %s\n",request); @@ -57,7 +59,7 @@ static void* load_thread(void* arg) { pthread_mutex_unlock(&drmr->load_mutex); } if (old_scount > 0) free_samples(old_samples,old_scount); - drmr->current_path = request; + drmr->current_path = request_orig; current_kit_changed = 1; } return 0; diff --git a/drmr_ui.c b/drmr_ui.c index 71c3a64..342a1be 100644 --- a/drmr_ui.c +++ b/drmr_ui.c @@ -723,6 +723,8 @@ port_event(LV2UI_Handle handle, lv2_atom_object_get(obj, ui->uris.kit_path, &path, 0); if (path) { char *kitpath = LV2_ATOM_BODY(path); + if (!strncmp(kitpath, "file://", 7)) + kitpath += 7; char *realp = realpath(kitpath,NULL); if (!realp) { fprintf(stderr,"Passed a path I can't resolve, bailing out\n"); From a593de0836790a3437b861cf0eb7acd1b581e512 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 9 May 2015 20:35:18 +0200 Subject: [PATCH 03/10] Fix crash when saving state without a kit loaded --- drmr.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drmr.c b/drmr.c index 0e63ecc..8c0a128 100644 --- a/drmr.c +++ b/drmr.c @@ -442,16 +442,18 @@ save_state(LV2_Handle instance, return LV2_STATE_ERR_NO_FEATURE; } - char* mapped_path = map_path->abstract_path(map_path->handle, - drmr->current_path); - - stat = store(handle, - drmr->uris.kit_path, - mapped_path, - strlen(mapped_path) + 1, - drmr->uris.string_urid, - LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE); - if (stat) return stat; + if (drmr->current_path != NULL) { + char* mapped_path = map_path->abstract_path(map_path->handle, + drmr->current_path); + + stat = store(handle, + drmr->uris.kit_path, + mapped_path, + strlen(mapped_path) + 1, + drmr->uris.string_urid, + LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE); + if (stat) return stat; + } flag = drmr->ignore_velocity?1:0; stat = store(handle, From a26418b7f47d9162b9e63f8db5d1f2dd2367ad13 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 17 Jul 2016 15:05:03 +0200 Subject: [PATCH 04/10] Set offset when triggering samples --- drmr.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drmr.c b/drmr.c index 8c0a128..723b1f6 100644 --- a/drmr.c +++ b/drmr.c @@ -229,7 +229,7 @@ static inline void layer_to_sample(drmr_sample *sample, float gain) { sample->data = sample->layers[0].data; } -static inline void trigger_sample(DrMr *drmr, int nn, uint8_t* const data) { +static inline void trigger_sample(DrMr *drmr, int nn, uint8_t* const data, uint32_t offset) { // need to mutex this to avoid getting the samples array // changed after the check that the midi-note is valid pthread_mutex_lock(&drmr->load_mutex); @@ -244,13 +244,13 @@ static inline void trigger_sample(DrMr *drmr, int nn, uint8_t* const data) { build_midi_info_message(drmr,data); } drmr->samples[nn].active = 1; - drmr->samples[nn].offset = 0; + drmr->samples[nn].offset = offset; drmr->samples[nn].velocity = drmr->ignore_velocity?1.0f:((float)data[2])/VELOCITY_MAX; } pthread_mutex_unlock(&drmr->load_mutex); } -static inline void untrigger_sample(DrMr *drmr, int nn) { +static inline void untrigger_sample(DrMr *drmr, int nn, uint32_t offset) { pthread_mutex_lock(&drmr->load_mutex); if (nn >= 0 && nn < drmr->num_samples) { if (drmr->samples[nn].layer_count > 0) { @@ -259,7 +259,7 @@ static inline void untrigger_sample(DrMr *drmr, int nn) { fprintf(stderr,"Failed to find layer at: %i for %f\n",nn,*drmr->gains[nn]); } drmr->samples[nn].active = 0; - drmr->samples[nn].offset = 0; + drmr->samples[nn].offset = offset; } pthread_mutex_unlock(&drmr->load_mutex); } @@ -286,19 +286,20 @@ static void run(LV2_Handle instance, uint32_t n_samples) { if (ev->body.type == drmr->uris.midi_event) { uint8_t nn; uint8_t* const data = (uint8_t* const)(ev + 1); + uint32_t offset = (ev->time.frames > 0 && ev->time.frames < n_samples) ? ev->time.frames : 0; //int channel = *data & 15; switch ((*data) >> 4) { case 8: if (!drmr->ignore_note_off) { nn = data[1]; nn-=baseNote; - untrigger_sample(drmr,nn); + untrigger_sample(drmr,nn,offset); } break; case 9: { nn = data[1]; nn-=baseNote; - trigger_sample(drmr,nn,data); + trigger_sample(drmr,nn,data,offset); break; } default: @@ -333,10 +334,11 @@ static void run(LV2_Handle instance, uint32_t n_samples) { if (trigger) { int32_t si = ((const LV2_Atom_Int*)trigger)->body; uint8_t mdata[3]; + uint32_t offset = (ev->time.frames > 0 && ev->time.frames < n_samples) ? ev->time.frames : 0; mdata[0] = 0x90; // note on mdata[1] = si+baseNote; mdata[2] = 0x7f; - trigger_sample(drmr,si,mdata); + trigger_sample(drmr,si,mdata,offset); } if (ignvel) drmr->ignore_velocity = ((const LV2_Atom_Bool*)ignvel)->body; From 8fac0013315a8fc1c6c9da35a46497b8d867f1b0 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 17 Jul 2016 15:25:51 +0200 Subject: [PATCH 05/10] Correct offset --- drmr.c | 14 +++++++++----- drmr.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drmr.c b/drmr.c index 723b1f6..0fe61db 100644 --- a/drmr.c +++ b/drmr.c @@ -244,8 +244,9 @@ static inline void trigger_sample(DrMr *drmr, int nn, uint8_t* const data, uint3 build_midi_info_message(drmr,data); } drmr->samples[nn].active = 1; - drmr->samples[nn].offset = offset; + drmr->samples[nn].offset = 0; drmr->samples[nn].velocity = drmr->ignore_velocity?1.0f:((float)data[2])/VELOCITY_MAX; + drmr->samples[nn].dataoffset = offset; } pthread_mutex_unlock(&drmr->load_mutex); } @@ -259,7 +260,8 @@ static inline void untrigger_sample(DrMr *drmr, int nn, uint32_t offset) { fprintf(stderr,"Failed to find layer at: %i for %f\n",nn,*drmr->gains[nn]); } drmr->samples[nn].active = 0; - drmr->samples[nn].offset = offset; + drmr->samples[nn].offset = 0; + drmr->samples[nn].dataoffset = offset; } pthread_mutex_unlock(&drmr->load_mutex); } @@ -378,7 +380,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) { for (i = 0;i < drmr->num_samples;i++) { int pos,lim; drmr_sample* cs = drmr->samples+i; - if (cs->active && (cs->limit > 0)) { + if ((cs->active || cs->dataoffset) && (cs->limit > 0)) { float coef_right, coef_left; if (i < 32) { float gain = DB_CO(*(drmr->gains[i])); @@ -390,10 +392,12 @@ static void run(LV2_Handle instance, uint32_t n_samples) { else { coef_right = coef_left = 1.0f; } + uint32_t dataoffset = cs->dataoffset; + cs->dataoffset = 0; if (cs->info->channels == 1) { // play mono sample lim = (n_samples < (cs->limit - cs->offset)?n_samples:(cs->limit-cs->offset)); - for(pos = 0;pos < lim;pos++) { + for(pos = dataoffset; pos < lim; pos++) { drmr->left[pos] += cs->data[cs->offset]*coef_left; drmr->right[pos] += cs->data[cs->offset]*coef_right; cs->offset++; @@ -401,7 +405,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) { } else { // play stereo sample lim = (cs->limit-cs->offset)/cs->info->channels; if (lim > n_samples) lim = n_samples; - for (pos=0;posleft[pos] += cs->data[cs->offset++]*coef_left; drmr->right[pos] += cs->data[cs->offset++]*coef_right; } diff --git a/drmr.h b/drmr.h index 1cf969c..17354d7 100644 --- a/drmr.h +++ b/drmr.h @@ -61,6 +61,7 @@ typedef struct { float velocity; drmr_layer *layers; float* data; + uint32_t dataoffset; } drmr_sample; // lv2 stuff From 25ecafb56f53bf80d7c8fde6c241a7ef0f4f58ff Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 17 Jul 2016 15:56:43 +0200 Subject: [PATCH 06/10] Fix note-off timing (and crash) --- drmr.c | 17 ++++++++++++----- drmr_hydrogen.c | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drmr.c b/drmr.c index 0fe61db..ea8e31b 100644 --- a/drmr.c +++ b/drmr.c @@ -260,7 +260,6 @@ static inline void untrigger_sample(DrMr *drmr, int nn, uint32_t offset) { fprintf(stderr,"Failed to find layer at: %i for %f\n",nn,*drmr->gains[nn]); } drmr->samples[nn].active = 0; - drmr->samples[nn].offset = 0; drmr->samples[nn].dataoffset = offset; } pthread_mutex_unlock(&drmr->load_mutex); @@ -378,7 +377,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) { pthread_mutex_lock(&drmr->load_mutex); for (i = 0;i < drmr->num_samples;i++) { - int pos,lim; + uint32_t pos,lim; drmr_sample* cs = drmr->samples+i; if ((cs->active || cs->dataoffset) && (cs->limit > 0)) { float coef_right, coef_left; @@ -392,12 +391,20 @@ static void run(LV2_Handle instance, uint32_t n_samples) { else { coef_right = coef_left = 1.0f; } - uint32_t dataoffset = cs->dataoffset; + + uint32_t datastart, dataend; + if (cs->active) { + datastart = cs->dataoffset; + dataend = (uint32_t)-1; + } else { + datastart = 0; + dataend = cs->dataoffset; + } cs->dataoffset = 0; if (cs->info->channels == 1) { // play mono sample lim = (n_samples < (cs->limit - cs->offset)?n_samples:(cs->limit-cs->offset)); - for(pos = dataoffset; pos < lim; pos++) { + for (pos = datastart; pos < lim && pos < dataend; pos++) { drmr->left[pos] += cs->data[cs->offset]*coef_left; drmr->right[pos] += cs->data[cs->offset]*coef_right; cs->offset++; @@ -405,7 +412,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) { } else { // play stereo sample lim = (cs->limit-cs->offset)/cs->info->channels; if (lim > n_samples) lim = n_samples; - for (pos = dataoffset; pos < lim; pos++) { + for (pos = datastart; pos < lim && pos < dataend; pos++) { drmr->left[pos] += cs->data[cs->offset++]*coef_left; drmr->right[pos] += cs->data[cs->offset++]*coef_right; } diff --git a/drmr_hydrogen.c b/drmr_hydrogen.c index fe0f730..5890072 100644 --- a/drmr_hydrogen.c +++ b/drmr_hydrogen.c @@ -565,6 +565,7 @@ drmr_sample* load_hydrogen_kit(char *path, double rate, int *num_samples) { samples[i].data = NULL; } samples[i].active = 0; + samples[i].dataoffset = 0; i_to_free = cur_i; cur_i = cur_i->next; From 242815968df788be94dc6c13b4ac6f2cb4a279dc Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 17 Jul 2016 16:04:19 +0200 Subject: [PATCH 07/10] Don't use unsigned --- drmr.c | 6 +++--- drmr.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drmr.c b/drmr.c index ea8e31b..f4175c2 100644 --- a/drmr.c +++ b/drmr.c @@ -377,7 +377,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) { pthread_mutex_lock(&drmr->load_mutex); for (i = 0;i < drmr->num_samples;i++) { - uint32_t pos,lim; + int pos,lim; drmr_sample* cs = drmr->samples+i; if ((cs->active || cs->dataoffset) && (cs->limit > 0)) { float coef_right, coef_left; @@ -392,10 +392,10 @@ static void run(LV2_Handle instance, uint32_t n_samples) { coef_right = coef_left = 1.0f; } - uint32_t datastart, dataend; + int datastart, dataend; if (cs->active) { datastart = cs->dataoffset; - dataend = (uint32_t)-1; + dataend = n_samples; } else { datastart = 0; dataend = cs->dataoffset; diff --git a/drmr.h b/drmr.h index 17354d7..036850a 100644 --- a/drmr.h +++ b/drmr.h @@ -61,7 +61,7 @@ typedef struct { float velocity; drmr_layer *layers; float* data; - uint32_t dataoffset; + int dataoffset; } drmr_sample; // lv2 stuff From e0017617935341185670da1ee6c58654d40b60f8 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 17 Jul 2016 16:26:22 +0200 Subject: [PATCH 08/10] Comment out printf during run --- drmr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drmr.c b/drmr.c index f4175c2..31fc43a 100644 --- a/drmr.c +++ b/drmr.c @@ -352,7 +352,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) { build_state_message(drmr); } } - else printf("unrecognized event\n"); + //else printf("unrecognized event\n"); } if ((drmr->curReq >= 0) && From 0c2c7947172b4b99c17a2e73ac1a57fecff7df0c Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 17 Jul 2016 16:31:16 +0200 Subject: [PATCH 09/10] Remove yet another print --- drmr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drmr.c b/drmr.c index 31fc43a..3e8c335 100644 --- a/drmr.c +++ b/drmr.c @@ -304,7 +304,8 @@ static void run(LV2_Handle instance, uint32_t n_samples) { break; } default: - printf("Unhandeled status: %i\n",(*data)>>4); + //printf("Unhandeled status: %i\n",(*data)>>4); + break; } } else if (ev->body.type == drmr->uris.atom_resource) { From 28791215c14d5c5e6fddd11e704238ab4fc51354 Mon Sep 17 00:00:00 2001 From: Petr Semiletov Date: Wed, 17 May 2023 15:20:52 +0300 Subject: [PATCH 10/10] modern Hydrogen drumkit format parsing fix --- drmr_hydrogen.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drmr_hydrogen.c b/drmr_hydrogen.c index 5890072..61124d9 100644 --- a/drmr_hydrogen.c +++ b/drmr_hydrogen.c @@ -90,6 +90,8 @@ struct hp_info { char in_instrument_list; char in_instrument; char in_layer; + char in_drumkit_component; + char counted_cur_inst; int cur_off; char cur_buf[MAX_CHAR_DATA]; @@ -106,7 +108,7 @@ startElement(void *userData, const char *name, const char **atts) info->cur_off = 0; if (info->in_info) { if (info->in_instrument) { - if (!strcmp(name,"layer") && !info->scan_only) { + if (!strcmp(name,"layer") && !info->scan_only) { info->in_layer = 1; info->cur_layer = malloc(sizeof(struct instrument_layer)); memset(info->cur_layer,0,sizeof(struct instrument_layer)); @@ -121,6 +123,10 @@ startElement(void *userData, const char *name, const char **atts) } else { if (!strcmp(name,"instrumentList")) info->in_instrument_list = 1; + + if (! strcmp (name,"drumkitComponent")) + info->in_drumkit_component = 1; + } } else { if (!strcmp(name,"drumkit_info")) @@ -135,7 +141,7 @@ endElement(void *userData, const char *name) if (info->cur_off == MAX_CHAR_DATA) info->cur_off--; info->cur_buf[info->cur_off]='\0'; - if (info->in_info && !info->in_instrument_list && !strcmp(name,"name")) + if (info->in_info && ! info->in_drumkit_component && !info->in_instrument_list && !strcmp(name,"name")) info->kit_info->name = strdup(info->cur_buf); if (info->scan_only && info->in_info && !info->in_instrument_list && !strcmp(name,"info")) info->kit_info->desc = strdup(info->cur_buf); @@ -188,6 +194,9 @@ endElement(void *userData, const char *name) info->in_instrument = 0; } if (info->in_instrument_list && !strcmp(name,"instrumentList")) info->in_instrument_list = 0; + if (info->in_drumkit_component && ! strcmp (name, "drumkitComponent")) + info->in_drumkit_component = 0; + if (info->in_info && !strcmp(name,"drumkit_info")) info->in_info = 0; }