Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "lilv-0/lilv/lilv.h"
- #include "lv2/lv2plug.in/ns/ext/urid/urid.h"
- struct Ports {
- float in;
- float *out;
- };
- LV2_URID map_put(LV2_URID_Map_Handle handle, const char *str)
- {
- (void)handle;
- (void)str;
- return 0;
- }
- void set_port(const char *port_symbol, void *user_data, const void *value, uint32_t size, uint32_t type)
- {
- (void)size;
- (void)type;
- struct Ports *ports = user_data;
- printf("In set_port\n");
- if (!strcmp(port_symbol, "frequency")) {
- printf("setting frequency...\n");
- ports->in = *(float*)value;
- } else if (!strcmp(port_symbol, "out")) {
- printf("setting out...\n");
- ports->out = (float*)value;
- }
- }
- int main()
- {
- LV2_URID_Map map;
- map.handle = NULL;
- map.map = map_put;
- /*
- * Declare a sampling rate and an audio buffer size that this host
- * will deal with. The buffer size SHOULD always be a power of two.
- */
- const double sample_rate = 44100;
- const unsigned buffer_size = 4096;
- struct Ports ports;
- /*
- * Declare an output buffer that our plugin can write to.
- */
- ports.out = malloc(buffer_size * sizeof(float));
- LilvWorld *lworld = lilv_world_new();
- if (!lworld) {
- fprintf(stderr, "Failed to create a lilv world.\n");
- goto jmp_main_exit;
- }
- lilv_world_load_all(lworld);
- const LilvPlugins *plugs = lilv_world_get_all_plugins(lworld);
- /*
- * Look for the LV2 plugin that identifies itself by the globally unique
- * string "https://sine.synth.love"
- *
- * This does NOT connect to the internet or anything! It is simply a
- * globally unique string identifier for a plugin! The URI scheme is
- * merely convention! The plugin still has to be installed on your
- * system for this to work!
- */
- LilvNode *pluguri = lilv_new_uri(lworld, "https://sine.synth.love/");
- const LilvPlugin *plug = lilv_plugins_get_by_uri(plugs, pluguri);
- if (!plug) {
- fprintf(stderr, "Could not find the plugin.\n");
- goto jmp_main_exit;
- }
- LilvInstance *pluginst = lilv_plugin_instantiate(plug, sample_rate, NULL);
- if (!pluginst) {
- fprintf(stderr, "Failed to instantiate the plugin.\n");
- goto jmp_main_exit;
- }
- lilv_node_free(pluguri);
- LilvState *initstate = lilv_state_new_from_world(lworld, &map, pluguri);
- lilv_state_restore(initstate, pluginst, (LilvSetPortValueFunc)set_port, &ports, 0, NULL);
- /*float freq = 0.0;*/
- lilv_instance_connect_port(pluginst, 0, &ports.in);
- lilv_instance_connect_port(pluginst, 1, ports.out);
- lilv_instance_run(pluginst, buffer_size);
- printf("Successfully ran the plugin.\n");
- int i;
- for (i = 0; i < 32; ++i) {
- printf("%f\n", ports.out[i]);
- }
- lilv_instance_free(pluginst);
- jmp_main_exit:
- lilv_world_free(lworld);
- free(ports.out);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement