]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - helpers/__init__.py
4b9529dc8b64b2b7869bb07c5c7b62135c391270
1 # -*- coding: utf-8 -*-
6 import sounddevice
as sd
9 def __init__(self
, **kwargs
):
11 setattr(self
, arg
, kwargs
[arg
])
13 config
= Config(yml_file
="config.yml")
16 if getattr(sys
, 'frozen', False):
17 return sys
._MEIPASS
+ "/"
19 path
= os
.path
.dirname(os
.path
.realpath(__file__
))
24 sys
.argv
= sys
.argv
[:1]
26 index
= argv
.index("--")
27 kivy_args
= argv
[index
+1:]
30 sys
.argv
.extend(kivy_args
)
32 parser
= argparse
.ArgumentParser(description
="A Music Sampler application.")
33 parser
.add_argument("-c", "--config",
36 help="Config file to load")
37 parser
.add_argument("-V", "--version",
39 help="Displays the current version and exits. Only use in bundled package",
40 version
=show_version())
41 parser
.add_argument("--device",
42 action
=SelectDeviceAction
,
43 help="Select this sound device"
45 parser
.add_argument("--list-devices",
47 action
=ListDevicesAction
,
48 help="List available sound devices"
50 parser
.add_argument('--',
52 help="Kivy arguments. All arguments after this are interpreted by Kivy. Pass \"-- --help\" to get Kivy's usage.")
53 args
= parser
.parse_args(argv
)
55 config
.yml_file
= args
.config
57 class SelectDeviceAction(argparse
.Action
):
58 def __call__(self
, parser
, namespace
, values
, option_string
=None):
59 sd
.default
.device
= values
61 class ListDevicesAction(argparse
.Action
):
63 def __call__(self
, parser
, namespace
, values
, option_string
=None):
64 print(sd
.query_devices())
68 if getattr(sys
, 'frozen', False):
69 with open(path() + ".pyinstaller_commit", "r") as f
:
72 return "option '-v' can only be used in bundled package"
75 return config
.yml_file
77 def duration_to_min_sec(duration
):
78 minutes
= int(duration
/ 60)
79 seconds
= int(duration
) % 60
81 return "{:2}:{:0>2}".format(minutes
, seconds
)
83 return "{}:{:0>2}".format(minutes
, seconds
)
85 def gain(volume
, old_volume
= None):
86 if old_volume
is None:
87 return 20 * math
.log10(volume
/ 100)
89 return [20 * math
.log10(max(volume
, 0.1) / max(old_volume
, 0.1)), max(volume
, 0)]