SPlaylist.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #include "SPlaylist.h"
  2. #include "api__playlist.h"
  3. #include "PlaylistManager.h"
  4. extern ScriptObjectController *script_root;
  5. extern PlaylistScriptController playlistController;
  6. // -- Functions table -------------------------------------
  7. function_descriptor_struct PlaylistScriptController::exportedFunction[] = {
  8. {L"Clear", 0, (void*)SPlaylist::script_vcpu_Clear },
  9. {L"GetNumItems", 0, (void*)SPlaylist::script_vcpu_GetNumItems },
  10. {L"GetItem", 1, (void*)SPlaylist::script_vcpu_GetItem },
  11. {L"GetItemTitle", 1, (void*)SPlaylist::script_vcpu_GetItemTitle },
  12. {L"GetItemLength", 1, (void*)SPlaylist::script_vcpu_GetItemLength },
  13. {L"GetItemExtendedInfo", 2, (void*)SPlaylist::script_vcpu_GetItemExtendedInfo },
  14. {L"Reverse", 0, (void*)SPlaylist::script_vcpu_Reverse },
  15. {L"Swap", 2, (void*)SPlaylist::script_vcpu_Swap },
  16. {L"Randomize", 0, (void*)SPlaylist::script_vcpu_Randomize },
  17. {L"Remove", 1, (void*)SPlaylist::script_vcpu_Remove },
  18. {L"SortByTitle", 0, (void*)SPlaylist::script_vcpu_SortByTitle },
  19. {L"SortByFilename", 0, (void*)SPlaylist::script_vcpu_SortByFilename },
  20. /* TODO:
  21. {L"Append", 3, (void*)SPlaylist::script_vcpu_Append },
  22. {L"Insert", 4, (void*)SPlaylist::script_vcpu_Insert },
  23. {L"SetItemFilename", 2, (void*)SPlaylist::script_vcpu_SetItemFilename },
  24. {L"SetItemTitle", 2, (void*)SPlaylist::script_vcpu_SetItemTitle },
  25. {L"SetItemLengthMilliseconds", 2, (void*)SPlaylist::script_vcpu_SetItemLengthMilliseconds },
  26. {L"SortByDirectory", 0, (void*)SPlaylist::script_vcpu_SortByDirectory },
  27. */
  28. };
  29. // --------------------------------------------------------
  30. const wchar_t *PlaylistScriptController::getClassName()
  31. {
  32. return L"Playlist";
  33. }
  34. const wchar_t *PlaylistScriptController::getAncestorClassName()
  35. {
  36. return L"Object";
  37. }
  38. ScriptObjectController *PlaylistScriptController::getAncestorController()
  39. {
  40. return script_root;
  41. }
  42. ScriptObject *PlaylistScriptController::instantiate()
  43. {
  44. SPlaylist *xd = new SPlaylist;
  45. ASSERT( xd != NULL );
  46. return xd->getScriptObject();
  47. }
  48. void PlaylistScriptController::destroy( ScriptObject *o )
  49. {
  50. SPlaylist *xd = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  51. ASSERT( xd != NULL );
  52. delete xd;
  53. }
  54. void *PlaylistScriptController::encapsulate( ScriptObject *o )
  55. {
  56. return NULL;
  57. }
  58. void PlaylistScriptController::deencapsulate( void *o )
  59. {}
  60. int PlaylistScriptController::getNumFunctions()
  61. {
  62. return sizeof( exportedFunction ) / sizeof( function_descriptor_struct );
  63. }
  64. const function_descriptor_struct *PlaylistScriptController::getExportedFunctions()
  65. {
  66. return exportedFunction;
  67. }
  68. GUID PlaylistScriptController::getClassGuid()
  69. {
  70. return makiPlaylistGUID;
  71. }
  72. /* ---- */
  73. SPlaylist::SPlaylist()
  74. {
  75. getScriptObject()->vcpu_setInterface( makiPlaylistGUID, static_cast<SPlaylist *>( this ) );
  76. getScriptObject()->vcpu_setClassName( L"Playlist" );
  77. getScriptObject()->vcpu_setController( &playlistController );
  78. }
  79. scriptVar SPlaylist::script_vcpu_Clear( SCRIPT_FUNCTION_PARAMS, ScriptObject *o )
  80. {
  81. SCRIPT_FUNCTION_INIT;
  82. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  83. if ( playlist )
  84. {
  85. playlist->playlist.Clear();
  86. }
  87. RETURN_SCRIPT_VOID
  88. }
  89. scriptVar SPlaylist::script_vcpu_GetNumItems( SCRIPT_FUNCTION_PARAMS, ScriptObject *o )
  90. {
  91. SCRIPT_FUNCTION_INIT;
  92. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  93. if ( playlist )
  94. {
  95. size_t count = playlist->playlist.GetNumItems();
  96. return MAKE_SCRIPT_INT( (int)count );
  97. }
  98. RETURN_SCRIPT_ZERO
  99. }
  100. static wchar_t splaylist_string_return[ 1024 ];
  101. static wchar_t *splaylist_string_empty = L"";
  102. scriptVar SPlaylist::script_vcpu_GetItem( SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar itemNumber )
  103. {
  104. SCRIPT_FUNCTION_INIT;
  105. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  106. if ( playlist )
  107. {
  108. int item = GET_SCRIPT_INT( itemNumber );
  109. size_t cch = playlist->playlist.GetItem( item, splaylist_string_return, sizeof( splaylist_string_return ) / sizeof( *splaylist_string_return ) );
  110. if ( cch == 0 )
  111. return MAKE_SCRIPT_STRING( splaylist_string_empty );
  112. else
  113. return MAKE_SCRIPT_STRING( splaylist_string_return );
  114. }
  115. return MAKE_SCRIPT_STRING( splaylist_string_empty );
  116. }
  117. scriptVar SPlaylist::script_vcpu_GetItemTitle( SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar itemNumber )
  118. {
  119. SCRIPT_FUNCTION_INIT;
  120. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  121. if ( playlist )
  122. {
  123. int item = GET_SCRIPT_INT( itemNumber );
  124. size_t cch = playlist->playlist.GetItemTitle( item, splaylist_string_return, sizeof( splaylist_string_return ) / sizeof( *splaylist_string_return ) );
  125. if ( cch == 0 )
  126. return MAKE_SCRIPT_STRING( splaylist_string_empty );
  127. else
  128. return MAKE_SCRIPT_STRING( splaylist_string_return );
  129. }
  130. return MAKE_SCRIPT_STRING( splaylist_string_empty );
  131. }
  132. scriptVar SPlaylist::script_vcpu_GetItemLength( SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar itemNumber )
  133. {
  134. SCRIPT_FUNCTION_INIT;
  135. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  136. if ( playlist )
  137. {
  138. int item = GET_SCRIPT_INT( itemNumber );
  139. int length = playlist->playlist.GetItemLengthMilliseconds( item );
  140. return MAKE_SCRIPT_INT( length );
  141. }
  142. return MAKE_SCRIPT_INT( -1 );
  143. }
  144. scriptVar SPlaylist::script_vcpu_GetItemExtendedInfo( SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar itemNumber, scriptVar metadata )
  145. {
  146. SCRIPT_FUNCTION_INIT;
  147. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  148. if ( playlist )
  149. {
  150. int item = GET_SCRIPT_INT( itemNumber );
  151. const wchar_t *tag = GET_SCRIPT_STRING( metadata );
  152. size_t cch = playlist->playlist.GetItemExtendedInfo( item, tag, splaylist_string_return, sizeof( splaylist_string_return ) / sizeof( *splaylist_string_return ) );
  153. if ( cch == 0 )
  154. return MAKE_SCRIPT_STRING( splaylist_string_empty );
  155. else
  156. return MAKE_SCRIPT_STRING( splaylist_string_return );
  157. }
  158. return MAKE_SCRIPT_STRING( splaylist_string_empty );
  159. }
  160. scriptVar SPlaylist::script_vcpu_Reverse( SCRIPT_FUNCTION_PARAMS, ScriptObject *o )
  161. {
  162. SCRIPT_FUNCTION_INIT;
  163. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  164. if ( playlist )
  165. {
  166. playlist->playlist.Reverse();
  167. }
  168. RETURN_SCRIPT_VOID
  169. }
  170. scriptVar SPlaylist::script_vcpu_Swap( SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar position1, scriptVar position2 )
  171. {
  172. SCRIPT_FUNCTION_INIT;
  173. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  174. if ( playlist )
  175. {
  176. int item1 = GET_SCRIPT_INT( position1 );
  177. int item2 = GET_SCRIPT_INT( position2 );
  178. playlist->playlist.Swap( item1, item2 );
  179. }
  180. RETURN_SCRIPT_VOID
  181. }
  182. scriptVar SPlaylist::script_vcpu_Randomize( SCRIPT_FUNCTION_PARAMS, ScriptObject *o )
  183. {
  184. SCRIPT_FUNCTION_INIT;
  185. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  186. if ( playlist )
  187. {
  188. playlistManager.Randomize( &playlist->playlist );
  189. }
  190. RETURN_SCRIPT_VOID
  191. }
  192. scriptVar SPlaylist::script_vcpu_Remove( SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar itemIndex )
  193. {
  194. SCRIPT_FUNCTION_INIT;
  195. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  196. if ( playlist )
  197. {
  198. int item = GET_SCRIPT_INT( itemIndex );
  199. playlist->playlist.Remove( item );
  200. }
  201. RETURN_SCRIPT_VOID
  202. }
  203. scriptVar SPlaylist::script_vcpu_SortByTitle( SCRIPT_FUNCTION_PARAMS, ScriptObject *o )
  204. {
  205. SCRIPT_FUNCTION_INIT;
  206. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  207. if ( playlist )
  208. {
  209. playlist->playlist.SortByTitle();
  210. }
  211. RETURN_SCRIPT_VOID
  212. }
  213. scriptVar SPlaylist::script_vcpu_SortByFilename( SCRIPT_FUNCTION_PARAMS, ScriptObject *o )
  214. {
  215. SCRIPT_FUNCTION_INIT;
  216. SPlaylist *playlist = static_cast<SPlaylist *>( o->vcpu_getInterface( makiPlaylistGUID ) );
  217. if ( playlist )
  218. {
  219. playlist->playlist.SortByFilename();
  220. }
  221. RETURN_SCRIPT_VOID
  222. }