]>
Commit | Line | Data |
---|---|---|
1df30f07 | 1 | # -*- coding: utf-8 -*- |
71715c04 | 2 | import argparse |
bb69f62e IB |
3 | import sys |
4 | import os | |
1b4b78f5 | 5 | import math |
bb69f62e | 6 | |
9b9dd12a IB |
7 | class Config: |
8 | def __init__(self, **kwargs): | |
9 | for arg in kwargs: | |
10 | setattr(self, arg, kwargs[arg]) | |
11 | ||
12 | config = Config(yml_file="config.yml") | |
13 | ||
bb69f62e IB |
14 | def path(): |
15 | if getattr(sys, 'frozen', False): | |
16 | return sys._MEIPASS + "/" | |
17 | else: | |
18 | path = os.path.dirname(os.path.realpath(__file__)) | |
19 | return path + "/../" | |
20 | ||
cc008de4 | 21 | def parse_args(): |
71715c04 IB |
22 | argv = sys.argv[1:] |
23 | sys.argv = sys.argv[:1] | |
24 | if "--" in argv: | |
25 | index = argv.index("--") | |
26 | kivy_args = argv[index+1:] | |
27 | argv = argv[:index] | |
28 | ||
29 | sys.argv.extend(kivy_args) | |
30 | ||
31 | parser = argparse.ArgumentParser(description="A Music Sampler application.") | |
32 | parser.add_argument("-c", "--config", | |
33 | default="config.yml", | |
34 | required=False, | |
35 | help="Config file to load") | |
36 | parser.add_argument("-V", "--version", | |
37 | action="version", | |
38 | help="Displays the current version and exits. Only use in bundled package", | |
39 | version=show_version()) | |
40 | parser.add_argument('--', | |
41 | dest="args", | |
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) | |
44 | ||
45 | config.yml_file = args.config | |
46 | ||
47 | def show_version(): | |
48 | if getattr(sys, 'frozen', False): | |
49 | with open(path() + ".pyinstaller_commit", "r") as f: | |
50 | return f.read() | |
51 | else: | |
52 | return "option '-v' can only be used in bundled package" | |
cc008de4 | 53 | |
9b9dd12a IB |
54 | def yml_file(): |
55 | return config.yml_file | |
56 | ||
98ff4305 IB |
57 | def duration_to_min_sec(duration): |
58 | minutes = int(duration / 60) | |
59 | seconds = int(duration) % 60 | |
60 | if minutes < 100: | |
61 | return "{:2}:{:0>2}".format(minutes, seconds) | |
62 | else: | |
63 | return "{}:{:0>2}".format(minutes, seconds) | |
1b4b78f5 IB |
64 | |
65 | def gain(volume, old_volume = None): | |
66 | if old_volume is None: | |
67 | return 20 * math.log10(volume / 100) | |
68 | else: | |
69 | return [20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)), max(volume, 0)] | |
70 |