Control to set kit index
This commit is contained in:
parent
44cd116946
commit
a2e14e6652
2
Makefile
2
Makefile
@ -8,7 +8,7 @@ $(BUNDLE): manifest.ttl drmr.ttl drmr.so
|
|||||||
cp manifest.ttl drmr.ttl drmr.so $(BUNDLE)
|
cp manifest.ttl drmr.ttl drmr.so $(BUNDLE)
|
||||||
|
|
||||||
drmr.so: drmr.c drmr_hydrogen.c
|
drmr.so: drmr.c drmr_hydrogen.c
|
||||||
$(CC) -g -shared -fPIC -DPIC drmr.c drmr_hydrogen.c `pkg-config --cflags --libs lv2-plugin sndfile` -lexpat -o drmr.so
|
$(CC) -g -shared -fPIC -DPIC drmr.c drmr_hydrogen.c `pkg-config --cflags --libs lv2-plugin sndfile` -lexpat -lm -o drmr.so
|
||||||
|
|
||||||
install: $(BUNDLE)
|
install: $(BUNDLE)
|
||||||
mkdir -p $(INSTALL_DIR)
|
mkdir -p $(INSTALL_DIR)
|
||||||
|
46
drmr.c
46
drmr.c
@ -18,6 +18,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "drmr.h"
|
#include "drmr.h"
|
||||||
#include "drmr_hydrogen.h"
|
#include "drmr_hydrogen.h"
|
||||||
@ -55,6 +56,19 @@ int load_sample(char* path, drmr_sample* samp) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void* load_thread(void* arg) {
|
||||||
|
DrMr* drmr = (DrMr*)arg;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&drmr->load_mutex);
|
||||||
|
for(;;) {
|
||||||
|
pthread_cond_wait(&drmr->load_cond,
|
||||||
|
&drmr->load_mutex);
|
||||||
|
load_hydrogen_kit(drmr,drmr->kits->kits[drmr->curKit].path);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&drmr->load_mutex);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static LV2_Handle
|
static LV2_Handle
|
||||||
instantiate(const LV2_Descriptor* descriptor,
|
instantiate(const LV2_Descriptor* descriptor,
|
||||||
double rate,
|
double rate,
|
||||||
@ -65,6 +79,22 @@ instantiate(const LV2_Descriptor* descriptor,
|
|||||||
drmr->map = NULL;
|
drmr->map = NULL;
|
||||||
drmr->num_samples = 0;
|
drmr->num_samples = 0;
|
||||||
|
|
||||||
|
if (pthread_mutex_init(&drmr->load_mutex, 0)) {
|
||||||
|
fprintf(stderr, "Could not initialize load_mutex.\n");
|
||||||
|
free(drmr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (pthread_cond_init(&drmr->load_cond, 0)) {
|
||||||
|
fprintf(stderr, "Could not initialize load_cond.\n");
|
||||||
|
free(drmr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (pthread_create(&drmr->load_thread, 0, load_thread, drmr)) {
|
||||||
|
fprintf(stderr, "Could not initialize loading thread.\n");
|
||||||
|
free(drmr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Map midi uri
|
// Map midi uri
|
||||||
while(*features) {
|
while(*features) {
|
||||||
if (!strcmp((*features)->URI, LV2_URI_MAP_URI)) {
|
if (!strcmp((*features)->URI, LV2_URI_MAP_URI)) {
|
||||||
@ -89,13 +119,11 @@ instantiate(const LV2_Descriptor* descriptor,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
load_hydrogen_kit(drmr,drmr->kits->kits->path);
|
load_hydrogen_kit(drmr,drmr->kits->kits->path);
|
||||||
|
drmr->curKit = 0;
|
||||||
|
|
||||||
drmr->gains = malloc(16*sizeof(float*));
|
drmr->gains = malloc(16*sizeof(float*));
|
||||||
for(i = 0;i<16;i++) drmr->gains[i] = NULL;
|
for(i = 0;i<16;i++) drmr->gains[i] = NULL;
|
||||||
|
|
||||||
|
|
||||||
//load_hydrogen_kit(drmr,"/usr/share/hydrogen/data/drumkits/3355606kit/");
|
|
||||||
|
|
||||||
return (LV2_Handle)drmr;
|
return (LV2_Handle)drmr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +142,10 @@ connect_port(LV2_Handle instance,
|
|||||||
case DRMR_RIGHT:
|
case DRMR_RIGHT:
|
||||||
drmr->right = (float*)data;
|
drmr->right = (float*)data;
|
||||||
break;
|
break;
|
||||||
|
case DRMR_KITNUM:
|
||||||
|
if(data) drmr->kitReq = (float*)data;
|
||||||
|
printf("Connected kit\n");
|
||||||
|
break;
|
||||||
case DRMR_GAIN_ONE:
|
case DRMR_GAIN_ONE:
|
||||||
if (data) drmr->gains[0] = (float*)data;
|
if (data) drmr->gains[0] = (float*)data;
|
||||||
break;
|
break;
|
||||||
@ -171,10 +203,16 @@ static void activate(LV2_Handle instance) { }
|
|||||||
|
|
||||||
|
|
||||||
static void run(LV2_Handle instance, uint32_t n_samples) {
|
static void run(LV2_Handle instance, uint32_t n_samples) {
|
||||||
int i;
|
int i,kitInt;
|
||||||
char first_active, one_active;
|
char first_active, one_active;
|
||||||
DrMr* drmr = (DrMr*)instance;
|
DrMr* drmr = (DrMr*)instance;
|
||||||
|
|
||||||
|
kitInt = (int)floorf(*(drmr->kitReq));
|
||||||
|
if (kitInt != drmr->curKit) { // requested a new kit
|
||||||
|
drmr->curKit = kitInt;
|
||||||
|
pthread_cond_signal(&drmr->load_cond);
|
||||||
|
}
|
||||||
|
|
||||||
LV2_Event_Iterator eit;
|
LV2_Event_Iterator eit;
|
||||||
if (lv2_event_begin(&eit,drmr->midi_port)) { // if we have any events
|
if (lv2_event_begin(&eit,drmr->midi_port)) { // if we have any events
|
||||||
LV2_Event *cur_ev;
|
LV2_Event *cur_ev;
|
||||||
|
13
drmr.h
13
drmr.h
@ -19,11 +19,13 @@
|
|||||||
#ifndef DRMR_H
|
#ifndef DRMR_H
|
||||||
#define DRMR_H
|
#define DRMR_H
|
||||||
|
|
||||||
|
#include <sndfile.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#include "lv2/lv2plug.in/ns/lv2core/lv2.h"
|
#include "lv2/lv2plug.in/ns/lv2core/lv2.h"
|
||||||
#include "lv2/lv2plug.in/ns/ext/event/event.h"
|
#include "lv2/lv2plug.in/ns/ext/event/event.h"
|
||||||
#include "lv2/lv2plug.in/ns/ext/event/event-helpers.h"
|
#include "lv2/lv2plug.in/ns/ext/event/event-helpers.h"
|
||||||
#include "lv2/lv2plug.in/ns/ext/uri-map/uri-map.h"
|
#include "lv2/lv2plug.in/ns/ext/uri-map/uri-map.h"
|
||||||
#include <sndfile.h>
|
|
||||||
|
|
||||||
// drumkit scanned from a hydrogen xml file
|
// drumkit scanned from a hydrogen xml file
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -57,6 +59,7 @@ typedef enum {
|
|||||||
DRMR_MIDI = 0,
|
DRMR_MIDI = 0,
|
||||||
DRMR_LEFT,
|
DRMR_LEFT,
|
||||||
DRMR_RIGHT,
|
DRMR_RIGHT,
|
||||||
|
DRMR_KITNUM,
|
||||||
DRMR_GAIN_ONE,
|
DRMR_GAIN_ONE,
|
||||||
DRMR_GAIN_TWO,
|
DRMR_GAIN_TWO,
|
||||||
DRMR_GAIN_THREE,
|
DRMR_GAIN_THREE,
|
||||||
@ -84,7 +87,7 @@ typedef struct {
|
|||||||
|
|
||||||
// params
|
// params
|
||||||
float** gains;
|
float** gains;
|
||||||
|
float* kitReq;
|
||||||
|
|
||||||
// URIs
|
// URIs
|
||||||
LV2_URI_Map_Feature* map;
|
LV2_URI_Map_Feature* map;
|
||||||
@ -94,11 +97,17 @@ typedef struct {
|
|||||||
|
|
||||||
// Available kits
|
// Available kits
|
||||||
kits* kits;
|
kits* kits;
|
||||||
|
int curKit;
|
||||||
|
|
||||||
// Samples
|
// Samples
|
||||||
drmr_sample* samples;
|
drmr_sample* samples;
|
||||||
uint8_t num_samples;
|
uint8_t num_samples;
|
||||||
|
|
||||||
|
// loading thread stuff
|
||||||
|
pthread_mutex_t load_mutex;
|
||||||
|
pthread_cond_t load_cond;
|
||||||
|
pthread_t load_thread;
|
||||||
|
|
||||||
} DrMr;
|
} DrMr;
|
||||||
|
|
||||||
|
|
||||||
|
41
drmr.ttl
41
drmr.ttl
@ -39,6 +39,17 @@
|
|||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 3;
|
lv2:index 3;
|
||||||
|
lv2:symbol "kit_num";
|
||||||
|
lv2:name "Kit Index";
|
||||||
|
lv2:minimum 0;
|
||||||
|
lv2:maximum 50;
|
||||||
|
lv2:default 0;
|
||||||
|
lv2:portProperty lv2:integer;
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
|
lv2:index 4;
|
||||||
lv2:symbol "gain_one";
|
lv2:symbol "gain_one";
|
||||||
lv2:name "Sample One Gain";
|
lv2:name "Sample One Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -48,7 +59,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 4;
|
lv2:index 5;
|
||||||
lv2:symbol "gain_two";
|
lv2:symbol "gain_two";
|
||||||
lv2:name "Sample Two Gain";
|
lv2:name "Sample Two Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -58,7 +69,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 5;
|
lv2:index 6;
|
||||||
lv2:symbol "gain_three";
|
lv2:symbol "gain_three";
|
||||||
lv2:name "Sample Three Gain";
|
lv2:name "Sample Three Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -68,7 +79,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 6;
|
lv2:index 7;
|
||||||
lv2:symbol "gain_four";
|
lv2:symbol "gain_four";
|
||||||
lv2:name "Sample Four Gain";
|
lv2:name "Sample Four Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -78,7 +89,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 7;
|
lv2:index 8;
|
||||||
lv2:symbol "gain_five";
|
lv2:symbol "gain_five";
|
||||||
lv2:name "Sample Five Gain";
|
lv2:name "Sample Five Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -88,7 +99,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 8;
|
lv2:index 9;
|
||||||
lv2:symbol "gain_siz";
|
lv2:symbol "gain_siz";
|
||||||
lv2:name "Sample Siz Gain";
|
lv2:name "Sample Siz Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -98,7 +109,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 9;
|
lv2:index 10;
|
||||||
lv2:symbol "gain_seven";
|
lv2:symbol "gain_seven";
|
||||||
lv2:name "Sample Seven Gain";
|
lv2:name "Sample Seven Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -108,7 +119,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 10;
|
lv2:index 11;
|
||||||
lv2:symbol "gain_eight";
|
lv2:symbol "gain_eight";
|
||||||
lv2:name "Sample Eight Gain";
|
lv2:name "Sample Eight Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -118,7 +129,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 11;
|
lv2:index 12;
|
||||||
lv2:symbol "gain_nine";
|
lv2:symbol "gain_nine";
|
||||||
lv2:name "Sample Nine Gain";
|
lv2:name "Sample Nine Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -128,7 +139,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 12;
|
lv2:index 13;
|
||||||
lv2:symbol "gain_ten";
|
lv2:symbol "gain_ten";
|
||||||
lv2:name "Sample Ten Gain";
|
lv2:name "Sample Ten Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -138,7 +149,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 13;
|
lv2:index 14;
|
||||||
lv2:symbol "gain_eleven";
|
lv2:symbol "gain_eleven";
|
||||||
lv2:name "Sample Eleven Gain";
|
lv2:name "Sample Eleven Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -148,7 +159,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 14;
|
lv2:index 15;
|
||||||
lv2:symbol "gain_twelve";
|
lv2:symbol "gain_twelve";
|
||||||
lv2:name "Sample Twelve Gain";
|
lv2:name "Sample Twelve Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -158,7 +169,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 15;
|
lv2:index 16;
|
||||||
lv2:symbol "gain_thirteen";
|
lv2:symbol "gain_thirteen";
|
||||||
lv2:name "Sample Thirteen Gain";
|
lv2:name "Sample Thirteen Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -168,7 +179,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 16;
|
lv2:index 17;
|
||||||
lv2:symbol "gain_fourteen";
|
lv2:symbol "gain_fourteen";
|
||||||
lv2:name "Sample Fourteen Gain";
|
lv2:name "Sample Fourteen Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -178,7 +189,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 17;
|
lv2:index 18;
|
||||||
lv2:symbol "gain_fifteen";
|
lv2:symbol "gain_fifteen";
|
||||||
lv2:name "Sample Fifteen Gain";
|
lv2:name "Sample Fifteen Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
@ -188,7 +199,7 @@
|
|||||||
|
|
||||||
[
|
[
|
||||||
a lv2:ControlPort, lv2:InputPort;
|
a lv2:ControlPort, lv2:InputPort;
|
||||||
lv2:index 18;
|
lv2:index 19;
|
||||||
lv2:symbol "gain_sixteen";
|
lv2:symbol "gain_sixteen";
|
||||||
lv2:name "Sample Sixteen Gain";
|
lv2:name "Sample Sixteen Gain";
|
||||||
lv2:minimum 0.0;
|
lv2:minimum 0.0;
|
||||||
|
@ -249,6 +249,13 @@ kits* scan_kits() {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void free_samples(drmr_sample* samples, int num_samples) {
|
||||||
|
int i;
|
||||||
|
for (i=0;i<num_samples;i++)
|
||||||
|
free(samples[i].data);
|
||||||
|
free(samples);
|
||||||
|
}
|
||||||
|
|
||||||
int load_hydrogen_kit(DrMr* drmr, char* path) {
|
int load_hydrogen_kit(DrMr* drmr, char* path) {
|
||||||
char* fp_buf;
|
char* fp_buf;
|
||||||
FILE* file;
|
FILE* file;
|
||||||
@ -292,9 +299,9 @@ int load_hydrogen_kit(DrMr* drmr, char* path) {
|
|||||||
XML_ParserFree(parser);
|
XML_ParserFree(parser);
|
||||||
|
|
||||||
{
|
{
|
||||||
drmr_sample* samples;
|
drmr_sample *samples, *old_samples;
|
||||||
struct instrument_info * cur_i;
|
struct instrument_info * cur_i;
|
||||||
int i = 0, num_inst = 0;
|
int i = 0, num_inst = 0, old_scount;
|
||||||
printf("Read kit: %s\n",kit_info.name);
|
printf("Read kit: %s\n",kit_info.name);
|
||||||
cur_i = kit_info.instruments;
|
cur_i = kit_info.instruments;
|
||||||
while(cur_i) { // first count how many samples we have
|
while(cur_i) { // first count how many samples we have
|
||||||
@ -314,6 +321,8 @@ int load_hydrogen_kit(DrMr* drmr, char* path) {
|
|||||||
i++;
|
i++;
|
||||||
cur_i = cur_i->next;
|
cur_i = cur_i->next;
|
||||||
}
|
}
|
||||||
|
old_samples = drmr->samples;
|
||||||
|
old_scount = drmr->num_samples;
|
||||||
if (num_inst > drmr->num_samples) {
|
if (num_inst > drmr->num_samples) {
|
||||||
// we have more, so we can safely swap our sample list in before updating num_samples
|
// we have more, so we can safely swap our sample list in before updating num_samples
|
||||||
drmr->samples = samples;
|
drmr->samples = samples;
|
||||||
@ -323,6 +332,7 @@ int load_hydrogen_kit(DrMr* drmr, char* path) {
|
|||||||
drmr->num_samples = num_inst;
|
drmr->num_samples = num_inst;
|
||||||
drmr->samples = samples;
|
drmr->samples = samples;
|
||||||
}
|
}
|
||||||
|
if (old_samples) free_samples(old_samples,old_scount);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user