Upload TMIDIX.py
Browse files1234567891011123 unmodified lines1617181920212223247 unmodified lines323334353637387 unmodified lines4647484950515253545556575 unmodified lines636465666768697071727374751371 unmodified lines144714481449145014511452145314542 unmodified lines14571458145914601461146214631464146514661467146814695686 unmodified lines71567157715871597160716171624 unmodified lines7167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721012 unmodified lines72237224722572267227722811379 unmodified lines186081860918610186111861218613#! /usr/bin/python3r'''##################################################################################################################################################################### Tegridy MIDI X Module (TMIDI X / tee-midi eks)## NOTE: TMIDI X Module starts after the partial MIDI.py module @ line 1450## Based upon MIDI.py module v.6.7. by Peter Billam / pjb.com.au#3 unmodified lines## https://github.com/Tegridy-Code/Project-Los-Angeles######################################################################################################################################################################### Copyright 2026 Project Los Angeles / Tegridy Code## Licensed under the Apache License, Version 2.0 (the "License");7 unmodified lines# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.######################################################################################################################################################################## PARTIAL MIDI.py Module v.6.7. by Peter Billam7 unmodified lines# Copyright 2020 Peter Billam#######################################################################################################################################################################'''###################################################################################__version__ = "26.4.21"print('=' * 70)print('TMIDIX Python module')5 unmodified linesimport sys, struct, copyVersion = '6.7'VersionDate = '20201120'_previous_warning = '' # 5.4_previous_times = 0 # 5.4_no_warning = False#------------------------------- Encoding stuff --------------------------def opus2midi(opus=[], text_encoding='ISO-8859-1'):1371 unmodified linesreturn b''.join(data)########################################################################################################################################################################################################################################################### Tegridy MIDI X Module (TMIDI X / tee-midi eks)2 unmodified lines# pjb.com.au## Project Los Angeles# Tegridy Code 2025## https://github.com/Tegridy-Code/Project-Los-Angeles##########################################################################################################################################################################################################################################################import os5686 unmodified linespatch=0,flip_matrix=False,reverse_matrix=False,encode_velocities=False):escore = [e for e in escore_notes if e[3] == channel and e[6] == patch]4 unmodified linesmax_last_dur = max([e[2] for e in last_notes])time_range = last_time+max_last_durescore_matrix = []escore_matrix = [[0] * 128 for _ in range(time_range)]for note in escore:etype, time, duration, chan, pitch, velocity, pat = notetime = max(0, time)duration = max(1, duration)chan = max(0, min(15, chan))pitch = max(0, min(127, pitch))velocity = max(1, min(127, velocity))pat = max(0, min(128, pat))if channel == chan and patch == pat:for t in range(time, min(time + duration, time_range)):if encode_velocities:escore_matrix[t][pitch] = velocityelse:escore_matrix[t][pitch] = 1if flip_matrix:temp_matrix = []for m in escore_matrix:temp_matrix.append(m[::-1])escore_matrix = temp_matrixif reverse_matrix:escore_matrix = escore_matrix[::-1]return escore_matrixelse:return None12 unmodified linesfor j in range(len(binary_matrix[0])):count = 1for i in range(1, len(binary_matrix)):11379 unmodified lines###################################################################################print('Module loaded!')print('=' * 70)print('Enjoy! :)')12345678910113 unmodified lines15161718192021227 unmodified lines303132333435367 unmodified lines444546474849505152535455565 unmodified lines626364656667686970717273747576777879808182838485861371 unmodified lines1458145914601461146214632 unmodified lines146614671468146914701471147214731474147514765686 unmodified lines716371647165716671677168716971704 unmodified lines7175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724212 unmodified lines725572567257725872597260726111379 unmodified lines186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667#! /usr/bin/python3r'''################################################################################# Tegridy MIDI X Module (TMIDI X / tee-midi eks)## NOTE: TMIDI X Module starts after the partial MIDI.py module @ line 1461## Based upon MIDI.py module v.6.7. by Peter Billam / pjb.com.au#3 unmodified lines## https://github.com/Tegridy-Code/Project-Los-Angeles###################################################################################### Copyright 2026 Project Los Angeles / Tegridy Code## Licensed under the Apache License, Version 2.0 (the "License");7 unmodified lines# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.###################################################################################### PARTIAL MIDI.py Module v.6.7. by Peter Billam7 unmodified lines# Copyright 2020 Peter Billam####################################################################################'''###################################################################################__version__ = "26.4.27" # TMIDIX version###################################################################################print('=' * 70)print('TMIDIX Python module')5 unmodified linesimport sys, struct, copy###################################################################################Version = '6.7'VersionDate = '20201120'###################################################################################_previous_warning = '' # 5.4_previous_times = 0 # 5.4_no_warning = False###################################################################################def set_no_warning(value: bool):global _no_warning_no_warning = value####################################################################################------------------------------- Encoding stuff --------------------------def opus2midi(opus=[], text_encoding='ISO-8859-1'):1371 unmodified linesreturn b''.join(data)##################################################################################### Tegridy MIDI X Module (TMIDI X / tee-midi eks)2 unmodified lines# pjb.com.au## Project Los Angeles# Tegridy Code 2026## https://github.com/Tegridy-Code/Project-Los-Angeles####################################################################################import os5686 unmodified linespatch=0,flip_matrix=False,reverse_matrix=False,encode_velocities=False,dry_run=False):escore = [e for e in escore_notes if e[3] == channel and e[6] == patch]4 unmodified linesmax_last_dur = max([e[2] for e in last_notes])time_range = last_time+max_last_durif dry_run:escore_matrix = [[] for _ in range(time_range)]for note in escore:etype, time, duration, chan, pitch, velocity, pat = notetime = max(0, time)duration = max(1, duration)chan = max(0, min(15, chan))pitch = max(0, min(127, pitch))velocity = max(1, min(127, velocity))pat = max(0, min(128, pat))if channel == chan and patch == pat:for t in range(time, min(time + duration, time_range)):if encode_velocities:escore_matrix[t].extend([pitch, velocity])else:escore_matrix[t].append(pitch)return escore_matrixelse:escore_matrix = [[0] * 128 for _ in range(time_range)]for note in escore:etype, time, duration, chan, pitch, velocity, pat = notetime = max(0, time)duration = max(1, duration)chan = max(0, min(15, chan))pitch = max(0, min(127, pitch))velocity = max(1, min(127, velocity))pat = max(0, min(128, pat))if channel == chan and patch == pat:for t in range(time, min(time + duration, time_range)):if encode_velocities:escore_matrix[t][pitch] = velocityelse:escore_matrix[t][pitch] = 1if flip_matrix:temp_matrix = []for m in escore_matrix:temp_matrix.append(m[::-1])escore_matrix = temp_matrixif reverse_matrix:escore_matrix = escore_matrix[::-1]return escore_matrixelse:return None12 unmodified linesfor j in range(len(binary_matrix[0])):count = 1i = 1for i in range(1, len(binary_matrix)):11379 unmodified lines###################################################################################def set_of_sublists(list_of_lists):seen = set()add = seen.addfor sub in list_of_lists:add(tuple(sub))return [list(t) for t in seen]###################################################################################def escore_notes_run_time(escore_notes, time_idx=1, dur_idx=2):last_time = escore_notes[-1][time_idx]last_notes = [e for e in escore_notes if e[time_idx] == last_time]max_dur = max([e[dur_idx] for e in last_notes])return [last_time+max_dur, last_time]###################################################################################print('Module loaded!')print('=' * 70)print('Enjoy! :)')
TMIDIX.py+94-40