Added VST SDK support.
This commit is contained in:
parent
a1482ec110
commit
8e09f58944
25 changed files with 850 additions and 23 deletions
15
src/main.c
15
src/main.c
|
|
@ -13,6 +13,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include "xtc/xtc_plugin.h"
|
||||
#include "plugin/module_path.h"
|
||||
|
||||
/* Dependency inspection checks readable regular files, never plugin code or
|
||||
* audio contents. Escape untrusted path/label bytes in terminal output. */
|
||||
|
|
@ -32,6 +33,14 @@ static int readable_file(const char *path)
|
|||
struct stat info;
|
||||
return stat(path,&info) == 0 && S_ISREG(info.st_mode) && access(path,R_OK) == 0;
|
||||
}
|
||||
static int readable_plugin(const xtc_plugin_spec *spec)
|
||||
{
|
||||
char binary[512];
|
||||
if (spec->format == XTC_PLUGIN_BUILTIN) return 1;
|
||||
if (spec->format == XTC_PLUGIN_VST3)
|
||||
return xtc_plugin_module_path(spec->path,binary) == XTC_OK && readable_file(binary);
|
||||
return readable_file(spec->path);
|
||||
}
|
||||
static int inspect(const xtc_project *project, uint64_t version)
|
||||
{
|
||||
size_t tracks = 0, clips = 0, nodes = 0, edges = 0, i, missing = 0;
|
||||
|
|
@ -54,7 +63,7 @@ static int inspect(const xtc_project *project, uint64_t version)
|
|||
xtc_node_info node; xtc_plugin_spec spec;
|
||||
xtc_graph_get_node(graph,i,&node);
|
||||
if (xtc_graph_get_plugin(graph,node.id,&spec) == XTC_OK) {
|
||||
int available = spec.format == XTC_PLUGIN_BUILTIN || readable_file(spec.path);
|
||||
int available = readable_plugin(&spec);
|
||||
printf("%s node %zu ID %u descriptor %u ",xtc_plugin_format_name(spec.format),node.id,spec.unique_id,spec.index);
|
||||
if (spec.identifier[0]) { quoted(spec.identifier); putchar(' '); }
|
||||
quoted(spec.label); printf(": %s ",available ? "available" : "missing/unreadable");
|
||||
|
|
@ -66,7 +75,7 @@ static int inspect(const xtc_project *project, uint64_t version)
|
|||
xtc_track_info track; xtc_plugin_spec spec;
|
||||
xtc_project_get_track(project,i,&track);
|
||||
if (xtc_project_get_instrument(project,track.id,&spec) == XTC_OK) {
|
||||
int available = spec.format == XTC_PLUGIN_BUILTIN || readable_file(spec.path);
|
||||
int available = readable_plugin(&spec);
|
||||
printf("%s instrument track %" PRIu64 " descriptor %u ",xtc_plugin_format_name(spec.format),track.id,spec.index);
|
||||
quoted(spec.identifier); putchar(' '); quoted(spec.label);
|
||||
printf(": %s ",available ? "available" : "missing/unreadable"); quoted(spec.path); putchar('\n');
|
||||
|
|
@ -85,7 +94,7 @@ static int inspect(const xtc_project *project, uint64_t version)
|
|||
printf("Track %" PRIu64 " insert chain: %zu slots, output gain %.6g\n",track.id,chain.count,(double)chain.output_gain);
|
||||
for(slot=0;slot<chain.count;++slot) {
|
||||
const xtc_track_insert *insert=chain.slots+slot;const xtc_plugin_spec *spec=&insert->plugin;
|
||||
int available=spec->format==XTC_PLUGIN_BUILTIN || readable_file(spec->path);
|
||||
int available=readable_plugin(spec);
|
||||
printf("%s insert track %" PRIu64 " slot %zu %s wet %.6g ",xtc_plugin_format_name(spec->format),track.id,slot+1,insert->enabled ? "enabled" : "bypassed",(double)insert->wet);
|
||||
quoted(spec->label);printf(" %s: ",available ? "available" : "MISSING");quoted(spec->path);putchar('\n');
|
||||
if(!available)++missing;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "modern.h"
|
||||
#include "module_path.h"
|
||||
#include "builtin.h"
|
||||
#include <dlfcn.h>
|
||||
#include <math.h>
|
||||
|
|
@ -11,7 +12,7 @@ xtc_result xtc_ladspa_describe(const xtc_plugin_spec *, double, xtc_plugin_detai
|
|||
xtc_result xtc_ladspa_create(const xtc_plugin_spec *, double, size_t, xtc_ladspa_plugin **);
|
||||
void xtc_ladspa_destroy(xtc_ladspa_plugin *);
|
||||
xtc_result xtc_ladspa_process_at(xtc_ladspa_plugin *, const float *, float *, size_t, uint64_t);
|
||||
struct xtc_plugin { xtc_ladspa_plugin *ladspa; xtc_modern *modern; xtc_builtin *builtin; uint64_t next; };
|
||||
struct xtc_plugin { xtc_ladspa_plugin *ladspa; xtc_modern *modern; xtc_builtin *builtin; uint64_t next; unsigned int tempo; };
|
||||
const char *xtc_plugin_format_name(xtc_plugin_format f)
|
||||
{ static const char *names[] = {"LADSPA", "CLAP", "VST2", "VST3", "Internal"}; return f >= 0 && f <= XTC_PLUGIN_BUILTIN ? names[f] : "Unknown"; }
|
||||
xtc_result xtc_plugin_probe_format(xtc_plugin_format f, const char *path, unsigned int index, double rate, xtc_plugin_spec *out)
|
||||
|
|
@ -28,9 +29,12 @@ xtc_result xtc_plugin_probe_format(xtc_plugin_format f, const char *path, unsign
|
|||
xtc_result xtc_plugin_probe(const char *path, unsigned int index, double rate, xtc_plugin_spec *out)
|
||||
{
|
||||
void *module; xtc_plugin_format f = XTC_PLUGIN_LADSPA;
|
||||
char binary[512]; xtc_result r;
|
||||
if (!path || path[0] != '/' || strlen(path) >= 512) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (!strcmp(path,XTC_BUILTIN_PATH)) return xtc_plugin_probe_format(XTC_PLUGIN_BUILTIN,path,index,rate,out);
|
||||
module = dlopen(path,RTLD_NOW | RTLD_LOCAL);
|
||||
r = xtc_plugin_module_path(path,binary);
|
||||
if (r != XTC_OK) return r;
|
||||
module = dlopen(binary,RTLD_NOW | RTLD_LOCAL);
|
||||
if (!module) return XTC_ERR_NOT_FOUND;
|
||||
if (dlsym(module,"clap_entry")) f = XTC_PLUGIN_CLAP;
|
||||
else if (dlsym(module,"VSTPluginMain")) f = XTC_PLUGIN_VST2;
|
||||
|
|
@ -74,7 +78,7 @@ xtc_result xtc_plugin_create(const xtc_plugin_spec *s, double rate, size_t frame
|
|||
strcmp(actual.identifier,s->identifier) || strcmp(actual.label,s->label))) r = XTC_ERR_UNSUPPORTED;
|
||||
}
|
||||
if (r != XTC_OK) { xtc_plugin_destroy(p); return r; }
|
||||
*out = p; return XTC_OK;
|
||||
p->tempo = s->tempo; *out = p; return XTC_OK;
|
||||
}
|
||||
xtc_result xtc_plugin_process_stereo_at(xtc_plugin *p,const float *left,const float *right,float *out,float *out_right,size_t frames,uint64_t position)
|
||||
{
|
||||
|
|
@ -87,7 +91,7 @@ xtc_result xtc_plugin_process_at(xtc_plugin *p, const float *in, float *out, siz
|
|||
{
|
||||
xtc_result r;
|
||||
if (!p) return XTC_ERR_INVALID_ARGUMENT;
|
||||
r = p->builtin ? xtc_builtin_process(p->builtin,in,out,frames,position) : p->modern ? xtc_modern_process(p->modern,in,out,frames) : xtc_ladspa_process_at(p->ladspa,in,out,frames,position);
|
||||
r = p->builtin ? xtc_builtin_process(p->builtin,in,out,frames,position) : p->modern ? xtc_modern_process(p->modern,in,out,frames,position,p->tempo) : xtc_ladspa_process_at(p->ladspa,in,out,frames,position);
|
||||
if (r == XTC_OK) p->next = position <= UINT64_MAX-frames ? position+frames : 0;
|
||||
return r;
|
||||
}
|
||||
|
|
@ -95,7 +99,7 @@ xtc_result xtc_plugin_process_midi_at(xtc_plugin *p, const xtc_midi_event *event
|
|||
{
|
||||
xtc_result r;
|
||||
if (!p || position>UINT64_MAX-frames) return XTC_ERR_INVALID_ARGUMENT;
|
||||
r=p->builtin ? xtc_builtin_midi(p->builtin,events,count,out,frames,position) : p->modern ? xtc_modern_process_midi(p->modern,events,count,out,frames) : XTC_ERR_UNSUPPORTED;
|
||||
r=p->builtin ? xtc_builtin_midi(p->builtin,events,count,out,frames,position) : p->modern ? xtc_modern_process_midi(p->modern,events,count,out,frames,position,p->tempo) : XTC_ERR_UNSUPPORTED;
|
||||
if(r==XTC_OK)p->next=position+frames;
|
||||
return r;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "modern.h"
|
||||
#include "module_path.h"
|
||||
#include "vst2_abi.h"
|
||||
#include "xtc/xtc_dsp.h"
|
||||
#include "xtc/xtc_version.h"
|
||||
|
|
@ -86,8 +87,11 @@ static void module_release(module *m)
|
|||
}
|
||||
static xtc_result module_open(xtc_plugin_format format, const char *path, module **out)
|
||||
{
|
||||
void *handle = dlopen(path,RTLD_NOW | RTLD_LOCAL);
|
||||
module *m; xtc_result r = XTC_ERR_UNSUPPORTED;
|
||||
char binary[512]; void *handle;
|
||||
module *m; xtc_result r = xtc_plugin_module_path(path,binary);
|
||||
if (r != XTC_OK) return r;
|
||||
handle = dlopen(binary,RTLD_NOW | RTLD_LOCAL);
|
||||
r = XTC_ERR_UNSUPPORTED;
|
||||
if (!handle) return XTC_ERR_NOT_FOUND;
|
||||
for (m = modules; m; m = m->next) if (m->handle == handle && m->format == format) {
|
||||
++m->references; dlclose(handle); *out = m; return XTC_OK;
|
||||
|
|
@ -367,10 +371,11 @@ void xtc_modern_destroy(xtc_modern *p)
|
|||
if (p->factory && p->factory->lpVtbl && p->factory->lpVtbl->release) p->factory->lpVtbl->release(p->factory);
|
||||
module_release(p->module); free(p->input); free(p->output); free(p);
|
||||
}
|
||||
xtc_result xtc_modern_process(xtc_modern *p, const float *input, float *output, size_t frames)
|
||||
xtc_result xtc_modern_process(xtc_modern *p, const float *input, float *output, size_t frames, uint64_t position, unsigned int tempo)
|
||||
{
|
||||
size_t i; int ok = 1;
|
||||
if (!p || !output || frames > p->frames) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (!p || !output || frames > p->frames || position > INT64_MAX ||
|
||||
tempo < 20000 || tempo > 300000) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (!frames) return XTC_OK;
|
||||
if (__atomic_load_n(&p->restart,__ATOMIC_ACQUIRE)) { memset(output,0,frames*sizeof(float)); return XTC_ERR_INVALID_STATE; }
|
||||
for (i = 0; i < frames; ++i) p->input[i] = input ? xtc_dsp_finite(input[i]) : 0;
|
||||
|
|
@ -396,6 +401,15 @@ xtc_result xtc_modern_process(xtc_modern *p, const float *input, float *output,
|
|||
else {
|
||||
struct Steinberg_Vst_AudioBusBuffers in = {0}, out = {0};
|
||||
struct Steinberg_Vst_ProcessData data = {0};
|
||||
struct Steinberg_Vst_ProcessContext context = {0};
|
||||
context.state = Steinberg_Vst_ProcessContext_StatesAndFlags_kPlaying |
|
||||
Steinberg_Vst_ProcessContext_StatesAndFlags_kTempoValid |
|
||||
Steinberg_Vst_ProcessContext_StatesAndFlags_kProjectTimeMusicValid;
|
||||
context.sampleRate = p->rate;
|
||||
context.projectTimeSamples = (Steinberg_Vst_TSamples)position;
|
||||
context.tempo = (double)tempo / 1000.0;
|
||||
context.projectTimeMusic = (double)position / p->rate * context.tempo / 60.0;
|
||||
data.processContext = &context;
|
||||
in.numChannels = out.numChannels = 1;
|
||||
in.Steinberg_Vst_AudioBusBuffers_channelBuffers32 = &p->input;
|
||||
out.Steinberg_Vst_AudioBusBuffers_channelBuffers32 = &p->output;
|
||||
|
|
@ -443,10 +457,11 @@ static void vst_note(xtc_modern *p, unsigned int offset, unsigned int channel, u
|
|||
}
|
||||
p->keys[channel][pitch] = (unsigned char)on;
|
||||
}
|
||||
xtc_result xtc_modern_process_midi(xtc_modern *p, const xtc_midi_event *events, size_t count, float *output, size_t frames)
|
||||
xtc_result xtc_modern_process_midi(xtc_modern *p, const xtc_midi_event *events, size_t count, float *output, size_t frames, uint64_t position, unsigned int tempo)
|
||||
{
|
||||
size_t i; xtc_result r;
|
||||
if (!p || !p->instrument || !output || (count && !events) || count > XTC_MIDI_MAX_EVENTS || frames > p->frames) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (!p || !p->instrument || !output || (count && !events) || count > XTC_MIDI_MAX_EVENTS || frames > p->frames ||
|
||||
position > INT64_MAX || tempo < 20000 || tempo > 300000) return XTC_ERR_INVALID_ARGUMENT;
|
||||
for (i = 0; i < count; ++i) {
|
||||
const xtc_midi_event *e = events+i;
|
||||
if (e->offset >= frames || (i && e->offset < events[i-1].offset) || e->channel > 15 || e->pitch > 127 || e->velocity > 127 ||
|
||||
|
|
@ -482,6 +497,6 @@ xtc_result xtc_modern_process_midi(xtc_modern *p, const xtc_midi_event *events,
|
|||
for (k = 0; k < 128; ++k) if (p->keys[e->channel][k]) vst_note(p,e->offset,e->channel,k,0,0);
|
||||
}
|
||||
}
|
||||
r = xtc_modern_process(p,NULL,output,frames);
|
||||
r = xtc_modern_process(p,NULL,output,frames,position,tempo);
|
||||
p->event_count = 0; p->clap_count = 0; p->vst_count = 0; return r;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "xtc/xtc_plugin.h"
|
||||
typedef struct xtc_modern xtc_modern;
|
||||
xtc_result xtc_modern_open(xtc_plugin_format format, const char *path, unsigned int index, double rate, size_t frames, xtc_modern **out, xtc_plugin_spec *spec);
|
||||
xtc_result xtc_modern_process(xtc_modern *plugin, const float *input, float *output, size_t frames);
|
||||
xtc_result xtc_modern_process_midi(xtc_modern *plugin, const xtc_midi_event *events, size_t count, float *output, size_t frames);
|
||||
xtc_result xtc_modern_process(xtc_modern *plugin, const float *input, float *output, size_t frames, uint64_t position, unsigned int tempo);
|
||||
xtc_result xtc_modern_process_midi(xtc_modern *plugin, const xtc_midi_event *events, size_t count, float *output, size_t frames, uint64_t position, unsigned int tempo);
|
||||
void xtc_modern_destroy(xtc_modern *plugin);
|
||||
#endif
|
||||
|
|
|
|||
40
src/plugin/module_path.c
Normal file
40
src/plugin/module_path.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#include "module_path.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
xtc_result xtc_plugin_module_path(const char *path, char out[512])
|
||||
{
|
||||
struct stat status;
|
||||
char resolved[512];
|
||||
const char *name;
|
||||
size_t length, stem;
|
||||
int count;
|
||||
if (!path || !out || path[0] != '/' || (length = strlen(path)) >= sizeof(resolved))
|
||||
return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (stat(path, &status)) return XTC_ERR_NOT_FOUND;
|
||||
if (S_ISREG(status.st_mode)) { memcpy(out, path, length + 1); return XTC_OK; }
|
||||
if (!S_ISDIR(status.st_mode)) return XTC_ERR_UNSUPPORTED;
|
||||
name = strrchr(path, '/') + 1;
|
||||
stem = strlen(name);
|
||||
if (stem <= 5 || strcmp(name + stem - 5, ".vst3")) return XTC_ERR_UNSUPPORTED;
|
||||
#if defined(__x86_64__)
|
||||
#define XTC_VST3_ARCH "x86_64-linux"
|
||||
#elif defined(__aarch64__)
|
||||
#define XTC_VST3_ARCH "aarch64-linux"
|
||||
#elif defined(__i386__)
|
||||
#define XTC_VST3_ARCH "i386-linux"
|
||||
#elif defined(__arm__)
|
||||
#define XTC_VST3_ARCH "arm-linux"
|
||||
#else
|
||||
return XTC_ERR_UNSUPPORTED;
|
||||
#define XTC_VST3_ARCH "unsupported"
|
||||
#endif
|
||||
count = snprintf(resolved, sizeof(resolved), "%s/Contents/" XTC_VST3_ARCH "/%.*s.so",
|
||||
path, (int)(stem - 5), name);
|
||||
if (count < 0 || (size_t)count >= sizeof(resolved)) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (stat(resolved, &status)) return XTC_ERR_NOT_FOUND;
|
||||
if (!S_ISREG(status.st_mode)) return XTC_ERR_UNSUPPORTED;
|
||||
memcpy(out, resolved, (size_t)count + 1);
|
||||
return XTC_OK;
|
||||
}
|
||||
6
src/plugin/module_path.h
Normal file
6
src/plugin/module_path.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef XTC_PLUGIN_MODULE_PATH_H
|
||||
#define XTC_PLUGIN_MODULE_PATH_H
|
||||
#include "xtc/xtc.h"
|
||||
/* Control-thread Linux binary/bundle resolution. Preserves out on error. */
|
||||
xtc_result xtc_plugin_module_path(const char *path, char out[512]);
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue