Guest User

Quicksound

a guest
Oct 6th, 2010
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.22 KB | None | 0 0
  1. ; <COMPILER: v1.0.47.6>
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9. Media_Open(File, Alias=""){
  10. Static SoundNumber = 0
  11. IfNotExist, %File%
  12. {
  13. ErrorLevel = -2
  14. Return 0
  15. }
  16. If Alias =
  17. {
  18. SoundNumber ++
  19. Alias = AutoHotkey%SoundNumber%
  20. }
  21.  
  22.  
  23. ErrorLevel := _mciExecute("open """ File """ alias " Alias)
  24. Return Alias
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. Media_Close(MediaHandle){
  33. Return _mciExecute("close " MediaHandle)
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. Media_Play(MediaHandle, Wait=0){
  52. If(Wait <> 0 AND Wait <> 1)
  53. Return -2
  54. If Wait = 1
  55. Return _mciExecute("play " MediaHandle " wait")
  56. Else
  57. Return _mciExecute("play " MediaHandle)
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. Media_Stop(MediaHandle){
  74. ret := _mciExecute("seek " MediaHandle " to start")
  75. ret := ret && _mciExecute("stop " MediaHandle)
  76. Return ret
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. Media_Pause(MediaHandle){
  93. Return _mciExecute("pause " MediaHandle)
  94. }
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. Media_Resume(MediaHandle){
  108. Return _mciExecute("resume " MediaHandle)
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. Media_Length(MediaHandle){
  125. rc := _mciSendString("set time format milliseconds", dummy)
  126. If !rc
  127. Return -rc
  128. _mciSendString("status " MediaHandle " length", ret)
  129. Return ret
  130. }
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. Media_Seek(MediaHandle, Position, Relative=0){
  149. rc := _mciSendString("set time format milliseconds", dummy)
  150. _mciSendString("status " MediaHandle " mode", stat)
  151. If stat = playing
  152. _mciExecute("pause " MediaHandle)
  153. If !rc
  154. Return -rc
  155. _mciSendString("status " MediaHandle " position", cpos)
  156. _mciSendString("status " MediaHandle " length", length)
  157. If Relative = 1
  158. cpos += Position
  159. Else
  160. cpos := Position
  161. If cpos > %length%
  162. cpos = %length%
  163. If cpos < 0
  164. cpos = 0
  165. ret := _mciExecute("seek " MediaHandle " to " cpos)
  166. If stat = playing
  167. _mciExecute("play " MediaHandle)
  168. Return ret
  169. }
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186. Media_Status(MediaHandle){
  187. _mciSendString("status " MediaHandle " mode", ret)
  188. Return ret
  189. }
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. Media_Position(MediaHandle){
  205. rc := _mciSendString("set time format milliseconds", dummy)
  206. If !rc
  207. Return -rc
  208. _mciSendString("status " MediaHandle " position", ret)
  209. Return ret
  210. }
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225. Media_ToMilliseconds(Hour, Min, Sec){
  226. milli := Sec * 1000
  227. milli += (Min * 60) * 1000
  228. milli += (Hour * 3600) * 1000
  229. Return milli
  230. }
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243. Media_ToHHMMSS(milliseconds, ByRef Hour, ByRef Min, ByRef Sec){
  244. milliseconds //= 1000
  245. Sec := Mod(milliseconds, 60)
  246. milliseconds //= 60
  247. Min := Mod(milliseconds, 60)
  248. milliseconds //= 60
  249. Hour := Mod(milliseconds, 60)
  250. }
  251.  
  252. _mciExecute(string){
  253. Return DllCall("winmm.dll\mciExecute", "str", string, "Cdecl Int")
  254. }
  255.  
  256. _mciSendString(string, ByRef output, handle=0){
  257. VarSetCapacity(output, 36, 0)
  258. ret := DllCall("winmm.dll\mciSendStringA", "str", string, "str", output, "int", 36, "uint", 0, "Cdecl Int")
  259. If ErrorLevel
  260. Return -ErrorLevel
  261. Return ret
  262. }
  263. #Persistent
  264.  
  265.  
  266.  
  267.  
  268. #SingleInstance force
  269. SetBatchLines, 10ms
  270. CoordMode, ToolTip
  271. IfNotExist, QuickSound.ini
  272. {
  273. Playcount = 0
  274. atrue=t
  275. IniWrite, %PlayCount%, Quicksound.ini, Playlist, Playcount
  276. IniWrite, %atrue%, Quicksound.ini, PlayRandom, PlayRandom
  277. Gui, Add, Text, x6 y0 w450 h130 ,
  278. (
  279. I see you are a First time user of QuickSound!`n`nTo use simply press F1`, type in your song and hit Enter and the song will load.
  280. You will need to`nset your File path of music First though.
  281. )
  282.  
  283. Gui, Add, Text, x6 y170 w440 h100 ,
  284. (
  285. If ToolTip Mode is set to 0 no ToolTip will appear.`n If set to 1 will display song `nIf set to 2 will display song and path directory
  286. `nIf set to 3 will display song with your static ToolXY coordinates`n If set to 4 will display song and
  287. path directory with your stationery ToolXY coordinates
  288. )
  289. Guide =
  290. (
  291. F1
  292. Type in part of a song name, it will play when you press enter (first match)
  293. F2
  294. Opens music list
  295. F3
  296. Type in where in the song you want to seek to
  297. F4
  298. Update music list
  299. F5
  300. Next random song
  301. F6
  302. Set ToolTip area
  303. F7
  304. Open current songs directory
  305. F8
  306. Open QuickSound.ini (you will understand later if you don't know :P)
  307. F9
  308. Opens programs directory
  309. F10
  310. Add song to playlist
  311. F11
  312. Play song from Playlist (random if playlist mode is already on)
  313.  
  314. After pressing OK this text will save itself to a help document.
  315. )
  316.  
  317. Gui, Add, Text, x456 y0 w470 h380 , %Guide%
  318. Gui, Add, Radio, vToolMode x25 y319 w100 h30 , 0
  319. Gui, Add, Radio, checked x25 y349 w100 h30 , 1
  320. Gui, Add, Radio, x25 y379 w100 h30 , 2
  321. Gui, Add, Text, x195 y469 w250 h30 , Set Music path
  322. Gui, Add, Edit, vPath x195 y499 w140 h30 , C:\Music
  323. Gui, Add, Edit, vToolX x150 y364 w140 h30 , ToolX(numbers)
  324. Gui, Add, Edit, vToolY x150 y404 w140 h30 , ToolY(numbers)
  325. Gui, Add, Button, gOk x506 y430 w340 h120 , OK
  326. Gui, Show, x131 y91 h605 w928, QuickSound
  327. FileDelete, Guide.txt
  328. FileAppend, %Guide%, Guide.txt
  329. Return
  330.  
  331.  
  332. }
  333. IfExist, QuickSound.ini
  334. {
  335. IniRead, Path, QuickSound.ini, Path, Path
  336. }
  337.  
  338.  
  339.  
  340. Gosub, UpdateMusic
  341. Gosub, RandomSong
  342. Return
  343. F1::
  344. PlayMusic:
  345. Exit = true
  346. ;Gosub, ToolTipMp3
  347.  
  348. Input, UserInput, T30,{Enter}{ins}
  349. IfEqual,userInput,, Return
  350. endkey=%Errorlevel%
  351. Loop, read, mp3s.txt
  352. {
  353. mp3 = %A_LoopReadline%
  354. Found = Yes
  355. Loop, Parse, UserInput, %a_Space%
  356. IfNotInString, mp3, %A_LoopField%, SetEnv, Found, No
  357.  
  358. IfEqual, Found, Yes
  359. {
  360. If hSound {
  361. Media_Close(hSound)
  362. }
  363.  
  364. hSound := Media_Open(mp3, "myfile")
  365. Found = No
  366. Break
  367. }
  368. }
  369. Gosub, MyPause
  370.  
  371. Goto, ToolTipMP3
  372. Return
  373.  
  374.  
  375. Pause::
  376. MyPause:
  377. Status := Media_Status(hSound)
  378. If(Status = "stopped" OR Status = "Paused")
  379. {
  380. If Status = stopped
  381. Media_Play(hSound)
  382. Else
  383. Media_Resume(hSound)
  384. playing = 1
  385. }Else{
  386. Media_Pause(hSound)
  387. playing = 0
  388. }
  389.  
  390. Return
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397. F2::
  398. Run mp3s.txt
  399. Return
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406. F3::
  407. Input, Seek,,{Enter}
  408. StringLen, Length, Seek
  409. If Length = 4
  410. {
  411. StringLeft, MinS, Seek, 2
  412. StringRight, SecS, Seek, 2
  413. }
  414. Else If Length = 3
  415. {
  416. StringLeft, MinS, Seek, 1
  417. StringRight, SecS, Seek, 2
  418. }
  419. Else If Length = 2
  420. StringRight, SecS, Seek, 2
  421. Else If Length = 1
  422. StringRight, SecS, Seek, 1
  423. Seek := SecS * 1000
  424. Seek += (MinS * 60) * 1000
  425.  
  426. Media_Seek(hSound, Seek)
  427. Return
  428.  
  429. RandomSong:
  430. IniRead, Count, QuickSound.ini, Count, Count
  431. If hSound {
  432. Media_Stop(hSound)
  433. Media_Close(hSound)
  434. }
  435. IniRead, PlayRandom, Quicksound.ini, PlayRandom, PlayRandom
  436. if (PlayRandom = "t")
  437. {
  438. Random, Rand, 1, %Count%
  439. FileReadLine, Mp3, mp3s.txt, %Rand%
  440.  
  441. }
  442. else if (PlayRandom ="f")
  443. {
  444. IniRead, Playcount, Quicksound.ini, Playlist, Playcount
  445. Playcount++
  446. IniWrite, %Playcount%, Quicksound.ini, Playlist, Playcount
  447. IniRead, PlayListSize, Quicksound.ini, Playlist, PlayListSize
  448.  
  449.  
  450. if (Playcount>PlayListSize) {
  451. Playcount = 1
  452. Iniwrite, %Playcount%, Quicksound.ini, Playlist, Playcount
  453. }
  454. FileReadLine, Mp3, playlist1.txt, %Playcount%
  455.  
  456. }
  457. hSound := Media_Open(Mp3, "myfile")
  458.  
  459. Gosub, MyPause
  460. Gosub, ToolTipMP3
  461. Gosub, RandomSong
  462. Return
  463. F4::
  464. UpdateMusic:
  465. Count = 0
  466. FileDelete, mp3s.txt
  467. Fileappend, , mp3s.txt
  468. Loop, %path%, 0,1
  469. {
  470. mp3 := A_loopfilename
  471.  
  472. Splitpath, mp3,,,Extension
  473. if (Extension != "mp3" && Extension != "wma")
  474. Continue
  475. else
  476. {
  477. FileAppend, %a_loopfilefullpath%`n, mp3s.txt
  478. Count++
  479. }
  480.  
  481.  
  482. }
  483.  
  484.  
  485.  
  486. Count -= 1
  487. IniWrite, %Count%, QuickSound.ini, Count, Count
  488. Tooltip, Ready%a_tab%%a_tab%%a_tab%`n`n`n`n%a_space%
  489. Sleep 1000
  490. Tooltip
  491. Return
  492.  
  493. F5::
  494. Next:
  495. Media_Seek(hSound, Media_Length(hSound))
  496. Return
  497. ExitSub:
  498. If hSound {
  499. Media_Close(hSound)
  500. }
  501. ExitApp
  502. Return
  503.  
  504.  
  505.  
  506. Return
  507.  
  508.  
  509.  
  510.  
  511. ToolTipMP3:
  512. if (Exit = true)
  513. Exit
  514. Exit = false
  515. Gosub, sNameTrim
  516. len := Media_Length(hSound)
  517. Loop {
  518. IniRead, ToolMode, QuickSound.ini, ToolMode, ToolMode
  519. IniRead, ToolX, QuickSound.ini, ToolX, ToolX
  520. IniRead, ToolY, QuickSound.ini, ToolY, ToolY
  521. Sleep 100
  522. pos := Media_Position(hSound)
  523. If(pos >= len){
  524. Break
  525. }
  526. Media_ToHHMMSS(pos, hh, mm, ss)
  527. Media_ToHHMMSS(len, hh, lm, ls)
  528. If (ToolMode = 0)
  529. ToolTip
  530.  
  531. Else If (ToolMode = 1)
  532. ToolTip, %sName%`n%mm%:%ss% / Length %lm%:%ls%, %ToolX%, %ToolY%
  533. Else If (ToolMode = 2)
  534. ToolTip, %sName%`n%mm%:%ss% / Length %lm%:%ls%`n%mp3%, %ToolX%, %ToolY%
  535. }
  536. IniWrite, %mp3%, QuickSound.ini, Mp3Playing, Mp3Playing
  537. Return
  538.  
  539. Ok:
  540. Gui, Submit
  541. Path = %Path%\*.*
  542. IniWrite, %Path%, QuickSound.ini, Path, Path
  543. IniWrite, %ToolX%, QuickSound.ini, ToolX, ToolX
  544. IniWrite, %ToolY%, QuickSound.ini, ToolY, ToolY
  545. IniWrite, %ToolMode%, QuickSound.ini, ToolMode, Toolmode
  546.  
  547. Gosub, UpdateMusic
  548. Gosub, RandomSong
  549. Return
  550.  
  551.  
  552.  
  553. F6::
  554.  
  555. MouseGetPos, ToolX, ToolY
  556. IniWrite, %ToolX%, QuickSound.ini, ToolX, ToolX
  557. IniWrite, %ToolY%, QuickSound.ini, ToolY, ToolY
  558. Return
  559.  
  560. F7::
  561. Splitpath, Mp3, , Mp3Dir
  562. Run %Mp3Dir%
  563. Return
  564. f8::
  565. Run QuickSound.ini
  566. return
  567.  
  568. f9::
  569. Run %a_scriptdir%
  570. return
  571.  
  572.  
  573.  
  574. F10::
  575. FileRead, NoDoubles, playlist1.txt
  576. IfNotInString, NoDoubles, %mp3%
  577. {
  578. Fileappend, %mp3%`n, playlist1.txt
  579. IniRead, PlayListSize, Quicksound.ini, Playlist, PlaylistSize
  580. PlayListSize++
  581. IniWrite, %PlayListSize%, Quicksound.ini, Playlist, PlaylistSize
  582. }
  583. Return
  584.  
  585. PgUp::
  586. Gosub, ListReadWrite
  587. Gosub, PlayfromList
  588. Return
  589.  
  590. PgDn::
  591. Pagedown:
  592. Gosub, ListReadWrite
  593. Gosub, PlayfromList
  594. Return
  595.  
  596.  
  597.  
  598. PlayfromList: ;() {
  599. FileReadLine, Mp3, playlist1.txt, %Playcount%
  600. If hSound {
  601. Media_Close(hSound)
  602. }
  603. hSound := Media_Open(Mp3, "myfile")
  604. Media_Play(hSound)
  605. Gosub, sNameTrim
  606. len := Media_Length(hSound)
  607. Media_ToHHMMSS(pos, hh, mm, ss)
  608. Media_ToHHMMSS(len, hh, lm, ls)
  609.  
  610.  
  611.  
  612. Return ;}
  613.  
  614. ListReadWrite: ;() {
  615.  
  616. IniRead, PlayListSize, Quicksound.ini, Playlist, PlaylistSize
  617. IniRead, Playcount, Quicksound.ini, Playlist, Playcount
  618.  
  619. if (A_ThisHotkey="PgUp")
  620. Playcount-=1
  621. if (A_ThisHotkey="PgDn")
  622. Playcount+=1
  623.  
  624. if (Playcount=0)
  625. Playcount := PlayListSize
  626. if (Playcount>PlayListSize)
  627. Playcount = 1
  628.  
  629.  
  630. IniWrite, %Playcount%, Quicksound.ini, Playlist, Playcount
  631.  
  632. Return ;}
  633.  
  634.  
  635.  
  636. sNameTrim:
  637. StringLen, sLength, mp3
  638. StringGetPos, cTrim, mp3, \, R1
  639. cTrim += 2
  640. fName := (sLength+1) - cTrim
  641. StringMid, sName, mp3, %cTrim%, %fName%
  642.  
  643. Return
Advertisement
Add Comment
Please, Sign In to add comment