Announcement

Collapse
No announcement yet.

Help translate this c code..

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help translate this c code..

    Code:
     void try_code( const char* file, const char* fmt)
    { 
    std:: cout<<"======" <<file<<" =====\n"
     dword h = BASS_StreamCreateFile( false, (const void*) file,0,0,BASS_Stream_Decode) 
     if (h)
              {
                 const char& t = tags_read(h,fmt);
                  if (*t)
                        std::cout<<t<<std::endl;
                  else
                        std::cout<<"("<<Tags_GetLastErrorDesc()<<")"<<std""endl;
                  BASS_STREAMFree(h);
               }else
                std::cout<<"(couldn't open)"<<std::endl;
    }
    I have most of it....the function up to if h.. I get lost in what to use for their pointers. I know the std::cout stufff (msgBox), and the bass_streamCreate, but basically within the IF (*t) is my problem.
    Last edited by Barry Erick; 27 Feb 2011, 10:25 AM.
    Barry

  • #2
    Maybe something like this...

    Code:
     
    %BASS_STREAM_DECODE = &#38;H200000
    FUNCTION try_code(sFile AS STRING, sFmt AS STRING) '{
      MSGBOX "======" &#38; sFile &#38; " ====="
      LOCAL h AS DWORD
      h = BASS_StreamCreateFile(%FALSE, BYVAL STRPTR(sFile), BYVAL 0, BYVAL 0, %BASS_Stream_Decode)
      IF h THEN
        LOCAL t AS ASCIIZ POINTER
        t = tags_read(h, BYVAL STRPTR(sFmt))
        IF t THEN
          MSGBOX @t
        ELSE
          LOCAL LastErrorDesc AS ASCIIZ POINTER
          LastErrorDesc = Tags_GetLastErrorDesc()
          MSGBOX  "(" &#38; @LastErrorDesc &#38; ")"
        END IF
        BASS_STREAMFree(h)
      ELSE
        MSGBOX "(couldn't open)"
      END IF
    END FUNCTION
    Last edited by Pierre Bellisle; 27 Feb 2011, 12:28 PM.

    Comment


    • #3
      Sorry, that is not it. It is printing the address of the string. The c version prints all the tags found on the file. Not the handle.

      Here is an etire test code in c. I am not using the files shown, I use Display Browse to pick the file to pass to Try_File and I do not use the timing_test.

      Code:
      //////////////////////////////////////////////////////////////////////////
      //
      // test.cpp - library testing tool. Not a regression test however...
      //
      // Author: Wraith, 2k5-2k6
      // Public domain. No warranty.
      // 
      
      
      #include "../basslib/bass.h"
      #include "../tags/tags.h"
      
      #include <iostream>
      
      void try_file( const char* file, const char* fmt )
      {
      	std::cout<<"====== "<<file<<" =======\n";
      	DWORD h = BASS_StreamCreateFile( false, (const void*)file, 0,0,BASS_STREAM_DECODE );
      	if( h )
      	{
      		const char* t = TAGS_Read( h, fmt );
      		if( *t )
      			std::cout<<t<<std::endl;
      		else
      			std::cout<<"("<<TAGS_GetLastErrorDesc()<<")"<<std::endl;
      		BASS_StreamFree( h );
      	}else
      		std::cout<<"(couldn't open)"<<std::endl;
      
      }
      
      void timing_test()
      {
      	std::cout<<"Timing test..."<<std::endl;
      	const char* const fmt = "%IFV1(%ITRM(%TRCK),%ITRM(%TRCK). )%IFV2(%ITRM(%ARTI),%ICAP(%ITRM(%ARTI)),no artist) - %IFV2(%ITRM(%TITL),%ICAP(%ITRM(%TITL)),no title)%IFV1(%ITRM(%ALBM), - %IUPC(%ITRM(%ALBM)))%IFV1(%YEAR, %(%YEAR%))%IFV1(%ITRM(%GNRE), {%ITRM(%GNRE)})%IFV1(%ITRM(%CMNT), [%ITRM(%CMNT)])";
      	DWORD h = BASS_StreamCreateFile( false, (const void*)"id3v2.mp3", 0,0,BASS_STREAM_DECODE );
      
      	__int64 s,c,f;
      	QueryPerformanceFrequency( (LARGE_INTEGER*) &f );
      	QueryPerformanceCounter( (LARGE_INTEGER*) &s );
      
      	float t = 0;
      	int cnt = 0;
      	const float duration = 3;
      
      	while( t<duration )
      	{
      		const char* tag = TAGS_Read( h, fmt );
      
      		QueryPerformanceCounter( (LARGE_INTEGER*)&c );
      		t += float(c-s)/f;
      		s = c;
      		++cnt;
      	}
      
      	std::cout<<"\r                                                 \r";
      	std::cout<<"Timing: "<<duration<<" sec., "<<cnt<<" calls, "<<duration/cnt<<" sec avg."<<std::endl;
      
      	BASS_StreamFree( h );
      
      }
      
      int main()
      {
      	const char* fmt = "[%TITL|%ARTI|%ALBM|%GNRE|%YEAR|%CMNT|%TRCK]";
      	BASS_Init( 0, 0, 0, 0, 0 );
      	BASS_PluginLoad( "basswma.dll" );
      	BASS_PluginLoad( "bass_ape.dll" );
      
      	try_file( "id3v2.mp3", fmt );
      	try_file( "id3v1.mp3", fmt );
      	try_file( "id3-both.mp3", fmt  );
      	try_file( "ogg.ogg", fmt  );
      	try_file( "wma.wma", fmt );
      	try_file( "ape.ape", fmt );
      	try_file( "ofr.ofr", fmt );
      
      	timing_test();
      
      	BASS_Free();
      }
      'This is my code to the call:
      Code:
      CALLBACK FUNCTION ShowDIALOG1Proc()
      
          LOCAL f AS STRING' ASCIIZ * %Max_Path
      
          SELECT CASE AS LONG CB.MSG
              CASE %WM_INITDIALOG
                  ' Initialization handler
                          IF HI(WORD,BASS_GetVersion) <> %BASSVERSION THEN
                  MSGBOX "An incorrect version of BASS.DLL was loaded", _
                      %MB_ICONERROR,ProgName
                  DIALOG END CB.HNDL
                  EXIT FUNCTION
              END IF
              'open default device now, later close it and open according to device selected.
              IF BASS_INIT(0,44100,0,CB.HNDL,BYVAL(0))=0 THEN
                  IF BASS_ERRORGETCODE <> %BASS_ERROR_ALREADY THEN
                      MSGBOX "Error on opening device",,ProgName
                      EXIT FUNCTION
                  END IF
              END IF
      
              CASE %WM_NCACTIVATE
                  STATIC hWndSaveFocus AS DWORD
                  IF ISFALSE CB.WPARAM THEN
                      ' Save control focus
                      hWndSaveFocus = GetFocus()
                  ELSEIF hWndSaveFocus THEN
                      ' Restore control focus
                      SetFocus(hWndSaveFocus)
                      hWndSaveFocus = 0
                  END IF
      
              CASE %WM_COMMAND
                  ' Process control notifications
                  SELECT CASE AS LONG CB.CTL
                      CASE %btn_Browse
                          IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                              LOCAL fmt AS STRING
                             DISPLAY BROWSE ,,,"","c:\pbwin90\audio",%BIF_BROWSEINCLUDEFILES OR %BIF_NEWDIALOGSTYLE TO f
                             IF f<> "" THEN
                                 fmt = "%TTL OR %ARTI OR %ALBM OR %GNRE OR %YEAR OR %CMNT OR %TRCK"
                                 try_File (f,fmt)
                             END IF
      
                          END IF
      
                      CASE %btn_Quit
                          IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                              DIALOG END CB.HNDL
                          END IF
      
                  END SELECT
          END SELECT
      END FUNCTION
      '------------------------------------------------------------------------------
      Last edited by Barry Erick; 27 Feb 2011, 12:04 PM. Reason: Adding code
      Barry

      Comment


      • #4
        Aren't there some PB-ready "Bass Box" functions in the source code forum?

        (Is that the same thing?)
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          I've update code above... still not sure...

          Comment


          • #6
            Originally posted by Michael Mattias View Post
            Aren't there some PB-ready "Bass Box" functions in the source code forum?

            (Is that the same thing?)
            Yes, and it is very easy to use another BASS funciton BASS_ChannelGetTags to get all but ID3.2 tags and un4seen.com themselves say to use this or another third party Tag program as theirs does not support ID3.2 That is the only reason I am doing this and BASSBOX does not have it in there. They show a VB wrapper for this dll but not a vb example. Google comes up with show me but not "here it is"
            Barry

            Comment


            • #7
              Originally posted by Pierre Bellisle View Post
              Maybe something like this...
              That is it. Only have to parse it now. I was almost there. Where you have
              Code:
              Local t as Asciiz Ptr
              I had
              Code:
              Local t as ASCIIZ * 1024
              Local tt as long ptr
              
              tt = varptr(t)
              
               @tt = Tag_Read....
               msgbox t
              I still do not fully understand pointers. Sometimes I get it right and lots of times I get it wrong.

              Thanks
              Barry

              Comment


              • #8
                I believe that t holds a pointer.
                The dereference of t, *t, gives the value of the first character of the string whose pointer is returned.
                This means that the string is not printed if the string is nul terminated at its t(0) character.
                Pointer math allows the zero element to be accessed by default.
                (*t), (*(t + 1)), (*(t + 2)), etc.. *t = *(t + 0)
                The output is the string itself. Passing a string pointer means passing the string, which is why it was necessary to dereference the first character to read it.
                In BASIC, this is the equivalent of ASC(myString) for an ASCIIZ string.
                Last edited by Kurt Kuzba; 10 Mar 2011, 03:46 PM. Reason: Left out half of a sentence. Oops.
                The world is strange and wonderful.*
                I reserve the right to be horrifically wrong.
                Please maintain a safe following distance.
                *wonderful sold separately.

                Comment

                Working...
                X