Announcement

Collapse
No announcement yet.

Winamp Scripting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #61
    Originally posted by DrO
    i'm not afraid since i've got other projects in the works anyway
    ... get alphas to 1.x state for example

    Comment


    • #62
      "the order in which plugins loads can affect things if the chain of loading isn't as expected."

      Yeah, its not too hard for other plugins to affect the operation of others, or a dependence not be satisfied due to the order not being as expected. Although the plugin will enter the 'chain' at the normal time, I'll be changing it so it doesnt initialise or start running scripts until the initial plugin shakedown is complete for all plugins.

      But there is stil the problem of command ids being used by other plugins. AFAIK the current standard is just use any old random spare id when adding to menus etc. If any two plugins try use the same id for any menu etc, there would be problems. Be good if you could request a range of ids from winamp.
      Music Plugins

      Comment


      • #63
        thanx for the bug fix

        I still hav some dumb question, here's my code :
        code:
        Const ForReading = 1, ForWriting = 2, ForAppending = 8

        Set fso = CreateObject("Scripting.FileSystemObject")
        Set MyFile = fso.OpenTextFile("C:\Program Files\Easyphp\www\songs_temp.txt", ForWriting, True)

        mlq = medialibrary.runqueryarray("type = 0")

        for each track in mlq

        if track.ATFString("%year%") < 0 Then
        MyFile.WriteLine(track.artist + ";" + track.album + track.ATFString(";%tracknumber% ") + track.title + track.ATFString(";%bitrate%;%lengthf%;;%genre%"))
        Else
        MyFile.WriteLine(track.artist + ";" + track.album + track.ATFString(";%tracknumber% ") + track.title + track.ATFString(";%bitrate%;%lengthf%;%year%;%genre%"))
        End if
        next

        MyFile.Close()

        set cmd1 = CreateObject("Wscript.Shell")
        cmd1.Run "sort C:\Progra~1\Easyphp\www\songs_~1.txt /o C:\Progra~1\Easyphp\www\songs.txt"

        quit

        Id like to add
        code:
        set cmd2 = CreateObject("Wscript.Shell")
        cmd2.Run "del C:\Progra~1\Easyphp\www\songs_~1.txt"

        or
        code:
        cmd1.Run "del C:\Progra~1\Easyphp\www\songs_~1.txt"
        but both don't work
        any clue ?


        And I have a totally OT question, a friend would like a random question that first choose a random artist and then one of his songs. He doesn't want to ear too much an artist when he owns his whole discography, you see ?

        Do you think I could do this with your plugin ? I think I need to query the ml with a DISTINCT option and the randomize on the artist. Then i just have to re-query with that artist and re-randomize one song.
        THe problem concerns that "distinct" (like in SQL), I think it's not possible to query the ml like that, is it ?

        Comment


        • #64
          i think i have the script like i want it, though... i have yet to figure out how to get it to play the first track of the cd.. but thats not that big of a deal

          my question is.. how can i add it to the script to sort the album by track number.. because sometimes when i 'insert album' some albums list the album backwards.(from last track to first)

          thanks
          There is no reset button on life... but the graphics kick ass

          Comment


          • #65
            Originally posted by shaneh
            But there is stil the problem of command ids being used by other plugins. AFAIK the current standard is just use any old random spare id when adding to menus etc. If any two plugins try use the same id for any menu etc, there would be problems. Be good if you could request a range of ids from winamp.
            there's a lot Winamp should do like natively handling menu insertion, etc but i doubt anything like this will happen (i've asked about a few things and basically have been told no)

            Originally posted by AnodA
            ... get alphas to 1.x state for example
            yup and some other things that are posted around. anyway back to the thread topic plzkthx

            -daz
            WACUP Project <โ€–> "Winamp Ramblings" - Indie Winamp Dev Blog

            Comment


            • #66
              @NeFast, I found this example in the msdn docs, it should work ok:
              Dim fso, MyFile
              Set fso = CreateObject("Scripting.FileSystemObject")
              Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
              MyFile.WriteLine("This is a test.")
              MyFile.Close
              Set MyFile = fso.GetFile("c:\testfile.txt")
              MyFile.Delete

              As far as I know there is no 'distinct' option, but there are many ways to overcome this. Just query for every song, then add each to a 'scripting.dictionary' object, using the artist as the key, and maybe the number of songs by that artist as the value, or anything else it doesnt really matter, it wont allow you to add duplicate keys. Then just choose a random one from 1 to .count.

              I want to avoid writing scripts for everyone though, and concentrate on the plugin which allows such scripts to be written. Unless I find that the script requires some change to the plugin.


              @electricmime: You will need to sort the results after you get them. Its not too difficult, I'll post up a script that does it soon.
              Music Plugins

              Comment


              • #67
                +Fixed more problems with ATFString when stuff wasnt loaded from the media library.

                +Added basic support for sendto_*.vbs items. You can get the items through GetSendToItems().

                +It will not start scripts or register hot keys etc until all plugins have finished initing.

                Fixed some example scripts that wouldnt quit properly if not enough items were selected. Added a send to 'export sorted' example.

                The basic API is getting pretty close to complete. Theres still a few things here and there, but the most used things are there.

                I still need to add methods for adding menu items and hot key callbacks etc. Plus some gui stuff as well as loading .js and other script types.
                Attached Files
                Music Plugins

                Comment


                • #68
                  ...back to the thread topic - yeah, that's what it's meant to be! Don't want to keep shaneh off form doing his plug. But ideas rise.

                  @shaneh:
                  1. That config thing you planed would be great I think. Keep this in mind, please! The scripts that are loaded or displayed should be set in an easy way. Not like it's actually with the Winamp plugins - I can't stand copy or deleate files in a folder somehow getting confused about my lastest setting, what plugs I need to do what I want, which combination of things can cause problems or where (damn) is the plug I tried out some time before (and that's EXACLTY what I need now!!) - I just want to define: Load or display this script or ignore this script till I tell you not to do this. Something special would be to have a couple of presets to choose - but I only want to be inquired if I really want to be. It should be easy to config for people that know not much about computers (should be the main aim ever, everybody knows). Too much? Doesn't mind. I just want to tell you: Take your time, finish the functionality first and think about the best way integrating this into Winamp. It's a promising thing I'm sure about that. Though it might grow to work more than fun . It's people like you bringing fun to other people. But you see the problem many scripts installed?
                  (btw s.o. agree that's nice for the plugin issue... no, sorry, getting of topic again. Perhaps that's something for the discussion forum)
                  2. Dreamed about OnWinampClosedown issues. Could be great if someone wants to fix things (last playlist, statistics, whatever...). Could be done with some watch things I know but would be better to do this in a clean and simple way. Agree?
                  3. The example scripts are fine right now. It's the best way to follow what it's intended to do. Please keep on including them.
                  Hope I'm not a pain in your neck - keep quiet now till there's something important.
                  Happy coding...

                  Comment


                  • #69
                    Hello I've done the "clever random" plugin I was talking about.

                    code:
                    dim i,j,Dict1,keys,tracks
                    i = 0
                    x = playlist.getselection()

                    Set Dict1 = CreateObject("Scripting.dictionary")
                    Dict1.CompareMode = BinaryCompare

                    mlq = medialibrary.runqueryarray("type = 0 AND trackno = 1")
                    for each track in mlq
                    Dict1(track.artist)=i
                    i=i+1
                    next

                    Randomize
                    keys = Dict1.keys

                    do while (tracks<=10)

                    Rand = Int((Dict1.Count + 1) * Rnd)

                    mlq2 = medialibrary.runqueryarray("artist HAS """ + keys(Rand) + """")
                    j=0
                    for each track in mlq2
                    j=j+1
                    next

                    Rand2 = Int((j + 1) * Rnd)
                    mlq2(Rand2).insert(x(1).position)

                    tracks=tracks+1
                    Loop

                    quit

                    It was a bit slow so I added "trackno = 1") in the first query so that each album is called one time. The drawback is that this will totally mess up the random if you don't have your tags correctly filled !

                    I repeat that I'm a total newbie with VB so If you see any way to optimize this plugin, please tell me.

                    And now "dumb question session"

                    Is it possible to add an item in the playlist when it's empty ? shaneh uses "if ubound(x,1) > 0 then" to avoid adding anything in that case, so I don't kwow ....

                    Then is it possible to put a form in a msgbox to asks the user for the number of files he'd like to add ?

                    neFAST - not that fast

                    Comment


                    • #70
                      ubound(x) just checks the number of values in 'x'. x is an array obtained from 'playlist.getselection'. So it effectively checks the number of values selected.

                      If the playlist is empty, then obviously the selection will be empty too. But you still need a place to insert. Thus you will have to manually choose a location, or you can use playlist.position. You can use playlist.count to get the number of items in the playlist.

                      If you dont care about the position and just want to enqueue it to the end, you can use track.enqueue.

                      Note in your example, you would be better off doing

                      j = ubound(mlq)

                      rather than a loop to find the number of items in the second query. That part wouldnt be too slow though, it would be adding the items to the dict object that would be slow. Im not sure of a faster way though. You could try doing 'ifexists(key)' or whatever and not re-adding a value if it does and see if its faster, i dont think it would be though.


                      The gnu sort utility allows you to list all the unique items using

                      sort -u file.txt

                      So you could try writing all the artists to a file then running that utility over it and see if its any faster. Then using wc to count the number of lines then read a random line etc. I am not sure if it would be ultimately faster though. But the advantage is you can cache the results in the file and not have to re-generate the list everytime.

                      You can do:
                      num = CInt(InputBox("number of items"))

                      to get a value from the user.
                      Music Plugins

                      Comment


                      • #71
                        Adding on this rather than editing:

                        It seems the slow part is having to do a query for every track you want to add. Queries are qutie slow


                        It may be possible to speed up your script by having the 'value' part of the key/value pair be a list of the available songs. ie, lookup the artist in the dictionary, then modify the value to include the database index of the new item.

                        You can obtain the dbindex from the media item through 'track.dbindex'. Or use the index into the array.

                        So basically your dictionary (key,value) would look like:

                        "Metallica", "10:16:17:20"
                        "Spearhead", "23:34:234:1:235:92"

                        ---------------heres a script that will do it---------

                        dim i,j,Dict1,tracks,num,idxs

                        Set Dict1 = CreateObject("Scripting.dictionary")
                        Dict1.CompareMode = BinaryCompare

                        mlq = medialibrary.runqueryarray("type = 0")
                        i = 0

                        for each track in mlq
                        Dict1(track.artist)=Dict1(track.artist) + ":" + CStr(i)
                        i = i + 1
                        next

                        Randomize
                        itms = Dict1.Items

                        num = CInt(InputBox("Number of items"))

                        do while (tracks<=num)

                        Rand = Int((Dict1.Count + 1) * Rnd)

                        idxs = Split(itms(Rand), ":", -1, 1)

                        Rand2 = CInt(idxs(Int(ubound(idxs)+1 * Rnd)))
                        mlq(Rand2).enqueue

                        tracks=tracks+1
                        Loop

                        quit
                        Last edited by shaneh; 12 September 2004, 13:23.
                        Music Plugins

                        Comment


                        • #72
                          Shaneh : you said you wanted to avoid scripting for everyone
                          now you've made a faster and clearer script in 20min, do do you want to discourage me ?

                          well, hum, thank you !

                          [edit]
                          I must tell you that your Export sorted script is not very fast and useful,:-รพ maybe an "album list" would be more interesting, using dictionary to list only unique data

                          Comment


                          • #73
                            It is not useful, but it does show how to use the 'send to' feature, and how to sort an array after a library query, based on a string field. And that is its only aim.
                            Music Plugins

                            Comment


                            • #74
                              Global Hotkeys solution!

                              You can't add your hotkey actions to Global Hotkeys plugin in the init() function. I have a solution for this which is attached. It uses a timer...
                              Attached Files

                              Comment


                              • #75
                                Timers are unreliable, it is dependant on the speed of the machine. It also means you miss any inital messages if you dont init everything until the timer fires.

                                It is much easier to just postmessage a custom message to the winamp hwnd. You will not get the message until all the plugins have been init'd. You will get it as soon as the plugins have all been loaded and init'd, and winamp is ready to start doing stuff.

                                alternatively, you can make the hot key registration a postmessage itself.
                                Music Plugins

                                Comment

                                Working...
                                X