File size: 3,459 Bytes
d1d6816
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import json
bins_path = 'configurations/conf.json'


def parameter_range(parameter_name):
    """
    :param parameter_name:
    :return: List[Float]--midpoints of bins for the input synthesizer parameter
    """

    with open(bins_path) as f:
        midpoints = json.load(f)["midpoints"]
    return midpoints[parameter_name]


def cluster_range():
    """
    :return: Dict[String:Int]--defines the range of cluster to search
    """
    with open(bins_path) as f:
        cluster_r = json.load(f)["subspace_range"]
    return cluster_r


def midi_parameter_range(parameter_name):
    """
    :param parameter_name:
    :return: List[Float]--midpoints of bins for the input midi parameter
    """
    with open(bins_path) as f:
        r = json.load(f)["midi_midpoints"]
    return r[parameter_name]


def is_discrete(parameter_name):
    """
    :param parameter_name:
    :return: Boolean--if the input synthesizer parameter is discrete
    """
    with open(bins_path) as f:
        is_dis = json.load(f)["is_discrete"]
    return is_dis[parameter_name]


def midi_is_discrete(parameter_name):
    """
    :param parameter_name:
    :return: Boolean--if the input midi parameter is discrete
    """
    with open(bins_path) as f:
        is_dis = json.load(f)["midi_is_discrete"]
    return is_dis[parameter_name]


def get_label_size():
    """
    :return: Int--length of synthesizer parameter encoding
    """
    with open(bins_path) as f:
        conf = json.load(f)
        midpoints = conf["midpoints"]
    n_labels = 0
    for key in midpoints:
        n_labels = n_labels + len(midpoints[key])

    return n_labels


def get_bins_length():
    """
    :return: Dict[String:Int]--Number of bins for all synthesizer parameters
    """
    with open(bins_path) as f:
        midpoints = json.load(f)["midpoints"]
    bins_length = {}

    for key in midpoints:
        bins_length[key] = len(midpoints[key])

    return bins_length


def get_conf_stft_hyperparameter():
    """
    :return: Dict[String:Int]--STFT hyper parameters
    """
    with open(bins_path) as f:
        STFT_hyperParameters = json.load(f)["STFT_hyperParameter"]

    return STFT_hyperParameters


def get_conf_sample_rate():
    """
    :return: Int--sample_rate
    """
    with open(bins_path) as f:
        sample_rate = json.load(f)["sample_rate"]

    return sample_rate


def get_conf_n_sample_note():
    """
    :return: Int--sample number of a note example
    """
    with open(bins_path) as f:
        n_sample_note = json.load(f)["n_sample_note"]

    return n_sample_note


def get_conf_n_sample():
    """
    :return: Int--sample number of a melody example
    """
    with open(bins_path) as f:
        n_sample = json.load(f)["n_sample_music"]

    return n_sample


def get_conf_time_resolution():
    """
    :return: Int--spectrogram resolution on time dimension
    """
    with open(bins_path) as f:
        resolution = json.load(f)["resolution"]

    return resolution["time_resolution"]


def get_conf_pitch_resolution():
    """
    :return: Int--spectrogram resolution on pitch dimension
    """
    with open(bins_path) as f:
        resolution = json.load(f)["resolution"]

    return resolution["freq_resolution"]


def get_conf_max_n_notes():
    """
    :return: Int--maximum number of notes to be generated in a melody
    """
    with open(bins_path) as f:
        max_n_notes = json.load(f)["midi_max_n_notes"]

    return max_n_notes