diff --git a/mapping/colorplay.py b/mapping/colorplay.py new file mode 100644 index 0000000..04f2fb8 --- /dev/null +++ b/mapping/colorplay.py @@ -0,0 +1,198 @@ +#!/bin/python3 + +# import pyautogui +from mapping.base import BasicMessageParse,BasicActions,MatchError,BasicMidiInterface +import mido +import re,configparser +import pyautogui + +from mapping.midi import MessageParse +from mapping.midi import Actions + +PLUGGED=[0,0,1,0,0,0,1,0] + +class demvars(): + def __init__(self): + self.interface_nb=1 + self.output=None + self.BASE_NOTE_INPUT=56 + self.BASE_NOTE_MASTERM=48 + self.BASE_COLORS=[ [1,1,1,1,1,1,1,1], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0] + ] + self.active_input=None + self.PLUGGED=PLUGGED + self.COLORS={"black":0,"green":1,"blinking_green":2,"red":3,"blinking_red":4,"yellow":5,"blinking_yellow":6} + # self. + def findit(self,col,row): + "All index start at zero" + return self.BASE_NOTE_INPUT+col-8*row + + def lightcolor(self,col,row,color): + self.light(col,row,val=self.COLORS[color]) + + def light(self,col,row,val=1): + self.lightnote(self.findit(col,row),val) + + def lightnote(self,note,val=1): + self.output.send(mido.Message("note_on",note=note,velocity=val)) + +VARS=demvars() + +A=[[3,3,3,0],[3,0,0,3],[3,0,0,3],[3,3,3,0],[3,0,0,3],[3,0,0,3],[3,3,3,0]] +B=[[1,1,1,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[1,1,1,0]] +C=[[1,1,1,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0]] +D=[[1,1,1,0],[1,0,0,0],[1,0,0,0],[1,1,1,0],[1,0,0,0],[1,0,0,0],[1,1,1,0]] + +E=[[3,0,3],[3,3,3]]+[[3,0,3]]*3 +F=[[0,1,0],[1,0,1],[1,1,1]]+[[1,0,1]]*2 +G=[[1,0,1]]*2+[[0,1,0]]+[[1,0,1]]*2 +SPACE3=[[0,0]]*5 +SPACE7=[[0,0,0]]*7 + +WORD=[A,B,C,D,SPACE7] +WORD2=[E,F,G,SPACE3] + +def makeword(table): + final=[[] for i in range(8)] + + for letter in table: + linef=[] + for i in range(len(letter)): + linef=letter[i]+[0] + final[i]+=linef + return final + +BIGWORD=makeword(WORD2) + +def _onload(self): + "Send a reset colors" + import time,sys + VARS.output=self.outputs[VARS.interface_nb] + for i in range(64): + VARS.lightnote(i,0) + + def printletter(letter): + for i in range(4): + for j in range(7): + VARS.light(i,j,letter[j][i]) + + + def normalize(i,dec,width,loop): + new=i-dec + # if i==0: + # print(i,dec,new,new%(width+0)) + if new>width: + if not loop: + return -1 + else: + return new%(width+0) + elif new<0: + if not loop: + return -1 + else: + while new<0: # Pretty shit implementation + new+=width + return new + return new + + + def makematrix(matrix,decx=0,decy=0,loop=False): + "Shift a matrix and return the 8x8 to print" + width,height=len(matrix[0]),len(matrix) + toprint=[[0]*8 for i in range(8)] + # print(width) + + for i in range(8): + for j in range(8): + new_x=normalize(i,decx,width,loop) + #new_y=normalize(j,decy,height,loop) + new_y=j + if new_x<0 or new_y<0: + color=0 + else: + try: + color=matrix[new_y][new_x] + except IndexError: + color=0 + toprint[j][i]=color + return toprint + + def printmatrix(newmatrix,oldmatrix=None): + "Print and 8x8 matrix" + for i in range(8): + for j in range(8): + if oldmatrix: + if oldmatrix[j][i]!=newmatrix[j][i]: + VARS.light(i,j,newmatrix[j][i]) + else: + VARS.light(i,j,newmatrix[j][i]) + time.sleep(0.01) + + def clearmatrix(matrix,decx,decy,loop=False): + pass + + newmat=None + for i in range(200): + oldmat,newmat=newmat,makematrix(BIGWORD,-i,0,True) + printmatrix(newmat,oldmat) + time.sleep(0.04) + + # for j in range(0,10): + # time.sleep(0.3) + # printmatrix(BIGWORD) + # # print("E") + # for i in range(64): + # VARS.lightnote(i,0) + # time.sleep(0.2) + # + # printmatrix(BIGWORD,0,0) + # time.sleep(0.01) + + # while 1: + # for k in range(4): + # printletter(WORD[k]) + # time.sleep(0.5) + sys.exit() + + +def presskey(trigger,val,note,*params): + "Press the given keys" + pass#print(val,note,params) + +def switchinput(trigger,val,note,*params): + "Switch to the desired layer i1" + topress=VARS.findit(note-VARS.BASE_NOTE_INPUT+1,0) + + VARS.active_input=topress + + for trigger in trigger.parent.findAction('note_on',note,"*"): + print(trigger.value,trigger.intensity) + #pyautogui.hotkey("i",str(topress)) + +def takeall(trigger,val,note,*params): + "Take all TA" + #pyautogui.hotkey("t","a") + +def mastermemory(trigger,val,note,*params): + "Switch to the desired master memory M1" + topress=note-BASE_NOTE_MASTERM+1 + #pyautogui.hotkey("m",str(topress)) + +# MidiInterface(config) +class MidiInterface(BasicMidiInterface): + "Adding a couple of custom functions" + + def __init__(self,configfile): + super(MidiInterface,self).__init__(configfile) + _onload(self) + self.functionlist["presskey"]=presskey + self.functionlist["switchinput"]=switchinput + self.functionlist["mastermemory"]=mastermemory + self.functionlist["takeall"]=takeall diff --git a/mapping/keystrokes.py b/mapping/keystrokes.py index 474a2c2..807904e 100644 --- a/mapping/keystrokes.py +++ b/mapping/keystrokes.py @@ -9,7 +9,13 @@ import pyautogui from mapping.midi import MessageParse from mapping.midi import Actions -PLUGGED=[0,0,1,0,0,0,1,0] +INPUTS= [0,0,1,0,0,0,1,0] +MEMORIES=[1,1,1,0,0,0,0,0] + + +_ACTIVE=0b1 +_SELECTED=0b10 +_LIVE=0b100 class demvars(): def __init__(self): @@ -17,19 +23,29 @@ class demvars(): self.output=None self.BASE_NOTE_INPUT=56 self.BASE_NOTE_MASTERM=48 - self.BASE_COLORS=[ [1,1,1,1,1,1,1,1], - [0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0] - ] - self.active_input=None - self.PLUGGED=PLUGGED + + self.live_input=None + self.selected_input=0 + # + # self.active_memory=None + # self.selected_memory=None + + self.INPUTS=[i*_ACTIVE for i in INPUTS] + self.MEMORIES=[i*_ACTIVE for i in MEMORIES] + self.COLORS={"black":0,"green":1,"blinking_green":2,"red":3,"blinking_red":4,"yellow":5,"blinking_yellow":6} - # self. + self.COLORPLUGS={0:self.COLORS["yellow"],1:self.COLORS["green"],2:self.COLORS["blinking_green"],3:self.COLORS["red"]} + self.PLUGCOLORS={ + 0: self.COLORS["yellow"], + _ACTIVE: self.COLORS["green"], + _SELECTED: self.COLORS["blinking_yellow"], + _LIVE: self.COLORS["red"], + _ACTIVE|_SELECTED: self.COLORS["blinking_green"], + _ACTIVE|_LIVE: self.COLORS["red"], + _SELECTED|_LIVE: self.COLORS["blinking_red"], + _ACTIVE|_SELECTED+_LIVE: self.COLORS["blinking_red"] + } + def findit(self,col,row): "All index start at zero" return self.BASE_NOTE_INPUT+col-8*row @@ -43,34 +59,16 @@ class demvars(): def lightnote(self,note,val=1): self.output.send(mido.Message("note_on",note=note,velocity=val)) + def updateinput(self,toupdate=range(8)): + "Update the inputline" + for i in toupdate: + self.light(i,0,self.PLUGCOLORS[self.INPUTS[i]]) + + def updatemasterm(self): + "Update the selected master memory" + VARS=demvars() -A=[[1,1,1,0],[1,0,0,1],[1,0,0,1],[1,1,1,0],[1,0,0,1],[1,0,0,1],[1,1,1,0]] -B=[[1,1,1,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[1,1,1,0]] -C=[[1,1,1,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0]] -D=[[1,1,1,0],[1,0,0,0],[1,0,0,0],[1,1,1,0],[1,0,0,0],[1,0,0,0],[1,1,1,0]] - -E=[[1,0,1],[1,1,1]]+[[1,0,1]]*3 -F=[[0,1,0],[1,0,1],[1,1,1]]+[[1,0,1]]*2 -G=[[1,0,1]]*2+[[0,1,0]]+[[1,0,1]]*2 -SPACE3=[[0,0]]*5 -SPACE7=[[0,0,0]]*7 - -WORD=[A,B,C,D] -WORD2=[E,F,G,SPACE3] - -def makeword(table): - final=[[] for i in range(8)] - - for letter in table: - linef=[] - for i in range(len(letter)): - linef=letter[i]+[0] - final[i]+=linef - return final - -BIGWORD=makeword(WORD2) - def _onload(self): "Send a reset colors" import time,sys @@ -78,111 +76,47 @@ def _onload(self): for i in range(64): VARS.lightnote(i,0) - def printletter(letter): - for i in range(4): - for j in range(7): - VARS.light(i,j,letter[j][i]) + VARS.updateinput() + VARS.updatemasterm() + + # sys.exit() - def normalize(i,dec,width,loop): - new=i-dec - # if i==0: - # print(i,dec,new,new%(width+0)) - if new>width: - if not loop: - return -1 - else: - return new%(width+0) - elif new<0: - if not loop: - return -1 - else: - while new<0: # Pretty shit implementation - new+=width - return new - return new - - - def makematrix(matrix,decx=0,decy=0,loop=False): - "Shift a matrix and return the 8x8 to print" - width,height=len(matrix[0]),len(matrix) - toprint=[[0]*8 for i in range(8)] - # print(width) - - for i in range(8): - for j in range(8): - new_x=normalize(i,decx,width,loop) - #new_y=normalize(j,decy,height,loop) - new_y=j - if new_x<0 or new_y<0: - color=0 - else: - try: - color=matrix[new_y][new_x] - except IndexError: - color=0 - toprint[j][i]=color - return toprint - - def printmatrix(newmatrix,oldmatrix=None): - "Print and 8x8 matrix" - for i in range(8): - for j in range(8): - if oldmatrix: - if oldmatrix[j][i]!=newmatrix[j][i]: - VARS.light(i,j,newmatrix[j][i]) - else: - VARS.light(i,j,newmatrix[j][i]) - time.sleep(0.01) - - def clearmatrix(matrix,decx,decy,loop=False): - pass - - newmat=None - for i in range(200): - oldmat,newmat=newmat,makematrix(BIGWORD,-i,0,True) - printmatrix(newmat,oldmat) - time.sleep(0.04) - - # for j in range(0,10): - # time.sleep(0.3) - # printmatrix(BIGWORD) - # # print("E") - # for i in range(64): - # VARS.lightnote(i,0) - # time.sleep(0.2) - # - # printmatrix(BIGWORD,0,0) - # time.sleep(0.01) - - # while 1: - # for k in range(4): - # printletter(WORD[k]) - # time.sleep(0.5) - sys.exit() - - -def presskey(trigger,val,note,*params): - "Press the given keys" - pass#print(val,note,params) - -def switchinput(trigger,val,note,*params): +def switchinput(trigger,val,note,*params): #HARDCODED COLORS ARE BAD "Switch to the desired layer i1" - topress=VARS.findit(note-VARS.BASE_NOTE_INPUT+1,0) + i=note-VARS.BASE_NOTE_INPUT + toup=[VARS.selected_input,i] - VARS.active_input=topress + VARS.INPUTS[VARS.selected_input]=INPUTS[VARS.selected_input] + VARS.selected_input=i + VARS.INPUTS[VARS.selected_input]|=_SELECTED + if VARS.live_input: + VARS.INPUTS[VARS.live_input]|=_LIVE + + VARS.updateinput(toup) - for trigger in trigger.parent.findAction('note_on',note,"*"): - print(trigger.value,trigger.intensity) #pyautogui.hotkey("i",str(topress)) def takeall(trigger,val,note,*params): "Take all TA" + if VARS.live_input!=None: + VARS.INPUTS[VARS.live_input]=INPUTS[VARS.live_input] + toup=[VARS.live_input,VARS.selected_input] + else: + toup=[VARS.selected_input] + + VARS.live_input=VARS.selected_input + VARS.INPUTS[VARS.selected_input]|=_SELECTED + VARS.INPUTS[VARS.live_input]|=_LIVE + VARS.updateinput(toup) + #pyautogui.hotkey("t","a") def mastermemory(trigger,val,note,*params): "Switch to the desired master memory M1" topress=note-BASE_NOTE_MASTERM+1 + + #pyautogui.hotkey("m",str(topress)) # MidiInterface(config) @@ -192,7 +126,6 @@ class MidiInterface(BasicMidiInterface): def __init__(self,configfile): super(MidiInterface,self).__init__(configfile) _onload(self) - self.functionlist["presskey"]=presskey self.functionlist["switchinput"]=switchinput self.functionlist["mastermemory"]=mastermemory self.functionlist["takeall"]=takeall diff --git a/patch/akailoop.ini b/patch/akailoop.ini index 0c42ab3..b9506b0 100644 --- a/patch/akailoop.ini +++ b/patch/akailoop.ini @@ -4,7 +4,7 @@ inputchanel = 1 outputchannel1 = 1 #outputchannel2 = 1 - mapping = keystrokes + mapping = colorplay # 1 Green / Blinking green 3 Red 5 Yellow [note_on] diff --git a/patch/pulse.ini b/patch/pulse.ini index e5ead19..3906826 100644 --- a/patch/pulse.ini +++ b/patch/pulse.ini @@ -10,17 +10,17 @@ 56-63/funct = switchinput() - 56 = 1/on/56/3 ;1/on/57/5 ;1/on/58/5 ;1/on/59/5 ;1/on/60/2 ;1/on/61/5 ;1/on/62/5 ;1/on/63/5 - 57 = 1/on/56/5 ;1/on/57/3 ;1/on/58/5 ;1/on/59/5 ;1/on/60/2 ;1/on/61/5 ;1/on/62/5 ;1/on/63/5 - 58 = 1/on/56/5 ;1/on/57/5 ;1/on/58/3 ;1/on/59/5 ;1/on/60/2 ;1/on/61/5 ;1/on/62/5 ;1/on/63/5 - 59 = 1/on/56/5 ;1/on/57/5 ;1/on/58/5 ;1/on/59/3 ;1/on/60/2 ;1/on/61/5 ;1/on/62/5 ;1/on/63/5 - 60 = 1/on/56/5 ;1/on/57/5 ;1/on/58/5 ;1/on/59/5 ;1/on/60/3 ;1/on/61/5 ;1/on/62/5 ;1/on/63/5 - 61 = 1/on/56/5 ;1/on/57/5 ;1/on/58/5 ;1/on/59/5 ;1/on/60/2 ;1/on/61/3 ;1/on/62/5 ;1/on/63/5 - 62 = 1/on/56/5 ;1/on/57/5 ;1/on/58/5 ;1/on/59/5 ;1/on/60/2 ;1/on/61/5 ;1/on/62/3 ;1/on/63/5 - 63 = 1/on/56/5 ;1/on/57/5 ;1/on/58/5 ;1/on/59/5 ;1/on/60/2 ;1/on/61/5 ;1/on/62/5 ;1/on/63/3 +# 56 = 1/on/56/3 ;1/on/57/5 ;1/on/58/5 ;1/on/59/5 ;1/on/60/2 ;1/on/61/5 ;1/on/62/5 ;1/on/63/5 +# 57 = 1/on/56/5 ;1/on/57/3 ;1/on/58/5 ;1/on/59/5 ;1/on/60/2 ;1/on/61/5 ;1/on/62/5 ;1/on/63/5 +# 58 = 1/on/56/5 ;1/on/57/5 ;1/on/58/3 ;1/on/59/5 ;1/on/60/2 ;1/on/61/5 ;1/on/62/5 ;1/on/63/5 +# 59 = 1/on/56/5 ;1/on/57/5 ;1/on/58/5 ;1/on/59/3 ;1/on/60/2 ;1/on/61/5 ;1/on/62/5 ;1/on/63/5 +# 60 = 1/on/56/5 ;1/on/57/5 ;1/on/58/5 ;1/on/59/5 ;1/on/60/3 ;1/on/61/5 ;1/on/62/5 ;1/on/63/5 +# 61 = 1/on/56/5 ;1/on/57/5 ;1/on/58/5 ;1/on/59/5 ;1/on/60/2 ;1/on/61/3 ;1/on/62/5 ;1/on/63/5 +# 62 = 1/on/56/5 ;1/on/57/5 ;1/on/58/5 ;1/on/59/5 ;1/on/60/2 ;1/on/61/5 ;1/on/62/3 ;1/on/63/5 +# 63 = 1/on/56/5 ;1/on/57/5 ;1/on/58/5 ;1/on/59/5 ;1/on/60/2 ;1/on/61/5 ;1/on/62/5 ;1/on/63/3 48-55/funct = mastermemory() - #98/funct = takeall() + 98/funct = takeall() #[control_change] # 16-18 = 2/cc/1