Note that even if your code is C that doesn't mean you should be storing any state in global variables, because normally a plugin is expected to support multiple instances, yet there is only one copy of the globals.Alex_Longard wrote: ↑Fri Dec 06, 2019 11:06 pm kirsty roland
My code on pure C, not C++
For C code in plugin not use audioeffect->object.
GUI for VST plugin on pure C
DSP, Plugin and Host development discussion.
Moderator: KVR Moderators (Main)
GUI for VST plugin on pure C
2019-12-03T17:24:23+00:00
Hello all!
I'm writing a plugin to pure C.
I have a problem with the translation of some code with C++ for GUI.
Who can set an example to create a code for the plug-in window?
I know how to write code for Windows standalone programm, only plug I Do not know how and where to call a function createwindow ()
Here my example code in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <windows.h>
#include "aeffect.h"
#include "aeffectx.h"
__declspec(dllexport) AEffect* VSTPluginMain(audioMasterCallback audioMaster);
typedef struct ERect ERect;
typedef struct VstEvents VstEvents;
typedef struct VstMidiEvent VstMidiEvent;
typedef struct VstParameterProperties VstParameterProperties;
const int channels = 2;
const int NumParams = 2;
float sampleRate;
int blockSize;
float param_volume = 0.5f;
float mode_value;
float sample(float in)
{
return in * (param_volume * 4.0f);
}
void int2string(VstInt32 value, char *string) { sprintf(string, "%d", value); }
void float2string(float value, char *string) { sprintf(string, "%.2f", value); }
VstInt32 float2int(float number) { return (VstInt32)(1000.0f * number); }
void setSampleRate(float sampleRate) { sampleRate = sampleRate; }
void setBlockSize(VstInt32 blockSize) { blockSize = blockSize; }
VstInt32 processEvents(VstEvents* ev) {
for (int i = 0; i < ev->numEvents; i++) {
VstEvent* event = ev->events[i];
if (event->type == kVstMidiType) {
VstMidiEvent* midiEvent = (VstMidiEvent*) event;
VstInt8 status = midiEvent->midiData[0];
VstInt8 data1 = midiEvent->midiData[0];
VstInt8 data2 = midiEvent->midiData[0];
printf("MIDI: %02x %02x %02x\n", status, data1, data2); } }
return 0; }
enum ParamNames {
parameter1,
parameter2 };
bool getVendorString(char* ptr) {
strncpy((char*)ptr, "Alex Longard", kVstMaxVendorStrLen);
return true; }
void getParameterName(VstInt32 index, char* text) {
switch (index) {
case parameter1:
strncpy((char*)text, "Volume", kVstMaxParamStrLen);
break;
case parameter2:
strncpy((char*)text, "Mode", kVstMaxParamStrLen);
break; } }
void getParameterLabel(VstInt32 index, char *label) {
switch (index) {
case parameter1:
float2string(param_volume, label);
break;
case parameter2: switch (float2int(mode_value)) {
case 0:
strncpy((char*)label, "Left", kVstMaxParamStrLen);
break;
case 1:
strncpy((char*)label, "Center", kVstMaxParamStrLen);
break;
case 2:
strncpy((char*)label, "Right", kVstMaxParamStrLen);
break;
default:
strncpy((char*)label, "Empty", kVstMaxParamStrLen);
break; } } }
void getParameterDisplay (VstInt32 index, char* text) {
*text = 0; }
bool getParameterProperties(VstInt32 index, VstParameterProperties* p) {
return false; }
VstIntPtr Dispatcher(AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
{
VstIntPtr result = 0;
switch (opcode)
{
case effSetSampleRate:
setSampleRate(opt);
break;
case effSetBlockSize:
setBlockSize((VstInt32)value);
break;
case effProcessEvents:
result = processEvents((VstEvents*)ptr);
break;
case effGetPlugCategory:
result = kPlugCategEffect | kPlugCategAnalysis;
break;
case effGetVendorString:
result = getVendorString(ptr);
break;
case effGetEffectName:
strncpy((char*)ptr, "VST test plugin", kVstMaxEffectNameLen);
break;
case effGetProductString:
strncpy((char*)ptr, "magic plugin", kVstMaxEffectNameLen);
break;
case effGetParamName:
getParameterName(index, (char*)ptr);
break;
case effGetParamDisplay:
getParameterDisplay(index, (char*)ptr);
break;
case effGetParamLabel:
getParameterLabel(index, (char*)ptr);
break;
case effGetParameterProperties:
result = getParameterProperties(index, (VstParameterProperties*)ptr);
break;
case effClose:
free(effect);
free(ptr);
break;
default:
break;
}
return result;
}
void process32(AEffect* effect, float** inputs, float** outputs, VstInt32 sampleframes)
{
float* ileft = inputs[0]; float* iright = inputs[1];
float* oleft = outputs[0]; float* oright = outputs[1];
while (--sampleframes >= 0) {
(*oleft) = sample((*ileft));
(*oright) = sample((*iright));
ileft++; iright++;
oleft++; oright++; } }
void setparam(AEffect* effect, VstInt32 index, float value)
{
switch (index) {
case parameter1:
param_volume = value;
break;
case parameter2:
mode_value = value;
break;
} }
float getparam(AEffect* effect, VstInt32 index)
{
float result = 0;
switch (index) {
case parameter1:
result = param_volume;
break;
case parameter2:
result = mode_value;
break; }
return result;
}
AEffect* VSTPluginMain(audioMasterCallback audioMaster)
{
AEffect* effect = (AEffect*) malloc(sizeof(AEffect));
memset(effect, 0, sizeof(AEffect));
effect->magic = kEffectMagic;
effect->dispatcher = &Dispatcher;
effect->setParameter = &setparam;
effect->getParameter = &getparam;
effect->numParams = NumParams;
effect->numInputs = channels;
effect->numOutputs = channels;
effect->flags = effFlagsCanReplacing;
effect->processReplacing = &process32;
effect->uniqueID = 1987;
effect->version = 1;
effect->object = 0;
return effect;
}
Alex_Longard
https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=343177
- KVRAF
- 7865 posts since 12 Feb, 2006 from Helsinki, Finland
- Contact:
-
- KVRist
- Topic Starter
- 146 posts since 4 Dec, 2014 from Ukraine, Germany->Munich
Post by Alex_Longard » Sat Dec 07, 2019 2:33 pm
Hello Mystran!
Thanks for the recommendation!
This code only for testing VST coding in pure C
In future i write my small framework and will use structures and local blocks { ... } for isolate variables and some functions.
Thanks for the recommendation!
This code only for testing VST coding in pure C
In future i write my small framework and will use structures and local blocks { ... } for isolate variables and some functions.
Return to “DSP and Plugin Development”
Jump to
- The Main Forums
- ↳ KVR Studio Manager
- ↳ KVR Experts
- ↳ Getting Started (AKA What is the best...?)
- ↳ Instruments
- ↳ Effects
- ↳ Hosts & Applications (Sequencers, DAWs, Audio Editors, etc.)
- ↳ Guitars
- ↳ Mobile Apps and Hardware
- ↳ Soundware
- ↳ Samplers, Sampling & Sample Libraries
- ↳ Hardware (Instruments and Effects)
- ↳ Modular Synthesis
- ↳ Sound Design
- ↳ Production Techniques
- ↳ Music Theory
- ↳ Computer Setup and System Configuration
- ↳ DSP and Plugin Development
- ↳ DIY: Build it and they will come
- ↳ Music Cafe
- ↳ Sell & Buy (+Special Offers, Deals & Promos)
- ↳ KVR Developer Challenge 2023
- ↳ Everything Else (Music related)
- ↳ Off Topic
- ↳ Off Topic Classics
- Official Company Forums
- ↳ 2getheraudio
- ↳ accSone
- ↳ Acon Digital
- ↳ AcousticsampleS
- ↳ AcousModules
- ↳ Agitated State
- ↳ AIR Music Technology
- ↳ AMG
- ↳ Ample Sound
- ↳ Antares Audio Technologies
- ↳ Apisonic Labs
- ↳ apulSoft
- ↳ AriesCode
- ↳ Arts Acoustic
- ↳ Arturia
- ↳ audioD3CK
- ↳ Audjoo
- ↳ AudioSpillage
- ↳ Audiority
- ↳ Back In Time Records
- ↳ Best Service
- ↳ Big Tick
- ↳ Bitwig
- ↳ Controller Scripting
- ↳ Blue Cat Audio
- ↳ CFA-Sound
- ↳ Cherry Audio
- ↳ CWITEC
- ↳ Drumdrops
- ↳ Embertone
- ↳ energyXT
- ↳ Eventide
- ↳ Expert Sleepers
- ↳ forward audio
- ↳ Futucraft
- ↳ Future Audio Workshop
- ↳ FXpansion
- ↳ g200kg
- ↳ Harrison Mixbus
- ↳ HG Fortune
- ↳ Homegrown Sounds
- ↳ HoRNet Plugins
- ↳ Ilya Efimov Production
- ↳ Image Line
- ↳ Impact Soundworks
- ↳ Indiginus
- ↳ Insert Piz Here
- ↳ Inspire Audio
- ↳ Ju-X
- ↳ Kirk Hunter Studios
- ↳ Kirnu
- ↳ Kong Audio
- ↳ Krakli
- ↳ Krotos
- ↳ Kuassa
- ↳ KV331 Audio
- ↳ LennarDigital
- ↳ Les Productions Zvon
- ↳ Liqube Audio
- ↳ Livelab.dk
- ↳ Loomer
- ↳ LVC-Audio
- ↳ Maizesoft
- ↳ Manytone Music
- ↳ MeldaProduction
- ↳ Mellowmuse
- ↳ MIDIMood
- ↳ moForte
- ↳ Mozaic Beats
- ↳ mucoder
- ↳ Muon Software
- ↳ MusicDevelopments
- ↳ Tips & Tricks
- ↳ MusicLab
- ↳ MUTOOLS
- ↳ New Sonic Arts
- ↳ NUSofting
- ↳ Oli Larkin Plugins
- ↳ Orange Tree Samples
- ↳ OverTone DSP
- ↳ patchpool
- ↳ Photosounder
- ↳ PlugInGuru
- ↳ Polyverse Music
- ↳ Precisionsound
- ↳ Premier Sound Factory
- ↳ Psychic Modulation
- ↳ RaXnTraX
- ↳ Realitone
- ↳ Resonance-Sound
- ↳ Reveal Sound
- ↳ Roger Linn Design
- ↳ rs-met
- ↳ S3A: Spatial Audio
- ↳ SaschArt
- ↳ Signaldust
- ↳ Skytopia
- ↳ Smart Electronix
- ↳ solar3d-software
- ↳ sonible
- ↳ SonicBirth
- ↳ Sonic Reality / eSoundz.com
- ↳ Sonigen
- ↳ Soundemote
- ↳ Soundiron
- ↳ SPC Plugins
- ↳ Squaredheads
- ↳ Sugar Bytes
- ↳ TAL Software
- ↳ Tokyo Dawn Labs
- ↳ Tracktion
- ↳ u-he
- ↳ u-he Linux support
- ↳ United Plugins
- ↳ VAZ Synths
- ↳ Virharmonic
- ↳ Westgatesounds.net
- ↳ Wolfgang Palm
- ↳ xoxos
- ↳ ZynAddSubFX
- Site Stuff
- ↳ Site Stuff
- Archived Forums
- ↳ AlgoMusic
- ↳ easytoolz
- ↳ Elevayta
- ↳ Hollow Sun
- ↳ Kazrog
- ↳ LinPlug
- ↳ Muse Research and Development
- ↳ Shuriken
- ↳ SoHa Sound Design
- ↳ Soniccouture
- ↳ Topten Software
- ↳ Tweakbench
- ↳ Valhalla DSP
- ↳ CK Modules & VST
- ↳ Sennheiser AMBEO
- KVR Forum index
- All times are UTC
- Delete cookies