titlefader.cc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**
  2. *
  3. * Copyright (c) 2002, Marc Bruenink
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * 3. Neither the name of the author nor the names of his contributors may be
  16. * used to endorse or promote products derived from this software without
  17. * specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #include <ostream.h>
  32. #include <cstdlib>
  33. #include <string.h>
  34. #include <gtk-1.2/gtk/gtk.h>
  35. #include <xmms/plugin.h>
  36. #include <xmms/xmmsctrl.h>
  37. #include <xmms/util.h>
  38. // my includes
  39. #include "Xlib_textfader.cc"
  40. #include "configuration.h"
  41. #include "myhelpfunctions.h"
  42. #define VERSION "0.4.7"
  43. extern "C" void init();
  44. extern "C" void about();
  45. extern "C" void configure();
  46. extern "C" void cleanup();
  47. extern "C" GeneralPlugin *get_gplugin_info();
  48. GeneralPlugin plugin = { NULL,
  49. NULL,
  50. -1,
  51. "Title Fader Plugin "VERSION,
  52. init,
  53. about,
  54. configure,
  55. cleanup};
  56. gint iTimeout;
  57. int timeoutFunction(gpointer);
  58. gchar *cLastTitle = NULL;
  59. Xlib_textfader *fader;
  60. Config conf;
  61. extern "C" {
  62. void init() {
  63. iTimeout = gtk_timeout_add(50, timeoutFunction, NULL);
  64. fader = new Xlib_textfader();
  65. ;
  66. }// end init()
  67. void about() {
  68. xmms_show_message("Title Fader Plugin", "This xmms plugin blends the title of new songs on screen.\n\n send all complaints & suggestions to:\nfidor@users.sourceforge.net\n\nhttp://xmms-titlefader.sourceforge.net", "OK", TRUE, NULL, NULL);
  69. }// end about()
  70. void configure() {
  71. // delete conf;
  72. //static Config conf;
  73. // conf = new Config();
  74. conf.show();
  75. }//end configure()
  76. void cleanup() {
  77. if(iTimeout){
  78. gtk_timeout_remove(iTimeout);
  79. }
  80. if (cLastTitle != NULL) {
  81. g_free(cLastTitle);
  82. cLastTitle = NULL;
  83. }
  84. delete fader;
  85. }//endcleanup()
  86. GeneralPlugin *get_gplugin_info(void)
  87. {
  88. return &plugin;
  89. }
  90. } // end extern
  91. int timeoutFunction(gpointer gpData){
  92. if (xmms_remote_is_playing(plugin.xmms_session) == TRUE) {
  93. gchar *cBuffer = NULL;
  94. cBuffer = xmms_remote_get_playlist_title(plugin.xmms_session, xmms_remote_get_playlist_pos(plugin.xmms_session));
  95. // print title
  96. if (cLastTitle != NULL) {
  97. if ( strcmp(cBuffer, cLastTitle) != 0) {
  98. fader->set_text_color(conf.col_selected[0], conf.col_selected[1], conf.col_selected[2]);
  99. fader->set_font(conf.font_selected);
  100. fader->set_fade_position(conf.hWinScalePos,conf.vWinScalePos);
  101. fader->fade(cBuffer, getCharLength(cBuffer)-1, conf.frameScalePos, conf.fadeOptions);
  102. }
  103. }
  104. else {
  105. fader->set_text_color(conf.col_selected[0], conf.col_selected[1], conf.col_selected[2]);
  106. fader->set_font(conf.font_selected);
  107. fader->set_fade_position(conf.hWinScalePos,conf.vWinScalePos);
  108. fader->fade(cBuffer, getCharLength(cBuffer)-1, conf.frameScalePos, conf.fadeOptions);
  109. }
  110. // strcpy(cLastTitle, cBuffer);
  111. if(cLastTitle != NULL) {
  112. g_free(cLastTitle);
  113. cLastTitle = NULL;
  114. }
  115. cLastTitle = strdup(cBuffer);
  116. // save old values
  117. if (cBuffer != NULL){
  118. g_free(cBuffer);
  119. cBuffer=NULL;
  120. }
  121. }// end if playing
  122. return TRUE;
  123. } // end timeout()