asigalov61 commited on
Commit
7dcbfde
·
verified ·
1 Parent(s): 3f6190e

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +195 -15
TMIDIX.py CHANGED
@@ -8,7 +8,7 @@ r'''############################################################################
8
  # Tegridy MIDI X Module (TMIDI X / tee-midi eks)
9
  # Version 1.0
10
  #
11
- # NOTE: TMIDI X Module starts after the partial MIDI.py module @ line 1342
12
  #
13
  # Based upon MIDI.py module v.6.7. by Peter Billam / pjb.com.au
14
  #
@@ -21,19 +21,19 @@ r'''############################################################################
21
  #
22
  ###################################################################################
23
  ###################################################################################
24
- # Copyright 2025 Project Los Angeles / Tegridy Code
25
  #
26
- # Licensed under the Apache License, Version 2.0 (the "License");
27
- # you may not use this file except in compliance with the License.
28
- # You may obtain a copy of the License at
29
  #
30
- # http://www.apache.org/licenses/LICENSE-2.0
31
  #
32
- # Unless required by applicable law or agreed to in writing, software
33
- # distributed under the License is distributed on an "AS IS" BASIS,
34
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35
- # See the License for the specific language governing permissions and
36
- # limitations under the License.
37
  ###################################################################################
38
  ###################################################################################
39
  #
@@ -1446,8 +1446,9 @@ def _encode(events_lol, unknown_callback=None, never_add_eot=False,
1446
  # pjb.com.au
1447
  #
1448
  # Project Los Angeles
1449
- # Tegridy Code 2021
1450
- # https://github.com/Tegridy-Code/Project-Los-Angeles
 
1451
  #
1452
  ###################################################################################
1453
  ###################################################################################
@@ -1490,6 +1491,10 @@ import math
1490
 
1491
  import matplotlib.pyplot as plt
1492
 
 
 
 
 
1493
  ###################################################################################
1494
  #
1495
  # Original TMIDI Tegridy helper functions
@@ -11182,7 +11187,182 @@ def rle_decode_ones(encoding, size=(128, 128)):
11182
  return matrix
11183
 
11184
  ###################################################################################
11185
- #
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11186
  # This is the end of the TMIDI X Python module
11187
- #
11188
  ###################################################################################
 
8
  # Tegridy MIDI X Module (TMIDI X / tee-midi eks)
9
  # Version 1.0
10
  #
11
+ # NOTE: TMIDI X Module starts after the partial MIDI.py module @ line 1438
12
  #
13
  # Based upon MIDI.py module v.6.7. by Peter Billam / pjb.com.au
14
  #
 
21
  #
22
  ###################################################################################
23
  ###################################################################################
24
+ # Copyright 2025 Project Los Angeles / Tegridy Code
25
  #
26
+ # Licensed under the Apache License, Version 2.0 (the "License");
27
+ # you may not use this file except in compliance with the License.
28
+ # You may obtain a copy of the License at
29
  #
30
+ # http://www.apache.org/licenses/LICENSE-2.0
31
  #
32
+ # Unless required by applicable law or agreed to in writing, software
33
+ # distributed under the License is distributed on an "AS IS" BASIS,
34
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35
+ # See the License for the specific language governing permissions and
36
+ # limitations under the License.
37
  ###################################################################################
38
  ###################################################################################
39
  #
 
1446
  # pjb.com.au
1447
  #
1448
  # Project Los Angeles
1449
+ # Tegridy Code 2025
1450
+ #
1451
+ # https://github.com/Tegridy-Code/Project-Los-Angeles
1452
  #
1453
  ###################################################################################
1454
  ###################################################################################
 
1491
 
1492
  import matplotlib.pyplot as plt
1493
 
1494
+ import psutil
1495
+
1496
+ from collections import defaultdict
1497
+
1498
  ###################################################################################
1499
  #
1500
  # Original TMIDI Tegridy helper functions
 
11187
  return matrix
11188
 
11189
  ###################################################################################
11190
+
11191
+ def vertical_list_search(list_of_lists, trg_list):
11192
+
11193
+ src_list = list_of_lists
11194
+
11195
+ if not src_list or not trg_list:
11196
+ return []
11197
+
11198
+ num_rows = len(src_list)
11199
+ k = len(trg_list)
11200
+
11201
+ row_sets = [set(row) for row in src_list]
11202
+
11203
+ results = []
11204
+
11205
+ for start in range(num_rows - k + 1):
11206
+ valid = True
11207
+
11208
+ for offset, target in enumerate(trg_list):
11209
+
11210
+ if target not in row_sets[start + offset]:
11211
+ valid = False
11212
+ break
11213
+
11214
+ if valid:
11215
+ results.append(list(range(start, start + k)))
11216
+
11217
+ return results
11218
+
11219
+ ###################################################################################
11220
+
11221
+ def smooth_values(values, window_size=3):
11222
+
11223
+ smoothed = []
11224
+
11225
+ for i in range(len(values)):
11226
+
11227
+ start = max(0, i - window_size // 2)
11228
+ end = min(len(values), i + window_size // 2 + 1)
11229
+
11230
+ window = values[start:end]
11231
+
11232
+ smoothed.append(int(sum(window) / len(window)))
11233
+
11234
+ return smoothed
11235
+
11236
+ ###################################################################################
11237
+
11238
+ def is_mostly_wide_peaks_and_valleys(values,
11239
+ min_range=32,
11240
+ threshold=0.7,
11241
+ smoothing_window=5
11242
+ ):
11243
+
11244
+ if not values:
11245
+ return False
11246
+
11247
+ smoothed_values = smooth_values(values, smoothing_window)
11248
+
11249
+ value_range = max(smoothed_values) - min(smoothed_values)
11250
+
11251
+ if value_range < min_range:
11252
+ return False
11253
+
11254
+ if all(v == smoothed_values[0] for v in smoothed_values):
11255
+ return False
11256
+
11257
+ trend_types = []
11258
+
11259
+ for i in range(1, len(smoothed_values)):
11260
+ if smoothed_values[i] > smoothed_values[i - 1]:
11261
+ trend_types.append(1)
11262
+
11263
+ elif smoothed_values[i] < smoothed_values[i - 1]:
11264
+ trend_types.append(-1)
11265
+
11266
+ else:
11267
+ trend_types.append(0)
11268
+
11269
+ trend_count = trend_types.count(1) + trend_types.count(-1)
11270
+
11271
+ proportion = trend_count / len(trend_types)
11272
+
11273
+ return proportion >= threshold
11274
+
11275
+ ###################################################################################
11276
+
11277
+ def system_memory_utilization(return_dict=False):
11278
+
11279
+ if return_dict:
11280
+ return dict(psutil.virtual_memory()._asdict())
11281
+
11282
+ else:
11283
+ print('RAM memory % used:', psutil.virtual_memory()[2])
11284
+ print('RAM Used (GB):', psutil.virtual_memory()[3]/(1024**3))
11285
+
11286
+ ###################################################################################
11287
+
11288
+ def create_files_list(datasets_paths=['./'],
11289
+ files_exts=['.mid', '.midi', '.kar', '.MID', '.MIDI', '.KAR'],
11290
+ randomize_files_list=True,
11291
+ verbose=True
11292
+ ):
11293
+ if verbose:
11294
+ print('=' * 70)
11295
+ print('Searching for files...')
11296
+ print('This may take a while on a large dataset in particular...')
11297
+ print('=' * 70)
11298
+
11299
+ filez_set = defaultdict(None)
11300
+
11301
+ files_exts = tuple(files_exts)
11302
+
11303
+ for dataset_addr in tqdm.tqdm(datasets_paths):
11304
+ for dirpath, dirnames, filenames in os.walk(dataset_addr):
11305
+ for file in filenames:
11306
+ if file not in filez_set and file.endswith(files_exts):
11307
+ filez_set[os.path.join(dirpath, file)] = None
11308
+
11309
+ filez = list(filez_set.keys())
11310
+
11311
+ if verbose:
11312
+ print('Done!')
11313
+ print('=' * 70)
11314
+
11315
+ if filez:
11316
+ if randomize_files_list:
11317
+
11318
+ if verbose:
11319
+ print('Randomizing file list...')
11320
+
11321
+ random.shuffle(filez)
11322
+
11323
+ if verbose:
11324
+ print('Done!')
11325
+ print('=' * 70)
11326
+
11327
+ if verbose:
11328
+ print('Found', len(filez), 'files.')
11329
+ print('=' * 70)
11330
+
11331
+ else:
11332
+ if verbose:
11333
+ print('Could not find any files...')
11334
+ print('Please check dataset dirs and files extensions...')
11335
+ print('=' * 70)
11336
+
11337
+ return filez
11338
+
11339
+ ###################################################################################
11340
+
11341
+ def has_consecutive_trend(nums, count):
11342
+
11343
+ if len(nums) < count:
11344
+ return False
11345
+
11346
+ increasing_streak = 1
11347
+ decreasing_streak = 1
11348
+
11349
+ for i in range(1, len(nums)):
11350
+ if nums[i] > nums[i - 1]:
11351
+ increasing_streak += 1
11352
+ decreasing_streak = 1
11353
+
11354
+ elif nums[i] < nums[i - 1]:
11355
+ decreasing_streak += 1
11356
+ increasing_streak = 1
11357
+
11358
+ else:
11359
+ increasing_streak = decreasing_streak = 1
11360
+
11361
+ if increasing_streak == count or decreasing_streak == count:
11362
+ return True
11363
+
11364
+ return False
11365
+
11366
+ ###################################################################################
11367
  # This is the end of the TMIDI X Python module
 
11368
  ###################################################################################