It is currently Sat Sep 26, 2020 12:29 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 43 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: VST SDK plugin example
PostPosted: Tue Apr 16, 2019 8:22 am 
Offline
User
User

Joined: Mon Dec 24, 2012 9:07 am
Posts: 40
Location: Ukraine, Donetck
Hello all!
I wrote a small example that works on Windows x86 / x64. I only tested at Cockos Reaper, in other DAWs it should work just as well.
Thanks a lot for helping Infratec and fixing my a few bugs with pointers.

There all translated basic include files and example VST plugin (no GUI).
https://www.dropbox.com/sh/j0vun0sg751f ... drVEa?dl=0

update link:
29.12.2019 vst window test.


Code:
EnableExplicit

Global channels.l = 2
Global  paramvolume.f = 1.0

PrototypeC.i DispatcherProc(*effect, opcode.l, index.l, Value.i, *ptr, opt.f)
PrototypeC ProcessProc(*effect, *inputs.Float, *outputs.Float, sampleframes.l)
PrototypeC SetParameterProc(*effect, index.l, parameter.f)
PrototypeC.f GetParameterProc(*effect, index.l)
PrototypeC ProcessReplacingProc(*effect, *inputs.Float, *outputs.Float, sampleframes.l)
PrototypeC ProcessDoubleReplacingProc(*effect, *inputs.Double, *outputs.Double, sampleframes.l)

Structure AEffect Align #PB_Structure_AlignC
magic.l
dispatcher.DispatcherProc
process.ProcessProc
setParameter.SetParameterProc
getParameter.GetParameterProc
numPrograms.l
numParams.l
numInputs.l
numOutputs.l
flags.l
*resvd1
*resvd2
initialDelay.l
realQualities.l
offQualities.l
ioRatio.f
*Object
*user
uniqueID.l
version.l
processReplacing.ProcessReplacingProc
processDoubleReplacing.ProcessDoubleReplacingProc
Array future.b(56)
EndStructure

; constants
#kEffectMagic = $56737450

#effFlagsCanReplacing = 16

#kPlugCategEffect = 1
#kPlugCategSynth = 2
#kPlugCategAnalysis = 3

; AEffect constants
#effClose = 1
#effGetParamLabel = 6
#effGetParamDisplay = 7
#effGetParamName = 8
#effSetSampleRate = 10
#effSetBlockSize = 11;
#effGetPlugCategory = 35
#effGetEffectName = 45
#effGetVendorString = 47
#effGetProductString = 48
#effGetVendorVersion = 49

; string sizes
#kVstMaxParamStrLen = 8
#kVstMaxVendorStrLen = 64
#kVstMaxProductStrLen = 64
#kVstMaxEffectNameLen = 32
 
; other procedures
Procedure getParameterName(index.l, *text)
Select index
Case 0
PokeS(*text, "Volume", #kVstMaxParamStrLen, #PB_Ascii)
EndSelect
EndProcedure

Procedure getParameterDisplay(index.l, *text)
Select index
Case 0
PokeS(*text, StrF(paramvolume, 4), 4, #PB_Ascii)
EndSelect
EndProcedure


; procedures for VST sdk
ProcedureC.i DispatcherProc(*d.AEffect, opcode.l, index.l, Value.i, *ptr, opt.f)
Protected result.i
Select opcode
Case #effClose
FreeStructure(*d)
Case #effGetParamDisplay
 getParameterDisplay(index, *ptr)
Case #effGetParamName
getParameterName(index, *ptr)
Case #effGetPlugCategory
result = #kPlugCategEffect | #kPlugCategAnalysis
Case #effGetEffectName
PokeS(*ptr, "test plugin", #kVstMaxEffectNameLen, #PB_Ascii)
Case #effGetVendorString
PokeS(*ptr, "Alex Longard", #kVstMaxVendorStrLen, #PB_Ascii)
Default
EndSelect
ProcedureReturn result
EndProcedure

ProcedureC ProcessReplacingProc(*ap.AEffect, *inputs, *outputs, sampleframes.l)
Protected *In1, *In2, *Out1, *Out2, i.l
*In1 = PeekI(*inputs)
*Out1 = PeekI(*outputs)
If channels = 2
*In2 = PeekI(*inputs + SizeOf(integer))
*Out2 = PeekI(*outputs + SizeOf(integer))
EndIf
For i = 0 To sampleframes - 1
PokeF(*Out1 + i * SizeOf(float), PeekF(*In1 + i * SizeOf(float)) * paramvolume)
If channels = 2
PokeF(*Out2 + i * SizeOf(float), PeekF(*In2 + i * SizeOf(float)) * paramvolume)
EndIf
Next i
EndProcedure

ProcedureC ProcessDoubleReplacingProc(*ap.AEffect, *inputs, *outputs, sampleframes.l)

EndProcedure

ProcedureC SetParameterProc(*asp.AEffect, index.l, value.f)
paramvolume = value
EndProcedure

ProcedureC.f GetParameterProc(*agp.AEffect, index.l)
ProcedureReturn paramvolume
EndProcedure

ProcedureCDLL VSTPluginMain(*audioMaster)
Protected *Aef.AEffect = AllocateStructure(AEffect)
*aef\magic = #kEffectMagic
*aef\dispatcher = @DispatcherProc()
*aef\setParameter = @SetParameterProc()
*aef\getParameter = @GetParameterProc()
*aef\numParams = 1
*aef\numInputs = channels
*aef\numOutputs = channels
*aef\flags = #effFlagsCanReplacing
*aef\processReplacing = @ProcessReplacingProc()
; *aef\processDoubleReplacing = @ProcessDoubleReplacingProc()
*aef\uniqueID = 02081987
*aef\version = 1
*aef\Object = 0
ProcedureReturn *aef
EndProcedure

_________________
Sory my bad english


Last edited by Aleks_Longard on Sun Dec 29, 2019 9:41 am, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Tue Apr 16, 2019 9:52 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14090
Location: France
Nice stuff !


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Tue Apr 16, 2019 11:15 am 
Offline
User
User

Joined: Wed Feb 26, 2014 3:16 pm
Posts: 76
@Aleks_Longard.

Hi, I've been doing this stuff for over 10 years now in PureBasic.
If you have any questions, don't hesitate to ask!
I'm glad I am not the only one anymore.

You can see my plugins here :
http://www.raxntrax.com

Beware though, there's a bug in the threadsave library of PureBasic.
So if you want to make stable plugins don't use threadsafety, you'll need to protect all your lists/maps/strings all by your own code.
It's an old bug that appears on closing the plugin only in some hosts (cantabile/tracktion/mulab/flstudio).
You'll get an access violation. Probably a threadsave ressource not cleaned up properly.

It has been mentioned a couple of times here on the forum, but still there seems to be no solution...

Success!
Eric


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Tue Apr 16, 2019 11:38 am 
Offline
User
User

Joined: Mon Dec 24, 2012 9:07 am
Posts: 40
Location: Ukraine, Donetck
Hello Fred, thank you!!!

Hello Sq4, thanks, i am C++ developer and write some plugins with VST SDK and Reaper SDK on C++.
I very love Purebasic, and only recently I had time to rewrite some my old codes on Purebasic, since in C++ I don’t like some things related to classes and silly wrappers for simple functions.
Cheers!

_________________
Sory my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Tue Apr 16, 2019 11:44 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Oct 16, 2009 10:12 am
Posts: 681
Location: BE
Aleks_Longard wrote:
...
If anyone is interested in this, I can translate the full VST SDK.

I'm realy interested in this !
This might give me a new start on some of my own smaller midi-projects.
I always found these VST-C sources to difficult to my knowledge,
so I realy hope you will continu your work.

Yet, some more info on 'how to use this' would help.
(DAW's and VST-host's I use here, are Logic on OSX and still one on XP too, Cantabile, LMMS).

Thanks and keep up the good work.

_________________
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Tue Apr 16, 2019 11:59 am 
Offline
User
User

Joined: Mon Dec 24, 2012 9:07 am
Posts: 40
Location: Ukraine, Donetck
Hello Joris,
I can't try this in Logic, since I don't have a Mac os, and vst plug's for Mac is different from Windows plugins.
I will try to find information for vst on a Mac, as long as I can translate all includes "aeffect.h, aeffectx.h" which are essential for plugins for Windows DAWs.
Cheers!

_________________
Sory my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Tue Apr 16, 2019 5:44 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jun 24, 2006 3:29 am
Posts: 258
Location: Edinburgh, Scotland.
Really great stuff Aleks. PLEASE continue :D

Compiled and loaded in daw (REAPER also) as vst dll without problems. It's a really nice basic starting framework.

How about simple ASIO vst host next? :DDD (Just kidding about that one ;) Or...? :D )

Thank you very much for this.

sq4: Your music software stuff has always highly impressed me. Very good work mate.

_________________
Proud supporter of PB! * Musician * C64/6502 Freak


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Tue Apr 16, 2019 6:59 pm 
Offline
User
User

Joined: Wed Feb 26, 2014 3:16 pm
Posts: 76
oreopa wrote:
How about simple ASIO vst host next? :DDD (Just kidding about that one ;) Or...? :D )


If you search for Asio you'll find an older topic of mine under my previous member name "eriansa".
I remember I had to write assembler for the x86 version due to calling conventions. Pure coding hell...

Btw thanks for your nice comment on my plugins. :D


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Wed Apr 17, 2019 7:27 am 
Offline
User
User

Joined: Mon Dec 24, 2012 9:07 am
Posts: 40
Location: Ukraine, Donetck
Oreopa
I not see problem trying to write Asio / VST host :)
AudioMasterCallback it's same as AEffectDispatcherProc function.
I will translate sdk and try to write something.
I already wrote a simple host on pure C to test my ideas for VST and Reaper))))
Cheers!

_________________
Sory my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Wed Apr 17, 2019 8:17 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Oct 16, 2009 10:12 am
Posts: 681
Location: BE
@Aleks_Longard
I also have a pc with XP still, but how do I have to use your code on that, isn't clear ?
If I run it nothing happens or appears ?
Somewhere the source looks like a DLL, so then it would be VST itself not a VST-host...
Sorry, for my stupidity about this.

_________________
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Wed Apr 17, 2019 9:16 am 
Offline
User
User

Joined: Mon Dec 24, 2012 9:07 am
Posts: 40
Location: Ukraine, Donetck
Hello Joris!
See this:
https://www.dropbox.com/sh/j0vun0sg751f ... drVEa?dl=0

I compile dll for x64 and x86 Windows.
And example.pb in folder.

I while not have time for write vsthost and some examples.

_________________
Sory my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Wed Apr 17, 2019 11:13 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Oct 16, 2009 10:12 am
Posts: 681
Location: BE
@Aleks_Longard,
I can open it here in Cantabile Lite (a VST host) and LMMS (a DAW).
In Cantabile I get some volume-controller shown, LMMS loads the VST but nothing is shown.
Logic (on XP) didn't work, yet I must retry as I might have done something wrong there.

Thanks

_________________
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Wed Apr 17, 2019 11:29 am 
Offline
User
User

Joined: Mon Dec 24, 2012 9:07 am
Posts: 40
Location: Ukraine, Donetck
Joris,
this example not have GUI, volume slider accessible as automatable control.
In Reaper DAW this shows in alternative GUI, which make Reaper for nongui plugins.
I can not have others DAWs for testing.

_________________
Sory my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Thu Apr 18, 2019 8:30 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Oct 16, 2009 10:12 am
Posts: 681
Location: BE
Aleks_Longard wrote:
I can not have others DAWs for testing.
Ok.
If you need some testings ... I have 4 DAW's available.
(LMMS is a free one and opensource.)

_________________
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.


Top
 Profile  
Reply with quote  
 Post subject: Re: VST SDK plugin example
PostPosted: Thu Apr 18, 2019 10:13 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 11, 2006 12:07 am
Posts: 566
Location: Near Hamburg
in adobe audition the x64 plugin example works great.
maybe in future i will dive into this vst stuff. it sounds amazing to write a vst plugin in purebasic.

Sent via mobile phone

_________________
PB 5.72 x64, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 52y
"Happiness is a pet." | "Never run a changing system!"


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 43 posts ]  Go to page 1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye