Spaces:
Running
Running
Commit
·
0e6b4b2
1
Parent(s):
f455314
feat: add reverb send slider and update parameter handling in demo
Browse files
app.py
CHANGED
@@ -331,7 +331,10 @@ def update_param(m, attr_name, value):
|
|
331 |
case torch.nn.Parameter:
|
332 |
getattr(m, attr_name).data.copy_(value)
|
333 |
case _:
|
334 |
-
|
|
|
|
|
|
|
335 |
|
336 |
|
337 |
@torch.no_grad()
|
@@ -604,6 +607,13 @@ with gr.Blocks() as demo:
|
|
604 |
interactive=True,
|
605 |
label="Low Pass Frequency (Hz)",
|
606 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
607 |
with gr.Column():
|
608 |
delay_plot = gr.Plot(
|
609 |
plot_delay(fx), label="Delay Frequency Response", elem_id="delay-plot"
|
@@ -688,15 +698,16 @@ with gr.Blocks() as demo:
|
|
688 |
]
|
689 |
delay_update_plot_flag = [True] * 4 + [False] * 2
|
690 |
|
691 |
-
all_effect_sliders = peq_sliders + cmp_sliders + delay_sliders
|
692 |
-
split_sizes = [len(peq_sliders), len(cmp_sliders), len(delay_sliders)]
|
693 |
|
694 |
def assign_fx_params(fx, *args):
|
695 |
peq_sliders, cmp_sliders, delay_sliders = (
|
696 |
args[: split_sizes[0]],
|
697 |
args[split_sizes[0] : sum(split_sizes[:2])],
|
698 |
-
args[sum(split_sizes[:2]) :],
|
699 |
)
|
|
|
700 |
for idx, s, attr_name in zip(peq_indices, peq_sliders, peq_attr_names):
|
701 |
update_param(fx[idx].params, attr_name, s)
|
702 |
|
@@ -707,76 +718,47 @@ with gr.Blocks() as demo:
|
|
707 |
m, name = get_last_attribute(fx[7].effects[0], attr_name)
|
708 |
f(m, name, s)
|
709 |
|
|
|
|
|
710 |
return fx
|
711 |
|
712 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
713 |
s.input(
|
714 |
chain_functions(
|
715 |
-
lambda x,
|
716 |
-
assign_fx_params(vec2fx(x), *all_s),
|
717 |
-
s,
|
718 |
-
extra_pc_idx,
|
719 |
-
),
|
720 |
-
lambda fx, s, extra_pc_idx, idx=idx, attr_name=attr_name: (
|
721 |
-
update_param(fx[idx].params, attr_name, s),
|
722 |
-
fx,
|
723 |
-
extra_pc_idx,
|
724 |
-
),
|
725 |
-
lambda _, fx, extra_pc_idx: (fx2x(fx), fx, extra_pc_idx),
|
726 |
-
lambda x, fx, extra_pc_idx: (x2z(x), x, fx, extra_pc_idx),
|
727 |
lambda z, x, fx, extra_pc_idx: [z, x]
|
728 |
+ [model2json(fx), plot_eq(fx)]
|
729 |
+ update_pc(z, extra_pc_idx),
|
730 |
),
|
731 |
-
inputs=[fx_params,
|
732 |
outputs=[z, fx_params, json_output, peq_plot] + update_pc_outputs,
|
733 |
)
|
734 |
|
735 |
-
for
|
736 |
-
cmp_update_funcs, cmp_sliders, cmp_attr_names, cmp_update_plot_flag
|
737 |
-
):
|
738 |
s.input(
|
739 |
chain_functions(
|
740 |
-
lambda x,
|
741 |
-
assign_fx_params(vec2fx(x), *all_s),
|
742 |
-
s,
|
743 |
-
e_pc_i,
|
744 |
-
),
|
745 |
-
lambda fx, s, e_pc_i, attr_name=attr_name, f=f: (
|
746 |
-
f(fx[6].params, attr_name, s),
|
747 |
-
fx,
|
748 |
-
e_pc_i,
|
749 |
-
),
|
750 |
-
lambda _, fx, e_pc_i: (fx2x(fx), fx, e_pc_i),
|
751 |
-
lambda x, fx, e_pc_i: (x2z(x), x, fx, e_pc_i),
|
752 |
lambda z, x, fx, e_pc_i, update_plot=update_plot: [z, x]
|
753 |
+ [model2json(fx)]
|
754 |
+ ([plot_comp(fx)] if update_plot else [])
|
755 |
+ update_pc(z, e_pc_i),
|
756 |
),
|
757 |
-
inputs=[fx_params,
|
758 |
outputs=[z, fx_params, json_output]
|
759 |
+ ([comp_plot] if update_plot else [])
|
760 |
+ update_pc_outputs,
|
761 |
)
|
762 |
|
763 |
-
for
|
764 |
-
delay_update_funcs, delay_sliders, delay_attr_names, delay_update_plot_flag
|
765 |
-
):
|
766 |
s.input(
|
767 |
chain_functions(
|
768 |
-
lambda x,
|
769 |
-
assign_fx_params(vec2fx(x), *all_s),
|
770 |
-
s,
|
771 |
-
e_pc_i,
|
772 |
-
),
|
773 |
-
lambda fx, s, e_pc_i, f=f, attr_name=attr_name: (
|
774 |
-
f(*get_last_attribute(fx[7].effects[0], attr_name), s),
|
775 |
-
fx,
|
776 |
-
e_pc_i,
|
777 |
-
),
|
778 |
-
lambda _, fx, e_pc_i: (fx2x(fx), fx, e_pc_i),
|
779 |
-
lambda x, fx, e_pc_i: (x2z(x), x, fx, e_pc_i),
|
780 |
lambda z, x, fx, e_pc_i, update_plot=update_plot: (
|
781 |
[z, x]
|
782 |
+ [model2json(fx)]
|
@@ -784,13 +766,22 @@ with gr.Blocks() as demo:
|
|
784 |
+ update_pc(z, e_pc_i)
|
785 |
),
|
786 |
),
|
787 |
-
inputs=[fx_params,
|
788 |
outputs=[z, fx_params]
|
789 |
+ [json_output]
|
790 |
+ ([delay_plot] if update_plot else [])
|
791 |
+ update_pc_outputs,
|
792 |
)
|
793 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
794 |
render_button.click(
|
795 |
chain_functions(
|
796 |
lambda audio, ratio, x, *all_s: (
|
@@ -841,6 +832,7 @@ with gr.Blocks() as demo:
|
|
841 |
fx[7].effects[0].eq.params.freq.item(),
|
842 |
fx[7].effects[0].odd_pan.params.pan.item() * 200 - 100,
|
843 |
fx[7].effects[0].even_pan.params.pan.item() * 200 - 100,
|
|
|
844 |
]
|
845 |
update_fx_outputs = [
|
846 |
pk1_freq,
|
@@ -870,6 +862,7 @@ with gr.Blocks() as demo:
|
|
870 |
delay_lp_freq,
|
871 |
odd_pan,
|
872 |
even_pan,
|
|
|
873 |
]
|
874 |
update_plots = lambda fx: [
|
875 |
plot_eq(fx),
|
|
|
331 |
case torch.nn.Parameter:
|
332 |
getattr(m, attr_name).data.copy_(value)
|
333 |
case _:
|
334 |
+
if getattr(m, attr_name).ndim == 0:
|
335 |
+
setattr(m, attr_name, torch.tensor(value))
|
336 |
+
else:
|
337 |
+
setattr(m, attr_name, torch.tensor([value]))
|
338 |
|
339 |
|
340 |
@torch.no_grad()
|
|
|
607 |
interactive=True,
|
608 |
label="Low Pass Frequency (Hz)",
|
609 |
)
|
610 |
+
reverb_send = gr.Slider(
|
611 |
+
minimum=-80,
|
612 |
+
maximum=0,
|
613 |
+
value=fx[7].params.sends_0.log10().item() * 20,
|
614 |
+
interactive=True,
|
615 |
+
label="Reverb Send (dB)",
|
616 |
+
)
|
617 |
with gr.Column():
|
618 |
delay_plot = gr.Plot(
|
619 |
plot_delay(fx), label="Delay Frequency Response", elem_id="delay-plot"
|
|
|
698 |
]
|
699 |
delay_update_plot_flag = [True] * 4 + [False] * 2
|
700 |
|
701 |
+
all_effect_sliders = peq_sliders + cmp_sliders + delay_sliders + [reverb_send]
|
702 |
+
split_sizes = [len(peq_sliders), len(cmp_sliders), len(delay_sliders), 1]
|
703 |
|
704 |
def assign_fx_params(fx, *args):
|
705 |
peq_sliders, cmp_sliders, delay_sliders = (
|
706 |
args[: split_sizes[0]],
|
707 |
args[split_sizes[0] : sum(split_sizes[:2])],
|
708 |
+
args[sum(split_sizes[:2]) : -1],
|
709 |
)
|
710 |
+
reverb_send_slider = args[-1]
|
711 |
for idx, s, attr_name in zip(peq_indices, peq_sliders, peq_attr_names):
|
712 |
update_param(fx[idx].params, attr_name, s)
|
713 |
|
|
|
718 |
m, name = get_last_attribute(fx[7].effects[0], attr_name)
|
719 |
f(m, name, s)
|
720 |
|
721 |
+
update_param(fx[7].params, "sends_0", 10 ** (reverb_send_slider / 20))
|
722 |
+
|
723 |
return fx
|
724 |
|
725 |
+
common_steps = chain_functions(
|
726 |
+
lambda x, *all_s: assign_fx_params(vec2fx(x), *all_s),
|
727 |
+
lambda fx: (fx2x(fx), fx),
|
728 |
+
lambda x, fx: (x2z(x), x, fx),
|
729 |
+
)
|
730 |
+
|
731 |
+
for s in peq_sliders:
|
732 |
s.input(
|
733 |
chain_functions(
|
734 |
+
lambda x, i, *args: common_steps(x, *args) + (i,),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
735 |
lambda z, x, fx, extra_pc_idx: [z, x]
|
736 |
+ [model2json(fx), plot_eq(fx)]
|
737 |
+ update_pc(z, extra_pc_idx),
|
738 |
),
|
739 |
+
inputs=[fx_params, extra_pc_dropdown] + all_effect_sliders,
|
740 |
outputs=[z, fx_params, json_output, peq_plot] + update_pc_outputs,
|
741 |
)
|
742 |
|
743 |
+
for s, update_plot in zip(cmp_sliders, cmp_update_plot_flag):
|
|
|
|
|
744 |
s.input(
|
745 |
chain_functions(
|
746 |
+
lambda x, i, *args: common_steps(x, *args) + (i,),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
747 |
lambda z, x, fx, e_pc_i, update_plot=update_plot: [z, x]
|
748 |
+ [model2json(fx)]
|
749 |
+ ([plot_comp(fx)] if update_plot else [])
|
750 |
+ update_pc(z, e_pc_i),
|
751 |
),
|
752 |
+
inputs=[fx_params, extra_pc_dropdown] + all_effect_sliders,
|
753 |
outputs=[z, fx_params, json_output]
|
754 |
+ ([comp_plot] if update_plot else [])
|
755 |
+ update_pc_outputs,
|
756 |
)
|
757 |
|
758 |
+
for s, update_plot in zip(delay_sliders, delay_update_plot_flag):
|
|
|
|
|
759 |
s.input(
|
760 |
chain_functions(
|
761 |
+
lambda x, i, *args: common_steps(x, *args) + (i,),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
762 |
lambda z, x, fx, e_pc_i, update_plot=update_plot: (
|
763 |
[z, x]
|
764 |
+ [model2json(fx)]
|
|
|
766 |
+ update_pc(z, e_pc_i)
|
767 |
),
|
768 |
),
|
769 |
+
inputs=[fx_params, extra_pc_dropdown] + all_effect_sliders,
|
770 |
outputs=[z, fx_params]
|
771 |
+ [json_output]
|
772 |
+ ([delay_plot] if update_plot else [])
|
773 |
+ update_pc_outputs,
|
774 |
)
|
775 |
|
776 |
+
reverb_send.input(
|
777 |
+
chain_functions(
|
778 |
+
lambda x, i, *args: common_steps(x, *args) + (i,),
|
779 |
+
lambda z, x, fx, e_pc_i: [z, x] + [model2json(fx)] + update_pc(z, e_pc_i),
|
780 |
+
),
|
781 |
+
inputs=[fx_params, extra_pc_dropdown] + all_effect_sliders,
|
782 |
+
outputs=[z, fx_params, json_output] + update_pc_outputs,
|
783 |
+
)
|
784 |
+
|
785 |
render_button.click(
|
786 |
chain_functions(
|
787 |
lambda audio, ratio, x, *all_s: (
|
|
|
832 |
fx[7].effects[0].eq.params.freq.item(),
|
833 |
fx[7].effects[0].odd_pan.params.pan.item() * 200 - 100,
|
834 |
fx[7].effects[0].even_pan.params.pan.item() * 200 - 100,
|
835 |
+
fx[7].params.sends_0.log10().item() * 20,
|
836 |
]
|
837 |
update_fx_outputs = [
|
838 |
pk1_freq,
|
|
|
862 |
delay_lp_freq,
|
863 |
odd_pan,
|
864 |
even_pan,
|
865 |
+
reverb_send,
|
866 |
]
|
867 |
update_plots = lambda fx: [
|
868 |
plot_eq(fx),
|