foo. bar. baz. quux.

Template:Foobar2000:Hooks

From WikiBazQuux

Revision as of 15:47, 8 May 2007; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

foo_cwb_hooks is a collection of utilities.

  • Adds various functions and variables to global title formatting
  • Masstagger action: "Stamp Current Date and Time"
  • New File Tagger - Ability to run a script on files added to the media library
  • Tagger Window - Columns UI panel for tagging files

Contents

Functions

  • $cwb_urldecode / $cwb_httpclean - decodes characters in URLs
  • $cwb_removethe - removes The and A at the beginning of a string
  • $cwb_ltrim - example: $cwb_ltrim(%artist%,The) $cwb_ltrim(%artist%,The ,A ,La )
  • $cwb_datediff(d1,d2) - number of days between two dates in the format yyyy-mm-dd or yyyy-mm-dd hh:mm:ss
  • $cwb_hms(n) converts a time in seconds into hh:mm:ss
  • $cwb_wdhms(n) - weeks, days, hours, minutes, seconds
  • $cwb_splitnum(n) - converts "12345678" to "12 345 678". optional second paramater can be delimiter (i.e. comma for comma separated)
  • $cwb_fileexists(filename) - returns whether a file exists. useful for determining whether albumart file exists.
    • example: $cwb_fileexists($replace(%_path%,%_filename_ext%,)folder.jpg)

Variables

  • %cwb_systemdate% - date in the formay yyyy-mm-dd
  • %cwb_systemdatetime% - date and time in the format yyyy-mm-dd hh:mm:ss
  • %cwb_activelist% - active playlist name
  • %cwb_activelist_count% - number of items in the active list
  • %cwb_activelist_duration% - seconds
  • %cwb_playinglist% - playing playlist name
  • %cwb_playinglist_count% - number of items in the playing list
  • %cwb_playinglist_duration% - seconds
  • %cwb_queueindex% - queueindex if in the queue, false otherwise
  • %cwb_queueindexes% - indices of the item in the queue, false otherwise
  • %cwb_queuelength% - length of the queue
  • %cwb_queue_end_playlist% - playlist of the last item in the queue
  • %cwb_next_title% - title of the next song in the playlist of the playing item or the next item in the queue
  • %cwb_next_artist% - artist of the next song in the playlist of the playing item or the next item in queue
  • %cwb_next_user1% - user definable string for next track (default %album%)
  • %cwb_next_user2% - user definable string for next track (default %path%)
  • %cwb_playback_order%
  • %cwb_stopaftercurrent%
  • %cwb_followcursor%
  • %cwb_volume%
  • %cwb_selection_duration% - in seconds
  • %cwb_playback_state% - stop, play, pause
  • %cwb_playing_index% (1 based)

Known Bugs

  • playlist order not available until a song is played

Not Bugs

  • When items such as %cwb_activelist% and other non-file specific changes happen, some components might not be refreshed because there is no mechanism in the SDK for telling other components to refresh. cwb_hooks adds a callback that other components can implement to allow them to get notified when a variable changes. If the component you are using does not refresh when cwb_hooks variables change, you might consider requesting this feature from the components author. Terrestrial, the author of the foo_track_info_mod and single_column_playlist has already agreed to support this when he had a chance.

Feature Requests

Please do not request any new features along the lines of %cwb_next_*%. Most of them are not possible.

  • wildcards in cwb_fileexists
  • Add following functions:
    • $cwb_foobar2000_path, $cwb_foobar2000_drive, %cwb_activelist_filesize%, %cwb_selection_filesize%
    • $cwb_systemdate that works with win32 filetimes
  • Add variables for the following:
    • selection index
    • play time start
    • last played, currently playing
    • %_replaygain_mode% - not really possible
    • %_database% - gives back if a file belongs to database or not
      • not easily possibe because you cannot use SDK functions in the title formatting callback
      • only way I could see to do it is to cache the library and test against that

Useful Strings

'Played Today', 'Played Yesterday', 'Played n days ago' or 'No last played info' 

$if(%last_played%, $puts(diff,$cwb_datediff(%last_played%,%cwb_systemdate%)) Played $ifgreater(1,$get(diff),Today, $ifgreater(2,$get(diff),Yesterday, $get(diff) days ago)), No last played info)

Developer Information

As of version 1.0.9 foo_cwb_hooks implements a service to notify other components of changes to its variables, so that they can refresh their display if necessary. Notification is done inside of a main_thread_callback.

To use this functionality, declare the service using the following code. Note that The const char * parameter in on_var_change is the name of the variable that has changed, which can be scanned for in your formatting string to see if your display needs updating. Note that is some cases it might not be the exact variable, but for example cwb_next_ when cwb_next_artist, cwb_next_title, etc change.

class NOVTABLE titleformatting_variable_callback : public service_base 
{
public:
   virtual void on_var_change( const char * var ) = 0;

   FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(titleformatting_variable_callback);
};

const GUID titleformatting_variable_callback::class_guid = 
{ 0xfcb81645, 0xe7b2, 0x4bc1, { 0x92, 0xb0, 0xf6, 0xfb, 0x4b, 0x43, 0x70, 0xe3 } };

here's a sample implementation that just prints out the name of the variable that has been changed.

class sample_callback : public titleformatting_variable_callback
{
public:
   void on_var_change( const char * var )
   {
      console::printf( "sample_callback: %s", var );
   }
};
service_factory_single_t<sample_callback> g_sample_callback;
Personal tools