Esempio n. 1
0
    def __init__(self, x_pos=0, y_pos=0):
        super().__init__(self.MEM_T, self.MEM_K, self.MEM_THRESHOLD)

        with open(os.path.join(this_dir, "CircleOfFifths.svg")) as f:
            svg = f.read()
        self.model_root, self.model_elements = parse(svg)
        #sys.stdout.write(serialize(self.model_root))
        #sys.stdout.write("elements = %s\n" % (self.model_elements,))
        #json.dump(self.model_root, sys.stdout, cls=JSONDebugEncoder, indent=2, sort_keys=True)
        #json.dump(self.model_elements, sys.stdout, cls=JSONDebugEncoder, indent=2, sort_keys=True)
        #sys.stdout.write("\n") # Python JSON dump misses last newline
        (x_min, y_min), (x_max, y_max) = self.model_root.aabbox()
        self.width = x_max - x_min
        self.height = y_max - y_min
        self.model_root = sg.Use(
            self.model_root,
            transform=[sg.Translate(margin - x_min + x_pos, margin - y_min + y_pos)]
        )

        self.orig_fill_color = {}
        for note in self.NOTES:
            label = 'inner_' + note
            self.orig_fill_color[label] = self.model_elements[label].fill
            label = 'outer_' + note
            self.orig_fill_color[label] = self.model_elements[label].fill
Esempio n. 2
0
def load(index):
	global scene, image
	filename = filenames[index]
	t = "[%3i+1/%i] %s" % (index, len(filenames), filename)
	glutSetWindowTitle(t.encode())
	print(t)
	try:
		if filename.endswith('z'):
			import gzip
			f = gzip.open(filename)
		else:
			f = open(filename)
		svg, elems = parse(f.read(), logging.WARNING)
	except:
		traceback.print_exception(*sys.exc_info())
		svg = sg.Group()
	image = sg.Image("../png/%s.png" % filename.rsplit(".", 1)[0], x=480)
	scene = sg.Group(
		children=[svg, image],
	)
	
	(x_min, y_min), (x_max, y_max) = scene.aabbox()
	glutReshapeWindow(int(x_max), int(y_max))
	glutPostRedisplay()
	return index
Esempio n. 3
0
    def __init__(self, x_pos=0, y_pos=0):
        with open(os.path.join(this_dir, "HexLayout.svg")) as f:
            svg = f.read()
        self.model_root, self.model_elements = parse(svg)
        (x_min, y_min), (x_max, y_max) = self.model_root.aabbox()
        self.width = x_max - x_min
        self.height = y_max - y_min
        self.model_root = sg.Use(
            self.model_root,
            transform=[sg.Translate(margin - x_min + x_pos, margin - y_min + y_pos)]
        )

        self.press_counter = [0] * 12
        self.accum_time = [0.] * 12
        self.last_timestamp = time.time_ns() / (10 ** 9) # Converted to floating-point seconds

        #self.note_map  = ['cC',  'cG',  'dD',  'dA',  'dE',  'dB', 'aGb', 'bDb', 'bAb', 'bEb', 'bBb', 'cF' ]
        #self.note_map  = ['cGb', 'cDb', 'dAb', 'dEb', 'dBb', 'dF', 'aC',  'bG',  'bD',  'bA',  'bE',  'cB' ]

        #self.note_map   = ['cEb', 'cBb', 'cF',  'dC',  'dG',  'dD', 'dA',  'bE_',  'bB',  'bGb', 'cDb_', 'cAb_']
        #self.note_map   = ['cEb', 'cBb', 'dF_',  'dC',  'dG',  'dD', 'aA',  'bE_',  'bB',  'bGb', 'bDb', 'cAb_']

        #self.note_map  = ['cGb', 'cDb', ['cAb', 'dAb'], 'dEb', ['aBb', 'dBb'], ['aF', 'dF', 'eF'] , ['aC', 'eC'],
        #                 ['aG', 'bG', 'eG'], ['bD', 'eD'],  'bA', ['bE', 'cE'], ['bB_', 'cB'] ]

        #self.note_map  = ['cC',  'cG',  'dD',  'dA',  'dE',  'dB',  'aGb', 'bDb', 'bAb', 'bEb', 'bBb', 'cF' ]
        #self.note_map  = ['cG',  'cD',  'dA',  'dE',  'dB',  'dGb', 'aDb', 'bAb', 'bEb', 'bBb', 'bF',  'cC' ]

        self.note_map  = [\
            [row + 'G'  for row in ['a', 'b', 'c', 'd', 'e']],
            [row + 'D'  for row in ['a', 'b', 'c', 'd', 'e']],
            [row + 'A'  for row in ['a', 'b', 'c', 'd', 'e']],
            [row + 'E'  for row in ['a', 'b', 'c', 'd', 'e']],
            [row + 'B'  for row in ['a', 'b', 'c', 'd', 'e']],
            [row + 'Gb' for row in ['a', 'b', 'c', 'd', 'e']],
            [row + 'Db' for row in ['a', 'b', 'c', 'd', 'e']],
            [row + 'Ab' for row in ['a', 'b', 'c', 'd', 'e']],
            [row + 'Eb' for row in ['a', 'b', 'c', 'd', 'e']],
            [row + 'Bb' for row in ['a', 'b', 'c', 'd', 'e']],
            [row + 'F'  for row in ['a', 'b', 'c', 'd', 'e']],
            [row + 'C'  for row in ['a', 'b', 'c', 'd', 'e']],
        ]
        for note_ids in self.note_map:
            if not isinstance(note_ids, (list, tuple)):
                note_ids = [note_ids]
            new_note_ids = [] 
            for note_id in note_ids:
                new_note_id = note_id + '_'
                if new_note_id in self.model_elements:
                    new_note_ids.append(new_note_id)
            note_ids += new_note_ids

        for note_ids in self.note_map:
            if not isinstance(note_ids, (list, tuple)):
                note_ids = [note_ids]
            for note_id in note_ids:
                self.model_elements[note_id].fill = self.IDLE_COLOR
                self.model_elements[note_id].stroke = self.IDLE_STROKE
                self.model_elements[note_id].stroke_width = 1
Esempio n. 4
0
 def __init__(self):
     with open(os.path.join(this_dir, "PianoKeyboard.svg")) as f:
         svg = f.read()
     self.model_root, self.model_elements = parse(svg)
     #sys.stdout.write(serialize(self.model_root))
     #sys.stdout.write("elements = %s\n" % (self.model_elements,))
     #json.dump(self.model_root, sys.stdout, cls=JSONDebugEncoder, indent=2, sort_keys=True)
     #json.dump(self.model_elements, sys.stdout, cls=JSONDebugEncoder, indent=2, sort_keys=True)
     #sys.stdout.write("\n") # Python JSON dump misses last newline
     self.orig_fill_color = {}
     for note in self.NOTES:
         self.orig_fill_color[note] = self.model_elements[note].fill
Esempio n. 5
0
    def __init__(self, x_pos=0, y_pos=0):
        super().__init__(self.MEM_T, self.MEM_K, self.MEM_THRESHOLD)

        for chord_info in self.CHORDS_INFO:
            if not chord_info[0]:
                chord_info[0] = [0] * 12
                for i in range(0, 12):
                    chord_mask = 0
                    for num_note in chord_info[1]:
                        chord_mask |= 1 << (i + num_note) % 12
                    chord_info[0][i] = chord_mask
            if chord_info[2] is None:
                chord_info[2] = self.COLOR_GRAY
        #json.dump(self.CHORDS_INFO, sys.stdout, cls=JSONDebugEncoder, indent=2, sort_keys=True)

        with open(os.path.join(this_dir, "ChordMatrix.svg")) as f:
            svg = f.read()
        self.model_root, self.model_elements = parse(svg)
        #sys.stdout.write(serialize(self.model_root))
        #sys.stdout.write("elements = %s\n" % (self.model_elements,))
        #json.dump(self.model_root, sys.stdout, cls=JSONDebugEncoder, indent=2, sort_keys=True)
        #json.dump(self.model_elements, sys.stdout, cls=JSONDebugEncoder, indent=2, sort_keys=True)
        #sys.stdout.write("\n") # Python JSON dump misses last newline
        (x_min, y_min), (x_max, y_max) = self.model_root.aabbox()
        self.width = x_max - x_min
        self.height = y_max - y_min
        self.model_root = sg.Use(
            self.model_root,
            transform=[sg.Translate(margin - x_min + x_pos, margin - y_min + y_pos)]
        )

        self.orig_fill_color = {}
        for note_id in self.CHROMATIC_NOTES:
            key_label = '{}'.format(note_id)
            self.orig_fill_color[key_label] = self.model_elements[key_label].fill
        for row in range(1,12):
            row_label = 'row{:02d}'.format(row)
            self.model_elements[row_label].active = False
            for note_id in self.CHROMATIC_NOTES:
                label = '{}{:02d}'.format(note_id, row)
                self.model_elements[label].active = False
Esempio n. 6
0
    def __init__(self, x_pos=0, y_pos=0):
        super().__init__(self.MEM_T, self.MEM_K, self.MEM_THRESHOLD)

        with open(os.path.join(this_dir, "CircleOfTriads.svg")) as f:
            svg = f.read()
        self.model_root, self.model_elements = parse(svg)
        (x_min, y_min), (x_max, y_max) = self.model_root.aabbox()
        self.width = x_max - x_min
        self.height = y_max - y_min
        self.model_root = sg.Use(
            self.model_root,
            transform=[sg.Translate(margin - x_min + x_pos, margin - y_min + y_pos)]
        )

        for note in self.NOTES:
            self.model_elements[note].stroke = self.COLOR_GRAY
            self.model_elements[note].stroke_width = 1
            self.model_elements[note].active = False
            for circle in self.CIRCLES:
                element_id = '{}{}'.format(circle, note)
                self.model_elements[element_id].fill = self.COLOR_WHITE
                self.model_elements[element_id].stroke = self.COLOR_GRAY
                self.model_elements[element_id].active = False
Esempio n. 7
0
from seagull.xml import parse, serialize
from seagull.opengl.utils import gl_prepare, gl_reshape, gl_display

fast = True
margin = 20

if fast:
    import OpenGL
    OpenGL.ERROR_CHECKING = False
    OpenGL.ERROR_LOGGING = False
    OpenGL.ERROR_ON_COPY = True
    OpenGL.STORE_POINTERS = False

with open(os.path.join(this_dir, "rgb_lights.svg")) as f:
    svg = f.read()
    svg, elements = parse(svg)
    #sys.stdout.write(serialize(svg))
    #sys.stdout.write("elements = %s\n" % (elements,))

(x_min, y_min), (x_max, y_max) = svg.aabbox()
window_size = int(x_max - x_min + 2 * margin), int(y_max - y_min + 2 * margin)

scene = sg.Use(svg, transform=[sg.Translate(margin - x_min, margin - y_min)])
feedback = sg.Group(fill=None, stroke=sg.Color.red)

elements['red'].active = False
elements['green'].active = True
elements['blue'].active = False


def profiling(f):
Esempio n. 8
0
# scene ######################################################################

if fast:
	import OpenGL
	OpenGL.ERROR_CHECKING = False
	OpenGL.ERROR_LOGGING = False
	OpenGL.ERROR_ON_COPY = True
	OpenGL.STORE_POINTERS = False

from seagull import scenegraph as sg
from seagull.scenegraph.transform import product, normalized
from seagull.xml import parse, serialize
from seagull.opengl.utils import gl_prepare, gl_reshape, gl_display

svg, elems = parse(svg)

(x_min, y_min), (x_max, y_max) = svg.aabbox()
window_size = int(x_max-x_min+2*margin), int(y_max-y_min+2*margin)

scene = sg.Use(svg, transform=[sg.Translate(margin-x_min, margin-y_min)])
feedback = sg.Group(fill=None, stroke=sg.Color.red)


# display ####################################################################

def profiling(f):
	"""a profiling decorator"""
	import cProfile, pstats, atexit
	pr = cProfile.Profile()