|
Post by paulo164 on Oct 18, 2021 11:50:21 GMT
Hello,
I am looking for a way to store the last time a note has been played, on a per-note basis. I know there are up to 7 timer variables but this doesn’t allow me to track when a particular note has been played for the last time. My idea is to create a velocity ‘smoothing’ filter which takes into account the last velocity of a particular note by mixing it with the current note velocity. The weight of the previous velocity is decreasing as the elapsed time between the 2 events becomes great. All is done except the timer which is global all across the keyboard for now.
I fear there is no way to do this but I am still hopping for a StreamByter guru who could really make my day 🤲🙏 Thank you very much !
Kindest regards, Paulo
|
|
nic
Soapbox Supremo  
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Oct 19, 2021 6:56:07 GMT
Hi paulo164 , You only need the one timer which you use to accumulate into a timestamp and then you store the timestamp for each note. I suggest using the P array for timestamps. Something like this (example code; completely untested!): if load alias P80 timestamp # set now timestamp sub mark_time calc timestamp = timestamp + T0 end
# start from zero mark_time assign timestamp = 0 end
# trap note on event if MT == 90 # save timestamp for this note # into P0 to P7F mark_time assign PM1 = P80 endThe last time a note was played would be calculated as follows elsewhere in your code, eg to get ms since last middle C was played: mark_time calc P81 = timestamp - P3CRegards, Nic.
|
|
|
Post by paulo164 on Oct 20, 2021 7:38:38 GMT
Hi Nic,
Thank you very much ! Yes, in the meantime I found the solution but I was tracking timestamp for all 88 keys every incoming event 😂. Your code is much more efficient since timestamp only has to be tracked in one variable P80 👍
I must say I am very impressed by what StreamByter has to offer. It is free and you are providing a great support for every newcomer here. So big big kudos to you… I am starting to love programming this language. My script already gives convincing results. So I will publish it here once I have finished polishing it.
Bye !
|
|
|
Post by paulo164 on Mar 20, 2022 20:59:32 GMT
# Velocity Enhancer v1.00 # by Robin Pauletto
IF LOAD
# configure widgets name and range SET Q0 HEADROOM $0 $30 SET Q1 MEMORY_ms 1 $1000 SET Q2 SPEED_FEEDBACK 0 $10 set Q3 DERIVATIVE 0 $10 set Q4 POWER_SWITCH +YESNO set Q5 +HIDE set Q6 SF_THRESHOLD $0 $127 set Q7 +HIDE
Set Q8 VELOCITY_IN $0 $127 Set Q9 VELOCITY_OUT $0 $127 SET QA +HIDE SET QB +HIDE SET QC +HIDE SET QD +HIDE SET QE +HIDE SET QF +HIDE
# set widget initial values ASS Q0 = $15 $300 4 3 1 0 $25
ass P80 = 0 #timestamp Ass P81 = 0 #current elapsed time since last note-on on same note ass P82 = 0 #current elapsed time since last note-on on all notes
alias Q0 INITIAL_MAX_VELOCITY Alias Q1 MAX_COEF alias Q2 SPEED_FEEDBACK_AMT alias Q3 DERIVATIVE_AMT Alias Q4 POWER_SWITCH Alias Q6 PF_THRESHOLD
Alias Q8 VEL_IN_LABEL Alias Q9 VEL_OUT_LABEL
subroutine CALCULATE_DECAY ELAPSED_TIME VAL if ELAPSED_TIME < 0 ASS VAL = 0 ELSE if ELAPSED_TIME > $5000 ASS VAL = 0 else Ass P$100 = ELAPSED_TIME MAT P$100 = P$100 * P$100 MAT P$100 = P$100 * $10 MAT P$100 = P$100 / Q1 MAT P$100 = P$100 + $1000 MAT P$100 = $500000 / P$100 Ass VAL = P$100 end end END
SUBROUTINE LOG10 X Y MAT X = X / $10 IF X > 0 Mat Y = Y + 1 LOG10 X Y END END
SUBROUTINE LOG2 X Y MAT X = X / 2 IF X > 0 Mat Y = Y + 1 LOG2 X Y END END
END
If POWER_SWITCH == 1 IF MT == 90
#We retrieve time components Ass P82 = T00 Mat P80 = P80 + P82 #we store the new global timestamp Mat P81 = P80 - PM1 #we calculate the elapsed time since last note-on Ass PM1 = P80 #we update the timestamp for current note
#Same note temporal velocity smoother
If M2 < JM1 #decrescendo
CALCULATE_DECAY P81 I81 #We calculate the weight of previous note velocity as a decay of elapsed time ASS I82 = I81 MAT I0 = JM1 - M2 if I0 > 40 #strong velocity variation mat I82 = I81 / 2 #-> we decrease the weight, thus the smoothing end Else #crescendo mat I84 = M2 - JM1 Mat I84 = I84 * M2 Mat I84 = I84 / P81 mat I84 = I84 / $30 Mat I84 = I84 + 1 Mat P84 = P81 / I84 CALCULATE_DECAY P84 I82 End
Ass I85 = I82
#same note smoothing
Ass I84 = LM1 Ass LM1 = I82 Mat I84 = I84 / 2 mat I82 = I82 / 2 Mat I82 = I82 * I84 Mat I82 = I82 / $125
MAT I83 = $500 - I82 # we calculate the weight of incoming note velocity
#we mix current and previous velocities MAT I82 = I82 * JM1 MAT I83 = I83 * M2
#########
#previous overall note smoothing
Ass I84 = L85 #previous overall coef Mat P84 = P82 / 1 CALCULATE_DECAY P84 I85 Ass I0 = I85 If M2 > J0 #crescendo mat I85 = I85 / $5 End
Ass L85 = I85 Mat I84 = I84 / 2 mat I85 = I85 / 2 Mat I85 = I85 * I84 Mat I85 = I85 / $125
MAT I86 = $500 - I85 # we calculate the weight of incoming note velocity
###########
Mat I0 = I0 * INITIAL_MAX_VELOCITY Mat I0 = I0 / $500 mat I0 = $127 - I0
If I82 == 0 # After a long inactive period for the key MAT I82 = I0 * M2 #we reduce the initial max velocity MAT I82 = I82 / $127 Else MAT I82 = I82 + I83 MAT I82 = I82 / $500
MAT I82 = I0 * I82 MAT I82 = I82 / $127
#we mix current and previous overall velocities MAT I85 = I85 * J0 MAT I86 = I86 * I82
MAT I82 = I85 + I86 MAT I82 = I82 / $500
End
#Additional velocity amount due to the derivative MAT P84 = P83 + P82
CALCULATE_DECAY P84 L0
Ass I84 = 0
If I82 < J0 #decrescendo If J0 <= K0 Mat I0 = K0 - J0 mat I84 = J0 - I82 mat I0 = I0 * I84 Mat I0 = I0 / $100 MAT I0 = I0 * L0
LOG2 I0 I84 Mat I84 = I84 * L0 Mat I84 = I84 / $5000 Mat I84 = I84 * DERIVATIVE_AMT If I84 >= L$101 Mat I84 = I84 - L$101 #adding former crescendo Else ASS I84 = 0 End
If I84 > I82 Mat I84 = I82 - 1 End IF Ass L$100 = I84 #we store the decrescendo Mat I82 = I82 - I84
Ass L$101 = 0 #we reset the former crescendo End Else #crescendo If J0 >= K0 Mat I0 = J0 - K0 mat I84 = I82 - J0 mat I0 = I0 * I84 Mat I0 = I0 / $100 MAT I0 = I0 * L0
LOG2 I0 I84 Mat I84 = I84 * L0 Mat I84 = I84 / $5000 Mat I84 = I84 * DERIVATIVE_AMT If I84 >= L$100 Mat I84 = I84 - L$100 #adding former decrescendo Else ASS I84 = 0 End Ass L$101 = I84 #we store the crescendo Mat I82 = I82 + I84 Ass L$100 = 0 #we reset the former decrescendo End End
#Additional velocity amount due to speedy playing CALCULATE_DECAY P82 I85
Ass L0 = I85 Mat L0 = L0 * J0 Mat L0 = L0 / $501 MAT I0 = $127 - I82 If I82 > M2 MAT I85 = I82 - M2 ELSE ASS I85 = $1 END IF Mat I85 = I85 * I85 MAT L0 = L0 * I0 MAT L0 = L0 / I85 Mat L0 = L0 * I82
Mat I84 = SPEED_FEEDBACK_AMT + $1 mat I84 = L0 / I84 Mat I84 = I84 + $127 Mat L0 = L0 / I84
If I82 >= PF_THRESHOLD Mat I84 = $127 - I82 If L0 > I84 Ass L0 = I84 End Mat I82 = I82 + L0 #we add to the nominal amount Else mat L0 = L0 * SPEED_FEEDBACK_AMT Mat I84 = PF_THRESHOLD - I82 Mat L0 = L0 * I84 Mat L0 = L0 / $127 Mat L0 = L0 * I82 Mat L0 = L0 / $127 If L0 > I82 Mat L0 = I82 - 1 END Mat I82 = I82 - L0 #we add to the nominal amount End IF
If I82 > $127 #limiter Ass I82 = $127 End
Ass IM1 = I82
Ass KM1 = JM1 #will be the last last velocity ASS JM1 = IM1 #will be the last velocity Ass K0 = J0 #will be the last last overall velocity Ass J0 = IM1 #will be the last overall velocity Ass P83 = P82 #will be the last overall elapsed time Ass L1 = L0
ASS VEL_IN_LABEL = M2 #we update the incoming velocity monitoring ASS M2 = IM1 #the output ASS VEL_OUT_LABEL = M2 #we update the outgoing velocity monitoring
END END
|
|
|
Post by paulo164 on Mar 20, 2022 21:14:59 GMT
Of course, I would be proud if this ends up in the code-boutique thread 😉
|
|
nic
Soapbox Supremo  
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Mar 25, 2022 18:00:49 GMT
|
|
|
Post by paulo164 on Mar 31, 2022 22:05:25 GMT
Cool, thanks. I will do other (useful) scripts.
|
|