def get_selection_for_new_device(selection, insert_left=False):
 selected = selection.selected_object
 if (isinstance(selected, Live.DrumPad.DrumPad) and selected.chains and selected.chains[0].devices):
  index = (0 if insert_left else (-1))
  selected = selected.chains[0].devices[index]
 elif (not isinstance(selected, Live.Device.Device)):
  selected = selection.selected_device
 return selected

def get_selection_for_new_device ( selection , insert_left = False ) : selected = selection . selected_object if ( isinstance ( selected , Live . DrumPad . DrumPad ) and selected . chains and selected . chains [ 0 ] . devices ) : index = ( 0 if insert_left else ( - 1 ) ) selected = selected . chains [ 0 ] . devices [ index ] elif ( not isinstance ( selected , Live . Device . Device ) ) : selected = selection . selected_device return selected
returns a device .