Winamp Scripting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • shaneh
    Major Dude
    • Jan 2004
    • 1193

    I have some web space and domains etc, but just lack of time to do up a site properly.

    A weighted shuffle wouldnt be impossible, just require a bit of work. The rating info isnt that difficult to extract if its stored in the media library, just do a query and look at the ratings, playcount last played etc and work with that.

    The easiest way to do it is probably to turn shuffle off, then fill the playlist with items based on whatever algorithm you choose. The algorithm would be the most difficult part.

    Otherwise you can do a sort of 'party shuffle' thing, where you just have a few items in the playlist, and add new ones as the songs change.

    You can get media library items by simply doing:

    mlitems = MediaLibrary.RunQueryArray("Rating > 0")
    'sort mlitems based on criteria
    for each song in mlitems
    song.enqueue
    next

    As you can see, the algorithm to sort/mix/whatever the items would be the most difficult part.

    I have a sort of weighted shuffle thing I picked up somewhere a while back. Dont think it works too well, but you can take a look at it:

    Dim songlist(), i, rndtotal, lasttrack
    Randomize

    Sub Application_ChangedTrack
    playlist.deleteindex playlist.position - 1

    ReDim songlist(playlist.count - 1)
    i = 0
    for each song in playlist
    songlist(i) = song.rating
    i = i + 1
    next

    i = 0
    ratingtotal = 0

    'calc average
    for each song in songlist
    ratingtotal = ratingtotal + songlist(i)
    i = i + 1
    next
    ratingavg = Int(ratingtotal / ubound(songlist))
    i = 0
    rndtotal = 0
    for each songr in songlist
    if songlist(i) = 0 Then
    songlist(i) = ratingavg
    End if
    rndtotal = rndtotal + songlist(i)
    i = i + 1
    next

    rval = Int((rndtotal - 0 + 1) * Rnd + 0)
    runningtot = 0
    i = 0
    for each songr in songlist
    i = i + 1
    runningtot = runningtot + songr
    if runningtot >= rval Then
    playlist.position = i
    play
    lasttrack = i
    exit for
    end if
    next
    End Sub
    Music Plugins

    Comment

    • Crestronite
      Junior Member
      • Jan 2005
      • 6

      A real newbie Q. I am trying somewhat succesfully to use ActiveWinamp from VB6. Most things are working but I wish to add a named file eg "C:\test.mp3" to a specific place in the playlist and then go on to manipulate the playlist position so it is played, and then delete it and resume. So adding to the end will be fine.I really don't want that track to become part of WinAMPs media library either. But I am struggling on how to add the named file (in VB6) not as VBscript. It would be most appreciated if someone could quickly show me how ??

      Also if anyone has any more extensive VB6 code using ActiveWinamp they could share as a learning exercise that would be great.

      Chris

      Comment

      • shaneh
        Major Dude
        • Jan 2004
        • 1193

        I dont feel like installing VB6 on my machine, but AFAIK its not much different from vbscript at least in syntax.

        To do that in vbscript, you would do something like:

        mi = loaditem "C:\test.mp3"
        mi.enqueue
        oldpos = playlist.position
        playlist.position = playlist.count
        play
        playlist.position = oldpos
        playlist.deleteindex playlist.count

        Edit: If youd like to not delete the item until it is done playing, you would need to trap the play state changed or song changed event, and then delete the item. However winamp will continue playing the item even though its not in the playlist. Its kinda weird though, and will screw up a few things that get current playing file info based on the current playlist position in wianmp. IMHO it is a fault in winamp.
        Music Plugins

        Comment

        • saivert
          Banned
          • Jan 2001
          • 927

          shaneh's ActiveWinamp plugin is actually an excellent scripting platform for Winamp. I have had some time experimenting with it and you can actually convert a lot of small plugins (dll files) into scripts for ActiveWinamp. If you ever used the "Find in Explorer" plugin to get a new item in the playlist context-menu to locate a file in the Explorer you may now do this as an ActiveWinamp script:

          VBScript
          code:

          Option Explicit
          Dim wsh, sel
          sel = Playlist.GetSelection
          Set wsh = CreateObject("WScript.Shell")

          If UBound(sel) = 1 Then
          wsh.Run "explorer.exe /select," & sel(1).Filename
          End If

          Quit 'end script

          PS! And please... what's all those WIDE posts for? Keep your CODE sections broken into multiple lines. Use the underscore to split lines in VBScript. Like:
          code:

          Dim x
          x = Playlist.GetSelection

          For y = ubound(x) To 1 Step -1
          set sep = LoadItem("x:-----" + _
          x(y).Album + _
          "-------------------.x")
          sep.Insert(CInt(x(y).position) -_
          1)
          Next

          Quit

          And please use capitalization when writing VBScripts. It's much easier to read then. Refer to the VBScript coding style info from Microsoft.
          All lowercase isn't neccessary in order to get the script running. shaneh uses Mixed case in his documentation so why shouldn't we?

          Comment

          • Crestronite
            Junior Member
            • Jan 2005
            • 6

            Originally posted by shaneh
            I dont feel like installing VB6 on my machine, but AFAIK its not much different from vbscript at least in syntax.

            To do that in vbscript, you would do something like:

            mi = loaditem "C:\test.mp3"
            mi.enqueue
            oldpos = playlist.position
            playlist.position = playlist.count
            play
            playlist.position = oldpos
            playlist.deleteindex playlist.count

            In VB6 I have a global declaration
            Dim WithEvents aWinAMP as ActiveWinamp.Application

            In my Form Load() I have
            Set aWinAMP=CreateObject("WINAMPCOM.APPLICATION")

            Most things seem to work ok including the event callback

            In a different subroutine I have
            Dim mi as MediaItem
            mi=aWinAMP.LoadItem("C:\temp.mp3")
            mi.enqueue

            ... etc

            but the loaditem assignment errors with invalid use of property - - although it looks as though the right hand side indicates it returns a MediaItem , I think it actually returns a string. I guess I'm being really stupid here ?

            mi= aWinAMP.Loaditem "C:\temp.mp3" is not a valid syntax

            msgbox aWinAMP.LoadItem("C:\temp.mp3") gives a "C:\temp.mp3" message and the filename is not checked in anyway as existing as it works for anything.

            Chris

            EDIT: AHHH - and the light went on... ;-)

            Set mi=aWinAMP.LoadItem("C:\temp.mp3")

            DUH ! Chris

            Comment

            • shaneh
              Major Dude
              • Jan 2004
              • 1193

              Yep, I forgot the brackets. I was going to edit it in but I figured youd work it out, the example in the help file for loaditem uses brackets.

              You should be using 'activewinamp.application' not winampcom.application. But if you can get loaditem to work, I guess you are using the correct one.

              I thought the 'Set' may have been needed, but I think its not necessary under vbscript.
              Music Plugins

              Comment

              • saivert
                Banned
                • Jan 2001
                • 927

                I have made an update to your ActiveWinamp examples. Here it is:

                NxS-ActiveWinamp-stuff-Setup.exe

                Comment

                • Crestronite
                  Junior Member
                  • Jan 2005
                  • 6

                  Originally posted by shaneh
                  You should be using 'activewinamp.application' not winampcom.application. But if you can get loaditem to work, I guess you are using the correct one.
                  Sorry yes - I was using the right one - just typed the wrong one in the message as I was trying a couple of different approaches. All is working now.

                  I have been trying three possible scripting solutions for my projects all of which have different strengths and weaknesses. ActiveWinAMP is my favourite in terms of most features and responsive developers (thanks !) - but I do need control of multiple instances on one machine (see thread http://forums.winamp.com/showthread....hreadid=206384 ) . This is because I use six channel (surround sound) audio cards divided into 3 stereo pairs each driven by a different WinAMP instance for 3 audio zones. I take it from your reply that launching WinAMP using the optional "class" parameter as Lion12 was doing earlier in this thread will not help either - even if I ensure my WinAMP instances are all up and running prior to my application. I am guessing I can't control which winamp instance I'm connecting to or even 'step' through multiple instances to identify a particular one by an ID or by recovery of the class name or something. ..

                  Chris

                  Comment

                  • shaneh
                    Major Dude
                    • Jan 2004
                    • 1193

                    snipped.
                    /EDIT: Ignore that ramble.

                    Im looking into adding proper multiple instance support. Will see how it goes. I'll upload a test version here. I will need to disable a few other things to get it working, but it may be useful for you to play with.
                    Last edited by shaneh; 1 February 2005, 12:40.
                    Music Plugins

                    Comment

                    • shaneh
                      Major Dude
                      • Jan 2004
                      • 1193

                      Heres a rough version of AW which supports multiple instances a little better. Note however its not fully tested.

                      Also note, it uses the REGCLS_SINGLEUSE registration in the ROT. What this basically means is, the active instance of the object is registered in the system, but once an external application grabs that object it disapears in the table.

                      So, you cannot re-grab the ActiveWinamp object once you have used it externally. ie, the registration assumes a new copy of the .exe will be started for every 'object grab', and the .exe will be basically terminated once finished. If this isnt the case, it causes problems when you go to use AW again, either from the same application or a different one. So you have to keep the reference around, lose it, and you have to start another copy of winamp and get another one.

                      So basically, this version of AW is for multiple use only, and just for playing with. I might look into a better solution using monikers and window classes.
                      Attached Files
                      Music Plugins

                      Comment

                      • Crestronite
                        Junior Member
                        • Jan 2005
                        • 6

                        Hi.. thanks for the changes you made here, this is working well for me in separating my instances, so I'm half way there. I have multiple instances running and controlled OK :-)

                        As I was previously set up I had several WinAMP folders and I used to launch each WinAMP individually , from its own folder and the preferences were set such that each used different output options effectively feeding the audio to different zones. How might I accomplish that using this type of solution as my instances are identical, would I in some way be able to load a different ini file in each instance perhaps , or set the output somehow ?

                        Alternatively if I wish to control an already running instances of WinAMP I think you are saying that is going to be not possible as I cant get at the object. I was just thinking of launching my 3 independant zones and picking them up that way.

                        Chris

                        <edit> What I think I shouldn't be doing is using 'CreateObject' and creating a new object but instead picking up one of the mutiple existing instances perhaps using GetObject.
                        Last edited by Crestronite; 6 February 2005, 14:55.

                        Comment

                        • Crestronite
                          Junior Member
                          • Jan 2005
                          • 6

                          Yes - just needed to use GetObject - and I can pick up the already existing instances so this is very suitable for what I need, (although as you say it can only run once without having to restart the WinAMPs) .. Many thanks

                          Chris

                          Comment

                          • shaneh
                            Major Dude
                            • Jan 2004
                            • 1193

                            I am working on a new implementation which will allow you to hopefully "GetObject" using the window class name of the started winamp. Im still looking into it but hopefully it will work ok.

                            I think that version I posted here is a bit broken, events may not work properly with it. Basically its just for playing with until I get a proper version released.
                            Music Plugins

                            Comment

                            • JohnKane
                              Junior Member
                              • Feb 2005
                              • 6

                              First off, let me say THANK YOU for developing an activex COM object for Winamp. I had been struggling for some time with WinampCom. While this did the trick initially, it has limitations with regards to creating multiple instantiations. In my application, the com object resides on a server and is called by clients. If a client's session was terminated, the COM object remained. Subsequent client calls spawned new instantiations, and then the COM object stopped working. There is no way to get a handle to an existing object instantiation that could find with winampcom. This was a show stopper and I had almost given up on this project, when I found your plug-in posted.


                              So I for one appreciate the single instantiation operation. I am going to run some tests to see what happens when a client session terminates (hopefully it will work.)

                              One small suggestion: I got the object up and running very quickly for play, stop, pause, etc., assuming I had used the UI to load a playlist. But I struggled with trying to get a new playlist loaded with the com object. I had tried Loaditem, Getitem etc, and several combinations. After running through this thread a few times, I finally found the missing piece, the enqueue method needs to be called after the load. I'm not a winamp power user, so this was extremely non-intuitive for me. (Maybe thats just me) A little bit of text in the help file or an enqueue method example would have helped me. I couldnt find any samples that showed a new playlist being loaded.

                              I'll keep plugging at this to see if it solves my problem, but initial tests look promising.

                              Comment

                              • shaneh
                                Major Dude
                                • Jan 2004
                                • 1193

                                Yes, enqueue is what you want.

                                LoadItem is just a way of creating a MediaItem and setting the filename to the one you specify. A MediaItem is essentially a representation of a file, which also caches meta data about that file if and when you request it. Consider LoadItem to be the class factory or constructor if you are familiar with OOP.

                                Once you have that MediaItem, you can call the various Winamp IPCs that require a filename, such as IPC_PLAYFILE, and the filename that is used is the one thats contained within the MediaItem in question.

                                The use is a bit different to WinampCOM, which is basically just a proxy for the API calls. ActiveWinamp was designed to be a little more 'object orientated' which leads to a better design in the long run IMHO. (ie, it lets you have an array of mediaitems and enqueue the ones you want etc instead of having to maintain your own array of filenames) People familiar with OOP should hopefully find it relatively intuitive. However coming from WinampCOMs design I can understand it may seem awkward.

                                I will be retooling the help file a bit in the next release with some more helpful information other than just a reference. Its currently not much more than a re-generation of the typelib with a couple lame examples, a couple of which are broken

                                The Enqueue method was used to represent the IPC_PLAYFILE API 'call', because that is what winamp essentially does with the file passed.

                                With this is mind, if winamp were able to enqueue playlist files (.m3u) via this API call, you could simply do:

                                set mi=loaditem("c:\pls.m3u")
                                mi.enqueue

                                But winamp just enqueues the file and doesnt parse the m3u. AW doesnt have support for IPC_CHANGECURRENTFILE yet, I am not sure exactly how this behaves, but it might let you load playlists, and play files with resetting the playlist. I will look at adding it in if so.


                                With regards to the single instantiation, AW is a singleton COM object. So multiple clients are actually using the same COM object as well as the same winamp.exe. I am working on a way to support both multiple and single instances by letting clients use GetObject with a window class name as a moniker. This wont affect anyone using AW+winamp in single instance mode, but it will allow people to obtain different instances of AW+Winamp if they needed to.
                                Last edited by shaneh; 12 February 2005, 01:50.
                                Music Plugins

                                Comment

                                Working...
                                X