SendToWinamp script

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: SendToWinamp script

Using IPC to add songs.

by saivert » Fri Jun 17, 2005 5:17 pm

Using IPC to add songs.

I think Winamp supports an IPC method to let external applications add songs to the playlist via IPC messages.

Following taken from wa_ipc.h C header file:

Code: Select all

#define IPC_ENQUEUEFILE 100 
/* sent as a WM_COPYDATA, with IPC_PLAYFILE as the dwData, and the string to play
** as the lpData. Just enqueues, does not clear the playlist or change the playback
** state.
*/
You would then do this in C:

Code: Select all

COPYDATASTRUCT cds;
cds.dwData = IPC_PLAYFILE;
cds.lpData = pSong; //variable which holds a pointer to songfilename
cds.cwData = strlen(pSong);
HWND hwnd_winamp = FindWindow("Winamp v1.x", NULL);
if (IsWindow(hwnd_winamp)) {
  int result = SendMessage(hwnd_winamp, WM_COPYDATA, (WPARAM)hwnd_mediamonkey, (LPARAM)&cds);
}

by W. Kyle White » Sun May 01, 2005 12:54 am

Peke wrote:;) May I suggest something. You better use File By File Add Too Winamp reather than all at once.
Are you talking about sending a new enqueue command for each file? If you'd like I could past my original script as I think it used this method. Since it takes over a half second for each command to be sent I "tweaked" this one to append as many songs to the command as it could, flushing by sending the command before the string gets too long (MaxCommandLength, which is set to 1000). It doesn't seem to have any problems, but if someone had a directory structure where a SINGLE FILE's path was over 1000 characters than it may be truncated and cause a problem.

by Peke » Sat Apr 30, 2005 6:49 pm

;) May I suggest something. You better use File By File Add Too Winamp reather than all at once.

by W. Kyle White » Sat Apr 30, 2005 1:41 pm

Oops, needed to flush the command one last time, here's the corrected script

Code: Select all

'SendToWinamp for MediaMonkey - Created by W. Kyle White 4/30/05 
'To install this script simply put it into the "scripts\auto" subdirectory of MediaMonkey 
'When you next start MediaMonkey you will be able to right click on the Track List or the Playlist and 
'select "Play in Winamp" or "Enqueue in Winamp" for the selected songs 
'If no song is selected then the entire list will be played/enqueued 
'This script may require modification if winamp is not in it's default directory 
'If path names are VERY long (> 1000 characters at least) then this program may not function due to 
'limitations on the length of commands being sent via the shell 
' 
' 
'Rights & Regards: 
'Script adapted from original Song Monitor/Previewer DJ Tool script by peke: 
'http://www.mediamonkey.com/forum/viewtopic.php?t=2432 
'Idea from howi: http://www.mediamonkey.com/forum/viewtopic.php?t=2712 
'This script is free for any form of personal use or modification 
'Use at your own risk, this script has not been throughly debugged 
'The author takes no responsibility for any harm or loss of data caused by this script 


WinampEXE = Chr(34)&"c:\Program Files\Winamp\Winamp.exe"&Chr(34) 
MaxCommandLength = 1000 


Sub onStartUp 
'                  This places commands in the tracklist context menu 

   Dim POPSWinamp 
   Set POPSWinamp = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_TrackList,0,-3) 
   POPSWinamp.Caption = "Play in Winamp" 
   POPSWinamp.OnClickFunc = "kwPlayWinamp" 
   POPSWinamp.UseScript = Script.ScriptPath 
   POPSWinamp.IconIndex = 14 
    
   Dim POPSPreview 
   Set POPSPreview = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_TrackList,0,-3) 
   POPSPreview.Caption = "Enqueue in Winamp" 
   POPSPreview.OnClickFunc = "kwEnqueueWinamp" 
   POPSPreview.UseScript = Script.ScriptPath 
   POPSPreview.IconIndex = 16 
    
'                  This places commands in the playlist context menu 
    
   Dim POPSWinamp2 
   Set POPSWinamp2 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_NP,0,-3) 
   POPSWinamp2.Caption = "Play in Winamp" 
   POPSWinamp2.OnClickFunc = "kwPlayWinamp" 
   POPSWinamp2.UseScript = Script.ScriptPath 
   POPSWinamp2.IconIndex = 14 
    
   Dim POPSPreview2 
   Set POPSPreview2 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_NP,0,-3) 
   POPSPreview2.Caption = "Enqueue in Winamp" 
   POPSPreview2.OnClickFunc = "kwEnqueueWinamp" 
   POPSPreview2.UseScript = Script.ScriptPath 
   POPSPreview2.IconIndex = 16 

End Sub 







Sub kwPlayWinamp(arg) 
   kwRunCommand("") 
End Sub 

Sub kwEnqueueWinamp(arg) 
  kwRunCommand("/ADD") 
End Sub 








Function kwRunCommand(inCommand) 
   Dim WShell, Result, Command, Song, Path, list, i 


   Set list = SDB.SelectedSongList 
   If list.count = 0 Then 
      Set list = SDB.AllVisibleSongList 
      If list.count = 0 Then 
         Result = SDB.MessageBox("There are no songs to send.", mtError, Array(mbOK)) 
         Exit Function 
      End If 
   End If 
   Set WShell = CreateObject("WScript.Shell")     
   Command = WinampEXE&" "&inCommand 

   For i=0 To list.count-1 
      Set Song = list.item(i) 
      If (Song.Cached = 1) Then 
         Path = Chr(34)&Song.CachedPath&Chr(34) 
      ElseIf Not(Left(Song.Path,1) = "?") Then 
         Path = Chr(34)&Song.Path&Chr(34) 
      Else 
         Path = "" 
         Result = SDB.MessageBox( Song.Title&" is not available... Continue?", mtConfirmation, Array(mbYes, mbNo)) 
         If (Result = mrNo) Then 
            Exit Function 
         End If 
      End If 
      If (len(Command) + len(Path) > MaxCommandLength) Then 
'Debugging: Uncomment the next part to read and confirm the commands being sent to winamp 
'         Result = SDB.MessageBox("Sending command: "&Command, mtConfirmation, Array(mbYes, mbNo)) 
'         If (Result = mrNo) Then 
'            Exit Function 
'         Else 
'                  Flush the command and start up again with a command to enqueue the next songs             Result = WShell.Run(Command, 1, 1) 
'         End If 
         Command = WinampEXE&" /ADD" 
      End If 
      Command = Command&" "&Path 
   Next 
Result = WShell.Run(Command, 1, 1)
End Function 

SendToWinamp script

by W. Kyle White » Sat Apr 30, 2005 1:31 pm

I've adapted a script by Peke to add context menu items to send selected songs to winamp via "play" or "enqueue". The context menu works for the track list and the now playing sections. While I prefer to use MediaMonkey for playing music, I've found that some winamp plugins don't work or don't quite work (some vis plugins won't fullscreen). I use MediaMonkey most of the time but there are some times I'd like to organize a playlist with mediamonkey and then send it to winamp so I can leave it running with some DSP and VIS plugins going. Since I got tired of editing the options panel I adapted this script from peke and howi

Code: Select all

'SendToWinamp for MediaMonkey - Created by W. Kyle White 4/30/05
'To install this script simply put it into the "scripts\auto" subdirectory of MediaMonkey
'When you next start MediaMonkey you will be able to right click on the Track List or the Playlist and
'select "Play in Winamp" or "Enqueue in Winamp" for the selected songs
'If no song is selected then the entire list will be played/enqueued
'This script may require modification if winamp is not in it's default directory
'If path names are VERY long (> 1000 characters at least) then this program may not function due to
'limitations on the length of commands being sent via the shell
'
'
'Rights & Regards:
'Script adapted from original Song Monitor/Previewer DJ Tool script by peke:
'http://www.mediamonkey.com/forum/viewtopic.php?t=2432
'Idea from howi: http://www.mediamonkey.com/forum/viewtopic.php?t=2712
'This script is free for any form of personal use or modification
'Use at your own risk, this script has not been throughly debugged
'The author takes no responsibility for any harm or loss of data caused by this script


WinampEXE = Chr(34)&"c:\Program Files\Winamp\Winamp.exe"&Chr(34)
MaxCommandLength = 1000


Sub onStartUp
'						This places commands in the tracklist context menu

	Dim POPSWinamp 
	Set POPSWinamp = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_TrackList,0,-3) 
	POPSWinamp.Caption = "Play in Winamp" 
	POPSWinamp.OnClickFunc = "kwPlayWinamp" 
	POPSWinamp.UseScript = Script.ScriptPath 
	POPSWinamp.IconIndex = 14 
	
	Dim POPSPreview 
	Set POPSPreview = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_TrackList,0,-3) 
	POPSPreview.Caption = "Enqueue in Winamp" 
	POPSPreview.OnClickFunc = "kwEnqueueWinamp" 
	POPSPreview.UseScript = Script.ScriptPath 
	POPSPreview.IconIndex = 16 
	
'						This places commands in the playlist context menu
	
	Dim POPSWinamp2 
	Set POPSWinamp2 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_NP,0,-3) 
	POPSWinamp2.Caption = "Play in Winamp" 
	POPSWinamp2.OnClickFunc = "kwPlayWinamp" 
	POPSWinamp2.UseScript = Script.ScriptPath 
	POPSWinamp2.IconIndex = 14 
	
	Dim POPSPreview2 
	Set POPSPreview2 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_NP,0,-3) 
	POPSPreview2.Caption = "Enqueue in Winamp" 
	POPSPreview2.OnClickFunc = "kwEnqueueWinamp" 
	POPSPreview2.UseScript = Script.ScriptPath 
	POPSPreview2.IconIndex = 16 

End Sub 







Sub kwPlayWinamp(arg)
	kwRunCommand("")
End Sub

Sub kwEnqueueWinamp(arg) 
  kwRunCommand("/ADD")
End Sub








Function kwRunCommand(inCommand) 
	Dim WShell, Result, Command, Song, Path, list, i


	Set list = SDB.SelectedSongList
	If list.count = 0 Then 
		Set list = SDB.AllVisibleSongList
		If list.count = 0 Then
			Result = SDB.MessageBox("There are no songs to send.", mtError, Array(mbOK))
			Exit Function
		End If
	End If
	Set WShell = CreateObject("WScript.Shell") 	
	Command = WinampEXE&" "&inCommand

	For i=0 To list.count-1
		Set Song = list.item(i) 
		If (Song.Cached = 1) Then
			Path = Chr(34)&Song.CachedPath&Chr(34)
		ElseIf Not(Left(Song.Path,1) = "?") Then 
			Path = Chr(34)&Song.Path&Chr(34)
		Else
			Path = ""
			Result = SDB.MessageBox( Song.Title&" is not available... Continue?", mtConfirmation, Array(mbYes, mbNo)) 
			If (Result = mrNo) Then
				Exit Function
			End If
		End If
		If (len(Command) + len(Path) > MaxCommandLength) Then
'Debugging: Uncomment the next part to read and confirm the commands being sent to winamp
'			Result = SDB.MessageBox("Sending command: "&Command, mtConfirmation, Array(mbYes, mbNo))
'			If (Result = mrNo) Then
'				Exit Function
'			Else
				Result = WShell.Run(Command, 1, 1)
'			End If
'						Flush the command and start up again with a command to enqueue the next songs
			Command = WinampEXE&" /ADD" 
		End If
		Command = Command&" "&Path
	Next
End Function
A couple known issues are that when the command forces winamp to open than some of the songs won't be added because they're sent while winamp is busy. Also, very long path names (> 1000 characters per file path) will break this program due to limitations on shell commands (limited to ~1024 characters?).

btw, I'm more of a C++/Java guy, I'm kinda just throwing this together so feel free to comment/modify.[/code]

Top