Exemple #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)
Exemple #2
0
def main():
    print "starting...."
    sleep(3)

    packets = [midi.note_on(0, 65, 120),
               midi.note_on(0, 68, 120),
               midi.note_on(0, 80, 120)]
    coremidi.midi_send(h, packets)
    print "note on..."

    sleep(.5)

    packets = [midi.note_aftertouch(0, 65, 60)]
    coremidi.midi_send(h, packets)
    print "note aftertouch 1..."

    sleep(.5)

    packets = [midi.note_aftertouch(0, 65, 30),
               midi.note_aftertouch(0, 68, 60)]
    coremidi.midi_send(h, packets)
    print "note aftertouch 2..."

    sleep(.5)

    packets = [midi.note_aftertouch(0, 65, 10),
               midi.note_aftertouch(0, 68, 30),
               midi.note_aftertouch(0, 80, 60)]
    coremidi.midi_send(h, packets)
    print "note aftertouch 3..."

    sleep(.5)

    packets = [midi.note_off(0, 65, 120),
               midi.note_off(0, 68, 120),
               midi.note_off(0, 80, 120)]
    coremidi.midi_send(h, packets)
    print "note off..."
    sleep(3)