PRANJAL KAR commited on
Commit
9b18f47
Β·
1 Parent(s): cb278d5

Added temp file

Browse files
Files changed (1) hide show
  1. temp_choose.py +174 -0
temp_choose.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import plotly.graph_objects as go
3
+ import numpy as np
4
+ import json
5
+
6
+ # Three base arrangements
7
+ arrangements = {
8
+ "High Energy Flow": [
9
+ (1, 16, "Intro", 16, "Linear"),
10
+ (17, 48, "Verse 1", 32, "Flat"),
11
+ (49, 64, "Build-Up", 16, "Linear"),
12
+ (65, 100, "Drop 1", 64, "Flat"),
13
+ (129, 40, "Breakdown", 16, "-ve Linear"),
14
+ (145, 60, "Bridge", 32, "Flat"),
15
+ (177, 64, "Build-Up", 16, "Linear"),
16
+ (193, 100, "Drop 2", 64, "Flat"),
17
+ (257, 40, "Outro/Fade", 16, "-ve Linear"),
18
+ ],
19
+ "Festival Vibes": [
20
+ (1, 20, "Intro", 8, "Linear"),
21
+ (9, 40, "Verse 1", 32, "Flat"),
22
+ (41, 60, "Pre-Chorus", 16, "Linear"),
23
+ (57, 100, "Drop 1", 64, "Flat"),
24
+ (121, 40, "Breakdown", 16, "-ve Linear"),
25
+ (137, 60, "Bridge", 32, "Flat"),
26
+ (169, 64, "Build-Up", 16, "Linear"),
27
+ (185, 100, "Drop 2", 64, "Flat"),
28
+ (249, 40, "Outro/Fade", 16, "-ve Linear"),
29
+ ],
30
+ "Underground Pulse": [
31
+ (1, 20, "Intro", 16, "Linear"),
32
+ (17, 40, "Verse 1", 32, "Flat"),
33
+ (49, 40, "Breakdown", 16, "-ve Linear"),
34
+ (65, 60, "Build-Up", 16, "Linear"),
35
+ (81, 100, "Drop 1", 64, "Flat"),
36
+ (145, 40, "Bridge", 16, "-ve Linear"),
37
+ (161, 60, "Pre-Chorus", 32, "Linear"),
38
+ (193, 100, "Drop 2", 64, "Flat"),
39
+ (257, 40, "Outro", 16, "-ve Linear"),
40
+ ],
41
+ }
42
+
43
+ arrangement = arrangements["High Energy Flow"].copy()
44
+
45
+
46
+ def shift_arrangement(start_index):
47
+ for i in range(start_index + 1, len(arrangement)):
48
+ prev_start, _, _, prev_length, _ = arrangement[i - 1]
49
+ arrangement[i] = (prev_start + prev_length, *arrangement[i][1:])
50
+
51
+
52
+ def editable_diagram(section_data):
53
+ fig = go.Figure()
54
+ total_bars = 0
55
+ for bar, tempo, name, length, curve in section_data:
56
+ x = np.arange(bar, bar + length + 1)
57
+ if curve == "Linear":
58
+ y = np.linspace(tempo * 0.6, tempo, len(x))
59
+ elif curve == "-ve Linear":
60
+ y = np.linspace(tempo, tempo * 0.6, len(x))
61
+ else:
62
+ y = np.full(len(x), tempo)
63
+ fig.add_trace(
64
+ go.Scatter(
65
+ x=x, y=y, fill="tozeroy", name=name, mode="lines", line_shape="hv"
66
+ )
67
+ )
68
+ total_bars = max(total_bars, bar + length)
69
+
70
+ fig.update_layout(
71
+ title="EDM Arrangement Energy Curve",
72
+ xaxis_title="Bar",
73
+ yaxis_title="Volume (Energy)",
74
+ xaxis=dict(range=[0, total_bars + 4]),
75
+ yaxis=dict(range=[0, 100]),
76
+ height=400,
77
+ )
78
+ return fig
79
+
80
+
81
+ def update_section(index, bar, tempo, length, curve):
82
+ global arrangement
83
+ current = arrangement[index]
84
+ arrangement[index] = (int(bar), int(tempo), current[2], int(length), curve)
85
+ shift_arrangement(index)
86
+ return editable_diagram(arrangement)
87
+
88
+
89
+ def insert_section(index, name="New Section", bar=0, tempo=50, length=8, curve="Flat"):
90
+ global arrangement
91
+ arrangement.insert(index, (bar, tempo, name, length, curve))
92
+ shift_arrangement(index)
93
+ return editable_diagram(arrangement)
94
+
95
+
96
+ def load_variation(variation_name):
97
+ global arrangement
98
+ arrangement = arrangements[variation_name].copy()
99
+ return editable_diagram(arrangement)
100
+
101
+
102
+ def finalise():
103
+ with open("final_arrangement.json", "w") as f:
104
+ json.dump(arrangement, f, indent=2)
105
+ return json.dumps(arrangement, indent=2)
106
+
107
+
108
+ # with gr.Blocks() as iface:
109
+ # gr.Markdown("# 🌚 Interactive EDM Arrangement Tool")
110
+
111
+ # with gr.Row():
112
+ # variation = gr.Radio(
113
+ # choices=list(arrangements.keys()),
114
+ # value="High Energy Flow",
115
+ # label="Choose Arrangement Variation",
116
+ # )
117
+
118
+ # out_plot = gr.Plot(label="Arrangement Diagram")
119
+ # variation.change(fn=load_variation, inputs=variation, outputs=out_plot)
120
+ # out_plot.value = editable_diagram(arrangement)
121
+
122
+ # with gr.Accordion("🎻 Edit Section Parameters", open=False):
123
+ # for i, (bar, tempo, name, length, curve) in enumerate(arrangement):
124
+ # with gr.Row():
125
+ # gr.Markdown(f"**{name}**")
126
+ # bar_slider = gr.Slider(
127
+ # minimum=0, maximum=300, value=bar, label="Start Bar"
128
+ # )
129
+ # tempo_slider = gr.Slider(
130
+ # minimum=20, maximum=100, value=tempo, label="Volume"
131
+ # )
132
+ # length_slider = gr.Slider(
133
+ # minimum=1, maximum=64, value=length, label="Length"
134
+ # )
135
+ # curve_selector = gr.Radio(
136
+ # choices=["Flat", "Linear", "-ve Linear"],
137
+ # value=curve,
138
+ # label="Curve Type",
139
+ # )
140
+ # update_btn = gr.Button("Update")
141
+ # update_btn.click(
142
+ # fn=update_section,
143
+ # inputs=[
144
+ # gr.Number(value=i, visible=False),
145
+ # bar_slider,
146
+ # tempo_slider,
147
+ # length_slider,
148
+ # curve_selector,
149
+ # ],
150
+ # outputs=[out_plot],
151
+ # )
152
+
153
+ # with gr.Accordion("βž• Insert New Section", open=False):
154
+ # new_index = gr.Number(value=0, label="Insert At Index")
155
+ # new_name = gr.Textbox(label="Section Name", value="New Section")
156
+ # new_bar = gr.Slider(minimum=0, maximum=300, value=0, label="Start Bar")
157
+ # new_tempo = gr.Slider(minimum=20, maximum=100, value=50, label="Volume")
158
+ # new_length = gr.Slider(minimum=1, maximum=64, value=8, label="Length")
159
+ # new_curve = gr.Radio(
160
+ # choices=["Flat", "Linear", "-ve Linear"], value="Flat", label="Curve Type"
161
+ # )
162
+ # insert_btn = gr.Button("Insert Section")
163
+ # insert_btn.click(
164
+ # fn=insert_section,
165
+ # inputs=[new_index, new_name, new_bar, new_tempo, new_length, new_curve],
166
+ # outputs=[out_plot],
167
+ # )
168
+
169
+ # gr.Markdown("## βœ… Finalise Your Arrangement")
170
+ # final_btn = gr.Button("Finalise and Export JSON")
171
+ # final_output = gr.Textbox(label="Final Arrangement JSON", lines=15)
172
+ # final_btn.click(fn=finalise, outputs=final_output)
173
+
174
+ # iface.launch()