def OnPadPressed(self, control, event): idx = CONTROLS.PADS_64.index(control) if ui.getFocused(midi.widMixer): idx += 1 # do not include the master track (0) if self.controls.isButtonMutePressed: mixer.enableTrack(idx) elif self.controls.isButtonSelectPressed: mixer.selectTrack(idx) else: mixer.deselectAll() mixer.selectTrack(idx) elif ui.getFocused(midi.widChannelRack): if self.controls.isButtonMutePressed: channels.muteChannel(idx) elif self.controls.isButtonSelectPressed: channels.selectChannel(idx) else: channels.deselectAll() channels.selectChannel(idx) elif ui.getFocused(midi.widPlaylist): idx += 1 # TODO figure out why patternNumber starts at one instead of zero! if self.controls.isButtonMutePressed: pass else: patterns.jumpToPattern(idx) else: pass self.updateLEDs()
def OnMidiMsg(self, event): #print('senderId', event.senderId) if (event.midiId == midi.MIDI_CONTROLCHANGE): if (event.midiChan == 0): event.inEv = event.data2 if event.inEv >= 0x40: event.outEv = -(event.inEv - 0x40) else: event.outEv = event.inEv # knobs if event.data1 in [0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17]: r = utils.KnobAccelToRes2(event.outEv) #todo outev signof Res = r * (1 / (40 * 2.5)) self.SetKnobValue(event.data1 - 0x10, event.outEv, Res) event.handled = True else: event.handled = False # for extra CCs in emulators else: event.handled = False # for extra CCs in emulators elif event.midiId == midi.MIDI_PITCHBEND: # pitch bend (faders) if event.midiChan <= 8: event.inEv = event.data1 + (event.data2 << 7) event.outEv = (event.inEv << 16) // 16383 event.inEv -= 0x2000 if self.ColT[event.midiChan].SliderEventID >= 0: # slider (mixer track volume) event.handled = True mixer.automateEvent(self.ColT[event.midiChan].SliderEventID, self.AlphaTrack_SliderToLevel(event.inEv + 0x2000), midi.REC_MIDIController, self.SmoothSpeed) # hint n = mixer.getAutoSmoothEventValue(self.ColT[event.midiChan].SliderEventID) s = mixer.getEventIDValueString(self.ColT[event.midiChan].SliderEventID, n) if s != '': s = ': ' + s self.OnSendTempMsg(self.ColT[event.midiChan].SliderName + s, 500) elif (event.midiId == midi.MIDI_NOTEON) | (event.midiId == midi.MIDI_NOTEOFF): # NOTE if event.midiId == midi.MIDI_NOTEON: if (event.pmeFlags & midi.PME_FromScript != 0): if event.data1 == 0x7F: self.SetFirstTrack(event.data2) # slider hold if event.data1 in [0x68, 0x69, 0x70]: self.SliderHoldCount += -1 + (int(event.data2 > 0) * 2) if (event.pmeFlags & midi.PME_System != 0): if (event.data1 == 0x2E) | (event.data1 == 0x2F): # mixer bank if event.data2 > 0: self.SetFirstTrack(self.FirstTrackT[self.FirstTrack] - 8 + int(event.data1 == 0x2F) * 16) elif (event.data1 == 0x30) | (event.data1 == 0x31): if event.data2 > 0: self.SetFirstTrack(self.FirstTrackT[self.FirstTrack] - 1 + int(event.data1 == 0x31) * 2) elif event.data1 == 0x32: # self.Flip if event.data2 > 0: self.Flip = not self.Flip self.UpdateColT() self.UpdateLEDs() elif event.data1 in [0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27]: # knob reset if event.data2 > 0: n = event.data1 - 0x20 self.SetKnobValue(n, midi.MaxInt) if (event.pmeFlags & midi.PME_System_Safe != 0): if event.data1 == 0x47: # link selected channels to current mixer track if event.data2 > 0: if self.Shift: mixer.linkTrackToChannel(midi.ROUTE_StartingFromThis) else: mixer.linkTrackToChannel(midi.ROUTE_ToThis) elif (event.data1 >= 0x18) & (event.data1 <= 0x1F): # select mixer track if event.data2 > 0: i = event.data1 - 0x18 ui.showWindow(midi.widMixer) mixer.setTrackNumber(self.ColT[i].TrackNum, midi.curfxScrollToMakeVisible | midi.curfxMinimalLatencyUpdate) elif (event.data1 >= 0x8) & (event.data1 <= 0xF): # solo if event.data2 > 0: i = event.data1 - 0x8 self.ColT[i].solomode = midi.fxSoloModeWithDestTracks if self.Shift: Include(self.ColT[i].solomode, midi.fxSoloModeWithSourceTracks) mixer.soloTrack(self.ColT[i].TrackNum, midi.fxSoloToggle, self.ColT[i].solomode) mixer.setTrackNumber(self.ColT[i].TrackNum, midi.curfxScrollToMakeVisible) elif (event.data1 >= 0x10) & (event.data1 <= 0x17): # mute if event.data2 > 0: mixer.enableTrack(self.ColT[event.data1 - 0x10].TrackNum) elif (event.data1 >= 0x0) & (event.data1 <= 0x7): # arm if event.data2 > 0: mixer.armTrack(self.ColT[event.data1].TrackNum) if mixer.isTrackArmed(self.ColT[event.data1].TrackNum): self.OnSendTempMsg(mixer.getTrackName(self.ColT[event.data1].TrackNum) + ' recording to ' + mixer.getTrackRecordingFileName(self.ColT[event.data1].TrackNum), 2500) else: self.OnSendTempMsg(mixer.getTrackName(self.ColT[event.data1].TrackNum) + ' unarmed') event.handled = True else: event.handled = False else: event.handled = False
def OnMidiIn(self, event): #tbuttons if (event.data1 == playb): transport.start() #play self.UpdateLEDs() if (event.data1 == recb): transport.record() #record self.UpdateLEDs() if (event.data1 == stopb): transport.stop() #stop self.UpdateLEDs() if (event.data1 == loopb): transport.setLoopMode() #loop/pattern mode self.UpdateLEDs() if (event.data1 == metrob): # metronome/button transport.globalTransport(midi.FPT_Metronome, 110) self.UpdateLEDs() if (event.data1 == tempob): transport.stop() #tap tempo if (event.data1 == quantizeb): transport.globalTransport(midi.FPT_Snap, 48) #snap toggle if (event.data1 == squantizeb): ui.snapMode(1) #snap toggle if (event.data1 == srecb): transport.globalTransport(midi.FPT_CountDown, 115) #countdown before recordin #if (event.data1 == sstopb): # transport.globalTransport(midi.FPT_F12, 71) #clear all windows if (event.data1 == undob): general.undoUp() #undo if (event.data1 == sundob): general.undo() #redo if (event.data1 == squantizeb): transport.globalTransport(midi.FPT_SnapMode, 49, event.pmeFlags) #snap toggle self.UpdateLEDs() if (event.data1 == tempob): transport.globalTransport(midi.FPT_TapTempo, 106) #tap tempo #4D controller if (event.data1 == knobe): transport.globalTransport(midi.FPT_Enter, 80) #enter if (event.data1 == knobsp) & (event.data2 == right): #4d encoder spin right ui.jog(1) elif (event.data1 == knobsp) & (event.data2 == left): #4d encoder spin left ui.jog(-1) if (event.data1 == knoblr) & (event.data2 == right): #4d encoder push right transport.globalTransport(midi.FPT_Right, 1) elif (event.data1 == knoblr) & (event.data2 == left): #4d encoder push left transport.globalTransport(midi.FPT_Left, 1) if (event.data1 == knobud) & (event.data2 == up): #4d encoder push up transport.globalTransport(midi.FPT_Up, 1) elif (event.data1 == knobud) & (event.data2 == down): #4d encoder push down transport.globalTransport(midi.FPT_Down, 1) #8 volume knobs for mixer & channel rack, 8 tracks at a time volinc = .005 #volume increments paninc = .01 # pan increments if ui.getFocused(0) == 1: #mixer volume control if (event.data1 == muteb): mixer.enableTrack(mixer.trackNumber()) #mute if (event.data1 == solob): mixer.soloTrack(mixer.trackNumber()) #solo # VOLUME CONTROL #knob 1 if (event.data1 == knob1): if event.data2 == 127: mixer.setTrackVolume( mixer.trackNumber() + 0, mixer.getTrackVolume(mixer.trackNumber()) + 0 - volinc) # volume values go down elif event.data2 == 1: mixer.setTrackVolume( mixer.trackNumber() + 0, mixer.getTrackVolume(mixer.trackNumber()) + 0 + volinc) # volume values go up #knob 2 if (event.data1 == knob2): if event.data2 == 127: mixer.setTrackVolume( mixer.trackNumber() + 1, mixer.getTrackVolume(mixer.trackNumber() + 1) - volinc) # volume values go down elif event.data2 == 1: mixer.setTrackVolume( mixer.trackNumber() + 1, mixer.getTrackVolume(mixer.trackNumber() + 1) + volinc) # volume values go up #knob 3 if (event.data1 == knob3): if event.data2 == 127: mixer.setTrackVolume( mixer.trackNumber() + 2, mixer.getTrackVolume(mixer.trackNumber() + 2) - volinc) # volume values go down elif event.data2 == 1: mixer.setTrackVolume( mixer.trackNumber() + 2, mixer.getTrackVolume(mixer.trackNumber() + 2) + volinc) # volume values go up #knob 4 if (event.data1 == knob4): if event.data2 == 127: mixer.setTrackVolume( mixer.trackNumber() + 3, mixer.getTrackVolume(mixer.trackNumber() + 3) - volinc) # volume values go down elif event.data2 == 1: mixer.setTrackVolume( mixer.trackNumber() + 3, mixer.getTrackVolume(mixer.trackNumber() + 3) + volinc) # volume values go up #knob5 if (event.data1 == knob5): if event.data2 == 127: mixer.setTrackVolume( mixer.trackNumber() + 4, mixer.getTrackVolume(mixer.trackNumber() + 4) - volinc) # volume values go down elif event.data2 == 1: mixer.setTrackVolume( mixer.trackNumber() + 4, mixer.getTrackVolume(mixer.trackNumber() + 4) + volinc) # volume values go up #knob 6 if (event.data1 == knob6): if event.data2 == 127: mixer.setTrackVolume( mixer.trackNumber() + 5, mixer.getTrackVolume(mixer.trackNumber() + 5) - volinc) # volume values go down elif event.data2 == 1: mixer.setTrackVolume( mixer.trackNumber() + 5, mixer.getTrackVolume(mixer.trackNumber() + 5) + volinc) # volume values go up #knob 7 if (event.data1 == knob7): if event.data2 == 127: mixer.setTrackVolume( mixer.trackNumber() + 6, mixer.getTrackVolume(mixer.trackNumber() + 6) - volinc) # volume values go down elif event.data2 == 1: mixer.setTrackVolume( mixer.trackNumber() + 6, mixer.getTrackVolume(mixer.trackNumber() + 6) + volinc) # volume values go up #knob 8 if (event.data1 == knob8): if event.data2 == 127: mixer.setTrackVolume( mixer.trackNumber() + 7, mixer.getTrackVolume(mixer.trackNumber() + 7) - volinc) # volume values go down elif event.data2 == 1: mixer.setTrackVolume( mixer.trackNumber() + 7, mixer.getTrackVolume(mixer.trackNumber() + 7) + volinc) # volume values go up # PAN CONTROL #sknob 1 if (event.data1 == sknob1): if event.data2 == 127: mixer.setTrackPan(mixer.trackNumber() + 0, mixer.getTrackPan(mixer.trackNumber()) + 0 - paninc) # volume values go down elif event.data2 == 1: mixer.setTrackPan(mixer.trackNumber() + 0, mixer.getTrackPan(mixer.trackNumber()) + 0 + paninc) # volume values go up #sknob 2 if (event.data1 == sknob2): if event.data2 == 127: mixer.setTrackPan( mixer.trackNumber() + 1, mixer.getTrackPan(mixer.trackNumber() + 1) - paninc) # volume values go down elif event.data2 == 1: mixer.setTrackPan( mixer.trackNumber() + 1, mixer.getTrackPan(mixer.trackNumber() + 1) + paninc) # volume values go up #sknob 3 if (event.data1 == sknob3): if event.data2 == 127: mixer.setTrackPan( mixer.trackNumber() + 2, mixer.getTrackPan(mixer.trackNumber() + 2) - paninc) # volume values go down elif event.data2 == 1: mixer.setTrackPan( mixer.trackNumber() + 2, mixer.getTrackPan(mixer.trackNumber() + 2) + paninc) # volume values go up #sknob 4 if (event.data1 == sknob4): if event.data2 == 127: mixer.setTrackPan( mixer.trackNumber() + 3, mixer.getTrackPan(mixer.trackNumber() + 3) - paninc) # volume values go down elif event.data2 == 1: mixer.setTrackPan( mixer.trackNumber() + 3, mixer.getTrackPan(mixer.trackNumber() + 3) + paninc) # volume values go up #sknob5 if (event.data1 == sknob5): if event.data2 == 127: mixer.setTrackPan( mixer.trackNumber() + 4, mixer.getTrackPan(mixer.trackNumber() + 4) - paninc) # volume values go down elif event.data2 == 1: mixer.setTrackPan( mixer.trackNumber() + 4, mixer.getTrackPan(mixer.trackNumber() + 4) + paninc) # volume values go up #sknob 6 if (event.data1 == sknob6): if event.data2 == 127: mixer.setTrackPan( mixer.trackNumber() + 5, mixer.getTrackPan(mixer.trackNumber() + 5) - paninc) # volume values go down elif event.data2 == 1: mixer.setTrackPan( mixer.trackNumber() + 5, mixer.getTrackPan(mixer.trackNumber() + 5) + paninc) # volume values go up #sknob 7 if (event.data1 == sknob7): if event.data2 == 127: mixer.setTrackPan( mixer.trackNumber() + 6, mixer.getTrackPan(mixer.trackNumber() + 6) - paninc) # volume values go down elif event.data2 == 1: mixer.setTrackPan( mixer.trackNumber() + 6, mixer.getTrackPan(mixer.trackNumber() + 6) + paninc) # volume values go up #sknob 8 if (event.data1 == sknob8): if event.data2 == 127: mixer.setTrackPan( mixer.trackNumber() + 7, mixer.getTrackPan(mixer.trackNumber() + 7) - paninc) # volume values go down elif event.data2 == 1: mixer.setTrackPan( mixer.trackNumber() + 7, mixer.getTrackPan(mixer.trackNumber() + 7) + paninc) # volume values go up elif ui.getFocused(0) == 0: # channel rack if (event.data1 == muteb): channels.muteChannel(channels.channelNumber()) #mute if (event.data1 == solob): channels.soloChannel(channels.channelNumber()) #solo # VOLUME CONTROL #knob 1 if (event.data1 == knob1): if event.data2 == 127: channels.setChannelVolume( channels.channelNumber() + 0, channels.getChannelVolume(channels.channelNumber() + 0) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelVolume( channels.channelNumber() + 0, channels.getChannelVolume(channels.channelNumber() + 0) + volinc) # volume values go up #knob 2 if (event.data1 == knob2): if event.data2 == 127: channels.setChannelVolume( channels.channelNumber() + 1, channels.getChannelVolume(channels.channelNumber() + 1) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelVolume( channels.channelNumber() + 1, channels.getChannelVolume(channels.channelNumber() + 1) + volinc) # volume values go up #knob 3 if (event.data1 == knob3): if event.data2 == 127: channels.setChannelVolume( channels.channelNumber() + 2, channels.getChannelVolume(channels.channelNumber() + 2) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelVolume( channels.channelNumber() + 2, channels.getChannelVolume(channels.channelNumber() + 2) + volinc) # volume values go up #knob 4 if (event.data1 == knob4): if event.data2 == 127: channels.setChannelVolume( channels.channelNumber() + 3, channels.getChannelVolume(channels.channelNumber() + 3) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelVolume( channels.channelNumber() + 3, channels.getChannelVolume(channels.channelNumber() + 3) + volinc) # volume values go up #knob 5 if (event.data1 == knob5): if event.data2 == 127: channels.setChannelVolume( channels.channelNumber() + 4, channels.getChannelVolume(channels.channelNumber() + 4) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelVolume( channels.channelNumber() + 4, channels.getChannelVolume(channels.channelNumber() + 4) + volinc) # volume values go up #knob 6 if (event.data1 == knob6): if event.data2 == 127: channels.setChannelVolume( channels.channelNumber() + 5, channels.getChannelVolume(channels.channelNumber() + 5) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelVolume( channels.channelNumber() + 5, channels.getChannelVolume(channels.channelNumber() + 5) + volinc) # volume values go up #knob 7 if (event.data1 == knob7): if event.data2 == 127: channels.setChannelVolume( channels.channelNumber() + 6, channels.getChannelVolume(channels.channelNumber() + 6) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelVolume( channels.channelNumber() + 6, channels.getChannelVolume(channels.channelNumber() + 6) + volinc) # volume values go up #knob 8 if (event.data1 == knob8): if event.data2 == 127: channels.setChannelVolume( channels.channelNumber() + 7, channels.getChannelVolume(channels.channelNumber() + 7) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelVolume( channels.channelNumber() + 7, channels.getChannelVolume(channels.channelNumber() + 7) + volinc) # volume values go up # PAN CONTROL #sknob 1 if (event.data1 == sknob1): if event.data2 == 127: channels.setChannelPan( channels.channelNumber() + 0, channels.getChannelPan(channels.channelNumber() + 0) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelPan( channels.channelNumber() + 0, channels.getChannelPan(channels.channelNumber() + 0) + volinc) # volume values go up #sknob 2 if (event.data1 == sknob2): if event.data2 == 127: channels.setChannelPan( channels.channelNumber() + 1, channels.getChannelPan(channels.channelNumber() + 1) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelPan( channels.channelNumber() + 1, channels.getChannelPan(channels.channelNumber() + 1) + volinc) # volume values go up #sknob 3 if (event.data1 == sknob3): if event.data2 == 127: channels.setChannelPan( channels.channelNumber() + 2, channels.getChannelPan(channels.channelNumber() + 2) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelPan( channels.channelNumber() + 2, channels.getChannelPan(channels.channelNumber() + 2) + volinc) # volume values go up #sknob 4 if (event.data1 == sknob4): if event.data2 == 127: channels.setChannelPan( channels.channelNumber() + 3, channels.getChannelPan(channels.channelNumber() + 3) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelPan( channels.channelNumber() + 3, channels.getChannelPan(channels.channelNumber() + 3) + volinc) # volume values go up #sknob 5 if (event.data1 == sknob5): if event.data2 == 127: channels.setChannelPan( channels.channelNumber() + 4, channels.getChannelPan(channels.channelNumber() + 4) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelPan( channels.channelNumber() + 4, channels.getChannelPan(channels.channelNumber() + 4) + volinc) # volume values go up #sknob 6 if (event.data1 == sknob6): if event.data2 == 127: channels.setChannelPan( channels.channelNumber() + 5, channels.getChannelPan(channels.channelNumber() + 5) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelPan( channels.channelNumber() + 5, channels.getChannelPan(channels.channelNumber() + 5) + volinc) # volume values go up #sknob 7 if (event.data1 == sknob7): if event.data2 == 127: channels.setChannelPan( channels.channelNumber() + 6, channels.getChannelPan(channels.channelNumber() + 6) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelPan( channels.channelNumber() + 6, channels.getChannelPan(channels.channelNumber() + 6) + volinc) # volume values go up #sknob 8 if (event.data1 == sknob8): if event.data2 == 127: channels.setChannelPan( channels.channelNumber() + 7, channels.getChannelPan(channels.channelNumber() + 7) - volinc) # volume values go down elif event.data2 == 1: channels.setChannelPan( channels.channelNumber() + 7, channels.getChannelPan(channels.channelNumber() + 7) + volinc) # volume values go up
def OnMidiMsg(self, event): print("On Midi Msg") #print("CC: ", event.controlNum, " Value: ", event.controlVal, " Chan: ", event.midiChan) i = mixer.trackNumber() if (event.midiChan == self.CHN.KNOB): event.handled = False if event.controlNum == self.KNOB.VOL: sVol = self.scaleValue(event.controlVal, 127, 1) mixer.setTrackVolume(mixer.trackNumber(), sVol) event.handled = True if event.controlNum == self.KNOB.PAN: sPan = (self.scaleValue(event.controlVal, 127, 2) - 1) if (abs(sPan) < 0.008): sPan = 0 mixer.setTrackPan(mixer.trackNumber(), sPan) event.handled = True elif (event.midiChan == self.CHN.BTN): event.handled = False if (event.controlNum == self.BTN.PLAY) & (event.controlVal == 127): transport.start() event.handled = True if (event.controlNum == self.BTN.STOP) & (event.controlVal == 127): transport.stop() event.handled = True if (event.controlNum == self.BTN.RECORD) & (event.controlVal == 127): transport.record() event.handled = True if (event.controlNum == self.BTN.LOOP_MODE) & (event.controlVal == 127): transport.setLoopMode() event.handled = True if (event.controlNum == self.BTN.MUTE) & (event.controlVal == 127): mixer.enableTrack(i) event.handled = True if (event.controlNum == self.BTN.SOLO) & (event.controlVal == 127): mixer.soloTrack(i) event.handled = True if (event.controlNum == self.BTN.TRACK_ARM) & (event.controlVal == 127): mixer.armTrack(i) event.handled = True else: event.handled = False