banovski

Tune generator (improved)

Apr 14th, 2020 (edited)
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import random
  4. # import pyperclip
  5.  
  6. #         0    1    2    3    4    5    6    7    8    9    10   11
  7. notes = ["G", "A", "H", "C", "D", "e", "f", "g", "a", "h", "c", "d"]
  8. virtual_piano = ["5", "6", "7", "8", "9", "0", "q", "w", "e", "r", "t", "y"]
  9.  
  10. chords = [[[1, 3, 5, 8, 10], [0, 0]],
  11.           [[2, 4, 6, 9, 11], [4, 6]],
  12.           [[0, 3, 5, 7, 10], [5, 5]],
  13.           [[4, 1, 11, 6, 8], [4, 6]],
  14.           [[0, 2, 5, 7, 9], [0, 0]],
  15.           [[1, 3, 6, 8, 10], [1, 3]],
  16.           [[0, 2, 4, 7, 9, 11], [0, 0]]]
  17.  
  18. def generate_note(current_note_index):
  19.     note_index_delta = 0
  20.     halt_flag = random.randint(0, 1)
  21.     while halt_flag != 1:
  22.         note_index_delta += 1
  23.         halt_flag = random.randint(0, 1)
  24.  
  25.     sign_number = random.randint(0, 1)
  26.     if sign_number == 0:
  27.         test_note_index = current_note_index + note_index_delta
  28.     else:
  29.         test_note_index = current_note_index - note_index_delta
  30.     return(test_note_index)
  31.  
  32. def pick_chord():
  33.     global first_launch_flag
  34.     global chord_index
  35.     if first_launch_flag == 1:
  36.         first_launch_flag = 0
  37.     else:
  38.         chord_index = random.choice(chords[chord_index][1])
  39.     return(chords[chord_index][0])
  40.  
  41. break_flag=""
  42. while break_flag != "q":
  43.  
  44.     first_launch_flag = 1
  45.     chord_index = random.randint(0, 6)
  46.     current_note_index = random.randint(0, 11)
  47.     to_clipboard = ""
  48.  
  49.     phrase = input("Enter the structure: ")
  50.     words = phrase.split(" ")
  51.  
  52.     for word in words:
  53.         syllables = list(word)
  54.         for syllable in syllables:
  55.             if syllables == "+":
  56.                 chord_notes = pick_chord()
  57.                 test_note_index = generate_note(current_note_index)
  58.                 while test_note_index < 0 or test_note_index > 11 or test_note_index not in chord_notes:
  59.                     test_note_index = generate_note(current_note_index)
  60.                 print(notes[test_note_index], end = "\t")
  61.                 to_clipboard += notes[test_note_index] + "\t"
  62.             else:
  63.                 test_note_index = generate_note(current_note_index)
  64.                 while test_note_index < 0 or test_note_index > 11:
  65.                     test_note_index = generate_note(current_note_index)
  66.                 print(notes[test_note_index], end = "\t")
  67.                 to_clipboard += notes[test_note_index] + "\t"
  68.  
  69.     # pyperclip.copy(to_clipboard)
  70.     print("")
  71.     break_flag = input("?:")
Add Comment
Please, Sign In to add comment