Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 103 additions & 50 deletions SwitchTrigger4/src/switchtrigger4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@
#include <stdio.h>
#include <string.h>
#include <math.h>

#include <lv2.h>
#include<lv2/lv2plug.in/ns/ext/urid/urid.h>
#include<lv2/lv2plug.in/ns/ext/atom/util.h>
#include<lv2/lv2plug.in/ns/ext/atom/atom.h>
#include<lv2/lv2plug.in/ns/ext/state/state.h>

/**********************************************************************************************************************************************************/

#define PLUGIN_URI "http://moddevices.com/plugins/mod-devel/SwitchTrigger4"
enum {IN, OUT_1, OUT_2, OUT_3, OUT_4, CHANNEL1, CHANNEL2, CHANNEL3, CHANNEL4};
#define CHANNEL_URI "http://moddevices.com/plugins/mod-devel/SwitchTrigger4#channel"

enum {IN, OUT_1, OUT_2, OUT_3, OUT_4, CHANNEL1, CHANNEL2, CHANNEL3, CHANNEL4, CHANNEL_OUTPUT};

/**********************************************************************************************************************************************************/

static LV2_State_Status channel_save(LV2_Handle handle, LV2_State_Store_Function store, LV2_State_Handle state_handle, uint32_t flags, const LV2_Feature* const* features);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order to make things consistent, these 2 calls should go inside the class

static LV2_State_Status channel_restore(LV2_Handle handle, LV2_State_Retrieve_Function retrieve, LV2_State_Handle state_handle, uint32_t flags, const LV2_Feature* const* features);

class SwitchTrigger
{
public:
Expand All @@ -22,6 +32,8 @@ class SwitchTrigger
static void connect_port(LV2_Handle instance, uint32_t port, void *data);
static void run(LV2_Handle instance, uint32_t n_samples);
static void cleanup(LV2_Handle instance);
static LV2_State_Status channel_save(LV2_Handle handle, LV2_State_Store_Function store, LV2_State_Handle state_handle, uint32_t flags, const LV2_Feature* const* features);
static LV2_State_Status channel_restore(LV2_Handle handle, LV2_State_Retrieve_Function retrieve, LV2_State_Handle state_handle, uint32_t flags, const LV2_Feature* const* features);
static const void* extension_data(const char* uri);
int select_channel();
float *in;
Expand All @@ -33,7 +45,17 @@ class SwitchTrigger
float *channel2;
float *channel3;
float *channel4;
float *channel_output;
int channel;

LV2_URID_Map *urid_map;

struct urids
{
LV2_URID atom_Int;
LV2_URID switch_channel;
} URIDs;

};

/**********************************************************************************************************************************************************/
Expand Down Expand Up @@ -63,6 +85,23 @@ const LV2_Descriptor* lv2_descriptor(uint32_t index)
LV2_Handle SwitchTrigger::instantiate(const LV2_Descriptor* descriptor, double samplerate, const char* bundle_path, const LV2_Feature* const* features)
{
SwitchTrigger *plugin = new SwitchTrigger();

for(int i=0; features[i]; i++)
{
if(!strcmp(features[i]->URI,LV2_URID__map))
{
plugin->urid_map = (LV2_URID_Map *) features[i]->data;
if(plugin->urid_map)
{
plugin->URIDs.atom_Int = plugin->urid_map->map(plugin->urid_map->handle,LV2_ATOM__Int);
plugin->URIDs.switch_channel = plugin->urid_map->map(plugin->urid_map->handle,CHANNEL_URI);
break;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a break after handling urid map, as there is no need to check any more features afterwards

}

plugin->channel = 0;

return (LV2_Handle)plugin;
}

Expand Down Expand Up @@ -116,6 +155,9 @@ void SwitchTrigger::connect_port(LV2_Handle instance, uint32_t port, void *data)
case CHANNEL4:
plugin->channel4 = (float*) data;
break;
case CHANNEL_OUTPUT:
plugin->channel_output = (float*) data;
break;
}
}

Expand Down Expand Up @@ -157,66 +199,35 @@ void SwitchTrigger::run(LV2_Handle instance, uint32_t n_samples)
switch (channel)
{
case 0:
for ( uint32_t i = 0; i < n_samples; i++)
{
*out_1 = *in;
*out_2=0;
*out_3=0;
*out_4=0;
in++;
out_1++;
out_2++;
out_3++;
out_4++;
}
memcpy(out_1, in, sizeof(float)*n_samples);
memset(out_2, 0, sizeof(float)*n_samples);
memset(out_3, 0, sizeof(float)*n_samples);
memset(out_4, 0, sizeof(float)*n_samples);
break;

case 1:
for (uint32_t i = 0; i < n_samples; i++)
{
*out_1=0;
*out_2 = *in;
*out_3=0;
*out_4=0;
in++;
out_1++;
out_2++;
out_3++;
out_4++;
}
memcpy(out_2, in, sizeof(float)*n_samples);
memset(out_1, 0, sizeof(float)*n_samples);
memset(out_3, 0, sizeof(float)*n_samples);
memset(out_4, 0, sizeof(float)*n_samples);
break;

case 2:
for (uint32_t i = 0; i < n_samples; i++)
{
*out_1=0;
*out_2=0;
*out_3 = *in;
*out_4=0;
in++;
out_1++;
out_2++;
out_3++;
out_4++;
}
memcpy(out_3, in, sizeof(float)*n_samples);
memset(out_1, 0, sizeof(float)*n_samples);
memset(out_2, 0, sizeof(float)*n_samples);
memset(out_4, 0, sizeof(float)*n_samples);
break;

case 3:
for (uint32_t i = 0; i < n_samples; i++)
{
*out_1=0;
*out_2=0;
*out_3=0;
*out_4 = *in;
in++;
out_1++;
out_2++;
out_3++;
out_4++;
}
memcpy(out_4, in, sizeof(float)*n_samples);
memset(out_1, 0, sizeof(float)*n_samples);
memset(out_2, 0, sizeof(float)*n_samples);
memset(out_3, 0, sizeof(float)*n_samples);
break;

}

plugin->channel_output = (float*)&channel;
}

/**********************************************************************************************************************************************************/
Expand All @@ -228,7 +239,49 @@ void SwitchTrigger::cleanup(LV2_Handle instance)

/**********************************************************************************************************************************************************/

LV2_State_Status SwitchTrigger::channel_save(LV2_Handle handle, LV2_State_Store_Function store, LV2_State_Handle state_handle,
uint32_t flags, const LV2_Feature* const* features)
{
SwitchTrigger *plugin = (SwitchTrigger*)handle;

void *body = &plugin->channel;
store(state_handle, plugin->URIDs.switch_channel, body, sizeof(int),
plugin->URIDs.atom_Int, LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);

return LV2_STATE_SUCCESS;
}

/**********************************************************************************************************************************************************/

LV2_State_Status SwitchTrigger::channel_restore(LV2_Handle handle, LV2_State_Retrieve_Function retrieve, LV2_State_Handle state_handle,
uint32_t flags, const LV2_Feature* const* features)
{
SwitchTrigger *plugin = (SwitchTrigger*)handle;

size_t size;
uint32_t type;
uint32_t valflags;

const void* value = retrieve( state_handle, plugin->URIDs.switch_channel, &size, &type, &valflags);

if ((value) && (size == sizeof(int)) && (type == plugin->URIDs.switch_channel))
{
plugin->channel = *((int*)(&value));
}

return LV2_STATE_SUCCESS;
}

/**********************************************************************************************************************************************************/

const void* SwitchTrigger::extension_data(const char* uri)
{
static const LV2_State_Interface state = { channel_save, channel_restore };

if (!strcmp(uri, LV2_STATE__interface))
{
return &state;
}

return NULL;
}
17 changes: 17 additions & 0 deletions SwitchTrigger4/ttl/SwitchTrigger4.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
@prefix mod: <http://moddevices.com/ns/modgui#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix atom: <http://lv2plug.in/ns/ext/atom#> .
@prefix urid: <http://lv2plug.in/ns/ext/urid#> .
@prefix patch: <http://lv2plug.in/ns/ext/patch#> .
@prefix state: <http://lv2plug.in/ns/ext/state#> .
@prefix units: <http://lv2plug.in/ns/extensions/units#> .
@prefix plug: <http://moddevices.com/plugins/mod-devel/SwitchTrigger4#> .

<http://moddevices.com/plugins/mod-devel/SwitchTrigger4>
a lv2:Plugin, lv2:UtilityPlugin;
Expand Down Expand Up @@ -32,6 +38,9 @@ The switch trigger was designed to use the MOD on stage. By addressing each cont
footswitch, the musician can quickly access a desired chain of effects.
""";

lv2:requiredFeature urid:map ;
lv2:extensionData state:interface ;

doap:license <GPL>;

lv2:minorVersion 1;
Expand Down Expand Up @@ -111,7 +120,15 @@ lv2:port
lv2:default 0;
lv2:minimum 0;
lv2:maximum 1;
],
[
a lv2:ControlPort, lv2:OutputPort;
lv2:index 9;
lv2:symbol "channelOut";
lv2:minimum 0;
lv2:maximum 3;
];

mod:gui [
mod:resourcesDirectory <modgui>;
mod:iconTemplate <modgui/icon-switchtrigger4.html>;
Expand Down
2 changes: 1 addition & 1 deletion SwitchTrigger4/ttl/modgui/stylesheet-switchtrigger4.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
text-shadow:0 0 1px black;
text-transform:uppercase;
}
.mod-switchtrigger4 .mod-footswitch5 {
.mod-switchtrigger4 .mod-footswitch {
background-image:url(/resources/footswitch.png{{{ns}}});
background-position:bottom center;
background-repeat:no-repeat;
Expand Down