Bukz

AC Music Player (ACMP) Concept

Jul 27th, 2011
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.94 KB | None | 0 0
  1. // ACMP (AC Music Player) Beta by Bukz - (currently SVN only)
  2.  
  3. // How to use:
  4. //
  5. // * Put .ogg audio files that you want in your music library into /packages/audio/soundtracks/
  6. // * Edit the following aliases:
  7. //    songLibrary
  8. //    songLengths
  9. //    songLibraryNames
  10. //    songLibraryArtists
  11. //   These aliases determine how the Music Player menu and your music library is setup.
  12. //   They MUST be in order with each other. (e.g. Item #1 of "songLibrary" corresponds
  13. //   with item #1 of "songLengths" and so on.)
  14.  
  15. // For easy access to the script's main menu, uncomment and edit the keybind below:
  16. // bind KEY [ showmenu $musicMainMenuName ]
  17. //
  18. // OR, execute the following command in-game at anytime to view the script's main menu:
  19. //
  20. //    /showmenu $musicMainMenuName
  21.  
  22. // Basic features:
  23. //
  24. // A song library to put all of your favorite songs into for easy access in-game at anytime.
  25. // Loop Library (aka Repeat Library/Playlist in order.)
  26. // Shuffle (w/ optional "Loop Shuffle" - a continuous loop of random songs.)
  27. // Repeat Track
  28. // Play
  29. // Stop
  30. // Next
  31. // Previous
  32. // Main Song Library Menu (w/ individual menuitems to play each song in your song library.)
  33. // Now Playing Menu
  34. // Settings Menu to tweak the script's behavior. (w/ debug mode.)
  35.  
  36. // START EDITING YOUR MUSIC LIBRARY BELOW
  37.  
  38. // songLibrary - List of music file names in /packages/audio/soundtracks/ without the ".ogg" extension.
  39. songLibrary = [
  40.   song_file_name_1
  41.   song_file_name_2
  42.   song_file_name_3
  43.   song_file_name_4
  44.   song_file_name_5
  45. ]
  46.  
  47. // songLengths - List of lengths (in milliseconds) of the music files listed above.
  48. songLengths = [
  49.   250000
  50.   234000
  51.   269000
  52.   258000
  53.   299000
  54. ]
  55.  
  56. // songLibraryNames - List of song titles of the music files listed above.
  57. songLibraryNames = [
  58.   "Song Title 1"
  59.   "Song Title 2"
  60.   "Song Title 3"
  61.   "Song Title 4"
  62.   "Song Title 5"
  63. ]
  64.  
  65. // songLibraryArtists - List of song artists of the music files above.
  66. songLibraryArtists = [
  67.   "Song Artist 1"
  68.   "Song Artist 2"
  69.   "Song Artist 3"
  70.   "Song Artist 4"
  71.   "Song Artist 5"
  72. ]
  73.  
  74. // STOP EDITING MUSIC LIBRARY
  75.  
  76. musicMainMenuName = (concatword (yellow) "Music " (green) Player (white))
  77.  
  78. genMusicMainMenu = [
  79.   if $musicDebugMode [ echo (blue)Debug: (white)Music Player Main Menu generating... ]
  80.   delmenu $musicMainMenuName
  81.   newmenu $musicMainMenuName
  82.   menuitem (concat (green) Now Playing) [ nowPlayingMenu ]
  83.   menuitem (concat (orange) Settings) [ showmenu "Music Player Settings" ]
  84.   menuitem "" -1
  85.   menuitem (concat (blue) ~ Music Library ~) -1
  86.   menuitem "" -1
  87.   genSongList
  88.   if $musicDebugMode [ echo (blue)Debug: (white)Done generating Main Menu. ]
  89. ]
  90.  
  91. genSongList = [
  92.   loop gm (listlen $songLibraryNames) [
  93.     if $musicDebugMode [ echo (blue)Debug: (white)Generating menu item for song - (at $songLibrary $gm) ]
  94.     menuitem (concatword (blue) (at $songLibraryArtists $gm) (gray) " - " (yellow) (at $songLibraryNames $gm)) [ playSong (at $lastmusicsel 0) (at $lastmusicsel 1) ] (addpunct (concat alias lastmusicsel (addpunct (concat (at $songLibrary $gm) (at $songLengths $gm)))) 2)
  95.   ]
  96.   if $musicDebugMode [ echo (blue)Debug: (white)Done generating Main Menu song menu items. ]
  97. ]
  98.  
  99. nowPlayingMenu = [
  100.   closemenu "Now Playing"
  101.   delmenu "Now Playing"
  102.   newmenu "Now Playing"
  103.   songPosition = (findlist $songLibrary (at $lastPlayedSong 0))
  104.   if (&& (> $songPosition -1) (! $musicstopped)) [
  105.     menuitem (concat (green) Now playing: (blue) (at $songLibraryArtists $songPosition) (gray) - (yellow) (at $songLibraryNames $songPosition)) -1
  106.     if (= $songPosition 0) [
  107.       menuitem (concat Track Number: (yellow) First (concatword (addpunct 0 2) (yellow) / (listlen $songLibrary))) -1
  108.     ] [
  109.       if (= $songPosition (- (listlen $songLibrary) 1)) [
  110.         menuitem (concat Track Number: (yellow) Last (concatword (addpunct (listlen $songLibrary) 2) (yellow) / (listlen $songLibrary))) -1
  111.       ] [
  112.         menuitem (concat Track Number: (yellow) (concatword (+ $songPosition 1) / (listlen $songLibrary))) -1
  113.       ]
  114.     ]
  115.   ] [
  116.     menuitem (concat (green) Now playing: (gray) None) -1
  117.   ]
  118.   menuitem (concat (green) Play) [ repeatLastPlayedSong ]
  119.   menuitem (concat (red) Stop) [ music; musicstopped = 1; showmenu $musicMainMenuName ]
  120.   menuitem (concat (yellow) Next Song in Library) [ skipSong 1; nowPlayingMenu ]
  121.   menuitem (concat (blue) Previous Song In Library) [ skipSong -1; nowPlayingMenu ]
  122.   menuitem (concat (orange) Shuffle) [ shuffleSongs; nowPlayingMenu ]
  123.   menuitem (concat (green) Loop Library) [ loopLib; nowPlayingMenu ]
  124.   menuitem (concat (yellow) Refresh Now Playing) [ nowPlayingMenu ]
  125.   menuitem Back [ showmenu $musicMainMenuName ]
  126.   menuitem "" -1
  127.   menuitemcheckbox "Repeat: " "$musicPlayerRepeat"[ musicPlayerRepeat = $arg1 ]
  128.   menuitemslider "Music Volume: " 0 255 "$musicvol" 10 [] [ musicvol $arg1 ]
  129.   menuitemslider "Sound Volume: " 0 255 "$soundvol" 10 [] [ soundvol $arg1 ]
  130.   if (|| $shuffling $musicPlayerLoopLib) [
  131.     if $musicDebugMode [ echo (blue)Debug: (white)Special playback mode active, generating menuitems... ]
  132.     menuitem "" -1
  133.     if (&& $shuffling (! $musicPlayerLoopLib)) [ menuitem (concat (purple) Active Modes: (white)Shuffle) ] [
  134.       if (&& $musicPlayerLoopLib (! $shuffling)) [ menuitem (concat (purple) Active Modes: (white)Loop) ] [
  135.         menuitem (concat (purple) Active Modes: Loop, Shuffle)
  136.       ]
  137.     ]
  138.     if $shuffling [ menuitem (concat (red) Turn Shuffle Off) [ shuffling = 0; showmenu $musicMainMenuName ] ]
  139.     if $musicPlayerLoopLib [ menuitem (concat (red) Turn Loop Off) [ musicPlayerLoopLib = 0; showmenu $musicMainMenuName ] ]
  140.   ]
  141.   sleep 1 [ showmenu "Now Playing" ]
  142. ]
  143.  
  144. playSong = [
  145.   if (> (findlist $songLibrary $arg1) -1) [
  146.     tmpSongInfo = (concat $arg1 $arg2)
  147.     if (strcmp $arg3 loop) [
  148.       if $musicDebugMode [ echo (blue)Debug: (white)Initiating song library loop... ]
  149.       music $arg1 $arg2 [ if $musicPlayerLoopLib [ skipSong 1 ] [ if $musicPlayerRepeat [ repeatLastPlayedSong ]; musicPlayerLoopLib = 0 ] ]
  150.     ] [
  151.       if (strcmp $arg3 shuffle) [
  152.         if $musicDebugMode [ echo (blue)Debug: (white)Executing shuffle... ]
  153.         shuffling = 1
  154.         music $arg1 $arg2 [ if $musicPlayerLoopShuffle [ shuffleSongs ] [ if $musicPlayerRepeat [ repeatLastPlayedSong ]; shuffling = 0 ] ]
  155.       ] [
  156.         music $arg1 $arg2 [ if $musicPlayerRepeat [ repeatLastPlayedSong ] ]
  157.       ]
  158.     ]
  159.     musicstopped = 0
  160.     lastPlayedSong = $tmpSongInfo
  161.     if $musicNowPlayingPopup [ nowPlayingMenu ]
  162.   ]
  163. ]
  164.  
  165. repeatLastPlayedSong = [
  166.   if (checkalias lastPlayedSong) [
  167.     playSong (at $lastPlayedSong 0) (at $lastPlayedSong 1)
  168.   ]
  169. ]
  170.  
  171. skipSong = [
  172.   tmpSongPos = (findlist $songLibrary (at $lastPlayedSong 0))
  173.   if (= $arg1 -1) [ -= tmpSongPos 1 ] [ += tmpSongPos 1 ]
  174.   if (= $tmpSongPos -1) [
  175.     if (|| $wrapAround $musicPlayerLoopLib) [ tmpSongPos = (- (listlen $songLibrary) 1); if $musicDebugMode [ echo (blue)Debug: (white)Wrapping down... ] ] [
  176.       if $musicDebugMode [ echo (blue)Debug: (white)First song, skipSong going to next track instead. ]
  177.       += tmpSongPos 2
  178.     ]
  179.   ] [
  180.     if (= $tmpSongPos (listlen $songLibrary)) [
  181.       if (|| $wrapAround $musicPlayerLoopLib) [ tmpSongPos = 0; if $musicDebugMode [ echo (blue)Debug: (white)Wrapping up... ] ] [
  182.         if $musicDebugMode [ echo (blue)Debug: (white)Last song, skipSong going to previous track instead. ]
  183.         -= tmpSongPos 2
  184.       ]
  185.     ]
  186.   ]
  187.   if (&& (> $tmpSongPos -1) (< $tmpSongPos (listlen $songLibrary))) [
  188.     if $musicPlayerLoopLib [ playSong (at $songLibrary $tmpSongPos) (at $songLengths $tmpSongPos) loop ] [
  189.       playSong (at $songLibrary $tmpSongPos) (at $songLengths $tmpSongPos)
  190.     ]
  191.   ] [ if $musicDebugMode [ echo (blue)Debug: (white)skipSong could not find a valid song to play. ] ]
  192. ]
  193.  
  194. loopLib = [
  195.   if (listlen $songLibrary) [
  196.     musicPlayerLoopLib = 1
  197.     playSong (at $songLibrary 0) (at $songLengths 0) loop
  198.   ]
  199. ]
  200.  
  201. wasAlreadyPlayed = [
  202.   yep = 0
  203.   if (= (listlen $alreadyPlayed) (listlen $songLibrary)) [
  204.     alreadyPlayed = ""
  205.     if $musicDebugMode [ echo (blue)Debug: (white)Resetting alreadyPlayed list. ]
  206.     result 0
  207.   ] [
  208.     loop fd (listlen $alreadyPlayed) [
  209.       if (strcmp (at $alreadyPlayed $fd) (at $songLibrary $arg1)) [ yep = 1; break ]
  210.     ]
  211.     if $yep [ if $musicDebugMode [ echo (blue)Debug: (white)Track (at $songLibrary $arg1) was already played. Trying again... ] ]
  212.     result $yep
  213.   ]
  214. ]
  215.  
  216. getValidSongInt = [
  217.   tmpRandomSong = (rrnd 0 (listlen $songLibrary))
  218.   if (wasAlreadyPlayed $tmpRandomSong) [ getValidSongInt ] [
  219.     result $tmpRandomSong
  220.   ]
  221. ]
  222.  
  223. shuffleSongs = [
  224.   randomSongPos = (getValidSongInt)
  225.   if $musicDebugMode [ echo (blue)Debug: (white)Chosen Random Position: (concatword $randomSongPos / (- (listlen $songLibrary) 1)) ]
  226.   playSong (at $songLibrary $randomSongPos) (at $songLengths $randomSongPos) shuffle
  227.   add2list alreadyPlayed (at $songLibrary $randomSongPos)
  228. ]
  229.  
  230. newmenu "Music Player Settings"
  231. menuitemcheckbox "Loop Shuffle: " "$musicPlayerLoopShuffle" [ musicPlayerLoopShuffle = $arg1 ]
  232. menuitemcheckbox "Pop-up Now Playing on new song: " "$musicNowPlayingPopup" [ musicNowPlayingPopup = $arg1 ]
  233. menuitemcheckbox "Next/Previous track library wrap around: " "$wrapAround" [ wrapAround = $arg1 ]
  234. menuitemcheckbox "Debug Mode: " "$musicDebugMode" [ musicDebugMode = $arg1 ]
  235.  
  236. reset  = [ loop za (listlen $arg1) [ (at $arg1 $za) = $arg2 ] ]
  237. resetc = [ loop za (listlen $arg1) [ if (! (checkalias (at $arg1 $za))) [ (at $arg1 $za) = $arg2 ] ] ]
  238.  
  239. reset "alreadyPlayed lastPlayedSong" ""
  240. reset "shuffling musicPlayerLoopLib" 0
  241. reset "musicstopped" 1
  242. resetc "musicPlayerRepeat musicNowPlayingPopup musicDebugMode" 0
  243. resetc "wrapAround musicPlayerLoopShuffle" 1
  244.  
  245. genMusicMainMenu
  246.  
  247. addListOnQuit "songLibrary songLengths songLibraryNames songLibraryArtists musicMainMenuName genMusicMainMenu genSongList nowPlayingMenu playSong repeatLastPlayedSong skipSong lastPlayedSong lastmusicsel tmpSongPos musicstopped songPosition reset resetc"
Advertisement
Add Comment
Please, Sign In to add comment