;Increase or decrease the avarage loudness of a style to standard values. ;Maintain the relative loudness of tracks and parts. ;If the diffences in loudness between tracks and parts are undesired then use FixedLoudness.stp. Define VolumeControllers Numeric Define Notes Numeric Define CountVolume Numeric Define TotalVolume Numeric Define OldAvarageVolume Numeric Define NewAvarageVolume Numeric Define CountVelocity Numeric Define TotalVelocity Numeric Define OldAvarageVelocity Numeric Define NewAvarageVelocity Numeric ForEachStyle PrintLine StyleName ;First check if there is a volume controller on each track that contains notes. ;If not add a volume controller with a default value (127). ;Delete volume controllers in tracks without notes. ForEachTrack Let Notes = 0 Let VolumeControllers = 0 ForEachPart ForEachEvent If EventType = 1 Let Notes = Add Notes 1 EndIf If EventType = 3 If DataByte1 = 7 Let VolumeControllers = Add VolumeControllers 1 EndIf EndIf NextEvent NextPart ;Add volume controller if needed If VolumeControllers = 0 If Notes > 0 ForEachPart If PartName = 'Control changes' Let Measure = 1 Let Beat = 1 Let Tick = 1 Let EventType = 3 Let DataByte1 = 7 Let DataByte2 = 127 InsertEvent EndIf NextPart EndIf EndIf ;Delete volume controller if not needed If VolumeControllers > 0 If Notes = 0 ForEachPart If PartName = 'Control changes' ForEachEvent If EventType = 3 If DataByte1 = 7 DeleteEvent EndIf EndIf NextEvent EndIf NextPart EndIf EndIf NextTrack ;Determine the avarage volume and velocity in the style Let CountVolume = 0 Let TotalVolume = 0 Let CountVelocity = 0 Let TotalVelocity = 0 ForEachPart ForEachTrack ForEachEvent If EventType = 3 ;Controller If DataByte1 = 7 ;Volume Let CountVolume = Add CountVolume 1 Let TotalVolume = Add TotalVolume DataByte2 EndIf EndIf If EventType = 1 ;Note on Let CountVelocity = Add CountVelocity 1 Let TotalVelocity = Add TotalVelocity DataByte2 EndIf NextEvent NextTrack NextPart Let OldAvarageVolume = Divide TotalVolume CountVolume Let OldAvarageVelocity = Divide TotalVelocity CountVelocity PrintLine CountVolume PrintLine TotalVolume PrintLine OldAvarageVolume PrintLine CountVelocity PrintLine OldAvarageVelocity ;Change volumes and velocities to create a new avarage volume and velocity Let NewAvarageVolume = 90 ; *** CUSTOMIZE VALUES HERE *** Let NewAvarageVelocity = 90 ; *** CUSTOMIZE VALUES HERE *** ForEachPart ForEachTrack ForEachEvent If EventType = 3 ;Controller If DataByte1 = 7 ;Volume Let DataByte2 = Multiply DataByte2 NewAvarageVolume Let DataByte2 = Divide DataByte2 OldAvarageVolume If DataByte2 < 1 Let DataByte2 = 1 Endif If DataByte2 > 127 Let DataByte2 = 127 Endif UpdateEvent EndIf EndIf If EventType = 1 ;Note on Let DataByte2 = Multiply DataByte2 NewAvarageVelocity Let DataByte2 = Divide DataByte2 OldAvarageVelocity If DataByte2 < 1 Let DataByte2 = 1 Endif If DataByte2 > 127 Let DataByte2 = 127 Endif UpdateEvent EndIf NextEvent NextTrack NextPart SaveStyle NextStyle