Advertisement
Redxone

[Python][ConsolePlayer] - Plays music notes in beeps!

Oct 27th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.53 KB | None | 0 0
  1. # Created By Lewisk3 / Redxone
  2. import winsound
  3. import time
  4.  
  5. music = []
  6. notes = {
  7.     'C':  { '1':131, '2':262, '3':523, '4':1046, '5':2096 },
  8.     'C#': { '1':139, '2':277, '3':554, '4':1108, '5':2217 },
  9.     'D':  { '1':147, '2':294, '3':587, '4':1175, '5':2349 },
  10.     'D#': { '1':156, '2':311, '3':622, '4':1244, '5':2489 },
  11.     'E':  { '1':165, '2':330, '3':659, '4':1318, '5':2637 },
  12.     'F':  { '1':175, '2':349, '3':698, '4':1397, '5':2794 },
  13.     'F#': { '1':185, '2':370, '3':740, '4':1480, '5':2960 },
  14.     'G':  { '1':196, '2':392, '3':784, '4':1568, '5':3136 },
  15.     'G#': { '1':208, '2':415, '3':831, '4':1664, '5':3322 },
  16.     'A':  { '1':220, '2':440, '3':880, '4':1760, '5':3520 },
  17.     'A#': { '1':233, '2':466, '3':932, '4':1866, '5':3729 },
  18.     'B':  { '1':248, '2':494, '3':988, '4':1973, '5':951 },
  19. }
  20.  
  21. def loadInto(table):
  22.     for note in table:
  23.         music.append( note )
  24.  
  25. def interpret(file):
  26.     online = 1
  27.     f_Song = []
  28.     #######################################################
  29.     try:
  30.         rFile = open(file, 'r')
  31.     except:
  32.        print('[NOSTALGIAFY] - File not found [' + file + ']')
  33.        time.sleep(1)
  34.        exit()
  35.     ################### - Done Open Trying - ###################
  36.     for line in rFile.readlines():
  37.         fInfo = str(line).split()
  38.         comp = len(fInfo)
  39.         if(str(fInfo[0]) in notes):
  40.            if comp == 2:
  41.                k, v = str(fInfo[0]), str(fInfo[1])
  42.                f_Song.append( ( notes[k][v], 250, 0.0 ) )
  43.            elif comp == 3:
  44.                k, v, l = str(fInfo[0]), str(fInfo[1]), int(fInfo[2])
  45.                f_Song.append( ( notes[k][v], l, 0.0 ) )
  46.            elif comp == 4:
  47.                k, v, l, t = str(fInfo[0]), str(fInfo[1]), int(fInfo[2]), float(fInfo[3])
  48.                f_Song.append( ( notes[k][v], l, t ) )
  49.         else:
  50.             print('[NOSTALGIAFY] - Invalid note on line [' + str(online) + ']')
  51.             time.sleep(1)
  52.             exit()
  53.         online += 1
  54.     #######################################################
  55.     # - DONE LOADING - # Put File Into Music Below \-/
  56.     ####################
  57.     loadInto(f_Song)
  58.     play()
  59.  
  60. def play():
  61.     for sound in music:
  62.         print ("[NOSTALGIAFY] - Frec[" + str(float(sound[0])) + "] Duration[" + str(float(sound[1])) + "]")
  63.         time.sleep(0.01)
  64.         winsound.Beep(sound[0], sound[1])
  65.         print ("[NOSTALGIAFY] - Waiting " + str(float(sound[2])) + "s")
  66.         time.sleep(sound[2])
  67.  
  68. music_file = input("Input Music File Location: ")
  69. interpret(music_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement