VAE_sound / configurations /read_configuration.py
WeixuanYuan's picture
Upload 35 files
d1d6816
raw
history blame
3.46 kB
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