static table with structs (and function ptr) (Pure C)

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
saulot
Captain Atari
Captain Atari
Posts: 190
Joined: Sat Sep 18, 2004 9:09 pm
Location: Warszawa
Contact:

static table with structs (and function ptr) (Pure C)

Postby saulot » Thu Mar 26, 2009 6:48 pm

Hi,
I have problem with PureC compiler. I'm trying to set up global static table with event type, function pointer, and size of struct.
It looks something like this:

Code: Select all


typedef struct Channel_t
{
   int x;   /* TODO! dummy struct */
}sChannel_t;



enum eEventType
{
   T_NOTEOFF=0,
   T_NOTEON,
   T_NOTEAFT,
   T_CONTROL,
   T_PRG_CH,
   T_CHAN_AFT,
   T_PITCH_BEND,
   T_EVT_COUNT      /* total number of events */
};

/*  Note On event block */
typedef struct
{
   U8 ubEventType;
   U8 ubKey;
   U8 ubVelocity;
}sNoteOn_EventBlock_t;

/* Note Off event block */
typedef struct
{
 U8 ubEventType;
 U8 ubKey;
 U8 ubVelocity;
}sNoteOff_EventBlock_t;

typedef struct
{
 U8 ubEventType;
}sNoteAft_EventBlock_t;


typedef struct
{
   U8 ubEventType;
}sController_EventBlock_t;

typedef struct
{
   U8 ubEventType;
}sPrgChng_EventBlock_t;


typedef struct
{
 U8 ubEventType;
}sChannelAft_EventBlock_t;


typedef struct
{
 U8 ubEventType;
}sPitchBend_EventBlock_t;

/* event function prototypes */

void fNoteOn(sChannel_t *pTrack)
{}
void fNoteOff(sChannel_t *pTrack)
{}
void fNoteAft(sChannel_t *pTrack)
{}
void fProgramChange (sChannel_t *pTrack)
{}
void fController(sChannel_t *pTrack)
{}
void fChannelAft(sChannel_t *pTrack)
{}
void fPitchBend(sChannel_t *pTrack)
{}

/* custom type evntFuncPtr for events in given sequence  */
typedef void (*evntFuncPtr)(sChannel_t *pTrack);

typedef struct
{
 U32 ubEvntType;      /* type of an event */
 evntFuncPtr func;     /* pointer to event handler */
 U32   size;      /* size of command string in bytes */
} sEventBlock_t;

/* event id, functionPtr, parameters struct */

static sEventBlock_t g_arSeqCmdTable[T_EVT_COUNT]
{   
    {T_NOTEON, fNoteOn, sizeof(sNoteOn_EventBlock_t)},
    {T_NOTEOFF, fNoteOff,sizeof(sNoteOff_EventBlock_t)},
    {T_NOTEAFT, fNoteAft, sizeof(sNoteAft_EventBlock_t)},
    {T_CONTROL, fController,sizeof(sController_EventBlock_t)},
    {T_PRG_CH, fProgramgChange,(U32)sizeof(sPrgChng_EventBlock_t)},
    {T_CHAN_AFT, fChannelAft,sizeof(sChannelAft_EventBlock_t)},
    {T_PITCH_BEND, fPitchBend,sizeof(sPitchBend_EventBlock_t)}
};


Pure C moans about declaration syntax error in arSeqCmdTable[].
Anyone has ideas about what could be wrong? :?:
I've also tried the 'portable way':

Code: Select all

static sEventBlock_t g_arSeqCmdTable[T_EVT_COUNT]
{   
    {T_NOTEON, &fNoteOn, sizeof(sNoteOn_EventBlock_t)},
    {T_NOTEOFF, &fNoteOff,sizeof(sNoteOff_EventBlock_t)},
    {T_NOTEAFT, &fNoteAft, sizeof(sNoteAft_EventBlock_t)},
    {T_CONTROL, &fController,sizeof(sController_EventBlock_t)},
    {T_PRG_CH, &fProgramgChange,(U32)sizeof(sPrgChng_EventBlock_t)},
    {T_CHAN_AFT, &fChannelAft,sizeof(sChannelAft_EventBlock_t)},
    {T_PITCH_BEND, &fPitchBend,sizeof(sPitchBend_EventBlock_t)}
};


But the problem remains the same...

User avatar
saulot
Captain Atari
Captain Atari
Posts: 190
Joined: Sat Sep 18, 2004 9:09 pm
Location: Warszawa
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby saulot » Thu Mar 26, 2009 10:25 pm

The problem was trivial one :roll: (as always) , I forgot to add '='.

The code should look like below:

Code: Select all

static sEventBlock_t g_arSeqCmdTable[T_EVT_COUNT] =
{   
    {T_NOTEON, fNoteOn, sizeof(sNoteOn_EventBlock_t)},
    {T_NOTEOFF, fNoteOff,sizeof(sNoteOff_EventBlock_t)},
    {T_NOTEAFT, fNoteAft, sizeof(sNoteAft_EventBlock_t)},
    {T_CONTROL, fController,sizeof(sController_EventBlock_t)},
    {T_PRG_CH, fProgramgChange,sizeof(sPrgChng_EventBlock_t)},
    {T_CHAN_AFT, fChannelAft,sizeof(sChannelAft_EventBlock_t)},
    {T_PITCH_BEND, fPitchBend,sizeof(sPitchBend_EventBlock_t)}
};



This time K&R Ansi C was invaluable. Thanks to me for solving this problem :P ...

User avatar
Desty
Atari God
Atari God
Posts: 1956
Joined: Thu Apr 01, 2004 2:36 pm
Location: 53 21N 6 18W
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby Desty » Thu Mar 26, 2009 10:49 pm

saulot wrote:This time K&R Ansi C was invaluable. Thanks to me for solving this problem :P ...

Hey, you forgot to add "I'm welcome!" to be polite ;)
tá'n poc ar buile!

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2217
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby charles » Thu Mar 26, 2009 10:50 pm

hey salout , u r really doing it this time ... midi and c ... good going !!!

whayt you trying to make?

i truely desire some c experience but i think it looks god awfull and will not ever try c .. i use some asm and pascal and gfa instead.

i can see you have static... is static considered "LOCAL" in c?

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!

User avatar
saulot
Captain Atari
Captain Atari
Posts: 190
Joined: Sat Sep 18, 2004 9:09 pm
Location: Warszawa
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby saulot » Thu Mar 26, 2009 11:03 pm

charles:
in this context static means array of structs which will be created and preinitialised before program start.
whayt you trying to make?


ATM I'm writing midi api for Roland mt-32 family (optimised for replaying midi files not for sequencing). I will release everything under GPL when it will be ready..

User avatar
oberje
Atari freak
Atari freak
Posts: 58
Joined: Sat Jan 10, 2009 2:38 pm
Location: Sussex, UK
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby oberje » Thu Mar 26, 2009 11:12 pm

saulot wrote:charles:
in this context static means array of structs which will be created and preinitialised before program start.
whayt you trying to make?


Oops, pedant-mode on! :D

Actually, in this context ( file scope ) the static just means the symbol will not be exported from the compilation unit. The array will be created and initialised whether you have the "static" keyword or not.
</pedant>


Cheers,
oberje

User avatar
saulot
Captain Atari
Captain Atari
Posts: 190
Joined: Sat Sep 18, 2004 9:09 pm
Location: Warszawa
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby saulot » Thu Mar 26, 2009 11:29 pm

oberje: you're right..

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2217
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby charles » Fri Mar 27, 2009 12:16 am

well if you can call using the "call" command a machine language cod ei got a mid file play code you can have,,,,

charles thanks for tip about static , i am using a basic right now that global or static arrays
never knew what that really was .. thanks i got to start a new thread!

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!

User avatar
saulot
Captain Atari
Captain Atari
Posts: 190
Joined: Sat Sep 18, 2004 9:09 pm
Location: Warszawa
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby saulot » Fri Mar 27, 2009 7:15 am

charles wrote:well if you can call using the "call" command a machine language cod ei got a mid file play code you can have,,,,


Thanks, I don't need it (and in my case this code would be useless, because firstly I'm reading needed midi data and putting it in some sort of custom structure, and after that I will be able to replay it).
I have an idea to sort all events by delta times or delta times an channels/tracks, additionally each midi file will be able to preload all needed SysEx patches (embedded in midi file itself or placed in external file).
It's not about just playing file, but about doing it right with all features of mt32 in mind.

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2217
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby charles » Thu Apr 02, 2009 4:44 pm

well i won;t go as far as its easy to say then i will play it , there is a great deal to learn before launching the midi song file..

here are a couple c examples i have found,, they are for amiga but should demonstrate
the sifting , program flow , staus meta id and file load for you...

let me know if they helped.

charles
You do not have the required permissions to view the files attached to this post.
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2217
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby charles » Fri Apr 10, 2009 10:34 pm

hey salout , are you there?
i am thinking about starting a new midi program in pascal , interested in participating?
just something simile like a midi file player with fileselect loader or something,,

hows the c thing doing , have not heard much from you laterilyly..

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!

User avatar
saulot
Captain Atari
Captain Atari
Posts: 190
Joined: Sat Sep 18, 2004 9:09 pm
Location: Warszawa
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby saulot » Sat Apr 11, 2009 7:06 am

charles wrote:hey salout , are you there?
i am thinking about starting a new midi program in pascal , interested in participating?
hows the c thing doing , have not heard much from you laterilyly..

Sorry, I will not touch pascal and first thing is finishing my projects.
Atm I'm bug hunting, so there is nothing to tell.

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2217
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: static table with structs (and function ptr) (Pure C)

Postby charles » Sun Apr 12, 2009 4:14 pm

hurry and get yours done saulot , i got mine done in pascal, omikron ,asm and gfa
i am conducting a speed test and want to learn from your code how to program in c.

see thread
viewtopic.php?f=69&t=16293&p=143329#p143329

any how mine just uses fileselector to load file and then play traks etc
all features of the mt 32 included as long as most general midi functions.

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 1 guest