Adding Console on Compiled Plugin For Debugging



  • Hi ! I tried to add Console to Compiled Plugin , but I couldn't find option in ContentType for floating-tile.
    Is it it bug or missing some?
    3130884c-243f-41a2-ae8d-91e156f5837e-image.png
    https://docs.hise.audio/ui-components/floating-tiles/hise/console.html



  • Yeah, the Console is not part of the codebase that is used for compiling the plugin, also all calls to Console.print() are removed.

    With a little bit of extra work you could write a file logger using the new FileSystem API though.



  • @Christoph-Hart Oh Okay ,
    Console.print() is real time debugging ,but I guess file logger is also work 😉
    Thank you



  • @Christoph-Hart Should HISE has File.appendText() or File.appendString() then?



  • Nope, you can write that functionality in HiseScript:

    /** A asynchronous file logger.
    
        You can use this in order to log to a file. It replaces
        Console.print and appends anything to a file on the desktop.
        
        The actual file writing is deferred to a timer callback,
        so you can use it in realtime callbacks without too much
        overhead. It handles multithreaded access gracefully, however
        you can opt to deactivate this in order to trade in CPU spikes
        vs. logging accuracy.
        
        CAUTION: Never ever leave it enabled in a real project as 
        it will still allocate memory for storing the pending message
        queue.
    */
    namespace FileLogger
    {
        // Set this to false if you want to keep the file content
        // between compilations.
        const var CLEAR_ON_COMPILE = true;
        
        // Or pick a file of your choice...
        const var logFile = FileSystem.getFolder(FileSystem.Desktop).getChildFile("Log.txt");
        
        const var lines = logFile.loadAsString().split("\n");
        
        if(CLEAR_ON_COMPILE)
            lines.clear();
        
        const var pendingLines = [];
        reg flag = false;
        reg enabled = false;
        
        /** You can enable / disable the logging with this function. */
        inline function setEnabled(state)
        {
            if(state != enabled)
            {
                enabled = state;
                
                if(enabled)
                    t.startTimer(30);
                else
                    t.stopTimer();
            }
        }
        
        /** Use this function if you want to print something. */
        inline function print(text)
        {
            if(enabled)
            {
                // This will lock the flag for the duration
                // of this operations.
                writeLock(flag);
                
                pendingLines.push(text);
                flag = true;
            }
        }
    
        const var t = Engine.createTimerObject();
        
        t.setTimerCallback(function()
        {
            if(flag)
            {
                // This locks the flag during a print operation
                // You can comment out this line in order to 
                // deactivate proper handling of multithreaded
                // access. This will remove CPU spikes (because it
                // will never lock, but it might cause undefined 
                // behaviour including dropped messages at potential 
                // crashes).
                readLock(flag);
                
                flag = false;
                lines.reserve(lines.length + pendingLines.length);
                
                for(e in pendingLines)
                    lines.push(e);
                
                pendingLines.clear();
                logFile.writeString(lines.join("\n"));
                
                // This will check whether there is a race condition
                // Try to comment out the lock statement above and it will
                // fire as soon as there is a concurrent access to 
                // the flag (eg. if the print command is being called
                // in a MIDI callback.
                if(flag)
                    Console.print("RACE!");
            }
        });
        
        // Enable it by default. You can call this method from a UI element.
        // If it's disabled it will produce almost no overhead. The rules of
        // never creating any Strings in a realtime thread still applies 
        // obviously...
        setEnabled(true);
    };
    


  • @Christoph-Hart Wow , Thank you.
    I will add this to my project now ,


Log in to reply
 

9
Online

1.2k
Users

3.8k
Topics

33.6k
Posts