palmarci / rbBeatDetect

Send OSC beat signals from rekordbox
15 stars 1 forks source link

Mood from Lighting Mode #2

Open martenumberto opened 1 year ago

martenumberto commented 1 year ago

Hello again!

Maybe it's possible to get the mood of the Master Deck which is analysed by the Lighting Mode in Rekordbox? Do you have any ideas?

palmarci commented 1 year ago

Hello! Yes i have been thinkering with that idea. Well, my original idea was to get the analyzed phrases somehow and check if it is changing, for example when a drop occures we could send an other signal to strobe the lights, change the scene or even just the color. However i have not been able to find anything in memory about the phrase numbers. I know that those values are stored on the disk in a special format which we could understand thanks to this work. These values must be in the memory, but im guessing i couldnt find them because they are in a custom struct with enum variables. Maybe if we could reverse engineer the rekordbox.exe... I think i will revisit this idea now.

ghost commented 8 months ago

First of all, this is a great project! Im thinking there must be a bitmap of the current waveform stored somewhere in memory. The color of it can be very relevant to lighting. It should be technically possible to find the array of bytes (rgb) that are constantly changing. Using an eyedropper tool to match the current color might be helpful. Its just an idea, but might work.

palmarci commented 8 months ago

@denncath thank you for contributing to the project! This is a good idea, sadly there are a few drawbacks: some people prefer playing with only a blue waveform, not caring about the RGB or the 3-band modes. Secondly the data stored in the phrase structure is much more revealing: the song's current phrase can change from for example "intro" to "chrous", or the song can have a mood like "vivid" or "club". Interpreting this information in the light controller software could really help the synchronization between the light and sound experience. Sadly I have not found that structure yet in memory, so I am open to suggestion and any help is appreciated :)

ghost commented 8 months ago

Well there is one way, but its a long way. Some dude wrote this amazing library in GO to decrypt the rekordbox library: https://github.com/dvcrn/go-rekordbox. If we could capture the current song name (or ID) that is currently playing (definitely doable), we could look it up in the library to get phrases. Then match them to the current track time and voila.

palmarci commented 8 months ago

Thats actually a great idea, sadly im not too comfortable in Go, but there is a python library too. I also found a very interesting function here: https://pyrekordbox.readthedocs.io/en/latest/_modules/pyrekordbox/anlz/file.html#AnlzFile.getall_tags I will check this out soon

palmarci commented 8 months ago

Using the pyrekordbox library and breaking on this line I can examine the decrypted song structure data. The data starts with the ASCII header "PSSI", which is the name of the song structure key used by the ANLZ format. Searching for this string in Cheat Engine reveals exciting stuff:image There are 4 real occurrences and they are close to each other with the same offset values. Also the deck pointers are in those regions, so I am guessing the decrypted PSSI content gets written into the deck's memory. Parsing that would be very easy, since its already documented and implemented by the library.

ghost commented 8 months ago

Wow, thats a great find! You are very close to making it work!

Update: I found a helpful file in another library which parses Anlz files. It gives a good insight how everything comes together: https://github.com/Deep-Symmetry/crate-digger/blob/main/src/main/kaitai/rekordbox_anlz.ksy

There is also some useful info in the readme.md

palmarci commented 8 months ago

Sadly it does not work the way I initially thought it would. I can not find any pointers to the memory region where the PSSI data gets loaded and that region gets freed after the struct gets parsed I think, so it seems like its only there temporarily. More work is needed

ghost commented 8 months ago

Hm. Well one more thing popped to my mind (cant test it now), but here it is.

If I understand correctly, mood is assigned to the track and based on mood you get different sets of phrase names: mood_low_phrase: 1: intro 2: verse_1 3: verse_1b # Just displayed as "Verse 1" in rekordbox. 4: verse_1c # Just displayed as "Verse 1" in rekordbox. 5: verse_2 6: verse_2b # Just displayed as "Verse 2" in rekordbox. 7: verse_2c # Just displayed as "Verse 2" in rekordbox. 8: bridge 9: chorus 10: outro

mood_mid_phrase: 1: intro 2: verse_1 3: verse_2 4: verse_3 5: verse_4 6: verse_5 7: verse_6 8: bridge 9: chorus 10: outro

mood_high_phrase: 1: intro 2: up 3: down 5: chorus 6: outro

I want to believe that there is such variable as current_mood and current_phrase since there is support for lighting. Mood is for sure an integer 1..3, phrase probably is too. We might want to load different tracks and try to manually edit phrases in rekordbox to watch for any changes. You might've already tried it though.