#! /usr/bin/python import sys, os # Compares Qtractor Normalize with an Alternative Normalize # written by dave@multitrack.co.nz #************************************** def QtrNorm(nVelo, percent, value, mxVelo): rtn = 0 # Formula: normalized_value = value * (param_percent * param_value) / (100 * max_value) w = percent * value x = 100 * mxVelo y = nVelo * (w / x) z = round(y) rtn = str(z) return rtn #************************************** def AltNorm(nVelo, percent, target, mxVelo): rtn = 0 # Recommend using compression ratio eg: 2:1, 3:1, 4:1, 6:1, 8:1 etc # Converted to a percentage for this test, to match Qtractor input. compress = 100 / percent # Prevent negative velocity, when re-scaling dff = mxVelo - target if dff > 0: compress = mxVelo / target # Formula: normalized_value = (note_velo / compress_ratio) + gain # Calculate gain gain = target - (mxVelo / compress) # Compress and Normalize x = (nVelo / compress) + gain y = round(x) rtn = str(y) return rtn #************************************** # Run process print('\n**** Compare Normalization ****') # User Inputs x = input('Compress data (percentage): ') percent = int(x) x = input('New max velocity (1-127): ') value = int(x) print() # Note: In the real world, mxVelo would not exceed the range of nVelo. mxVelo = nVelo = 127 while nVelo >= 0: qtr = QtrNorm(nVelo, percent, value, mxVelo) alt = AltNorm(nVelo, percent, value, mxVelo) print('Note Velocity:',nVelo,'\tQtr Norm Value:',qtr,'\tAlt Norm Value:',alt) nVelo -= 2 # My conclusion: The Alt Normalizer produces the best result, # for the most common use of a Bass or Keys playing with Drums. # (2:1 or 50%) data spread and a reduced max velocity. # Foot note a velocity of 0 in MIDI is a NOTE_OFF.