Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
c67f3f2
univaersal shortcut parser for ck extensions
narcode Feb 19, 2020
9e3e29a
allow for shortuts with up to 2 modifier keys
narcode Mar 12, 2020
9f3e079
allow for alernative evaluation or shortcut mappings for snippets
narcode Mar 12, 2020
ba6995b
debug new shortcuts
narcode Mar 12, 2020
e299e1e
debug new shortcuts
narcode Mar 12, 2020
44ea14d
debug new shortcuts
narcode Mar 12, 2020
30f2374
debug new shortcuts
narcode Mar 12, 2020
5246373
debug new shortcuts
narcode Mar 12, 2020
40e0193
debug new shortcuts
narcode Mar 12, 2020
c756c89
debug new shortcuts
narcode Mar 12, 2020
aac92d2
nightly
narcode Mar 12, 2020
331dc4f
goofd night ane
narcode Mar 12, 2020
cd4b045
goofd night ane
narcode Mar 12, 2020
12a614a
good night gine lady with baby
narcode Mar 12, 2020
07616bb
shortcuts in mini motifs
narcode Mar 13, 2020
e00d776
fixed release of modifier keys in ini shortcuts
narcode Mar 13, 2020
c8da79d
fix anne bug whats app stuff
narcode Mar 14, 2020
5c3134c
allow eval to use single keyboard chars
narcode Mar 15, 2020
9f3c512
anne anne anne
narcode Mar 15, 2020
0bfbe8a
anne anne anne
narcode Mar 15, 2020
4edccca
dear anne the shortcuts are working as you want. take care and wish y…
narcode Mar 15, 2020
a410e3c
super anne super mom
narcode Mar 16, 2020
1747b38
super anne super mom
narcode Mar 16, 2020
ffd4275
add release duh anne get us a new grant and free soda and choco
narcode Mar 16, 2020
04c28c7
fixed ck_loop deltatime crash
narcode Mar 18, 2020
916d943
anne loves this etensions
narcode Mar 18, 2020
cea6fd6
anne loves this etensions
narcode Mar 18, 2020
cd8ebee
anne chord face
narcode Mar 18, 2020
588226c
custom prefix and suffix for tremolo snippets
narcode Mar 24, 2020
c28a890
anne keeps bringing stuff
narcode Mar 25, 2020
baa94e0
anne keeps bringing stuff
narcode Mar 25, 2020
92b9fe3
anne says wait wait
narcode Mar 25, 2020
2472833
trying to patch within ini
narcode Mar 25, 2020
167ac8d
trying to patch within ini
narcode Mar 25, 2020
fd46705
trying to patch within ini
narcode Mar 25, 2020
fa972c1
trying to patch within ini
narcode Mar 25, 2020
c860bdf
trying to patch within ini
narcode Mar 25, 2020
15b9baa
trying to patch within ini
narcode Mar 25, 2020
b56e1d3
trying to patch within ini
narcode Mar 25, 2020
dfa0852
trying to patch within ini quick test
narcode Mar 25, 2020
5a2721c
make a none
narcode Mar 25, 2020
9830b8c
send empty space at the end of line
narcode Mar 25, 2020
5d8b0c8
debug message sout
narcode Mar 25, 2020
55e67f4
opes
narcode Mar 25, 2020
b1eadb7
debug message sout
narcode Mar 25, 2020
10f1171
eval: none in .ini disables autoevaluate in general
narcode Mar 25, 2020
69d9732
anne has 15
narcode Mar 30, 2020
ec4e353
anne has 15
narcode Mar 30, 2020
89fbc95
big motif counter flag limit
narcode Mar 30, 2020
d7b2b67
big motif counter flag limit
narcode Mar 30, 2020
d200c10
belly
narcode Mar 30, 2020
2c1814e
belly
narcode Mar 30, 2020
581b2ff
add fucliong scapace
narcode Mar 30, 2020
ce1e094
better function for getting the eval shortcuts
narcode Apr 8, 2020
29c729e
anna
narcode Apr 8, 2020
6f77191
anne wants this and that
narcode Apr 8, 2020
88227f8
anne wants this and that
narcode Apr 8, 2020
945dfb6
anne wants this and that
narcode Apr 8, 2020
968433e
anne wants this and that
narcode Apr 8, 2020
42e3481
anne wants this and that
narcode Apr 8, 2020
77df805
anne wants this and that
narcode Apr 8, 2020
ecb5e7b
anne wants this and that
narcode Apr 8, 2020
bcaf900
corrected deltatimes passing into parse midi func
narcode Apr 8, 2020
5791fbe
better tremolo recognition
narcode Apr 8, 2020
70fe9ea
better tremolo recognition
narcode Apr 8, 2020
52335de
better tremolo recognition
narcode Apr 8, 2020
7018a02
better tremolo recognition
narcode Apr 8, 2020
76b7d31
clean output
narcode Apr 8, 2020
d0ef57d
denug shortcut
narcode Apr 8, 2020
3956f48
denug shortcut
narcode Apr 8, 2020
88605f1
denug shortcut
narcode Apr 8, 2020
546afb7
shortcuts are ok
narcode Apr 8, 2020
96c772a
cmon orca
narcode Apr 8, 2020
987a2ad
debug msg out
narcode Apr 8, 2020
e2fa4cd
remove debug messages and correct tremolo full sarg
narcode Apr 8, 2020
e7f5c84
anne wihtout glasses lokfunn
narcode Apr 9, 2020
df08bc0
anne get a bikinni and enjoy the sun wioth yiour loved ones
narcode Apr 9, 2020
66ebfd5
anne whats ur favourite programming language?
narcode Apr 9, 2020
c1002db
anne show us ur white spot
narcode Apr 9, 2020
6ff49bb
add enter annes universal solution to happiness problems
narcode Apr 15, 2020
d737007
anne broke trems?
narcode Apr 15, 2020
9df8195
add enter annes universal solution to happiness problems
narcode Apr 15, 2020
0438eb5
fix perpetual flag on range counter
narcode Apr 22, 2020
2e8def5
support up to 5 cond. before was max 3
narcode Apr 23, 2020
cd85158
its not wednsday
narcode Apr 23, 2020
d4d056f
its not wednsdaygit add . git add .
narcode Apr 23, 2020
b0c3d86
anne wants scaling now he he
narcode May 13, 2020
688164c
parse floats or ints
narcode May 13, 2020
bfff70a
no cool nick numbers
narcode May 13, 2020
d33216b
better faster stronger regex for annes extensions scaling belly
narcode May 20, 2020
0c92c5d
better faster stronger regex for annes extensions scaling belly
narcode May 20, 2020
7d45fa2
anne is the best belly and m,ilk feeder ever
narcode May 20, 2020
fc2ab66
toggel can have an optional callback
narcode May 20, 2020
196d4a1
anne is dressed up for a quickie OMG
narcode May 20, 2020
f96c1bc
little cheat if a 0 is given in the exp range
narcode May 20, 2020
39f9315
saled value var init
narcode May 22, 2020
c8680e0
test on wednsaday the ck day jeeeeeeez
narcode May 22, 2020
e290db0
poppers for anne
narcode May 22, 2020
4f80e48
anne veinberg is so nice
narcode May 27, 2020
314c69d
allow for floats in random ranges from ini
narcode May 27, 2020
c8ef9eb
anne wants floats , of course and coffie and milk
narcode May 27, 2020
5df6779
better scaling func for tremolos
narcode May 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 154 additions & 26 deletions CodeKlavier/Mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, debug=True, snippets='snippets code output'):
self._osc = udp_client.SimpleUDPClient('127.0.0.1', 57120) #standard supercollider OSC listening port

def evaluate(self, what, flash=True, display=5):
"""Evaluate the SuperCollider command 'what'
"""Evaluate the mapped command 'what' from .ini file

:param string what: the command that should be evaluated
:param bool flash: should eval command flash the screen
Expand Down Expand Up @@ -81,16 +81,56 @@ def evaluate(self, what, flash=True, display=5):
self.__keyboard.type('e')
self.__keyboard.release(Key.cmd)
elif what == 'eval':
with self.__keyboard.pressed(eval('Key.'+self._shortcuts[what][0].strip())):
self.__keyboard.press(eval('Key.'+self._shortcuts[what][1].strip()))
self.__keyboard.release(eval('Key.'+self._shortcuts[what][1].strip()))
time.sleep(0.2)
self.__keyboard.press(Key.enter)
self.__keyboard.release(Key.enter)
if len(self._shortcuts[what]) == 1:
if len(self._shortcuts[what][0].strip()) > 1:
if self._shortcuts[what][0].strip() == 'none': #TODO: make a better function
self.parseShortcut('eval_manual')
else:
self.__keyboard.press(eval('Key.'+self._shortcuts[what][0].strip()))
else:
self.__keyboard.type(self._shortcuts[what][0].strip())
else:
with self.__keyboard.pressed(eval('Key.'+self._shortcuts[what][0].strip())):
if len(self._shortcuts[what][1].strip()) > 1:
self.__keyboard.press(eval('Key.'+self._shortcuts[what][1].strip()))
else:
self.__keyboard.type(self._shortcuts[what][1].strip())
time.sleep(0.2)
self.__keyboard.press(Key.enter)
self.__keyboard.release(Key.enter)
elif what == 'noEnter_eval':
with self.__keyboard.pressed(Key.shift):
self.__keyboard.press(Key.enter)
self.__keyboard.release(Key.enter)
else:
self.parseShortcut(what)


def parseShortcut(self, what):
""" parse the evaluate code from the ini file"""
if len(self._shortcuts[what]) == 3:
with self.__keyboard.pressed(eval('Key.'+self._shortcuts[what][0].strip()),
eval('Key.'+self._shortcuts[what][1].strip())):
if len(self._shortcuts[what][2].strip()) > 1:
self.__keyboard.press(eval('Key.'+self._shortcuts[what][2].strip()))
else:
self.__keyboard.type(self._shortcuts[what][2].strip())

elif len(self._shortcuts[what]) == 2:
with self.__keyboard.pressed(eval('Key.'+self._shortcuts[what][0].strip())):
if len(self._shortcuts[what][1].strip()) > 1:
self.__keyboard.press(eval('Key.'+self._shortcuts[what][1].strip()))
else:
self.__keyboard.type(self._shortcuts[what][1].strip());

else:
if len(self._shortcuts[what][0].strip()) > 1:
self.__keyboard.press(eval('Key.'+self._shortcuts[what][0].strip()))
self.__keyboard.release(eval('Key.'+self._shortcuts[what][0].strip()))
else:
self.__keyboard.type(self._shortcuts[what][0].strip());
self.__keyboard.type(' ');


def goDown(self, display=5):
"""Press command-arrow down and enter.
Expand Down Expand Up @@ -215,17 +255,31 @@ def snippets(self, motif):
:param str motif: the name of the motif to map
"""
displays = [1,2]
#num = re.search(r"\d", motif).group()
try:
evaluate = self._config['shortcuts mapping'].get(motif)
except KeyError:
print('fallback eval')

if evaluate == None:
if self._config['shortcuts'].get('eval') != 'none':
evaluate = 'eval'

#display = displays[(int(num)-1)%len(displays)]
try:
display = self._config['motippets display settings'].getint(motif)
snippet = self._config['snippets code output'].get(motif)
self.__keyboard.type(snippet)
self.formatAndSend(snippet, display=display, syntax_color='snippet:')
self.evaluate('eval', flash=False)
except KeyError:
print(motif, 'does not exists in the snippets code output section of .ini file')

if evaluate == 'eval': #automatic evaluation
self.__keyboard.type(snippet)
self.formatAndSend(snippet, display=display, syntax_color='snippet:')
self.evaluate(evaluate, flash=False)
elif evaluate == None: #disabled automatic evaluation
self.__keyboard.type(snippet)
self.__keyboard.type(' ')
self.formatAndSend(snippet, display=display, syntax_color='snippet:')
else: # just a keyboadshortcut and without printed code
self.evaluate(evaluate, flash=False)

def miniSnippets(self, motif, pianosection, callback=None):
"""Type a mini snippet for specific pianosections'utf-8'
Expand All @@ -241,49 +295,120 @@ def miniSnippets(self, motif, pianosection, callback=None):
except KeyError:
print(motif, 'missing in snippets code output or motippets display settings')

try:
evaluate = self._config['shortcuts mapping'].get(motif)
except KeyError:
print('fallback eval')

if evaluate == None:
if self._config['shortcuts'].get('eval') != 'none':
evaluate = 'eval'

if display == None:
display = '### no display setting for ' + motif + ' in .ini ###'
if snippet == None:
snippet = '### code output error with ' + motif + ' (check .ini) ###'

if callback == None:
self.__keyboard.type(snippet)
self.evaluate('eval', flash=False)
self.formatAndSend(snippet, display=display, syntax_color=pianosection+':')
if evaluate == 'eval':
self.__keyboard.type(snippet)
self.evaluate(evaluate, flash=False)
self.formatAndSend(snippet, display=display, syntax_color=pianosection+':')
elif evaluate == None:
self.__keyboard.type(snippet)
self.__keyboard.type(' ')
self.formatAndSend(snippet, display=display, syntax_color=pianosection+':')
else:
self.evaluate(evaluate, flash=False)
else:
self.__keyboard.type(snippet)
self.evaluate('eval', flash=False)
self.formatAndSend(snippet, display=display, syntax_color=pianosection+':')
if evaluate == 'eval':
self.__keyboard.type(snippet)
self.evaluate(evaluate, flash=False)
self.formatAndSend(snippet, display=display, syntax_color=pianosection+':')
elif evaluate == None:
self.__keyboard.type(snippet)
self.__keyboard.type(' ')
self.formatAndSend(snippet, display=display, syntax_color=pianosection+':')
else:
self.evaluate(evaluate, flash=False)

callback_snippet = self._config['snippets code output callback'].get(callback)
if callback_snippet == None:
callback_snippet = '### callback error with ' + callback + ' (check .ini) ###'

self.__keyboard.type(callback_snippet)
self.evaluate('eval', flash=False)
self.formatAndSend(callback_snippet, display=display, syntax_color='low:')
if evaluate == 'eval':
self.evaluate(evaluate, flash=False)
self.formatAndSend(callback_snippet, display=display, syntax_color='low:')
elif evaluate == None:
self.formatAndSend(callback_snippet, display=display, syntax_color='low:')

def tremolo(self, motif, value, syntax_color):
def tremolo(self, motif, value, syntax_color, debug=False):
"""Type the tremolo command + the tremolo-value

:param string motif: the motif name to be mapped and prependend to the tremolo value.
:param int value: the tremolo value as distance between the notes
"""

code = self._config['snippets for tremolos'].get(motif)
display = self._config['motippets display settings'].getint(motif)
prefix = ''
suffix = ''

if display == None:
display = '### no display setting for ' + motif + ' in .ini ###'
if code == None:
print('### tremolo error with ' + motif + ' (check .ini) ###')
if debug:
print('### tremolo error with ' + motif + ' (check .ini) ###')

def scale(value, minmax):
minout = float(minmax[0])
if minout == 0:
minout = 0.0000000000001

if len(minmax) == 3:
if value >= 16:
return float(minmax[1])
return round( pow( (value - 1) / (16-1), float(minmax[2]) )
* (float(minmax[1]) - float(minmax[0]))
+ float(minmax[0]),
2)
else:
return value

if code != None:
self.__keyboard.type(code + ' ' + str(value))
self.formatAndSend(code + ' ' + str(value), display=display, syntax_color=syntax_color+':')
scaled_value = str(value)
code = code.split(',')
scaling = [x for x in code if re.match("minmax.+", x)]
if len(scaling) == 1:
scaling = re.findall("[0-9.?]+", scaling[0])
code.pop()
if len(scaling) > 2:
scaled_value = str(scale(value, scaling))
else:
scaled_value = str(scale(value, scaling+['1']))
if len(code) == 2:
prefix = code[1]
elif len(code) == 3:
prefix = code[1]
suffix = code[2]

self.__keyboard.type(code[0] + prefix + scaled_value + suffix)
self.__keyboard.type(' ')
self.formatAndSend(code[0] + prefix + scaled_value + suffix, display=display, syntax_color=syntax_color+':')

try:
evaluate = self._config['shortcuts mapping'].get(motif)
except KeyError:
print('fallback eval')

if evaluate == None:
if self._config['shortcuts'].get('eval') != 'none':
evaluate = 'eval'

flash = display == 5
self.evaluate('eval', flash=flash)
if evaluate == 'eval':
self.evaluate('eval', flash=flash)


def conditional(self, motif):
"""Setup a conditional
Expand Down Expand Up @@ -322,6 +447,9 @@ def result(self, motif_name, text, mod=0, flags=None):
display = 3
syntax_color = self._config['motippets display settings'].get(motif_name)

self.__keyboard.press(Key.enter)
self.__keyboard.release(Key.enter)

if flags in ('gomb', ):
output = [r.strip() for r in self._config['snippets code output'].get(motif_name+'_'+text).split(',')]
self.__keyboard.type('GOMB countdown started!')
Expand Down
Loading