how do you get "godot internal widgets" in your own game ?

urieluriel Posts: 59Member
edited September 2019 in 2D

Hi everyone,
sometimes, you just want to have a similar widget in your game... and as i know, there is no a version of godot made by godot itself ;)
i tried to look at the doc, the api and even the source code, but i cant figure out how to get what i want.
here is a little exemple:

i want to get the audiostream "preview" widget
i could understand that the image is created when the stream recognize de file, but i cant find the function to do it.

i look at this page: https://github.com/godotengine/godot/blob/master/editor/audio_stream_preview.cpp
but all my test are not working... i would need some help from more experienced people :)

please, if you did something similar, comment :)
thanks a lot

uriel


Tags :

Comments

  • MegalomaniakMegalomaniak Posts: 2,748Admin

    Well first of all, you are looking at master, in this case both master and 3.1 branch(assuming that's what you are using) are the same length so that's probably not the issue here, but I'd recommend to always look at the source for the version you are using otherwise you might be spending time trying to figure out a way to use something that doesn't exist in your build.

    Second of all, I expect the preview to be generated by the class AudioStreamPreviewGenerator : public Node { at line 54 in the header file instead:
    https://github.com/godotengine/godot/blob/3.1/editor/audio_stream_preview.h

    Not sure it can be used outside of C++ though.

  • urieluriel Posts: 59Member

    hi > @Megalomaniak
    thanks, you are right, i was not looking at the source of the release i am using :+1: as i do compile to experiment as well.

    about your point over the class, you may be right that there is no method to call this particular item... humm, hummm... thats sad... but i suppose there is an other option for "audiobuffer to image" convertion... but where and how ?
    i really need this to make my game interesting. maybe i will find a trick that does the expected result.

  • TwistedTwiglegTwistedTwigleg Posts: 2,831Admin

    This doesn't give quite the right result, but the code below prints the audio waveform of a AudioStreamOGGVorbis file:

    extends Node2D
    
    export (AudioStreamOGGVorbis) var audio_stream;
    
    func _ready():
        update();
    
    func _draw():
        for i in range(0, len(audio_stream.data)):
            var horizontal_offset = Vector2(i * 0.05, 0);
            draw_line(Vector2.ZERO + horizontal_offset, Vector2(0, -audio_stream.data[i] / audio_stream.get_length()) + horizontal_offset, Color.green, 0.01);
    

    With some edits, you might be able to get it drawing correctly and like the audio preview in the Godot editor. The code above doesn't give the same result, though I'm wondering if the issue is post-processing and/or positioning.

    Maybe with something like the code above and the C++ code, you can generate audio waveforms like those seen in the Godot editor. It might be something worth messing around with if you want to go the GDScript route.

  • TwistedTwiglegTwistedTwigleg Posts: 2,831Admin
    edited October 2019

    I just saw this rhythm game on Reddit, and it seems the OP has managed to get a working waveform preview of the Godot audio stream using Godot 3.2.

    @uriel - if you are still interesting in displaying the audio waveform in Godot, I would ask the person who posted on Reddit and see if they do not mind sharing how they got the waveform display working in Godot.

  • urieluriel Posts: 59Member
    edited October 2019

    Hi,
    i saw his post and comment it, he answered he was using an external lib to get the result.that was challenging me during those days :) and i came up with a_ full GDscript waveform preview_ with custom parameters

    i will release all the code soon and share these experiments.

    i have added a bit of 2d Glow effect.. maybe too much :D

    in other hand, i know i will have to look for a more advanced audio analysis features and i am always interested to discuss external libs and options. thanks @TwistedTwigleg

  • urieluriel Posts: 59Member
    edited October 2019

    how will you do check the memory or anything usage for this widget ? i would like to evaluate the amount used ,pls

  • JackRedstoniaJackRedstonia Posts: 1Member
    edited July 24

    @uriel Do you still have the source code for this? I'm making a rhythm game and I need some way to visualise the audio waveform - some guidance would be great.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file