Advertisement
Guest User

ijo_suna

a guest
Jul 21st, 2009
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. # Guitar Shift 0.1
  2. # This program displays the same note on all the strings of the guitar.
  3.  
  4. from sys import argv
  5.  
  6. usage = """
  7. Usage: python guitar_shift.py [string] [fret]
  8. Example: python guitar_shift.py 1 3 -- first string, third fret
  9. """
  10.  
  11. # Standard tuning: E B G D A E
  12. tuning = {
  13.     1: 5,
  14.     2: 12,
  15.     3: 8,
  16.     4: 3,
  17.     5: 10,
  18.     6: 5,
  19. }
  20. # Number of frets on the guitar
  21. frets = 24
  22.  
  23. try:
  24.     given_string = int(argv[1])
  25.     given_fret = int(argv[2])
  26. except (TypeError, ValueError, IndexError):
  27.     exit(usage)
  28. if not tuning.has_key(given_string):
  29.     exit('Error: unknown string.')
  30. if not (0 <= given_fret <= frets):
  31.     exit('Error: no such fret.')
  32.  
  33. given_note = tuning[given_string] + given_fret
  34. while given_note >= 12:
  35.     given_note -= 12
  36.  
  37. for string in tuning:
  38.     # first position on the string -- could be negative, not used if so
  39.     fret = given_note - tuning[string]
  40.     if fret >= 0:
  41.         string_frets = [(given_note - tuning[string])]
  42.     else:
  43.         string_frets = []
  44.     while fret <= (frets - 12):
  45.     fret += 12
  46.         string_frets += [fret]
  47.     print "%i:" % (string), string_frets
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement