示例#1
0
def OnMidiMsg(event):
    if event.midiId == midi.MIDI_CONTROLCHANGE:
        if event.data2 > 0:
            # 39 = play button
            if event.data1 == 39:
                transport.start()
                event.handled = True
            # 40 = stop button
            elif event.data1 == 40:
                transport.stop()
                event.handled = True
            # 38 = record button
            elif event.data1 == 38:
                transport.record()
                event.handled = True
            # 6 = metronome button
            elif event.data1 == 6:
                transport.globalTransport(midi.FPT_Metronome, 1, event.pmeFlags)
                event.handled = True
            # 10 = mixer button = show fl mixer
            elif event.data1 == 10:
                transport.globalTransport(midi.FPT_F9, 1, event.pmeFlags)
                event.handled = True
            # 9 = tape button = show fl playlist
            elif event.data1 == 9:
                transport.globalTransport(midi.FPT_F5, 1, event.pmeFlags)
                event.handled = True
            # 8 = drum button = show fl channel rack
            elif event.data1 == 8:
                transport.globalTransport(midi.FPT_F6, 1, event.pmeFlags)
                event.handled = True
示例#2
0
def chatter_callback(msg):
    if msg.angular.z == 0 and msg.linear.x == 0:
        transport.stop()
        print('Stopping')
        return

    if msg.linear.x > 0:
        transport.move_forward()
        print('Forward')
        return

    if msg.linear.x < 0:
        transport.move_reverse()
        print('Reverse')
        return

    if msg.angular.z > 0:
        transport.move_left()
        print('Left')
        return

    if msg.angular.z < 0:
        transport.move_right()
        print('Right')
        return
示例#3
0
 def togglePlay(self, note):
     print("isPlaying: " + str(transport.isPlaying()))
     if (transport.isPlaying() == 0):
         transport.start()
         print("Starting Playback")
     elif (transport.isPlaying() == 1):
         transport.stop()
         print("Stopping Playback")
示例#4
0
 def OnButtonPlayPressed(self, control, event):
     # stop if Shift button is pressed else pause
     if self.controls.isButtonShiftPressed:
         transport.stop()
     elif self.controls.isButtonSelectPressed:
         transport.globalTransport(FPT_AddMarker, event.pmeFlags)
     else:
         transport.start()
    def handle_stop_press(self, event, stop):
        """ Put stop press code here.
        """
        print(ui.getFocusedPluginName())
        transport.stop()
        self.output = "Transport: Stop"
        self.set_hint_message(self.output)
        print("Pressed stop button.")

        event.handled = True
示例#6
0
    def OnTransportsStop(self, event):
        if self._is_pressed(event):
            self._button_mode |= arturia_macros.STOP_BUTTON
            self._button_hold_action_committed = False
            debug.log('OnTransportsStop [down]', 'Dispatched', event=event)
            data1 = arturia_midi.INTER_SCRIPT_DATA1_BTN_DOWN_CMD
        else:
            debug.log('OnTransportsStop [up]', 'Dispatched', event=event)
            data1 = arturia_midi.INTER_SCRIPT_DATA1_BTN_UP_CMD
            self._button_mode &= ~arturia_macros.STOP_BUTTON
            if not self._button_hold_action_committed:
                self._controller.metronome().Reset()
                transport.stop()

        arturia_midi.dispatch_message_to_other_scripts(
            arturia_midi.INTER_SCRIPT_STATUS_BYTE, data1, event.controlNum)
示例#7
0
def main(args=None):
    if args is None:
        args = sys.argv

    rclpy.init(args)

    node = rclpy.create_node('rosdi_ws')

    sub = node.create_subscription(Twist, 'cmd_vel', chatter_callback,
                                   qos_profile_default)
    assert sub  # prevent unused warning

    transport.stop()
    print('rosdi_ws ready.')
    while rclpy.ok():
        rclpy.spin_once(node)
示例#8
0
    def OnMidiMsg(self, event):
        event.handled = False
        print("{:X} {:X} {:2X} {}".format(
            event.status, event.data1, event.data2,
            EventNameT[(event.status - 0x80) // 16] + ': ' +
            utils.GetNoteName(event.data1)))

        # Use midi.MIDI_NOTEON for note events.
        if event.midiId == midi.MIDI_CONTROLCHANGE:
            if event.data2 > 0:
                if event.data1 == Transport['Stop']:
                    transport.stop()
                    event.handled = True
                elif event.data1 == Transport['Start']:
                    transport.start()
                    event.handled = True
                elif event.data1 == Transport['Record']:
                    transport.record()
                    event.handled = True
                elif event.data1 == Transport['Loop']:
                    transport.setLoopMode()
                    event.handled = True

        #FL Window Stuff
        GlobalMIDIChannel = event.status // 16

        #Show Window
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad01']) and (event.data2
                                                                  == 0x7F):
            ui.showWindow(2)
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad02']) and (event.data2
                                                                  == 0x7F):
            ui.showWindow(1)
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad03']) and (event.data2
                                                                  == 0x7F):
            ui.showWindow(3)
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad04']) and (event.data2
                                                                  == 0x7F):
            ui.showWindow(0)

        #Hide Window
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad01']) and (event.data2
                                                                  == 0):
            ui.hideWindow(2)
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad02']) and (event.data2
                                                                  == 0):
            ui.hideWindow(1)
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad03']) and (event.data2
                                                                  == 0):
            ui.hideWindow(3)
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad04']) and (event.data2
                                                                  == 0):
            ui.hideWindow(0)

        #Navigation
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad06']) and (event.data2
                                                                  == 0x7F):
            ui.escape()
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad07']) and (event.data2
                                                                  == 0x7F):
            ui.up()
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad08']) and (event.data2
                                                                  == 0x7F):
            ui.enter()
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad14']) and (event.data2
                                                                  == 0x7F):
            ui.left()
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad15']) and (event.data2
                                                                  == 0x7F):
            ui.down()
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad16']) and (event.data2
                                                                  == 0x7F):
            ui.right()

        #Global Transport
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad09']) and (event.data2
                                                                  == 0x7F):
            transport.globalTransport(midi.FPT_Metronome, True)
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad10']) and (event.data2
                                                                  == 0x7F):
            transport.globalTransport(midi.FPT_Overdub, True)
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad11']) and (event.data2
                                                                  == 0x7F):
            transport.globalTransport(midi.FPT_CountDown, True)
        if (GlobalMIDIChannel == 0xB) and (event.data1
                                           == Pads['Pad12']) and (event.data2
                                                                  == 0x7F):
            transport.globalTransport(midi.FPT_TapTempo, True)
示例#9
0
    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 OnMidiIn(event):
    """ Wrapper for the OnMidiIn thread. """
    # Play button
    if event.data1 == nihia.buttons.get("PLAY"):
        event.handled = True
        transport.start()

    # Restart button
    elif event.data1 == nihia.buttons.get("RESTART"):
        event.handled = True
        transport.setLoopMode()

    # Record button
    elif event.data1 == nihia.buttons.get("REC"):
        event.handled = True
        transport.record()

    # Count-In button
    elif event.data1 == nihia.buttons.get("COUNT_IN"):
        event.handled = True

        # Defines the standard behaviour (just to toggle "Countdown before recording" on/off)
        if COUNT_IN_BEHAVIOUR == 0:
            transport.globalTransport(midi.FPT_CountDown, 1)

        # Defines behaviour of the button if the user chooses the Maschine-alike behaviour
        if COUNT_IN_BEHAVIOUR == 1:

            # Toggles recording on if it isn't enabled already
            if transport.isRecording() == 0:
                transport.record()

            # Toggles countdown before recording on if it isn't enabled already
            if ui.isPrecountEnabled() == 0:
                transport.globalTransport(midi.FPT_CountDown, 1)

            # Stops playback if FL Studio is playing
            if transport.isPlaying() == True:
                transport.stop()

            # Then turns playback on again. This time record and countdown before recording will be activated
            transport.start()

    # Stop button
    elif event.data1 == nihia.buttons.get("STOP"):
        event.handled = True
        transport.stop()

    # Clear button
    # This one in other DAWs (in Maschine, specifically) this button is meant to clear the MIDI clip you're
    # on so you can record again on it without having to use a mouse to delete all of the notes on the clip before
    # recording again
    #
    # However, since the MIDI API on FL Studio doesn't allow control over the piano roll specifically, for now it will only just
    # emulate the delete button (which does the same)
    elif event.data1 == nihia.buttons.get("CLEAR"):
        event.handled = True
        ui.delete()

    # Loop button (toggles loop recording on/off)
    elif event.data1 == nihia.buttons.get("LOOP"):
        event.handled = True
        transport.globalTransport(midi.FPT_LoopRecord, 1)

    # Metronome button
    elif event.data1 == nihia.buttons.get("METRO"):
        event.handled = True
        transport.globalTransport(midi.FPT_Metronome, 1)

    # Tempo button
    elif event.data1 == nihia.buttons.get("TEMPO"):
        event.handled = True
        transport.globalTransport(midi.FPT_TapTempo, 1)

    # Undo button
    elif event.data1 == nihia.buttons.get("UNDO"):
        event.handled = True
        general.undoUp()

    # Redo button
    elif event.data1 == nihia.buttons.get("REDO"):
        event.handled = True
        general.undo()

    # Quantize button
    # TODO: Not imlpemented yet in FL Studio MIDI API
    #
    # Instead, it changes between FL windows
    # TODO: The code is correctly written, but the ui.showWindow() method has a bug that causes the Piano roll and Browser windows not to
    # appear when invoked. It has been said it should be fixed in a future update.
    # -----------------------------------------------------------------------------------------------------------------------------------
    # if event.data1 == nihia.buttons.get("QUANTIZE"):
    #     global window
    #     window += 1

    #     if window <= 4:
    #         ui.showWindow(window)
    #         print("if reached")
    #     elif window > 4:
    #         window = 0
    #         ui.showWindow(window)
    # -----------------------------------------------------------------------------------------------------------------------------------
    #
    # Alternative implementation: Emulate the Fn buttons
    elif event.data1 == nihia.buttons.get("QUANTIZE"):
        event.handled = True
        global window2
        window2 += 1

        # Normal behaviour if the action ID is between the desired range
        if window2 <= 68 and window2 != 67:
            transport.globalTransport(window2, 1)

        # Skips the 67 value which calls the full screen plugin picker and calls the mixer instead
        elif window2 == 67:
            window2 += 1
            transport.globalTransport(window2, 1)

        # Once window value is out of range, it sets it again to the first value in range
        elif window2 > 68:
            window2 = 64
            transport.globalTransport(window2, 1)

    # Automation button
    # Enables and disables the recording automation events
    # TODO: Not implemented yet in FL Studio MIDI API
    #
    # Instead, it shows the full-screen plugin browser
    elif event.data1 == nihia.buttons.get("AUTO"):
        event.handled = True
        transport.globalTransport(midi.FPT_F8, 1)

    # Mute button - A-Series
    elif event.data1 == nihia.buttons.get("MUTE_SELECTED"):
        event.handled = True
        mixer.muteTrack(mixer.trackNumber())

    # Solo button - A-Series
    elif event.data1 == nihia.buttons.get("SOLO_SELECTED"):
        event.handled = True
        mixer.soloTrack(mixer.trackNumber())

    # Mute button - S-Series
    elif event.data1 == nihia.buttons.get("MUTE"):
        event.handled = True
        mixerMuteSoloHandler("MUTE", event.data2, mixer.trackNumber())

    # Solo button - S-Series
    elif event.data1 == nihia.buttons.get("SOLO"):
        event.handled = True
        mixerMuteSoloHandler("SOLO", event.data2, mixer.trackNumber())

    # 4D Encoder +
    elif event.data1 == nihia.buttons.get(
            "ENCODER_GENERAL") and event.data2 == nihia.buttons.get("PLUS"):
        event.handled = True

        # Mixer navigation (right)
        if ui.getFocused(midi.widMixer) == True:
            ui.right()

        # Playback jogging
        elif (ui.getFocused(midi.widPianoRoll) == True) or (ui.getFocused(
                midi.widPlaylist) == True):
            transport.setSongPos(
                transport.getSongPos(midi.SONGLENGTH_S) + 1, midi.SONGLENGTH_S)

        # General navigation
        else:
            ui.down()

    # 4D Encoder -
    elif event.data1 == nihia.buttons.get(
            "ENCODER_GENERAL") and event.data2 == nihia.buttons.get("MINUS"):
        event.handled = True

        # Mixer navigation
        if ui.getFocused(midi.widMixer) == True:
            ui.left()

        elif (ui.getFocused(midi.widPianoRoll) == True) or (ui.getFocused(
                midi.widPlaylist) == True):
            transport.setSongPos(
                transport.getSongPos(midi.SONGLENGTH_S) - 1, midi.SONGLENGTH_S)

        # General navigation
        else:
            ui.up()

    # 4D Encoder + (selected track volume)
    elif event.data1 == nihia.buttons.get(
            "ENCODER_VOLUME_SELECTED") and event.data2 == nihia.buttons.get(
                "PLUS"):
        event.handled = True
        mixer.setTrackVolume(mixer.trackNumber(),
                             mixer.getTrackVolume(mixer.trackNumber()) + 0.01)

    # 4D Encoder - (selected track volume)
    elif event.data1 == nihia.buttons.get(
            "ENCODER_VOLUME_SELECTED") and event.data2 == nihia.buttons.get(
                "MINUS"):
        event.handled = True
        mixer.setTrackVolume(mixer.trackNumber(),
                             mixer.getTrackVolume(mixer.trackNumber()) - 0.01)

    # 4D Encoder + (selected track pan)
    elif event.data1 == nihia.buttons.get(
            "ENCODER_PAN_SELECTED") and event.data2 == nihia.buttons.get(
                "PLUS"):
        event.handled = True
        mixer.setTrackPan(mixer.trackNumber(),
                          mixer.getTrackPan(mixer.trackNumber()) + 0.01)

    # 4D Encoder + (selected track pan)
    elif event.data1 == nihia.buttons.get(
            "ENCODER_PAN_SELECTED") and event.data2 == nihia.buttons.get(
                "MINUS"):
        event.handled = True
        mixer.setTrackPan(mixer.trackNumber(),
                          mixer.getTrackPan(mixer.trackNumber()) - 0.01)

    # 4D Encoder up
    elif event.data1 == encoderHandler(
            "Y") and event.data2 == nihia.buttons.get("UP"):
        event.handled = True
        ui.up()

    # 4D Encoder down
    elif event.data1 == encoderHandler(
            "Y") and event.data2 == nihia.buttons.get("DOWN"):
        event.handled = True
        ui.down()

    # 4D Encoder (using FPT because ui.left doesn't work on the playlist)
    elif event.data1 == encoderHandler(
            "X") and event.data2 == nihia.buttons.get("LEFT"):
        event.handled = True
        if ui.getFocused(midi.widMixer) == True:
            # This one doesn't move the mixer view as you get to the border
            # ----------------------------------------------------
            # mixer.setTrackNumber(mixer.trackNumber() - 1)
            # ----------------------------------------------------
            ui.left()

        else:
            ui.left()

    # 4D Encoder (using FPT because ui.right doesn't work on the playlist)
    elif event.data1 == encoderHandler(
            "X") and event.data2 == nihia.buttons.get("RIGHT"):
        event.handled = True
        if ui.getFocused(midi.widMixer) == True:
            # This one doesn't move the mixer view as you get to the border
            # ----------------------------------------------------
            # mixer.setTrackNumber(mixer.trackNumber() + 1)
            # ----------------------------------------------------
            ui.right()

        else:
            ui.right()

    # 4D Encoder button
    elif event.data1 == nihia.buttons.get("ENCODER_BUTTON"):
        event.handled = True
        ui.enter()

    # 4D Encoder button (shifted)
    elif event.data1 == nihia.buttons.get("ENCODER_BUTTON_SHIFTED"):
        event.handled = True
        transport.globalTransport(midi.FPT_Menu, 1)

    # Knobs
    # Normal knobs - increase values
    elif event.data1 == nihia.knobs.get(
            "KNOB_1A") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(0, "VOLUME", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_2A") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(1, "VOLUME", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_3A") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(2, "VOLUME", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_4A") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(3, "VOLUME", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_5A") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(4, "VOLUME", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_6A") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(5, "VOLUME", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_7A") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        # Handles track group 15 exception
        if math.trunc(1 / 8 * mixer.trackNumber()) == 15:
            return
        else:
            adjustMixer(6, "VOLUME", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_8A") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        # Handles track group 15 exception
        if math.trunc(1 / 8 * mixer.trackNumber()) == 15:
            return
        else:
            adjustMixer(7, "VOLUME", "INCREASE", mixer.trackNumber())

    # Normal knobs - decrease values
    elif event.data1 == nihia.knobs.get(
            "KNOB_1A") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(0, "VOLUME", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_2A") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(1, "VOLUME", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_3A") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(2, "VOLUME", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_4A") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(3, "VOLUME", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_5A") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(4, "VOLUME", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_6A") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(5, "VOLUME", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_7A") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        # Handles track group 15 exception
        if math.trunc(1 / 8 * mixer.trackNumber()) == 15:
            return
        else:
            adjustMixer(6, "VOLUME", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_8A") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        # Handles track group 15 exception
        if math.trunc(1 / 8 * mixer.trackNumber()) == 15:
            return
        else:
            adjustMixer(7, "VOLUME", "DECREASE", mixer.trackNumber())

    # Shifted knobs - increase values
    elif event.data1 == nihia.knobs.get(
            "KNOB_1B") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(0, "PAN", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_2B") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(1, "PAN", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_3B") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(2, "PAN", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_4B") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(3, "PAN", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_5B") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(4, "PAN", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_6B") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        adjustMixer(5, "PAN", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_7B") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        # Handles track group 15 exception
        if math.trunc(1 / 8 * mixer.trackNumber()) == 15:
            return
        else:
            adjustMixer(6, "PAN", "INCREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_8B") and event.data2 == nihia.knobs.get("INCREASE"):
        event.handled = True
        # Handles track group 15 exception
        if math.trunc(1 / 8 * mixer.trackNumber()) == 15:
            return
        else:
            adjustMixer(7, "PAN", "INCREASE", mixer.trackNumber())

    # Shifted knobs - decrease values
    elif event.data1 == nihia.knobs.get(
            "KNOB_1B") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(0, "PAN", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_2B") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(1, "PAN", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_3B") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(2, "PAN", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_4B") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(3, "PAN", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_5B") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(4, "PAN", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_6B") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        adjustMixer(5, "PAN", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_7B") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        # Handles track group 15 exception
        if math.trunc(1 / 8 * mixer.trackNumber()) == 15:
            return
        else:
            adjustMixer(6, "PAN", "DECREASE", mixer.trackNumber())

    elif event.data1 == nihia.knobs.get(
            "KNOB_8B") and event.data2 == nihia.knobs.get("DECREASE"):
        event.handled = True
        # Handles track group 15 exception
        if math.trunc(1 / 8 * mixer.trackNumber()) == 15:
            return
        else:
            adjustMixer(7, "PAN", "DECREASE", mixer.trackNumber())
 def OnTransportsStop(self, event):
     debug.log('OnTransportsStop', 'Dispatched', event=event)
     self._controller.metronome().Reset()
     transport.stop()
    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
示例#13
0
    def OnMidiMsg(self, event):
        event.handled = False

        # FOR PRINTING DATA ON SCRIPT OUTPUT

        print("status: {}, port: {}, midiId: {}, data1: {}, data2: {}".format(
            event.status, event.port, event.midiId, event.data1, event.data2))

        # CONTROL CHANGE EVENT FOR BUTTONS OF MIDI
        if event.midiId == midi.MIDI_CONTROLCHANGE:
            if event.data2 > 0:

                if event.data1 == Play:
                    print('Playback')
                    transport.start()
                    ui.setHintMsg("Play/Pause")
                    event.handled = True
                elif event.data1 == Record:
                    print('Record')
                    transport.record()
                    ui.setHintMsg("Record")
                    event.handled = True
                elif event.data1 == Stop:
                    print('Stop')
                    transport.stop()
                    ui.setHintMsg("Stop")
                    event.handled = True
                elif event.data1 == ToggleLoop:
                    print('Toggle Loop')
                    transport.setLoopMode()
                    ui.setHintMsg("Pattern/Song")
                    event.handled = True

                elif event.data1 == Left:
                    print('Previous Tab')
                    transport.globalTransport(midi.FPT_WindowJog, -1)
                    ui.setHintMsg("Previous Tab")
                    event.handled = True
                elif event.data1 == Right:
                    print('Next Tab')
                    transport.globalTransport(midi.FPT_WindowJog, 1)
                    ui.setHintMsg("Next Tab")
                    event.handled = True

                elif event.data1 == Up:
                    print('Undo Up')
                    general.undoUp()
                    ui.setHintMsg("Undo Up")
                    event.handled = True
                elif event.data1 == Down:
                    print('Undo Down/ReDo')
                    general.restoreUndo()
                    ui.setHintMsg("Undo Down/ReDo")
                    event.handled = True

                elif event.data1 in Knobs:
                    mixer.setTrackVolume(
                        mixer.trackNumber() + Knobs.index(event.data1),
                        event.data2 / 127)
                    event.handled = True

        #MIDI NOTE ON/OFF FOR NOTE EVENTS
        elif event.midiId == midi.MIDI_NOTEON:
            if (event.pmeFlags & midi.PME_System != 0):

                if event.data1 == Playlist:
                    print('Playlist')
                    transport.globalTransport(midi.FPT_F5, 1)
                    ui.setHintMsg("Playlist")
                    event.handled = True
                elif event.data1 == ChannelRack:
                    print('ChannelRack')
                    transport.globalTransport(midi.FPT_F6, 1)
                    ui.setHintMsg("ChannelRack")
                    event.handled = True
                elif event.data1 == PianoRoll:
                    print('PianoRoll')
                    transport.globalTransport(midi.FPT_F7, 1)
                    ui.setHintMsg("PianoRoll")
                    event.handled = True
                elif event.data1 == Mixer:
                    print('Mixer')
                    transport.globalTransport(midi.FPT_F9, 1)
                    ui.setHintMsg("Mixer")
                    event.handled = True

                elif event.data1 == Previous:
                    print('Previous')
                    ui.previous()
                    ui.setHintMsg("Previous")
                    event.handled = True
                elif event.data1 == Next:
                    print('Next')
                    ui.next()
                    ui.setHintMsg("Next")
                    event.handled = True

                elif event.data1 == Mute:
                    print('Mute')
                    channels.muteChannel(channels.channelNumber())
                    ui.setHintMsg("Mute")
                    event.handled = True
                elif event.data1 == Solo:
                    print('Solo')
                    channels.soloChannel(channels.channelNumber())
                    ui.setHintMsg("Solo")
                    event.handled = True

                elif event.data1 == PatternUp:
                    print('Pattern Up')
                    transport.globalTransport(midi.FPT_PatternJog, -1)
                    ui.setHintMsg("Pattern Up")
                    event.handled = True
                elif event.data1 == PatternDown:
                    print('Pattern Down')
                    transport.globalTransport(midi.FPT_PatternJog, 1)
                    ui.setHintMsg("Pattern Down")
                    event.handled = True

                elif event.data1 == Overdub:
                    print('Overdub')
                    transport.globalTransport(midi.FPT_Overdub, 1)
                    ui.setHintMsg("Overdub")
                    event.handled = True
                elif event.data1 == LoopRecord:
                    print('Loop Record')
                    transport.globalTransport(midi.FPT_LoopRecord, 1)
                    ui.setHintMsg("Loop Record")
                    event.handled = True

                elif event.data1 == SnapUp:
                    print('Snap -1')
                    transport.globalTransport(midi.FPT_SnapMode, -1)
                    ui.setHintMsg("Snap -1")
                    event.handled = True
                elif event.data1 == SnapDown:
                    print('Snap +1')
                    transport.globalTransport(midi.FPT_SnapMode, 1)
                    ui.setHintMsg("Snap +1")
                    event.handled = True

                elif event.data1 == TapTempo:
                    print('Tap Tempo')
                    transport.globalTransport(midi.FPT_TapTempo, 1)
                    ui.setHintMsg("Tap Tempo")
                    event.handled = True
                elif event.data1 == Metro:
                    print('Metronome')
                    transport.globalTransport(midi.FPT_Metronome, 1)
                    ui.setHintMsg("Metronome")
                    event.handled = True
def process(command):

    command.actions.addProcessor("Default Processor")

    #---------------------------------
    # Transport functions
    #---------------------------------
    if command.type == eventconsts.TYPE_TRANSPORT:
        # Play-pause: only on lift
        if command.id == eventconsts.TRANSPORT_PLAY and command.is_lift:
            transport.start()
            command.actions.appendAction("Play/Pause Transport")
            command.handled = True

        # Stop: only on lift
        if command.id == eventconsts.TRANSPORT_STOP and command.is_lift:
            transport.stop()
            command.actions.appendAction("Stop Transport")
            command.handled = True

        # Loop: only on lift
        if command.id == eventconsts.TRANSPORT_LOOP and command.is_lift:
            transport.setLoopMode()
            command.actions.appendAction("Toggle Loop Mode")
            command.handled = True

        # Record: only on lift
        if command.id == eventconsts.TRANSPORT_RECORD and command.is_lift:
            transport.record()
            command.actions.appendAction("Toggle Recording")
            command.handled = True

        # Skip forward: start on press, stop on lift, faster on double press?
        if command.id == eventconsts.TRANSPORT_FORWARD:
            speed = 1
            command.actions.appendAction("Fast Forward")
            if command.is_double_click:
                speed = 2
                command.actions.appendAction("[2x Speed]")

            if command.is_lift is False:
                transport.continuousMove(speed, 2)
            if command.is_lift is True:
                transport.continuousMove(speed, 0)
                command.actions.appendAction("Stopped")
            command.handled = True

        # Skip back: start on press, stop on lift, faster on double press?
        if command.id == eventconsts.TRANSPORT_BACK:
            speed = -1
            command.actions.appendAction("Rewind")
            if command.is_double_click:
                speed = -2
                command.actions.appendAction("[2x Speed]")

            if command.is_lift is False:
                transport.continuousMove(speed, 2)
            if command.is_lift is True:
                transport.continuousMove(speed, 0)
                command.actions.appendAction("Stopped")
            command.handled = True

        # Next Track: next UI element
        if command.id == eventconsts.TRANSPORT_TRACK_NEXT and command.is_lift:
            ui.next()
            command.actions.appendAction("Next UI Element")
            command.handled = True

        # Prev Track: prev UI element
        if command.id == eventconsts.TRANSPORT_TRACK_PREVIOUS and command.is_lift:
            ui.previous()
            command.actions.appendAction("Previous UI Element")
            command.handled = True
示例#15
0
    def OnMidiIn(self, event):

        print("Output from M32: data 1 =", event.data1, ", data 2 =",
              event.data2, ", handled ", event.handled)
        u = 0
        #tbuttons
        if (event.data1 == playb):
            transport.start()  #play

        if (event.data1 == recb):
            transport.record()  #record

        if (event.data1 == stopb):
            transport.stop()  #stop

        if (event.data1 == loopb):
            transport.setLoopMode()  #loop/pattern mode

        if (event.data1 == metrob):  # metronome/button self.Clicking
            transport.globalTransport(midi.FPT_Metronome, 110)

        if (event.data1 == tempob):
            transport.stop()  #tap tempo

        if (event.data1 == quantizeb):
            transport.globalTransport(midi.FPT_Snap, 48)  #snap toggle

        if (event.data1 == squantizeb):
            transport.globalTransport(midi.FPT_Snap, 48)  #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 == 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

        if (event.data1 == tempob):
            transport.globalTransport(midi.FPT_TapTempo, 106)  #tap tempo

        #knobs
        if (event.data1 == knobe):
            transport.globalTransport(midi.FPT_Enter, 80)  #enter

        if (event.data1 == knobsp) & (event.data2
                                      == right):  #4d encoder spin right
            transport.globalTransport(midi.FPT_Jog, 1)

        elif (event.data1 == knobsp) & (event.data2
                                        == left):  #4d encoder spin left
            transport.globalTransport(midi.FPT_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)
示例#16
0
    def OnMidiIn(self, event):
        # print ("Event: {:X} {:X} {:2X} {} {:2X}".format(event.status, event.data1, event.data2,  EventNameT[(event.status - 0x80) // 16] + ': '+  utils.GetNoteName(event.data1), int(hex(event.data2), 16)))

        # Create output string
        output = ""

        event.handled = False
        global loopDown
        global loopInterrupt

        # Set has snapped flag
        hasSnapped = False

        # Process Long Presses:

        # Stop Button
        if (event.status is 0xB0 and event.data1 is 0x2E):
            global stop_PressTime
            global stop_LiftTime

            # Press - Start timer
            if event.data2 is 0x7F:
                stop_PressTime = time.perf_counter()
            # Lift - Stop timer
            elif event.data2 is 0x00:
                stop_LiftTime = time.perf_counter()
                if (stop_LiftTime - stop_PressTime) >= LONG_PRESS_TIME:
                    ui.escape()
                    output += "UI: Escape"
                    event.handled = True

        if event.handled is True:
            handleOutput(output)
            return

        # In popup
        if ui.isInPopupMenu() is 1 and loopDown is False:
            output += "[In popup menu] "
            # Currently this is always inactive?

        if event.handled is True:
            handleOutput(output)
            return

        # In Playlist
        if ui.getFocused(2) is 1 and loopDown is False:

            # Forward Button
            if (event.status is 0xB0 and event.data1 is 0x30):
                # Press - No action if markers exist
                if event.data2 is 0x7F and arrangement.getMarkerName(
                        0) is not "":
                    event.handled = True
                # Lift - Skip to next marker, only if markers exist
                elif event.data2 is 0x00 and arrangement.getMarkerName(
                        0) is not "":
                    transport.markerJumpJog(1)
                    output += "Transport: Jump to next marker"
                    event.handled = True

            # Back Button
            if (event.status is 0xB0 and event.data1 is 0x2F):
                # Press - No action if markers exist
                if event.data2 is 0x7F and arrangement.getMarkerName(
                        0) is not "":
                    event.handled = True
                # Lift - Skip to previous marker, only if markers exist
                elif event.data2 is 0x00 and arrangement.getMarkerName(
                        0) is not "":
                    transport.markerJumpJog(-1)
                    output += "Transport: Jump to previous marker"
                    event.handled = True

        if event.handled is True:
            handleOutput(output)
            return

        # In Mixer
        if ui.getFocused(0) is 1 and loopDown is False:
            selectedTrack = mixer.trackNumber()

            # Record Button
            if (event.status is 0xB0 and event.data1 is 0x2C):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Toggle track arm
                elif event.data2 is 0x00:
                    mixer.armTrack(selectedTrack)
                    if mixer.isTrackArmed(selectedTrack) is 1:
                        output += "Mixer: Armed track: " + getMixerTrackName(
                            selectedTrack)
                    else:
                        output += "Mixer: Disarmed track: " + getMixerTrackName(
                            selectedTrack)
                    event.handled = True

            # Forward Button
            if (event.status is 0xB0 and event.data1 is 0x30):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Next track
                elif event.data2 is 0x00:
                    ui.next()
                    output += "Mixer: Selected next track: " + getMixerTrackName(
                        selectedTrack + 1)

                    event.handled = True

            # Back Button
            if (event.status is 0xB0 and event.data1 is 0x2F):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Previous track
                elif event.data2 is 0x00:
                    ui.previous()
                    output += "Mixer: Selected previous track: " + getMixerTrackName(
                        selectedTrack - 1)

                    event.handled = True

            # Fader, knob and buttons #9 act on the selected track

            # Upper button 9
            if (event.status is 0xB0 and
                (event.data1 is 0x1F or event.data1 is 0x4B
                 or event.data1 is 0x73)) or (event.status is 0xB8
                                              and event.data1 is 0x10):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Solo track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or event.status is 0xB8:
                    output += mixerToggleSolo(selectedTrack)
                    event.handled = True

            # Lower button 9
            if (event.status is 0xB0 and
                (event.data1 is 0x29 or event.data1 is 0x54
                 or event.data1 is 0x7C)) or (event.status is 0xB8
                                              and event.data1 is 0x11):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Mute track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or event.status is 0xB8:
                    output += mixerToggleMute(selectedTrack)
                    event.handled = True

            # Fader 9 - Selected volume
            if (event.status is 0xB0 and
                (event.data1 is 0x0D or event.data1 is 0x38
                 or event.data1 is 0x5D)) or (event.status is 0xB8
                                              and event.data1 is 0x07):
                output += mixerAdjustFader(selectedTrack, event.data2)
                event.handled = True

            # Knob 9 - Selected pan
            if (event.status is 0xB0 and
                (event.data1 is 0x16 or event.data1 is 0x42
                 or event.data1 is 0x6A)) or (event.status is 0xB8
                                              and event.data1 is 0x0A):
                output += mixerAdjustPan(selectedTrack, event.data2)
                event.handled = True

            # Faders, knobs and buttons #1-8 act on tracks 1-8 respectively

            # Upper button 1
            if (event.status is 0xB0 and
                (event.data1 is 0x17 or event.data1 is 0x43
                 or event.data1 is 0x6B)) or (event.status is 0xB0
                                              and event.data1 is 0x10):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Solo track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB0
                                           and event.data1 is 0x10
                                           and event.data2 is 0x7F):
                    output += mixerToggleSolo(1)
                    event.handled = True

            # Lower button 1
            if (event.status is 0xB0 and
                (event.data1 is 0x21 or event.data1 is 0x4C
                 or event.data1 is 0x74)) or (event.status is 0xB0
                                              and event.data1 is 0x11):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Mute track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB0
                                           and event.data1 is 0x11
                                           and event.data2 is 0x7F):
                    output += mixerToggleMute(1)
                    event.handled = True

            # Upper button 2
            if (event.status is 0xB0 and
                (event.data1 is 0x18 or event.data1 is 0x44
                 or event.data1 is 0x6C)) or (event.status is 0xB1
                                              and event.data1 is 0x10):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Solo track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB1
                                           and event.data1 is 0x10):
                    output += mixerToggleSolo(2)
                    event.handled = True

            # Lower button 2
            if (event.status is 0xB0 and
                (event.data1 is 0x22 or event.data1 is 0x4D
                 or event.data1 is 0x75)) or (event.status is 0xB1
                                              and event.data1 is 0x11):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Mute track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB2
                                           and event.data1 is 0x11):
                    output += mixerToggleMute(2)
                    event.handled = True

            # Upper button 3
            if (event.status is 0xB0 and
                (event.data1 is 0x19 or event.data1 is 0x45
                 or event.data1 is 0x6D)) or (event.status is 0xB2
                                              and event.data1 is 0x10):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Solo track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB2
                                           and event.data1 is 0x10):
                    output += mixerToggleSolo(3)
                    event.handled = True

            # Lower button 3
            if (event.status is 0xB0 and
                (event.data1 is 0x23 or event.data1 is 0x4E
                 or event.data1 is 0x76)) or (event.status is 0xB2
                                              and event.data1 is 0x11):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Mute track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB2
                                           and event.data1 is 0x11):
                    output += mixerToggleMute(3)
                    event.handled = True

            # Upper button 4
            if (event.status is 0xB0 and
                (event.data1 is 0x1A or event.data1 is 0x46
                 or event.data1 is 0x6E)) or (event.status is 0xB3
                                              and event.data1 is 0x10):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Solo track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB3
                                           and event.data1 is 0x10):
                    output += mixerToggleSolo(4)
                    event.handled = True

            # Lower button 4
            if (event.status is 0xB0 and
                (event.data1 is 0x24 or event.data1 is 0x4F
                 or event.data1 is 0x77)) or (event.status is 0xB3
                                              and event.data1 is 0x11):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Mute track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB3
                                           and event.data1 is 0x11):
                    output += mixerToggleMute(4)
                    event.handled = True

            # Upper button 5
            if (event.status is 0xB0 and
                (event.data1 is 0x1B or event.data1 is 0x47
                 or event.data1 is 0x6F)) or (event.status is 0xB4
                                              and event.data1 is 0x10):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Solo track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB4
                                           and event.data1 is 0x10):
                    output += mixerToggleSolo(5)
                    event.handled = True

            # Lower button 5
            if (event.status is 0xB0 and
                (event.data1 is 0x25 or event.data1 is 0x50
                 or event.data1 is 0x78)) or (event.status is 0xB4
                                              and event.data1 is 0x11):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Mute track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB4
                                           and event.data1 is 0x11):
                    output += mixerToggleMute(5)
                    event.handled = True

            # Upper button 6
            if (event.status is 0xB0 and
                (event.data1 is 0x1C or event.data1 is 0x48
                 or event.data1 is 0x70)) or (event.status is 0xB5
                                              and event.data1 is 0x10):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Solo track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB5
                                           and event.data1 is 0x10):
                    output += mixerToggleSolo(6)
                    event.handled = True

            # Lower button 6
            if (event.status is 0xB0 and
                (event.data1 is 0x26 or event.data1 is 0x51
                 or event.data1 is 0x79)) or (event.status is 0xB5
                                              and event.data1 is 0x11):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Mute track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB5
                                           and event.data1 is 0x11):
                    output += mixerToggleMute(6)
                    event.handled = True

            # Upper button 7
            if (event.status is 0xB0 and
                (event.data1 is 0x1D or event.data1 is 0x49
                 or event.data1 is 0x71)) or (event.status is 0xB6
                                              and event.data1 is 0x10):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Solo track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB6
                                           and event.data1 is 0x10):
                    output += mixerToggleSolo(7)
                    event.handled = True

            # Lower button 7
            if (event.status is 0xB0 and
                (event.data1 is 0x27 or event.data1 is 0x52
                 or event.data1 is 0x7A)) or (event.status is 0xB6
                                              and event.data1 is 0x11):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Mute track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB6
                                           and event.data1 is 0x11):
                    output += mixerToggleMute(7)
                    event.handled = True

            # Upper button 8
            if (event.status is 0xB0 and
                (event.data1 is 0x1E or event.data1 is 0x4A
                 or event.data1 is 0x72)) or (event.status is 0xB7
                                              and event.data1 is 0x10):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Solo track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB7
                                           and event.data1 is 0x10):
                    output += mixerToggleSolo(8)
                    event.handled = True

            # Lower button 8
            if (event.status is 0xB0 and
                (event.data1 is 0x28 or event.data1 is 0x53
                 or event.data1 is 0x7B)) or (event.status is 0xB7
                                              and event.data1 is 0x11):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Mute track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or (event.status is 0xB7
                                           and event.data1 is 0x11):
                    output += mixerToggleMute(8)
                    event.handled = True

            # Fader 1 - Track 1 volume
            if event.status is 0xB0 and (event.data1 is 0x02
                                         or event.data1 is 0x2A
                                         or event.data1 is 0x55
                                         or event.data1 is 0x07):
                output += mixerAdjustFader(1, event.data2)
                event.handled = True

            # Knob 1 - Track 1 pan
            if event.status is 0xB0 and (event.data1 is 0x0E
                                         or event.data1 is 0x39
                                         or event.data1 is 0x5E
                                         or event.data1 is 0x0A):
                output += mixerAdjustPan(1, event.data2)
                event.handled = True

            # Fader 2 - Track 2 volume
            if (event.status is 0xB0 and
                (event.data1 is 0x03 or event.data1 is 0x2B
                 or event.data1 is 0x56)) or (event.status is 0xB1
                                              and event.data1 is 0x07):
                output += mixerAdjustFader(2, event.data2)
                event.handled = True

            # Knob 2 - Track 2 pan
            if (event.status is 0xB0 and
                (event.data1 is 0x0F or event.data1 is 0x3A
                 or event.data1 is 0x5F)) or (event.status is 0xB1
                                              and event.data1 is 0x0A):
                output += mixerAdjustPan(2, event.data2)
                event.handled = True

            # Fader 3 - Track 3 volume
            if (event.status is 0xB0 and
                (event.data1 is 0x04 or event.data1 is 0x32
                 or event.data1 is 0x57)) or (event.status is 0xB2
                                              and event.data1 is 0x07):
                output += mixerAdjustFader(3, event.data2)
                event.handled = True

            # Knob 3 - Track 3 pan
            if ((event.status is 0xB0 and
                 (event.data1 is 0x10 or event.data1 is 0x3B
                  or event.data1 is 0x60)) or
                (event.status is 0xB2
                 and event.data1 is 0x0A)) and event.handled is False:
                output += mixerAdjustPan(3, event.data2)
                event.handled = True

            # Fader 4 - Track 4 volume
            if (event.status is 0xB0 and
                (event.data1 is 0x05 or event.data1 is 0x33
                 or event.data1 is 0x58)) or (event.status is 0xB3
                                              and event.data1 is 0x07):
                output += mixerAdjustFader(4, event.data2)
                event.handled = True

            # Knob 4 - Track 4 pan
            if ((event.status is 0xB0 and
                 (event.data1 is 0x11 or event.data1 is 0x3C
                  or event.data1 is 0x61)) or
                (event.status is 0xB3
                 and event.data1 is 0x0A)) and event.handled is False:
                output += mixerAdjustPan(4, event.data2)
                event.handled = True

            # Fader 5 - Track 5 volume
            if (event.status is 0xB0 and
                (event.data1 is 0x06 or event.data1 is 0x34
                 or event.data1 is 0x59)) or (event.status is 0xB4
                                              and event.data1 is 0x07):
                output += mixerAdjustFader(5, event.data2)
                event.handled = True

            # Knob 5 - Track 5 pan
            if (event.status is 0xB0 and
                (event.data1 is 0x12 or event.data1 is 0x3D
                 or event.data1 is 0x66)) or (event.status is 0xB4
                                              and event.data1 is 0x0A):
                output += mixerAdjustPan(5, event.data2)
                event.handled = True

            # Fader 6 - Track 6 volume
            if (event.status is 0xB0 and
                (event.data1 is 0x08 or event.data1 is 0x35
                 or event.data1 is 0x5A)) or (event.status is 0xB5
                                              and event.data1 is 0x07):
                output += mixerAdjustFader(1, event.data2)
                event.handled = True

            # Knob 6 - Track 6 pan
            if (event.status is 0xB0 and
                (event.data1 is 0x13 or event.data1 is 0x3E
                 or event.data1 is 0x67)) or (event.status is 0xB5
                                              and event.data1 is 0x0A):
                output += mixerAdjustPan(6, event.data2)
                event.handled = True

            # Fader 7 - Track 7 volume
            if (event.status is 0xB0 and
                (event.data1 is 0x09 or event.data1 is 0x36
                 or event.data1 is 0x5B)) or (event.status is 0xB6
                                              and event.data1 is 0x07):
                output += mixerAdjustFader(1, event.data2)
                event.handled = True

            # Knob 7 - Track 7 pan
            if (event.status is 0xB0 and
                (event.data1 is 0x14 or event.data1 is 0x3F
                 or event.data1 is 0x68)) or (event.status is 0xB6
                                              and event.data1 is 0x0A):
                output += mixerAdjustPan(7, event.data2)
                event.handled = True

            # Fader 8 - Track 8 volume
            if (event.status is 0xB0 and
                (event.data1 is 0x0C or event.data1 is 0x37
                 or event.data1 is 0x5C)) or (event.status is 0xB7
                                              and event.data1 is 0x07):
                output += mixerAdjustFader(1, event.data2)
                event.handled = True

            # Knob 8 - Track 8 pan
            if (event.status is 0xB0 and
                (event.data1 is 0x15 or event.data1 is 0x41
                 or event.data1 is 0x69)) or (event.status is 0xB7
                                              and event.data1 is 0x0A):
                output += mixerAdjustPan(8, event.data2)
                event.handled = True

        if event.handled is True:
            handleOutput(output)
            return

        # In Channel rack
        if ui.getFocused(1) is 1 and loopDown is False:
            selectedChannel = channels.channelNumber()

            # Forward Button
            if (event.status is 0xB0 and event.data1 is 0x30):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Next track
                elif event.data2 is 0x00:
                    ui.next()
                    mixerTrackSelect(channels.channelNumber())
                    output += "Channel rack: Select next track: " + getChannelName(
                        channels.channelNumber())

                    event.handled = True

            # Back Button
            if (event.status is 0xB0 and event.data1 is 0x2F):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Previous track
                elif event.data2 is 0x00:
                    ui.previous()
                    mixerTrackSelect(channels.channelNumber())
                    output += "Channel rack: Select previous track: " + getChannelName(
                        channels.channelNumber())

                    event.handled = True

            # Fader, knob and buttons #9 act on the selected channel

            # Upper button 9
            if (event.status is 0xB0 and
                (event.data1 is 0x1F or event.data1 is 0x4B
                 or event.data1 is 0x73)) or (event.status is 0xB8
                                              and event.data1 is 0x10):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Solo channel (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or event.status is 0xB8:
                    output += channelToggleSolo(selectedChannel)
                    event.handled = True

            # Lower button 9
            if (event.status is 0xB0 and
                (event.data1 is 0x29 or event.data1 is 0x54
                 or event.data1 is 0x7C)) or (event.status is 0xB8
                                              and event.data1 is 0x11):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Mute track (in scene 4, the buttons toggle automatically)
                if event.data2 is 0x00 or event.status is 0xB8:
                    output += channelToggleMute(selectedChannel)
                    event.handled = True

            # Fader 9 - Selected volume
            if (event.status is 0xB0 and
                (event.data1 is 0x0D or event.data1 is 0x38
                 or event.data1 is 0x5D)) or (event.status is 0xB8
                                              and event.data1 is 0x07):
                output += channelAdjustVolume(selectedChannel, event.data2)
                event.handled = True

            # Knob 9 - Selected pan
            if (event.status is 0xB0 and
                (event.data1 is 0x16 or event.data1 is 0x42
                 or event.data1 is 0x6A)) or (event.status is 0xB8
                                              and event.data1 is 0x0A):
                output += channelAdjustPan(selectedChannel, event.data2)
                event.handled = True

            # Maybe include step editor here (when I figure out lights)

        if event.handled is True:
            handleOutput(output)
            return

        # In Browser
        if ui.getFocused(4) is 1 and loopDown is False:

            # Play Button
            if (event.status is 0xB0 and event.data1 is 0x2D):
                # Press - Play sample/expand menu
                if event.data2 is 0x7F:
                    ui.next()
                    ui.previous()
                    ui.right()
                    output += "Browser: Select"
                    event.handled = True
                # Lift - No action
                elif event.data2 is 0x00:
                    event.handled = True

            # Forward Button
            if (event.status is 0xB0 and event.data1 is 0x30):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Next item
                elif event.data2 is 0x00:
                    ui.next()
                    output += "Browser: Next"

                    event.handled = True

            # Back Button
            if (event.status is 0xB0 and event.data1 is 0x2F):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Previous item
                elif event.data2 is 0x00:
                    ui.previous()
                    output += "Browser: Previous"

                    event.handled = True

            # Stop Button
            if (event.status is 0xB0 and event.data1 is 0x2E):
                # Press - No action
                if event.data2 is 0x7F:
                    event.handled = True
                # Lift - Collapse menu
                elif event.data2 is 0x00:
                    ui.left()
                    output += "Browser: Collapse"

                    event.handled = True

        if event.handled is True:
            handleOutput(output)
            return

        # Default Actions:

        # Play Button
        if (event.status is 0xB0 and event.data1 is 0x2D):
            loopInterrupt = True
            # Press - No action
            if event.data2 is 0x7F:
                event.handled = True
            # Lift - Play/Pause
            elif event.data2 is 0x00:
                transport.start()
                if transport.isPlaying() is 1: output += "Transport: Play"
                else: output += "Transport: Pause"

                event.handled = True

        # Stop Button
        if (event.status is 0xB0 and event.data1 is 0x2E):
            loopInterrupt = True
            # Press - No action
            if event.data2 is 0x7F:
                event.handled = True
            # Lift - Stop
            elif event.data2 is 0x00:
                transport.stop()
                output += "Transport: Stop"

                event.handled = True

        # Forward Button
        if (event.status is 0xB0 and event.data1 is 0x30):
            loopInterrupt = True
            # Press - Start FF
            if event.data2 is 0x7F:
                transport.fastForward(2)
                event.handled = True
                output += "Transport: Fast Forward: Begin"
            # Lift - End FF
            elif event.data2 is 0x00:
                transport.fastForward(0)
                output += "Transport: Fast Forward: End"
                event.handled = True

        # Back Button
        if (event.status is 0xB0 and event.data1 is 0x2F):
            # Press - Start Rew
            if event.data2 is 0x7F:
                transport.rewind(2)
                event.handled = True
                output += "Transport: Rewind: Begin"
            # Lift - End Rew
            elif event.data2 is 0x00:
                transport.rewind(0)
                output += "Transport: Rewind: End"
                event.handled = True

        # Record Button
        if (event.status is 0xB0 and event.data1 is 0x2C):
            loopInterrupt = True
            # Press - No action
            if event.data2 is 0x7F:
                event.handled = True
            # Lift - Toggle Recording
            elif event.data2 is 0x00:
                transport.record()
                if transport.isRecording() is 1:
                    output += "Transport: Recording Enabled"
                else:
                    output += "Transport: Recording Disabled"
                event.handled = True

        # Loop Button
        if (event.status is 0xB0 and event.data1 is 0x31):
            # Press - Set Loop flags
            if event.data2 is 0x7F:
                # Set flags for loop modifier commands
                loopDown = True
                loopInterrupt = False
                event.handled = True

            # Lift - Toggle Loop if no action taken
            elif event.data2 is 0x00:
                event.handled = True
                loopDown = False
                if loopInterrupt is False:
                    transport.setLoopMode()
                    if transport.getLoopMode() is 1:
                        output += "Transport: Loop Mode: Song"
                    else:
                        output += "Transport: Loop Mode: Pattern"

        # Scene Change
        """
		if event.status is 0xF0:
			global scene
			scene += 1
			if scene is 5:
				scene = 1

			windowToShow = -1
			if scene is 1: 
				windowToShow = 2 # Playlist
				output += "Scene: Playlist"
			if scene is 2: 
				windowToShow = 1 # Channel Rack
				output += "Scene: Channel Rack"
			if scene is 3: 
				windowToShow = 3 # Piano roll
				output += "Scene: Piano Roll"
			if scene is 4: 
				windowToShow = 0 # Mixer
				output += "Scene: Mixer"

			ui.showWindow(windowToShow)
			event.handled = True
		"""

        if event.handled is True:
            handleOutput(output)
            return

        # Event not recognised
        if event.handled is False:
            print("Unknown Event: {:X} {:X} {:2X} {} {:2X}".format(
                event.status, event.data1, event.data2,
                EventNameT[(event.status - 0x80) // 16] + ': ' +
                utils.GetNoteName(event.data1), int(hex(event.data2), 16)))
示例#17
0
    def actionButton(self, event, FoundButton):
        #Action to Button (wiht my Index FoundButton[2])
        global goTo
        global Tog_TP
        global Tog_Steps
        global StepsPerTick
        global lsSPT_Values
        global SPT_IDX
        snapVal = 7

        def goRight(steps):
            #Selection go steps to the rigeht sight of Mixer
            sEnd = " "
            global goTo  #Warum hier global und in goSteps nicht?
            lastgoTo = goTo
            if goTo + NK_NrOf_ControlGr + steps < FL_TR_COUNT_MAX:
                goTo = goTo + steps  #print("right")
            else:
                goTo = FL_TR_COUNT_MAX - NK_NrOf_ControlGr
                sEnd = "END of Mixer (right)! - "  #wird mir goTo nie überschritten
            sHi_MixTR_Range = sEnd + "Mix-Tracks " + str(goTo) + "-" + str(
                NK_NrOf_ControlGr + goTo - 1)  #activ HintMsg Track area
            ui.setHintMsg(sHi_MixTR_Range)
            if lastgoTo != goTo: resetTrackName(event, lastgoTo)
            selectActivArea(goTo)
            event.handled = True

        def goLeft(steps):
            #Selection go steps to the left sight of Mixer
            sEnd = " "
            global goTo
            lastgoTo = goTo
            if goTo > steps - 1: goTo = goTo - steps  #print("left")
            else:
                goTo = 0
                sEnd = "END of Mixer (left)! - "
            sHi_MixTR_Range = sEnd + "Mix-Tracks " + str(goTo) + "-" + str(
                NK_NrOf_ControlGr + goTo - 1)  #activ HintMsg Track area
            ui.setHintMsg(sHi_MixTR_Range)
            if lastgoTo != goTo: resetTrackName(event, lastgoTo)
            selectActivArea(goTo)

        if FoundButton[2] == 2:  #8 to left
            goLeft(NK_NrOf_ControlGr)

        elif FoundButton[2] == 3:  #8 to right
            goRight(NK_NrOf_ControlGr)

        elif FoundButton[2] == 4:  #reset
            ui.showWindow(midi.widMixer)
            resetAllName()
            event.handled = True  #sonst knallt es

        elif FoundButton[2] == 5:  #set stepswide
            ### Könnte ich dazu verwenden um einen Track fest zu zu ordnen
            if Tog_Steps and SPT_IDX < len(lsSPT_Values):
                SPT_IDX += 1
                if SPT_IDX == (len(lsSPT_Values) - 1):
                    Tog_Steps = not Tog_Steps  #max 7 per Ticker, Toggel betwenn Up/down
            elif SPT_IDX > 0:
                SPT_IDX -= 1
                if SPT_IDX == 0: Tog_Steps = not Tog_Steps  #max 7 per Ticker
            else: print("Error: Step-Counter")
            StepsPerTick = lsSPT_Values[SPT_IDX]
            ui.setHintMsg("set " + str(lsSPT_Values[SPT_IDX]) + " steps")
            event.handled = True
            time.sleep(ST_HintMsg)

        elif FoundButton[2] == 6:  #StepsPerTick) to left
            goLeft(StepsPerTick)

        elif FoundButton[2] == 7:  #StepsPerTick) to right
            goRight(StepsPerTick)

        elif FoundButton[2] == 8:  #TP Rew
            if Tog_TP: transport.rewind(2)
            else: transport.rewind(0)
            Tog_TP = not Tog_TP
            event.handled = True

        elif FoundButton[2] == 9:  #TP FF
            if Tog_TP: transport.fastForward(2)
            else: transport.fastForward(0)
            Tog_TP = not Tog_TP
            event.handled = True

        elif FoundButton[2] == 10:  #TP stop
            if Tog_TP: transport.fastForward(2)
            transport.stop()
            event.handled = True

        elif FoundButton[2] == 11:  #TP play
            transport.start()
            event.handled = True

        elif FoundButton[2] == 12:  #TP rec
            if bPrintAction:
                print("TP rec ", FoundButton[1], " Wert: ", FoundButton[4])
            transport.record()
            event.handled = True

        elif FoundButton[2] in lsKnob:  #Paning
            nMixTrIndex = FoundButton[3] - (NK_CC_Knob_First
                                            )  #36to43-35=MixTrackIdx in FL
            nMixTrPan = (1 / 64) * (FoundButton[4] - 63
                                    )  # max Pan. FL=-1.0 - 1.0 (0-127 steps)
            FL_Pan = int(mixer.getTrackPan(nMixTrIndex + goTo) * 64)

            #Only change the value if the position of the controller matches the FL value. To avoid jumps
            if FoundButton[4] - 63 in range(FL_Pan - snapVal,
                                            FL_Pan + snapVal) and Reg_Snap:
                mixer.setTrackPan(nMixTrIndex + goTo, nMixTrPan)  #Set Paning
            if Reg_Snap == False:
                mixer.setTrackPan(nMixTrIndex + goTo, nMixTrPan)  #Set Paning
            selectActivMixTrack(nMixTrIndex + goTo)
            event.handled = True

        elif FoundButton[2] in lsSld:  #Volume
            nMixTrIndex = FoundButton[3] - (NK_CC_SLider_First
                                            )  #36to43-35=MixTrackIdx in FL
            nMixTrVolu = (1 / 127) * FoundButton[
                4]  # max Vol. FL=1.0 / max Vol. nK2=127, event.data2=Value from nK2-Slider
            FL_Vol = int(mixer.getTrackVolume(nMixTrIndex + goTo) * 127)
            #Only change the value if the position of the controller matches the FL value. To avoid jumps
            if FoundButton[4] in range(FL_Vol - snapVal,
                                       FL_Vol + snapVal) and Reg_Snap:
                mixer.setTrackVolume(nMixTrIndex + goTo, nMixTrVolu)  #Set Vol
            if Reg_Snap == False:
                mixer.setTrackVolume(nMixTrIndex + goTo, nMixTrVolu)  #Set Vol
            selectActivMixTrack(nMixTrIndex + goTo)
            event.handled = True

        elif FoundButton[2] in lsSoloB:  #Solo-Button
            nMixTrIndex = FoundButton[3] + NK_Solo_But_First
            selectActivMixTrack(nMixTrIndex + goTo)
            mixer.soloTrack(nMixTrIndex + goTo)  #
            event.handled = True

        elif FoundButton[2] in lsMuteB:  #Mute-Button
            nMixTrIndex = FoundButton[3] - (NK_Mute_But_First
                                            )  #36to43-35=MixTrackIdx in FL
            mixer.muteTrack(nMixTrIndex + goTo)  #
            selectActivMixTrack(nMixTrIndex + goTo)
            event.handled = True

        elif FoundButton[2] in lsRecB:  #Rec-Button
            nMixTrIndex = FoundButton[3] - (NK_Rec_But_First
                                            )  #72to73-71=MixTrackIdx in FL
            mixer.armTrack(nMixTrIndex + goTo)  #
            selectActivMixTrack(nMixTrIndex + goTo)
            event.handled = True
示例#18
0
	def switch_moment(event):
		"""handles momentary witch midi events"""
		if event.data1 == button["pad_mode_toggle"]:				# This Rotates through pad modes - standard, step sequencer, pad to channel		
			Switch.mode_toggle += 1
			if Switch.mode_toggle == 4:
				Switch.mode_toggle = 0
			print('Pad Mode: ' + mode[Switch.mode_toggle])
			ui.setHintMsg(mode[Switch.mode_toggle])

		elif event.midiId == 224: 								# pitch wheel
			Switch.pitch_num = event.data2	
			if Switch.shift_status == True:
				print(data.notes_list[int(mapvalues(Switch.pitch_num, 0, 11, 0, 244))])

		elif event.data1 == button["play"]:			
			transport.start()
			event.handled = True

		elif event.data1 == button["offset_range"]:
			Switch.offset_iter += 1
			if Switch.offset_iter == 2:     								# 2 here will limit to 32 steps, knobs. Changing to 4 will allow up to 64 steps, knobs. 
				Switch.offset_iter = 0
			ui.setHintMsg("Offset Range: " + str(Switch.offset_iter))
	
		elif event.data1 == button["stop"]:
			print('Stop')
			transport.stop()
			event.handled = True						
																	
		elif event.data1 == button["record"]:			
			print('Record')
			transport.record()
			event.handled = True

		elif event.data1 == button["pattern_down"]:
			if ui.getFocused(5):
				print("Previous Preset")
				ui.previous()
			else:
				print('Pattern Down')
				transport.globalTransport(midi.FPT_PatternJog, -1)
				event.handled = True
					
		elif event.data1 == button["pattern_up"]:
			if ui.getFocused(5):
				print("Next Preset")
				ui.next()
			else:
				print('Pattern Up')
				transport.globalTransport(midi.FPT_PatternJog, 1)
				event.handled = True
																	# Set mod wheel to control channels when channels focused and tracks when mixer
		elif event.data1 == button["mod_wheel"]:					
			if ui.getFocused(0):
				mixer.setTrackNumber(int(mapvalues(event.data2, 0, 64, 0, 127)))
				ui.scrollWindow(midi.widMixer, mixer.trackNumber())
			elif ui.getFocused(1):
				print("Channel Number: " + str(channels.selectedChannel()))
				channels.selectOneChannel(int(round(mapvalues(event.data2, channels.channelCount()-1, 0, 0, 127), 0)))				

		elif event.data1 == 72:
			print(channels.getChannelColor(channels.selectedChannel())) 
			Switch.color_num += 1
			if Switch.color_num == len(colors):
				Switch.color_num = 0
			if ui.getFocused(1):
				channels.setChannelColor(channels.selectedChannel(), colors[Switch.color_num])
			elif ui.getFocused(0):
				mixer.setTrackColor(mixer.trackNumber(), colors[Switch.color_num])
			event.handled = True
		
		elif event.data1 == button["enter"]:
			if ui.getFocused(4):
				print("Select Browser Item")
				ui.selectBrowserMenuItem()		
				event.handled = True
			elif ui.getFocused(1):
				print("Mute Channel")
				channels.muteChannel(channels.selectedChannel())
			elif ui.getFocused(0):
				print("Mute Track")
				mixer.muteTrack(mixer.trackNumber())
			else:
				print('enter')
				ui.enter()
				event.handled = True

		elif event.data1 in range(59, 64) and config.PATTERN_JUMP_ON:						# Sets jump to pattern
			patterns.jumpToPattern(event.data1 - 58)
			event.handled = True		

		elif event.data1 in range(75, 80) and config.PATTERN_JUMP_ON:
			patterns.jumpToPattern(event.data1 - 69)
			event.handled = True

		elif event.data1 == button["solo"]:
			print('Solo')
			if ui.getFocused(0):
				mixer.soloTrack(mixer.trackNumber())
			elif ui.getFocused(1):
				channels.soloChannel(channels.selectedChannel())

		elif event.data1 == button["view_plugin_picker"]:
			print('View Plugin Picker')
			transport.globalTransport(midi.FPT_F8, 67)
			event.handled = True	
			
		elif event.data1 == button["song_mode_toggle"]:			
			print('Toggle Song and Pattern Mode')
			transport.setLoopMode()
			event.handled = True
			
		elif event.data1 == button["view_playlist"]:			
			print('View Playlist')
			transport.globalTransport(midi.FPT_F5, 65)
			event.handled = True
			
		elif event.data1 == button["view_piano_roll"]:
			print('View Piano Roll')
			transport.globalTransport(midi.FPT_F7, 66)
			event.handled = True
		
		elif event.data1 == button["view_channel_rack"]:
			print('View Channel Rack')
			transport.globalTransport(midi.FPT_F6, 65)
			event.handled = True
			
		elif event.data1 == button["view_mixer"]:
			print('View Mixer')
			transport.globalTransport(midi.FPT_F9, 68)
			event.handled = True
																	# Toggle through step parameter options - pitch, pan etc. No Shift control right now. 
		elif event.data1 == button["step_parameter"]:
			
			if ui.getFocused(1) and Switch.mode_toggle == 1:
				print('Toggle Step Parameter')
				Switch.parameter += 1
				if Switch.parameter == 7:
					Switch.parameter = 0
				print(Switch.parameter)
				ui.setHintMsg(parameters[Switch.parameter])

			elif ui.getFocused(0):
				Switch.mixer_num += 1
				if Switch.mixer_num == 2:
					Switch.mixer_num = 0
				print('Mixer Mode: ' + str(Switch.mixer_num))
				ui.setHintMsg(mixer_choice[Switch.mixer_num])
			event.handled = True

		elif event.data1 == button["open_channel_sampler"]:			
			print('Open Sampler Channel')
			channels.showCSForm(channels.channelNumber(), -1)
			event.handled = True					
							
		elif event.data1 == button["left"]:							
			print('Left')
			ui.left()
			event.handled = True	
		
		elif event.data1 == button["down"]:							
			print('Down')
			ui.down()
			event.handled = True				
			
		elif event.data1 == button["right"]:						
			print('Right')
			ui.right()
			event.handled = True			

		elif event.data1 == button["save"]:
			print('Save')
			transport.globalTransport(midi.FPT_Save, 92)
																	# If mixer is open and mute mode selected, top row will mute respective track 
		elif event.data1 == button["undo"]:					
				print('Undo')
				transport.globalTransport(midi.FPT_Undo, 20)
				device.midiOutMsg(144, 1, 63, 80)
				event.handled = True

		elif event.data1 == button["escape"]:
			print('Escape')
			ui.escape()
			event.handled = True
		
		elif event.data1 == button["up"]:
			print('Up')
			ui.up()
			event.handled = True			

		elif event.data1 == button["rotate_window"]:				
			print('Rotate Window')
			ui.nextWindow()
			event.handled = True

		elif event.data1 == button["browser"]:				
			print('Browser')
			if Switch.shift_status == False:
				if ui.getFocused(4):
					ui.hideWindow(4)
					event.handled = True
				else:
					ui.showWindow(4)
					ui.setFocused(4)
					event.handled = True
			
		elif event.data1 == button["step_rec"]:	
			if ui.getFocused(0):
				mixer.armTrack(mixer.trackNumber())	
				print("Toggle Track Rec")
			else:			
				transport.globalTransport(midi.FPT_StepEdit, 114)
				print('Step Record')
				event.handled = True							

		elif event.data1 == button["quantize"]:
			print('quantize')
			channels.quickQuantize(channels.channelNumber())
			event.handled = True

		elif event.data1 == button["link_chan"]:
			print('link channel')
			mixer.linkTrackToChannel(0)

		elif event.data1 == button["rand_steps"]:
			print("Random")
			print(f'Pitch Bend: {event.pitchBend}')
			for i in range(patterns.getPatternLength(patterns.patternNumber())):
				channels.setGridBit(channels.channelNumber(), i, 0)
			for z in range (patterns.getPatternLength(patterns.patternNumber())):
				y = num_gen()
				if y > ( Switch.pitch_num * 516):
					channels.setGridBit(channels.channelNumber(), z, 1)
				else:
					pass
			event.handled = True

		elif event.data1 == button["rand_notes"]:
			print("Randomize Notes")
			Switch.note_gen()
			event.handled = True