-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeat_studio_ui_advanced.py
More file actions
1245 lines (1036 loc) · 42.3 KB
/
beat_studio_ui_advanced.py
File metadata and controls
1245 lines (1036 loc) · 42.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Advanced_Beat_Studio_UI_Components
"""
beat_studio_ui_advanced.py - Advanced UI components for Beat Studio
Provides enhanced interface elements for professional beat production
"""
import tkinter as tk
from tkinter import ttk, messagebox, filedialog
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.scrolled import ScrolledText
import numpy as np
import threading
from typing import Dict, List, Callable, Optional
import json
from datetime import datetime
# ============================================================================
# ADVANCED PATTERN EDITOR
# ============================================================================
class AdvancedPatternEditor(ttk.Frame):
"""Professional pattern editor with velocity, swing, and more."""
def __init__(self, parent, on_pattern_change: Callable = None):
super().__init__(parent)
self.on_pattern_change = on_pattern_change
self.current_pattern_length = 16
self.current_page = 0 # For patterns longer than 16 steps
# Pattern data structure with velocity
self.patterns = {
'kick': {'hits': [0]*64, 'velocities': [0.8]*64},
'snare': {'hits': [0]*64, 'velocities': [0.8]*64},
'hihat': {'hits': [0]*64, 'velocities': [0.6]*64},
'openhat': {'hits': [0]*64, 'velocities': [0.6]*64},
'crash': {'hits': [0]*64, 'velocities': [0.9]*64},
'perc': {'hits': [0]*64, 'velocities': [0.7]*64}
}
self.selected_instrument = 'kick'
self.velocity_mode = False
self._create_ui()
def _create_ui(self):
"""Create the advanced pattern editor UI."""
# Top controls
control_frame = ttk.Frame(self)
control_frame.pack(fill=tk.X, pady=(0, 10))
# Pattern length
ttk.Label(control_frame, text="Length:").pack(side=tk.LEFT, padx=(0, 5))
self.length_var = tk.IntVar(value=16)
length_combo = ttk.Combobox(
control_frame,
textvariable=self.length_var,
values=[16, 32, 64],
width=5,
state="readonly"
)
length_combo.pack(side=tk.LEFT, padx=(0, 20))
length_combo.bind("<<ComboboxSelected>>", self._on_length_change)
# Page navigation
ttk.Button(
control_frame,
text="◀",
command=self._prev_page,
width=3
).pack(side=tk.LEFT)
self.page_label = ttk.Label(control_frame, text="Page 1/1")
self.page_label.pack(side=tk.LEFT, padx=5)
ttk.Button(
control_frame,
text="▶",
command=self._next_page,
width=3
).pack(side=tk.LEFT, padx=(0, 20))
# Mode buttons
ttk.Button(
control_frame,
text="🎹 Velocity Mode",
command=self._toggle_velocity_mode,
bootstyle="info"
).pack(side=tk.LEFT, padx=5)
ttk.Button(
control_frame,
text="🎲 Randomize",
command=self._randomize_pattern,
bootstyle="warning"
).pack(side=tk.LEFT, padx=5)
ttk.Button(
control_frame,
text="🗑️ Clear",
command=self._clear_pattern,
bootstyle="danger"
).pack(side=tk.LEFT)
# Pattern grid
self.grid_frame = ttk.Frame(self)
self.grid_frame.pack(fill=tk.BOTH, expand=True)
self._create_pattern_grid()
def _create_pattern_grid(self):
"""Create the visual pattern grid."""
# Clear existing grid
for widget in self.grid_frame.winfo_children():
widget.destroy()
# Step numbers
header_frame = ttk.Frame(self.grid_frame)
header_frame.pack(fill=tk.X)
ttk.Label(header_frame, text="", width=10).pack(side=tk.LEFT)
start_step = self.current_page * 16
for i in range(16):
step_num = start_step + i + 1
weight = "bold" if (i % 4) == 0 else "normal"
ttk.Label(
header_frame,
text=str(step_num),
width=3,
font=("Courier", 8, weight)
).pack(side=tk.LEFT)
# Instrument rows
instruments = [
("🥁 Kick", "kick", "#FF5722"),
("🥁 Snare", "snare", "#2196F3"),
("🎩 Hi-Hat", "hihat", "#4CAF50"),
("🎩 Open", "openhat", "#FFC107"),
("💥 Crash", "crash", "#FF9800"),
("🎵 Perc", "perc", "#9C27B0")
]
self.pattern_buttons = {}
for inst_name, inst_key, color in instruments:
row_frame = ttk.Frame(self.grid_frame)
row_frame.pack(fill=tk.X, pady=1)
# Instrument label with selection
inst_btn = tk.Button(
row_frame,
text=inst_name,
width=10,
relief=tk.RAISED if inst_key == self.selected_instrument else tk.FLAT,
command=lambda k=inst_key: self._select_instrument(k)
)
inst_btn.pack(side=tk.LEFT)
# Pattern buttons
self.pattern_buttons[inst_key] = []
for i in range(16):
step_idx = start_step + i
if self.velocity_mode and inst_key == self.selected_instrument:
# Velocity slider
vel_var = tk.DoubleVar(value=self.patterns[inst_key]['velocities'][step_idx])
vel_scale = ttk.Scale(
row_frame,
from_=0.0,
to=1.0,
variable=vel_var,
length=20,
orient=tk.VERTICAL,
command=lambda v, k=inst_key, idx=step_idx: self._update_velocity(k, idx, float(v))
)
vel_scale.pack(side=tk.LEFT, padx=1)
else:
# Hit button
is_hit = self.patterns[inst_key]['hits'][step_idx]
velocity = self.patterns[inst_key]['velocities'][step_idx]
btn = tk.Button(
row_frame,
text="●" if is_hit else "○",
width=2,
height=1,
font=("Arial", 8),
bg=self._velocity_to_color(color, velocity) if is_hit else "gray80",
fg="white",
relief=tk.FLAT,
command=lambda k=inst_key, idx=step_idx, c=color: self._toggle_hit(k, idx, c)
)
btn.pack(side=tk.LEFT, padx=1)
self.pattern_buttons[inst_key].append(btn)
def _velocity_to_color(self, base_color: str, velocity: float) -> str:
"""Convert velocity to color shade."""
# Simple brightness adjustment based on velocity
if velocity > 0.8:
return base_color
elif velocity > 0.5:
return base_color + "CC" # Slightly transparent
else:
return base_color + "88" # More transparent
def _toggle_hit(self, instrument: str, step: int, color: str):
"""Toggle a hit in the pattern."""
self.patterns[instrument]['hits'][step] = 1 - self.patterns[instrument]['hits'][step]
self._update_grid()
if self.on_pattern_change:
self.on_pattern_change(self.get_current_pattern())
def _update_velocity(self, instrument: str, step: int, velocity: float):
"""Update velocity for a step."""
self.patterns[instrument]['velocities'][step] = velocity
if self.on_pattern_change:
self.on_pattern_change(self.get_current_pattern())
def _select_instrument(self, instrument: str):
"""Select an instrument for editing."""
self.selected_instrument = instrument
self._create_pattern_grid()
def _toggle_velocity_mode(self):
"""Toggle velocity editing mode."""
self.velocity_mode = not self.velocity_mode
self._create_pattern_grid()
def _randomize_pattern(self):
"""Randomize the current instrument's pattern."""
instrument = self.selected_instrument
length = self.length_var.get()
# Random hits with musical probability
for i in range(length):
# Higher probability on downbeats
prob = 0.7 if i % 4 == 0 else 0.3
self.patterns[instrument]['hits'][i] = 1 if np.random.random() < prob else 0
# Random velocities
if self.patterns[instrument]['hits'][i]:
self.patterns[instrument]['velocities'][i] = np.random.uniform(0.5, 1.0)
self._update_grid()
if self.on_pattern_change:
self.on_pattern_change(self.get_current_pattern())
def _clear_pattern(self):
"""Clear the current instrument's pattern."""
instrument = self.selected_instrument
self.patterns[instrument]['hits'] = [0] * 64
self.patterns[instrument]['velocities'] = [0.8] * 64
self._update_grid()
if self.on_pattern_change:
self.on_pattern_change(self.get_current_pattern())
def _on_length_change(self, event=None):
"""Handle pattern length change."""
self.current_pattern_length = self.length_var.get()
self._update_page_label()
self._create_pattern_grid()
def _prev_page(self):
"""Go to previous page."""
if self.current_page > 0:
self.current_page -= 1
self._update_page_label()
self._create_pattern_grid()
def _next_page(self):
"""Go to next page."""
max_pages = self.current_pattern_length // 16
if self.current_page < max_pages - 1:
self.current_page += 1
self._update_page_label()
self._create_pattern_grid()
def _update_page_label(self):
"""Update page navigation label."""
max_pages = self.current_pattern_length // 16
self.page_label.config(text=f"Page {self.current_page + 1}/{max_pages}")
def _update_grid(self):
"""Update the visual grid."""
self._create_pattern_grid()
def get_current_pattern(self) -> Dict:
"""Get the current pattern data."""
length = self.current_pattern_length
pattern = {}
for instrument in self.patterns:
pattern[instrument] = {
'hits': self.patterns[instrument]['hits'][:length],
'velocities': self.patterns[instrument]['velocities'][:length]
}
return pattern
# ============================================================================
# MIXER CONSOLE
# ============================================================================
class MixerConsole(ttk.Frame):
"""Professional mixing console UI."""
def __init__(self, parent, num_channels: int = 8, on_change: Callable = None):
super().__init__(parent)
self.num_channels = num_channels
self.on_change = on_change
self.channels = []
self._create_ui()
def _create_ui(self):
"""Create mixer UI."""
# Main mixer frame
mixer_frame = ttk.Frame(self)
mixer_frame.pack(fill=tk.BOTH, expand=True)
# Create channel strips
for i in range(self.num_channels):
channel = self._create_channel_strip(mixer_frame, i)
channel.pack(side=tk.LEFT, fill=tk.Y, padx=2)
self.channels.append(channel)
# Master section
master_frame = self._create_master_section(mixer_frame)
master_frame.pack(side=tk.RIGHT, fill=tk.Y, padx=(20, 5))
def _create_channel_strip(self, parent, channel_num: int) -> ttk.Frame:
"""Create a single channel strip."""
strip = ttk.LabelFrame(parent, text=f"CH {channel_num + 1}", padding=5)
# Channel data
channel_data = {
'volume': tk.DoubleVar(value=0.8),
'pan': tk.DoubleVar(value=0.0),
'mute': tk.BooleanVar(value=False),
'solo': tk.BooleanVar(value=False),
'eq_low': tk.DoubleVar(value=0.0),
'eq_mid': tk.DoubleVar(value=0.0),
'eq_high': tk.DoubleVar(value=0.0)
}
# EQ Section
eq_frame = ttk.LabelFrame(strip, text="EQ", padding=5)
eq_frame.pack(fill=tk.X, pady=(0, 10))
# High
ttk.Label(eq_frame, text="H", font=("Arial", 8)).pack()
high_knob = ttk.Scale(
eq_frame,
from_=-12,
to=12,
variable=channel_data['eq_high'],
length=60,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
)
high_knob.pack()
# Mid
ttk.Label(eq_frame, text="M", font=("Arial", 8)).pack()
mid_knob = ttk.Scale(
eq_frame,
from_=-12,
to=12,
variable=channel_data['eq_mid'],
length=60,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
)
mid_knob.pack()
# Low
ttk.Label(eq_frame, text="L", font=("Arial", 8)).pack()
low_knob = ttk.Scale(
eq_frame,
from_=-12,
to=12,
variable=channel_data['eq_low'],
length=60,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
)
low_knob.pack()
# Pan
ttk.Label(strip, text="PAN", font=("Arial", 8)).pack()
pan_knob = ttk.Scale(
strip,
from_=-1.0,
to=1.0,
variable=channel_data['pan'],
length=60,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
)
pan_knob.pack(pady=5)
# Volume fader
ttk.Label(strip, text="VOL", font=("Arial", 8)).pack()
volume_fader = ttk.Scale(
strip,
from_=1.0,
to=0.0,
variable=channel_data['volume'],
length=150,
orient=tk.VERTICAL,
command=lambda v: self._on_change()
)
volume_fader.pack(pady=5)
# Mute/Solo buttons
button_frame = ttk.Frame(strip)
button_frame.pack()
mute_btn = ttk.Checkbutton(
button_frame,
text="M",
variable=channel_data['mute'],
bootstyle="danger",
command=self._on_change
)
mute_btn.pack(side=tk.LEFT, padx=2)
solo_btn = ttk.Checkbutton(
button_frame,
text="S",
variable=channel_data['solo'],
bootstyle="warning",
command=self._on_change
)
solo_btn.pack(side=tk.LEFT, padx=2)
# Store channel data
strip.channel_data = channel_data
return strip
def _create_master_section(self, parent) -> ttk.Frame:
"""Create master channel section."""
master = ttk.LabelFrame(parent, text="MASTER", padding=10)
# Master volume
self.master_volume = tk.DoubleVar(value=0.8)
ttk.Label(master, text="MASTER", font=("Arial", 10, "bold")).pack()
master_fader = ttk.Scale(
master,
from_=1.0,
to=0.0,
variable=self.master_volume,
length=200,
orient=tk.VERTICAL,
command=lambda v: self._on_change()
)
master_fader.pack(pady=10)
# Master limiter
self.limiter_on = tk.BooleanVar(value=True)
ttk.Checkbutton(
master,
text="Limiter",
variable=self.limiter_on,
command=self._on_change
).pack()
return master
def _on_change(self):
"""Handle any mixer change."""
if self.on_change:
self.on_change(self.get_mixer_state())
def get_mixer_state(self) -> Dict:
"""Get current mixer state."""
state = {
'channels': [],
'master_volume': self.master_volume.get(),
'limiter_on': self.limiter_on.get()
}
for channel in self.channels:
if hasattr(channel, 'channel_data'):
ch_state = {
key: var.get()
for key, var in channel.channel_data.items()
}
state['channels'].append(ch_state)
return state
# ============================================================================
# EFFECTS RACK
# ============================================================================
class EffectsRack(ttk.Frame):
"""Professional effects rack with multiple processors."""
def __init__(self, parent, on_change: Callable = None):
super().__init__(parent)
self.on_change = on_change
self.effects = {}
self._create_ui()
def _create_ui(self):
"""Create effects rack UI."""
# Title
ttk.Label(self, text="🎛️ Effects Rack", font=("Arial", 12, "bold")).pack(pady=5)
# Effects container
effects_container = ttk.Frame(self)
effects_container.pack(fill=tk.BOTH, expand=True, padx=10)
# Create effect modules
self._create_reverb_module(effects_container)
self._create_delay_module(effects_container)
self._create_distortion_module(effects_container)
self._create_compressor_module(effects_container)
def _create_reverb_module(self, parent):
"""Create reverb effect module."""
reverb_frame = ttk.LabelFrame(parent, text="🌊 Reverb", padding=10)
reverb_frame.pack(fill=tk.X, pady=5)
self.effects['reverb'] = {
'enabled': tk.BooleanVar(value=False),
'room_size': tk.DoubleVar(value=0.5),
'damping': tk.DoubleVar(value=0.5),
'mix': tk.DoubleVar(value=0.2)
}
# Enable checkbox
ttk.Checkbutton(
reverb_frame,
text="Enable",
variable=self.effects['reverb']['enabled'],
command=self._on_change
).pack(anchor=tk.W)
# Controls
controls_frame = ttk.Frame(reverb_frame)
controls_frame.pack(fill=tk.X, pady=5)
# Room Size
ttk.Label(controls_frame, text="Room:").grid(row=0, column=0, sticky=tk.W)
ttk.Scale(
controls_frame,
from_=0.0,
to=1.0,
variable=self.effects['reverb']['room_size'],
length=100,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
).grid(row=0, column=1, padx=5)
# Damping
ttk.Label(controls_frame, text="Damp:").grid(row=1, column=0, sticky=tk.W)
ttk.Scale(
controls_frame,
from_=0.0,
to=1.0,
variable=self.effects['reverb']['damping'],
length=100,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
).grid(row=1, column=1, padx=5)
# Mix
ttk.Label(controls_frame, text="Mix:").grid(row=2, column=0, sticky=tk.W)
ttk.Scale(
controls_frame,
from_=0.0,
to=1.0,
variable=self.effects['reverb']['mix'],
length=100,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
).grid(row=2, column=1, padx=5)
def _create_delay_module(self, parent):
"""Create delay effect module."""
delay_frame = ttk.LabelFrame(parent, text="⏱️ Delay", padding=10)
delay_frame.pack(fill=tk.X, pady=5)
self.effects['delay'] = {
'enabled': tk.BooleanVar(value=False),
'time': tk.DoubleVar(value=0.25),
'feedback': tk.DoubleVar(value=0.3),
'mix': tk.DoubleVar(value=0.2)
}
# Enable checkbox
ttk.Checkbutton(
delay_frame,
text="Enable",
variable=self.effects['delay']['enabled'],
command=self._on_change
).pack(anchor=tk.W)
# Controls
controls_frame = ttk.Frame(delay_frame)
controls_frame.pack(fill=tk.X, pady=5)
# Delay Time
ttk.Label(controls_frame, text="Time:").grid(row=0, column=0, sticky=tk.W)
ttk.Scale(
controls_frame,
from_=0.01,
to=1.0,
variable=self.effects['delay']['time'],
length=100,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
).grid(row=0, column=1, padx=5)
# Feedback
ttk.Label(controls_frame, text="Feedback:").grid(row=1, column=0, sticky=tk.W)
ttk.Scale(
controls_frame,
from_=0.0,
to=0.9,
variable=self.effects['delay']['feedback'],
length=100,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
).grid(row=1, column=1, padx=5)
# Mix
ttk.Label(controls_frame, text="Mix:").grid(row=2, column=0, sticky=tk.W)
ttk.Scale(
controls_frame,
from_=0.0,
to=1.0,
variable=self.effects['delay']['mix'],
length=100,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
).grid(row=2, column=1, padx=5)
def _create_distortion_module(self, parent):
"""Create distortion effect module."""
dist_frame = ttk.LabelFrame(parent, text="🔥 Distortion", padding=10)
dist_frame.pack(fill=tk.X, pady=5)
self.effects['distortion'] = {
'enabled': tk.BooleanVar(value=False),
'drive': tk.DoubleVar(value=2.0),
'tone': tk.DoubleVar(value=0.5),
'mix': tk.DoubleVar(value=0.5)
}
# Enable checkbox
ttk.Checkbutton(
dist_frame,
text="Enable",
variable=self.effects['distortion']['enabled'],
command=self._on_change
).pack(anchor=tk.W)
# Controls
controls_frame = ttk.Frame(dist_frame)
controls_frame.pack(fill=tk.X, pady=5)
# Drive
ttk.Label(controls_frame, text="Drive:").grid(row=0, column=0, sticky=tk.W)
ttk.Scale(
controls_frame,
from_=1.0,
to=10.0,
variable=self.effects['distortion']['drive'],
length=100,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
).grid(row=0, column=1, padx=5)
# Tone
ttk.Label(controls_frame, text="Tone:").grid(row=1, column=0, sticky=tk.W)
ttk.Scale(
controls_frame,
from_=0.0,
to=1.0,
variable=self.effects['distortion']['tone'],
length=100,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
).grid(row=1, column=1, padx=5)
# Mix
ttk.Label(controls_frame, text="Mix:").grid(row=2, column=0, sticky=tk.W)
ttk.Scale(
controls_frame,
from_=0.0,
to=1.0,
variable=self.effects['distortion']['mix'],
length=100,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
).grid(row=2, column=1, padx=5)
def _create_compressor_module(self, parent):
"""Create compressor effect module."""
comp_frame = ttk.LabelFrame(parent, text="🎚️ Compressor", padding=10)
comp_frame.pack(fill=tk.X, pady=5)
self.effects['compressor'] = {
'enabled': tk.BooleanVar(value=True),
'threshold': tk.DoubleVar(value=0.7),
'ratio': tk.DoubleVar(value=4.0),
'attack': tk.DoubleVar(value=0.005),
'release': tk.DoubleVar(value=0.1)
}
# Enable checkbox
ttk.Checkbutton(
comp_frame,
text="Enable",
variable=self.effects['compressor']['enabled'],
command=self._on_change
).pack(anchor=tk.W)
# Controls
controls_frame = ttk.Frame(comp_frame)
controls_frame.pack(fill=tk.X, pady=5)
# Threshold
ttk.Label(controls_frame, text="Threshold:").grid(row=0, column=0, sticky=tk.W)
ttk.Scale(
controls_frame,
from_=0.0,
to=1.0,
variable=self.effects['compressor']['threshold'],
length=100,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
).grid(row=0, column=1, padx=5)
# Ratio
ttk.Label(controls_frame, text="Ratio:").grid(row=1, column=0, sticky=tk.W)
ttk.Scale(
controls_frame,
from_=1.0,
to=20.0,
variable=self.effects['compressor']['ratio'],
length=100,
orient=tk.HORIZONTAL,
command=lambda v: self._on_change()
).grid(row=1, column=1, padx=5)
def _on_change(self):
"""Handle effect parameter change."""
if self.on_change:
self.on_change(self.get_effects_state())
def get_effects_state(self) -> Dict:
"""Get current effects state."""
state = {}
for effect_name, effect_params in self.effects.items():
state[effect_name] = {
key: var.get()
for key, var in effect_params.items()
}
return state
# ============================================================================
# LIVE PERFORMANCE PAD
# ============================================================================
class PerformancePad(ttk.Frame):
"""MPC-style performance pad interface."""
def __init__(self, parent, on_trigger: Callable = None):
super().__init__(parent)
self.on_trigger = on_trigger
self.pads = []
self.pad_sounds = {}
self._create_ui()
def _create_ui(self):
"""Create performance pad UI."""
# Title
ttk.Label(self, text="🎹 Performance Pads", font=("Arial", 12, "bold")).pack(pady=5)
# Pad grid (4x4)
pad_container = ttk.Frame(self)
pad_container.pack(padx=10, pady=10)
colors = [
"#FF5722", "#2196F3", "#4CAF50", "#FFC107",
"#9C27B0", "#00BCD4", "#FF9800", "#E91E63",
"#795548", "#607D8B", "#FF5252", "#536DFE",
"#69F0AE", "#FFD740", "#FF6E40", "#18FFFF"
]
for i in range(16):
row = i // 4
col = i % 4
pad_btn = tk.Button(
pad_container,
text=str(i + 1),
width=8,
height=4,
bg=colors[i],
fg="white",
font=("Arial", 12, "bold"),
relief=tk.RAISED,
bd=3
)
pad_btn.grid(row=row, column=col, padx=2, pady=2)
# Bind events
pad_btn.bind("<ButtonPress-1>", lambda e, idx=i: self._on_pad_press(idx))
pad_btn.bind("<ButtonRelease-1>", lambda e, idx=i: self._on_pad_release(idx))
self.pads.append(pad_btn)
# Control panel
control_frame = ttk.Frame(self)
control_frame.pack(fill=tk.X, pady=10)
ttk.Button(
control_frame,
text="🎵 Load Sounds",
command=self._load_sounds,
bootstyle="info"
).pack(side=tk.LEFT, padx=5)
ttk.Button(
control_frame,
text="🎹 Velocity Sensitive",
command=self._toggle_velocity,
bootstyle="warning"
).pack(side=tk.LEFT, padx=5)
self.velocity_sensitive = tk.BooleanVar(value=True)
def _on_pad_press(self, pad_index: int):
"""Handle pad press."""
self.pads[pad_index].config(relief=tk.SUNKEN)
# Calculate velocity based on how quickly the pad was pressed
velocity = 0.8 # Default velocity
if self.on_trigger:
self.on_trigger(pad_index, velocity, 'press')
def _on_pad_release(self, pad_index: int):
"""Handle pad release."""
self.pads[pad_index].config(relief=tk.RAISED)
if self.on_trigger:
self.on_trigger(pad_index, 0, 'release')
def _load_sounds(self):
"""Load sounds for pads."""
# This would open a dialog to assign sounds to pads
messagebox.showinfo("Load Sounds", "Sound loading interface would appear here")
def _toggle_velocity(self):
"""Toggle velocity sensitivity."""
self.velocity_sensitive.set(not self.velocity_sensitive.get())
def assign_sound(self, pad_index: int, sound_name: str):
"""Assign a sound to a pad."""
if 0 <= pad_index < 16:
self.pad_sounds[pad_index] = sound_name
# Update pad label
self.pads[pad_index].config(text=f"{pad_index + 1}\n{sound_name[:8]}")
# ============================================================================
# BEAT SUGGESTION PANEL
# ============================================================================
class BeatSuggestionPanel(ttk.Frame):
"""AI-powered beat suggestion interface."""
def __init__(self, parent, on_apply_suggestion: Callable = None):
super().__init__(parent)
self.on_apply_suggestion = on_apply_suggestion
self.current_suggestions = []
self._create_ui()
def _create_ui(self):
"""Create suggestion panel UI."""
# Header
header_frame = ttk.Frame(self)
header_frame.pack(fill=tk.X, pady=(0, 10))
ttk.Label(
header_frame,
text="🤖 AI Beat Suggestions",
font=("Arial", 12, "bold")
).pack(side=tk.LEFT)
ttk.Button(
header_frame,
text="🔄 Refresh",
command=self._refresh_suggestions,
bootstyle="info",
width=10
).pack(side=tk.RIGHT)
# Suggestions container
self.suggestions_frame = ttk.Frame(self)
self.suggestions_frame.pack(fill=tk.BOTH, expand=True)
# Initial suggestions
self._create_suggestion_cards()
def _create_suggestion_cards(self):
"""Create suggestion cards."""
# Clear existing cards
for widget in self.suggestions_frame.winfo_children():
widget.destroy()
# Sample suggestions
suggestions = [
{
'name': 'Trap Banger',
'tempo': 140,
'style': 'Aggressive trap with heavy 808s',
'energy': 9,
'color': 'danger'
},
{
'name': 'Lo-Fi Chill',
'tempo': 75,
'style': 'Relaxed boom bap with vinyl texture',
'energy': 3,
'color': 'info'
},
{
'name': 'Drill Intensity',
'tempo': 145,
'style': 'UK drill with sliding 808s',
'energy': 8,
'color': 'warning'
},
{
'name': 'Jazz Fusion',
'tempo': 110,
'style': 'Complex jazz-influenced hip-hop',
'energy': 6,
'color': 'success'
}
]
for i, suggestion in enumerate(suggestions):
card = self._create_suggestion_card(self.suggestions_frame, suggestion, i)
card.pack(fill=tk.X, pady=5, padx=10)
self.current_suggestions = suggestions
def _create_suggestion_card(self, parent, suggestion: Dict, index: int) -> ttk.Frame:
"""Create a single suggestion card."""
card = ttk.LabelFrame(parent, text=suggestion['name'], bootstyle=suggestion['color'])
# Description
ttk.Label(
card,
text=suggestion['style'],
font=("Arial", 9),
wraplength=300
).pack(anchor=tk.W, padx=10, pady=(5, 0))
# Metrics
metrics_frame = ttk.Frame(card)
metrics_frame.pack(fill=tk.X, padx=10, pady=5)
ttk.Label(
metrics_frame,
text=f"BPM: {suggestion['tempo']}",
font=("Arial", 9, "bold")
).pack(side=tk.LEFT, padx=(0, 20))
ttk.Label(
metrics_frame,
text=f"Energy: {suggestion['energy']}/10",
font=("Arial", 9, "bold")
).pack(side=tk.LEFT)
# Apply button
ttk.Button(
card,
text="Apply This Style",