Пример #1
0
 def OnEncoderDecreased(self, control, event):
     control_type, control_name, control_id, control_note_or_color = control.split(
         ".")
     control_number = int(control_name)
     if ui.getFocused(midi.widMixer):
         index = mixer.trackNumber() + control_number - 1
         if self.mixer.encodersTarget == ENCODERS_NUM_TARGETS.MIXER.TRACK_VOL:
             mixer.setTrackVolume(index,
                                  mixer.getTrackVolume(index) - VOL_INC)
         elif self.mixer.encodersTarget == ENCODERS_NUM_TARGETS.MIXER.TRACK_PAN:
             mixer.setTrackPan(index, mixer.getTrackPan(index) - PAN_INC)
     elif ui.getFocused(midi.widChannelRack
                        ) and control_number <= channels.channelCount():
         index = channels.channelNumber() + control_number - 1
         if self.channels.encodersTarget == ENCODERS_NUM_TARGETS.CHANNELS.CHANNEL_VOL:
             channels.setChannelVolume(
                 index,
                 channels.getChannelVolume(index) - VOL_INC)
         elif self.channels.encodersTarget == ENCODERS_NUM_TARGETS.CHANNELS.CHANNEL_PAN:
             channels.setChannelPan(index,
                                    channels.getChannelPan(index) - PAN_INC)
     elif ui.getFocused(midi.widPlaylist):
         index = playlist.trackNumber() + control_number - 1
         if self.playlist.encodersTarget == ENCODERS_NUM_TARGETS.TRACK_VOL:
             pass
def adjustMixer(knob: int, dataType: str, action: str, selectedTrack: int):
    """ Dynamically maps the physical knob to the right mixer track depending on the track group the selected track belongs to, and adjusts the parameter.
    ### Parameters

     - knob: From 0 to 7. Number of the physical knob you are mapping.
    
     - dataType: The parameter you are going to adjust. Can be PAN or VOLUME.

     - action: Can be INCREASE or DECREASE.

     - selectedTrack: The actual selected track that will be used to calculate the track group.
    """
    # Calculates which track group the current track belongs to and truncates the value to get the exact number
    trackGroup = math.trunc(1 / 8 * selectedTrack)

    # Multiplies the trackGroup to 8 to get the index of the first track of that group
    trackFirst = trackGroup * 8

    if dataType == "VOLUME":
        if action == "INCREASE":
            mixer.setTrackVolume(
                trackFirst + knob,
                mixer.getTrackVolume(trackFirst + knob) + 0.02)

        if action == "DECREASE":
            mixer.setTrackVolume(
                trackFirst + knob,
                mixer.getTrackVolume(trackFirst + knob) - 0.02)

    if dataType == "PAN":
        if action == "INCREASE":
            mixer.setTrackPan(trackFirst + knob,
                              mixer.getTrackPan(trackFirst + knob) + 0.01)

        if action == "DECREASE":
            mixer.setTrackPan(trackFirst + knob,
                              mixer.getTrackPan(trackFirst + knob) - 0.01)
Пример #3
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
Пример #4
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 updateMixerTracks(dataType: str, selectedTrack: int):
    """ Given the number of the selected track number on the mixer, it is able to know which track group should render into the screen device and bulk reports their information.
    
    ### Parameters

     - dataType: The kind of data you are going to update (PEAK is not valid. Use `updatePeak()` instead)
    
     - trackNumber: The number of the track that is currently selected, going from 0 to 125. `mixer.trackNumber()` can be used directly to fill the argument.
    """

    # Uses the function to know which track group the current track belongs to and truncates the value to get the exact number
    trackGroup = math.trunc(1 / 8 * selectedTrack)

    # Multiplies the trackGroup to 8 to get the index of the first track that has to be shown
    trackFirst = trackGroup * 8

    # If the selected track belongs to the 16th group, it will declare the last two tracks as non existant
    # Otherwise, it will declare all as existant
    if trackGroup == 15:
        nihia.mixerSendInfo("EXIST", 0, value=1)
        nihia.mixerSendInfo("EXIST", 1, value=1)
        nihia.mixerSendInfo("EXIST", 2, value=1)
        nihia.mixerSendInfo("EXIST", 3, value=1)
        nihia.mixerSendInfo("EXIST", 4, value=1)
        nihia.mixerSendInfo("EXIST", 5, value=1)
        nihia.mixerSendInfo("EXIST", 6, value=0)
        nihia.mixerSendInfo("EXIST", 7, value=0)

    else:
        for x in range(trackFirst, trackFirst + 8):
            nihia.mixerSendInfo("EXIST", x - trackFirst, value=1)

    # In case the group track is the 15th one, it will limit the declaration of tracks to 7
    if trackGroup == 15:
        trackLimit = trackFirst + 7

    elif trackGroup != 15:
        trackLimit = trackFirst + 8

    # Loop that updates the info of the tracks one by one (sums the actual track number)
    for x in range(trackFirst, trackLimit):

        if dataType == "NAME":
            nihia.mixerSendInfo("NAME",
                                x - trackFirst,
                                info=mixer.getTrackName(x))

        if dataType == "VOLUME":

            # Declares volume as minus infinite if the value is 0
            if mixer.getTrackVolume(x) == 0:
                dB = "-oo"

            elif mixer.getTrackVolume(x) != 0:
                # Calculates the dB value of the current track -- based of a code snippet by soundwrightpro
                dB = (math.exp(mixer.getTrackVolume(x) * 1.25 * math.log(11)) -
                      1) * 0.1
                dB = round(math.log10(dB) * 20, 1)

            dB = str(dB) + " dB"

            nihia.mixerSendInfo("VOLUME", x - trackFirst, info=dB)

        if dataType == "PAN":
            # Centered
            if math.trunc(mixer.getTrackPan(x)) == 0:
                nihia.mixerSendInfo("PAN", x - trackFirst, info="Centered")

            # Right
            if mixer.getTrackPan(x) > 0:
                nihia.mixerSendInfo(
                    "PAN",
                    x - trackFirst,
                    info=str(round(
                        (abs(mixer.getTrackPan(x)) * 100))) + "% " + "Right")

            # Left
            if mixer.getTrackPan(x) < 0:
                nihia.mixerSendInfo(
                    "PAN",
                    x - trackFirst,
                    info=str(round(
                        (abs(mixer.getTrackPan(x)) * 100))) + "% " + "Left")

        if dataType == "IS_MUTE":
            nihia.mixerSendInfo("IS_MUTE",
                                x - trackFirst,
                                value=mixer.isTrackMuted(x))

        if dataType == "IS_SOLO":
            nihia.mixerSendInfo("IS_SOLO",
                                x - trackFirst,
                                value=mixer.isTrackSolo(x))

        if dataType == "SELECTED":
            nihia.mixerSendInfo("SELECTED",
                                x - trackFirst,
                                value=mixer.isTrackSelected(x))

        if dataType == "VOLUME_GRAPH":
            nihia.mixerSetGraph(x - trackFirst, "VOLUME",
                                mixer.getTrackVolume(x))

        if dataType == "PAN_GRAPH":
            nihia.mixerSetGraph(x - trackFirst, "PAN", mixer.getTrackPan(x))

    # Checks the track group once more to clean up the last two tracks
    if trackGroup == 15:
        if dataType == "NAME":
            nihia.mixerSendInfo("NAME", 6, info="")
            nihia.mixerSendInfo("NAME", 7, info="")

        # Track 7 --> Current
        if dataType == "VOLUME":
            nihia.mixerSendInfo("VOLUME", 6, info=" ")
            nihia.mixerSendInfo("VOLUME", 7, info=" ")

        if dataType == "PAN":
            nihia.mixerSendInfo("PAN", 6, info=" ")
            nihia.mixerSendInfo("PAN", 7, info=" ")

        if dataType == "IS_MUTE":
            nihia.mixerSendInfo("IS_MUTE", 6, value=0)
            nihia.mixerSendInfo("IS_MUTE", 7, value=0)

        if dataType == "IS_SOLO":
            nihia.mixerSendInfo("IS_SOLO", 6, value=0)
            nihia.mixerSendInfo("IS_SOLO", 7, value=0)

        if dataType == "VOLUME_GRAPH":
            nihia.mixerSetGraph(6, "VOLUME", 0)
            nihia.mixerSetGraph(7, "VOLUME", 0)

        if dataType == "PAN_GRAPH":
            nihia.mixerSetGraph(6, "PAN", 0)
            nihia.mixerSetGraph(7, "PAN", 0)
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 OnRefresh(self, flags):

        if device.isAssigned():
            print("On Refresh")

            i = mixer.trackNumber()

            Volume = mixer.getTrackVolume(i)
            sVol = self.scaleValue(Volume, 1, 127)
            self.UpdateKnobs(self.KNOB.VOL, sVol)
            self.UpdateLEDs(self.KNOB.VOL, self.COLOR.BRIGHT_GREEN,
                            self.ANI.SOLID)

            Pan = 1 + (mixer.getTrackPan(i))
            sPan = self.scaleValue(Pan, 2, 127)
            self.UpdateKnobs(self.KNOB.PAN, sPan)

            if mixer.isTrackSolo(i):
                self.UpdateLEDs(self.BTN.SOLO, self.COLOR.GREEN_YELLOW,
                                self.ANI.PULSE)
            else:
                if (Pan < 1):
                    self.UpdateLEDs(self.KNOB.PAN, self.COLOR.YELLOW,
                                    self.ANI.SOLID)
                elif (Pan > 1):
                    self.UpdateLEDs(self.KNOB.PAN, self.COLOR.RED,
                                    self.ANI.SOLID)
                else:
                    self.UpdateLEDs(self.KNOB.PAN, self.COLOR.BRIGHT_GREEN,
                                    self.ANI.SOLID)

            if mixer.isTrackEnabled(i):
                self.UpdateLEDs(self.BTN.MUTE, self.COLOR.BRIGHT_GREEN,
                                self.ANI.SOLID)
            else:
                self.UpdateLEDs(self.BTN.MUTE, self.COLOR.GREEN_YELLOW,
                                self.ANI.PULSE)

            if mixer.isTrackArmed(i):
                self.UpdateLEDs(self.KNOB.VOL, self.COLOR.RED, self.ANI.PULSE)

            color = mixer.getTrackColor(i)

            if transport.isPlaying():
                self.UpdateLEDs(self.BTN.PLAY, self.COLOR.GREEN,
                                self.ANI.PULSE)
                self.UpdateLEDs(self.BTN.STOP, self.COLOR.GREEN,
                                self.ANI.SOLID)
            else:
                self.UpdateLEDs(self.BTN.PLAY, self.COLOR.DARK_BLUE,
                                self.ANI.SOLID)
                self.UpdateLEDs(self.BTN.STOP, self.COLOR.DARK_BLUE,
                                self.ANI.SOLID)

            if transport.isRecording():
                self.UpdateLEDs(self.BTN.RECORD, self.COLOR.RED,
                                self.ANI.PULSE)
            else:
                self.UpdateLEDs(self.BTN.RECORD, self.COLOR.YELLOW,
                                self.ANI.SOLID)

            if transport.getLoopMode():
                self.UpdateLEDs(self.BTN.LOOP_MODE, self.COLOR.BRIGHT_GREEN,
                                self.ANI.SOLID)
            else:
                self.UpdateLEDs(self.BTN.LOOP_MODE, self.COLOR.LIGHT_ORANGE,
                                self.ANI.SOLID)
Пример #8
0
	def __init__(self, event):
		global proceed
		self.event = event
		global temp_chan
		proceed = False
		self.mode_toggle = Switch.mode_toggle
		# self.mixer_num = mixer.trackNumber()
		self.channel = channels.channelNumber()
		self.round_offset = 0.16
		self.get_track_value = 0
		self.data_one = event.data1 + offset[switch.Switch.offset_iter]
		self.data_two = event.data2
		self.two_rounded = round(self.data_two/127, 2)
		self.plugin = 0
		self.event_one = event.data1
		print('knob class')

		if ui.getFocused(1) and Switch.shift_status == True:
			print('enter step param edit in turning')
			if event.data1 == knob['knob_one']:
				Switch.root_note = int(mapvalues(self.data_two, 0, 11, 0, 127))
				ui.setHintMsg(data.notes_list [int(mapvalues(self.data_two, 0, 11, 0, 127)) ] )
				print(Switch.root_note)
				event.handled = True

			if event.data1 == knob['knob_two']:
				Switch.scale_choice = int(mapvalues(self.data_two, 0, len(data.scale_names)-1, 0, 127))
				ui.setHintMsg(data.scale_names[int(mapvalues(self.data_two, 0, len(data.scale_names)-1, 0, 127))])
				print(Switch.scale_choice)
				event.handled = True

			if event.data1 == knob['knob_three']:
				Switch.lower_limit = int(mapvalues(self.data_two, 0, 25, 0, 127))
				ui.setHintMsg("Setting Lower Limit")
				print(Switch.lower_limit)
				event.handled = True

			if event.data1 == knob['knob_four']:
				Switch.upper_limit = int(mapvalues(self.data_two, 50, 0, 0, 127))
				ui.setHintMsg("Setting Upper Limit")
				print(Switch.upper_limit)
				event.handled = True

		elif ui.getFocused(5) and plugins.isValid(self.channel):
			print('plugin control')
			self.plugin_control()

		elif ui.getFocused(0) and proceed == False:						# This stores the current value at the destination of the knob
			# print('proceed false mixer focused')
			if Switch.mixer_num == 0:
				if mixer.trackNumber() == 0:								# Check if master is selected
					self.get_track_value = mixer.getTrackVolume(0)
				else:		
					self.get_track_value = mixer.getTrackVolume(self.data_one - 19) 

			elif Switch.mixer_num == 1:
				# print('store panning info')
				self.get_track_value = mixer.getTrackPan(self.data_one-19)
				print(self.get_track_value)
				self.two_rounded = mapvalues(self.data_two, -1.0, 1.0, 0, 127)
				print(self.two_rounded)

		elif ui.getFocused(1) and Switch.shift_status == False:
			# print('stored channel')
			if self.mode_toggle != 1 and self.mode_toggle != 3:
				if self.data_one-20 < channels.channelCount():
					self.get_track_value = channels.getChannelVolume(self.data_one-20) 
			else:
				# print('go to step parameter function')
				self.step_param()


	
																					# Knob must match current value before it engages.
		if self.two_rounded <= (self.get_track_value + self.round_offset) and self.two_rounded >= (self.get_track_value - self.round_offset):
			print("matched") 
			proceed = True
			temp_chan = self.data_one
			# print(f'temp chan:  {temp_chan}')
			if switch.Switch.mode_toggle != 1 and Switch.mode_toggle != 3 or ui.getFocused(1)==False:
				# print('enter knob turn function')
				self.knob_turn()