-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_patternchange2.py
More file actions
122 lines (117 loc) · 8.35 KB
/
replace_patternchange2.py
File metadata and controls
122 lines (117 loc) · 8.35 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
import re
with open('src/hooks/useAppState.tsx', 'r') as f:
content = f.read()
diff = """<<<<<<< SEARCH
const handlePatternChange = useCallback((rowKey: keyof Pattern, i: number, _subIndex?: number | unknown, updates?: { length?: number, slide?: boolean, chord?: string[], sliceIndex?: number }) => {
const prev = patternRef.current;
const copy = { ...prev };
let changedSequence;
if (rowKey === 'sampler') {
const bankIndex = activeSamplerBankRef.current;
const newSampler = [...prev.sampler];
newSampler[bankIndex] = { ...newSampler[bankIndex], steps: [...newSampler[bankIndex].steps] };
const steps = newSampler[bankIndex].steps;
const existing = steps[i];
if (updates) {
if (existing) {
const newStep = { ...existing };
if (updates.length !== undefined) newStep.length = updates.length;
if (updates.slide !== undefined) newStep.slide = updates.slide;
if (updates.chord !== undefined) newStep.chord = updates.chord;
if (updates.sliceIndex !== undefined) newStep.sliceIndex = updates.sliceIndex;
steps[i] = newStep;
if (updates.length !== undefined) { for (let k = 1; k < updates.length; k++) { const nextStepIdx = i + k; if (nextStepIdx < steps.length) { steps[nextStepIdx] = null; } } }
}
} else { if (existing) { steps[i] = null; } else { steps[i] = { note: 'C4', velocity: 1, length: 1, slide: false }; } }
changedSequence = copy.sampler;
} else {
const track = rowKey as TrackKey;
copy[track] = { ...copy[track], steps: [...copy[track].steps] };
const steps = copy[track].steps;
const existing = steps[i];
if (updates) {
if (existing) {
const newStep = { ...existing };
if (updates.length !== undefined) newStep.length = updates.length;
if (updates.slide !== undefined) newStep.slide = updates.slide;
if (updates.chord !== undefined) newStep.chord = updates.chord;
steps[i] = newStep;
if (updates.length !== undefined) { for (let k = 1; k < updates.length; k++) { const nextStepIdx = i + k; if (nextStepIdx < steps.length) { steps[nextStepIdx] = null; } } }
}
} else { if (existing) { steps[i] = null; } else { const defaultNote = rowKey.startsWith('part') ? (rowKey === 'partA' ? 'C4' : 'C3') : 'C4'; steps[i] = { note: defaultNote, velocity: 1, length: 1, slide: false }; } }
changedSequence = copy[rowKey];
}
setPattern(copy);
updateStorageForTrack(rowKey, changedSequence);
}, [updateStorageForTrack]);
const handleStepToggle = useCallback((rowKey: TrackKey, index: number, e: any) => {
if (e.altKey) { e.preventDefault(); let step = null; if (rowKey === 'sampler') { step = patternRef.current.sampler[activeSamplerBankRef.current].steps[index]; } else { step = patternRef.current[rowKey].steps[index]; } if (step) { handlePatternChange(rowKey, index, undefined, { slide: !step.slide }); } return; }
if (e.ctrlKey || e.metaKey) { e.preventDefault(); let step = null; if (rowKey === 'sampler') { step = patternRef.current.sampler[activeSamplerBankRef.current].steps[index]; } else { step = patternRef.current[rowKey].steps[index]; } if (step) { if (step.chord && step.chord.length > 0) { handlePatternChange(rowKey, index, undefined, { chord: [] }); } else { const root = noteToMidi(step.note); const chord = [midiToNote(root + 4), midiToNote(root + 7)]; handlePatternChange(rowKey, index, undefined, { chord }); } } return; }
const pattern = patternRef.current;
let step = null;
if (rowKey === 'sampler') { step = pattern.sampler[activeSamplerBankRef.current].steps[index]; }
else { step = pattern[rowKey].steps[index]; }
const isActive = !!step;
setIsDrawing(true);
setDrawMode(isActive ? 'remove' : 'add');
handlePatternChange(rowKey, index, e);
}, [handlePatternChange]);
=======
const handlePatternChange = useCallback((rowKey: keyof Pattern, i: number, _subIndex?: number | unknown, updates?: { length?: number, slide?: boolean, chord?: string[], sliceIndex?: number }) => {
const prev = patternRef.current;
const copy = { ...prev };
let changedSequence;
if (rowKey === 'sampler') {
const bankIndex = activeSamplerBankRef.current;
const newSampler = [...prev.sampler];
newSampler[bankIndex] = { ...newSampler[bankIndex], steps: [...newSampler[bankIndex].steps] };
const steps = newSampler[bankIndex].steps;
const existing = steps[i];
if (updates) {
if (existing) {
const newStep = { ...existing };
if (updates.length !== undefined) newStep.length = updates.length;
if (updates.slide !== undefined) newStep.slide = updates.slide;
if (updates.chord !== undefined) newStep.chord = updates.chord;
if (updates.sliceIndex !== undefined) newStep.sliceIndex = updates.sliceIndex;
steps[i] = newStep;
if (updates.length !== undefined) { for (let k = 1; k < updates.length; k++) { const nextStepIdx = i + k; if (nextStepIdx < steps.length) { steps[nextStepIdx] = null; } } }
}
} else { if (existing) { steps[i] = null; } else { steps[i] = { note: 'C4', velocity: 1, length: 1, slide: false }; } }
changedSequence = newSampler;
copy.sampler = newSampler;
} else {
const track = rowKey as TrackKey;
copy[track] = { ...(copy[track] as any), steps: [...(copy[track] as any).steps] };
const steps = (copy[track] as any).steps;
const existing = steps[i];
if (updates) {
if (existing) {
const newStep = { ...existing };
if (updates.length !== undefined) newStep.length = updates.length;
if (updates.slide !== undefined) newStep.slide = updates.slide;
if (updates.chord !== undefined) newStep.chord = updates.chord;
steps[i] = newStep;
if (updates.length !== undefined) { for (let k = 1; k < updates.length; k++) { const nextStepIdx = i + k; if (nextStepIdx < steps.length) { steps[nextStepIdx] = null; } } }
}
} else { if (existing) { steps[i] = null; } else { const defaultNote = rowKey.startsWith('part') ? (rowKey === 'partA' ? 'C4' : 'C3') : 'C4'; steps[i] = { note: defaultNote, velocity: 1, length: 1, slide: false }; } }
changedSequence = copy[rowKey];
}
setPattern(copy);
updateStorageForTrack(rowKey, changedSequence);
}, [updateStorageForTrack]);
const handleStepToggle = useCallback((rowKey: TrackKey, index: number, e: any) => {
if (e.altKey) { e.preventDefault(); let step = null; if (rowKey === 'sampler') { step = patternRef.current.sampler[activeSamplerBankRef.current].steps[index]; } else { step = patternRef.current[rowKey].steps[index]; } if (step) { handlePatternChange(rowKey, index, undefined, { slide: !step.slide }); } return; }
if (e.ctrlKey || e.metaKey) { e.preventDefault(); let step = null; if (rowKey === 'sampler') { step = patternRef.current.sampler[activeSamplerBankRef.current].steps[index]; } else { step = patternRef.current[rowKey].steps[index]; } if (step) { if (step.chord && step.chord.length > 0) { handlePatternChange(rowKey, index, undefined, { chord: [] }); } else { const root = noteToMidi(step.note); const chord = [midiToNote(root + 4), midiToNote(root + 7)]; handlePatternChange(rowKey, index, undefined, { chord }); } } return; }
const pattern = patternRef.current;
let step = null;
if (rowKey === 'sampler') { step = pattern.sampler[activeSamplerBankRef.current].steps[index]; }
else { step = pattern[rowKey].steps[index]; }
const isActive = !!step;
setIsDrawing(true);
setDrawMode(isActive ? 'remove' : 'add');
handlePatternChange(rowKey, index, e);
}, [handlePatternChange]);
>>>>>>> REPLACE"""
with open('replace.txt', 'w') as f:
f.write(diff)