the_free_software_song.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python3
  2. #
  3. # This script is used to generate the music for
  4. # examples/raspberrypi-pixtend-musicplayer.awlpro
  5. #
  6. notes = []
  7. def note(name, value):
  8. nameMap = {
  9. "pause" : 0,
  10. "c" : 1,
  11. "d" : 2,
  12. "e" : 3,
  13. "f" : 4,
  14. "g" : 5,
  15. "a" : 6,
  16. "b" : 7,
  17. "c'" : 8,
  18. "d'" : 9,
  19. "e'" : 10,
  20. "f'" : 11,
  21. "g'" : 12,
  22. "a'" : 13,
  23. "b'" : 14,
  24. None : 15,
  25. }
  26. valueMap = {
  27. "1/1" : 0,
  28. "1/2" : 1,
  29. "1/4" : 2,
  30. "1/8" : 3,
  31. "1/16" : 4,
  32. "1/32" : 5,
  33. "1/64" : 6,
  34. "sharp" : 0,
  35. "dot" : 1,
  36. "tie" : 2,
  37. "up" : 3,
  38. "down" : 4,
  39. }
  40. notes.append(nameMap[name] | (valueMap[value] << 4))
  41. n = note
  42. tie = lambda: note(None, "tie")
  43. dot = lambda: note(None, "dot")
  44. # The Free Software Song
  45. # Sadi moma bela loza (Bulgarian folk song)
  46. # Words by Richard Stallman, the Free Software Foundation http://fsf.org/
  47. # Richard Stallman and the Free Software Foundation claim no copyright on this song.
  48. # The official homepage for this song is http://www.gnu.org/music/free-software-song.html
  49. n("d'", "1/4"); n("c'", "1/8"); n("b", "1/4"); n("a", "1/4")
  50. n("b", "1/4"); n("c'", "1/8"); n("b", "1/8"); tie(); n("a", "1/8"); n("g", "1/4")
  51. n("g", "1/4"); dot(); n("a", "1/4"); dot(); tie(); n("b", "1/8")
  52. n("c'", "1/4"); dot(); n("b", "1/4"); n("b", "1/8"); n("d'", "1/4")
  53. n("a", "1/4"); dot(); n("a", "1/2")
  54. n("d'", "1/4"); tie(); n("c'", "1/8"); tie(); n("b", "1/2")
  55. n("d'", "1/4"); n("c'", "1/8"); n("b", "1/4"); n("a", "1/4")
  56. n("b", "1/4"); n("c'", "1/8"); n("b", "1/8"); tie(); n("a", "1/8"); n("g", "1/4")
  57. n("g", "1/4"); dot(); n("a", "1/4"); dot(); tie(); n("b", "1/8")
  58. n("c'", "1/4"); dot(); n("b", "1/4"); n("b", "1/8"); n("d'", "1/4")
  59. n("a", "1/4"); dot(); n("a", "1/2")
  60. n("a", "1/4"); dot(); tie(); n("a", "1/2")
  61. header="""DATA_BLOCK "DB_song"
  62. STRUCT
  63. SONG : ARRAY [0 .. %d] OF BYTE;
  64. END_STRUCT;
  65. BEGIN
  66. """ % (len(notes))
  67. footer="END_DATA_BLOCK\n"
  68. print(header, end='')
  69. for i, n in enumerate(notes):
  70. print("\tSONG[%d] := B#16#%02X;\n" % (i, n), end='')
  71. print("\tSONG[%d] := B#16#FF;\n" % (i + 1), end='')
  72. print(footer, end='')