On Tue, 2010-06-29 at 22:15 +0100, Harry Van Haaren wrote:
> 

> 
> enum
> {    /* True and false */
>     SF_FALSE    = 0,
>     SF_TRUE        = 1,
>     /* Modes for opening files. */
>     SFM_READ    = 0x10,
>     SFM_WRITE    = 0x20,
>     SFM_RDWR    = 0x30,
>     SF_AMBISONIC_NONE        = 0x40,
>     SF_AMBISONIC_B_FORMAT    = 0x41
> } ;
> 
> Is the one I'm stuck on now. I tried this in the .vapi:
> class Sndfile
> { // all other functions ommitted for brevity
>     [CCode (cname="")]
>     public enum FileMode
>     {    /* True and false */
>         SF_FALSE    = 0,
>         SF_TRUE        = 1,
>         /* Modes for opening files. */
>         SFM_READ    = 0x10,
>         SFM_WRITE    = 0x20,
>         SFM_RDWR    = 0x30,
>         SF_AMBISONIC_NONE        = 0x40,
>         SF_AMBISONIC_B_FORMAT    = 0x41
>     }
> }
> 
> but the C output goes like so  SNDFILE_FILE_MODE_SFM_READ  while I
> want SFM_READ.
> I hoped that the  cname=""  would clear the SNDFILE_FILE_MODE_  from
> the start but it didnt..

Hi,

what a bad enum: it seems more as an aggregate of constants!

Attached you can find an example vapi, but be aware that I haven't
tested it.

Here a vala snippet to test it:

using SndFile;

int main()
{
        var fm = FileMode.READ;
        var info = Info ();
        var file = File.open ("test.wav", fm, ref info);
        return 0;
}


You can look also at the posix.vapi (/usr/share/vala/vapi/posix.vapi).

Regards,
        Andrea


[CCode (cheader_filename="sndfile.h", lower_case_cprefix="sf_", upper_case_cprefix="SF_")]
namespace SndFile
{
	[CCode (cname="int", cprefix="SFM_")]
	public enum FileMode
	{    
		READ    = 0x10,
		WRITE    = 0x20,
		RDWR    = 0x30,
	}

	[CCode (cname="int")]
	public enum Ambisonic
	{
		NONE        = 0x40,
		B_FORMAT    = 0x41
	}

	[CCode (cname="int")]
	public const bool TRUE;

	[CCode (cname="int")]
	public const bool FALSE;

	/* Extract of format enum */
	[CCode (cname="int")]
	public enum Format
	{
		WAV,                              /* Microsoft WAV format (little endian default). */
		AIFF,                             /* Apple/SGI AIFF format (big endian). */
		AU                                /* Sun/NeXT AU format (big endian). */
	}

	[CCode (default_value = "0UL")]
	[IntegerType (rank = 9)]
	public struct count_t
	{
	}

	[CCode (cname="SF_INFO", has_copy_function = false, has_destroy_function = false)]
	public struct Info
	{
		public count_t frames;
		public int samplerate;
		public int channels;
		public int format;
		public int sections;
		public int seekable;
	}

	[Compact]
	[CCode (cname="SNDFILE", free_function="sf_close")]
	public class File
	{
		[CCode (cname="sf_open")]
		public static File? open (string path, FileMode mode, ref SndFile.Info info);
	}
}

_______________________________________________
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to