Example #1
0
    def event_to_midi(e, A, base_note_num=24):
        mes = []
        ename = e[0]

        # normalize and (maybe) filter parameters for output
        if ename.startswith('acc'):
            # update filter accelerometer state
            a = A[ename]
            ap = A[ename] = lpf(a, e[2][1])
            # modify event acc event with filtering & MIDI scale
            e = (e[0], (e[1][0], scaleShort(int(a))), (e[2][0], scaleShort(int(ap))))
        else:
            # normal event pressure/control value for MIDI scale
            e = (e[0], (e[1][0], scaleChar(e[1][1])), (e[2][0], scaleChar(e[2][1])))

        if prog_mode and abs(e[1][1] - e[2][1]) < 10:
            return (mes, A)

        if ename in note:
            event_note = base_note_num + note[ename]
            (was_on, prev_pressure) = e[1]
            (is_on, cur_pressure) = e[2]

            if is_on and not was_on:
                mes.append(m.note_on(channel, event_note, cur_pressure))
            elif was_on and not is_on:
                mes.append(m.note_off(channel, event_note, prev_pressure))
            else:
                mes.append(m.note_aftertouch(channel, event_note, cur_pressure))

        if ename in cc:
            (blank, ctrl_val) = e[2]
            mes.append(m.control_change(channel, cc[ename], invert(ctrl_val)))

        if ename in PITCH_WHEEL:
            PITCH_WHEEL[ename] = e[2][1]
            [ph, pl] = PITCH_WHEEL.values()
            if ph and pl:
                mes.append(m.pitch_wheel(channel, invert(ph) * 128 + invert(pl)))

        if ename in PITCH_TWO_SIDE:
            PITCH_TWO_SIDE[ename] = e[2][1]
            [pu, pd] = PITCH_TWO_SIDE.values()
            mes.append(m.pitch_wheel(channel, int(8192 + 32.125 * (pu if pu >= pd else -pd))))

        return (mes, A)
Example #2
0
    scale = [0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19]

    dev = open('/dev/input/js0')
    out = midi.MidiOut(open('/dev/midi1', 'w'))

    # out.send(midi.program_change(0, 19))
    out.send(midi.program_change(0, 16))

    while 1:
        e = read_event(dev)
        if e.type == JS_EVENT_BUTTON:
            note = 62 + 12 + scale[e.number]
            if e.value:
                out.send(midi.note_on(0, note, 64))
            else:
                out.send(midi.note_off(0, note, 64))

        if e.type == JS_EVENT_AXIS:
            #if e.number == 1:
            #    if e.value <= 0:
            #        value = int((-e.value) * 127)
            #        out.send(midi.control_change(0, 7, value))
            #
            #        print e.value, value

            if e.number == 0:
                bend = int(((e.value + 1) / 2) * 16383)
                hi = bend >> 7
                lo = bend & 0x7f
                out.send(midi.pitch_wheel(0, lo, hi))
Example #3
0
    scale = [0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19]

    dev = open('/dev/input/js0')
    out = midi.MidiOut(open('/dev/midi1', 'w'))

    # out.send(midi.program_change(0, 19))
    out.send(midi.program_change(0, 16))

    while 1:
        e = read_event(dev)
        if e.type == JS_EVENT_BUTTON:
            note = 62 + 12 + scale[e.number]
            if e.value:
                out.send(midi.note_on(0, note, 64))
            else:
                out.send(midi.note_off(0, note, 64))

        if e.type == JS_EVENT_AXIS:
            #if e.number == 1:
            #    if e.value <= 0:
            #        value = int((-e.value) * 127)
            #        out.send(midi.control_change(0, 7, value))
            #
            #        print e.value, value

            if e.number == 0:
                bend = int(((e.value + 1)/2) * 16383)
                hi = bend >> 7
                lo = bend & 0x7f
                out.send(midi.pitch_wheel(0, lo, hi))