midi + splity

This commit is contained in:
SatyrDiamond 2023-10-03 12:26:56 -04:00
parent af313cd561
commit 4defc28f2d
5 changed files with 305 additions and 49 deletions

View file

@ -149,3 +149,5 @@ def closest(i_dict, in_value):
for num in i_dict:
if num <= in_value: outnum = num
return outnum
def most_frequent(i_list): return max(set(i_list), key = i_list.count)

134
functions/repeatfind.py Normal file
View file

@ -0,0 +1,134 @@
# SPDX-FileCopyrightText: 2023 SatyrDiamond
# SPDX-License-Identifier: GPL-3.0-or-later
from functions import xtramath
from functions import data_values
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# -------------------------------------------------- Print --------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
p_headersize = 20
p_partsize = 4
def print_usedlist(i_name, numlist):
print((i_name).rjust(p_headersize), end=' |')
for x in numlist:
if x == True: x = '###'
if x == False: x = ' '
print(str(x).rjust(p_partsize)+'|', end='')
print()
def print_numlist(i_name, numlist):
print((i_name).rjust(p_headersize), end=' |')
[print(str(x).rjust(p_partsize)+'|', end='') for x in numlist]
print()
def print_regions(i_length, i_name, regions):
usedparts = [' ' for _ in range(i_length*2)]
for region in regions:
for num in range(region[0], region[0]+region[1]):
usedparts[num] = '####'
usedparts[region[0]+region[1]] = '##\\ '
print((i_name).rjust(p_headersize), end=' |')
[print(str(x).rjust(p_partsize)+'|', end='') for x in usedparts]
print()
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# -------------------------------------------------- Find Loop --------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
cond_values_tres = 0.05
cond_same_loc_tres = 0.5
cond_null_tres = 0.4
def subfind(lst_numberlist_in, foundlocs, patnum):
foundlocs_cur = [x for x in foundlocs]
highestloc = max(foundlocs)
numlistlen = len(lst_numberlist_in)
lst_numberlist = lst_numberlist_in.copy()
lst_numberlist += [None for _ in range(numlistlen)]
out_length = 0
#print(patnum, foundlocs)
while highestloc < numlistlen:
foundlocs_cur = [x+1 for x in foundlocs_cur]
precond_values = [lst_numberlist[x] for x in foundlocs_cur]
cond_values = 1 - xtramath.average([int(x == precond_values[0]) for x in precond_values])
cond_null = 1 - xtramath.average([int(x == None) for x in precond_values])
precond_same_loc = [int(x in foundlocs) for x in foundlocs_cur]
cond_same_loc = xtramath.average(precond_same_loc)
bool_values = cond_values > cond_values_tres
bool_same_loc = cond_same_loc > cond_same_loc_tres
bool_cond_null = cond_null < cond_null_tres
#print('---', out_length, '|', precond_values, cond_values, bool_values, '|', precond_same_loc, cond_same_loc, bool_same_loc)
if bool_same_loc or bool_values or bool_cond_null: break
else:
highestloc += 1
out_length += 1
regions = [[x, out_length] for x in foundlocs]
if out_length > 1:
return regions
else:
return []
def find(lst_numberlist):
#print('---------------- repeat find ----------------')
lst_existing = []
for x in lst_numberlist:
if x != None: lst_existing.append(x)
#print_numlist('NUMLIST', lst_numberlist)
len_numberlist = len(lst_numberlist)
numbdone = []
regionsdata = []
for patnum in lst_existing:
foundlocs = [ind for ind, ele in enumerate(lst_numberlist) if ele == patnum]
if patnum not in numbdone:
if len(foundlocs) > 1:
regions = subfind(lst_numberlist, foundlocs, patnum)
if regions != []:
regionsdata.append([patnum, regions])
numbdone.append(patnum)
used_areas = [False for _ in range(len_numberlist) ]
d_endpoints = {}
for s_regionsdata in regionsdata:
#print_regions(len_numberlist, 'FOUND '+str(s_regionsdata[0]), s_regionsdata[1])
for s_reg in s_regionsdata[1]:
endpointval = s_reg[0]+s_reg[1]
for num in range(s_reg[0], s_reg[0]+s_reg[1]):
used_areas[num] = True
if endpointval not in d_endpoints: d_endpoints[endpointval] = 0
d_endpoints[endpointval] += 1
for d_endpoint in d_endpoints:
if len(regionsdata) > 4:
if d_endpoints[d_endpoint] > 1: used_areas[d_endpoint] = False
else:
if d_endpoints[d_endpoint] > 0: used_areas[d_endpoint] = False
#print_usedlist('USED', used_areas)
return used_areas

View file

@ -109,6 +109,11 @@ def cutloop(position, duration, startoffset, loopstart, loopend):
else: cutpoints = loop_after(position, duration, startoffset, loopstart, loopend)
return cutpoints
def similar(first, second):
if first == second: return 1.0
elif first == second == []: return 1.0
else: return len(set(first) & set(second)) / float(len(set(first) | set(second)))

View file

@ -5,12 +5,78 @@ notelist_blocks = []
timesigblocks = None
from functions import xtramath
from functions import data_values
from functions import repeatfind
def get_similarity_val(first, second, nlb_exists):
first_pos = [x[0] for x in nlb_exists[first]]
first_dur = [x[1] for x in nlb_exists[first]]
first_key = [x[2] for x in nlb_exists[first]]
second_pos = [x[0] for x in nlb_exists[second]]
second_dur = [x[1] for x in nlb_exists[second]]
second_key = [x[2] for x in nlb_exists[second]]
dif_pos = xtramath.similar(first_pos, second_pos)
dif_dur = xtramath.similar(first_dur, second_dur)
dif_key = xtramath.similar(first_key, second_key)
dif_all = xtramath.average([dif_pos, dif_dur, dif_key])
return dif_all
def get_similarity(patstofind, nlb_exists):
patfindlen = len(patstofind)
similarity = [[None for _ in range(patfindlen)] for _ in range(patfindlen)]
similarity_done = []
for first in patstofind:
for second in patstofind:
if ([first, second] not in similarity_done) and ([second, first] not in similarity_done):
simout = get_similarity_val(first, second, nlb_exists)
similarity_done.append([first, second])
similarity_done.append([second, first])
similarity[second][first] = simout
similarity[first][second] = simout
return similaritys
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# -------------------------------------------------- Main Function ----------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------
def smart_merge(global_regions, local_region_count_list):
nlb_pos = 0
for lregc in local_region_count_list:
nlb_exists = []
nlb_patnum = []
for nlb_num in range(nlb_pos, nlb_pos+lregc):
nlb_notes = global_regions[nlb_num][2]
if nlb_notes == []: nlb_patnum.append(None)
else:
if nlb_notes not in nlb_exists: nlb_exists.append(nlb_notes)
nlb_patnum.append(nlb_exists.index(nlb_notes))
used_areas = repeatfind.find(nlb_patnum)
for nlb_num in range(nlb_pos, nlb_pos+lregc):
used_area = used_areas[nlb_num-nlb_pos]
if global_regions[nlb_num][5] == False and used_area:
global_regions[nlb_num][5] = used_area
nlb_pos += lregc
def mergetablenotes(initnotereg, addnotereg):
inr_pos, inr_dur, inr_notes = initnotereg
anr_pos, anr_dur, anr_notes = addnotereg
for anr_note in anr_notes:
inr_notes.append([anr_note[0]+inr_dur, anr_note[1], anr_note[2]])
inr_notes.append([anr_note[0]+inr_dur, anr_note[1], anr_note[2], anr_note[3]])
return [inr_pos, inr_dur+anr_dur, inr_notes]
def add_timesigblocks(in_timesigblocks):
@ -18,8 +84,6 @@ def add_timesigblocks(in_timesigblocks):
timesigblocks = in_timesigblocks
def add_notelist(inid, notelist):
global timesigblocks
notelist_regions = []
for _ in range(len(timesigblocks)):
notelist_regions.append([])
@ -27,12 +91,14 @@ def add_notelist(inid, notelist):
for note in notelist:
note_start = note['position']
note_end = note['duration']
note_key = note['key']
del note['position']
del note['duration']
del note['key']
for tsbnum in range(len(timesigblocks)):
tsbdat = timesigblocks[tsbnum]
if tsbdat[0] <= note_start < tsbdat[1]:
notelist_regions[tsbnum].append([note_start-tsbdat[0], note_end, note])
notelist_regions[tsbnum].append([note_start-tsbdat[0], note_end, note_key, note])
break
global_regions = []
@ -76,9 +142,12 @@ def add_notelist(inid, notelist):
greg_of -= global_regions[greg_lanum][1]
greg_lanum += 1
smart_merge(global_regions, local_region_count_list)
notelist_blocks.append([inid, global_regions])
def get_notelist():
global notelist_blocks
for notelist_block in notelist_blocks:
@ -106,10 +175,12 @@ def get_notelist():
for preoutput_reg in preoutput_regs:
pop_pos, pop_dur, pop_notes = preoutput_reg
cur_placement = {'notelist': [], 'position': pop_pos, 'duration': pop_dur}
for rn_pos, rn_dur, rn_extra in pop_notes:
for pop_note in pop_notes:
rn_pos, rn_dur, rn_key, rn_extra = pop_note
out_note = rn_extra
out_note['position'] = rn_pos
out_note['duration'] = rn_dur
out_note['key'] = rn_key
cur_placement['notelist'].append(out_note)
out_placements.append(cur_placement)

View file

@ -3,10 +3,7 @@
from functions import data_bytes
fx_paramvals = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
def decode(model, device, command, data):
global fx_paramvals
devicename = 'unknown'
parsed = []
@ -27,7 +24,7 @@ def decode(model, device, command, data):
if mem_paramid[1] == 0: groups[1], nameval = 'main', ['ad_12_part_on', firstval]
if mem_paramid[1] == 1: groups[1], nameval = 'main', ['karaoke_on', firstval]
if model == 76:
elif model == 76:
devicename = 'yamaha_xg'
if command == 0 and mem_paramid[0] == 0:
@ -43,9 +40,8 @@ def decode(model, device, command, data):
if mem_paramid[1] == 126 and firstval== 0: groups[1], nameval[0] = None, 'xg_on'
if mem_paramid[1] == 126 and firstval== 0:
groups[1], nameval[0] = 'reset', 'all_params'
fx_paramvals = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
if command == 2 and mem_paramid[0] == 1:
elif command == 2 and mem_paramid[0] == 1:
groups[0] = 'effects'
if mem_paramid[1] == 0: groups[1], nameval = 'reverb', ['type', list(mem_data)]
@ -85,7 +81,7 @@ def decode(model, device, command, data):
if mem_paramid[1] == 52: groups[1], nameval = 'chorus', ['input_mode', firstval]
if mem_paramid[1] == 64:
value = list(data[2:4])
value = list(mem_data)
groups[1], nameval = 'variation', ['effect_type', value]
if value == [0,0]: fx_set = ['off']
if value[0] in [1,2,3,4]:
@ -127,40 +123,17 @@ def decode(model, device, command, data):
fxval = int.from_bytes(mem_data, "little")
if mem_paramid[1] in [66,68,70,72,74,76,78,80,82,84]:
if mem_paramid[1] == 66: fx_paramvals[0] = fxval
if mem_paramid[1] == 68: fx_paramvals[1] = fxval
if mem_paramid[1] == 70: fx_paramvals[2] = fxval
if mem_paramid[1] == 72: fx_paramvals[3] = fxval
if mem_paramid[1] == 74: fx_paramvals[4] = fxval
if mem_paramid[1] == 76: fx_paramvals[5] = fxval
if mem_paramid[1] == 78: fx_paramvals[6] = fxval
if mem_paramid[1] == 80: fx_paramvals[7] = fxval
if mem_paramid[1] == 82: fx_paramvals[8] = fxval
if mem_paramid[1] == 84: fx_paramvals[9] = fxval
groups[1], nameval = 'variation', ['params_vals', fx_paramvals]
#if fx_set[0] == 'reverb':
# if mem_paramid[1] == 112: groups[1], nameval = 'reverb', 'delay', firstval
# if mem_paramid[1] == 113: groups[1], nameval = 'reverb', 'CracleDensity', firstval
# if mem_paramid[1] == 114: groups[1], nameval = 'reverb', 'early_reflect', firstval
# if mem_paramid[1] == 116: groups[1], nameval = 'reverb', 'feedback', firstval
#if fx_set[0] in ['delay_lr', 'delay_lcr', 'echo', 'delay_cross']:
# if mem_paramid[1] == 114: groups[1], nameval = fx_set[0], 'low_freq', firstval
# if mem_paramid[1] == 115: groups[1], nameval = fx_set[0], 'low_gain', firstval
# if mem_paramid[1] == 116: groups[1], nameval = fx_set[0], 'hi_freq', firstval
# if mem_paramid[1] == 117: groups[1], nameval = fx_set[0], 'hi_gain', firstval
#
#if fx_set[0] in ['early_reflect', 'gate_reverb']:
# if mem_paramid[1] == 114: groups[1], nameval = fx_set[0], 'liveness', firstval
# if mem_paramid[1] == 115: groups[1], nameval = fx_set[0], 'density', firstval
# if mem_paramid[1] == 116: groups[1], nameval = fx_set[0], 'high_damp', firstval
#if fx_set[0] in ['chorus', 'celeste']:
# if mem_paramid[1] == 116: groups[1], nameval = fx_set[0], 'input_mode', firstval
#if fx_set[0] in ['flanger']:
# if mem_paramid[1] == 116: groups[1], nameval = fx_set[0], 'lfo_phase_diff', firstval
groups[1], nameval[1] = 'variation_param', fxval
if mem_paramid[1] == 66: nameval[0] = 0
if mem_paramid[1] == 68: nameval[0] = 1
if mem_paramid[1] == 70: nameval[0] = 2
if mem_paramid[1] == 72: nameval[0] = 3
if mem_paramid[1] == 74: nameval[0] = 4
if mem_paramid[1] == 76: nameval[0] = 5
if mem_paramid[1] == 78: nameval[0] = 6
if mem_paramid[1] == 80: nameval[0] = 7
if mem_paramid[1] == 82: nameval[0] = 8
if mem_paramid[1] == 84: nameval[0] = 9
if mem_paramid[1] == 86: groups[1], nameval = 'variation', ['return', firstval]
if mem_paramid[1] == 87: groups[1], nameval = 'variation', ['panorama', firstval]
@ -174,7 +147,77 @@ def decode(model, device, command, data):
if mem_paramid[1] == 95: groups[1], nameval = 'variation', ['ctrl_1', firstval]
if mem_paramid[1] == 96: groups[1], nameval = 'variation', ['ctrl_2', firstval]
if command == 8:
if mem_paramid[1] == 112: groups[1], nameval = 'variation_param', [10, firstval]
if mem_paramid[1] == 113: groups[1], nameval = 'variation_param', [11, firstval]
if mem_paramid[1] == 114: groups[1], nameval = 'variation_param', [12, firstval]
if mem_paramid[1] == 115: groups[1], nameval = 'variation_param', [13, firstval]
if mem_paramid[1] == 116: groups[1], nameval = 'variation_param', [14, firstval]
if mem_paramid[1] == 117: groups[1], nameval = 'variation_param', [15, firstval]
elif command == 2 and mem_paramid[0] == 64:
groups[0] = 'effects'
if mem_paramid[1] == 0: groups[1], nameval = 'eq', ['type', firstval]
if mem_paramid[1] == 1: groups[1], nameval = 'eq_1', ['gain', firstval]
if mem_paramid[1] == 2: groups[1], nameval = 'eq_1', ['freq', firstval]
if mem_paramid[1] == 3: groups[1], nameval = 'eq_1', ['q', firstval]
if mem_paramid[1] == 4: groups[1], nameval = 'eq_1', ['shape', firstval]
if mem_paramid[1] == 5: groups[1], nameval = 'eq_2', ['gain', firstval]
if mem_paramid[1] == 6: groups[1], nameval = 'eq_2', ['freq', firstval]
if mem_paramid[1] == 7: groups[1], nameval = 'eq_2', ['q', firstval]
if mem_paramid[1] == 8: groups[1], nameval = 'eq_2', ['shape', firstval]
if mem_paramid[1] == 9: groups[1], nameval = 'eq_3', ['gain', firstval]
if mem_paramid[1] == 10: groups[1], nameval = 'eq_3', ['freq', firstval]
if mem_paramid[1] == 11: groups[1], nameval = 'eq_3', ['q', firstval]
if mem_paramid[1] == 12: groups[1], nameval = 'eq_3', ['shape', firstval]
if mem_paramid[1] == 13: groups[1], nameval = 'eq_4', ['gain', firstval]
if mem_paramid[1] == 14: groups[1], nameval = 'eq_4', ['freq', firstval]
if mem_paramid[1] == 15: groups[1], nameval = 'eq_4', ['q', firstval]
if mem_paramid[1] == 16: groups[1], nameval = 'eq_4', ['shape', firstval]
if mem_paramid[1] == 17: groups[1], nameval = 'eq_5', ['gain', firstval]
if mem_paramid[1] == 18: groups[1], nameval = 'eq_5', ['freq', firstval]
if mem_paramid[1] == 19: groups[1], nameval = 'eq_5', ['q', firstval]
if mem_paramid[1] == 20: groups[1], nameval = 'eq_5', ['shape', firstval]
elif command == 3 and mem_paramid[0] == 0:
groups[0] = 'effects'
if mem_paramid[1] == 0: groups[1], nameval = 'xg_fx', ['type', list(mem_data)]
if mem_paramid[1] == 2: groups[1], nameval = 'xg_fx_param', [0, firstval]
if mem_paramid[1] == 3: groups[1], nameval = 'xg_fx_param', [1, firstval]
if mem_paramid[1] == 4: groups[1], nameval = 'xg_fx_param', [2, firstval]
if mem_paramid[1] == 5: groups[1], nameval = 'xg_fx_param', [3, firstval]
if mem_paramid[1] == 6: groups[1], nameval = 'xg_fx_param', [4, firstval]
if mem_paramid[1] == 7: groups[1], nameval = 'xg_fx_param', [5, firstval]
if mem_paramid[1] == 8: groups[1], nameval = 'xg_fx_param', [6, firstval]
if mem_paramid[1] == 9: groups[1], nameval = 'xg_fx_param', [7, firstval]
if mem_paramid[1] == 10: groups[1], nameval = 'xg_fx_param', [8, firstval]
if mem_paramid[1] == 11: groups[1], nameval = 'xg_fx_param', [9, firstval]
if mem_paramid[1] == 12: groups[1], nameval = 'xg_fx', ['part', firstval]
if mem_paramid[1] == 13: groups[1], nameval = 'xg_fx', ['mw_depth', firstval]
if mem_paramid[1] == 14: groups[1], nameval = 'xg_fx', ['bend', firstval]
if mem_paramid[1] == 15: groups[1], nameval = 'xg_fx', ['cat', firstval]
if mem_paramid[1] == 16: groups[1], nameval = 'xg_fx', ['ac1', firstval]
if mem_paramid[1] == 17: groups[1], nameval = 'xg_fx', ['ac2', firstval]
if mem_paramid[1] == 32: groups[1], nameval = 'xg_fx_param', [10, firstval]
if mem_paramid[1] == 33: groups[1], nameval = 'xg_fx_param', [11, firstval]
if mem_paramid[1] == 34: groups[1], nameval = 'xg_fx_param', [12, firstval]
if mem_paramid[1] == 35: groups[1], nameval = 'xg_fx_param', [13, firstval]
if mem_paramid[1] == 36: groups[1], nameval = 'xg_fx_param', [14, firstval]
elif command == 6 and mem_paramid[0] == 0:
groups, nameval = ['display', 'text'], ['text', mem_data]
elif command == 7:
bmpext = data_bytes.splitbyte(mem_paramid[0])
groups, nameval = ['display', 'bitmap'], [bmpext, mem_data]
elif command == 8:
groups = ['part', mem_paramid[0]]
if mem_paramid[1] != 9: nameval[1] = firstval
else: nameval[1] = mem_data
@ -285,7 +328,8 @@ def decode(model, device, command, data):
if mem_paramid[1] == 115: nameval[0] = "eq_treble_gain"
if mem_paramid[1] == 118: nameval[0] = "eq_bass_frequency"
if mem_paramid[1] == 119: nameval[0] = "eq_treble_frequency"
#print('[Yamaha]', devicename, model, hex(model), command, groups, nameval)
#else:
# print('[UNK Yamaha]', devicename, model, hex(model), command, groups, nameval)
return devicename, groups, nameval