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("-m", "--builtin-mixing",
37 help="Make the mixing of sounds manually (do it if the system cannot handle it correctly)")
38 parser
.add_argument("-l", "--latency",
41 help="Latency: low, high or number of seconds")
42 parser
.add_argument("-b", "--blocksize",
46 help="Blocksize: If not 0, the numbe of frames to take at each step for the mixer")
47 parser
.add_argument("-f", "--frame-rate",
51 help="Frame rate to play the musics")
52 parser
.add_argument("-x", "--channels",
56 help="Number of channels to use")
57 parser
.add_argument("-s", "--sample-width",
61 help="Sample width (number of bytes for each frame)")
62 parser
.add_argument("-V", "--version",
64 help="Displays the current version and exits. Only use in bundled package",
65 version
=show_version())
66 parser
.add_argument("--device",
67 action
=SelectDeviceAction
,
68 help="Select this sound device"
70 parser
.add_argument("--list-devices",
72 action
=ListDevicesAction
,
73 help="List available sound devices"
75 parser
.add_argument('--',
77 help="Kivy arguments. All arguments after this are interpreted by Kivy. Pass \"-- --help\" to get Kivy's usage.")
78 args
= parser
.parse_args(argv
)
80 Config
.yml_file
= args
.config
81 Config
.latency
= args
.latency
82 Config
.blocksize
= args
.blocksize
83 Config
.frame_rate
= args
.frame_rate
84 Config
.channels
= args
.channels
85 Config
.sample_width
= args
.sample_width
86 Config
.builtin_mixing
= args
.builtin_mixing
88 class SelectDeviceAction(argparse
.Action
):
89 def __call__(self
, parser
, namespace
, values
, option_string
=None):
90 sd
.default
.device
= values
92 class ListDevicesAction(argparse
.Action
):
94 def __call__(self
, parser
, namespace
, values
, option_string
=None):
95 print(sd
.query_devices())
99 if getattr(sys
, 'frozen', False):
100 with open(path() + ".pyinstaller_commit", "r") as f
:
103 return "option '-v' can only be used in bundled package"
105 def duration_to_min_sec(duration
):
106 minutes
= int(duration
/ 60)
107 seconds
= int(duration
) % 60
109 return "{:2}:{:0>2}".format(minutes
, seconds
)
111 return "{}:{:0>2}".format(minutes
, seconds
)
113 def gain(volume
, old_volume
= None):
114 if old_volume
is None:
115 return 20 * math
.log10(volume
/ 100)
117 return [20 * math
.log10(max(volume
, 0.1) / max(old_volume
, 0.1)), max(volume
, 0)]