Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import linecache
- import math
- import os
- import time as _time
- import tracemalloc
- from neoscore.core import neoscore
- from neoscore.core.flowable import Flowable
- from neoscore.core.units import ZERO, Mm
- from neoscore.western.clef import Clef
- from neoscore.western.duration import Duration
- from neoscore.western.key_signature import KeySignature
- from neoscore.western.notehead import Notehead
- from neoscore.western.staff import Staff
- def display_top(snapshot, key_type="traceback", limit=10):
- snapshot = snapshot.filter_traces(
- (tracemalloc.Filter(False, "<frozen importlib._bootstrap>"),)
- )
- top_stats = snapshot.statistics(key_type)
- print("Top %s lines" % limit)
- for index, stat in enumerate(top_stats[:limit], 1):
- frame = stat.traceback[0]
- print(
- "#%s: %s:%s: %.1f KiB"
- % (index, frame.filename, frame.lineno, stat.size / 1024)
- )
- for line in stat.traceback:
- print(line)
- line_content = (
- " %s" % linecache.getline(line.filename, line.lineno).strip()
- )
- if line_content.strip():
- print(line_content)
- print()
- print("----------------------------------")
- print()
- other = top_stats[limit:]
- if other:
- size = sum(stat.size for stat in other)
- print("%s other: %.1f KiB" % (len(other), size / 1024))
- total = sum(stat.size for stat in top_stats)
- print("Total allocated size: %.1f KiB" % (total / 1024))
- tracemalloc.start(15)
- #################
- neoscore.setup()
- flowable = Flowable((Mm(0), Mm(0)), None, Mm(500), Mm(30), Mm(10))
- staff = Staff((Mm(0), Mm(0)), flowable, Mm(500))
- unit = staff.unit
- clef = Clef(ZERO, staff, "treble")
- KeySignature(ZERO, staff, "g_major")
- center = unit(15)
- n1 = Notehead(center, staff, "g", Duration(1, 4))
- n2 = Notehead(center, staff, "b", Duration(1, 4))
- n3 = Notehead(center, staff, "d'", Duration(1, 4))
- n4 = Notehead(center, staff, "f'", Duration(1, 4))
- start_time = _time.time()
- def refresh_func(time):
- #################################################################
- #################################################################
- # Dump profile after 10 seconds, adjust as needed
- #################################################################
- #################################################################
- if time - start_time > 10:
- print("==================================")
- snapshot = tracemalloc.take_snapshot()
- display_top(snapshot)
- print("==================================")
- quit()
- n1.x = center + Mm(math.sin((time / 2)) * 10)
- n2.x = center + Mm(math.sin((time / 2) + 1) * 12)
- n3.x = center + Mm(math.sin((time / 2) + 1.7) * 7)
- n4.x = center + Mm(math.sin((time / 2) + 2.3) * 15)
- if __name__ == "__main__":
- neoscore.show(refresh_func)
Advertisement
Add Comment
Please, Sign In to add comment