Author Topic: Translate C code to O2  (Read 1110 times)

0 Members and 1 Guest are viewing this topic.

Alex_Longard

  • Newbie
  • *
  • Posts: 35
Translate C code to O2
« on: July 12, 2018, 04:12:21 AM »
Hello all!
Help me please!
I'am translate Steinberg VST2 sdk to O2 and have some problems, because I do not know well C.
How to write this code in O2:

Code: [Select]
typedef VstIntPtr (VSTCALLBACK *audioMasterCallback) (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);


PS: vstint32 - int, vstintptr - pointer.

Thanks in advance!

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4268
    • Oxygen Basic
Re: Translate C code to O2
« Reply #1 on: July 12, 2018, 06:25:38 AM »
Hi Alex,

This is all new to me.

In the context of creating a VST host which I'm assuming is cdecl:

Code: [Select]
'http://teragonaudio.com/article/How-to-make-your-own-VST-host.html

'typedef VstIntPtr (VSTCALLBACK *audioMasterCallback) (
' AEffect* effect,
' VstInt32 opcode,
' VstInt32 index,
'  VstIntPtr value,
' void* ptr,
' float opt);

extern cdecl

function HostCallback (
=====================
  AEffect* effect,
  VstInt32 opcode,
  VstInt32 index,
  VstIntPtr value,
  void* ptr,
  float opt
 ) as sys, callback
 ...
end function

end extern

...
'@HostCallback

string vstPath="..." 'specify pathname
sys VST=LoadLibrary(vstPath)
sys p=GetProcAddress(VST,"VSTPluginMain")
sys plugin = call p(@HostCallback) 'passing address of your main callback
...

I hope this helps

Alex_Longard

  • Newbie
  • *
  • Posts: 35
Re: Translate C code to O2
« Reply #2 on: July 12, 2018, 07:19:54 AM »
Hello Charles!
Thanks for your code.
I try to write vst plugin in Oxygen, i have some ideas for write this, only i not translate "AudioMasterCallback" and "Dispatcher" functions.

In attached file assembler test plugin written on Fasm.

Alex_Longard

  • Newbie
  • *
  • Posts: 35
Re: Translate C code to O2
« Reply #3 on: July 16, 2018, 12:56:48 PM »
Hi Charles!
It's possible to make function as field in structure?

For example:
Code: [Select]
Type mytype
int a
int b

Function myfunc(int a, int b)
return a+b
End Function
End Type

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4268
    • Oxygen Basic
Re: Translate C code to O2
« Reply #4 on: July 16, 2018, 01:26:03 PM »
Hi Alex,

This is the simplest form of o2 OOP:

Code: [Select]
class mytype

  int a
  int b

  Function myfunc() as int
  return a+b
  End Function

end class

mytype t
t.a=1
t.b=2
print t.myfunc()

Alex_Longard

  • Newbie
  • *
  • Posts: 35
Re: Translate C code to O2
« Reply #5 on: July 16, 2018, 08:08:29 PM »
Good morning Charles,
Thanks for your code, i will try this.
 

Alex_Longard

  • Newbie
  • *
  • Posts: 35
Re: Translate C code to O2
« Reply #6 on: December 25, 2019, 09:51:37 PM »
Hi Charles!
Help me please:)

If i write in Oxygen my code in C style, this not work and show errors...

Code: [Select]
#include "inc\msvcrt.inc"

#define effVendorName 1

struct AEffect
{
int* (*dispatcher) (struct AEffect*, int, int, int*, void*, float);
};

int* dispatcher(AEffect *effect, int index, int opcode, int *value, void* ptr, float opt);
{
switch (opcode)
{
case effVendorName:
strncpy((char*)ptr, "Alexey Longard", 20);
}
...
}

AEffect* VSTPluginMain()
{
AEffect *effect = (AEffect*) malloc(sizeof(AEffect));
memset(effect, 0, sizeof(AEffect));
effect->dispatcher = @dispatcher;
return effect;
}

Thanks in advance!!!
Happy Merry Christmas and happy New Year!
Cheers.
« Last Edit: December 25, 2019, 10:12:53 PM by Alex_Longard »

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4268
    • Oxygen Basic
Re: Translate C code to O2
« Reply #7 on: December 26, 2019, 06:54:12 AM »
Merry Christmas Alex,

I assume this code is part of a DLL. This is one way to do it without the heavy C type-casting:

Code: [Select]
'12:01 26/12/2019
'#include "inc\msvcrt.inc"
uses msvcrt

extern

  #define effVendorName 1


  type AEffect
    sys pDispatcher
  end type

  function dispatcher(AEffect*effect,int index, int opcode, int *value, sys pt, float opt) as int*
    switch (opcode)
      case effVendorName:
        copy (pt, "Alexey Longard", 20)
    end switch
    ...
  end function

  function VSTPluginMain() as AEffect*, export
    AEffect *effect
    @effect = malloc(sizeof(AEffect))
    memset(@effect, 0, sizeof(AEffect))
    effect.pdispatcher = @dispatcher
    return @effect
  end function


Alex_Longard

  • Newbie
  • *
  • Posts: 35
Re: Translate C code to O2
« Reply #8 on: December 26, 2019, 08:04:07 AM »
Very big thanks Charles!!!
I will try to test it.