Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: how to get the playlist number of selected files (Read 3128 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

how to get the playlist number of selected files

This is my code:

Quote
class contextmenu_test : public menu_item_context
{
public:
   virtual int get_num_items()
   {
  return 1;
   }

   virtual const char * enum_item(int n)
   {
  if (n==0) return "test";
  else return 0;
   }
   
   virtual void context_command(int n,const ptr_list_base<metadb_handle> & data,bool is_playlist)
   {
  g_activate();

  string8 temp = "selcount: ";
  temp.add_int(data.get_count());
  uSendDlgItemMessageText(g_wnd,  IDC_LIST, LB_ADDSTRING, 0, temp);

  for (int i = 0; i < (int) data.get_count(); i++)
  {
  metadb_handle * handle = data.get_item(i);
 
  string8 temp;
  handle->handle_format_title(temp,"%_playlist_number% %_filename%",0);
  uSendDlgItemMessageText(g_wnd, IDC_LIST, LB_ADDSTRING, 0, temp);
  }
   }
};



The problem is that %tracknumber%  returns "?" and not the actually tracknumber. What am I doing wrong?

I guess the Problem is on my side because i'm playing around with the SDK just for a couple of days and don't understand all of that stuff. I searched through the example plugins but none of them are using such a function.

edit: i mean %_playlist_number% not %TRACKNUMBER%

how to get the playlist number of selected files

Reply #1
use: $num(%tracknumber%,2) instead.

how to get the playlist number of selected files

Reply #2
Actually, if you want to get the number of the track in the playlist (reffering to the title of the thread), you should use: "$num(%_playlist_number%,3)".

"$num(%tracknumber%,2)" will display the tracknumber (as in album), not the number of the track in the playlist.

edit: typo

edit2: 

Sorry, it seems that the information I gave you won't solve your problem.

 

how to get the playlist number of selected files

Reply #3
Has been explained on IRC already but I'll post it again for future reference.
metadb_handle objects you get in contextmenu aren't "aware" of their location in playlist. In order to use %_playlist_number%, you need to call playlist_oper::get()->format_title(). Whenever your contextmenu is called with "context_is_playlist" set to true, items you've got should be same as currently selected playlsit items, so you can ignore them and use playlist API instead to perform your action.
Microsoft Windows: We can't script here, this is bat country.