Skip to content

Commit

Permalink
Ver(1.6): Fix findLibary function (won't work on Linux)
Browse files Browse the repository at this point in the history
  • Loading branch information
duangsuse committed Apr 26, 2020
1 parent 7583fc4 commit 542948a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 5 additions & 1 deletion hachiko_bapu/funutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ def flatMap(f, xs):
for ys in map(f, xs):
for y in ys: yield y

def takePipeIf(p, transform, value):
res = transform(value)
return res if p(res) else value

def findLibrary(name, lib_names, solver=lambda name: [f"./{name}.dll"]) -> str:
paths = filter(isNotNone, map(find_library, lib_names))
for dlls in map(solver, lib_names):
paths = chain(paths, filter(isfile, dlls))

path = next(paths, None) #< appended dll scan
if path == None: raise ImportError(f"couldn't find the {name} library")
else: return abspath(str(path))
else: return takePipeIf(isfile, abspath, str(path)) #< only if found file, not libname in PATH

def createLibrary(path, mode = 1):
lib = CDLL(path)
Expand Down
3 changes: 2 additions & 1 deletion hachiko_bapu/hachi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from .hachitools import *
from .synthesize import NoteSynth
from pkg_resources import resource_filename

def splitAs(type, transform = int, delim = ","):
return lambda it: type(transform(s) for s in it.split(delim))
Expand All @@ -27,7 +28,7 @@ def splitAs(type, transform = int, delim = ","):
askMethod = env("ASK_METHOD", str, "tk")
playDuration = env("PLAY_DURATION", splitAs(list, transform=float), [0.3, 0.5, 1.5])

INSTRUMENT_SF2 = env("SFONT", str, resourcePath("instrument.sf2"))
INSTRUMENT_SF2 = env("SFONT", str, resource_filename(__name__, "instrument.sf2"))
sampleRate = env("SAMPLE_RATE", int, 44100)
sfontPreset = 0 #< used twice

Expand Down
5 changes: 0 additions & 5 deletions hachiko_bapu/hachitools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from threading import Timer
from os import environ
from pkg_resources import resource_filename

SEC_MS = 1000

Expand All @@ -11,10 +10,6 @@ def grayColor(n:int): return (n,n,n)
def env(name:str, transform:Callable[[str],T], default:T) -> T:
return transform(environ[name]) if name in environ else default

def resourcePath(path) -> str:
try: return resource_filename(__name__, path)
except ModuleNotFoundError: return path

def timeout(n_sec:float, op):
timer = Timer(n_sec, op); timer.start()
return timer
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def parse_requirements(requirements):
return list(filter(lambda s: s.strip() != "", items))

setup(
name="hachiko-bapu", version="0.1.5",
name="hachiko-bapu", version="0.1.6",
python_requires=">=3.5",
author="duangsuse", author_email="fedora-opensuse@outlook.com",
url="https://github.com/duangsuse-valid-projects/Hachiko",
Expand Down

0 comments on commit 542948a

Please sign in to comment.