-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvopamo.c
115 lines (98 loc) · 2.86 KB
/
vopamo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* vopamo.c
*
* Copyright (C) 2016 - Yann Collette
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "helper.h"
#include "vopamo.h"
#define VOPA_VOL_DIR 100.0
void runVOPA_MO(LV2_Handle arg, uint32_t nframes) {
VOPA_MO* so = (VOPA_MO*)arg;
float* outbuffer = so->output;
const float* inbuffer = so->input;
LV2_ATOM_SEQUENCE_FOREACH(so->MidiIn, ev) {
if (ev->body.type == so->midi_MidiEvent) {
const uint8_t* const msg = (const uint8_t*)(ev + 1);
if ((lv2_midi_message_type(msg) & MIDI_COMMANDMASK)==MIDI_CONTROL) {
switch(msg[1]) {
case 7:
so->volume = msg[2];
break;
}
}
}
}
float vol = so->volume / VOPA_VOL_DIR;
for(int i = 0; i < nframes; i++) {
outbuffer[i] = inbuffer[i] * vol;
}
}
LV2_Handle instantiateVOPA_MO(const LV2_Descriptor *descriptor,double s_rate, const char *path,const LV2_Feature * const* features) {
LV2_URID_Map* map = NULL;
for (int i = 0; features[i]; ++i) {
if (!strcmp(features[i]->URI, LV2_URID__map)) {
map = (LV2_URID_Map*)features[i]->data;
break;
}
}
if (!map) {
return NULL;
}
VOPA_MO* self = (VOPA_MO*)calloc(1, sizeof(VOPA_MO));
self->map = map;
self->midi_MidiEvent = map->map(map->handle, LV2_MIDI__MidiEvent);
self->volume = 100;
return self;
}
void cleanupVOPA_MO(LV2_Handle instance) {
free(instance);
}
void connectPortVOPA_MO(LV2_Handle instance, uint32_t port, void *data_location) {
VOPA_MO* so = (VOPA_MO*) instance;
switch(port) {
case PORT_VOPA_OUTPUT:
so->output = data_location;
break;
case PORT_VOPA_INPUT:
so->input = data_location;
break;
case PORT_VOPA_MIDI:
so->MidiIn = (const LV2_Atom_Sequence*)data_location;
break;
default:
fputs("Warning, unconnected port!\n",stderr);
}
}
static const LV2_Descriptor descriptorVOPA_MO = {
.URI = "https://github.com/ycollet/vopa:VoPaMo",
.instantiate = instantiateVOPA_MO,
.connect_port = connectPortVOPA_MO,
.activate = NULL,
.run = runVOPA_MO,
.deactivate = NULL,
.cleanup = cleanupVOPA_MO,
.extension_data = NULL,
};
LV2_SYMBOL_EXPORT
const LV2_Descriptor *lv2_descriptor(uint32_t index)
{
switch (index) {
case 0:
return &descriptorVOPA_MO;
default:
return NULL;
}
}