so I thought I would start with decoding a value first
Code: Select all
def mutator_schema(hex_string):
# int(value, base [16=hex])
version = int(hex_string[:2], 16)
total_notes = int(hex_string[4:6], 16)
note_data = []
for i in range(len(hex_string) // 12):
# i think the about might be wrong ?
step = int(hex_string[6 + i * 12:8 + i * 12], 16)
pitch = int(hex_string[8 + i * 12:10 + i * 12], 16) - 1
velocity = int(hex_string[10 + i * 12:12 + i * 12], 16) - 1
lengthinsteps = int(hex_string[12 + i * 12:14 + i * 12], 16) - 1
# these are possibly less needed when converting from midi
flags = int(hex_string[14 + i * 12:16 + i * 12], 16)
mute = bool(flags & 32)
tied = bool(flags & 16)
octave_offset = flags & 7 - 3
note_data.append((step, pitch, velocity, lengthinsteps, mute, tied, octave_offset))
return version, total_notes, note_data
pattern_data_1 = "020110013D67028380023D5E028380033D63028380043D35028380053D6A028380063D54028380073D36028380083D69028380093D300283800A3D2E0283800B3D610283800C3D320283800D3D670283800E3D340283800F3D43028380"
version, total_notes, note_data = mutator_schema(pattern_data_1)
print(f'{version} {total_notes}')
for note in note_data:
step, pitch, velocity, lengthinsteps, mute, tied, octave_offset = note
print(f"Note: pos={step:02}, pitch={pitch}, velocity={velocity:03}, length={lengthinsteps}, mute={mute}, tied={tied}, octave_offset={octave_offset}")
does that look right to others ?
I'm still having difficulty getting my head around it all, got stuff going on that's keeping me away from the screen.
as things stand my initial script works fine when working with my random rhythm generator script as I'm only working in 1/16th for 16 steps, but being able to dump any reasonable size midi into PM would just be cool.
that's the output from the above.
Code: Select all
2 16
Note: pos=01, pitch=60, velocity=102, length=1, mute=False, tied=False, octave_offset=0
Note: pos=02, pitch=60, velocity=093, length=1, mute=False, tied=False, octave_offset=0
Note: pos=03, pitch=60, velocity=098, length=1, mute=False, tied=False, octave_offset=0
Note: pos=04, pitch=60, velocity=052, length=1, mute=False, tied=False, octave_offset=0
Note: pos=05, pitch=60, velocity=105, length=1, mute=False, tied=False, octave_offset=0
Note: pos=06, pitch=60, velocity=083, length=1, mute=False, tied=False, octave_offset=0
Note: pos=07, pitch=60, velocity=053, length=1, mute=False, tied=False, octave_offset=0
Note: pos=08, pitch=60, velocity=104, length=1, mute=False, tied=False, octave_offset=0
Note: pos=09, pitch=60, velocity=047, length=1, mute=False, tied=False, octave_offset=0
Note: pos=10, pitch=60, velocity=045, length=1, mute=False, tied=False, octave_offset=0
Note: pos=11, pitch=60, velocity=096, length=1, mute=False, tied=False, octave_offset=0
Note: pos=12, pitch=60, velocity=049, length=1, mute=False, tied=False, octave_offset=0
Note: pos=13, pitch=60, velocity=102, length=1, mute=False, tied=False, octave_offset=0
Note: pos=14, pitch=60, velocity=051, length=1, mute=False, tied=False, octave_offset=0
Note: pos=15, pitch=60, velocity=066, length=1, mute=False, tied=False, octave_offset=0
PS C:\Billy>