1 # -*- coding: utf-8 -*-
6 import sounddevice
as sd
12 if getattr(sys
, 'frozen', False):
13 return sys
._MEIPASS
+ "/"
15 path
= os
.path
.dirname(os
.path
.realpath(__file__
))
20 sys
.argv
= sys
.argv
[:1]
22 index
= argv
.index("--")
23 kivy_args
= argv
[index
+1:]
26 sys
.argv
.extend(kivy_args
)
28 parser
= argparse
.ArgumentParser(
29 description
="A Music Sampler application.",
30 formatter_class
=argparse
.ArgumentDefaultsHelpFormatter
)
31 parser
.add_argument("-c", "--config",
34 help="Config file to load")
35 parser
.add_argument("-l", "--latency",
38 help="Latency: low, high or number of seconds")
39 parser
.add_argument("-b", "--blocksize",
43 help="Blocksize: If not 0, the numbe of frames to take at each step for the mixer")
44 parser
.add_argument("-f", "--frame-rate",
48 help="Frame rate to play the musics")
49 parser
.add_argument("-x", "--channels",
53 help="Number of channels to use")
54 parser
.add_argument("-s", "--sample-width",
58 help="Sample width (number of bytes for each frame)")
59 parser
.add_argument("-V", "--version",
61 help="Displays the current version and exits. Only use in bundled package",
62 version
=show_version())
63 parser
.add_argument("--device",
64 action
=SelectDeviceAction
,
65 help="Select this sound device"
67 parser
.add_argument("--list-devices",
69 action
=ListDevicesAction
,
70 help="List available sound devices"
72 parser
.add_argument('--',
74 help="Kivy arguments. All arguments after this are interpreted by Kivy. Pass \"-- --help\" to get Kivy's usage.")
75 args
= parser
.parse_args(argv
)
77 Config
.yml_file
= args
.config
78 Config
.latency
= args
.latency
79 Config
.blocksize
= args
.blocksize
80 Config
.frame_rate
= args
.frame_rate
81 Config
.channels
= args
.channels
82 Config
.sample_width
= args
.sample_width
84 class SelectDeviceAction(argparse
.Action
):
85 def __call__(self
, parser
, namespace
, values
, option_string
=None):
86 sd
.default
.device
= values
88 class ListDevicesAction(argparse
.Action
):
90 def __call__(self
, parser
, namespace
, values
, option_string
=None):
91 print(sd
.query_devices())
95 if getattr(sys
, 'frozen', False):
96 with open(path() + ".pyinstaller_commit", "r") as f
:
99 return "option '-v' can only be used in bundled package"
101 def duration_to_min_sec(duration
):
102 minutes
= int(duration
/ 60)
103 seconds
= int(duration
) % 60
105 return "{:2}:{:0>2}".format(minutes
, seconds
)
107 return "{}:{:0>2}".format(minutes
, seconds
)
109 def gain(volume
, old_volume
= None):
110 if old_volume
is None:
111 return 20 * math
.log10(volume
/ 100)
113 return [20 * math
.log10(max(volume
, 0.1) / max(old_volume
, 0.1)), max(volume
, 0)]