parser.add_argument("-s","--save",action='store',dest="directory",help="Use this directory to save. Will be created or loaded from if already present. Deactivates Agordejo/New-Session-Manager support.")
parser.add_argument("-p","--profiler",action='store_true',help="(Development) Run the python profiler and produce a .cprof file at quit. The name will appear in your STDOUT.")
parser.add_argument("-m","--mute",action='store_true',help="(Development) Use a fake cbox module, effectively deactivating midi and audio.")
parser.add_argument("-V","--verbose",action='store_true',help="(Development) Switch the logger to INFO and print out all kinds of information to get a high-level idea of what the program is doing.")
#"lib": os.path.join(prefix, "lib", METADATA["shortName"]), #cbox is found via the PYTHONPATH
}
_root=os.path.dirname(__file__)
_root=os.path.abspath(os.path.join(_root,".."))
importzipfile
importtempfile
logger.info("Extracting shared library to temporary directory")
zipfilePath=get_script_dir().rstrip("/template")
assertzipfile.is_zipfile(zipfilePath),(zipfilePath)#in our tests this worked. but in lss this results not in a zip file header. linux file also says it is no zip. However, unzip works.
#Extract included .so to tmp dir, tmp dir gets garbage collected at the end of our program.
libsharedDir=tempfile.TemporaryDirectory()
#Not compiled, not installed. Running pure python directly in the source tree.
else:
_root=os.path.dirname(__file__)
_root=os.path.abspath(os.path.join(_root,".."))
PATHS={#this gets imported
"root":_root,
"bin":_root,
"doc":os.path.join(_root,"documentation","out"),
"desktopfile":os.path.join(_root,"desktop","desktop.desktop"),#not ~/Desktop but our desktop file
#NSM changes our cwd to whereever we started new-session-manager from.
#print (os.getcwd())
importsys
fromosimportgetenv
ifnotgetenv("NSM_URL"):#NSMClient checks for this itself but we can anticipate an error and inform the user.
path=ChooseSessionDirectory(qtApp).path#ChooseSessionDirectory is calling exec. We can't call qtapp.exec_ because that blocks forever, even after quitting the window.
#qSessionDirApp.quit()
#del qSessionDirApp
#path = "/tmp"
ifpath:
startPseudoNSMServer(path)
else:
sys.exit()
#message = f"""Please start {prettyName} only through the New Session Manager (NSM) or use the --save command line parameter."""
#exitWithMessage(message)
def_is_jack_running():
"""Check for JACK"""
importctypes
importos
silent=os.open(os.devnull,os.O_WRONLY)
stdout=os.dup(1)
stderr=os.dup(2)
os.dup2(silent,1)#stdout
os.dup2(silent,2)#stderr
cjack=ctypes.cdll.LoadLibrary("libjack.so.0")
classjack_client_t(ctypes.Structure):
_fields_=[]
cjack.jack_client_open.argtypes=[ctypes.c_char_p,ctypes.c_int,ctypes.POINTER(ctypes.c_int)]#the two ints are enum and pointer to enum. #http://jackaudio.org/files/docs/html/group__ClientFunctions.html#gab8b16ee616207532d0585d04a0bd1d60
startSingleNSMServer(path)#provides NSM_URL environment variable and a limited drop-in replacement for NSM that will only answer to our application
assertgetenv("NSM_URL")
sys.path.append("sitepackages")# If you compiled but did not install you can still run with the local build of cbox in our temp dir sitepackages. Add path to the last place, in case there is an installed or bundled version
ifargs.directory:
#Switch to the mode without NSM.
startPseudoNSMServer(args.directory)
checkNsmOrExit(METADATA["name"])
checkJackOrExit(args.mute,METADATA["name"])
try:
#Only cosmetics
setProcessName(METADATA["shortName"])
except:
pass
ifargs.mute:
"""This uses the fact that imports are global and only triggered once.
libname=ctypes.util.find_library("calfbox-lss")#returns something like 'libcalfbox-lss.so.1' without a path, but with "lib"
iflibname:
logger.info(f"libcalfbox-lss name is {libname}")
os.environ["CALFBOXLIBFILENAME"]="calfbox-lss"#let _cbox2 use ctypes to find the name and path again. We just need to tell it that we are not the standard cbox file name.