Lots of fixes (multi-layer, ui):
- Fix ui to properly re-init sample table - Fix ui to only adjust existing sliders - Actually load multi-layer kits - Play correct layer for multi-layer
This commit is contained in:
parent
9e760341b4
commit
45b2eeae22
31
drmr.c
31
drmr.c
@ -140,6 +140,26 @@ connect_port(LV2_Handle instance,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void layer_to_sample(drmr_sample *sample, float gain) {
|
||||||
|
int i;
|
||||||
|
float mapped_gain = (1-(gain/GAIN_MIN));
|
||||||
|
if (mapped_gain > 1.0f) mapped_gain = 1.0f;
|
||||||
|
for(i = 0;i < sample->layer_count;i++) {
|
||||||
|
if (sample->layers[i].min <= mapped_gain &&
|
||||||
|
(sample->layers[i].max > mapped_gain ||
|
||||||
|
sample->layers[i].max == 1 && mapped_gain == 1)) {
|
||||||
|
sample->limit = sample->layers[i].limit;
|
||||||
|
sample->info = sample->layers[i].info;
|
||||||
|
sample->data = sample->layers[i].data;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(stderr,"Couldn't find layer for gain %f in sample\n\n",gain);
|
||||||
|
sample->limit = 0;
|
||||||
|
sample->info = NULL;
|
||||||
|
sample->data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#define DB3SCALE -0.8317830986718104f
|
#define DB3SCALE -0.8317830986718104f
|
||||||
#define DB3SCALEPO 1.8317830986718104f
|
#define DB3SCALEPO 1.8317830986718104f
|
||||||
// taken from lv2 example amp plugin
|
// taken from lv2 example amp plugin
|
||||||
@ -172,6 +192,11 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
|
|||||||
// changed after the check that the midi-note is valid
|
// changed after the check that the midi-note is valid
|
||||||
pthread_mutex_lock(&drmr->load_mutex);
|
pthread_mutex_lock(&drmr->load_mutex);
|
||||||
if (nn >= 0 && nn < drmr->num_samples) {
|
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) {
|
||||||
|
printf("Fail at: %i for %f\n",nn,*drmr->gains[nn]);
|
||||||
|
}
|
||||||
drmr->samples[nn].active = 1;
|
drmr->samples[nn].active = 1;
|
||||||
drmr->samples[nn].offset = 0;
|
drmr->samples[nn].offset = 0;
|
||||||
}
|
}
|
||||||
@ -195,7 +220,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
|
|||||||
for (i = 0;i < drmr->num_samples;i++) {
|
for (i = 0;i < drmr->num_samples;i++) {
|
||||||
int pos,lim;
|
int pos,lim;
|
||||||
drmr_sample* cs = drmr->samples+i;
|
drmr_sample* cs = drmr->samples+i;
|
||||||
if (cs->active) {
|
if (cs->active && (cs->limit > 0)) {
|
||||||
float coef_right, coef_left;
|
float coef_right, coef_left;
|
||||||
if (i < 32) {
|
if (i < 32) {
|
||||||
float gain = DB_CO(*(drmr->gains[i]));
|
float gain = DB_CO(*(drmr->gains[i]));
|
||||||
@ -208,7 +233,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
|
|||||||
coef_right = coef_left = 1.0f;
|
coef_right = coef_left = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cs->info.channels == 1) { // play mono sample
|
if (cs->info->channels == 1) { // play mono sample
|
||||||
lim = (n_samples < (cs->limit - cs->offset)?n_samples:(cs->limit-cs->offset));
|
lim = (n_samples < (cs->limit - cs->offset)?n_samples:(cs->limit-cs->offset));
|
||||||
for(pos = 0;pos < lim;pos++) {
|
for(pos = 0;pos < lim;pos++) {
|
||||||
drmr->left[pos] += cs->data[cs->offset]*coef_left;
|
drmr->left[pos] += cs->data[cs->offset]*coef_left;
|
||||||
@ -216,7 +241,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
|
|||||||
cs->offset++;
|
cs->offset++;
|
||||||
}
|
}
|
||||||
} else { // play stereo sample
|
} else { // play stereo sample
|
||||||
lim = (cs->limit-cs->offset)/cs->info.channels;
|
lim = (cs->limit-cs->offset)/cs->info->channels;
|
||||||
if (lim > n_samples) lim = n_samples;
|
if (lim > n_samples) lim = n_samples;
|
||||||
for (pos=0;pos<lim;pos++) {
|
for (pos=0;pos<lim;pos++) {
|
||||||
drmr->left[pos] += cs->data[cs->offset++]*coef_left;
|
drmr->left[pos] += cs->data[cs->offset++]*coef_left;
|
||||||
|
14
drmr.h
14
drmr.h
@ -41,10 +41,21 @@ typedef struct {
|
|||||||
// libsndfile stuff
|
// libsndfile stuff
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SF_INFO info;
|
float min;
|
||||||
|
float max;
|
||||||
|
|
||||||
|
SF_INFO *info;
|
||||||
|
uint32_t limit;
|
||||||
|
float* data;
|
||||||
|
} drmr_layer;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SF_INFO *info;
|
||||||
char active;
|
char active;
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
uint32_t limit;
|
uint32_t limit;
|
||||||
|
uint32_t layer_count;
|
||||||
|
drmr_layer *layers;
|
||||||
float* data;
|
float* data;
|
||||||
} drmr_sample;
|
} drmr_sample;
|
||||||
|
|
||||||
@ -52,6 +63,7 @@ typedef struct {
|
|||||||
|
|
||||||
#define DRMR_URI "http://github.com/nicklan/drmr"
|
#define DRMR_URI "http://github.com/nicklan/drmr"
|
||||||
#define GAIN_MIN -60.0f
|
#define GAIN_MIN -60.0f
|
||||||
|
#define GAIN_MAX 6.0f
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
DRMR_MIDI = 0,
|
DRMR_MIDI = 0,
|
||||||
|
104
drmr_hydrogen.c
104
drmr_hydrogen.c
@ -38,9 +38,9 @@ static char* default_drumkit_locations[] = {
|
|||||||
|
|
||||||
struct instrument_layer {
|
struct instrument_layer {
|
||||||
char* filename;
|
char* filename;
|
||||||
int min;
|
float min;
|
||||||
int max;
|
float max;
|
||||||
int gain;
|
float gain;
|
||||||
struct instrument_layer *next;
|
struct instrument_layer *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ struct instrument_info {
|
|||||||
int id;
|
int id;
|
||||||
char* filename;
|
char* filename;
|
||||||
char* name;
|
char* name;
|
||||||
int gain;
|
float gain;
|
||||||
struct instrument_layer *layers;
|
struct instrument_layer *layers;
|
||||||
struct instrument_info *next;
|
struct instrument_info *next;
|
||||||
// maybe pan/vol/etc..
|
// maybe pan/vol/etc..
|
||||||
@ -124,11 +124,11 @@ endElement(void *userData, const char *name)
|
|||||||
if (!strcmp(name,"filename"))
|
if (!strcmp(name,"filename"))
|
||||||
info->cur_layer->filename = strdup(info->cur_buf);
|
info->cur_layer->filename = strdup(info->cur_buf);
|
||||||
if (!strcmp(name,"min"))
|
if (!strcmp(name,"min"))
|
||||||
info->cur_layer->min = atoi(info->cur_buf);
|
info->cur_layer->min = atof(info->cur_buf);
|
||||||
if (!strcmp(name,"max"))
|
if (!strcmp(name,"max"))
|
||||||
info->cur_layer->max = atoi(info->cur_buf);
|
info->cur_layer->max = atof(info->cur_buf);
|
||||||
if (!strcmp(name,"gain"))
|
if (!strcmp(name,"gain"))
|
||||||
info->cur_layer->gain = atoi(info->cur_buf);
|
info->cur_layer->gain = atof(info->cur_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->in_instrument) {
|
if (info->in_instrument) {
|
||||||
@ -138,7 +138,7 @@ endElement(void *userData, const char *name)
|
|||||||
info->counted_cur_inst = 1;
|
info->counted_cur_inst = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (!info->in_layer) {
|
||||||
if (!strcmp(name,"id"))
|
if (!strcmp(name,"id"))
|
||||||
info->cur_instrument->id = atoi(info->cur_buf);
|
info->cur_instrument->id = atoi(info->cur_buf);
|
||||||
if (!strcmp(name,"filename"))
|
if (!strcmp(name,"filename"))
|
||||||
@ -310,42 +310,53 @@ kits* scan_kits() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void free_samples(drmr_sample* samples, int num_samples) {
|
void free_samples(drmr_sample* samples, int num_samples) {
|
||||||
int i;
|
int i,j;
|
||||||
for (i=0;i<num_samples;i++)
|
for (i=0;i<num_samples;i++) {
|
||||||
if (samples[i].data)
|
if (samples[i].layer_count == 0) {
|
||||||
free(samples[i].data);
|
if (samples[i].info) free(samples[i].info);
|
||||||
|
if (samples[i].data) free(samples[i].data);
|
||||||
|
} else {
|
||||||
|
for (j = 0;j < samples[i].layer_count;j++) {
|
||||||
|
if (samples[i].layers[j].info) free(samples[i].layers[j].info);
|
||||||
|
if (samples[i].layers[j].data) free(samples[i].layers[j].data);
|
||||||
|
}
|
||||||
|
free(samples[i].layers);
|
||||||
|
}
|
||||||
|
}
|
||||||
free(samples);
|
free(samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
int load_sample(char* path, drmr_sample* samp) {
|
int load_sample(char* path, drmr_layer* layer) {
|
||||||
SNDFILE* sndf;
|
SNDFILE* sndf;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
//printf("Loading: %s\n",path);
|
//printf("Loading: %s\n",path);
|
||||||
|
|
||||||
samp->active = 0;
|
layer->info = malloc(sizeof(SF_INFO));
|
||||||
|
memset(layer->info,0,sizeof(SF_INFO));
|
||||||
memset(&(samp->info),0,sizeof(SF_INFO));
|
sndf = sf_open(path,SFM_READ,layer->info);
|
||||||
sndf = sf_open(path,SFM_READ,&(samp->info));
|
|
||||||
|
|
||||||
if (!sndf) {
|
if (!sndf) {
|
||||||
fprintf(stderr,"Failed to open sound file: %s - %s\n",path,sf_strerror(sndf));
|
fprintf(stderr,"Failed to open sound file: %s - %s\n",path,sf_strerror(sndf));
|
||||||
|
free(layer->info);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (samp->info.channels > 2) {
|
if (layer->info->channels > 2) {
|
||||||
fprintf(stderr, "File has too many channels. Can only handle mono/stereo samples\n");
|
fprintf(stderr, "File has too many channels. Can only handle mono/stereo samples\n");
|
||||||
|
free(layer->info);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
size = samp->info.frames * samp->info.channels;
|
size = layer->info->frames * layer->info->channels;
|
||||||
samp->limit = size;
|
layer->limit = size;
|
||||||
samp->data = malloc(size*sizeof(float));
|
layer->data = malloc(size*sizeof(float));
|
||||||
if (!samp->data) {
|
if (!layer->data) {
|
||||||
fprintf(stderr,"Failed to allocate sample memory for %s\n",path);
|
fprintf(stderr,"Failed to allocate sample memory for %s\n",path);
|
||||||
|
free(layer->info);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sf_read_float(sndf,samp->data,size);
|
sf_read_float(sndf,layer->data,size);
|
||||||
sf_close(sndf);
|
sf_close(sndf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -406,14 +417,53 @@ int load_hydrogen_kit(DrMr* drmr, char* path) {
|
|||||||
samples = malloc(num_inst*sizeof(drmr_sample));
|
samples = malloc(num_inst*sizeof(drmr_sample));
|
||||||
cur_i = kit_info.instruments;
|
cur_i = kit_info.instruments;
|
||||||
while(cur_i) {
|
while(cur_i) {
|
||||||
|
if (cur_i->filename) { // top level filename, just make one dummy layer
|
||||||
|
drmr_layer *layer = malloc(sizeof(drmr_layer));
|
||||||
|
layer->min = 0;
|
||||||
|
layer->max = 1;
|
||||||
snprintf(buf,BUFSIZ,"%s/%s",path,cur_i->filename);
|
snprintf(buf,BUFSIZ,"%s/%s",path,cur_i->filename);
|
||||||
if (load_sample(buf,samples+i)) {
|
if (load_sample(buf,layer)) {
|
||||||
fprintf(stderr,"Could not load sample: %s\n",buf);
|
fprintf(stderr,"Could not load sample: %s\n",buf);
|
||||||
samples[i].offset = 0;
|
|
||||||
// set limit to zero, will never try and play
|
// set limit to zero, will never try and play
|
||||||
samples[i].limit = 0;
|
layer->info = NULL;
|
||||||
samples[i].data = NULL;
|
layer->limit = 0;
|
||||||
|
layer->data = NULL;
|
||||||
}
|
}
|
||||||
|
samples[i].layer_count = 0;
|
||||||
|
samples[i].layers = NULL;
|
||||||
|
samples[i].offset = 0;
|
||||||
|
samples[i].info = layer->info;
|
||||||
|
samples[i].limit = layer->limit;
|
||||||
|
samples[i].data = layer->data;
|
||||||
|
free(layer);
|
||||||
|
} else {
|
||||||
|
int layer_count = 0;
|
||||||
|
int j;
|
||||||
|
struct instrument_layer *cur_l = cur_i->layers;
|
||||||
|
while(cur_l) {
|
||||||
|
layer_count++;
|
||||||
|
cur_l = cur_l->next;
|
||||||
|
}
|
||||||
|
samples[i].layer_count = layer_count;
|
||||||
|
samples[i].layers = malloc(sizeof(drmr_layer)*layer_count);
|
||||||
|
cur_l = cur_i->layers;
|
||||||
|
j = 0;
|
||||||
|
while(cur_l) {
|
||||||
|
snprintf(buf,BUFSIZ,"%s/%s",path,cur_l->filename);
|
||||||
|
if (load_sample(buf,samples[i].layers+j)) {
|
||||||
|
fprintf(stderr,"Could not load sample: %s\n",buf);
|
||||||
|
// set limit to zero, will never try and play
|
||||||
|
samples[i].layers[j].info = NULL;
|
||||||
|
samples[i].layers[j].limit = 0;
|
||||||
|
samples[i].layers[j].data = NULL;
|
||||||
|
}
|
||||||
|
samples[i].layers[j].min = cur_l->min;
|
||||||
|
samples[i].layers[j].max = cur_l->max;
|
||||||
|
j++;
|
||||||
|
cur_l = cur_l->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
samples[i].active = 0;
|
||||||
i++;
|
i++;
|
||||||
cur_i = cur_i->next;
|
cur_i = cur_i->next;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
kits* scan_kits();
|
kits* scan_kits();
|
||||||
void free_samples(drmr_sample* samples, int num_samples);
|
void free_samples(drmr_sample* samples, int num_samples);
|
||||||
int load_sample(char* path,drmr_sample* smp);
|
int load_sample(char* path,drmr_layer* layer);
|
||||||
int load_hydrogen_kit(DrMr* drmr, char* path);
|
int load_hydrogen_kit(DrMr* drmr, char* path);
|
||||||
|
|
||||||
#endif // DRMR_HYDRO_H
|
#endif // DRMR_HYDRO_H
|
||||||
|
111
drmr_ui.c
111
drmr_ui.c
@ -30,11 +30,14 @@ typedef struct {
|
|||||||
|
|
||||||
GtkWidget *drmr_widget;
|
GtkWidget *drmr_widget;
|
||||||
GtkTable *sample_table;
|
GtkTable *sample_table;
|
||||||
GtkComboBoxText *kit_combo;
|
GtkComboBox *kit_combo;
|
||||||
|
GtkListStore *kit_store;
|
||||||
GtkWidget** gain_sliders;
|
GtkWidget** gain_sliders;
|
||||||
GtkWidget** pan_sliders;
|
GtkWidget** pan_sliders;
|
||||||
int cols;
|
int cols;
|
||||||
|
|
||||||
|
int samples;
|
||||||
|
|
||||||
GQuark gain_quark, pan_quark;
|
GQuark gain_quark, pan_quark;
|
||||||
|
|
||||||
int curKit;
|
int curKit;
|
||||||
@ -55,15 +58,12 @@ static void pan_callback(GtkRange* range, gpointer data) {
|
|||||||
ui->write(ui->controller,pidx+DRMR_PAN_ONE,4,0,&pan);
|
ui->write(ui->controller,pidx+DRMR_PAN_ONE,4,0,&pan);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fill_sample_table(DrMrUi* ui, int samples) {
|
static void fill_sample_table(DrMrUi* ui, int samples, GtkWidget** gain_sliders, GtkWidget** pan_sliders) {
|
||||||
int row = 0;
|
int row = 0;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
int si;
|
int si;
|
||||||
gchar buf[32];;
|
gchar buf[32];;
|
||||||
GtkRequisition req;
|
|
||||||
int rows = (samples/ui->cols);
|
int rows = (samples/ui->cols);
|
||||||
req.width=500;
|
|
||||||
req.height=500;
|
|
||||||
gtk_table_resize(ui->sample_table,rows,ui->cols);
|
gtk_table_resize(ui->sample_table,rows,ui->cols);
|
||||||
for(si = 0;si<samples;si++) {
|
for(si = 0;si<samples;si++) {
|
||||||
GtkWidget *frame,*hbox,*gain_vbox,*pan_vbox;
|
GtkWidget *frame,*hbox,*gain_vbox,*pan_vbox;
|
||||||
@ -71,7 +71,7 @@ static void fill_sample_table(DrMrUi* ui, int samples) {
|
|||||||
GtkWidget* pan_slider;
|
GtkWidget* pan_slider;
|
||||||
GtkWidget* gain_label;
|
GtkWidget* gain_label;
|
||||||
GtkWidget* pan_label;
|
GtkWidget* pan_label;
|
||||||
sprintf(buf,"<b>Sample %i</b>",si);
|
sprintf(buf,"<b>Sample %i</b>",(si+1));
|
||||||
|
|
||||||
frame = gtk_frame_new(buf);
|
frame = gtk_frame_new(buf);
|
||||||
gtk_label_set_use_markup(GTK_LABEL(gtk_frame_get_label_widget(GTK_FRAME(frame))),true);
|
gtk_label_set_use_markup(GTK_LABEL(gtk_frame_get_label_widget(GTK_FRAME(frame))),true);
|
||||||
@ -81,8 +81,7 @@ static void fill_sample_table(DrMrUi* ui, int samples) {
|
|||||||
gain_slider = gtk_vscale_new_with_range(GAIN_MIN,6.0,1.0);
|
gain_slider = gtk_vscale_new_with_range(GAIN_MIN,6.0,1.0);
|
||||||
g_object_set_qdata (G_OBJECT(gain_slider),ui->gain_quark,GINT_TO_POINTER(si));
|
g_object_set_qdata (G_OBJECT(gain_slider),ui->gain_quark,GINT_TO_POINTER(si));
|
||||||
g_signal_connect(G_OBJECT(gain_slider),"value-changed",G_CALLBACK(gain_callback),ui);
|
g_signal_connect(G_OBJECT(gain_slider),"value-changed",G_CALLBACK(gain_callback),ui);
|
||||||
if (ui->gain_sliders)
|
if (gain_sliders) gain_sliders[si] = gain_slider;
|
||||||
ui->gain_sliders[si] = gain_slider;
|
|
||||||
gtk_range_set_inverted(GTK_RANGE(gain_slider),true);
|
gtk_range_set_inverted(GTK_RANGE(gain_slider),true);
|
||||||
gtk_scale_set_value_pos(GTK_SCALE(gain_slider),GTK_POS_BOTTOM);
|
gtk_scale_set_value_pos(GTK_SCALE(gain_slider),GTK_POS_BOTTOM);
|
||||||
gtk_range_set_value(GTK_RANGE(gain_slider),0.0);
|
gtk_range_set_value(GTK_RANGE(gain_slider),0.0);
|
||||||
@ -94,8 +93,7 @@ static void fill_sample_table(DrMrUi* ui, int samples) {
|
|||||||
gain_vbox = gtk_vbox_new(false,0);
|
gain_vbox = gtk_vbox_new(false,0);
|
||||||
|
|
||||||
pan_slider = gtk_hscale_new_with_range(-1.0,1.0,0.1);
|
pan_slider = gtk_hscale_new_with_range(-1.0,1.0,0.1);
|
||||||
if (ui->pan_sliders)
|
if (pan_sliders) pan_sliders[si] = pan_slider;
|
||||||
ui->pan_sliders[si] = pan_slider;
|
|
||||||
gtk_range_set_value(GTK_RANGE(pan_slider),0);
|
gtk_range_set_value(GTK_RANGE(pan_slider),0);
|
||||||
g_object_set_qdata (G_OBJECT(pan_slider),ui->pan_quark,GINT_TO_POINTER(si));
|
g_object_set_qdata (G_OBJECT(pan_slider),ui->pan_quark,GINT_TO_POINTER(si));
|
||||||
gtk_scale_add_mark(GTK_SCALE(pan_slider),0.0,GTK_POS_TOP,NULL);
|
gtk_scale_add_mark(GTK_SCALE(pan_slider),0.0,GTK_POS_TOP,NULL);
|
||||||
@ -103,7 +101,6 @@ static void fill_sample_table(DrMrUi* ui, int samples) {
|
|||||||
pan_label = gtk_label_new("Pan");
|
pan_label = gtk_label_new("Pan");
|
||||||
pan_vbox = gtk_vbox_new(false,0);
|
pan_vbox = gtk_vbox_new(false,0);
|
||||||
|
|
||||||
|
|
||||||
gtk_box_pack_start(GTK_BOX(gain_vbox),gain_slider,true,true,0);
|
gtk_box_pack_start(GTK_BOX(gain_vbox),gain_slider,true,true,0);
|
||||||
gtk_box_pack_start(GTK_BOX(gain_vbox),gain_label,false,false,0);
|
gtk_box_pack_start(GTK_BOX(gain_vbox),gain_label,false,false,0);
|
||||||
|
|
||||||
@ -115,8 +112,6 @@ static void fill_sample_table(DrMrUi* ui, int samples) {
|
|||||||
|
|
||||||
gtk_container_add(GTK_CONTAINER(frame),hbox);
|
gtk_container_add(GTK_CONTAINER(frame),hbox);
|
||||||
|
|
||||||
gtk_widget_size_request(frame,&req);
|
|
||||||
|
|
||||||
gtk_table_attach_defaults(ui->sample_table,frame,col,col+1,row,row+1);
|
gtk_table_attach_defaults(ui->sample_table,frame,col,col+1,row,row+1);
|
||||||
|
|
||||||
col++;
|
col++;
|
||||||
@ -131,50 +126,38 @@ void kit_combobox_changed(GtkComboBox* box, gpointer data) {
|
|||||||
DrMrUi* ui = (DrMrUi*)data;
|
DrMrUi* ui = (DrMrUi*)data;
|
||||||
gint new_kit = gtk_combo_box_get_active (GTK_COMBO_BOX(box));
|
gint new_kit = gtk_combo_box_get_active (GTK_COMBO_BOX(box));
|
||||||
float fkit = (float)new_kit;
|
float fkit = (float)new_kit;
|
||||||
if (ui->curKit >= 0 && ui->curKit != new_kit) {
|
if (ui->curKit != new_kit)
|
||||||
int samples = ui->kits->kits[new_kit].samples;
|
|
||||||
if (ui->sample_table)
|
|
||||||
gtk_widget_destroy(GTK_WIDGET(ui->sample_table));
|
|
||||||
ui->sample_table = GTK_TABLE(gtk_table_new(1,1,true));
|
|
||||||
ui->curKit = new_kit;
|
|
||||||
if (ui->gain_sliders) free(ui->gain_sliders);
|
|
||||||
if (ui->pan_sliders) free(ui->pan_sliders);
|
|
||||||
ui->gain_sliders = malloc(samples*sizeof(GtkWidget*));
|
|
||||||
ui->pan_sliders = malloc(samples*sizeof(GtkWidget*));
|
|
||||||
fill_sample_table(ui,samples);
|
|
||||||
gtk_box_pack_start(GTK_BOX(ui->drmr_widget),GTK_WIDGET(ui->sample_table),
|
|
||||||
true,true,5);
|
|
||||||
gtk_box_reorder_child(GTK_BOX(ui->drmr_widget),GTK_WIDGET(ui->sample_table),0);
|
|
||||||
gtk_widget_show_all(GTK_WIDGET(ui->sample_table));
|
|
||||||
ui->write(ui->controller,DRMR_KITNUM,4,0,&fkit);
|
ui->write(ui->controller,DRMR_KITNUM,4,0,&fkit);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void fill_kit_combo(GtkComboBoxText* combo, kits* kits) {
|
static void fill_kit_combo(GtkComboBox* combo, kits* kits) {
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<kits->num_kits;i++)
|
GtkTreeIter iter;
|
||||||
gtk_combo_box_text_append_text(combo,kits->kits[i].name);
|
GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(combo));
|
||||||
|
for (i=0;i<kits->num_kits;i++) {
|
||||||
|
gtk_list_store_append (store, &iter);
|
||||||
|
gtk_list_store_set(store, &iter, 0, kits->kits[i].name, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void build_drmr_ui(DrMrUi* ui) {
|
static void build_drmr_ui(DrMrUi* ui) {
|
||||||
GtkWidget *drmr_ui_widget;
|
GtkWidget *drmr_ui_widget;
|
||||||
GtkWidget *sample_table;
|
|
||||||
GtkWidget *kit_hbox, *kit_combo_box, *kit_label;
|
GtkWidget *kit_hbox, *kit_combo_box, *kit_label;
|
||||||
|
GtkCellRenderer *cell_rend;
|
||||||
|
|
||||||
drmr_ui_widget = gtk_vbox_new(false,0);
|
drmr_ui_widget = gtk_vbox_new(false,0);
|
||||||
g_object_set(drmr_ui_widget,"border-width",6,NULL);
|
g_object_set(drmr_ui_widget,"border-width",6,NULL);
|
||||||
|
|
||||||
sample_table = gtk_table_new(1,1,true);
|
ui->kit_store = gtk_list_store_new(1,G_TYPE_STRING);
|
||||||
gtk_table_set_col_spacings(GTK_TABLE(sample_table),5);
|
|
||||||
gtk_table_set_row_spacings(GTK_TABLE(sample_table),5);
|
|
||||||
|
|
||||||
gtk_box_pack_start(GTK_BOX(drmr_ui_widget),sample_table,
|
|
||||||
true,true,5);
|
|
||||||
|
|
||||||
kit_hbox = gtk_hbox_new(false,0);
|
kit_hbox = gtk_hbox_new(false,0);
|
||||||
kit_combo_box = gtk_combo_box_text_new();
|
kit_combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ui->kit_store));
|
||||||
kit_label = gtk_label_new("Kit:");
|
kit_label = gtk_label_new("Kit:");
|
||||||
|
|
||||||
|
cell_rend = gtk_cell_renderer_text_new();
|
||||||
|
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(kit_combo_box), cell_rend, true);
|
||||||
|
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(kit_combo_box), cell_rend,"text",0,NULL);
|
||||||
|
|
||||||
gtk_box_pack_start(GTK_BOX(kit_hbox),kit_label,
|
gtk_box_pack_start(GTK_BOX(kit_hbox),kit_label,
|
||||||
false,false,15);
|
false,false,15);
|
||||||
gtk_box_pack_start(GTK_BOX(kit_hbox),kit_combo_box,
|
gtk_box_pack_start(GTK_BOX(kit_hbox),kit_combo_box,
|
||||||
@ -183,8 +166,9 @@ static void build_drmr_ui(DrMrUi* ui) {
|
|||||||
false,false,5);
|
false,false,5);
|
||||||
|
|
||||||
ui->drmr_widget = drmr_ui_widget;
|
ui->drmr_widget = drmr_ui_widget;
|
||||||
ui->sample_table = GTK_TABLE(sample_table);
|
ui->sample_table = NULL;
|
||||||
ui->kit_combo = GTK_COMBO_BOX_TEXT(kit_combo_box);
|
ui->kit_combo = GTK_COMBO_BOX(kit_combo_box);
|
||||||
|
|
||||||
|
|
||||||
g_signal_connect(G_OBJECT(kit_combo_box),"changed",G_CALLBACK(kit_combobox_changed),ui);
|
g_signal_connect(G_OBJECT(kit_combo_box),"changed",G_CALLBACK(kit_combobox_changed),ui);
|
||||||
|
|
||||||
@ -206,6 +190,7 @@ instantiate(const LV2UI_Descriptor* descriptor,
|
|||||||
ui->controller = controller;
|
ui->controller = controller;
|
||||||
ui->drmr_widget = NULL;
|
ui->drmr_widget = NULL;
|
||||||
ui->curKit = -1;
|
ui->curKit = -1;
|
||||||
|
ui->samples = 0;
|
||||||
*widget = NULL;
|
*widget = NULL;
|
||||||
|
|
||||||
build_drmr_ui(ui);
|
build_drmr_ui(ui);
|
||||||
@ -227,6 +212,8 @@ instantiate(const LV2UI_Descriptor* descriptor,
|
|||||||
static void cleanup(LV2UI_Handle handle) {
|
static void cleanup(LV2UI_Handle handle) {
|
||||||
DrMrUi* ui = (DrMrUi*)handle;
|
DrMrUi* ui = (DrMrUi*)handle;
|
||||||
gtk_widget_destroy(ui->drmr_widget);
|
gtk_widget_destroy(ui->drmr_widget);
|
||||||
|
if (ui->gain_sliders) free(ui->gain_sliders);
|
||||||
|
if (ui->pan_sliders) free(ui->pan_sliders);
|
||||||
free(ui);
|
free(ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,31 +232,55 @@ port_event(LV2UI_Handle handle,
|
|||||||
else {
|
else {
|
||||||
int kit = (int)(*((float*)buffer));
|
int kit = (int)(*((float*)buffer));
|
||||||
int samples = ui->kits->kits[kit].samples;
|
int samples = ui->kits->kits[kit].samples;
|
||||||
|
GtkWidget** gain_sliders;
|
||||||
|
GtkWidget** pan_sliders;
|
||||||
|
if (ui->sample_table) {
|
||||||
|
ui->gain_sliders = NULL;
|
||||||
|
ui->pan_sliders = NULL;
|
||||||
|
gtk_widget_destroy(GTK_WIDGET(ui->sample_table));
|
||||||
|
}
|
||||||
|
ui->sample_table = GTK_TABLE(gtk_table_new(1,1,true));
|
||||||
|
gtk_table_set_col_spacings(ui->sample_table,5);
|
||||||
|
gtk_table_set_row_spacings(ui->sample_table,5);
|
||||||
ui->curKit = kit;
|
ui->curKit = kit;
|
||||||
ui->gain_sliders = malloc(samples*sizeof(GtkWidget*));
|
if (ui->gain_sliders) free(ui->gain_sliders);
|
||||||
ui->pan_sliders = malloc(samples*sizeof(GtkWidget*));
|
if (ui->pan_sliders) free(ui->pan_sliders);
|
||||||
fill_sample_table(ui,samples);
|
gain_sliders = malloc(samples*sizeof(GtkWidget*));
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX(ui->kit_combo), kit);
|
pan_sliders = malloc(samples*sizeof(GtkWidget*));
|
||||||
|
fill_sample_table(ui,samples,gain_sliders,pan_sliders);
|
||||||
|
gtk_box_pack_start(GTK_BOX(ui->drmr_widget),GTK_WIDGET(ui->sample_table),
|
||||||
|
true,true,5);
|
||||||
|
gtk_box_reorder_child(GTK_BOX(ui->drmr_widget),GTK_WIDGET(ui->sample_table),0);
|
||||||
gtk_widget_show_all(GTK_WIDGET(ui->sample_table));
|
gtk_widget_show_all(GTK_WIDGET(ui->sample_table));
|
||||||
|
gtk_combo_box_set_active(ui->kit_combo,kit);
|
||||||
|
ui->samples = samples;
|
||||||
|
ui->gain_sliders = gain_sliders;
|
||||||
|
ui->pan_sliders = pan_sliders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (index >= DRMR_GAIN_ONE &&
|
else if (index >= DRMR_GAIN_ONE &&
|
||||||
index <= DRMR_GAIN_SIXTEEN) {
|
index <= DRMR_GAIN_THIRTYTWO) {
|
||||||
if (ui->gain_sliders) {
|
if (ui->gain_sliders) {
|
||||||
float gain = *(float*)buffer;
|
float gain = *(float*)buffer;
|
||||||
GtkRange* range = GTK_RANGE(ui->gain_sliders[index-DRMR_GAIN_ONE]);
|
int idx = index-DRMR_GAIN_ONE;
|
||||||
|
if (idx < ui->samples) {
|
||||||
|
GtkRange* range = GTK_RANGE(ui->gain_sliders[idx]);
|
||||||
gtk_range_set_value(range,gain);
|
gtk_range_set_value(range,gain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (index >= DRMR_PAN_ONE &&
|
else if (index >= DRMR_PAN_ONE &&
|
||||||
index <= DRMR_PAN_SIXTEEN) {
|
index <= DRMR_PAN_THIRTYTWO) {
|
||||||
if (ui->pan_sliders) {
|
if (ui->pan_sliders) {
|
||||||
float pan = *(float*)buffer;
|
float pan = *(float*)buffer;
|
||||||
GtkRange* range = GTK_RANGE(ui->pan_sliders[index-DRMR_PAN_ONE]);
|
int idx = index-DRMR_PAN_ONE;
|
||||||
|
if (idx < ui->samples) {
|
||||||
|
GtkRange* range = GTK_RANGE(ui->pan_sliders[idx]);
|
||||||
gtk_range_set_value(range,pan);
|
gtk_range_set_value(range,pan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static const void*
|
static const void*
|
||||||
extension_data(const char* uri) {
|
extension_data(const char* uri) {
|
||||||
|
Loading…
Reference in New Issue
Block a user