# libnjb.h

Go to the documentation of this file.

    00001
    00013 #ifndef __LIBNJB__H
    00014 #define __LIBNJB__H
    00015
    00017 #define LIBNJB_VERSION 2.2.6
    00018
    00019 #define LIBNJB_COMPILED_FOR_LIBUSB 1
    00020
    00021 /* This handles MSVC pecularities */
    00022 #ifdef _MSC_VER
    00023 #include <windows.h>
    00024 #define __WIN32__
    00025 #define snprintf _snprintf
    00026 #define ssize_t SSIZE_T
    00027 #endif
    00028
    00029 #include <sys/types.h>
    00030 #ifdef __WIN32__
    00031 /* Windows specific code, types that do not exist in Windows
    00032  * sys/types.h
    00033  */
    00034 typedef char int8_t;
    00035 typedef unsigned char u_int8_t;
    00036 typedef __int16 int16_t;
    00037 typedef unsigned __int16 u_int16_t;
    00038 typedef __int32 int32_t;
    00039 typedef unsigned __int32 u_int32_t;
    00040 typedef unsigned __int64 u_int64_t;
    00041 #endif
    00042 #ifdef __sun
    00043
    00044 /*
    00045  * Solaris specific code, types that do not exist in Solaris'
    00046  * sys/types.h. u_intN_t is the ISO C way, whereas Solaris'
    00047  * way is POSIXly correct.
    00048  */
    00049 #define u_int8_t uint8_t
    00050 #define u_int16_t uint16_t
    00051 #define u_int32_t uint32_t
    00052 #define u_int64_t uint64_t
    00053 #endif
    00054
    00055
    00056 #include <stdio.h>
    00057 #include <usb.h>
    00058
    00060 #define NJB_MAX_DEVICES 0xFF
    00061
    00072 #define NJB_DEVICE_NJB1         0x00
    00073 #define NJB_DEVICE_NJB2         0x01
    00074 #define NJB_DEVICE_NJB3         0x02
    00075 #define NJB_DEVICE_NJBZEN       0x03
    00076 #define NJB_DEVICE_NJBZEN2      0x04
    00077 #define NJB_DEVICE_NJBZENNX     0x05
    00078 #define NJB_DEVICE_NJBZENXTRA   0x06
    00079 #define NJB_DEVICE_DELLDJ       0x07
    00080 #define NJB_DEVICE_NJBZENTOUCH  0x08
    00081 #define NJB_DEVICE_NJBZENMICRO  0x09
    00082 #define NJB_DEVICE_DELLDJ2      0x0a
    00083 #define NJB_DEVICE_POCKETDJ     0x0b
    00084 #define NJB_DEVICE_ZENSLEEK     0x0c
    00085 #define NJB_DEVICE_CREATIVEZEN  0x0d
    00086 #define NJB_DEVICE_DELLDJ3      0x0e
    00093 #define NJB_TYPE_STRING         0x00
    00094 #define NJB_TYPE_UINT16         0x02
    00095 #define NJB_TYPE_UINT32         0x03
    00102 #define NJB_CODEC_MP3   "MP3"
    00103 #define NJB_CODEC_WMA   "WMA"
    00104 #define NJB_CODEC_WAV   "WAV"
    00105 #define NJB_CODEC_AA    "AA"
    00112 #define FR_SIZE         "FILE SIZE"
    00113 #define FR_LENGTH       "LENGTH"
    00114 #define FR_CODEC        "CODEC"
    00115 #define FR_TITLE        "TITLE"
    00116 #define FR_ALBUM        "ALBUM"
    00117 #define FR_GENRE        "GENRE"
    00118 #define FR_ARTIST       "ARTIST"
    00119 #define FR_TRACK        "TRACK NUM"
    00120 #define FR_FNAME        "FNAME"
    00121 #define FR_YEAR         "YEAR"
    00122 #define FR_PROTECTED    "PlayOnly"
    00123 /* These two are used by Notmad on NJB1, not Creative */
    00124 #define FR_BITRATE      "BITRATE"
    00125 #define FR_COMMENT      "COMMENT"
    00126 /* This one is used on series 3 devices only */
    00127 #define FR_FOLDER       "FOLDER"
    00135 #define DD_USBCTL       1
    00136 #define DD_USBBLKLIM    2
    00137 #define DD_USBBLK       4
    00138 #define DD_SUBTRACE     8
    00146 #define NJB_UC_8859     0
    00147 #define NJB_UC_UTF8     1
    00155 #define NJB_TURBO_OFF   0
    00156 #define NJB_TURBO_ON    1
    00160 #define OWNER_STRING_LENGTH     128
    00161
    00162 typedef unsigned char owner_string[OWNER_STRING_LENGTH + 1];
    00163
    00168 typedef struct njb_struct njb_t;
    00169 typedef struct njb_songid_frame_struct njb_songid_frame_t;
    00170 typedef struct njb_songid_struct njb_songid_t;
    00171 typedef struct njb_playlist_track_struct njb_playlist_track_t;
    00172 typedef struct njb_playlist_struct njb_playlist_t;
    00173 typedef struct njb_datafile_struct njb_datafile_t;
    00174 typedef struct njb_eax_struct njb_eax_t;
    00175 typedef struct njb_time_struct njb_time_t;
    00176 typedef struct njb_keyval_struct njb_keyval_t;
    00182 struct njb_struct {
    00183         struct usb_device *device;
    00184         usb_dev_handle *dev;
    00185         u_int8_t usb_config;
    00186         u_int8_t usb_interface;
    00187         u_int8_t usb_bulk_in_ep;
    00188         u_int8_t usb_bulk_out_ep;
    00189         int device_type;
    00190         int updated;
    00191         u_int32_t xfersize;
    00192         void *protocol_state;
    00193         void *error_stack;
    00194 };
    00195
    00196 /* Song/track tag definitions */
    00197
    00202 struct njb_songid_frame_struct {
    00203         char *label;
    00204         u_int8_t type;
    00208         union {
    00209                 char *strval;
    00210                 u_int8_t u_int8_val;
    00211                 u_int16_t u_int16_val;
    00212                 u_int32_t u_int32_val;
    00213                 u_int64_t u_int64_val;
    00214         } data;
    00215         njb_songid_frame_t *next;
    00216 };
    00217
    00222 struct njb_songid_struct {
    00223         u_int32_t trid;
    00224         u_int16_t nframes;
    00225         njb_songid_frame_t *first;
    00226         njb_songid_frame_t *last;
    00227         njb_songid_frame_t *cur;
    00228         njb_songid_t *next;
    00229 };
    00230
    00231 /* Playlist definitions */
    00232
    00237 struct njb_playlist_track_struct {
    00238         u_int32_t trackid;
    00239         struct njb_playlist_track_struct *prev;
    00240         struct njb_playlist_track_struct *next;
    00241 };
    00242
    00247 struct njb_playlist_struct {
    00248         char *name;
    00249         int _state;
    00250 #define NJB_PL_NEW              0
    00251 #define NJB_PL_UNCHANGED        1
    00252 #define NJB_PL_CHNAME           2
    00253 #define NJB_PL_CHTRACKS         3
    00254         u_int32_t ntracks;
    00255         u_int32_t plid;
    00256         njb_playlist_track_t *first;
    00257         njb_playlist_track_t *last;
    00258         njb_playlist_track_t *cur;
    00259         njb_playlist_t *nextpl;
    00261 };
    00262
    00269 #define NJB_FILEFLAGS_REGULAR_FILE   0x80000000U
    00270
    00275 struct njb_datafile_struct {
    00276         char *filename;
    00281         char *folder;
    00288         u_int32_t timestamp;
    00290         u_int32_t flags;
    00323         u_int32_t dfid;
    00325         u_int64_t filesize;
    00331         njb_datafile_t *nextdf;
    00333 };
    00334
    00335
    00339 typedef enum {
    00340        NJB_EAX_NO_CONTROL,
    00341        NJB_EAX_SLIDER_CONTROL,
    00342        NJB_EAX_FIXED_OPTION_CONTROL
    00343 } njb_eax_control_t;
    00344
    00345
    00349 struct njb_eax_struct {
    00350         u_int16_t number;
    00351         char *name;
    00352         u_int8_t exclusive;
    00360         u_int8_t group;
    00366         njb_eax_control_t type;
    00374         int16_t   current_value;
    00379         int16_t   min_value;
    00384         int16_t   max_value;
    00388         char **option_names;
    00394         njb_eax_t *next;
    00398 };
    00399
    00403 struct njb_time_struct {
    00404         int16_t year;
    00405         int16_t month;
    00406         int16_t day;
    00407         int16_t weekday;
    00408         int16_t hours;
    00409         int16_t minutes;
    00410         int16_t seconds;
    00411 };
    00412
    00417 struct njb_keyval_struct {
    00418         char key[5];
    00419         u_int32_t value1;
    00420         u_int32_t value2;
    00421         unsigned char deviceid[16];
    00422         njb_keyval_t *next;
    00423 };
    00424
    00425 #ifdef __cplusplus
    00426 extern "C" {
    00427 #endif
    00428
    00429 /* NJB commands */
    00430
    00432 typedef int NJB_Xfer_Callback(u_int64_t sent, u_int64_t total,
    00433                 const char* buf, unsigned len, void *data);
    00434
    00439 void NJB_Set_Debug (int debug_flags);
    00440 void NJB_Set_Unicode (int unicode_flag);
    00441 int NJB_Error_Pending(njb_t *njb);
    00442 void NJB_Error_Reset_Geterror(njb_t *njb);
    00443 const char *NJB_Error_Geterror(njb_t *njb);
    00444 void NJB_Error_Dump(njb_t *njb, FILE *fp);
    00450 int NJB_Discover(njb_t *njbs, int limit, int *n);
    00451 int NJB_Open(njb_t *njb);
    00452 void NJB_Close(njb_t *njb);
    00453 int NJB_Capture (njb_t *njb);
    00454 int NJB_Release (njb_t *njb);
    00455 void NJB_Ping(njb_t *njb);
    00456 int NJB_Get_Disk_Usage (njb_t *njb, u_int64_t *btotal, u_int64_t *bfree);
    00457 char *NJB_Get_Owner_String (njb_t *njb);
    00458 int NJB_Set_Owner_String (njb_t *njb, const char *name);
    00459 int NJB_Get_Bitmap_Dimensions(njb_t *njb, int *x, int *y, int *bytes);
    00460 int NJB_Set_Bitmap(njb_t *njb, const unsigned char *bitmap);
    00461 njb_keyval_t *NJB_Get_Keys(njb_t *njb);
    00462 u_int64_t NJB_Get_NJB1_Libcounter(njb_t *njb);
    00463 int NJB_Send_Firmware (njb_t *njb, const char *path, NJB_Xfer_Callback *callback, void *data);
    00464 int NJB_Get_Battery_Level (njb_t *njb);
    00465 int NJB_Get_Battery_Charging (njb_t *njb);
    00466 int NJB_Get_Auxpower (njb_t *njb);
    00467 int NJB_Get_SDMI_ID(njb_t *njb, u_int8_t *sdmiid);
    00468 const char *NJB_Get_Device_Name(njb_t *njb, int type);
    00469 int NJB_Get_Firmware_Revision(njb_t *njb, u_int8_t *major, u_int8_t *minor, u_int8_t *release);
    00470 int NJB_Get_Hardware_Revision(njb_t *njb, u_int8_t *major, u_int8_t *minor, u_int8_t *release);
    00471 int NJB_Set_Turbo_Mode(njb_t *njb, u_int8_t mode);
    00477 njb_songid_t *NJB_Songid_New(void);
    00478 void NJB_Songid_Destroy(njb_songid_t *song);
    00479 void NJB_Songid_Addframe(njb_songid_t *song, njb_songid_frame_t *frame);
    00480 void NJB_Songid_Reset_Getframe(njb_songid_t *song);
    00481 njb_songid_frame_t *NJB_Songid_Getframe(njb_songid_t *song);
    00482 njb_songid_frame_t *NJB_Songid_Findframe(njb_songid_t *song, const char *label);
    00483 njb_songid_frame_t *NJB_Songid_Frame_New_String(const char *label, const char *value);
    00484 njb_songid_frame_t *NJB_Songid_Frame_New_Uint16(const char *label, u_int16_t value);
    00485 njb_songid_frame_t *NJB_Songid_Frame_New_Uint32(const char *label, u_int32_t value);
    00486 /* Good helper functions for creating frames - USE THESE IF YOU CAN */
    00487 njb_songid_frame_t *NJB_Songid_Frame_New_Codec(const char *value);
    00488 /* #define NJB_Songid_Frame_New_Codec(a) NJB_Songid_Frame_New_String(FR_CODEC, a) */
    00489 #define NJB_Songid_Frame_New_Title(a) NJB_Songid_Frame_New_String(FR_TITLE, a)
    00490 #define NJB_Songid_Frame_New_Album(a) NJB_Songid_Frame_New_String(FR_ALBUM, a)
    00491 #define NJB_Songid_Frame_New_Genre(a) NJB_Songid_Frame_New_String(FR_GENRE, a)
    00492 #define NJB_Songid_Frame_New_Artist(a) NJB_Songid_Frame_New_String(FR_ARTIST, a)
    00493 #define NJB_Songid_Frame_New_Length(a) NJB_Songid_Frame_New_Uint16(FR_LENGTH, a)
    00494 #define NJB_Songid_Frame_New_Filesize(a) NJB_Songid_Frame_New_Uint32(FR_SIZE, a)
    00495 #define NJB_Songid_Frame_New_Tracknum(a) NJB_Songid_Frame_New_Uint16(FR_TRACK, a)
    00496 #define NJB_Songid_Frame_New_Year(a) NJB_Songid_Frame_New_Uint16(FR_YEAR, a)
    00497 #define NJB_Songid_Frame_New_Filename(a) NJB_Songid_Frame_New_String(FR_FNAME, a)
    00498 #define NJB_Songid_Frame_New_Protected(a) NJB_Songid_Frame_New_Uint16(FR_PROTECTED, a)
    00499 /* These two only apply to NJB1 */
    00500 #define NJB_Songid_Frame_New_Bitrate(a) NJB_Songid_Frame_New_Uint32(FR_BITRATE, a)
    00501 #define NJB_Songid_Frame_New_Comment(a) NJB_Songid_Frame_New_String(FR_COMMENT, a)
    00502 /* This one only apply to series 3 devices */
    00503 #define NJB_Songid_Frame_New_Folder(a) NJB_Songid_Frame_New_String(FR_FOLDER, a)
    00504 void NJB_Songid_Frame_Destroy (njb_songid_frame_t *frame);
    00505 void NJB_Get_Extended_Tags (njb_t *njb, int extended);
    00506 void NJB_Reset_Get_Track_Tag (njb_t *njb);
    00507 njb_songid_t *NJB_Get_Track_Tag (njb_t *njb);
    00508 int NJB_Replace_Track_Tag(njb_t *njb, u_int32_t trackid, njb_songid_t *songid);
    00509 int NJB_Get_Track (njb_t *njb, u_int32_t trackid, u_int32_t size,
    00510         const char *path, NJB_Xfer_Callback *callback, void *data);
    00511 int NJB_Get_Track_fd (njb_t *njb, u_int32_t trackid, u_int32_t size,
    00512         int fd, NJB_Xfer_Callback *callback, void *data);
    00513 int NJB_Send_Track (njb_t *njb, const char *path, njb_songid_t *songid,
    00514         NJB_Xfer_Callback *callback, void *data, u_int32_t *trackid);
    00515 int NJB_Delete_Track (njb_t *njb, u_int32_t trackid);
    00521 void NJB_Reset_Get_Playlist (njb_t *njb);
    00522 njb_playlist_t *NJB_Get_Playlist (njb_t *njb);
    00523 int NJB_Delete_Playlist (njb_t *njb, u_int32_t plid);
    00524 int NJB_Update_Playlist (njb_t *njb, njb_playlist_t *pl);
    00525 njb_playlist_t *NJB_Playlist_New(void);
    00526 void NJB_Playlist_Destroy(njb_playlist_t *pl);
    00527 void NJB_Playlist_Addtrack(njb_playlist_t *pl, njb_playlist_track_t *track,
    00528         unsigned int pos);
    00529 #define NJB_PL_END      0
    00530 #define NJB_PL_START    1
    00531 void NJB_Playlist_Reset_Gettrack(njb_playlist_t *pl);
    00532 njb_playlist_track_t *NJB_Playlist_Gettrack(njb_playlist_t *pl);
    00533 int NJB_Playlist_Set_Name(njb_playlist_t *pl, const char *name);
    00534 void NJB_Playlist_Deltrack(njb_playlist_t *pl, unsigned int pos);
    00535 void NJB_Playlist_Deltrack_TrackID(njb_playlist_t *pl, u_int32_t trackid);
    00536 njb_playlist_track_t *NJB_Playlist_Track_New(u_int32_t trackid);
    00537 void NJB_Playlist_Track_Destroy(njb_playlist_track_t *track);
    00543 void NJB_Reset_Get_Datafile_Tag (njb_t *njb);
    00544 njb_datafile_t *NJB_Get_Datafile_Tag (njb_t *njb);
    00545 void NJB_Datafile_Destroy(njb_datafile_t *df);
    00546 #define NJB_Get_File NJB_Get_Track
    00547 #define NJB_Get_File_fd NJB_Get_Track_fd
    00548 int NJB_Send_File (njb_t *njb, const char *path, const char *name, const char *folder,
    00549         NJB_Xfer_Callback *callback, void *data, u_int32_t *fileid);
    00550 int NJB_Delete_Datafile (njb_t *njb, u_int32_t fileid);
    00551 int NJB_Create_Folder (njb_t *njb, const char *name, u_int32_t *folderid);
    00557 void NJB_Reset_Get_EAX_Type (njb_t *njb);
    00558 njb_eax_t *NJB_Get_EAX_Type (njb_t *njb);
    00559 void NJB_Destroy_EAX_Type (njb_eax_t *eax);
    00560 void NJB_Adjust_EAX (njb_t *njb,
    00561         u_int16_t eaxid,
    00562         u_int16_t patchindex,
    00563         int16_t scalevalue);
    00569 njb_time_t *NJB_Get_Time(njb_t *njb);
    00570 int NJB_Set_Time(njb_t *njb, njb_time_t *time);
    00571 void NJB_Destroy_Time(njb_time_t *time);
    00577 int NJB_Play_Track (njb_t *njb, u_int32_t trackid);
    00578 int NJB_Queue_Track (njb_t *njb, u_int32_t trackid);
    00579 int NJB_Stop_Play (njb_t *njb);
    00580 int NJB_Pause_Play (njb_t *njb);
    00581 int NJB_Resume_Play (njb_t *njb);
    00582 int NJB_Seek_Track (njb_t *njb, u_int32_t position);
    00583 int NJB_Elapsed_Time (njb_t *njb, u_int16_t *elapsed, int *change);
    00586 #ifdef __cplusplus
    00587 }
    00588 #endif
    00589
    00590 #endif