Guest User

Untitled

a guest
Jun 26th, 2022
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.92 KB | None | 0 0
  1. import linecache
  2. import math
  3. import os
  4. import time as _time
  5. import tracemalloc
  6.  
  7. from neoscore.core import neoscore
  8. from neoscore.core.flowable import Flowable
  9. from neoscore.core.units import ZERO, Mm
  10. from neoscore.western.clef import Clef
  11. from neoscore.western.duration import Duration
  12. from neoscore.western.key_signature import KeySignature
  13. from neoscore.western.notehead import Notehead
  14. from neoscore.western.staff import Staff
  15.  
  16.  
  17. def display_top(snapshot, key_type="traceback", limit=10):
  18.     snapshot = snapshot.filter_traces(
  19.         (tracemalloc.Filter(False, "<frozen importlib._bootstrap>"),)
  20.     )
  21.     top_stats = snapshot.statistics(key_type)
  22.  
  23.     print("Top %s lines" % limit)
  24.     for index, stat in enumerate(top_stats[:limit], 1):
  25.         frame = stat.traceback[0]
  26.         print(
  27.             "#%s: %s:%s: %.1f KiB"
  28.             % (index, frame.filename, frame.lineno, stat.size / 1024)
  29.         )
  30.         for line in stat.traceback:
  31.             print(line)
  32.             line_content = (
  33.                 "    %s" % linecache.getline(line.filename, line.lineno).strip()
  34.             )
  35.             if line_content.strip():
  36.                 print(line_content)
  37.         print()
  38.         print("----------------------------------")
  39.         print()
  40.  
  41.     other = top_stats[limit:]
  42.     if other:
  43.         size = sum(stat.size for stat in other)
  44.         print("%s other: %.1f KiB" % (len(other), size / 1024))
  45.     total = sum(stat.size for stat in top_stats)
  46.     print("Total allocated size: %.1f KiB" % (total / 1024))
  47.  
  48.  
  49. tracemalloc.start(15)
  50.  
  51. #################
  52.  
  53.  
  54. neoscore.setup()
  55.  
  56. flowable = Flowable((Mm(0), Mm(0)), None, Mm(500), Mm(30), Mm(10))
  57.  
  58. staff = Staff((Mm(0), Mm(0)), flowable, Mm(500))
  59. unit = staff.unit
  60. clef = Clef(ZERO, staff, "treble")
  61. KeySignature(ZERO, staff, "g_major")
  62.  
  63. center = unit(15)
  64.  
  65. n1 = Notehead(center, staff, "g", Duration(1, 4))
  66. n2 = Notehead(center, staff, "b", Duration(1, 4))
  67. n3 = Notehead(center, staff, "d'", Duration(1, 4))
  68. n4 = Notehead(center, staff, "f'", Duration(1, 4))
  69.  
  70. start_time = _time.time()
  71.  
  72.  
  73. def refresh_func(time):
  74.     #################################################################
  75.     #################################################################
  76.     # Dump profile after 10 seconds, adjust as needed
  77.     #################################################################
  78.     #################################################################
  79.     if time - start_time > 10:
  80.         print("==================================")
  81.         snapshot = tracemalloc.take_snapshot()
  82.         display_top(snapshot)
  83.         print("==================================")
  84.         quit()
  85.  
  86.     n1.x = center + Mm(math.sin((time / 2)) * 10)
  87.     n2.x = center + Mm(math.sin((time / 2) + 1) * 12)
  88.     n3.x = center + Mm(math.sin((time / 2) + 1.7) * 7)
  89.     n4.x = center + Mm(math.sin((time / 2) + 2.3) * 15)
  90.  
  91.  
  92. if __name__ == "__main__":
  93.     neoscore.show(refresh_func)
  94.  
Advertisement
Add Comment
Please, Sign In to add comment