]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - helpers/__init__.py
1 # -*- coding: utf-8 -*-
8 def __init__(self
, **kwargs
):
10 setattr(self
, arg
, kwargs
[arg
])
12 config
= Config(yml_file
="config.yml")
15 if getattr(sys
, 'frozen', False):
16 return sys
._MEIPASS
+ "/"
18 path
= os
.path
.dirname(os
.path
.realpath(__file__
))
23 sys
.argv
= sys
.argv
[:1]
25 index
= argv
.index("--")
26 kivy_args
= argv
[index
+1:]
29 sys
.argv
.extend(kivy_args
)
31 parser
= argparse
.ArgumentParser(description
="A Music Sampler application.")
32 parser
.add_argument("-c", "--config",
35 help="Config file to load")
36 parser
.add_argument("-V", "--version",
38 help="Displays the current version and exits. Only use in bundled package",
39 version
=show_version())
40 parser
.add_argument('--',
42 help="Kivy arguments. All arguments after this are interpreted by Kivy. Pass \"-- --help\" to get Kivy's usage.")
43 args
= parser
.parse_args(argv
)
45 config
.yml_file
= args
.config
48 if getattr(sys
, 'frozen', False):
49 with open(path() + ".pyinstaller_commit", "r") as f
:
52 return "option '-v' can only be used in bundled package"
55 return config
.yml_file
57 def duration_to_min_sec(duration
):
58 minutes
= int(duration
/ 60)
59 seconds
= int(duration
) % 60
61 return "{:2}:{:0>2}".format(minutes
, seconds
)
63 return "{}:{:0>2}".format(minutes
, seconds
)
65 def gain(volume
, old_volume
= None):
66 if old_volume
is None:
67 return 20 * math
.log10(volume
/ 100)
69 return [20 * math
.log10(max(volume
, 0.1) / max(old_volume
, 0.1)), max(volume
, 0)]