Spaces:
Sleeping
Sleeping
#!/usr/bin/env python | |
# coding: utf-8 | |
import contextlib | |
import glob | |
import io | |
import json | |
import logging | |
import multiprocessing | |
import os | |
import random | |
import time | |
import traceback | |
import sys | |
from pydub import AudioSegment, silence | |
from anyio import Path | |
import dawdreamer as daw | |
import numpy as np | |
from scipy.io import wavfile | |
from pydub import AudioSegment | |
from pydub.silence import split_on_silence | |
import tqdm | |
import csv | |
SAMPLE_RATE = 44100 | |
# Parameters will undergo automation at this buffer/block size. | |
BUFFER_SIZE = 128 | |
PPQN = 960 # Pulses per quarter note. | |
SYNTH_PLUGIN = "libTAL-NoiseMaker.so" | |
# SYNTH_PLUGIN = "C:/Program Files/Common Files/VST3/Surge Synth Team/Surge XT.vst3/Contents/x86_64-win/Surge XT.vst3" | |
def make_sine(freq: float, duration: float, sr=SAMPLE_RATE): | |
"""Return sine wave based on freq in Hz and duration in seconds""" | |
N = int(duration * sr) # Number of samples | |
return np.sin(np.pi*2.*freq*np.arange(N)/sr) | |
def gen(): | |
# print(f'Current gen: {self.current_num}') | |
engine = daw.RenderEngine(SAMPLE_RATE, BUFFER_SIZE) | |
output_dir = Path("yay") | |
# Make a processor and give it the unique name "my_synth", which we use later. | |
synth = engine.make_plugin_processor("my_synth", SYNTH_PLUGIN) | |
assert synth.get_name() == "my_synth" | |
#Outputs the properties names and dumps them in a json | |
params = {} | |
for param in range(1,86): | |
params[param] = (synth.get_parameter_name(param)) | |
with open(str(f'params_.json'), 'w') as f: | |
json.dump(params, f) | |
#synth.load_preset("C:/Users/yderre/AppData/Roaming/ToguAudioLine/TAL-NoiseMaker/presets/Factory Presets/DRUM/DR 8bit Kick II FN.noisemakerpreset") | |
# Get the parameters description from the plugin | |
parameters = synth.get_parameters_description() | |
array = [] | |
# Create a dictionary with parameter names as keys and their indices as values | |
synth.add_midi_note(40, 127, 0, 0.2) | |
# for i in range(0,120): | |
# print(f"{parameters[i]['name']}") | |
# return | |
with open('InverSynth_01998.wav.csv', 'r') as csvfile: | |
reader = csv.reader(csvfile) | |
# Skip the header row | |
next(reader) | |
i=0 | |
# Loop through the rows | |
for row in reader: | |
# Get the floating-point number from the third column | |
value = float(row[2]) | |
params = {} | |
# (MIDI note, velocity, start, duration) | |
print(f"{parameters[i]['name']} changed from {parameters[i]['defaultValue']} to {value} ") | |
synth.set_parameter(i, value) | |
i+=1 | |
# don't do reverb | |
graph = [ | |
# synth takes no inputs, so we give an empty list. | |
(synth, []), | |
] | |
engine.load_graph(graph) | |
engine.render(1) | |
output = engine.get_audio() | |
wavfile.write( | |
str(output_dir/f'test_.wav'), SAMPLE_RATE, output.transpose()) | |
synth.open_editor() # Open the editor, make changes, and clos | |
if __name__ == "__main__": | |
gen() | |