AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Useless Toy: PC Beep Composer

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Tyrsius



Joined: 09 Jul 2009
Posts: 140

PostPosted: Thu Jan 21, 2010 2:53 am    Post subject: Useless Toy: PC Beep Composer Reply with quote

Bored at work one day using a computer with no speakers, I set out to make music from error tones. This little package is the result.

It is a GUI that allows you create sequences to play through your PC Beep Speaker, allowing you to control Frequency, Duration, and tempo (pause before the next tone) for each individual sound. You can add as many sounds as you want. The notes to make it play Zelda are below the code.

Warning: This tool can quickly become a time-waster.

Code:

F9::
Gui, 14: Destroy
   {
   Gui, 14:Default
   TunerRowCount=3
   TunerRowHeight=80
   Gui, Add, Text, x5 y5 w60 h20 , Frequency:
   Gui, Add, Text, x75 y5 w60 h20, Duration:
   Gui, Add, Text, x145 y5 w60 h20, Tempo:
   Gui, Add, Button, x5 y110 w60 h20 default vTunerPlay, Play
   Gui, Add, Edit, x75 y110 w20 h20 vTunerLoop, 1
   Gui, Add, Button, x145 y110 w60 h20 vTunerAddRow gTuner_AddRow, Add Row
   Gui, Add, Edit, x5 y30 w60 h20 vBeepFreq1,
   Gui, Add, Edit, x75 y30 w60 h20 vBeepDur1, 
   Gui, Add, Edit, x145 y30 w60 h20 vBeepTempo1, 
   Gui, Add, Edit, x5 y55 w60 h20 vBeepFreq2,
   Gui, Add, Edit, x75 y55 w60 h20 vBeepDur2, 
   Gui, Add, Edit, x145 y55 w60 h20 vBeepTempo2, 
   Gui, Add, Edit, x5 y80 w60 h20 vBeepFreq3,
   Gui, Add, Edit, x75 y80 w60 h20 vBeepDur3, 
   Gui, Add, Edit, x145 y80 w60 h20 vBeepTempo3,
   Gui, Show, Autosize, PC Beep Composer
   Return
   
   14GuiEscape:
   14GuiClose:
   Gui, 14:Destroy
   Return
   
   14ButtonPlay:
   Gui, Submit, NoHide
   loop, %TunerLoop%
      {
      loop, %TunerRowCount%
         {
         BeepFreq := BeepFreq%A_Index%
         BeepDur :=  BeepDur%A_Index%
         BeepTempo := BeepTempo%A_Index%
         if (BeepFreq="")
            {
            continue
            }
         SoundBeep, %BeepFreq%, %BeepDur%
         Sleep, %BeepTempo%
         }
      }
   Return
   
   Tuner_AddRow:
   Gui, 14:Submit, NoHide
   TunerRowCount++
   TunerRowHeight+=25
   TunerButtonRowHeight := TunerRowHeight+30
   Gui, Add, Edit, x5 y%TunerRowHeight% w60 h20 vBeepFreq%TunerRowCount%,
   Gui, Add, Edit, x75 y%TunerRowHeight% w60 h20 vBeepDur%TunerRowCount%,
   Gui, Add, Edit, x145 y%TunerRowHeight% w60 h20 vBeepTempo%TunerRowCount%, 

   GuiControl, Move, TunerPlay, x5 y%TunerButtonRowHeight%
   GuiControl, Move, TunerLoop, x75 y%TunerButtonRowHeight%
   GuiControl, Move, TunerAddRow, x145 y%TunerButtonRowHeight%
   Gui, Show, AutoSize
   Return
   }

Return


You can use this next bit to add in the necessary information to play the zelda tone. Ensure you have 30 rows before starting this.

Code:

F10::
zelda=
(
463{tab}400{tab}{tab}
344{tab}500{tab}{tab}
463{tab}100{tab}{tab}
463{tab}100{tab}{tab}
512{tab}100{tab}{tab}
576{tab}100{tab}{tab}
612{tab}100{tab}{tab}
689{tab}800{tab}{tab}
689{tab}200{tab}{tab}
689{tab}133{tab}{tab}
732{tab}133{tab}{tab}
823{tab}133{tab}{tab}
926{tab}950{tab}{tab}
926{tab}150{tab}{tab}
926{tab}100{tab}{tab}
926{tab}133{tab}{tab}
823{tab}133{tab}{tab}
732{tab}133{tab}{tab}
823{tab}300{tab}{tab}
732{tab}100{tab}{tab}
689{tab}800{tab}{tab}
689{tab}400{tab}{tab}
612{tab}200{tab}{tab}
612{tab}100{tab}{tab}
689{tab}100{tab}{tab}
732{tab}800{tab}{tab}
698{tab}200{tab}{tab}
612{tab}200{tab}{tab}
544{tab}200{tab}{tab}
544{tab}100{tab}{tab}
612{tab}100{tab}{tab}
689{tab}800{tab}{tab}
)
stringreplace, zelda, zelda, `n,, all
stringreplace, zelda, zelda, `r,, all
sendinput %zelda%
Return


Enjoy =)
Back to top
View user's profile Send private message
Tyrsius



Joined: 09 Jul 2009
Posts: 140

PostPosted: Fri Mar 12, 2010 2:03 am    Post subject: Reply with quote

Now has Open/Save capability!

This version is a standalone script
Code:

TunerRowCount=3
TunerRowHeight=80
Gui, Add, Text, x5 y5 w60 h20 , Frequency:
Gui, Add, Text, x75 y5 w60 h20, Duration:
Gui, Add, Text, x145 y5 w60 h20, Tempo:
Gui, Add, Button, x5 y110 w60 h20 default vTunerPlay, Play
Gui, Add, Edit, x75 y110 w20 h20 vTunerLoop, 1
Gui, Add, Button, x145 y110 w60 h20 vTunerAddRow gTuner_AddRow, Add Row
Gui, Add, Edit, x5 y30 w60 h20 vBeepFreq1,
Gui, Add, Edit, x75 y30 w60 h20 vBeepDur1, 
Gui, Add, Edit, x145 y30 w60 h20 vBeepTempo1, 
Gui, Add, Edit, x5 y55 w60 h20 vBeepFreq2,
Gui, Add, Edit, x75 y55 w60 h20 vBeepDur2, 
Gui, Add, Edit, x145 y55 w60 h20 vBeepTempo2, 
Gui, Add, Edit, x5 y80 w60 h20 vBeepFreq3,
Gui, Add, Edit, x75 y80 w60 h20 vBeepDur3, 
Gui, Add, Edit, x145 y80 w60 h20 vBeepTempo3,

Menu, PCBeepFileMenu, Add, Open Composition, PCBeepMenuOpen
Menu, PCBeepFileMenu, Add, Save Composition, PCBeepMenuSave
Menu, PCBeepFileMenu, Add,
Menu, PCBeepFileMenu, Add, Exit, PCBeepMenuExit
Menu, PCBeepMenuBar, Add, File, :PCBeepFileMenu

Gui, Menu, PCBeepMenuBar
Gui, Show, Autosize, PC Beep Composer
Return

PCBeepMenuOpen:
FileSelectFile, PCBFileToOpen, 3, %A_MyDocuments%, Select a Composition, PC Beep Composition (*.pcbc)
if ErrorLevel
   return
FileRead, PCBOpenedFile, %PCBFileToOpen%
PCBOpenedFile_RowCount=0
loop, parse, PCBOpenedFile, `n
   {
   PCBOpenedFile_RowCount++
   loop, parse, A_Loopfield, CSV
      {
      PCBOpenedFile_R%PCBOpenedFile_RowCount%_C%A_Index% := A_Loopfield
      }
   }
if (PCBOpenedFile_RowCount>TunerRowCount)
   {
   PCBOpenedFile_RowDiff := PCBOpenedFile_RowCount-TunerRowCount
   loop, %PCBOpenedFile_RowDiff%
      {
      GoSub, Tuner_AddRow
      }
   }
   
loop, %PCBOpenedFile_RowCount%
   {
   BeepFreq := PCBOpenedFile_R%A_Index%_C1
   BeepDur :=  PCBOpenedFile_R%A_Index%_C2
   BeepTempo := PCBOpenedFile_R%A_Index%_C3
   
   GuiControl,, BeepFreq%A_Index%, %BeepFreq%
   GuiControl,, BeepDur%A_Index%, %BeepDur%
   GuiControl,, BeepTempo%A_Index%, %BeepTempo%
   
   }
Return

PCBeepMenuSave:
Gui, Submit, NoHide
FileSelectFile, PCBFileToSave, S 19, %A_MyDocuments%\untitled, Select a Composition, PC Beep Composition (*.pcbc)
if ErrorLevel
   return
ifnotinstring, PCBFileToSave, `.pcbc
   PCBFileToSave := PCBFileToSave ".pcbc"
PCBFileData :=

loop, %TunerRowCount%
   {
   BeepFreq := BeepFreq%A_Index%
   BeepDur :=  BeepDur%A_Index%
   BeepTempo := BeepTempo%A_Index%
   PCBFileData := PCBFileData BeepFreq "," BeepDur "," BeepTempo ",`n"
   }
StringTrimRight, PCBFileData, PCBFileData, 1
IfExist, %PCBFileToSave%
   FileDelete, %PCBFileToSave%
FileAppend, %PCBFileData%, %PCBFileToSave%
return

      
GuiEscape:
GuiClose:
PCBeepMenuExit:
Gui, Destroy
Menu, PCBeepFileMenu, DeleteAll
ExitApp
Return

ButtonPlay:
Gui, Submit, NoHide
if (TunerLoop>5)
   {
   msgbox, Loop restricted to 5
   TunerLoop=5
   }
loop, %TunerLoop%
   {
   loop, %TunerRowCount%
      {
      BeepFreq := BeepFreq%A_Index%
      BeepDur :=  BeepDur%A_Index%
      BeepTempo := BeepTempo%A_Index%
      if (BeepFreq>=7000) && (A_Username="mmurrow")
         {
         msgbox, NO! THATS TOO HIGH!
         return
         }
      if (BeepFreq="")
         {
         continue
         }
      SoundBeep, %BeepFreq%, %BeepDur%
      Sleep, %BeepTempo%
      }
   }
Return

Tuner_AddRow:
Gui, Submit, NoHide
TunerRowCount++
TunerRowHeight+=25
TunerButtonRowHeight := TunerRowHeight+30
Gui, Add, Edit, x5 y%TunerRowHeight% w60 h20 vBeepFreq%TunerRowCount%,
Gui, Add, Edit, x75 y%TunerRowHeight% w60 h20 vBeepDur%TunerRowCount%,
Gui, Add, Edit, x145 y%TunerRowHeight% w60 h20 vBeepTempo%TunerRowCount%, 

GuiControl, Move, TunerPlay, x5 y%TunerButtonRowHeight%
GuiControl, Move, TunerLoop, x75 y%TunerButtonRowHeight%
GuiControl, Move, TunerAddRow, x145 y%TunerButtonRowHeight%
Gui, Show, AutoSize
Return

Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 1886
Location: Germany

PostPosted: Fri Mar 12, 2010 8:18 am    Post subject: Reply with quote

nice

I love The Legend of Zelda.
_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--
Back to top
View user's profile Send private message Send e-mail Visit poster's website
bar
Guest





PostPosted: Sat Mar 13, 2010 1:54 am    Post subject: Reply with quote

it doesnt seem to work for me
Back to top
Tyrsius



Joined: 09 Jul 2009
Posts: 140

PostPosted: Sat Mar 13, 2010 3:49 am    Post subject: Reply with quote

Okay so I know I filed this thing under useless, but my co-workers have been getting a good kick out of it and this update is pretty significant. The script remains a standalone, with a hotkey to call the GUI up (so that it can remain open without a window).

It now uses tabs for pages, allowing much, much larger compositions to be made. The RowsPerPage and starting pages are easily modified variables near the top of the script, and can be changed without modifying any other code. Instead of an add row button, there is not an add page button.Saving is still supported, and Opening will work with files made using the last posted version.

The default RowsPerPage is set to 25, and the tabs are capped at 250, so with default settings you can have up to 6250 rows. The old version could fit between 35-50 depending on your screen size. Its a pretty significant gain.

If you have any problems with this version (I am looking at you, previous poster) please let me know what errors you got, or what you did that failed to produce the expected output.

Code:

F1::
FormatTime, TimeCheck, , HH

PCBeepHelpText=
(
Thanks to Patrick, PC Beep now supports EasyNote Conversions.
Simply Type in one of the notes below into the Frequency box
and PC Beep will translate it into a matching freqeuncy!

*=a/b/c/d/e/f/g
$=a/b/d/e/g

-2* - Note 2 octaves below C
-* - Note 1 ocatave below C
* - Note in octave C
2* - Note 2 octaves above C
3c - C above high C
-$b - Flat notes an octave below C
$b - Flat notes an octave even with C
2$b - Flat notes 2 octaves above C

)

Gui, 14: Destroy
   {
   Gui, 14:Default
   
   RowsPerPage=25
   PageCount=0
   PagesToStart=2
   PageHeight := (RowsPerPage*25)+20
   TabText :=
   Gui, Add, Button, x5 y2 w60 h20 default vTunerPlay, Play
   Gui, Add, Edit, x75 y5 w20 h20 vTunerLoop, 1
   Gui, Add, Button, x145 y5 w60 h20 vTunerAddRow gTuner_AddPage, Add Page
   
   Gui, Add, Tab2, x5 y35 w230 h%PageHeight% vPCBeepTab -wrap buttons,
   loop, %PagesToStart%
      {
      gosub Tuner_AddPage
      }
   
   Menu, PCBeepFileMenu, Add, Open Composition, PCBeepMenuOpen
   Menu, PCBeepFileMenu, Add, Save Composition, PCBeepMenuSave
   Menu, PCBeepFileMenu, Add, Help, PCBeepMenuHelp
   Menu, PCBeepFileMenu, Add,
   Menu, PCBeepFileMenu, Add, Exit, PCBeepMenuExit
   Menu, PCBeepMenuBar, Add, File, :PCBeepFileMenu
   
   Gui, Menu, PCBeepMenuBar
   Gui, Show, Autosize, PC Beep Composer
   Return
   
   PCBeepMenuOpen:
   FileSelectFile, PCBFileToOpen, 3, %A_MyDocuments%, Select a Composition, PC Beep Composition (*.pcbc)
   if ErrorLevel
      return
   loop, %TunerRowCount% ; clear current contents
      {
      GuiControl,, BeepFreq%A_Index%,
      GuiControl,, BeepDur%A_Index%,
      GuiControl,, BeepTempo%A_Index%,   
      }
   FileRead, PCBOpenedFile, %PCBFileToOpen%
   PCBOpenedFile_RowCount=0
   loop, parse, PCBOpenedFile, `n
      {
      PCBOpenedFile_RowCount++
      loop, parse, A_Loopfield, CSV
         {
         PCBOpenedFile_R%PCBOpenedFile_RowCount%_C%A_Index% := A_Loopfield
         }
      }
   PagesRequired := PCBOpenedFile_RowCount / RowsPerPage
   if (PagesRequired>PageCount)
      {
      PCBOpenedFile_Diff := PagesRequired-PageCount
      while (PCBOpenedFile_Diff>0)
         {
         GoSub, Tuner_AddPage
         PCBOpenedFile_Diff--
         }
      }
      
   loop, %PCBOpenedFile_RowCount%
      {
      BeepFreq := PCBOpenedFile_R%A_Index%_C1
      BeepDur :=  PCBOpenedFile_R%A_Index%_C2
      BeepTempo := PCBOpenedFile_R%A_Index%_C3
      
      GuiControl,, BeepFreq%A_Index%, %BeepFreq%
      GuiControl,, BeepDur%A_Index%, %BeepDur%
      GuiControl,, BeepTempo%A_Index%, %BeepTempo%
      
      }
   Return
   
   PCBeepMenuSave:
   Gui, Submit, NoHide
   FileSelectFile, PCBFileToSave, S 19, %A_MyDocuments%\untitled, Select a Composition, PC Beep Composition (*.pcbc)
   if ErrorLevel
      return
   ifnotinstring, PCBFileToSave, `.pcbc
      PCBFileToSave := PCBFileToSave ".pcbc"
   PCBFileData :=
   
   loop, %TunerRowCount%
      {
      BeepFreq := BeepFreq%A_Index%
      BeepDur :=  BeepDur%A_Index%
      BeepTempo := BeepTempo%A_Index%
      PCBFileData := PCBFileData BeepFreq "," BeepDur "," BeepTempo ",`n"
      }
   StringTrimRight, PCBFileData, PCBFileData, 1
   IfExist, %PCBFileToSave%
      FileDelete, %PCBFileToSave%
   FileAppend, %PCBFileData%, %PCBFileToSave%
   return
   
   PCBeepMenuHelp:
   msgbox, %PCBeepHelpText%
   return
         
   14GuiEscape:
   14GuiClose:
   PCBeepMenuExit:
   Gui, 14:Destroy
   Menu, PCBeepFileMenu, DeleteAll
   Return
   
   14ButtonPlay:
   Gui, Submit, NoHide
   if (TunerLoop>5)
      {
      msgbox, Loop restricted to 5
      TunerLoop=5
      }
   loop, %TunerLoop%
      {
      loop, %TunerRowCount%
         {
         BeepFreq := BeepFreq%A_Index%
         BeepDur :=  BeepDur%A_Index%
         BeepTempo := BeepTempo%A_Index%
         if (BeepFreq="")
            {
            continue
            }
         GoSub Tuner_EasyNoteTranslate
         SoundBeep, %BeepFreq%, %BeepDur%
         Sleep, %BeepTempo%
         }
      }
   Return
   
   Tuner_AddPage:
   Gui, Submit, NoHide
   PageCount++
   if (PageCount=251)
      {
      msgbox, Unable to create more pages, please upgrade your OS.
      PageCount--
      return
      }
   TabText .= "Page " PageCount "`|"
   GuiControl, , PCBeepTab, |%TabText%
   GuiControl, Choose, PCBeepTab, %PCBeepTab%
   Gui, Tab, %PageCount%
   Gui, Add, Text, x+5 y+5 w60 h20 section, Frequency:
   Gui, Add, Text, xp+75 ys w60 h20, Duration:
   Gui, Add, Text, xp+75 ys w60 h20, Tempo:
   loop, %RowsPerPage%
      {
      TunerRowCount := (PageCount-1) * RowsPerPage + A_Index
      Gui, Add, Edit, xs yp+25 w60 h20 vBeepFreq%TunerRowCount%,
      Gui, Add, Edit, xp+75 yp w60 h20 vBeepDur%TunerRowCount%,
      Gui, Add, Edit, xp+75 yp w60 h20 vBeepTempo%TunerRowCount%,
      }
   Return
   
   Tuner_EasyNoteTranslate:
   if (BeepFreq="-2c")
      BeepFreq=64
   else if (BeepFreq="-2d")
      BeepFreq=72
   else if (BeepFreq="-2e")
      BeepFreq=81
   else if (BeepFreq="-2f")
      BeepFreq=86
   else if (BeepFreq="-2g")
      BeepFreq=97
   else if (BeepFreq="-2a")
      BeepFreq=109
   else if (BeepFreq="-2b")
      BeepFreq=123
   else if (BeepFreq="-c")
      BeepFreq=128
   else if (BeepFreq="-d")
      BeepFreq=144
   else if (BeepFreq="-e")
      BeepFreq=162
   else if (BeepFreq="-f")
      BeepFreq=172
   else if (BeepFreq="-g")
      BeepFreq=193
   else if (BeepFreq="-a")
      BeepFreq=217
   else if (BeepFreq="-b")
      BeepFreq=245
   else if (BeepFreq="c")
      BeepFreq=256
   else if (BeepFreq="d")
      BeepFreq=288
   else if (BeepFreq="e")
      BeepFreq=324
   else if (BeepFreq="f")
      BeepFreq=344
   else if (BeepFreq="g")
      BeepFreq=387
   else if (BeepFreq="a")
      BeepFreq=436
   else if (BeepFreq="b")
      BeepFreq=490
   else if (BeepFreq="2c")
      BeepFreq=512
   else if (BeepFreq="2d")
      BeepFreq=576
   else if (BeepFreq="2e")
      BeepFreq=648
   else if (BeepFreq="2f")
      BeepFreq=689
   else if (BeepFreq="2g")
      BeepFreq=775
   else if (BeepFreq="2a")
      BeepFreq=871
   else if (BeepFreq="2b")
      BeepFreq=980
   else if (BeepFreq="3c")
      BeepFreq=1024
   else if (BeepFreq="-Db")
      BeepFreq=136
   else if (BeepFreq="-Eb")
      BeepFreq=153
   else if (BeepFreq="-Gb")
      BeepFreq=183
   else if (BeepFreq="-Ab")
      BeepFreq=208
   else if (BeepFreq="-Bb")
      BeepFreq=231
   else if (BeepFreq="Db")
      BeepFreq=272
   else if (BeepFreq="Eb")
      BeepFreq=306
   else if (BeepFreq="Gb")
      BeepFreq=366
   else if (BeepFreq="Ab")
      BeepFreq=411
   else if (BeepFreq="Bb")
      BeepFreq=463
   else if (BeepFreq="2Db")
      BeepFreq=544
   else if (BeepFreq="2Eb")
      BeepFreq=612
   else if (BeepFreq="2Gb")
      BeepFreq=732
   else if (BeepFreq="2Ab")
      BeepFreq=823
   else if (BeepFreq="2Bb")
      BeepFreq=926
   Return
   }
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Mar 14, 2010 11:23 am    Post subject: Reply with quote

doesn't work for me either. i'm on vista fwiw.

but looking at the gui, how about using sliders instead of edits?

vertical sliders side by side, would be almost graphical representation of the 'tune'
Smile
Back to top
mrmike



Joined: 20 Jan 2007
Posts: 9
Location: Wisconsin, USA

PostPosted: Mon Mar 15, 2010 3:51 am    Post subject: Reply with quote

Working fine for me. Using Vista Home Premium SP2.
Back to top
View user's profile Send private message
Tyrsius



Joined: 09 Jul 2009
Posts: 140

PostPosted: Mon Mar 15, 2010 7:35 pm    Post subject: Reply with quote

This will not work on Windows 7, I have tested it. Regardless of tone or duration, the pc beep function in Windows 7 seems to be intercepted by the OS and it plays its default error tone instead.

I have not tested on Vista, but I would assume that it behaves similarly.

Compatability has only been tested on Windows XP.
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Mar 17, 2010 12:29 am    Post subject: Reply with quote

haha. this is going to be fun to waste some time with at work.
Back to top
promithius
Guest





PostPosted: Wed Aug 17, 2011 9:13 pm    Post subject: Reply with quote

i have win7 and it works just fine for me, i am enjoying the classic Zelda theme right now
Back to top
sumon



Joined: 18 May 2010
Posts: 1016
Location: Sweden

PostPosted: Thu Aug 18, 2011 12:08 am    Post subject: Reply with quote

promithius wrote:
i have win7 and it works just fine for me, i am enjoying the classic Zelda theme right now


Same here. Damn, classy script! A bit not-so-user-friendly, I imagine this could become quite the cool thing if it came with a pack of songs etc. Smile BeepSong revolution!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group