示例#1
0
    def get(self):
        uri = self.get_argument('uri')

        try:
            data = get_plugin_info(uri)
        except:
            print("ERROR: get_plugin_info for '%s' failed" % uri)
            raise HTTPError(404)

        self.write(data)
示例#2
0
def take_screenshot(bundle_path, html_dir, cache_dir, size):
    os.makedirs(cache_dir, exist_ok=True)
    lv2_init()
    pb = get_pedalboard_info(bundle_path)

    if size:
        w, h = size.split('x')
        width, height = int(w), int(h)
    else:
        width, height = pb['width'], pb['height']
    if (width, height) == (0, 0):
        width, height = 3840, 2160

    img_dir = os.path.join(html_dir, 'img')

    # preload images
    audio_input_img = Image.open(os.path.join(img_dir, 'audio-input.png'))
    audio_output_img = Image.open(os.path.join(img_dir, 'audio-output.png'))
    audio_input_connected = Image.open(
        os.path.join(img_dir, 'audio-input-connected.png'))
    audio_output_connected = Image.open(
        os.path.join(img_dir, 'audio-output-connected.png'))
    midi_input_img = Image.open(os.path.join(img_dir, 'midi-input.png'))
    midi_output_img = Image.open(os.path.join(img_dir, 'midi-output.png'))
    midi_input_connected = Image.open(
        os.path.join(img_dir, 'midi-input-connected.png'))
    midi_output_connected = Image.open(
        os.path.join(img_dir, 'midi-output-connected.png'))
    cv_input_img = Image.open(os.path.join(img_dir, 'cv-input.png'))
    cv_output_img = Image.open(os.path.join(img_dir, 'cv-output.png'))
    cv_input_connected = Image.open(
        os.path.join(img_dir, 'cv-input-connected.png'))
    cv_output_connected = Image.open(
        os.path.join(img_dir, 'cv-output-connected.png'))
    default_screenshot = Image.open(
        os.path.join(html_dir, 'resources', 'pedals', 'default.png'))

    right_padding = audio_input_connected.size[0] * 2
    bottom_padding = right_padding

    # create capture/playback connectors
    device_capture = []
    for ix in range(0, pb['hardware']['audio_ins']):
        device_capture.append({
            'symbol': 'capture_{0}'.format(ix + 1),
            'img': audio_output_img,
            'connected_img': audio_output_connected,
            'type': 'audio',
        })
    if not pb.get('midi_separated_mode', False):
        device_capture.append({
            'symbol': 'midi_merger_out',
            'img': midi_output_img,
            'connected_img': midi_output_connected,
            'type': 'midi',
        })
    elif pb['hardware'].get('serial_midi_in', False):
        device_capture.append({
            'symbol': 'serial_midi_in',
            'img': midi_output_img,
            'connected_img': midi_output_connected,
            'type': 'midi',
        })
    for midi_in in pb['hardware']['midi_ins']:
        device_capture.append({
            'symbol': midi_in['symbol'],
            'img': midi_output_img,
            'connected_img': midi_output_connected,
            'type': 'midi',
        })
    for ix in range(0, pb['hardware']['cv_ins']):
        device_capture.append({
            'symbol': 'cv_capture_{0}'.format(ix + 1),
            'img': cv_output_img,
            'connected_img': cv_output_connected,
            'type': 'cv',
        })

    device_playback = []
    for ix in range(0, pb['hardware']['audio_outs']):
        device_playback.append({
            'symbol': 'playback_{0}'.format(ix + 1),
            'img': audio_input_img,
            'connected_img': audio_input_connected,
            'type': 'audio',
        })
    if not pb.get('midi_separated_mode', False):
        device_playback.append({
            'symbol': 'midi_broadcaster_in',
            'img': midi_input_img,
            'connected_img': midi_input_connected,
            'type': 'midi',
        })
    elif pb['hardware'].get('serial_midi_out', False):
        device_playback.append({
            'symbol': 'serial_midi_out',
            'img': midi_input_img,
            'connected_img': midi_input_connected,
            'type': 'midi',
        })
    for midi_out in pb['hardware']['midi_outs']:
        device_playback.append({
            'symbol': midi_out['symbol'],
            'img': midi_input_img,
            'connected_img': midi_input_connected,
            'type': 'midi',
        })
    for ix in range(0, pb['hardware']['cv_outs']):
        device_playback.append({
            'symbol': 'cv_playback_{0}'.format(ix + 1),
            'img': cv_input_img,
            'connected_img': cv_input_connected,
            'type': 'cv',
        })

    # create plugins
    plugins = pb['plugins']
    plugin_map = {}
    for p in plugins:
        # read plugin data
        data = get_plugin_info(p['uri'])
        p['data'] = data

        # read plugin image
        gui = get_plugin_gui(p['uri'])
        screenshot_path = gui.get('screenshot', None)
        pimg = Image.open(screenshot_path).convert(
            'RGBA') if screenshot_path else default_screenshot
        p['img'] = pimg

        if screenshot_path:
            # detect ports and save/read
            version = '{0}.{1}'.format(data['version'],
                                       data.get('release',
                                                0)).replace('.', '_')
            encoded_uri = base64.b64encode(p['uri'].encode()).decode()
            filename = os.path.join(
                cache_dir, '{0}_{1}_{2}'.format(__version__.replace('.', '_'),
                                                encoded_uri, version))
            if os.path.isfile(filename):
                with open(filename, 'r') as fh:
                    columns = json.loads(fh.read())
            else:
                columns = {
                    'in_ports':
                    tuple(
                        tuple(c)
                        for c in detect_first_column(pimg, pimg.size[0])),
                    'out_ports':
                    tuple(
                        tuple(c) for c in detect_first_column(
                            pimg, pimg.size[0], rtol=True)),
                }
                with open(filename, 'w') as fh:
                    fh.write(json.dumps(columns))
        else:  # tuna can, we have to guess the position of the connectors
            columns = {
                'in_ports': ((-9, 121), (-9, 146), (-9, 190), (-9, 215),
                             (-9, 259), (-9, -284), (-9, 328), (-9, 353)),
                'out_ports': ((259, 121), (259, 146), (259, 190), (259, 215),
                              (259, 259), (259, 284), (259, 328), (259, 353))
            }

        # detect connectors
        in_ports = data['ports']['audio']['input'] + data['ports']['midi'][
            'input'] + data['ports']['cv']['input']
        if len(in_ports) > 0:
            audio_in_ix = len(data['ports']['audio']['input'])
            cv_in_ix = len(data['ports']['cv']['input']) + audio_in_ix
            for ix, conn in enumerate(chunks(columns['in_ports'], 2)):
                if ix < len(in_ports):
                    in_ports[ix]['connector'] = conn
                    if ix < audio_in_ix:
                        in_ports[ix]['connected_img'] = audio_input_connected
                        in_ports[ix]['offset'] = (79, 15)
                        in_ports[ix]['type'] = 'audio'
                    elif ix < cv_in_ix:
                        in_ports[ix]['connected_img'] = cv_input_connected
                        in_ports[ix]['offset'] = (67, 15)
                        in_ports[ix]['type'] = 'cv'
                    else:
                        in_ports[ix]['connected_img'] = midi_input_connected
                        in_ports[ix]['offset'] = (67, 9)
                        in_ports[ix]['type'] = 'midi'
            if not all('connector' in p for p in in_ports):
                raise Exception(
                    'Connector detection for input ports of plugin {0} failed'.
                    format(p['uri']))
        out_ports = data['ports']['audio']['output'] + data['ports']['midi'][
            'output'] + data['ports']['cv']['output']
        if len(out_ports) > 0:
            audio_out_ix = len(data['ports']['audio']['output'])
            cv_out_ix = len(data['ports']['cv']['output']) + audio_out_ix
            for ix, conn in enumerate(chunks(columns['out_ports'], 2)):
                if ix < len(out_ports):
                    out_ports[ix]['connector'] = conn
                    if ix < audio_out_ix:
                        out_ports[ix]['connected_img'] = audio_output_connected
                        out_ports[ix]['offset'] = (8, 15)
                        out_ports[ix]['type'] = 'audio'
                    elif ix < cv_out_ix:
                        out_ports[ix]['connected_img'] = cv_output_connected
                        out_ports[ix]['offset'] = (11, 22)
                        out_ports[ix]['type'] = 'cv'
                    else:
                        out_ports[ix]['connected_img'] = midi_output_connected
                        out_ports[ix]['offset'] = (8, 9)
                        out_ports[ix]['type'] = 'midi'
            if not all('connector' in p for p in out_ports):
                raise Exception(
                    'Connector detection for output ports of plugin {0} failed'
                    .format(p['uri']))

        plugin_map[p['instance']] = p

    # calculate image size
    height = 0
    for p in plugins:
        if p['x'] + p['img'].size[0] + right_padding > width:
            width = p['x'] + p['img'].size[0] + right_padding
        if p['y'] + p['img'].size[1] + bottom_padding > height:
            height = p['y'] + p['img'].size[1] + bottom_padding
    width = rint(width)
    height = rint(height) or rint(1112)

    # calculate device connectors positions
    used_symbols = tuple(c['source'] for c in pb['connections']) + tuple(
        c['target'] for c in pb['connections'])
    used_types = ('audio', 'cv')
    device_capture = tuple(
        d for d in device_capture if d['type'] in used_types or d['symbol'] in
        ('serial_midi_in', 'midi_merger_out') or d['symbol'] in used_symbols)
    device_playback = tuple(
        d for d in device_playback
        if d['type'] in used_types or d['symbol'] in (
            'serial_midi_out',
            'midi_broadcaster_in') or d['symbol'] in used_symbols)
    step = rint(height / (len(device_capture) + 1))
    h = step
    for d in device_capture:
        d.update({'x': 0, 'y': h})
        h = h + step
    h = step
    for d in device_playback:
        d.update({'x': width, 'y': h})
        h = h + step

    # draw plugin cables and calculate connectors
    connectors = []
    paths = []
    for ix, c in enumerate(pb['connections']):
        # source
        source = next(
            (s for s in device_capture if s['symbol'] == c['source']), None)
        if source:
            source_connected_img = source['connected_img']
            source_pos = anchor(source_connected_img.size, source['x'],
                                source['y'], Anchor.LEFT_CENTER)
            source_x = source['x'] + source_connected_img.size[0]
            source_y = source['y']
            source_type = source['type']
        else:
            if '/' not in c['source']:
                continue
            source_i, source_s = c['source'].split('/')
            source = plugin_map[source_i]
            all_ports = source['data']['ports']['audio']['output'] + source[
                'data']['ports']['midi']['output'] + source['data']['ports'][
                    'cv']['output']
            port = next(p for p in all_ports if p['symbol'] == source_s)
            conn = port['connector']
            source_connected_img = port['connected_img']
            source_pos = (source['x'] + conn[0][0] - port['offset'][0],
                          source['y'] + conn[0][1] - port['offset'][1])
            source_x = source_pos[0] + source_connected_img.size[0]
            source_y = source_pos[1] + source_connected_img.size[1] / 2
            source_type = port['type']
        # target
        target = next(
            (t for t in device_playback if t['symbol'] == c['target']), None)
        if target:
            target_connected_img = target['connected_img']
            target_pos = anchor(target_connected_img.size, target['x'],
                                target['y'], Anchor.RIGHT_CENTER)
            target_x = target['x'] - target_connected_img.size[0]
            target_y = target['y']
            target_type = target['type']
        else:
            if '/' not in c['target']:
                continue
            target_i, target_s = c['target'].split('/')
            target = plugin_map[target_i]
            all_ports = target['data']['ports']['audio']['input'] + target[
                'data']['ports']['midi']['input'] + target['data']['ports'][
                    'cv']['input']
            port = next(p for p in all_ports if p['symbol'] == target_s)
            conn = port['connector']
            target_connected_img = port['connected_img']
            target_pos = (target['x'] + conn[0][0] - port['offset'][0],
                          target['y'] + conn[0][1] - port['offset'][1])
            target_x = target_pos[0]
            target_y = target_pos[1] + target_connected_img.size[1] / 2
            target_type = port['type']

        delta_x = target_x - source_x - 50
        if delta_x < 0:
            delta_x = 8.5 * (delta_x / 6)
        else:
            delta_x /= 1.5

        path = 'm{0},{1} c{2},{3},{4},{5},{6},{7}'.format(
            rint(source_x), rint(source_y),
            rint(target_x - delta_x - source_x), 0, rint(delta_x),
            rint(target_y - source_y), rint(target_x - source_x),
            rint(target_y - source_y))
        paths.append((path, source_type, target_type))
        connectors.append(
            (source_connected_img, (rint(source_pos[0]), rint(source_pos[1])),
             source_connected_img))
        connectors.append(
            (target_connected_img, (rint(target_pos[0]), rint(target_pos[1])),
             target_connected_img))

    # create image
    img = Image.new('RGBA', (width, height), (0, 0, 0, 0))

    # draw device connectors
    for d in device_capture:
        img.paste(d['img'],
                  anchor(d['img'].size, d['x'], d['y'], Anchor.LEFT_CENTER))
    for d in device_playback:
        img.paste(d['img'],
                  anchor(d['img'].size, d['x'], d['y'], Anchor.RIGHT_CENTER))

    # draw all paths
    try:
        import aggdraw
        draw = aggdraw.Draw(img)
        audio_pen = aggdraw.Pen('#81009A', 7)
        midi_pen = aggdraw.Pen('#00546C', 7)
        cv_pen = aggdraw.Pen('#BB6736', 7)
        for path, source_type, target_type in paths:
            symbol = aggdraw.Symbol(path)
            pen = audio_pen
            if source_type == 'midi' or target_type == 'midi':
                pen = midi_pen
            elif source_type == 'cv' or target_type == 'cv':
                pen = cv_pen
            draw.symbol((0, 0), symbol, pen)
        draw.flush()
    except:
        print('Aggdraw failed')

    # draw all connectors
    for c in connectors:
        img.paste(*c)

    # draw plugins
    for p in plugins:
        img.paste(p['img'], (rint(p['x']), rint(p['y'])), p['img'])

    img.save(os.path.join(bundle_path, 'screenshot.png'), compress_level=3)
    resize_image(img)
    img.save(os.path.join(bundle_path, 'thumbnail.png'))
    img.close()
示例#3
0
def take_screenshot(bundle_path, html_dir, cache_dir, size):
    os.makedirs(cache_dir, exist_ok=True)
    lv2_init()
    pb = get_pedalboard_info(bundle_path)

    if size:
        w, h = size.split('x')
        width, height = int(w), int(h)
    else:
        width, height = pb['width'],  pb['height']
    if (width, height) == (0, 0):
        width, height = 3840, 2160

    img_dir = os.path.join(html_dir, 'img')

    # preload images
    audio_input_img = Image.open(os.path.join(img_dir, 'audio-input.png'))
    audio_output_img = Image.open(os.path.join(img_dir, 'audio-output.png'))
    audio_input_connected = Image.open(os.path.join(img_dir, 'audio-input-connected.png'))
    audio_output_connected = Image.open(os.path.join(img_dir, 'audio-output-connected.png'))
    midi_input_img = Image.open(os.path.join(img_dir, 'midi-input.png'))
    midi_output_img = Image.open(os.path.join(img_dir, 'midi-output.png'))
    midi_input_connected = Image.open(os.path.join(img_dir, 'midi-input-connected.png'))
    midi_output_connected = Image.open(os.path.join(img_dir, 'midi-output-connected.png'))
    default_screenshot = Image.open(os.path.join(html_dir, 'resources', 'pedals', 'default.png'))

    right_padding = audio_input_connected.size[0] * 2
    bottom_padding = right_padding

    # create capture/playback connectors
    device_capture = []
    for ix in range(0, pb['hardware']['audio_ins']):
        device_capture.append({
            'symbol': 'capture_{0}'.format(ix + 1),
            'img': audio_output_img,
            'connected_img': audio_output_connected,
            'type': 'audio',
        })
    if pb['hardware'].get('serial_midi_in', False):
        device_capture.append({
            'symbol': 'serial_midi_in',
            'img': midi_output_img,
            'connected_img': midi_output_connected,
            'type': 'midi',
        })
    for midi_in in pb['hardware']['midi_ins']:
        device_capture.append({
            'symbol': midi_in['symbol'],
            'img': midi_output_img,
            'connected_img': midi_output_connected,
            'type': 'midi',
        })

    device_playback = []
    for ix in range(0, pb['hardware']['audio_outs']):
        device_playback.append({
            'symbol': 'playback_{0}'.format(ix + 1),
            'img': audio_input_img,
            'connected_img': audio_input_connected,
            'type': 'audio',
        })
    if pb['hardware'].get('serial_midi_out', False):
        device_playback.append({
            'symbol': 'serial_midi_out',
            'img': midi_input_img,
            'connected_img': midi_input_connected,
            'type': 'midi',
        })
    for midi_out in pb['hardware']['midi_outs']:
        device_playback.append({
            'symbol': midi_out['symbol'],
            'img': midi_input_img,
            'connected_img': midi_input_connected,
            'type': 'midi',
        })

    # create plugins
    plugins = pb['plugins']
    plugin_map = {}
    for p in plugins:
        # read plugin data
        data = get_plugin_info(p['uri'])
        p['data'] = data

        # read plugin image
        gui = get_plugin_gui(p['uri'])
        screenshot_path = gui.get('screenshot', None)
        pimg = Image.open(screenshot_path).convert('RGBA') if screenshot_path else default_screenshot
        p['img'] = pimg

        if screenshot_path:
            # detect ports and save/read
            version = '{0}.{1}'.format(data['version'], data.get('release', 0)).replace('.', '_')
            encoded_uri = base64.b64encode(p['uri'].encode()).decode()
            filename = os.path.join(cache_dir, '{0}_{1}_{2}'.format(__version__.replace('.', '_'), encoded_uri, version))
            if os.path.isfile(filename):
                with open(filename, 'r') as fh:
                    columns = json.loads(fh.read())
            else:
                columns = {
                    'in_ports': [list(c) for c in detect_first_column(pimg, pimg.size[0])],
                    'out_ports': [list(c) for c in detect_first_column(pimg, pimg.size[0], rtol=True)],
                }
                with open(filename, 'w') as fh:
                    fh.write(json.dumps(columns))
        else:  # tuna can, we have to guess the position of the connectors
            columns = {
                'in_ports': [[-9, 121], [-9, 146], [-9, 190], [-9, 215], [-9, 259], [-9, -284], [-9, 328], [-9, 353]],
                'out_ports': [[259, 121], [259, 146], [259, 190], [259, 215], [259, 259], [259, 284], [259, 328], [259, 353]]
            }

        # detect connectors
        in_ports = data['ports']['audio']['input'] + data['ports']['midi']['input']
        if len(in_ports) > 0:
            for ix, conn in enumerate(chunks(columns['in_ports'], 2)):
                if ix < len(in_ports):
                    in_ports[ix]['connector'] = conn
                    if ix < len(data['ports']['audio']['input']):
                        in_ports[ix]['connected_img'] = audio_input_connected
                        in_ports[ix]['offset'] = (79, 15)
                        in_ports[ix]['type'] = 'audio'
                    else:
                        in_ports[ix]['connected_img'] = midi_input_connected
                        in_ports[ix]['offset'] = (67, 9)
                        in_ports[ix]['type'] = 'midi'
            if not all('connector' in p for p in in_ports):
                raise Exception('Connector detection for input ports of plugin {0} failed'.format(p['uri']))
        out_ports = data['ports']['audio']['output'] + data['ports']['midi']['output']
        if len(out_ports) > 0:
            for ix, conn in enumerate(chunks(columns['out_ports'], 2)):
                if ix < len(out_ports):
                    out_ports[ix]['connector'] = conn
                    if ix < len(data['ports']['audio']['output']):
                        out_ports[ix]['connected_img'] = audio_output_connected
                        out_ports[ix]['offset'] = (8, 15)
                        out_ports[ix]['type'] = 'audio'
                    else:
                        out_ports[ix]['connected_img'] = midi_output_connected
                        out_ports[ix]['offset'] = (8, 9)
                        out_ports[ix]['type'] = 'midi'
            if not all('connector' in p for p in out_ports):
                raise Exception('Connector detection for output ports of plugin {0} failed'.format(p['uri']))

        plugin_map[p['instance']] = p

    # calculate image size
    height = 0
    for p in plugins:
        if p['x'] + p['img'].size[0] + right_padding > width:
            width = p['x'] + p['img'].size[0] + right_padding
        if p['y'] + p['img'].size[1] + bottom_padding > height:
            height = p['y'] + p['img'].size[1] + bottom_padding
    width = rint(width)
    height = rint(height) or rint(1112)

    # calculate device connectors positions
    used_symbols = [c['source'] for c in pb['connections']] + [c['target'] for c in pb['connections']]
    device_capture = [
        d for d in device_capture
        if d['type'] == 'audio' or d['symbol'] == 'serial_midi_in' or d['symbol'] in used_symbols
    ]
    device_playback = [
        d for d in device_playback
        if d['type'] == 'audio' or d['symbol'] == 'serial_midi_out' or d['symbol'] in used_symbols
    ]
    step = rint(height / (len(device_capture) + 1))
    h = step
    for d in device_capture:
        d.update({'x': 0, 'y': h})
        h = h + step
    h = step
    for d in device_playback:
        d.update({'x': width, 'y': h})
        h = h + step

    # draw plugin cables and calculate connectors
    connectors = []
    paths = []
    for ix, c in enumerate(pb['connections']):
        # source
        source = next((s for s in device_capture if s['symbol'] == c['source']), None)
        if source:
            source_connected_img = source['connected_img']
            source_pos = anchor(source_connected_img.size, source['x'], source['y'], Anchor.LEFT_CENTER)
            source_x = source['x'] + source_connected_img.size[0]
            source_y = source['y']
            source_type = source['type']
        else:
            if '/' not in c['source']:
                continue
            source_i, source_s = c['source'].split('/')
            source = plugin_map[source_i]
            all_ports = source['data']['ports']['audio']['output'] + source['data']['ports']['midi']['output']
            port = next(p for p in all_ports if p['symbol'] == source_s)
            conn = port['connector']
            source_connected_img = port['connected_img']
            source_pos = (source['x'] + conn[0][0] - port['offset'][0], source['y'] + conn[0][1] - port['offset'][1])
            source_x = source_pos[0] + source_connected_img.size[0]
            source_y = source_pos[1] + source_connected_img.size[1] / 2
            source_type = port['type']
        # target
        target = next((t for t in device_playback if t['symbol'] == c['target']), None)
        if target:
            target_connected_img = target['connected_img']
            target_pos = anchor(target_connected_img.size, target['x'], target['y'], Anchor.RIGHT_CENTER)
            target_x = target['x'] - target_connected_img.size[0]
            target_y = target['y']
            target_type = target['type']
        else:
            if '/' not in c['target']:
                continue
            target_i, target_s = c['target'].split('/')
            target = plugin_map[target_i]
            all_ports = target['data']['ports']['audio']['input'] + target['data']['ports']['midi']['input']
            port = next(p for p in all_ports if p['symbol'] == target_s)
            conn = port['connector']
            target_connected_img = port['connected_img']
            target_pos = (target['x'] + conn[0][0] - port['offset'][0], target['y'] + conn[0][1] - port['offset'][1])
            target_x = target_pos[0]
            target_y = target_pos[1] + target_connected_img.size[1] / 2
            target_type = port['type']

        delta_x = target_x - source_x - 50
        if delta_x < 0:
            delta_x = 8.5 * (delta_x / 6)
        else:
            delta_x /= 1.5

        path = 'm{0},{1} c{2},{3},{4},{5},{6},{7}'.format(
            rint(source_x),
            rint(source_y),
            rint(target_x - delta_x - source_x),
            0,
            rint(delta_x),
            rint(target_y - source_y),
            rint(target_x - source_x),
            rint(target_y - source_y)
        )
        paths.append((path, source_type, target_type))
        connectors.append((source_connected_img, (rint(source_pos[0]), rint(source_pos[1])), source_connected_img))
        connectors.append((target_connected_img, (rint(target_pos[0]), rint(target_pos[1])), target_connected_img))

    # create image
    img = Image.new('RGBA', (width, height), (0, 0, 0, 0))

    # draw device connectors
    for d in device_capture:
        img.paste(d['img'], anchor(d['img'].size, d['x'], d['y'], Anchor.LEFT_CENTER))
    for d in device_playback:
        img.paste(d['img'], anchor(d['img'].size, d['x'], d['y'], Anchor.RIGHT_CENTER))

    # draw all paths
    try:
        import aggdraw
        draw = aggdraw.Draw(img)
        audio_pen = aggdraw.Pen('#81009A', 7)
        midi_pen = aggdraw.Pen('#00546C', 7)
        for path, source_type, target_type in paths:
            symbol = aggdraw.Symbol(path)
            draw.symbol((0, 0), symbol, midi_pen if source_type == 'midi' or target_type == 'midi' else audio_pen)
        draw.flush()
    except:
        print('Aggdraw failed')

    # draw all connectors
    for c in connectors:
        img.paste(*c)

    # draw plugins
    for p in plugins:
        img.paste(p['img'], (rint(p['x']), rint(p['y'])), p['img'])

    img.save(os.path.join(bundle_path, 'screenshot.png'), compress_level=3)
    resize_image(img)
    img.save(os.path.join(bundle_path, 'thumbnail.png'))
    img.close()
示例#4
0
    def __init__(self):
        QMainWindow.__init__(self)
        gCarla.gui = self

        URI = sys.argv[1]

        # ----------------------------------------------------------------------------------------------------
        # Internal stuff

        self.fCurrentFrame = None
        self.fDocElemement = None
        self.fCanSetValues = False
        self.fNeedsShow = False
        self.fSizeSetup = False
        self.fQuitReceived = False
        self.fWasRepainted = False

        lv2_init()

        self.fPlugin = get_plugin_info(URI)
        self.fPorts = self.fPlugin['ports']
        self.fPortSymbols = {}
        self.fPortValues = {}
        self.fParamTypes = {}
        self.fParamValues = {}

        for port in self.fPorts['control']['input']:
            self.fPortSymbols[port['index']] = (port['symbol'], False)
            self.fPortValues[port['index']] = port['ranges']['default']

        for port in self.fPorts['control']['output']:
            self.fPortSymbols[port['index']] = (port['symbol'], True)
            self.fPortValues[port['index']] = port['ranges']['default']

        for parameter in self.fPlugin['parameters']:
            if parameter['ranges'] is None:
                continue
            if parameter['type'] == "http://lv2plug.in/ns/ext/atom#Bool":
                paramtype = 'b'
            elif parameter['type'] == "http://lv2plug.in/ns/ext/atom#Int":
                paramtype = 'i'
            elif parameter['type'] == "http://lv2plug.in/ns/ext/atom#Long":
                paramtype = 'l'
            elif parameter['type'] == "http://lv2plug.in/ns/ext/atom#Float":
                paramtype = 'f'
            elif parameter['type'] == "http://lv2plug.in/ns/ext/atom#Double":
                paramtype = 'g'
            elif parameter['type'] == "http://lv2plug.in/ns/ext/atom#String":
                paramtype = 's'
            elif parameter['type'] == "http://lv2plug.in/ns/ext/atom#Path":
                paramtype = 'p'
            elif parameter['type'] == "http://lv2plug.in/ns/ext/atom#URI":
                paramtype = 'u'
            else:
                continue
            if paramtype not in ('s', 'p', 'u') and parameter['ranges'][
                    'minimum'] == parameter['ranges']['maximum']:
                continue
            self.fParamTypes[parameter['uri']] = paramtype
            self.fParamValues[
                parameter['uri']] = parameter['ranges']['default']

        # ----------------------------------------------------------------------------------------------------
        # Init pipe

        if len(sys.argv) == 7:
            self.fPipeClient = gCarla.utils.pipe_client_new(
                lambda s, msg: self.msgCallback(msg))
        else:
            self.fPipeClient = None

        # ----------------------------------------------------------------------------------------------------
        # Init Web server

        self.fWebServerThread = WebServerThread(self)
        self.fWebServerThread.start()

        # ----------------------------------------------------------------------------------------------------
        # Set up GUI

        self.setContentsMargins(0, 0, 0, 0)

        self.fWebview = QWebView(self)
        #self.fWebview.setAttribute(Qt.WA_OpaquePaintEvent, False)
        #self.fWebview.setAttribute(Qt.WA_TranslucentBackground, True)
        self.setCentralWidget(self.fWebview)

        page = self.fWebview.page()
        page.setViewportSize(QSize(980, 600))

        mainFrame = page.mainFrame()
        mainFrame.setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
        mainFrame.setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)

        palette = self.fWebview.palette()
        palette.setBrush(QPalette.Base, palette.brush(QPalette.Window))
        page.setPalette(palette)
        self.fWebview.setPalette(palette)

        settings = self.fWebview.settings()
        settings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True)

        self.fWebview.loadFinished.connect(self.slot_webviewLoadFinished)

        url = "http://127.0.0.1:%s/icon.html#%s" % (PORT, URI)
        print("url:", url)
        self.fWebview.load(QUrl(url))

        # ----------------------------------------------------------------------------------------------------
        # Connect actions to functions

        self.SIGTERM.connect(self.slot_handleSIGTERM)

        # ----------------------------------------------------------------------------------------------------
        # Final setup

        self.fIdleTimer = self.startTimer(30)

        if self.fPipeClient is None:
            # testing, show UI only
            self.setWindowTitle("TestUI")
            self.fNeedsShow = True