evaluate some harbor in c.

evaluate some harbor in c.

Postby carlos vargas » Thu Dec 06, 2018 7:20 pm

I have a class called tvlc, which has a data called bOnEvent of type codeblock
that codeblock I need to pass it to c and evaluate its content.
I am very confused with this since it exceeds my little knowledge in c.

this is what I have the api de vlc, has an event manager, which should be indicated that
do under certain conditions.
Code: Select all  Expand view  RUN
/*---------------------------------------------------------------------------------------------*/
CLASS TVlc

   /*hidden datas and methods*/
   HIDDEN:
   DATA bOnEvent
   DATA hContainer
   DATA pInstance, pMedia, pMediaPlayer, pEventManager, nStatus
   DATA nVolumeStep INIT 5
   DATA nVolume     INIT 50
   DATA nLen        INIT 0
   DATA nPos        INIT 0
   DATA nTime       INIT 0
   DATA cMediaFile  INIT ""
   DATA aMetaInfo
...

/*Play mediafile*/
METHOD Play() CLASS TVlc

   /*If paused, resume*/
   IF ::Status() == VLC_INPUT_STATE_PAUSED
      ::Pause()
   ELSE
      /*Is playing, exit*/
      IF ::Status() == VLC_INPUT_STATE_PLAYING
         RETURN NIL
      ELSE
         /*If defines mediafile*/
         IF !Empty( ::cMediaFile )
            /*Init info value*/
            ::nLen  := 0
            ::nPos  := 0
            ::nTime := 0

            /*clear metainfo*/
            ::aMetaInfo := NIL

            /*Exist vlc instance*/
            IF !Empty( ::pInstance )

               /*Create media instance*/
               ::pMedia := VLC_CreateMedia( ::pInstance, ::cMediaFile )

               IF !Empty( ::pMedia )
                 
                  /*if metainfo parse medifile and get metainfo*/
                  IF ::lMetaInfo
                     VLC_MediaParse( ::pMedia )
                     ::aMetaInfo := VLC_MediaGetMeta( ::pMedia )
                  ENDIF

                  /*Create mediaplayer instance*/
                  ::pMediaPlayer := VLC_CreateMediaPlayer( ::pMedia )

                  /*Exist mediaplayer instance*/
                  IF !Empty( ::pMediaPlayer )

                     /*Relase media handle, not need*/
                     VLC_MediaRelease( ::pMedia )
                     ::pMedia := NIL
                     
                     /*create event mediamanager*/
                     ::pEventManager := VLC_EventManager( ::pMediaPlayer )

                     /*Define windows container for mediaplayer*/
                     VLC_SetWindow( ::pMediaPlayer, ::hContainer )

                     /*Apply volume*/
                     ::Volume( ::nVolume )

                     /*Play media*/
                     ::nStatus := VLC_Play( ::pMediaPlayer )
 

Code: Select all  Expand view  RUN

/*---------------------------------------------------------------------*/
/*
Get the Event Manager from which the media player send event.
return the event manager associated with p_mi (mediaplayer)
LIBVLC_API libvlc_event_manager_t * libvlc_media_player_event_manager ( libvlc_media_player_t *p_mi );
*/

HB_FUNC( VLC_EVENTMANAGER )
{
   libvlc_media_player_t *mediaplayer = (libvlc_media_player_t *) hb_parptr( 1 );
   if( mediaplayer )
   {
      hb_retptr( (void *) libvlc_media_player_event_manager( mediaplayer ) );
   }
   else
   {
      hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
   }
}
/*---------------------------------------------------------------------*/

HB_FUNC( VLC_EVENTATTACH )
{
   libvlc_event_manager_t *eventmanager = (libvlc_event_manager_t *) hb_parptr( 1 );
   if( eventmanager )
   {
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerMediaChanged   , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerNothingSpecial , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerOpening        , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerPlaying        , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerPaused         , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerStopped        , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerEndReached     , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerTimeChanged    , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerPositionChanged, vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerPausableChanged, vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerMuted          , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerUnmuted        , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerAudioVolume    , vlc_mycallback, NULL );
      libvlc_event_attach( eventmanager, libvlc_MediaPlayerLengthChanged  , vlc_mycallback, NULL );
   }
}

/*---------------------------------------------------------------------*/

HB_FUNC( VLC_EVENTDETCH )
{
   libvlc_event_manager_t *eventmanager = (libvlc_event_manager_t *) hb_parptr( 1 );
   if( eventmanager )
   {
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerMediaChanged   , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerNothingSpecial , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerOpening        , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerPlaying        , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerPaused         , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerStopped        , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerEndReached     , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerTimeChanged    , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerPositionChanged, vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerPausableChanged, vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerMuted          , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerUnmuted        , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerAudioVolume    , vlc_mycallback, NULL );
      libvlc_event_detach( eventmanager, libvlc_MediaPlayerLengthChanged  , vlc_mycallback, NULL );
   }
}

/*---------------------------------------------------------------------*/

void vlc_mycallback( const libvlc_event_t *event, void *param )
{
   switch ( event->type )
   {
      case libvlc_MediaPlayerMediaChanged:
      case libvlc_MediaPlayerNothingSpecial:
      case libvlc_MediaPlayerOpening:
      case libvlc_MediaPlayerPlaying:
      case libvlc_MediaPlayerPaused:
      case libvlc_MediaPlayerStopped:
      case libvlc_MediaPlayerEndReached:
      case libvlc_MediaPlayerTimeChanged:
      case libvlc_MediaPlayerPositionChanged:
      case libvlc_MediaPlayerPausableChanged:
      case libvlc_MediaPlayerMuted:
      case libvlc_MediaPlayerUnmuted:
      case libvlc_MediaPlayerAudioVolume:
         break;
   }
}
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1721
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: evaluate some harbor in c.

Postby AntoninoP » Fri Dec 07, 2018 8:38 am

I did it some weeks ago:
for the EMF, in harbour I have:
Code: Select all  Expand view  RUN
EnumEnhMetaFile(hDC,hMeta,{|pDC,pTable,pRECORD| MyCB(pdf,pTable,pRECORD) },{0,0,100,100})

and in C I have:
Code: Select all  Expand view  RUN
int CALLBACK HBEnhEnumProc(HDC hDC,HANDLETABLE *lpHTable,const ENHMETARECORD *lpEMFR,int nObj,LPARAM lpData)
{
    PHB_ITEM pBlock = (PHB_ITEM)lpData;
    PHB_ITEM pDC = hb_itempPutFw(0,(FWCAST)hDC);
    PHB_ITEM pHandleTable = hb_itemArrayNew(nObj);
    PHB_ITEM pRecord = hb_itemArrayNew(lpEMFR->nSize/4+1);
    PHB_ITEM pRet;
    int i;
    for(i=0;i<nObj;i++)
        hb_itemArrayPut(pHandleTable,i+1,hb_itemPutPtr(0,lpHTable->objectHandle[i]));
       
    hb_itemArrayPut(pRecord,1,hb_itemPutNI(0,lpEMFR->iType));
    for(i=0;i<(int)lpEMFR->nSize/4;i++)
        hb_itemArrayPut(pRecord,i+2,hb_itemPutNInt(0,lpEMFR->dParm[i]));

    hb_evalBlock(pBlock, pDC, pHandleTable, pRecord, 0);

    for(i=0;i<nObj;i++)
        lpHTable->objectHandle[i] = (HGDIOBJ)hb_itemGetPtr(hb_itemArrayGet(pHandleTable,i+1));

    pRet = hb_stackReturnItem();
    if HB_IS_NUMBER(pRet)
    {
        return hb_itemGetNI(pRet);
    }
    else
    {
        return 0;
    }
}

HB_FUNC( ENUMENHMETAFILE )
{
    RECT rect;
    rect.top    = hb_parvni( 4, 1);
    rect.left   = hb_parvni( 4, 2);
    rect.bottom = hb_parvni( 4, 3);
    rect.right  = hb_parvni( 4, 4);
    EnumEnhMetaFile((HDC)hb_parfw(1),(HENHMETAFILE)hb_parfw(2),HBEnhEnumProc, hb_param( 3, HB_IT_BLOCK ),&rect);
    hb_ret();
}


The core is the function hb_evalBlock that takes a list of PHB_ITEM with a zero to mark the end.
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 61 guests