コード例 #1
0
ファイル: osc.py プロジェクト: dewiweb/AddRoutes
def set_props(item, bl_item, val):
    global qf_frame
    if len(val) == 1:
        val = val[0]

    func = item['func']
    result = func(bl_item, item, val)
    post_func = item['post_func']

    if bl_item.is_str2eval:
        g_vars.evalprop(bl_item.str2eval, bl_item.withctx)
        prop = g_vars.eval_prop
        ref = g_vars.eval_ref
    else:
        ref = item['ref']
        prop = item['prop']

    if bl_item.is_array and (bl_item.use_array is False):
        current = getattr(ref, prop)[bl_item.array]
        getattr(ref, prop)[bl_item.array] = post_func(current, result, bl_item)
    else:
        current = getattr(ref, prop)
        result2 = post_func(current, result, bl_item)
        setattr(ref, prop, result2)

    # insert keyframe
    print(qf_frame)
    if bl_item.record and (bpy.data.screens[0].is_animation_playing or qf_frame is not None):
        if bl_item.is_array and (bl_item.use_array is False):
            index = bl_item.array
            ref.keyframe_insert(data_path=prop, index=index, **item['ks_params'], **qf_frame)
        else:
            ref.keyframe_insert(data_path=prop, **item['ks_params'], **qf_frame)
コード例 #2
0
def set_props(item, bl_item, val):
    global midifile_conv

    # testing rescale feature mode
    if bl_item.rescale_mode == 'Direct':
        result = val

    elif bl_item.rescale_mode == 'Auto':
        # no need to clamp
        result = rescale(val, bl_item.rescale_blender_low,
                         bl_item.rescale_blender_high, item['quant'])

    elif bl_item.rescale_mode == "Cut":
        if val < bl_item.rescale_outside_low or val > bl_item.rescale_outside_high:
            return
        else:
            val = clamp(bl_item.rescale_outside_low, val,
                        bl_item.rescale_outside_high)
            result = rescale(val, bl_item.rescale_blender_low,
                             bl_item.rescale_blender_high, item['quant'])

    elif bl_item.rescale_mode == 'Wrap':
        val = clamp(bl_item.rescale_outside_low, val,
                    bl_item.rescale_outside_high)
        result = rescale(val, bl_item.rescale_blender_low,
                         bl_item.rescale_blender_high, item['quant'])

    func = item['func']
    result = func(bl_item, item, result)
    post_func = item['post_func']

    if bl_item.is_str2eval:
        g_vars.evalprop(bl_item.str2eval, bl_item.withctx)
        prop = g_vars.eval_prop
        ref = g_vars.eval_ref
    else:
        ref = item['ref']
        prop = item['prop']

    if bl_item.is_array:
        current = getattr(ref, prop)[bl_item.array]
        getattr(ref, prop)[bl_item.array] = post_func(current, result, bl_item)
    else:
        current = getattr(ref, prop)
        result2 = post_func(current, result, bl_item)
        setattr(ref, prop, result2)

    # insert keyframe
    if bl_item.record and (bpy.data.screens[0].is_animation_playing
                           or midifile_conv):
        if bl_item.is_array:
            index = bl_item.array
            ref.keyframe_insert(data_path=prop,
                                index=index,
                                **item['ks_params'],
                                **mf_frame)
        else:
            ref.keyframe_insert(data_path=prop,
                                **item['ks_params'],
                                **mf_frame)
コード例 #3
0
ファイル: blemote.py プロジェクト: devcurmudgeon/AddRoutes
def actua_bl():
    prefs = bpy.context.preferences.addons['AddRoutes'].preferences
    in_len = len(g_vars.blemote_fb)

    if in_len > prefs.overflow:
        g_vars.blemote_fb = g_vars.blemote_fb[:prefs.overflow]
        bpy.context.window_manager.n_overflow += 1

    for i in range(prefs.overflow):
        if len(g_vars.blemote_fb) == 0:
            break
        else:
            msg = g_vars.blemote_fb.pop(0)
            bl_item = msg[0]
            item = msg[1]
            val = float(msg[2])

            func = item['func']
            post_func = item['post_func']

            # scene can change in the meanwhile
            try:
                result = func(bl_item, item, val)

                if bl_item.is_str2eval:
                    g_vars.evalprop(bl_item.str2eval, bl_item.withctx)
                    prop = g_vars.eval_prop
                    ref = g_vars.eval_ref
                else:
                    ref = item['ref']
                    prop = item['prop']

                if bl_item.is_array:
                    current = getattr(ref, prop)[bl_item.array]
                    getattr(ref, prop)[bl_item.array] = post_func(
                        current, result, bl_item)
                else:
                    current = getattr(ref, prop)
                    result2 = post_func(current, result, bl_item)
                    setattr(ref, prop, result2)

                # insert keyframe
                if bl_item.record and bpy.data.screens[0].is_animation_playing:
                    if bl_item.is_array:
                        index = bl_item.array
                        ref.keyframe_insert(data_path=prop,
                                            index=index,
                                            **item['ks_params'])
                    else:
                        ref.keyframe_insert(data_path=prop,
                                            **item['ks_params'])

            except:
                print(
                    "Error while sending, improper Blemote route parameters with: "
                    + repr(bl_item))

    return prefs.refresh / 1000
コード例 #4
0
ファイル: osc.py プロジェクト: dewiweb/AddRoutes
def osc_frame_upd(scn):
    # kludge to avoid error while changing scene
    if g_vars.scene is not scn:
        return

    # send osc events
    bcw = bpy.context.window_manager
    osc = OSCClient(bcw.addroutes_osc_udp_out, bcw.addroutes_osc_port_out, encoding='utf8')

    if bcw.addroutes_osc_out_enable is True:
        for bl_item, item in g_vars.addroutes_osc_out:
            # getting current value
            if bl_item.is_str2eval:
                g_vars.evalprop(bl_item.str2eval, bl_item.withctx)
                prop = g_vars.eval_prop
                ref = g_vars.eval_ref
            else:
                ref = item['ref']
                prop = item['prop']

            # apply func
            func = item['func']

            try:
                if bl_item.is_array:
                    if bl_item.use_array is False:
                        val = getattr(ref, prop)[bl_item.array]
                        val2 = [func(bl_item, item, val)]
                    else:
                        val = getattr(ref, prop)
                        val2 = list(func(bl_item, item, val))
                else:
                    val = getattr(ref, prop)
                    val2 = [func(bl_item, item, val)]


                # the value has changed
                if val2 != item['val']:
                    item['val'] = val2

                    # for multi routes
                    val3 = val2.copy()
                    if bl_item.is_multi:
                        val3.insert(0, item['idx'])

                    addr = str.encode(item['address'])
                    osc.send_message(addr, val3)

            except:
                print("Error while sending, improper OSC route #", item["n"], 'category :', bl_item.category)
            break
コード例 #5
0
def midi_frame_upd(scn):
    # kludge to avoid error while changing scene
    if g_vars.scene is not scn:
        return

    # for midifile live playing
    global midifile_array, prev_frame

    # frame change pre is buggy !
    # print(scn.frame_current)

    if scn.mf_play and bpy.data.screens[0].is_animation_playing:
        n_to_play = scn.frame_current - scn.mf_offset
        if (len(midifile_array) > n_to_play) and (n_to_play >= 0):
            for msg in midifile_array[n_to_play]:
                arr = decode(scn, msg)
                actualise(scn, arr)

    # this is for SPP out
    new_frame = scn.frame_current
    if scn.SPP_out and midiout.is_port_open():
        # for restarting while playing in loop mode OR when not playing
        if ((new_frame != prev_frame + 1)
                and is_playing) or is_playing is False:
            pos_sec = scn.frame_current / scn.render.fps
            beats = (pos_sec / 60
                     ) * scn.tempo * 4  # in fact 16th not beat, hence the "4"
            p2 = int(beats / 128)
            p1 = beats % 128
            midiout.send_message([242, p1, p2])
    prev_frame = new_frame

    # send midi events
    for bl_item, item in g_vars.addroutes_out:
        # getting current value
        if bl_item.is_str2eval:
            g_vars.evalprop(bl_item.str2eval, bl_item.withctx)
            prop = g_vars.eval_prop
            ref = g_vars.eval_ref
        else:
            ref = item['ref']
            prop = item['prop']

        try:
            if bl_item.is_array:
                val = getattr(ref, prop)[bl_item.array]
            else:
                val = getattr(ref, prop)

            # apply func
            func = item['func']
            val = func(bl_item, item, val)

            # testing rescale feature mode
            scale = item['rescale_bl']
            quant = item['quant']

            if bl_item.rescale_mode == 'Direct':
                val2 = int(clamp(0, val, quant))

            if bl_item.rescale_mode == 'Auto':
                val2 = rescale(val, 0, quant, scale)
                val2 = int(clamp(0, val2, quant))

            elif bl_item.rescale_mode == "Cut":
                if val < bl_item.rescale_outside_low or val > bl_item.rescale_outside_high:
                    return
                else:
                    val2 = rescale(val, 0, quant, scale)
                    val2 = int(
                        clamp(bl_item.rescale_outside_low, val2,
                              bl_item.rescale_outside_high))

            elif bl_item.rescale_mode == 'Wrap':
                val2 = rescale(val, 0, quant, scale)
                val2 = int(
                    clamp(bl_item.rescale_outside_low, val2,
                          bl_item.rescale_outside_high))

            # the value has changed
            if val2 != item['val']:
                item['val'] = val2

                # simple 7bit parameter like pgm change and mono AT
                if item['lenx'] == 1:
                    midiout.send_message([item['midi'], val2])

                # others 2 bytes msg
                elif item['reg'] is None:
                    # for poly AT, cc7
                    if item['quant'] == 127:
                        midiout.send_message(
                            [item['midi'], item['filter'], val2])
                    # for pitchbend
                    else:
                        LSB = val2 % 128
                        MSB = int(val2 / 128)
                        midiout.send_message([item['midi'], LSB, MSB])

                # for rpn/nrpn 7bit and 14bit
                else:
                    # 7bit
                    if item['quant'] == 127:
                        for msg in item['reg']:
                            midiout.send_message(
                                [item['midi'], msg[0],
                                 eval(msg[1])])

                    # 14bit msg
                    else:
                        LSB = val2 % 128
                        MSB = int(val2 / 128)
                        for msg in item['reg']:
                            midiout.send_message(
                                [item['midi'], msg[0],
                                 eval(msg[1])])
        except:
            print("Error while sending, improper MIDI route #", item["n"],
                  'category :', bl_item.category)