def process(command): """Processes events to forward them onto note processors Args: command (ParsedEvent): command to process """ # If in note mode menu, use that processor if note_menu_active: processNoteModeMenu(command) # Otherwise use note processors else: for x in customProcessorsAll: object_to_call = getattr(noteprocessors, x) if object_to_call.NAME == internal.noteMode.getState(): if object_to_call.FORWARD_NOTES and command.type == eventconsts.TYPE_NOTE and not internal.getPortExtended(): internal.sendCompleteInternalMidiMessage(command.getDataMIDI()) object_to_call.process(command) if command.ignored: break # Then check the note mode menu button processNoteModeMenuOpener(command)
def processNoteModeMenuOpener(command): command.addProcessor("Note Menu Opener Processor") if ( command.type is eventconsts.TYPE_PAD and command.is_lift and (command.coord_X, command.coord_Y) == (8, 1) ): if not note_menu_active: switchNoteModeMenu(True) command.handle("Open note mode menu", True) else: # If on last page if noteModeMenu.num_modes - 1 == noteModeMenu.mode: # Exit menu switchNoteModeMenu(False) command.handle("Exit note mode menu", True) else: noteModeMenu.nextMode() command.handle("Next page of note mode menu", True) elif ( # Basic drum pad: forward event command.type is eventconsts.TYPE_BASIC_PAD and command.is_lift and (command.coord_X, command.coord_Y) == (8, 1) and not note_menu_active ): switchNoteModeMenu(True) if not internal.getPortExtended(): internal.sendCompleteInternalMidiMessage(command.getDataMIDI(), "Forward drum for opening note mode menu") else: internal.extendedMode.setVal(True, eventconsts.INCONTROL_PADS) command.handle("Open note mode menu", True)
def processNoteModeMenu(command): command.addProcessor("Note Menu Processor") if command.type is eventconsts.TYPE_PAD and command.is_lift: note_mode_index = noteModeMenu.getMode()*16 + command.coord_X + 8*command.coord_Y if note_mode_index < len(customProcessors): internal.sendCompleteInternalMidiMessage(internal.consts.MESSAGE_INPUT_MODE_SELECT + (note_mode_index << 16)) switchNoteModeMenu(False) setModeByIndex(note_mode_index) command.handle("Set note mode to " + getattr(noteprocessors, customProcessors[note_mode_index]).NAME) elif command.coord_X < 8: command.handle("Note mode catch-all", silent=True)
def processBasic(command): """Processes ParsedEvents in basic mode script Args: command (ParsedEvent): a parsed MIDI event """ # Send event to reset other controller internal.sendCompleteInternalMidiMessage( internal.consts.MESSAGE_RESET_INTERNAL_CONTROLLER) try: if command.recieved_internal: processReceived(command) return # Process key mappings controllerprocessors.process(command) # Call primary processor processfirst_basic.process(command) if command.ignored: return # Process through shift processors internal.shifts.process(command) if command.ignored: return # Send to note processors noteprocessors.process(command) if command.type == eventconsts.TYPE_PAD: command.handle("Post-note-processor pad catch", True) if command.ignored: return # For note events quit now if command.type == eventconsts.TYPE_NOTE: return # Only call plugin and window processors if it is safe to do so | Currently disabled due to errors if command.pme_system_safe or True: # Attempt to process event using custom processors for plugins pluginprocessors.process(command) if command.ignored: return except Exception as e: internal.errors.triggerError(e)
def process(command): """Called with an event to be processed by your note processor. Events aren't filtered so you'll want to make sure your processor checks that events are notes. Args: command (ParsedEvent): An event for your function to modify/act on. """ global current_set command.addProcessor("Note Randomiser Processor") # If the note processor isn't initialised, call the initialise function instead if not INIT_COMPLETE: processInit(command) return # If command is a note if command.type is eventconsts.TYPE_NOTE: if command.value: new_note = chord_sets[current_set][math.floor( abs(rng.random() * len(chord_sets[current_set]) - 0.01))] internal.notesDown.noteOn( processorhelpers.ExtensibleNote(command, [ processorhelpers.RawEvent(command.status, new_note, command.value) ])) command.handle("Randomise note") else: internal.notesDown.noteOff(command) command.handle("Randomise note off", True) elif command.id == eventconsts.PEDAL: if command.is_lift: command.handle("Pedal lift", True) else: toNextSet() if not internal.getPortExtended(): # Forward note internal.sendCompleteInternalMidiMessage(command.getDataMIDI()) command.handle("Next chord set") elif command.type is eventconsts.TYPE_PAD: if command.coord_Y == 1 and command.coord_X < 8: if len(chord_sets[command.coord_X]): current_set = command.coord_X command.handle("Set chord set number") else: command.handle("Chord set doesn't exist") elif command.coord_Y == 0 and command.coord_X < 8: command.handle("Drum pads catch-all", True)
def processInit(command): """Called if the INIT_COMPLETE flag is set to false Args: command (ParsedEvent): event to process """ global current_set, chord_sets, INIT_COMPLETE, FORWARD_NOTES, bar_progresses_set # If command is a note if command.type is eventconsts.TYPE_NOTE and not command.value: chord_sets[current_set].append(command.note) command.ignore("Add note to list " + str(current_set)) elif command.id == eventconsts.PEDAL: if command.is_lift: command.handle("Pedal lift", True) else: current_set += 1 if current_set >= 8: current_set = 0 if not internal.getPortExtended(): # Forward note to other processor internal.sendCompleteInternalMidiMessage(command.getDataMIDI()) command.handle("Next chord set") elif command.type is eventconsts.TYPE_PAD: if command.is_lift: if command.coord_Y == 1 and command.coord_X < 8: current_set = command.coord_X command.handle("Set chord set number") elif command.coord_X == 7 and command.coord_Y == 0: non_empty = -1 for i in range(8): if len(chord_sets[i]): non_empty = i break if non_empty != -1: current_set = non_empty INIT_COMPLETE = True FORWARD_NOTES = False command.handle("Finish setup") else: command.handle("Couldn't finish setup - no notes added") elif command.coord_X == 6 and command.coord_Y == 0: bar_progresses_set = not bar_progresses_set command.handle("Toggle automatic set progression")