一个Python库来驱动AKAI LPD8 pad控制器
lpd8的Python项目详细描述
lpd8型
连接AKAI LPD8 pad设备的Python库
这个小库是为了帮助将AKAI LPD8 pad集成到Python程序中而设计的。 它易于集成,使用简单。基于rtmidi库,它使用MIDI消息来 与LPD8设备通信并读取来自它的消息。 在PAD模式下,它允许某些焊盘闪烁或处于ON(灯亮)和OFF(灯熄灭)状态。 它允许使用4个程序和一个粘性模式旋钮控制,这意味着图书馆 存储每个程序的旋钮状态,仅当旋钮的值设置为以前的状态时才对其作出反应 对于给定的程序。 旋钮限制和行为是可配置的,衬垫也是。 它对每个事件使用订阅机制,允许触发对象的特定方法。这些方法 然后可以实现其他MIDI或OSC事件或引导视觉界面。在
使用示例
fromlpd8.lpd8importLPD8fromlpd8.programsimportProgramsfromlpd8.padsimportPad,Padsfromlpd8.knobsimportKnobsfromlpd8.pgm_chgimportPgm_ChgfromconsummerimportConsummerfromtimeimportsleep# This object is created to test different callbacks from LPD8 classconsummer=Consummer()# Create an LPD8 object and try to start it (open MIDI in and out communication)lpd8=LPD8()lpd8.start()# In normal times, a control knob is meant to be sticky. That means that if we change program and then knob# value, knob will not react when we return to original program until last stored value for this program# will be reached. It will then follow changes normally# Note that we can define sticky mode for a single knob, an array of knobs or all knobslpd8.set_not_sticky_knob(Programs.PGM_4,[Knobs.KNOB_1,Knobs.KNOB_2,Knobs.KNOB_3,Knobs.KNOB_4])# In all following settings, we will define limits / actions for PROGRAM 4# Define control knob 1 limits from -1 to 1 and set increments to float values# Define control knob 2 limits from 0 to 100 with 10 steps (limit values to 0, 10, 20, ..., 90, 100)# Knobs that have no definition range from 0..127 with integer increments of 1 (default MIDI behaviour)lpd8.set_knob_limits(Programs.PGM_4,Knobs.KNOB_1,-1,1,is_int=False)lpd8.set_knob_limits(Programs.PGM_4,Knobs.KNOB_2,0,100,steps=10)# Set An initial value for knob 3 to 63lpd8.set_knob_value(Programs.PGM_4,Knobs.KNOB_3,63)# Set different modes for pads# Note that we can define modes for a single pad, an array of pads or all pads# Pads 1 and two will blink and will be in switch mode (every push changes state between 0 and 1)# Pad 3 won't blink but will be in switch mode too# Pad 4 will be in push mode, sending a 1 at every NOTE ON event and a 0 at every NOTE OFF event# Pads that have no definition are set in classical pad mode with NOTE ON / NOTE OFF events and velocity valueslpd8.set_pad_mode(Programs.PGM_4,[Pads.PAD_1,Pads.PAD_2],Pad.SWITCH_MODE+Pad.BLINK_MODE)lpd8.set_pad_mode(Programs.PGM_4,Pads.PAD_3,Pad.SWITCH_MODE)lpd8.set_pad_mode(Programs.PGM_4,Pads.PAD_4,Pad.PUSH_MODE)# For a pad of type SWITCH, sets the initial state of pad# Note that we can define modes for a single pad, an array of pads or all padslpd8.set_pad_switch_state(Programs.PGM_4,[Pads.PAD_1,Pads.PAD_3],Pad.ON)# Subscribe to different events and map them to a method in test object# Note that we can subscribe events for a single object, an array of objects or all objects of a grouplpd8.subscribe(consummer,consummer.ctrl_value,Programs.PGM_4,LPD8.CTRL,Knobs.ALL_KNOBS)lpd8.subscribe(consummer,consummer.note_on_value,Programs.PGM_4,LPD8.NOTE_ON,Pads.ALL_PADS)lpd8.subscribe(consummer,consummer.note_off_value,Programs.PGM_4,LPD8.NOTE_OFF,Pads.ALL_PADS)lpd8.subscribe(consummer,consummer.pgm_change,Programs.PGM_4,LPD8.PGM_CHG,Pgm_Chg.PGM_CHG_4)# We loop as long as test class allows itwhileconsummer.is_running():# Every loop, we update pads status (blink, ON or OFF)# This method returns True if LPD8 pad is still running, False otherwiseiflpd8.pad_update():sleep(.5)else:# If LPD8 pad is not running anymore, we leave the loopconsummer.stop()# We tidy up things and kill LPD8 processlpd8.stop()
- 项目
标签: