libnjb  2.2.7
libnjb.h
Go to the documentation of this file.
1 
13 #ifndef __LIBNJB__H
14 #define __LIBNJB__H
15 
17 #define LIBNJB_VERSION 2.2.7
18 
19 #define LIBNJB_COMPILED_FOR_LIBUSB 1
20 
21 /* This handles MSVC pecularities */
22 #ifdef _MSC_VER
23 #include <windows.h>
24 #define __WIN32__
25 #define snprintf _snprintf
26 #define ssize_t SSIZE_T
27 #endif
28 
29 #include <sys/types.h>
30 #ifdef __WIN32__
31 /* Windows specific code, types that do not exist in Windows
32  * sys/types.h
33  */
34 typedef char int8_t;
35 typedef unsigned char u_int8_t;
36 typedef __int16 int16_t;
37 typedef unsigned __int16 u_int16_t;
38 typedef __int32 int32_t;
39 typedef unsigned __int32 u_int32_t;
40 typedef unsigned __int64 u_int64_t;
41 #endif
42 #ifdef __sun
43 
44 /*
45  * Solaris specific code, types that do not exist in Solaris'
46  * sys/types.h. u_intN_t is the ISO C way, whereas Solaris'
47  * way is POSIXly correct.
48  */
49 #define u_int8_t uint8_t
50 #define u_int16_t uint16_t
51 #define u_int32_t uint32_t
52 #define u_int64_t uint64_t
53 #endif
54 
55 
56 #include <stdio.h>
57 #include <usb.h>
58 
60 #define NJB_MAX_DEVICES 0xFF
61 
72 #define NJB_DEVICE_NJB1 0x00
73 #define NJB_DEVICE_NJB2 0x01
74 #define NJB_DEVICE_NJB3 0x02
75 #define NJB_DEVICE_NJBZEN 0x03
76 #define NJB_DEVICE_NJBZEN2 0x04
77 #define NJB_DEVICE_NJBZENNX 0x05
78 #define NJB_DEVICE_NJBZENXTRA 0x06
79 #define NJB_DEVICE_DELLDJ 0x07
80 #define NJB_DEVICE_NJBZENTOUCH 0x08
81 #define NJB_DEVICE_NJBZENMICRO 0x09
82 #define NJB_DEVICE_DELLDJ2 0x0a
83 #define NJB_DEVICE_POCKETDJ 0x0b
84 #define NJB_DEVICE_ZENSLEEK 0x0c
85 #define NJB_DEVICE_CREATIVEZEN 0x0d
86 #define NJB_DEVICE_DELLDJ3 0x0e
93 #define NJB_TYPE_STRING 0x00
94 #define NJB_TYPE_UINT16 0x02
95 #define NJB_TYPE_UINT32 0x03
102 #define NJB_CODEC_MP3 "MP3"
103 #define NJB_CODEC_WMA "WMA"
104 #define NJB_CODEC_WAV "WAV"
105 #define NJB_CODEC_AA "AA"
112 #define FR_SIZE "FILE SIZE"
113 #define FR_LENGTH "LENGTH"
114 #define FR_CODEC "CODEC"
115 #define FR_TITLE "TITLE"
116 #define FR_ALBUM "ALBUM"
117 #define FR_GENRE "GENRE"
118 #define FR_ARTIST "ARTIST"
119 #define FR_TRACK "TRACK NUM"
120 #define FR_FNAME "FNAME"
121 #define FR_YEAR "YEAR"
122 #define FR_PROTECTED "PlayOnly"
123 /* These two are used by Notmad on NJB1, not Creative */
124 #define FR_BITRATE "BITRATE"
125 #define FR_COMMENT "COMMENT"
126 /* This one is used on series 3 devices only */
127 #define FR_FOLDER "FOLDER"
135 #define DD_USBCTL 1
136 #define DD_USBBLKLIM 2
137 #define DD_USBBLK 4
138 #define DD_SUBTRACE 8
146 #define NJB_UC_8859 0
147 #define NJB_UC_UTF8 1
155 #define NJB_TURBO_OFF 0
156 #define NJB_TURBO_ON 1
160 #define OWNER_STRING_LENGTH 128
161 
162 typedef unsigned char owner_string[OWNER_STRING_LENGTH + 1];
163 
168 typedef struct njb_struct njb_t;
174 typedef struct njb_eax_struct njb_eax_t;
175 typedef struct njb_time_struct njb_time_t;
182 struct njb_struct {
183  struct usb_device *device;
184  usb_dev_handle *dev;
185  u_int8_t usb_config;
186  u_int8_t usb_interface;
187  u_int8_t usb_bulk_in_ep;
188  u_int8_t usb_bulk_out_ep;
190  int updated;
191  u_int32_t xfersize;
193  void *error_stack;
194 };
195 
196 /* Song/track tag definitions */
197 
203  char *label;
204  u_int8_t type;
208  union {
209  char *strval;
210  u_int8_t u_int8_val;
211  u_int16_t u_int16_val;
212  u_int32_t u_int32_val;
213  u_int64_t u_int64_val;
214  } data;
216 };
217 
223  u_int32_t trid;
224  u_int16_t nframes;
229 };
230 
231 /* Playlist definitions */
232 
238  u_int32_t trackid;
241 };
242 
248  char *name;
249  int _state;
250 #define NJB_PL_NEW 0
251 #define NJB_PL_UNCHANGED 1
252 #define NJB_PL_CHNAME 2
253 #define NJB_PL_CHTRACKS 3
254  u_int32_t ntracks;
255  u_int32_t plid;
256  njb_playlist_track_t *first;
257  njb_playlist_track_t *last;
258  njb_playlist_track_t *cur;
259  njb_playlist_t *nextpl;
261 };
262 
269 #define NJB_FILEFLAGS_REGULAR_FILE 0x80000000U
270 
276  char *filename;
281  char *folder;
288  u_int32_t timestamp;
290  u_int32_t flags;
323  u_int32_t dfid;
325  u_int64_t filesize;
333 };
334 
335 
339 typedef enum {
340  NJB_EAX_NO_CONTROL,
341  NJB_EAX_SLIDER_CONTROL,
342  NJB_EAX_FIXED_OPTION_CONTROL
344 
345 
350  u_int16_t number;
351  char *name;
352  u_int8_t exclusive;
360  u_int8_t group;
374  int16_t current_value;
379  int16_t min_value;
384  int16_t max_value;
388  char **option_names;
398 };
399 
404  int16_t year;
405  int16_t month;
406  int16_t day;
407  int16_t weekday;
408  int16_t hours;
409  int16_t minutes;
410  int16_t seconds;
411 };
412 
418  char key[5];
419  u_int32_t value1;
420  u_int32_t value2;
421  unsigned char deviceid[16];
423 };
424 
425 #ifdef __cplusplus
426 extern "C" {
427 #endif
428 
429 /* NJB commands */
430 
432 typedef int NJB_Xfer_Callback(u_int64_t sent, u_int64_t total,
433  const char* buf, unsigned len, void *data);
434 
439 void NJB_Set_Debug (int debug_flags);
440 void NJB_Set_Unicode (int unicode_flag);
441 int NJB_Error_Pending(njb_t *njb);
443 const char *NJB_Error_Geterror(njb_t *njb);
444 void NJB_Error_Dump(njb_t *njb, FILE *fp);
450 int NJB_Discover(njb_t *njbs, int limit, int *n);
451 int NJB_Open(njb_t *njb);
452 void NJB_Close(njb_t *njb);
453 int NJB_Capture (njb_t *njb);
454 int NJB_Release (njb_t *njb);
455 void NJB_Ping(njb_t *njb);
456 int NJB_Get_Disk_Usage (njb_t *njb, u_int64_t *btotal, u_int64_t *bfree);
457 char *NJB_Get_Owner_String (njb_t *njb);
458 int NJB_Set_Owner_String (njb_t *njb, const char *name);
459 int NJB_Get_Bitmap_Dimensions(njb_t *njb, int *x, int *y, int *bytes);
460 int NJB_Set_Bitmap(njb_t *njb, const unsigned char *bitmap);
462 u_int64_t NJB_Get_NJB1_Libcounter(njb_t *njb);
463 int NJB_Send_Firmware (njb_t *njb, const char *path, NJB_Xfer_Callback *callback, void *data);
464 int NJB_Get_Battery_Level (njb_t *njb);
466 int NJB_Get_Auxpower (njb_t *njb);
467 int NJB_Get_SDMI_ID(njb_t *njb, u_int8_t *sdmiid);
468 const char *NJB_Get_Device_Name(njb_t *njb, int type);
469 int NJB_Get_Firmware_Revision(njb_t *njb, u_int8_t *major, u_int8_t *minor, u_int8_t *release);
470 int NJB_Get_Hardware_Revision(njb_t *njb, u_int8_t *major, u_int8_t *minor, u_int8_t *release);
471 int NJB_Set_Turbo_Mode(njb_t *njb, u_int8_t mode);
478 void NJB_Songid_Destroy(njb_songid_t *song);
482 njb_songid_frame_t *NJB_Songid_Findframe(njb_songid_t *song, const char *label);
483 njb_songid_frame_t *NJB_Songid_Frame_New_String(const char *label, const char *value);
484 njb_songid_frame_t *NJB_Songid_Frame_New_Uint16(const char *label, u_int16_t value);
485 njb_songid_frame_t *NJB_Songid_Frame_New_Uint32(const char *label, u_int32_t value);
486 /* Good helper functions for creating frames - USE THESE IF YOU CAN */
488 /* #define NJB_Songid_Frame_New_Codec(a) NJB_Songid_Frame_New_String(FR_CODEC, a) */
489 #define NJB_Songid_Frame_New_Title(a) NJB_Songid_Frame_New_String(FR_TITLE, a)
490 #define NJB_Songid_Frame_New_Album(a) NJB_Songid_Frame_New_String(FR_ALBUM, a)
491 #define NJB_Songid_Frame_New_Genre(a) NJB_Songid_Frame_New_String(FR_GENRE, a)
492 #define NJB_Songid_Frame_New_Artist(a) NJB_Songid_Frame_New_String(FR_ARTIST, a)
493 #define NJB_Songid_Frame_New_Length(a) NJB_Songid_Frame_New_Uint16(FR_LENGTH, a)
494 #define NJB_Songid_Frame_New_Filesize(a) NJB_Songid_Frame_New_Uint32(FR_SIZE, a)
495 #define NJB_Songid_Frame_New_Tracknum(a) NJB_Songid_Frame_New_Uint16(FR_TRACK, a)
496 #define NJB_Songid_Frame_New_Year(a) NJB_Songid_Frame_New_Uint16(FR_YEAR, a)
497 #define NJB_Songid_Frame_New_Filename(a) NJB_Songid_Frame_New_String(FR_FNAME, a)
498 #define NJB_Songid_Frame_New_Protected(a) NJB_Songid_Frame_New_Uint16(FR_PROTECTED, a)
499 /* These two only apply to NJB1 */
500 #define NJB_Songid_Frame_New_Bitrate(a) NJB_Songid_Frame_New_Uint32(FR_BITRATE, a)
501 #define NJB_Songid_Frame_New_Comment(a) NJB_Songid_Frame_New_String(FR_COMMENT, a)
502 /* This one only apply to series 3 devices */
503 #define NJB_Songid_Frame_New_Folder(a) NJB_Songid_Frame_New_String(FR_FOLDER, a)
505 void NJB_Get_Extended_Tags (njb_t *njb, int extended);
506 void NJB_Reset_Get_Track_Tag (njb_t *njb);
508 int NJB_Replace_Track_Tag(njb_t *njb, u_int32_t trackid, njb_songid_t *songid);
509 int NJB_Get_Track (njb_t *njb, u_int32_t trackid, u_int32_t size,
510  const char *path, NJB_Xfer_Callback *callback, void *data);
511 int NJB_Get_Track_fd (njb_t *njb, u_int32_t trackid, u_int32_t size,
512  int fd, NJB_Xfer_Callback *callback, void *data);
513 int NJB_Send_Track (njb_t *njb, const char *path, njb_songid_t *songid,
514  NJB_Xfer_Callback *callback, void *data, u_int32_t *trackid);
515 int NJB_Delete_Track (njb_t *njb, u_int32_t trackid);
521 void NJB_Reset_Get_Playlist (njb_t *njb);
523 int NJB_Delete_Playlist (njb_t *njb, u_int32_t plid);
528  unsigned int pos);
529 #define NJB_PL_END 0
530 #define NJB_PL_START 1
533 int NJB_Playlist_Set_Name(njb_playlist_t *pl, const char *name);
534 void NJB_Playlist_Deltrack(njb_playlist_t *pl, unsigned int pos);
535 void NJB_Playlist_Deltrack_TrackID(njb_playlist_t *pl, u_int32_t trackid);
536 njb_playlist_track_t *NJB_Playlist_Track_New(u_int32_t trackid);
546 #define NJB_Get_File NJB_Get_Track
547 #define NJB_Get_File_fd NJB_Get_Track_fd
548 int NJB_Send_File (njb_t *njb, const char *path, const char *name, const char *folder,
549  NJB_Xfer_Callback *callback, void *data, u_int32_t *fileid);
550 int NJB_Delete_Datafile (njb_t *njb, u_int32_t fileid);
551 int NJB_Create_Folder (njb_t *njb, const char *name, u_int32_t *folderid);
557 void NJB_Reset_Get_EAX_Type (njb_t *njb);
559 void NJB_Destroy_EAX_Type (njb_eax_t *eax);
560 void NJB_Adjust_EAX (njb_t *njb,
561  u_int16_t eaxid,
562  u_int16_t patchindex,
563  int16_t scalevalue);
570 int NJB_Set_Time(njb_t *njb, njb_time_t *time);
571 void NJB_Destroy_Time(njb_time_t *time);
577 int NJB_Play_Track (njb_t *njb, u_int32_t trackid);
578 int NJB_Queue_Track (njb_t *njb, u_int32_t trackid);
579 int NJB_Stop_Play (njb_t *njb);
580 int NJB_Pause_Play (njb_t *njb);
581 int NJB_Resume_Play (njb_t *njb);
582 int NJB_Seek_Track (njb_t *njb, u_int32_t position);
583 int NJB_Elapsed_Time (njb_t *njb, u_int16_t *elapsed, int *change);
586 #ifdef __cplusplus
587 }
588 #endif
589 
590 #endif