Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Winamp function/shell


  • Please log in to reply
26 replies to this topic
jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005
Background (Skip this part if you're in a hurry)
OK, I'll admit it. I have love-hate relationship with Winamp. When I starting using Winamp back in the version 2.x days (late 1990's), the program was a small, simple, and lightweight music player. I thought it was a thing of beauty. Over the years, Winamp has gone through a large number of changes (both good and bad) to become a feature-packed multi-media player.

Although the most recent versions of Winamp are bloated with extra plug-ins and junk that I don't want or need, I still like the program and use it on a daily basis. To help speed up the program, I unload most of the extraneous plug-ins. Don't get me wrong. Winamp is not my only media player. Winamp's video player is somewhat limited so I use jetAudio to play most of my video and Windows Media Player to play the tiny few formats that jetAudio doesn't support. But when comes to music, Winamp is still my player of choice.

When I started using AutoHotkey a few months back, writing code to control Winamp was a natural application. Using the examples in the AHK help file, I had some luck sending commands to Winamp (via ControlSend), but I had a lot of problems executing these commands when Winamp was active. Also, Winamp's use of multiple windows (some hidden) and window titles proved to be a pain in the butt.

Later while browsing through the forum, I stumbled on to some old posts that discuss the SendMessage commands supported by Winamp. Although not a perfect solution (not all of the commands work for all Winamp versions), the SendMessage commands proved to be a more complete solution. Here are just a few of posts (not all of them) that I found that use PostMessage/SendMessage to communicate with Winamp:

http://www.autohotke...topic.php?t=115 (The original)
http://www.autohotke...topic.php?t=177
http://www.autohotke...topic.php?t=239
http://www.autohotke...opic.php?t=2258
http://www.autohotke...opic.php?t=4612
http://www.autohotke...opic.php?t=4916The problem with using PostMessage/SendMessage command to control Winamp (or any application for that matter) is that the message parameters are very cryptic. For example, what the heck does this do?
SendMessage 0x0111,40001,,,ahk_class Winamp v1.x
If you've commented your code correctly, you would have noted that this message closes the Winamp application. You were only able to code this command by extracting it from someone else's code/posts (that's what I did) or by downloading the Winamp SDK, extracting the message information from the code, and use the AHK help file or Rajat's SendMessage tutorial to code it into AHK (did that too!)

Finally getting around to it...
To make controlling Winamp a bit easier to code for, I've written an "all inclusive" Winamp function that uses English (or any language if converted) word(s) as parameters to communicate/control Winamp. By "all inclusive", I mean that if there is anything you want to check or do with Winamp, you put into the Winamp function.

The Winamp function currently does simple window checks (if exist, if active, etc.), simple window commands, (activate, close, etc.), and some of the more popular SendMessage commands supported by Winamp. I could have included all possible commands but that would have bloated the code into an unmanageable monster so I only included the commands that I use or commands that I thought I might use in the future.

I refer to the function as a "shell" because the code was written so that anyone can be easily modify it to include any commands (or aliases) that I did not include. If you want to add a Winamp message that wasn't included, you still have to do your homework to find the appropriate message number, but the rest of the code to format and send the message should already be included.

Here are a few examples of how this this function can be used in a script:

^#!Up::Winamp("Play")  ;-- Nothing will happen if Winamp is not running.

^#!Down::
if Winamp("Exist") ;-- Winamp running?
    if Winamp("Is Playing")=1  ;-- Winamp playing? (Check to avoid Pause toggle)
           Winamp("Pause")
return

^#!Left::Winamp("Previous Track")  ;-- Go back 1 track
   
^#!Right::Winamp("Next Track")  ;-- Skip to the next track
The code is not completely mature (never will be) but I'm tired of working on it and I wanted to share it before I forget. Of course, I've only tested this code on my version of Winamp (5.11) and on my OS (XP Pro SP2) but it should work for most.

The Code
The pertinent files are as follows:
Source code: Winamp.ahk
Documentation: Included in the source code

I hope someone find this useful.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Thanks for posting your work and presenting it so clearly. Since there are times when I use Winamp heavily, I can see myself using this someday.

scusi
  • Guests
  • Last active:
  • Joined: --
Hey guys,

i'm looking for some code to delete the song which is playing from the playlist (found a lot of scripts to move the file to another directory, but not to remove it from the playlist).

Any ideas ?

jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005

Hey guys,

i'm looking for some code to delete the song which is playing from the playlist (found a lot of scripts to move the file to another directory, but not to remove it from the playlist).

Any ideas ?

These are just ideas. I haven't tried any of them.

Check out http://www.autohotke...pic.php?t=13255. If you only want to delete the song from the playlist, just remove the code that deletes the file from the hard disk.

Here's another that I think uses similar techniques: http://www.autohotke...opic.php?t=8721 (multiple posts).

If you want to accomplish the task with messages only (PostMessage/SendMessage), you'll probably want to dig into the Winamp SDK. I found some promising code in ipc_pe.h but it looked like you would need to do a bit of fancy coding to make it sing.

Them be my thoughts. Good luck!

scusi
  • Guests
  • Last active:
  • Joined: --
thanks for your suggestions.
unfortunately it didn't work...

any other ideas ?

scusi

Industry
  • Guests
  • Last active:
  • Joined: --
Have you thought of removing the file (either putting it into the recycle bin or moving it to another directory) and then sending ALT + DEL to the playlist to remove all items from the playlist that don't exist anymore? Has the same effect as selecting the song and pressing Rem -> Rem Misc -> Physically remove selected files.

automaticman
  • Members
  • 658 posts
  • Last active: Nov 20 2012 06:10 PM
  • Joined: 27 Oct 2006

SetTitleMatchMode,2



^#Left::

;;  should be a tool for DJ's or label owners/producers/A&R's who get a lot of productions or mixes and should listen to them

;;  how does it work?

;;  winamp jumps to the end of the mix/track and plays for 10 seconds and then jumps 60 seconds back in time. so you can listen to tracks/mixes from backwards to the beginning hearing always only 10 seconds regions out of 1 minute.

;;  it seems to work here, have fun with it and thanks for the Winamp functions!



if Winamp("Exist") ;-- Winamp running? 

    if Winamp("Is Playing")=1  ;-- Winamp playing? (Check to avoid Pause toggle) 

	   

	   

	Loop,1000

	{

	   Winamp("GetOutputTime",1)

		

	   Winamp("JumpToTime",0.95*Winamp("GetOutputTime",1)*1000)

	   Sleep,5000





	   Position := 0.93*Winamp("GetOutputTime",1)*1000

	   ;MsgBox Position is %Position%.

	   ;Winamp("JumpToTime",Position)

	   ;Sleep,5000

	   

	   Loop

	  	{

		 if Winamp("GetOutputTime",0)<65000

			{

				Sleep,1000

				break

			}

			

			if (Position > 3000)

				Winamp("JumpToTime",Position)

  	   		Sleep,10000

			Position -= 60000

	  	}

 	    	Winamp("NextTrack")

		Sleep,500

		Winamp("JumpToTime",0.95*Winamp("GetOutputTime",1)*1000)

	}

	

return 



HuBa
  • Members
  • 175 posts
  • Last active: Feb 13 2012 09:51 AM
  • Joined: 24 Feb 2007
Winamp 5 has global hotkey support via plugin. You can control Winamp with them easily.
You need AHK just for the special commands.

Arnoud
  • Members
  • 15 posts
  • Last active: Oct 22 2007 02:17 PM
  • Joined: 23 Mar 2007

Winamp 5 has global hotkey support via plugin. You can control Winamp with them easily.
You need AHK just for the special commands.


Special commands?

You can use it for a lot of automation as well. Using handheld remotecontrol (especially with not so supported ir-receivers) or using shortcuts (general or HID devices) at remote computers, I think there is no better solution.

automaticman
  • Members
  • 658 posts
  • Last active: Nov 20 2012 06:10 PM
  • Joined: 27 Oct 2006
Does anyone know which message to use to remove the current playing track/song from the Winamp playlist? I would like to combine this message/feature with NextTrack feature in such a way that each time I activate "jump to NextTrack" previously the current playing track should be removed from the playlist.

Explanation:
Usually the reason for jumping to the next track is that you didn't like the current playing that much (in your current mood) so by jumping to the next track the previously playing track shouldn't be anymoe in the playlist. If you continue in that way with all your other songs in your playlist you should end up with a playlist where you like all songs, which you might save for later reuse.

I could easily implement this feature by activating the playlist window. But I would prefer a solution without a window activation is necessary by sending direct messages to Winamp, so I could continue working with any other software without any window changing distractions.

jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005

Does anyone know which message to use to remove the current playing track/song from the Winamp playlist? I would like to combine this message/feature with NextTrack feature in such a way that each time I activate "jump to NextTrack" previously the current playing track should be removed from the playlist.

[snip]

I would prefer a solution without a window activation is necessary by sending direct messages to Winamp, so I could continue working with any other software without any window changing distractions.

I did some digging in the Winamp SDK and came up with the following:
;-- The information for the following message was extracted from the wa_ipc.h
;   module (Winamp SDK).

;-- This message collects the hWnd for the Playlist Editor window which is used
;   by the subsequent messages.
;
SendMessage,0x400,1,260,,ahk_class Winamp v1.x    ;-- 260=IPC_GETWND, 1=IPC_GETWND_PE
WAPEhWnd:=ErrorLevel
;;;;;msgbox WAPEhWnd=%WAPEhWnd%



;-- The information for the following messages was extracted from ipc_pe.h
;   module (Winamp SDK).

;-- This message collects the current index (relative to 0).  Note that the
;   message is sent to the Playlist Editor window, not to the main Winamp
;   window.  Also note that the order of the message parameters are not the same
;   as other Winamp messages.
;
SendMessage,0x400,100,0,,ahk_id %WAPEhWnd%        ;-- 100=IPC_PE_GETCURINDEX
CURINDEX=%ErrorLevel%
;;;;;msgbox CURINDEX=%CURINDEX%



;-- This message deletes the specified guy from from the playlist.  If
;   successful, the ErrorLevel will be 0.
;
SendMessage,0x400,104,CURINDEX,,ahk_id %WAPEhWnd% ;-- 104=IPC_PE_DELETEINDEX
msgbox Delete message sent.  ErrorLevel=%ErrorLevel%
return
I haven't done extensive testing on this so please use with care.

The messages used in this example are not currently defined in the Winamp function but they could be added without too much difficulty.

Good luck!

automaticman
  • Members
  • 658 posts
  • Last active: Nov 20 2012 06:10 PM
  • Joined: 27 Oct 2006
Thanks jballi,

I appriciate your effort and help really, it seems to solve my problem. When combined immediately after that with

Winamp("NextTrack")

there seem to be no problems also index-wise... which I already wanted to use in this way. (For other uses there might be eventually some problems with the next index not being defined in some conditions.)

Your help increases my Winamp listening pleasure a little more.
Thanks man!!! (I hope you make use of my suggestion above, too?)

automaticman
  • Members
  • 658 posts
  • Last active: Nov 20 2012 06:10 PM
  • Joined: 27 Oct 2006
Can we get with this library also the path+file name of the playing song in Winamp? (Right now I'm opening the file info box first with Alt-3, getting control Edit19 there, closing this info box) A faster method without opening this info box would be nicer.

jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005

Can we get with this library also the path+file name of the playing song in Winamp? (Right now I'm opening the file info box first with Alt-3, getting control Edit19 there, closing this info box) A faster method without opening this info box would be nicer.

The message that you want is IPC_GETPLAYLISTFILE (211 or 0xD3). However, this message returns a pointer that is only valid inside of Winamp's memory space. The information can be accessed via AutoHotkey but it requires some mad programming skills (well above my security level).

Lucky for us, Chris solved this problem a while back (2005) in this post: http://www.autohotke...p?p=22158#22158. Just change 0xD4 to 0xD3 (or 211) and it should get you where you need to go.

I hope this helps.

grossermanitu
  • Guests
  • Last active:
  • Joined: --
Hi I dont know if I get it right. Do I need the attached script of jballi of running in my bakround to controll winamp?

I just want to send a "Stop" command to Winamp. Actually I only need one line that includes the stop command.

Can anybody help me? Thanks.