Convert .h to .pbi this way

Share your advanced PureBasic knowledge/code with the community.
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Convert .h to .pbi this way

Post by WolfgangS »

How to convert a .h include file to a .pbi file ?

I recomment to copy the whole file to your PB Editor and mark it all as comment.

At first you can do the simple things:
If you find some #define stuff convert it to PB. this way:

Code: Select all

/// Enable/disable anti-alias filter in pitch transposer (0 = disable)
#define SETTING_USE_AA_FILTER       0
/// Pitch transposer anti-alias filter length (8 .. 128 taps, default = 32)
#define SETTING_AA_FILTER_LENGTH    1
to

Code: Select all

#SETTING_USE_AA_FILTER     =0
#SETTING_AA_FILTER_LENGTH  =1
And so on.

If you find emums, this is also very simple:

Code: Select all

;   /// Supported audio file formats.
;   enum FileFormat {
;     FF_AUTODETECT,
;     FF_WAV,
;     FF_OGG,
;     FF_FLAC,
;     FF_MP3,
;     FF_MOD,
;     FF_AIFF,
;   };
To

Code: Select all

Enumeration
  #AUDIERE_FF_AUTODETECT
  #AUDIERE_FF_WAV
  #AUDIERE_FF_OGG
  #AUDIERE_FF_FLAC
  #AUDIERE_FF_MP3
  #AUDIERE_FF_MOD
  #AUDIERE_FF_AIFF
EndEnumeration
If you find some STRUCTs, just convert it like this:

Code: Select all

typedef struct 
{
    char  fmt[4];
    int   format_len;
    short fixed;
    short channel_number;
    int   sample_rate;
    int   byte_rate;
    short byte_per_sample;
    short bits_per_sample;
} WavFormat;
to

Code: Select all

Structure WavFormat
  char.b[4]
  formal_len.l
  fixed.w
  channel_nummer.w
  sample_rate.l
  byte_rate.l
  byte_per_sample.w
  bits_per_sample.w
EndStructure
NOW comes the most important: the classes.
Simple classes looks like this:

Code: Select all

class FIFOSamplePipe
{
public:
        virtual short *ptrBegin() const = 0;
        virtual void putSamples(const short *samples, const uint numSamples) = 0;
        void moveSamples(FIFOSamplePipe &other)
        virtual uint receiveSamples(short *output,const uint maxSamples) = 0;
        virtual uint numSamples() const = 0;
        virtual int isEmpty() const = 0;
        virtual void clear() = 0
};
You can simply convert it to:

Code: Select all

Interface FIFOSamplePipe
  ptrBegin()  ; word
  moveSamples(FIFOSamplePipe_ptrOther)  ; void
  receiveSamples(output.w,maxSamples.l) ; LONG
  numSamples()                          ; LONG
  isEmpty()                             ; LONG
  clear()                               ; VOID
EndInterface
Please, please, please don't forget to comment the methods with the type which it gives back. VOID means it gives nothing

back.

Note: It is NOT necessarily to convert private methods.

If you find a Class with such a head:

Code: Select all

class FIFOProcessor :public FIFOSamplePipe
{
public:
... fooo
you have to give the class FIFOProcessor also the class FIFOSamplePipe this way:

Code: Select all

Interface FIFOProcessor Using FIFOSamplePipe 
That means the class FIFOProcessor ows all methods of FIFOProcessor AND FIFOSamplePipe !!! This is very important.

Don't forget to convert also the functions of the dll (doubleclick the dll !!). The Functions will give you the Objects of your class.

It can look like this:

Code: Select all

Procedure.l AUDIERE_OpenDevice(device.l,parameter.l)        ; OK
  ProcedureReturn CallFunction(#audiere,"_AdrOpenDevice@8",device.l,parameter.l) 
EndProcedure
Create an object this way:

Code: Select all

myobj.FIFOProcessor=TheFunction(foo)


I also want to tell you some tipps:

1. If a method needs to transfer a DOUBLE type write 2 LONGS and split the value with this procedures:

Code: Select all

Structure dblout
  p1.l
  p2.l
EndStructure

SendADouble(DoublePart1(yourValue),DoublePart2(yourValue))
; Converts float to double
Procedure DoublePart1(flt.f)
  Global _input.f:_input.f=flt
  Global _dblout.dblout
  !FLD dword[v__input]
  !FST qword[v__dblout]
  ProcedureReturn _dblout\p1
EndProcedure

Procedure DoublePart2(flt.f)
  Global _input.f:_input.f=flt
  Global _dblout.dblout
  !FLD dword[v__input]
  !FST qword[v__dblout]
  ProcedureReturn _dblout\p2
EndProcedure

2. If you get back a double value you can get it with this:

Code: Select all

; * Converts DOUBLE(part1,part2) To FLOAT
Procedure.f Float(p1.l,p2.l)
  Global _output.f
  Global _dblin.dblout
  _dblin\p1=p1
  _dblin\p2=p2
  !FLD qword[v__dblin]
  !FST dword[v__output]
  ProcedureReturn _output
EndProcedure
(this small converters are made by the mighty PureFan)


This is all information i know to convert c/c++ includes to PB. (don't forget it to save it as .pbi file ;))

Unfortunately there are still a few questions open, maybe some one else can help out:
1. What happends if a class contains 2 methods with the same name ?
2. What happends if a class contains also some code. E.g.:

Code: Select all

    virtual uint numSamples() const
    {
        return output->numSamples();
    }

I know this isn't all information what can be written about this theme (but it's all i know) but i think it gives you an idea how it works.
Feel free to enhance this text and distribute it again.



Maybe it will help you to convert your stuff.


MFG
WolfgangS

PS: You can also peek in my audiere.pbi and compare it with the c++ audiere includes
WolfgangS' projects http://www.schliess.net
Quotation of the month:
<p3hicy>oder ich hol mir so eine geile aus asien
<p3hicy>die ständig poppen will
<p3hicy>'n brötchen pro tag reicht doch
<p3hicy>die essen eh' nich so viel
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Thanks for the tips.
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Ok, here comes the most secret *insider* tip:

Go to the /LibrarySDK/HeaderConverter/ directory, run the
HeaderConverter.exe tool, and let it do the work for you :wink:

...also the InterfaceImporter tool might come in handy :wink:

Ok, the output of HeaderConverter is not quite perfect, but it is being
improved...

Timo
quidquid Latine dictum sit altum videtur
Cor
Enthusiast
Enthusiast
Posts: 124
Joined: Fri Apr 25, 2003 7:52 pm
Location: Netherlands
Contact:

Post by Cor »

Thanks,

this will surely help a lot
Cor de Visser

Registered PureBasic user

Author of ChordPlanet
Made with PureBasic
http://www.chordplanet.com
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Post by WolfgangS »

freak wrote:Ok, here comes the most secret *insider* tip:
...
Ok, the output of HeaderConverter is not quite perfect, but it is being
improved...
Timo
... and you need this knowledge to help out the converters .... :lol:

MFG
WolfgangS
WolfgangS' projects http://www.schliess.net
Quotation of the month:
<p3hicy>oder ich hol mir so eine geile aus asien
<p3hicy>die ständig poppen will
<p3hicy>'n brötchen pro tag reicht doch
<p3hicy>die essen eh' nich so viel
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

@ Wolfgang
Thanks for sharing.

@ Freak
To have a tool that does the work for you is good, but to know what is going on is even better, this way I learn what's going on :wink:

well sometimes...
Post Reply