Ingreso rápido:  

Forum: VirtualDJ Technical Support

Tema: VDJscript: BPM to MIDI Out (calculation)
Hey guys,

I need help getting BPM to MIDI from Virtual DJ to MaizeDMX, the lighting software I use. The integration between them works fine, but my problem is in calculating the BPM (from 0 to 300) for MIDI (from 0 to 127). I'm doing it like this:

- Button (with repeat): set '$vSpeedMaster' `deck master get_bpm`
- Mapping Controller: get_var '$vSpeedMaster' & param_multiply 0.423 [0.423 means 127/300]
- In MaizeDMX: take the received value (from 0 to 127) and multiply it by 2.362 [2.362 means 300/127]

That is, as BPM can go from 0 to 300, but MIDI only goes from 0 to 127, so I need to reduce the scale to send in MIDI Out and when receiving in MIDI In I increase the scale to return to the BPM of the song , the closest possible.

But, looking at the MIDI data monitor, the information that comes out of Virtual DJ is not the expected one... the value sent in the MIDI Out is not the result of the calculation, I tried to identify some pattern but I didn't come to any conclusion. Look at these examples:

music | get_bpm | calc 0.423 | send midi
1 | 81.501 | 34.475 | 26
2 | 82.499 | 34.897 | 80
3 | 83.331 | 35.249 | 125
4 | 86.999 | 36.801 | 66
5 | 150.00 | 63.450 | 122
6 | 200.843 | 84.957 | 37

I.e. for song 1, I expected the MIDI output value to be 34.475 but the MIDI monitor shows that Virtual DJ sent 26.

I did a lot of research on the forum, I read some threads about calculating the BPM, but none addressed MIDI integration (I can't use MIDI Clock). I'm lost, I've tried several calculations but I can't conclude... please, anyone who knows, help me with this question. Thanks!
 

Mensajes Fri 11 Aug 23 @ 9:11 pm
AdionPRO InfinityCTOMember since 2006
Normally vdj mappings expect values between 0 and 1, so you need to multiply by 1/300 in the vdj script.
When vdj then sends it over midi it will be mapped to the 127 range.

Note that using a range of 0 to 300 bpm means you have a precision of less than 2 bpm, so unless you actually have 300 bpm music I'd narrow it down further
 

Mensajes Sat 12 Aug 23 @ 4:08 am
Thanks for the feedback @Adion, but the problem wasn't quite the aspect you mentioned... it was actually related to the calculation of the parameters, and resolved as follows:

In relation to what I mentioned earlier, needed to turn the number into an integer and invert the scale... that is, for example, BPM->MIDI cc value: 1->127, 3- >125, 5->123, ... 125->3, 127->1. That is, the higher the BPM, the lower the MIDI cc value sent, so the calculation script looks like this:

"get_var '$vSpeedMaster' & param_multiply 0.425 & param_cast 'integer' & param_invert & param_add 128"

Just in case someone needs to send the BPM via MIDI cc to another software, here's the complete code:

This part is for including the MIDI controller in virtual DJ. In this case, it is the connection with MaizeDMX, the lighting software I use.

<device name="MaizeDMX" author="MaizeDMX" version="802" description="MaizeDMX Control" type="MIDI" drivername="MaizeDMX" decks="1">
<bar cc="0x02" name="oSpeedMaster" channel="0" />
</device>

<mapper device="MaizeDMX" version="802" date="2023-08-02">
<map value="oSpeedMaster" action="get_var '$vSpeedMaster' & param_multiply 0.425 & param_cast 'integer' & param_invert & param_add 128" />
</mapper>


Already on the Virtual DJ frontend, I included the code below in the Pad Custom Menu. The script below does other things too, but for the purpose of this thread, only the snippet below matters.

LightSound +[repeat_start 'LightSound' ? on & repeat_stop 'LightSound' : off & repeat_start 'LightSound' 1000ms & set '$vSpeedMaster' `deck master get_bpm`]

That was it. And then in the lighting software I included a script to read the MIDI cc Out of Virtual DJ and recalculate the BPM, but that is not the case in this forum. If someone uses MaizeDMX and wants to implement the MIDI connection, let me know and I'll send the script to the lighting software.

Note: Regarding my comment at the opening of this topic, the most correct values to transform BPM (from 0 to 300) to MIDI (from 0 to 127) are the ones below:

- Mapping Controller: param_multiply 0.425 [0.425 means 128/301]
- In MaizeDMX: multiply it by 2.351 [2.351 means 301/128]

I don't know if this is the most correct way, considering that we know that there is a MIDI Clock, but for my need, which was to pass the BPM through MIDI cc, that's how I solved it. If someone more expert knows how to improve, help is always welcome.
 

Mensajes Sat 12 Aug 23 @ 2:47 pm