Hey just wanted to share this quick script incase it is of value for anyone. I have been in need of console statements for debugging in daw but you can't print console statements outside of HISE. So I created a little python script that looks for all instances of "Console.print" in a .txt file and adds a line directly below them that makes a function call to onboardConsole().
Then in the onboardConsole() function we can update the value of a ScriptLabel with the same information we log to console.
I have been finding it pretty handy and I hope it is of value to you too.
What you do is copy your HISEScript and save it to a .txt file. Then run the following python script. The script will prompt you to choose the .txt file where you saved your HISEScript. It will then prompt you for a name and location to save the new version of your HISEScript with the added onboardConsole() function calls. You can then copy and paste this into HISE.
Here is the python script:
import tkinter as tk
from tkinter import filedialog
def add_onboard_console(input_file, output_file):
with open(input_file, 'r') as f:
lines = f.readlines()
with open(output_file, 'w') as f:
for line in lines:
f.write(line)
stripped_line = line.strip()
if stripped_line.startswith("Console.print(") and stripped_line.endswith(");"):
onboard_line = stripped_line.replace("Console.print(", "onboardConsole(")
f.write("\n" + " " * (line.index("Console.print(")) + onboard_line)
def main():
root = tk.Tk()
root.withdraw()
# Prompt for input file
input_file_path = filedialog.askopenfilename(title="Select the text file to transform")
# Exit if no file is selected
if not input_file_path:
return
# Prompt for output file
output_file_path = filedialog.asksaveasfilename(title="Save the transformed file as", defaultextension=".txt", filetypes=[("Text files", "*.txt"), ("All files", "*.*")])
# Exit if no save path is chosen
if not output_file_path:
return
add_onboard_console(input_file_path, output_file_path)
if __name__ == "__main__":
main()
Then add this function to the top of your project right under where you create the interface:
const var Label1 = Content.getComponent("Label1");
// Declare an array to hold the recent messages
var recentMessages = [];
function onboardConsole(message) {
// Convert everything to a string using JSON.stringify
var messageStr = JSON.stringify(message);
// Remove unwanted newline characters
messageStr = messageStr.replace("\n", " ");
// Truncate the message to the first 100 characters
var truncatedMessage = messageStr.substring(0, 100);
// Add the new message to the start of the array
recentMessages.insert(0, truncatedMessage);
// If the array has more than 10 messages, remove the oldest one
while (recentMessages.length > 10) {
recentMessages.pop();
}
// Update the Label1 label's text with the concatenated recent messages
Label1.setValue(recentMessages.join("\n"));
}
Here the label is called Label1, but you can change this based on the ID of the label you want to display the console content in.
Here is a HISESnippet of how it works:
HiseSnippet 1195.3ocsV09aaSDF+bacUafgXR6Ofi7Eb0JYIkw.ABnqugBr1FszUgDfltZ+33iZem0cmaZzz9N+4x+Avyc1IwwMzsEIxGb7879K+d7yMPICAsVpHdaewjbf38w9CmHLIGlv3BR+iHdeh+oLsATzRRGLImo0PDwya8exRva6MHte+8Od.KkIBg4jHjKk7P3E7LtYN0A6+K7zzSXQvE7rZR+z86GJEGJSkEX7rteWRNK7Z1H3LlUr07IdadbD2HUCMLCnQYNPFMYXhbrnT9K4Z9Uof8POxPzPkjIGlvSiFLMW0Dh2FClm4qWl4Ox+TdDeF84UfO0wfNWi50.u0tuPp2GPH4UKj1nLjdn+vPEO2LmiMd9H+9BrgDyvRc8PoTVxZ+ku+gRTBgoSF6Z3DEdXlFA60s6tT7wNeWqVX4Van2vTzWvtBR6Q+d5TMGAlCkY4RAdHncI61VcdxSnGAgoLEPYBJSoXSnFIMQlFQMI.UAgnJzLLdwVmtk05kzNshD5ke6OPKEWHBMbofJEWIYpHz0ZYJDTo5Nz2zhh+PGhbtATFJfOmXR3hQVWxnZix9dg197mGd9YcJovim3T056JqMznP+tnLy7DFLUd5kPl7FfVHFyv5PDU.iS4BfFlvTrPrFpcRtfQmeniBxSsE41+tn8tz1z10L8EJLeQPhqJUoiMMrGi4JrQzqa2lNxlAlJEipJfK5RcwUkIT.1W6U1Wq73yiJaIXRzzgZCCqmxX2AWSzozhMpNbgFK6VC2LFp4k90LBMgooYRkMIQzQutyvA6h11UZsxhXE.yWDb4LxXbV.nAMbdJHFYRn+.ZkoPgkDh4x7.LXrbdq6YSLyRvjyQsyPvXkPTjcEnvd9Ln6zFvTN0.vMhhLVdvT3bPldztTtHBtcw31TnDz.GC5io81Aez9aQPxionFUoPs55qxilhVplNSs+84ZpAt0PGywhikINDa6LBa24NSeVaUpcGMXtjkV.AMSmN+ojKbP1cP2+V2H9YxwzbDUYnZYlEtTDG+YsplP633Dz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