PRANJAL KAR commited on
Commit
cf93b82
·
1 Parent(s): 6eb216c

Refactor section configuration to load from final_arrangement.json and update finalise function to map section names to keys

Browse files
Files changed (3) hide show
  1. app.py +2 -9
  2. final_arrangement.json +47 -0
  3. temp_choose.py +31 -2
app.py CHANGED
@@ -391,15 +391,8 @@ def setup_section_event_handlers(section_name, section_ui):
391
 
392
 
393
  # Load section configuration from a JSON file or string
394
- section_config_json = """
395
- {
396
- "intro": {"bpm": 120, "bars": 8, "p": 0.3},
397
- "buildup": {"bpm": 120, "bars": 16, "p": 0.4},
398
- "breakdown": {"bpm": 120, "bars": 16, "p": 0.6},
399
- "drop": {"bpm": 120, "bars": 16, "p": 0.7},
400
- "outro": {"bpm": 120, "bars": 8, "p": 0.3}
401
- }
402
- """
403
 
404
  sections = json.loads(section_config_json)
405
 
 
391
 
392
 
393
  # Load section configuration from a JSON file or string
394
+ with open("final_arrangement.json", "r") as f:
395
+ section_config_json = f.read()
 
 
 
 
 
 
 
396
 
397
  sections = json.loads(section_config_json)
398
 
final_arrangement.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "intro": {
3
+ "bpm": 120,
4
+ "bars": 8,
5
+ "p": 0.3
6
+ },
7
+ "verse1": {
8
+ "bpm": 40,
9
+ "bars": 32,
10
+ "p": 0.5
11
+ },
12
+ "pre_chorus": {
13
+ "bpm": 60,
14
+ "bars": 16,
15
+ "p": 0.5
16
+ },
17
+ "drop": {
18
+ "bpm": 120,
19
+ "bars": 16,
20
+ "p": 0.7
21
+ },
22
+ "breakdown": {
23
+ "bpm": 120,
24
+ "bars": 16,
25
+ "p": 0.6
26
+ },
27
+ "bridge": {
28
+ "bpm": 60,
29
+ "bars": 32,
30
+ "p": 0.5
31
+ },
32
+ "buildup": {
33
+ "bpm": 120,
34
+ "bars": 16,
35
+ "p": 0.4
36
+ },
37
+ "drop2": {
38
+ "bpm": 100,
39
+ "bars": 64,
40
+ "p": 0.5
41
+ },
42
+ "outro": {
43
+ "bpm": 120,
44
+ "bars": 8,
45
+ "p": 0.3
46
+ }
47
+ }
temp_choose.py CHANGED
@@ -100,9 +100,38 @@ def load_variation(variation_name):
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:
 
100
 
101
 
102
  def finalise():
103
+ # Map from display names to keys
104
+ section_key_map = {
105
+ "Intro": "intro",
106
+ "Build-Up": "buildup",
107
+ "Breakdown": "breakdown",
108
+ "Drop 1": "drop",
109
+ "Drop 2": "drop2",
110
+ "Outro": "outro",
111
+ "Outro/Fade": "outro",
112
+ "Verse 1": "verse1",
113
+ "Pre-Chorus": "pre_chorus",
114
+ "Bridge": "bridge",
115
+ # Add more mappings as needed
116
+ }
117
+ # Example default values for bpm, bars, p (customize as needed)
118
+ default_section_params = {
119
+ "intro": {"bpm": 120, "bars": 8, "p": 0.3},
120
+ "buildup": {"bpm": 120, "bars": 16, "p": 0.4},
121
+ "breakdown": {"bpm": 120, "bars": 16, "p": 0.6},
122
+ "drop": {"bpm": 120, "bars": 16, "p": 0.7},
123
+ "outro": {"bpm": 120, "bars": 8, "p": 0.3},
124
+ # Add more as needed
125
+ }
126
+ result = {}
127
+ for bar, tempo, name, length, curve in arrangement:
128
+ key = section_key_map.get(name, name.lower().replace(' ', '_'))
129
+ # You can customize how you set bpm, bars, p here
130
+ params = default_section_params.get(key, {"bpm": tempo, "bars": length, "p": 0.5})
131
+ result[key] = params
132
  with open("final_arrangement.json", "w") as f:
133
+ json.dump(result, f, indent=2)
134
+ return json.dumps(result, indent=2)
135
 
136
 
137
  # with gr.Blocks() as iface: