Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » Finished MUD Scripts
Obyron
Novice


Joined: 29 Jan 2006
Posts: 40
Location: Aardwolf

PostPosted: Sun Jan 29, 2006 5:15 pm   

ZMud and iTunes = myTunes
 
Here's my ZMud script to retrieve data from and control iTunes that I wrote for a friend. As you'll notice everything is command line only, as that's the way I play. I'd rather type "ns" than click on a shiny button. :) I have a command line script to control Winamp based partly off of zAmp if anyone is interested in such a thing.

Known oddities:
* You cannot use other buttons if you are using the myTunes gauge and the music is playing. This is because Zmud will not allow more than one button to be active at a time. Solution: Pause the music.

* Closing iTunes while the script is running makes Zmud go absolutely psychotic. This happens because when ZMud receives an error from a COM call it just reports it instead of reporting it and closing the connection. A graceful way to code around this would be greatly-- GREATLY-- appreciated. Solution: If you receive an error keep hitting F4 while clicking OK. This sucks, but it works. OR: Use the "mytunes" command instead of closing Winamp. See next post.


Here's the code. Spaces are for readability, and you'll want to remove them before importing. Just a couple of edits to make sure the install is clean. The first export was done while the script was "on," which wouldn't have hurt anything, but might've looked odd. :) Also removed a small error in ssft based from copying from my Winamp script. Oops! I've reimported from this to test, and it's tip-top.

Code:

#CLASS {skbscripts|myTunes}
#ALIAS mytunes {#IF (@itunes = "") {#VAR itunes {%comcreate( "iTunes.Application")} _nodef myTunes;#T+ mytunes_data;SKB_MT_Announce myTunes Enabled.} {#T- myTunes_data;#CALL @iTunes.Quit;#VAR itunes {%null} _nodef myTunes;SKB_MT_Announce myTunes Disabled.}}
#ALIAS ns {#CALL @iTunes.NextTrack;SKB_MT_UpdateData;SKB_MT_Announce Now Playing: @mytunes_artist - ~"@mytunes_title~"}
#ALIAS ls {#CALL @iTunes.BackTrack;SKB_MT_UpdateData;SKB_MT_Announce Now Playing: @mytunes_artist - ~"@mytunes_title~"}
#ALIAS pause {#CALL @iTunes.Pause;SKB_MT_UpdateData;SKB_MT_Announce Paused: @mytunes_artist - ~"@mytunes_title~"}
#ALIAS play {#CALL @iTunes.Play;SKB_MT_UpdateData;SKB_MT_Announce Playing: @mytunes_artist - ~"@mytunes_title~"}
#ALIAS stop {pause}
#ALIAS ssft {#IF (%1 = %null) {ft :is listening to @mytunes_artist - ~"@mytunes_title~"} {ft :%-1 @mytunes_artist - ~"@mytunes_title~"}}
#VAR itunes {}
#KEY F4 {#var itunes {%null} _nodef myTunes}
#CLASS 0

#CLASS {skbscripts|myTunes|mytunes_data}
#VAR mytunes_artist {}
#VAR mytunes_title {}
#VAR mytunes_length {}
#VAR mytunes_status {}
#VAR mytunes_elapsed {}
#ALARM {1} {#IF (@iTunes = %null) {#T- mytunes_data;#VAR itunes "" _nodef mytunes;SKB_MT_Announce No connection! Type ~"mytunes~" when iTunes is running again.} {SKB_MT_UpdateData}}
#BUTTON 3 {@mytunes_status} {} {} {} {@mytunes_elapsed} {} {} {Size} {125} {14} {Pos} {1} {42} {32864} {} {Gauge||12|@mytunes_length|0|7} {} "" {} {} {itunesbar}
#CLASS 0

#CLASS {skbscripts|myTunes|mytunes_backend}
#ALIAS SKB_MT_Announce {#SHOW %ansi( 15)myTunes%ansi( 12)> %ansi( 7)%1}
#ALIAS SKB_MT_UpdateData {#VAR mytunes_artist {@iTunes.CurrentTrack.Artist} _nodef mytunes_data;#VAR mytunes_title {@iTunes.CurrentTrack.Name} _nodef mytunes_data;#VAR mytunes_length {@iTunes.CurrentTrack.Duration} _nodef mytunes_data;#VAR mytunes_status {%case(@iTunes.PlayerState+1,"Paused/Stopped",@mytunes_artist - @mytunes_title)} _nodef mytunes_data;#IF (@mytunes_status != "Paused/Stopped") {#VAR mytunes_elapsed {@iTunes.PlayerPosition} _nodef mytunes_data}}
#CLASS 0


Last edited by Obyron on Sun Jan 29, 2006 5:42 pm; edited 3 times in total
Reply with quote
Obyron
Novice


Joined: 29 Jan 2006
Posts: 40
Location: Aardwolf

PostPosted: Sun Jan 29, 2006 5:21 pm   
 
Here's the relevant help:

Commands:

mytunes -- When you open ZMud type "mytunes" to connect to iTunes and initialize the script. If iTunes is not currently open this will open it. If iTunes is already open and the script is connected typing "mytunes" AGAIN will close iTunes and shut down the script, thus avoiding the annoying bug mentioned in the first post.

ns -- Advances to the next track.

ls -- Goes to the last track.

pause -- Pauses/Stops (is there a different in iTunes? :P) the current song.

stop -- Aliased to "Pause"

ssft -- By itself will send ":is currently listening to ARTIST - "TITLE"" to ftalk. With any argument... well, an example will suffice: ssft is bouncing around to would "ft :is bouncing around to ARTIST - "TITLE"" This command is Aardwolf specific.

F4 -- This macro kills the COM server connection, and is included as a shoddy, two-bit hack for the above-mentioned error. But I'm not bitter.


If you have any questions about myTunes or about the iTunes COM Typelib please let me know here, or send me a tell on Aardwolf. If you program an iTunes majiggy based on this one, please credit me as "Obyron@Aardwolf". Bug reporting is greatly appreciated, but it should be more or less stable.
Reply with quote
Ethemos1
Newbie


Joined: 09 Feb 2006
Posts: 7

PostPosted: Thu Feb 09, 2006 3:34 pm   Buggy
 
It does not show which song is playing, not is it removable for some reason, bugged my entire zmud, so I have to reinstall the damned thing quit zmud start itunes and then zmud again Evil or Very Mad
_________________
There can be no order without chaos
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 672
Location: New York

PostPosted: Fri Feb 10, 2006 2:18 am   
 
weird, at least 3 people on my flist on aard have been using it since he posted it.
And it works perfectly.
Don't use it myself tho.
_________________
http://www.Aardwolf.com
http://www.facebook.com/AardWolf.Vitae.DaemonChilde <--add if you play the apps or are willing to add apps just to help out.
Reply with quote
Adnil
Newbie


Joined: 21 Dec 2005
Posts: 4

PostPosted: Fri Feb 10, 2006 9:33 am   
 
Worked nicely for me, I also wanted to control the volume via the command line, so created 2 aliases to help with that.
Mute just toggles the mute setting, volume takes a percentage argument, so volume 50 sets the volume to 50 percent.

Code:
#ALIAS mute {#VAR Muted %comget( @iTunes, Mute) _nodef mytunes_data;#If (@Muted) {%comset( @iTunes, Mute, False);SKB_MT_Announce UnMuted.} {%comset( @iTunes, Mute, True);SKB_MT_Announce Muted.}}
#ALIAS volume {%comset( @iTunes, SoundVolume, %1);SKB_MT_UpdateData;SKB_MT_Announce Volume set to %1 percent.}
Reply with quote
Ethemos1
Newbie


Joined: 09 Feb 2006
Posts: 7

PostPosted: Mon Feb 13, 2006 12:53 am   
 
Could some more test this please so I well use ya as bug testers so I don't have to experience zmud problems again ? Cool
_________________
There can be no order without chaos
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Mon Feb 13, 2006 3:23 pm   The few things i added
 
(A Piece of code similar to this has been posted here i see but..)

Code:
#ALIAS volumeUp {
  #var itunes.SoundVolume %min( %eval( @itunes.SoundVolume+%if( %len( %1)>0, %1, 10)), 100)
  SKB_MT_Announce Volume Set to @itunes.SoundVolume
  }
#ALIAS volumeDown {
  #var itunes.SoundVolume %max( %eval( @itunes.SoundVolume-%if( %len( %1)>0, %1, 10)), 0)
  SKB_MT_Announce Volume Set to @itunes.SoundVolume
  }
#ALIAS setArtist {
  #var CurrentTrack @iTunes.CurrentTrack
  #CALL %comset(CurrentTrack,"Artist",%param)
  #noop
  }
#ALIAS setTitle {
  #var CurrentTrack @iTunes.CurrentTrack
  #CALL %comset(CurrentTrack,"Name",%param)
  #noop
  }
#ALIAS showLyrics {
  SKB_MT_Announce Lyrics to %char( 34)@iTunes.CurrentTrack.Name%char( 34)
  #say %ansi( grey)@iTunes.CurrentTrack.Lyrics
  }
#ALIAS setLyrics {
  #var CurrentTrack @iTunes.CurrentTrack
  #var TempLyrics @iTunes.CurrentTrack.Lyrics%cr%right( %param, 1)
  #if (%left( %param, 1)=="+") {#CALL %comset(CurrentTrack,"Lyrics",@TempLyrics} {#CALL %comset(CurrentTrack,"Lyrics",%param)}
  #noop
  }
#ALIAS showSong {#if (%len( %1)>0) {%param @mytunes_artist - ~"@mytunes_title~"} {gt :is listening to @mytunes_artist - ~"@mytunes_title~"}}


I also edited the update data alias

Code:
#ALIAS SKB_MT_UpdateData {
  #VAR mytunes_oldartist {@mytunes_artist} _nodef mytunes_data
  #VAR mytunes_oldtitle {@mytunes_title} _nodef mytunes_data
  #VAR mytunes_artist {@iTunes.CurrentTrack.Artist} _nodef mytunes_data
  #VAR mytunes_title {@iTunes.CurrentTrack.Name} _nodef mytunes_data
  #IF ((@mytunes_oldartist!=@mytunes_artist) or (@mytunes_oldtitle!=@mytunes_title)) {
    skb_mt_announce Now Playing: @mytunes_artist - ~"@mytunes_title~"
    #if (@mytunes_AutoAnnounce!="") {
      @mytunes_AutoAnnounce ~@WmyTunes~@R~> ~@wNow Playing: @mytunes_artist - ~"@mytunes_title~"
      #gag
      }
    #var mytunes_oldartist {@mytunes_artist} _nodef mytunes_data
    #var mytunes_oldtitle {@mytunes_title} _nodef mytunes_data
    }
  #VAR mytunes_length {@iTunes.CurrentTrack.Duration} _nodef mytunes_data
  #VAR mytunes_status {%case( @iTunes.PlayerState+1, "Paused/Stopped", @mytunes_artist - @mytunes_title)} _nodef mytunes_data
  #IF (@mytunes_status != "Paused/Stopped") {#VAR mytunes_elapsed {@iTunes.PlayerPosition} _nodef mytunes_data}
  }


This allows you to automatically report when your song changes
_________________
The Drake Forestseer
Reply with quote
Obyron
Novice


Joined: 29 Jan 2006
Posts: 40
Location: Aardwolf

PostPosted: Wed Feb 15, 2006 4:39 am   
 
So far I know of several people using it and no one has reported having any issues with it. I wish I could be more help, but I'm not sure what the problem could be. It was written with ZMud 7.20b, and I can't guarantee that it'd work with any older versions. Also, "Good work" to Alluran on the auto-update script. I'd have written something like that in the original, but I figured it'd probably annoy the hell out of people and be the first thing people would want to know how to turn off. ;)

Cheers, and feel free to contact me on Aard (Obyron) if you have any questions.

--Obs
Reply with quote
EmilyRose
Newbie


Joined: 09 Jul 2008
Posts: 8

PostPosted: Fri Dec 11, 2009 2:38 am   
 
I've been using this script since shortly after Obyron posted it. no problems whatsoever. Until I updated itunes a week or so ago, now everytime I type mytunes to turn it on, I get an error.

Parsing error
Invalid Class String
#VAR itunes {%comcreate( "iTunes.Application")} _nodef myTunes;#T+ mytunes_data;SKB_MT_Announce myTunes Enabled.

Had I made any changes to my settings, I could see the problem being my settings. I haven't changed my settings for quite some time, so the only thing that changed was the update to itunes.

Has anyone else had this problem and figured out how to fix it?
Thanks
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » Finished MUD Scripts All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net