Use midi velocity to set intensity of sample. Core only
This commit is contained in:
parent
6992a246aa
commit
534525ce9b
29
drmr.c
29
drmr.c
@ -23,6 +23,7 @@
|
|||||||
#include "drmr_hydrogen.h"
|
#include "drmr_hydrogen.h"
|
||||||
|
|
||||||
#define REQ_BUF_SIZE 10
|
#define REQ_BUF_SIZE 10
|
||||||
|
#define VELOCITY_MAX 127
|
||||||
|
|
||||||
static int current_kit_changed = 0;
|
static int current_kit_changed = 0;
|
||||||
|
|
||||||
@ -228,6 +229,21 @@ static inline void trigger_sample(DrMr *drmr, int nn, uint8_t* const data) {
|
|||||||
}
|
}
|
||||||
drmr->samples[nn].active = 1;
|
drmr->samples[nn].active = 1;
|
||||||
drmr->samples[nn].offset = 0;
|
drmr->samples[nn].offset = 0;
|
||||||
|
drmr->samples[nn].velocity = ((float)data[2])/VELOCITY_MAX;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&drmr->load_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void untrigger_sample(DrMr *drmr, int nn) {
|
||||||
|
pthread_mutex_lock(&drmr->load_mutex);
|
||||||
|
if (nn >= 0 && nn < drmr->num_samples) {
|
||||||
|
if (drmr->samples[nn].layer_count > 0) {
|
||||||
|
layer_to_sample(drmr->samples+nn,*(drmr->gains[nn]));
|
||||||
|
if (drmr->samples[nn].limit == 0)
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&drmr->load_mutex);
|
pthread_mutex_unlock(&drmr->load_mutex);
|
||||||
}
|
}
|
||||||
@ -253,14 +269,17 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
|
|||||||
LV2_SEQUENCE_FOREACH(drmr->control_port, i) {
|
LV2_SEQUENCE_FOREACH(drmr->control_port, i) {
|
||||||
LV2_Atom_Event* const ev = lv2_sequence_iter_get(i);
|
LV2_Atom_Event* const ev = lv2_sequence_iter_get(i);
|
||||||
if (ev->body.type == drmr->uris.midi_event) {
|
if (ev->body.type == drmr->uris.midi_event) {
|
||||||
|
uint8_t nn;
|
||||||
uint8_t* const data = (uint8_t* const)(ev + 1);
|
uint8_t* const data = (uint8_t* const)(ev + 1);
|
||||||
//int channel = *data & 15;
|
//int channel = *data & 15;
|
||||||
switch ((*data) >> 4) {
|
switch ((*data) >> 4) {
|
||||||
case 8: // ignore note-offs for now, should probably be a setting
|
case 8:
|
||||||
//if (drmr->cur_samp) drmr->cur_samp->active = 0;
|
nn = data[1];
|
||||||
|
nn-=baseNote;
|
||||||
|
untrigger_sample(drmr,nn);
|
||||||
break;
|
break;
|
||||||
case 9: {
|
case 9: {
|
||||||
uint8_t nn = data[1];
|
nn = data[1];
|
||||||
nn-=baseNote;
|
nn-=baseNote;
|
||||||
trigger_sample(drmr,nn,data);
|
trigger_sample(drmr,nn,data);
|
||||||
break;
|
break;
|
||||||
@ -331,8 +350,8 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
|
|||||||
float gain = DB_CO(*(drmr->gains[i]));
|
float gain = DB_CO(*(drmr->gains[i]));
|
||||||
float pan_right = ((*drmr->pans[i])+1)/2.0f;
|
float pan_right = ((*drmr->pans[i])+1)/2.0f;
|
||||||
float pan_left = 1-pan_right;
|
float pan_left = 1-pan_right;
|
||||||
coef_right = (pan_right * (DB3SCALE * pan_right + DB3SCALEPO))*gain;
|
coef_right = (pan_right * (DB3SCALE * pan_right + DB3SCALEPO))*gain*cs->velocity;
|
||||||
coef_left = (pan_left * (DB3SCALE * pan_left + DB3SCALEPO))*gain;
|
coef_left = (pan_left * (DB3SCALE * pan_left + DB3SCALEPO))*gain*cs->velocity;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
coef_right = coef_left = 1.0f;
|
coef_right = coef_left = 1.0f;
|
||||||
|
Loading…
Reference in New Issue
Block a user