Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
hobyst committed Jul 8, 2020
2 parents 36fdc45 + b51979e commit d8aa28e
Show file tree
Hide file tree
Showing 2 changed files with 250 additions and 11 deletions.
96 changes: 85 additions & 11 deletions device_Komplete Kontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@
import math

# Imports the low-level threading module
import _thread
# threading module isn't supported by FL's interpreter but _thread does
# However, using _thread makes FL crash eventually at launch on Windows and it isn't compatible with the macOS Python interpreter
# Using _dummy_thread instead
import sys

if sys.platform == "win32":
print("Windows OS detected. Imported _thread module.")
import _thread

if sys.platform == "darwin":
print("macOS detected. Imported _dummy_thread module.")
import lib._dummy_thread as _thread

######################################################################################################################
# User-editable constants for script customization
Expand Down Expand Up @@ -145,6 +156,37 @@ def updateMixerTracks(dataType: str, selectedTrack: int):
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", 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 updateMixer():
""" Updates every property of the mixer of the deivce but the peak values. """
Expand Down Expand Up @@ -181,10 +223,10 @@ def adjustMixer(knob: int, dataType: str, action: str, selectedTrack: int):

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

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

if dataType == "PAN":
if action == "INCREASE":
Expand Down Expand Up @@ -567,11 +609,19 @@ def OnMidiIn(event):

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

if event.data1 == nihia.knobs.get("KNOB_8A") and event.data2 == nihia.knobs.get("INCREASE"):
event.handled = True
adjustMixer(7, "VOLUME", "INCREASE", mixer.trackNumber())
# 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
if event.data1 == nihia.knobs.get("KNOB_1A") and event.data2 == nihia.knobs.get("DECREASE"):
Expand Down Expand Up @@ -600,11 +650,19 @@ def OnMidiIn(event):

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

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



Expand Down Expand Up @@ -635,11 +693,19 @@ def OnMidiIn(event):

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

if event.data1 == nihia.knobs.get("KNOB_8B") and event.data2 == nihia.knobs.get("INCREASE"):
event.handled = True
adjustMixer(7, "PAN", "INCREASE", mixer.trackNumber())
# 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
if event.data1 == nihia.knobs.get("KNOB_1B") and event.data2 == nihia.knobs.get("DECREASE"):
Expand Down Expand Up @@ -668,11 +734,19 @@ def OnMidiIn(event):

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

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

######################################################################################################################
# Script logic
Expand Down
165 changes: 165 additions & 0 deletions lib/_dummy_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Copyright © 2001-2020 Python Software Foundation; All Rights Reserved

"""Drop-in replacement for the thread module.
Meant to be used as a brain-dead substitute so that threaded code does
not need to be rewritten for when the thread module is not present.
Suggested usage is::
try:
import _thread
except ImportError:
import _dummy_thread as _thread
"""
# Exports only things specified by thread documentation;
# skipping obsolete synonyms allocate(), start_new(), exit_thread().
__all__ = ['error', 'start_new_thread', 'exit', 'get_ident', 'allocate_lock',
'interrupt_main', 'LockType']

# A dummy value
TIMEOUT_MAX = 2**31

# NOTE: this module can be imported early in the extension building process,
# and so top level imports of other modules should be avoided. Instead, all
# imports are done when needed on a function-by-function basis. Since threads
# are disabled, the import lock should not be an issue anyway (??).

error = RuntimeError

def start_new_thread(function, args, kwargs={}):
"""Dummy implementation of _thread.start_new_thread().
Compatibility is maintained by making sure that ``args`` is a
tuple and ``kwargs`` is a dictionary. If an exception is raised
and it is SystemExit (which can be done by _thread.exit()) it is
caught and nothing is done; all other exceptions are printed out
by using traceback.print_exc().
If the executed function calls interrupt_main the KeyboardInterrupt will be
raised when the function returns.
"""
if type(args) != type(tuple()):
raise TypeError("2nd arg must be a tuple")
if type(kwargs) != type(dict()):
raise TypeError("3rd arg must be a dict")
global _main
_main = False
try:
function(*args, **kwargs)
except SystemExit:
pass
except:
import traceback
traceback.print_exc()
_main = True
global _interrupt
if _interrupt:
_interrupt = False
raise KeyboardInterrupt

def exit():
"""Dummy implementation of _thread.exit()."""
raise SystemExit

def get_ident():
"""Dummy implementation of _thread.get_ident().
Since this module should only be used when _threadmodule is not
available, it is safe to assume that the current process is the
only thread. Thus a constant can be safely returned.
"""
return -1

def allocate_lock():
"""Dummy implementation of _thread.allocate_lock()."""
return LockType()

def stack_size(size=None):
"""Dummy implementation of _thread.stack_size()."""
if size is not None:
raise error("setting thread stack size not supported")
return 0

def _set_sentinel():
"""Dummy implementation of _thread._set_sentinel()."""
return LockType()

class LockType(object):
"""Class implementing dummy implementation of _thread.LockType.
Compatibility is maintained by maintaining self.locked_status
which is a boolean that stores the state of the lock. Pickling of
the lock, though, should not be done since if the _thread module is
then used with an unpickled ``lock()`` from here problems could
occur from this class not having atomic methods.
"""

def __init__(self):
self.locked_status = False

def acquire(self, waitflag=None, timeout=-1):
"""Dummy implementation of acquire().
For blocking calls, self.locked_status is automatically set to
True and returned appropriately based on value of
``waitflag``. If it is non-blocking, then the value is
actually checked and not set if it is already acquired. This
is all done so that threading.Condition's assert statements
aren't triggered and throw a little fit.
"""
if waitflag is None or waitflag:
self.locked_status = True
return True
else:
if not self.locked_status:
self.locked_status = True
return True
else:
if timeout > 0:
import time
time.sleep(timeout)
return False

__enter__ = acquire

def __exit__(self, typ, val, tb):
self.release()

def release(self):
"""Release the dummy lock."""
# XXX Perhaps shouldn't actually bother to test? Could lead
# to problems for complex, threaded code.
if not self.locked_status:
raise error
self.locked_status = False
return True

def locked(self):
return self.locked_status

def __repr__(self):
return "<%s %s.%s object at %s>" % (
"locked" if self.locked_status else "unlocked",
self.__class__.__module__,
self.__class__.__qualname__,
hex(id(self))
)

# Used to signal that interrupt_main was called in a "thread"
_interrupt = False
# True when not executing in a "thread"
_main = True

def interrupt_main():
"""Set _interrupt flag to True to have start_new_thread raise
KeyboardInterrupt upon exiting."""
if _main:
raise KeyboardInterrupt
else:
global _interrupt
_interrupt = True

0 comments on commit d8aa28e

Please sign in to comment.