need help with VST lib

Just starting out? Need help? Post your questions and find answers here.
cherri123
User
User
Posts: 32
Joined: Tue Apr 13, 2010 5:39 am

need help with VST lib

Post by cherri123 »

Hi all.
Can anybody worked with the interface VST?
My problem is that I can't get the dimensions plug-in with the help of effEditGetRect (in the specification of the value 13).
There is a structure defining the values of sizes.

in C

Code: Select all

struct ERect
{
	short top;
	short left;
	short bottom;
	short right;
};
in PB

Code: Select all

CompilerIf Defined(ERect,#PB_Structure) = 0
Structure ERect

	top.w;
	left.w;
	bottom.w;
	right.w;
	
EndStructure
CompilerEndIf


Procedure dispatcher(opCode.l, index.l, value.l, *ptr, opt.f)
 ;Result = #PB_ProcessPureBasicEvents 
  Result=CallCFunctionFast(*myAEffect\ptrDispatcher, *myAEffect,opCode, index, value, *ptr, opt)


	ProcedureReturn Result;
EndProcedure

res=Dispatcher(#effEditGetRect,0,0,rect.ERect,0);
Debug "rect resultate>>>"+Str(res)

If res=1
  Debug "top "+Str(Rect\top)
  Debug "left "+Str(Rect\left)
  Debug "bottom "+Str(Rect\bottom)
  Debug "right "+Str(Rect\right)

Else
  Debug "error"
EndIf
can I do something wrong
User avatar
idle
Always Here
Always Here
Posts: 5926
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: need help with VST lib

Post by idle »

I think you need to use a prototype, callcfunctionfast doesn't support floats in it's parameters

Try this modify it to suit

Code: Select all

CompilerIf Defined(ERect,#PB_Structure) = 0
Structure ERect

   top.i;
   left.i;
   bottom.i;
   right.i;
   
EndStructure
CompilerEndIf
#effEditGetRect=1

;test the prototype call 
ProcedureC testDisp(*effect,opcode,index,value,*ptr.erect,opt.f)
   Debug "called" 
   *ptr\bottom = 10
   Debug StrF(opt,1) 
   ProcedureReturn 1
 EndProcedure   
 
 ;prototype the function since a float is involved 
 PrototypeC pDispatcher(*effect,opcode,index,value,*ptr,opt.f) 
 
 ;make the prototype in you structure 
 Structure effects 
   ptrDispatche.pDispatcher 
 EndStructure    
 
 
 Global myAEffect.effects
 Define rect.erect 
 
  ;assign the function from the lib 
 myAEffect\ptrDispatche = @testDisp()
 

res = myAEffect\ptrDispatche(#effEditGetRect,0,0,0,rect,1.2);

Debug "rect resultate>>>"+Str(res)

If res=1
  Debug "top "+Str(Rect\top)
  Debug "left "+Str(Rect\left)
  Debug "bottom "+Str(Rect\bottom)
  Debug "right "+Str(Rect\right)

Else
  Debug "error"
EndIf
Windows 11, Manjaro, Raspberry Pi OS
Image
sq4
User
User
Posts: 98
Joined: Wed Feb 26, 2014 3:16 pm
Contact:

Re: need help with VST lib

Post by sq4 »

Hi,

I was "eriansa"..., lost my password so I needed a new user...

CallCFunctionFast(*myAEffect\ptrDispatcher,*myAEffect.AEffect, opcode.l, 0,0,@*Rect.ERect,0.0)

your Erect structure is correct.
cherri123
User
User
Posts: 32
Joined: Tue Apr 13, 2010 5:39 am

Re: need help with VST lib

Post by cherri123 »

eriansa, I am very glad to see you.
Unfortunately

Code: Select all

@ * Rect.ERekt

structure does not always returns a value to change the size of the editor window (you can test dblue_Glitch_v1_3)

Another problem is the sound output by means DSOUND or MME. There are no errors when using

Code: Select all

* myAEffect \ ProcessReplacing (* myAEffect, @ ptrInputBuffers (), @ ptrOutputBuffers (), blocksize)
.
All I can is now using

Code: Select all

waveOutWrite_ ()

to output sound, but only in the right channel and the left output only noise.

I hope that will help me figure it out.
If you need the code I publish it
sq4
User
User
Posts: 98
Joined: Wed Feb 26, 2014 3:16 pm
Contact:

Re: need help with VST lib

Post by sq4 »

Do not forget to implement "#audioMasterSizeWindow" in your host's callback (the plugin calls this)
Some Vst's do this when the effEditor opens.

You should also implement "#effGetOutputProperties". This tells the host how the outputs are arranged (stereo/mono...)
But indeed, if the plugin has numOutputs=2, you can assume that it's stereo.

Some plugins use Process instead of ProcessReplacing : see flags -> #effFlagsCanReplacing.
Also, do not forget to clear the inputbuffers before calling the process(Replacing) function.

Success!
cherri123
User
User
Posts: 32
Joined: Tue Apr 13, 2010 5:39 am

Re: need help with VST lib

Post by cherri123 »

Thanks for the comments. Code corrected.

Code: Select all

#DSBLOCK_ENTIREBUFFER = $2
#DSBLOCK_FROMWRITECURSOR=$1

IncludeFile "VST_PB.pbi"

Structure DSBUFFERDESC
 dwSize.l           
 dwFlags.l           
 dwBufferBytes.l     
 dwReserved.l       
 *lpwfxFormat       
 guid3DAlgorithm.GUID
EndStructure

Global *m.Word, dsound.IDirectSound8, dsb.IDirectSoundBuffer, *effect.AEffect

Global bloksize.l;=512;
Global samplerate.f;=44100;

Global BPM.d=120
Debug BPM

Procedure HostInit();                   /* initialize to sensible values     */
samplerate = 44100
bloksize = 512;
vstTimeInfo\samplePos = 0.0;
vstTimeInfo\sampleRate = samplerate;
vstTimeInfo\nanoSeconds = 0.0;
vstTimeInfo\ppqPos = 0.0;
vstTimeInfo\tempo = BPM;
vstTimeInfo\barStartPos = 0.0;
vstTimeInfo\cycleStartPos = 0.0;
vstTimeInfo\cycleEndPos = 0.0;
vstTimeInfo\timeSigNumerator = 4;
vstTimeInfo\timeSigDenominator = 4;
vstTimeInfo\smpteOffset = 0;
vstTimeInfo\smpteFrameRate = 1;         // 0:24, 1:25, 2:29.97, 3:30, 4:29.97 df, 5:30 df
vstTimeInfo\samplesToNextClock = 0;
vstTimeInfo\flags =0; #kVstTransportChanged|#kVstTransportPlaying;
EndProcedure


; открываем библы
If OpenLibrary(0, "dsound.dll") And OpenLibrary(1, OpenFileRequester("vst","d:\Program Files\VstPlugins\","VST (*.dll)|*.dll",0)); And GetWavHeader(wavFormat.WAVEFORMATEX, wavefile) And GetWavData(wavData.WAVDATA, wavefile)
  ; // Wave device And VST buffer cosntants
#T_FORMAT           =#WAVE_FORMAT_PCM
#T_SAMPLERATE       =44100
#T_CHANNELS         =2
#T_BITS             =16
#T_BLOCKALIGN       =(#T_CHANNELS*#T_BITS/8); // 2*16/8 = 4
#T_BYTESPERSEC      =(#T_SAMPLERATE*#T_BLOCKALIGN)

;// Total buffer size For 1 second worth of playback:
#T_WAVBUFSIZE       =(#T_SAMPLERATE*#T_BLOCKALIGN)*10

#T_UPDATESPERSEC    =10; // Which gives me 10 playback "pages"
#T_BLOCKSIZE        =(#T_SAMPLERATE/#T_UPDATESPERSEC); // 4410 samples
#T_DELAY            =(1000/#T_UPDATESPERSEC); // 100 ms timer delay

#NUM_BUFFERS = 5

Global wavFormat.WAVEFORMATEX
wavFormat\wFormatTag      = #T_FORMAT;
wavFormat\nChannels       = #T_CHANNELS;
wavFormat\nSamplesPerSec  = #T_SAMPLERATE;
wavFormat\wBitsPerSample  = #T_BITS;
wavFormat\nBlockAlign     = #T_BLOCKALIGN;(wavFormat\wBitsPerSample * wavFormat\nChannels / 8);
wavFormat\nAvgBytesPerSec = #T_BYTESPERSEC;wavFormat\nSamplesPerSec * wavFormat\nBlockAlign;
wavFormat\cbSize = 0;SizeOf(wavFormat);
Else
  MessageRequester("Error","Can't open VST plugin ",0)
  End
EndIf  
  HostInit()
;   If 
  ;Debug "LEN>"+Str(@len)
  hwnd = OpenWindow(0,0,0,80,80,"Sound", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  hwnd2=OpenWindow(2,0,0,800,600,"vst", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  CallFunction(0,"DirectSoundCreate8",0,@dsound,0)
  dsound\SetCooperativeLevel(hwnd,1)

  desc.DSBUFFERDESC\dwSize = SizeOf(DSBUFFERDESC)
  desc\dwBufferBytes = #T_WAVBUFSIZE
  desc\lpwfxFormat = @wavFormat
  dsound\CreateSoundBuffer(@desc,@dsb,0)
 
  sampleFrames = #T_WAVBUFSIZE / 4
  
  Debug sampleFrames

  main=Get_Main(1)
  If main
    *myAEffect.AEffect = CallCFunctionFast(main, @VST_CallBack())
  Else
    Debug "Not VTS"
    End
  EndIf
  
  *myAEffect\Dispatcher(*myAEffect, #effOpen,0,1,#Null, 0.0)
  
  *myAEffect\Dispatcher(*myAEffect, #effMainsChanged,0,0,#Null, 0.0)
  
  *myAEffect\Dispatcher(*myAEffect, #effSetSampleRate,0,0,#Null, samplerate)
  
  *myAEffect\Dispatcher(*myAEffect, #effSetBlockSize,0,sampleFrames,#Null, 0.0)
  
  *myAEffect\Dispatcher(*myAEffect, #effMainsChanged,0,1,#Null, 0.0)
  
  *myAEffect\Dispatcher(*myAEffect, #effEditOpen,0,0,hwnd2, 0.0)
  
  ;**************************************************
; создание окна
VST_getRect(@ERect)

*myAEffect\Dispatcher(*myAEffect, #effEditGetRect, 0, 0, @ERect, 0.0)
Debug "res " +Str(res)
*rec.ERect=ERect
ResizeWindow(2,#PB_Ignore,#PB_Ignore,*rec\left+*rec\right,*rec\bottom+*rec\top)


  
    ;*************************************************************************************
   If *myAEffect\numInputs>0
    Global Dim in.l(*myAEffect\numInputs-1) 
    Global Dim leftIn.f(sampleFrames-1)
    Global Dim rightIn.f(sampleFrames-1)

    If *myAEffect\numInputs>2

      in(0) = leftIn()
      in(1) = rightIn()
    
    EndIf 
   EndIf
   
    ;**********************

    Global Dim out.l(*myAEffect\numOutputs-1)
    Global Dim leftOut.f(sampleFrames-1)
    Global Dim rightOut.f(sampleFrames-1)
    
    If *myAEffect\numOutputs>2
      For i=0 To 1  
        out(0+n) = leftOut()
        out(1+n) = rightOut()
        n=n+2
      Next
      
    Else
      out(0) = leftOut()
      out(1) = rightOut()
    EndIf
     

     #channels=2
  Structure SOUND_BUFFER ; channels, each 16 bit  
    channel.w[#channels]  
  EndStructure  
 Global *Buffer.SOUND_BUFFER
;     dsb\Play(0, 0, $1)
 
Procedure PlayThread(play)
dsb\Play(0, 0, $1)
  While play=0
    ;Debug "."
  dsb\Lock(0,0,@m,@len,0,0,#DSBLOCK_ENTIREBUFFER)
  
  *Buffer = m  
  
      If *myAEffect\flags & #effFlagsCanReplacing
        *myAEffect\ProcessReplacing(*myAEffect,@in(), @out(), sampleFrames)
      Else
        *myAEffect\Process(*myAEffect,@in(), @out(), sampleFrames)
      EndIf
      Debug *myAEffect
  For i = 0 To sampleFrames-1
    *Buffer\channel[0]=leftOut(i)* 32768.0
    *Buffer\channel[1]=rightOut(i)* 32768.0
    *Buffer + SizeOf(SOUND_BUFFER)  
  Next
  dsb\UnLock(m,len,0,0)
  Wend
EndProcedure    
;CreateThread(@PlayThread(),0)

 Repeat 
   event=  WaitWindowEvent(1)   
   *myAEffect\Dispatcher(*myAEffect, #effEditIdle, 0, 0,#Null, 0.0)
  ;*************************************************************************************
;
  dsb\Lock(0,0,@m,@len,0,0,#DSBLOCK_ENTIREBUFFER)
  
  *Buffer = m 
  
      If *myAEffect\flags & #effFlagsCanReplacing
        *myAEffect\ProcessReplacing(*myAEffect,@in(), @out(), sampleFrames)
      Else
        *myAEffect\Process(*myAEffect,@in(), @out(), sampleFrames)
      EndIf
;       
    For i = 0 To sampleFrames-1
      *Buffer\channel[0]=leftOut(i)* 32768.0
      *Buffer\channel[1]=rightOut(i)* 32768.0
      *Buffer + SizeOf(SOUND_BUFFER)  
    Next
    dsb\UnLock(m,len,0,0)
    dsb\Play(0, 0, 1)


Until event = #PB_Event_CloseWindow


*myAEffect\Dispatcher(*myAEffect, #effEditClose, 0, 0,#Null, 0.0)  
*myAEffect\Dispatcher(*myAEffect, #effClose,0,0,#Null, 0.0)
  
   
  dsb\Stop()
  dsb\Release()
  dsound\Release()
  CloseLibrary(1)
  CloseLibrary(0)
cherri123
User
User
Posts: 32
Joined: Tue Apr 13, 2010 5:39 am

Re: need help with VST lib

Post by cherri123 »

Tell me how to apply to this code waveOutWrite_
part of the code

Code: Select all

For i=0 To 1
    wh(i)\lpData=ptrOutputBuffers(i)
    wh(i)\dwBufferLength=sampleFrames
    wh(i)\dwLoops=0
    wh(i)\dwFlags=0
Next    

    res=waveOutPrepareHeader_(hwo, @wh(), SizeOf(WAVEHDR))
    res=waveOutWrite_(hwo, @wh(), SizeOf(WAVEHDR))
    res=waveOutUnprepareHeader_(hwo, wh(), SizeOf(WAVEHDR))
right channel works and the left produces noise. Moreover, in the right channel sounds all the audio stream from VSTi


And more ...
In synthesizers, using the previous code, the end of the delay, reverb and releases are cut off at the completion of the clicks on the keyboard synth (eg Sylenth1).
cherri123
User
User
Posts: 32
Joined: Tue Apr 13, 2010 5:39 am

Re: need help with VST lib

Post by cherri123 »

With the output of the sound is clear. Can not understand how to configure the MIDI data to send via VstEvents. Who worked with the help
cherri123
User
User
Posts: 32
Joined: Tue Apr 13, 2010 5:39 am

Re: need help with VST lib

Post by cherri123 »

cherri123
User
User
Posts: 32
Joined: Tue Apr 13, 2010 5:39 am

Re: need help with VST lib

Post by cherri123 »

cherri123
User
User
Posts: 32
Joined: Tue Apr 13, 2010 5:39 am

Re: need help with VST lib

Post by cherri123 »

Who tested the code with VST synthesizer at the output sound from the clicks?
Post Reply