coreactions.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #include <precomp.h>
  2. #include "coreactions.h"
  3. #include <api/config/items/cfgitem.h>
  4. #include <api/core/buttons.h>
  5. #include <api/api.h>
  6. #include <api/core/corehandle.h>
  7. #include <api/service/svcs/svc_player.h>
  8. #include <api/locales/xlatstr.h>
  9. CoreActions::CoreActions() {
  10. registerAction("prev", ACTION_PREV);
  11. registerAction("play", ACTION_PLAY);
  12. registerAction("pause", ACTION_PAUSE);
  13. registerAction("stop", ACTION_STOP);
  14. registerAction("next", ACTION_NEXT);
  15. registerAction("eject", ACTION_EJECT);
  16. registerAction("eject_url", ACTION_EJECTURL);
  17. registerAction("eject_dir", ACTION_EJECTDIR);
  18. registerAction("seek", ACTION_SEEK);
  19. registerAction("volume", ACTION_VOLUME);
  20. registerAction("pan", ACTION_PAN);
  21. registerAction("volume_up", ACTION_VOLUME_UP);
  22. registerAction("volume_down", ACTION_VOLUME_DOWN);
  23. registerAction("rewind_5s", ACTION_REWIND_5S);
  24. registerAction("ffwd_5s", ACTION_FFWD_5S);
  25. registerAction("toggle_repeat", ACTION_TOGGLE_REPEAT);
  26. registerAction("toggle_shuffle", ACTION_TOGGLE_SHUFFLE);
  27. registerAction("toggle_crossfader", ACTION_TOGGLE_CROSSFADER);
  28. registerAction("mute", ACTION_MUTE);
  29. registerAction("eq_preamp", ACTION_EQ_PREAMP);
  30. registerAction("eq_band", ACTION_EQ_BAND);
  31. registerAction("eq_auto", ACTION_EQ_AUTO);
  32. registerAction("eq_reset", ACTION_EQ_RESET);
  33. registerAction("toggle_repeat", ACTION_TOGGLE_REPEAT);
  34. registerAction("toggle_shuffle", ACTION_TOGGLE_SHUFFLE);
  35. registerAction("toggle_crossfader", ACTION_TOGGLE_CROSSFADER);
  36. registerAction("eq_toggle", ACTION_EQ_TOGGLE);
  37. for (int i=0;i<4;i++)
  38. registerAction(StringPrintf("play_cd%d", i+1), ACTION_PLAY_CD+i);
  39. }
  40. CoreActions::~CoreActions() {
  41. }
  42. int CoreActions::onActionId(int pvtid, const char *action, const char *param/* =NULL */, int p1/* =0 */, int p2/* =0 */, void *data/* =NULL */, int datalen/* =0 */, api_window *source/* =NULL */) {
  43. int d = ATOI(param);
  44. CoreHandle ch("main");
  45. switch(pvtid) {
  46. case ACTION_PREV: { if (d==0) ch.prev(); } break;
  47. case ACTION_PLAY: { if (d==0) ch.play(); } break;
  48. case ACTION_PAUSE: { if (d==0) ch.pause(); } break;
  49. case ACTION_STOP: { if (d==0) ch.stop(); } break;
  50. case ACTION_NEXT: { if (d==0) ch.next(); } break;
  51. case ACTION_EJECT: {
  52. svc_player *sp = SvcEnumByGuid<svc_player>();
  53. if (d == 0) {
  54. if (sp) sp->openFiles(source, "files");
  55. } else {
  56. if (sp) sp->openFiles(source);
  57. }
  58. WASABI_API_SVC->service_release(sp);
  59. }
  60. break;
  61. case ACTION_EJECTURL: if (d==0) {
  62. svc_player *sp = SvcEnumByGuid<svc_player>();
  63. if (sp) sp->openFiles(source, "location");
  64. api->service_release(sp);
  65. }
  66. break;
  67. case ACTION_EJECTDIR: if (d==0) {
  68. svc_player *sp = SvcEnumByGuid<svc_player>();
  69. if (sp) sp->openFiles(source, "directory");
  70. api->service_release(sp);
  71. }
  72. break;
  73. case ACTION_VOLUME_UP: if (d==0) {
  74. int v=ch.getVolume();
  75. ch.setVolume(MIN(255,(v+5)));
  76. }
  77. break;
  78. case ACTION_VOLUME_DOWN: if (d==0) {
  79. int v=ch.getVolume();
  80. ch.setVolume(MAX(0,(v-5)));
  81. }
  82. break;
  83. case ACTION_REWIND_5S: if (d==0) {
  84. int p=ch.getPosition();
  85. ch.setPosition(MAX(0,(p-5000)));
  86. }
  87. break;
  88. case ACTION_FFWD_5S: if (d==0) {
  89. int p=ch.getPosition();
  90. int mp=ch.getLength();
  91. ch.setPosition(MIN(mp,(p+5000)));
  92. }
  93. break;
  94. case ACTION_EQ_AUTO:
  95. if (d==0) ch.setEqAuto(!ch.getEqAuto());
  96. break;
  97. case ACTION_EQ_RESET: {
  98. if (d==0) for(int i=0;i<10;i++) ch.setEqBand(i,0);
  99. }
  100. break;
  101. case ACTION_EQ_TOGGLE: if (d==0) ch.setEqStatus(!ch.getEqStatus()); break;
  102. case ACTION_MUTE: if (d==0) {
  103. ch.setMute(!ch.getMute());;
  104. }
  105. break;
  106. case ACTION_TOGGLE_REPEAT:
  107. case ACTION_TOGGLE_SHUFFLE: if (d==0) {
  108. // {45F3F7C1-A6F3-4ee6-A15E-125E92FC3F8D}
  109. const GUID pledit_guid =
  110. { 0x45f3f7c1, 0xa6f3, 0x4ee6, { 0xa1, 0x5e, 0x12, 0x5e, 0x92, 0xfc, 0x3f, 0x8d } };
  111. CfgItem *pli=WASABI_API_CONFIG->config_getCfgItemByGuid(pledit_guid);
  112. if(pli) {
  113. if(pvtid==ACTION_TOGGLE_REPEAT) pli->setDataAsInt("Repeat",!pli->getDataAsInt("Repeat"));
  114. if(pvtid==ACTION_TOGGLE_SHUFFLE) pli->setDataAsInt("Shuffle",!pli->getDataAsInt("Shuffle"));
  115. }
  116. }
  117. break;
  118. case ACTION_TOGGLE_CROSSFADER: if (d==0) {
  119. // {FC3EAF78-C66E-4ED2-A0AA-1494DFCC13FF}
  120. const GUID xfade_guid =
  121. { 0xFC3EAF78, 0xC66E, 0x4ED2, { 0xA0, 0xAA, 0x14, 0x94, 0xDF, 0xCC, 0x13, 0xFF } };
  122. CfgItem *pli=WASABI_API_CONFIG->config_getCfgItemByGuid(xfade_guid);
  123. if(pli) pli->setDataAsInt("Enable crossfading",!pli->getDataAsInt("Enable crossfading"));
  124. }
  125. break;
  126. }
  127. if (pvtid >= ACTION_PLAY_CD && pvtid < ACTION_PLAY_CD+16) if (d==0) {
  128. const GUID cdda_guid =
  129. { 0x86b40069, 0x126f, 0x4e11, { 0xa8, 0x7f, 0x55, 0x8f, 0xfa, 0x3d, 0xff, 0xa8 } };
  130. #if 0//BU: need some api to send messages like this
  131. ComponentManager::sendNotify(cdda_guid, 12345, pvtid-ACTION_PLAY_CD);
  132. #endif
  133. }
  134. return 1;
  135. }
  136. const char *CoreActions::getHelp(int action) {
  137. static String name;
  138. switch (action) {
  139. case ACTION_PREV: name = _("Previous track"); break;
  140. case ACTION_PAUSE: name = _("Pause/Resume playback"); break;
  141. case ACTION_STOP: name = _("Stop playback"); break;
  142. case ACTION_NEXT: name = _("Next track"); break;
  143. case ACTION_EJECT: name = _("Load file"); break;
  144. case ACTION_EJECTURL: name = _("Load URL"); break;
  145. case ACTION_EJECTDIR: name = _("Load directory"); break;
  146. case ACTION_SEEK: name = _("Seek"); break;
  147. case ACTION_VOLUME: name = _("Volume"); break;
  148. case ACTION_PAN: name = _("Panning"); break;
  149. case ACTION_EQ_TOGGLE: name = _("Toggle equalizer"); break;
  150. case ACTION_EQ_PREAMP: name = _("Toggle preamplifier"); break;
  151. case ACTION_EQ_BAND: name = _("Change equalizer band"); break;
  152. case ACTION_EQ_AUTO: name = _("Auto equalizer"); break;
  153. case ACTION_EQ_RESET: name = _("Reset equalizer"); break;
  154. case ACTION_VOLUME_UP: name = _("Volume up"); break;
  155. case ACTION_VOLUME_DOWN: name = _("Volume down"); break;
  156. case ACTION_REWIND_5S: name = _("Rewind 5 seconds"); break;
  157. case ACTION_FFWD_5S: name = _("Fast forward 5 seconds"); break;
  158. case ACTION_MUTE: name = _("Mute/Unmute sound"); break;
  159. case ACTION_TOGGLE_REPEAT: name = _("Toggle repeat"); break;
  160. case ACTION_TOGGLE_SHUFFLE: name = _("Toggle shuffle"); break;
  161. case ACTION_TOGGLE_CROSSFADER: name = _("Toggle crossfader"); break;
  162. }
  163. return name;
  164. }