asigalov61 commited on
Commit
62cfc69
·
verified ·
1 Parent(s): b2efcdc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -72
app.py CHANGED
@@ -35,109 +35,88 @@ def read_MIDI(input_midi)
35
  #=======================================================
36
  # PRE-PROCESSING
37
 
38
- # checking number of instruments in a composition
39
- instruments_list_without_drums = list(set([y[3] for y in events_matrix1 if y[3] != 9]))
40
  instruments_list = list(set([y[3] for y in events_matrix1]))
41
 
42
- if len(events_matrix1) > 0 and len(instruments_list_without_drums) > 0:
 
 
43
 
44
- #======================================
 
45
 
46
- events_matrix2 = []
 
47
 
48
- # Recalculating timings
49
- for e in events_matrix1:
50
 
51
- # Original timings
52
- e[1] = int(e[1] / 16)
53
- e[2] = int(e[2] / 16)
 
54
 
55
- #===================================
56
- # ORIGINAL COMPOSITION
57
- #===================================
 
58
 
59
- # Sorting by patch, pitch, then by start-time
60
 
61
- events_matrix1.sort(key=lambda x: x[6])
62
- events_matrix1.sort(key=lambda x: x[4], reverse=True)
63
- events_matrix1.sort(key=lambda x: x[1])
64
 
65
- #=======================================================
66
- # FINAL PROCESSING
67
 
68
- melody_chords = []
69
- melody_chords2 = []
70
 
71
- # Break between compositions / Intro seq
72
 
73
- if 9 in instruments_list:
74
- drums_present = 19331 # Yes
75
- else:
76
- drums_present = 19330 # No
77
 
78
- if events_matrix1[0][3] != 9:
79
- pat = events_matrix1[0][6]
80
- else:
81
- pat = 128
82
 
83
- melody_chords.extend([19461, drums_present, 19332+pat]) # Intro seq
84
 
85
  #=======================================================
86
- # MAIN PROCESSING CYCLE
87
- #=======================================================
88
 
89
- abs_time = 0
 
90
 
91
- pbar_time = 0
92
 
93
- pe = events_matrix1[0]
 
94
 
95
- chords_counter = 1
96
-
97
- comp_chords_len = len(list(set([y[1] for y in events_matrix1])))
98
-
99
- for e in events_matrix1:
100
-
101
- #=======================================================
102
- # Timings...
103
-
104
- # Cliping all values...
105
- delta_time = max(0, min(255, e[1]-pe[1]))
106
-
107
- # Durations and channels
108
-
109
- dur = max(0, min(255, e[2]))
110
- cha = max(0, min(15, e[3]))
111
-
112
- # Patches
113
- if cha == 9: # Drums patch will be == 128
114
- pat = 128
115
 
116
- else:
117
- pat = e[6]
118
 
119
- # Pitches
120
 
121
- ptc = max(1, min(127, e[4]))
122
 
123
- # Velocities
124
 
125
- # Calculating octo-velocity
126
- vel = max(8, min(127, e[5]))
127
- velocity = round(vel / 15)-1
128
 
129
- #=======================================================
130
- # FINAL NOTE SEQ
131
 
132
- # Writing final note asynchronously
133
 
134
- dur_vel = (8 * dur) + velocity
135
- pat_ptc = (129 * pat) + ptc
136
 
137
- melody_chords.extend([delta_time, dur_vel+256, pat_ptc+2304])
138
- melody_chords2.append([delta_time, dur_vel+256, pat_ptc+2304])
139
 
140
- pe = e
141
 
142
  return melody_chords, melody_chords2
143
 
 
35
  #=======================================================
36
  # PRE-PROCESSING
37
 
 
 
38
  instruments_list = list(set([y[3] for y in events_matrix1]))
39
 
40
+ #======================================
41
+
42
+ events_matrix1 = TMIDIX.augment_enhanced_score_notes(events_matrix1, timings_divider=16)
43
 
44
+ #=======================================================
45
+ # FINAL PROCESSING
46
 
47
+ melody_chords = []
48
+ melody_chords2 = []
49
 
50
+ # Break between compositions / Intro seq
 
51
 
52
+ if 9 in instruments_list:
53
+ drums_present = 19331 # Yes
54
+ else:
55
+ drums_present = 19330 # No
56
 
57
+ if events_matrix1[0][3] != 9:
58
+ pat = events_matrix1[0][6]
59
+ else:
60
+ pat = 128
61
 
62
+ melody_chords.extend([19461, drums_present, 19332+pat]) # Intro seq
63
 
64
+ #=======================================================
65
+ # MAIN PROCESSING CYCLE
66
+ #=======================================================
67
 
68
+ abs_time = 0
 
69
 
70
+ pbar_time = 0
 
71
 
72
+ pe = events_matrix1[0]
73
 
74
+ chords_counter = 1
 
 
 
75
 
76
+ comp_chords_len = len(list(set([y[1] for y in events_matrix1])))
 
 
 
77
 
78
+ for e in events_matrix1:
79
 
80
  #=======================================================
81
+ # Timings...
 
82
 
83
+ # Cliping all values...
84
+ delta_time = max(0, min(255, e[1]-pe[1]))
85
 
86
+ # Durations and channels
87
 
88
+ dur = max(0, min(255, e[2]))
89
+ cha = max(0, min(15, e[3]))
90
 
91
+ # Patches
92
+ if cha == 9: # Drums patch will be == 128
93
+ pat = 128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
+ else:
96
+ pat = e[6]
97
 
98
+ # Pitches
99
 
100
+ ptc = max(1, min(127, e[4]))
101
 
102
+ # Velocities
103
 
104
+ # Calculating octo-velocity
105
+ vel = max(8, min(127, e[5]))
106
+ velocity = round(vel / 15)-1
107
 
108
+ #=======================================================
109
+ # FINAL NOTE SEQ
110
 
111
+ # Writing final note asynchronously
112
 
113
+ dur_vel = (8 * dur) + velocity
114
+ pat_ptc = (129 * pat) + ptc
115
 
116
+ melody_chords.extend([delta_time, dur_vel+256, pat_ptc+2304])
117
+ melody_chords2.append([delta_time, dur_vel+256, pat_ptc+2304])
118
 
119
+ pe = e
120
 
121
  return melody_chords, melody_chords2
122